]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: _gbsizer.i | |
3 | // Purpose: SWIG interface stuff for wxGBGridBagSizer and etc. | |
4 | // | |
5 | // Author: Robin Dunn | |
6 | // | |
7 | // Created: 05-Nov-2003 | |
8 | // RCS-ID: $Id$ | |
9 | // Copyright: (c) 2003 by Total Control Software | |
10 | // Licence: wxWindows license | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | // Not a %module | |
14 | ||
15 | ||
16 | //--------------------------------------------------------------------------- | |
17 | ||
18 | %{ | |
19 | %} | |
20 | ||
21 | //--------------------------------------------------------------------------- | |
22 | ||
23 | %typemap(in) wxGBPosition& (wxGBPosition temp) { | |
24 | $1 = &temp; | |
25 | if ( ! wxGBPosition_helper($input, &$1)) SWIG_fail; | |
26 | } | |
27 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBPosition& { | |
28 | $1 = wxPySimple_typecheck($input, wxT("wxGBPosition"), 2); | |
29 | } | |
30 | ||
31 | %typemap(in) wxGBSpan& (wxGBSpan temp) { | |
32 | $1 = &temp; | |
33 | if ( ! wxGBSpan_helper($input, &$1)) SWIG_fail; | |
34 | } | |
35 | %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBSpan& { | |
36 | $1 = wxPySimple_typecheck($input, wxT("wxGBSpan"), 2); | |
37 | } | |
38 | ||
39 | ||
40 | %{ | |
41 | bool wxGBPosition_helper(PyObject* source, wxGBPosition** obj) | |
42 | { | |
09b77fb7 RD |
43 | if (source == Py_None) { |
44 | **obj = wxGBPosition(-1,-1); | |
45 | return True; | |
46 | } | |
d14a1e28 RD |
47 | return wxPyTwoIntItem_helper(source, obj, wxT("wxGBPosition")); |
48 | } | |
49 | ||
50 | bool wxGBSpan_helper(PyObject* source, wxGBSpan** obj) | |
51 | { | |
09b77fb7 RD |
52 | if (source == Py_None) { |
53 | **obj = wxGBSpan(-1,-1); | |
54 | return True; | |
55 | } | |
d14a1e28 RD |
56 | return wxPyTwoIntItem_helper(source, obj, wxT("wxGBSpan")); |
57 | } | |
58 | ||
59 | %} | |
60 | ||
61 | ||
62 | //--------------------------------------------------------------------------- | |
63 | %newgroup; | |
94d33c49 | 64 | |
d14a1e28 RD |
65 | |
66 | class wxGBPosition | |
67 | { | |
68 | public: | |
69 | wxGBPosition(int row=0, int col=0); | |
70 | ||
71 | int GetRow() const; | |
72 | int GetCol() const; | |
73 | void SetRow(int row); | |
74 | void SetCol(int col); | |
d14a1e28 | 75 | |
09b77fb7 RD |
76 | // %extend { |
77 | // bool __eq__(const wxGBPosition* other) { return other ? (*self == *other) : False; } | |
78 | // bool __ne__(const wxGBPosition* other) { return other ? (*self != *other) : True; } | |
79 | // } | |
80 | ||
81 | bool operator==(const wxGBPosition& other); | |
82 | bool operator!=(const wxGBPosition& other); | |
83 | ||
d14a1e28 | 84 | %extend { |
dd9f7fea RD |
85 | void Set(int row=0, int col=0) { |
86 | self->SetRow(row); | |
87 | self->SetCol(col); | |
88 | } | |
89 | ||
90 | PyObject* Get() { | |
da32eb53 | 91 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
92 | PyObject* tup = PyTuple_New(2); |
93 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow())); | |
94 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol())); | |
da32eb53 | 95 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
96 | return tup; |
97 | } | |
98 | } | |
99 | %pythoncode { | |
d07d2bc9 | 100 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
101 | def __str__(self): return str(self.Get()) |
102 | def __repr__(self): return 'wx.GBPosition'+str(self.Get()) | |
103 | def __len__(self): return len(self.Get()) | |
104 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
105 | def __setitem__(self, index, val): |
106 | if index == 0: self.SetRow(val) | |
107 | elif index == 1: self.SetCol(val) | |
108 | else: raise IndexError | |
dd9f7fea | 109 | def __nonzero__(self): return self.Get() != (0,0) |
02376d73 RD |
110 | __safe_for_unpickling__ = True |
111 | def __reduce__(self): return (wx.GBPosition, self.Get()) | |
d14a1e28 RD |
112 | } |
113 | ||
114 | %pythoncode { | |
115 | row = property(GetRow, SetRow) | |
116 | col = property(GetCol, SetCol) | |
117 | } | |
118 | }; | |
119 | ||
120 | ||
121 | ||
d14a1e28 RD |
122 | |
123 | class wxGBSpan | |
124 | { | |
125 | public: | |
126 | wxGBSpan(int rowspan=1, int colspan=1); | |
127 | ||
128 | int GetRowspan() const; | |
129 | int GetColspan() const; | |
130 | void SetRowspan(int rowspan); | |
131 | void SetColspan(int colspan); | |
132 | ||
09b77fb7 RD |
133 | // %extend { |
134 | // bool __eq__(const wxGBSpan* other) { return other ? (*self == *other) : False; } | |
135 | // bool __ne__(const wxGBSpan* other) { return other ? (*self != *other) : True; } | |
136 | // } | |
137 | bool operator==(const wxGBSpan& other); | |
138 | bool operator!=(const wxGBSpan& other); | |
139 | ||
d14a1e28 RD |
140 | |
141 | %extend { | |
dd9f7fea RD |
142 | void Set(int rowspan=1, int colspan=1) { |
143 | self->SetRowspan(rowspan); | |
144 | self->SetColspan(colspan); | |
145 | } | |
146 | ||
147 | PyObject* Get() { | |
da32eb53 | 148 | bool blocked = wxPyBeginBlockThreads(); |
d14a1e28 RD |
149 | PyObject* tup = PyTuple_New(2); |
150 | PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan())); | |
151 | PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan())); | |
da32eb53 | 152 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
153 | return tup; |
154 | } | |
155 | } | |
156 | %pythoncode { | |
d07d2bc9 | 157 | asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead") |
dd9f7fea RD |
158 | def __str__(self): return str(self.Get()) |
159 | def __repr__(self): return 'wx.GBSpan'+str(self.Get()) | |
160 | def __len__(self): return len(self.Get()) | |
161 | def __getitem__(self, index): return self.Get()[index] | |
d14a1e28 RD |
162 | def __setitem__(self, index, val): |
163 | if index == 0: self.SetRowspan(val) | |
164 | elif index == 1: self.SetColspan(val) | |
165 | else: raise IndexError | |
dd9f7fea | 166 | def __nonzero__(self): return self.Get() != (0,0) |
02376d73 RD |
167 | __safe_for_unpickling__ = True |
168 | def __reduce__(self): return (wx.GBSpan, self.Get()) | |
d14a1e28 RD |
169 | } |
170 | ||
171 | %pythoncode { | |
172 | rowspan = property(GetRowspan, SetRowspan) | |
173 | colspan = property(GetColspan, SetColspan) | |
174 | } | |
175 | }; | |
176 | ||
177 | ||
178 | %immutable; | |
179 | const wxGBSpan wxDefaultSpan; | |
180 | %mutable; | |
181 | ||
182 | ||
183 | //--------------------------------------------------------------------------- | |
184 | ||
185 | ||
186 | class wxGBSizerItem : public wxSizerItem | |
187 | { | |
188 | public: | |
189 | wxGBSizerItem(); | |
190 | ||
191 | %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window, | |
192 | const wxGBPosition& pos, | |
193 | const wxGBSpan& span, | |
194 | int flag, | |
195 | int border, | |
196 | wxObject* userData ); | |
197 | ||
198 | %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer, | |
199 | const wxGBPosition& pos, | |
200 | const wxGBSpan& span, | |
201 | int flag, | |
202 | int border, | |
203 | wxObject* userData ); | |
204 | ||
205 | %name(GBSizerItemSpacer) wxGBSizerItem( int width, | |
206 | int height, | |
207 | const wxGBPosition& pos, | |
208 | const wxGBSpan& span, | |
209 | int flag, | |
210 | int border, | |
211 | wxObject* userData); | |
212 | ||
213 | ||
214 | // Get the grid position of the item | |
215 | wxGBPosition GetPos() const; | |
dd9f7fea | 216 | %pythoncode { def GetPosTuple(self): return self.GetPos().Get() } |
d14a1e28 RD |
217 | |
218 | // Get the row and column spanning of the item | |
219 | wxGBSpan GetSpan() const; | |
dd9f7fea | 220 | %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() } |
d14a1e28 RD |
221 | |
222 | // If the item is already a member of a sizer then first ensure that there | |
223 | // is no other item that would intersect with this one at the new | |
dd9f7fea | 224 | // position, then set the new position. Returns True if the change is |
d14a1e28 RD |
225 | // successful and after the next Layout the item will be moved. |
226 | bool SetPos( const wxGBPosition& pos ); | |
227 | ||
228 | // If the item is already a member of a sizer then first ensure that there | |
229 | // is no other item that would intersect with this one with its new | |
dd9f7fea | 230 | // spanning size, then set the new spanning. Returns True if the change |
d14a1e28 RD |
231 | // is successful and after the next Layout the item will be resized. |
232 | bool SetSpan( const wxGBSpan& span ); | |
233 | ||
234 | %nokwargs Intersects; | |
235 | ||
dd9f7fea | 236 | // Returns True if this item and the other item instersect |
d14a1e28 RD |
237 | bool Intersects(const wxGBSizerItem& other); |
238 | ||
dd9f7fea | 239 | // Returns True if the given pos/span would intersect with this item. |
d14a1e28 RD |
240 | bool Intersects(const wxGBPosition& pos, const wxGBSpan& span); |
241 | ||
242 | // Get the row and column of the endpoint of this item | |
243 | void GetEndPos(int& row, int& col); | |
244 | ||
245 | ||
246 | wxGridBagSizer* GetGBSizer() const; | |
247 | void SetGBSizer(wxGridBagSizer* sizer); | |
248 | ||
249 | }; | |
250 | ||
251 | ||
252 | //--------------------------------------------------------------------------- | |
253 | ||
254 | ||
255 | class wxGridBagSizer : public wxFlexGridSizer | |
256 | { | |
257 | public: | |
258 | wxGridBagSizer(int vgap = 0, int hgap = 0 ); | |
259 | ||
dd9f7fea RD |
260 | // The Add method returns True if the item was successfully placed at the |
261 | // given cell position, False if something was already there. | |
d14a1e28 RD |
262 | %extend { |
263 | bool Add( PyObject* item, | |
264 | const wxGBPosition& pos, | |
265 | const wxGBSpan& span = wxDefaultSpan, | |
266 | int flag = 0, | |
267 | int border = 0, | |
268 | PyObject* userData = NULL ) { | |
269 | ||
270 | wxPyUserData* data = NULL; | |
da32eb53 | 271 | bool blocked = wxPyBeginBlockThreads(); |
dd9f7fea | 272 | wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False); |
d14a1e28 RD |
273 | if ( userData && (info.window || info.sizer || info.gotSize) ) |
274 | data = new wxPyUserData(userData); | |
da32eb53 | 275 | wxPyEndBlockThreads(blocked); |
d14a1e28 RD |
276 | |
277 | // Now call the real Add method if a valid item type was found | |
278 | if ( info.window ) | |
279 | return self->Add(info.window, pos, span, flag, border, data); | |
280 | else if ( info.sizer ) | |
281 | return self->Add(info.sizer, pos, span, flag, border, data); | |
282 | else if (info.gotSize) | |
283 | return self->Add(info.size.GetWidth(), info.size.GetHeight(), | |
284 | pos, span, flag, border, data); | |
dd9f7fea | 285 | return False; |
d14a1e28 RD |
286 | } |
287 | } | |
288 | ||
289 | %name(AddItem) bool Add( wxGBSizerItem *item ); | |
290 | ||
291 | ||
292 | // Get/Set the size used for cells in the grid with no item. | |
293 | wxSize GetEmptyCellSize() const; | |
294 | void SetEmptyCellSize(const wxSize& sz); | |
295 | ||
296 | // Get the grid position of the specified item | |
297 | %nokwargs GetItemPosition; | |
298 | wxGBPosition GetItemPosition(wxWindow *window); | |
299 | wxGBPosition GetItemPosition(wxSizer *sizer); | |
300 | wxGBPosition GetItemPosition(size_t index); | |
301 | ||
dd9f7fea | 302 | // Set the grid position of the specified item. Returns True on success. |
d14a1e28 | 303 | // If the move is not allowed (because an item is already there) then |
dd9f7fea | 304 | // False is returned. |
d14a1e28 RD |
305 | %nokwargs SetItemPosition; |
306 | bool SetItemPosition(wxWindow *window, const wxGBPosition& pos); | |
307 | bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos); | |
308 | bool SetItemPosition(size_t index, const wxGBPosition& pos); | |
309 | ||
310 | // Get the row/col spanning of the specified item | |
311 | %nokwargs GetItemSpan; | |
312 | wxGBSpan GetItemSpan(wxWindow *window); | |
313 | wxGBSpan GetItemSpan(wxSizer *sizer); | |
314 | wxGBSpan GetItemSpan(size_t index); | |
315 | ||
dd9f7fea | 316 | // Set the row/col spanning of the specified item. Returns True on |
d14a1e28 | 317 | // success. If the move is not allowed (because an item is already there) |
dd9f7fea | 318 | // then False is returned. |
d14a1e28 RD |
319 | %nokwargs SetItemSpan; |
320 | bool SetItemSpan(wxWindow *window, const wxGBSpan& span); | |
321 | bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span); | |
322 | bool SetItemSpan(size_t index, const wxGBSpan& span); | |
323 | ||
324 | ||
325 | // Find the sizer item for the given window or subsizer, returns NULL if | |
326 | // not found. (non-recursive) | |
327 | %nokwargs FindItem; | |
328 | wxGBSizerItem* FindItem(wxWindow* window); | |
329 | wxGBSizerItem* FindItem(wxSizer* sizer); | |
330 | ||
331 | ||
332 | // Return the sizer item for the given grid cell, or NULL if there is no | |
333 | // item at that position. (non-recursive) | |
334 | wxGBSizerItem* FindItemAtPosition(const wxGBPosition& pos); | |
335 | ||
336 | ||
dd9f7fea RD |
337 | // Return the sizer item located at the point given in pt, or NULL if |
338 | // there is no item at that point. The (x,y) coordinates in pt correspond | |
339 | // to the client coordinates of the window using the sizer for | |
340 | // layout. (non-recursive) | |
341 | wxGBSizerItem* FindItemAtPoint(const wxPoint& pt); | |
342 | ||
343 | ||
d14a1e28 RD |
344 | // Return the sizer item that has a matching user data (it only compares |
345 | // pointer values) or NULL if not found. (non-recursive) | |
346 | wxGBSizerItem* FindItemWithData(const wxObject* userData); | |
347 | ||
348 | ||
349 | // These are what make the sizer do size calculations and layout | |
350 | virtual void RecalcSizes(); | |
351 | virtual wxSize CalcMin(); | |
352 | ||
353 | ||
354 | // Look at all items and see if any intersect (or would overlap) the given | |
dd9f7fea | 355 | // item. Returns True if so, False if there would be no overlap. If an |
d14a1e28 RD |
356 | // excludeItem is given then it will not be checked for intersection, for |
357 | // example it may be the item we are checking the position of. | |
358 | %nokwargs CheckForIntersection; | |
359 | bool CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL); | |
360 | bool CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL); | |
361 | ||
362 | }; | |
363 | ||
364 | ||
365 | //--------------------------------------------------------------------------- |