]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_gbsizer.i
Added a note to self to look at adding ProvidesBackground in the future
[wxWidgets.git] / wxPython / src / _gbsizer.i
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 {
43 if (source == Py_None) {
44 **obj = wxGBPosition(-1,-1);
45 return true;
46 }
47 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBPosition"));
48 }
49
50 bool wxGBSpan_helper(PyObject* source, wxGBSpan** obj)
51 {
52 if (source == Py_None) {
53 **obj = wxGBSpan(-1,-1);
54 return true;
55 }
56 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBSpan"));
57 }
58
59 %}
60
61
62 //---------------------------------------------------------------------------
63 %newgroup;
64
65 DocStr(wxGBPosition,
66 "This class represents the position of an item in a virtual grid of
67 rows and columns managed by a `wx.GridBagSizer`. wxPython has
68 typemaps that will automatically convert from a 2-element sequence of
69 integers to a wx.GBPosition, so you can use the more pythonic
70 representation of the position nearly transparently in Python code.", "");
71
72 class wxGBPosition
73 {
74 public:
75 wxGBPosition(int row=0, int col=0);
76
77 int GetRow() const;
78 int GetCol() const;
79 void SetRow(int row);
80 void SetCol(int col);
81
82 // %extend {
83 // bool __eq__(const wxGBPosition* other) { return other ? (*self == *other) : false; }
84 // bool __ne__(const wxGBPosition* other) { return other ? (*self != *other) : true; }
85 // }
86
87 bool operator==(const wxGBPosition& other);
88 bool operator!=(const wxGBPosition& other);
89
90 %extend {
91 void Set(int row=0, int col=0) {
92 self->SetRow(row);
93 self->SetCol(col);
94 }
95
96 PyObject* Get() {
97 bool blocked = wxPyBeginBlockThreads();
98 PyObject* tup = PyTuple_New(2);
99 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
100 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
101 wxPyEndBlockThreads(blocked);
102 return tup;
103 }
104 }
105 %pythoncode {
106 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
107 def __str__(self): return str(self.Get())
108 def __repr__(self): return 'wx.GBPosition'+str(self.Get())
109 def __len__(self): return len(self.Get())
110 def __getitem__(self, index): return self.Get()[index]
111 def __setitem__(self, index, val):
112 if index == 0: self.SetRow(val)
113 elif index == 1: self.SetCol(val)
114 else: raise IndexError
115 def __nonzero__(self): return self.Get() != (0,0)
116 __safe_for_unpickling__ = True
117 def __reduce__(self): return (wx.GBPosition, self.Get())
118 }
119
120 %pythoncode {
121 row = property(GetRow, SetRow)
122 col = property(GetCol, SetCol)
123 }
124 };
125
126
127
128
129 DocStr(wxGBSpan,
130 "This class is used to hold the row and column spanning attributes of
131 items in a `wx.GridBagSizer`. wxPython has typemaps that will
132 automatically convert from a 2-element sequence of integers to a
133 wx.GBSpan, so you can use the more pythonic representation of the span
134 nearly transparently in Python code.
135 ", "");
136
137 class wxGBSpan
138 {
139 public:
140 DocCtorStr(
141 wxGBSpan(int rowspan=1, int colspan=1),
142 "Construct a new wxGBSpan, optionally setting the rowspan and
143 colspan. The default is (1,1). (Meaning that the item occupies one
144 cell in each direction.", "");
145
146 int GetRowspan() const;
147 int GetColspan() const;
148 void SetRowspan(int rowspan);
149 void SetColspan(int colspan);
150
151 // %extend {
152 // bool __eq__(const wxGBSpan* other) { return other ? (*self == *other) : false; }
153 // bool __ne__(const wxGBSpan* other) { return other ? (*self != *other) : true; }
154 // }
155 bool operator==(const wxGBSpan& other);
156 bool operator!=(const wxGBSpan& other);
157
158
159 %extend {
160 void Set(int rowspan=1, int colspan=1) {
161 self->SetRowspan(rowspan);
162 self->SetColspan(colspan);
163 }
164
165 PyObject* Get() {
166 bool blocked = wxPyBeginBlockThreads();
167 PyObject* tup = PyTuple_New(2);
168 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan()));
169 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan()));
170 wxPyEndBlockThreads(blocked);
171 return tup;
172 }
173 }
174 %pythoncode {
175 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
176 def __str__(self): return str(self.Get())
177 def __repr__(self): return 'wx.GBSpan'+str(self.Get())
178 def __len__(self): return len(self.Get())
179 def __getitem__(self, index): return self.Get()[index]
180 def __setitem__(self, index, val):
181 if index == 0: self.SetRowspan(val)
182 elif index == 1: self.SetColspan(val)
183 else: raise IndexError
184 def __nonzero__(self): return self.Get() != (0,0)
185 __safe_for_unpickling__ = True
186 def __reduce__(self): return (wx.GBSpan, self.Get())
187 }
188
189 %pythoncode {
190 rowspan = property(GetRowspan, SetRowspan)
191 colspan = property(GetColspan, SetColspan)
192 }
193 };
194
195
196 %immutable;
197 const wxGBSpan wxDefaultSpan;
198 %mutable;
199
200
201 //---------------------------------------------------------------------------
202
203
204 DocStr(wxGBSizerItem,
205 "The wx.GBSizerItem class is used to track the additional data about
206 items in a `wx.GridBagSizer` such as the item's position in the grid
207 and how many rows or columns it spans.
208 ", "");
209 class wxGBSizerItem : public wxSizerItem
210 {
211 public:
212 DocCtorStr(
213 wxGBSizerItem(),
214 "Constructs an empty wx.GBSizerItem. Either a window, sizer or spacer
215 size will need to be set, as well as a position and span before this
216 item can be used in a Sizer.
217
218 You will probably never need to create a wx.GBSizerItem directly as they
219 are created automatically when the sizer's Add method is called.", "");
220
221 %extend {
222 DocStr(wxGBSizerItem( wxWindow *window, const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
223 "Construct a `wx.GBSizerItem` for a window.", "");
224 %name(GBSizerItemWindow) wxGBSizerItem( wxWindow *window,
225 const wxGBPosition& pos,
226 const wxGBSpan& span,
227 int flag,
228 int border,
229 PyObject* userData=NULL )
230 {
231 wxPyUserData* data = NULL;
232 if ( userData ) {
233 bool blocked = wxPyBeginBlockThreads();
234 data = new wxPyUserData(userData);
235 wxPyEndBlockThreads(blocked);
236 }
237 return new wxGBSizerItem(window, pos, span, flag, border, data);
238 }
239
240
241 DocStr(wxGBSizerItem( wxSizer *sizer,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
242 "Construct a `wx.GBSizerItem` for a sizer", "");
243 %name(GBSizerItemSizer) wxGBSizerItem( wxSizer *sizer,
244 const wxGBPosition& pos,
245 const wxGBSpan& span,
246 int flag,
247 int border,
248 PyObject* userData=NULL )
249 {
250 wxPyUserData* data = NULL;
251 if ( userData ) {
252 bool blocked = wxPyBeginBlockThreads();
253 data = new wxPyUserData(userData);
254 wxPyEndBlockThreads(blocked);
255 }
256 return new wxGBSizerItem(sizer, pos, span, flag, border, data);
257 }
258
259
260 DocStr(wxGBSizerItem( int width,int height,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL),
261 "Construct a `wx.GBSizerItem` for a spacer.", "");
262 %name(GBSizerItemSpacer) wxGBSizerItem( int width,
263 int height,
264 const wxGBPosition& pos,
265 const wxGBSpan& span,
266 int flag,
267 int border,
268 PyObject* userData=NULL)
269 {
270 wxPyUserData* data = NULL;
271 if ( userData ) {
272 bool blocked = wxPyBeginBlockThreads();
273 data = new wxPyUserData(userData);
274 wxPyEndBlockThreads(blocked);
275 }
276 return new wxGBSizerItem(width, height, pos, span, flag, border, data);
277 }
278 }
279
280
281 DocDeclStr(
282 wxGBPosition , GetPos() const,
283 "Get the grid position of the item", "");
284
285 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
286
287
288
289 DocDeclStr(
290 wxGBSpan , GetSpan() const,
291 "Get the row and column spanning of the item", "");
292
293 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
294
295
296
297 DocDeclStr(
298 bool , SetPos( const wxGBPosition& pos ),
299 "If the item is already a member of a sizer then first ensure that
300 there is no other item that would intersect with this one at the new
301 position, then set the new position. Returns True if the change is
302 successful and after the next Layout() the item will be moved.", "");
303
304
305 DocDeclStr(
306 bool , SetSpan( const wxGBSpan& span ),
307 "If the item is already a member of a sizer then first ensure that
308 there is no other item that would intersect with this one with its new
309 spanning size, then set the new spanning. Returns True if the change
310 is successful and after the next Layout() the item will be resized.
311 ", "");
312
313
314
315 DocDeclStr(
316 bool , Intersects(const wxGBSizerItem& other),
317 "Returns True if this item and the other item instersect.", "");
318
319
320 DocDeclStrName(
321 bool , Intersects(const wxGBPosition& pos, const wxGBSpan& span),
322 "Returns True if the given pos/span would intersect with this item.", "",
323 IntersectsPos);
324
325
326 %extend {
327 DocStr(GetEndPos,
328 "Get the row and column of the endpoint of this item.", "");
329 wxGBPosition GetEndPos() {
330 int row, col;
331 self->GetEndPos(row, col);
332 return wxGBPosition(row, col);
333 }
334 }
335
336
337 DocDeclStr(
338 wxGridBagSizer* , GetGBSizer() const,
339 "Get the sizer this item is a member of.", "");
340
341 DocDeclStr(
342 void , SetGBSizer(wxGridBagSizer* sizer),
343 "Set the sizer this item is a member of.", "");
344
345 };
346
347
348 //---------------------------------------------------------------------------
349
350 DocStr(wxGridBagSizer,
351 "A `wx.Sizer` that can lay out items in a virtual grid like a
352 `wx.FlexGridSizer` but in this case explicit positioning of the items
353 is allowed using `wx.GBPosition`, and items can optionally span more
354 than one row and/or column using `wx.GBSpan`. The total size of the
355 virtual grid is determined by the largest row and column that items are
356 positioned at, adjusted for spanning.
357 ", "");
358
359 class wxGridBagSizer : public wxFlexGridSizer
360 {
361 public:
362 %pythonAppend wxGridBagSizer "self._setOORInfo(self)"
363
364 DocCtorStr(
365 wxGridBagSizer(int vgap = 0, int hgap = 0 ),
366 "Constructor, with optional parameters to specify the gap between the
367 rows and columns.", "");
368
369
370 %extend {
371 DocAStr(Add,
372 "Add(self, item, GBPosition pos, GBSpan span=DefaultSpan, int flag=0,
373 int border=0, userData=None) -> wx.GBSizerItem",
374
375 "Adds an item to the sizer at the grid cell *pos*, optionally spanning
376 more than one row or column as specified with *span*. The remaining
377 args behave similarly to `wx.Sizer.Add`.
378
379 Returns True if the item was successfully placed at the given cell
380 position, False if something was already there.
381 ", "");
382 wxGBSizerItem* Add( PyObject* item,
383 const wxGBPosition& pos,
384 const wxGBSpan& span = wxDefaultSpan,
385 int flag = 0,
386 int border = 0,
387 PyObject* userData = NULL ) {
388
389 wxPyUserData* data = NULL;
390 bool blocked = wxPyBeginBlockThreads();
391 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
392 if ( userData && (info.window || info.sizer || info.gotSize) )
393 data = new wxPyUserData(userData);
394 wxPyEndBlockThreads(blocked);
395
396 // Now call the real Add method if a valid item type was found
397 if ( info.window )
398 return (wxGBSizerItem*)self->Add(info.window, pos, span, flag, border, data);
399 else if ( info.sizer )
400 return (wxGBSizerItem*)self->Add(info.sizer, pos, span, flag, border, data);
401 else if (info.gotSize)
402 return (wxGBSizerItem*)self->Add(info.size.GetWidth(), info.size.GetHeight(),
403 pos, span, flag, border, data);
404 return NULL;
405 }
406 }
407
408 DocDeclAStrName(
409 wxGBSizerItem* , Add( wxGBSizerItem *item ),
410 "Add(self, GBSizerItem item) -> wx.GBSizerItem",
411 "Add an item to the sizer using a `wx.GBSizerItem`. Returns True if
412 the item was successfully placed at its given cell position, False if
413 something was already there.", "",
414 AddItem);
415
416 DocDeclStr(
417 wxSize , GetCellSize(int row, int col) const,
418 "Get the size of the specified cell, including hgap and
419 vgap. Only valid after a Layout.", "");
420
421 DocDeclStr(
422 wxSize , GetEmptyCellSize() const,
423 "Get the size used for cells in the grid with no item.", "");
424
425 DocDeclStr(
426 void , SetEmptyCellSize(const wxSize& sz),
427 "Set the size used for cells in the grid with no item.", "");
428
429
430
431 %nokwargs GetItemPosition;
432 %noautodoc GetItemPosition;
433 DocStr(GetItemPosition,
434 "GetItemPosition(self, item) -> GBPosition
435
436 Get the grid position of the specified *item* where *item* is either a
437 window or subsizer that is a member of this sizer, or a zero-based
438 index of an item.", "");
439 wxGBPosition GetItemPosition(wxWindow *window);
440 wxGBPosition GetItemPosition(wxSizer *sizer);
441 wxGBPosition GetItemPosition(size_t index);
442
443
444 %nokwargs SetItemPosition;
445 %noautodoc SetItemPosition;
446 DocStr(SetItemPosition,
447 "SetItemPosition(self, item, GBPosition pos) -> bool
448
449 Set the grid position of the specified *item* where *item* is either a
450 window or subsizer that is a member of this sizer, or a zero-based
451 index of an item. Returns True on success. If the move is not
452 allowed (because an item is already there) then False is returned.
453 ", "");
454 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
455 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
456 bool SetItemPosition(size_t index, const wxGBPosition& pos);
457
458
459
460 %nokwargs GetItemSpan;
461 %noautodoc GetItemSpan;
462 DocStr(GetItemSpan,
463 "GetItemSpan(self, item) -> GBSpan
464
465 Get the row/col spanning of the specified *item* where *item* is
466 either a window or subsizer that is a member of this sizer, or a
467 zero-based index of an item.", "");
468 wxGBSpan GetItemSpan(wxWindow *window);
469 wxGBSpan GetItemSpan(wxSizer *sizer);
470 wxGBSpan GetItemSpan(size_t index);
471
472
473
474 %nokwargs SetItemSpan;
475 %noautodoc SetItemSpan;
476 DocStr(SetItemSpan,
477 "SetItemSpan(self, item, GBSpan span) -> bool
478
479 Set the row/col spanning of the specified *item* where *item* is
480 either a window or subsizer that is a member of this sizer, or a
481 zero-based index of an item. Returns True on success. If the move is
482 not allowed (because an item is already there) then False is returned.", "");
483 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
484 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
485 bool SetItemSpan(size_t index, const wxGBSpan& span);
486
487
488
489 %nokwargs FindItem;
490 %noautodoc FindItem;
491 DocStr(FindItem,
492 "FindItem(self, item) -> GBSizerItem
493
494 Find the sizer item for the given window or subsizer, returns None if
495 not found. (non-recursive)", "");
496 wxGBSizerItem* FindItem(wxWindow* window);
497 wxGBSizerItem* FindItem(wxSizer* sizer);
498
499
500 DocDeclStr(
501 wxGBSizerItem* , FindItemAtPosition(const wxGBPosition& pos),
502 "Return the sizer item for the given grid cell, or None if there is no
503 item at that position. (non-recursive)", "");
504
505
506
507 DocDeclStr(
508 wxGBSizerItem* , FindItemAtPoint(const wxPoint& pt),
509 "Return the sizer item located at the point given in *pt*, or None if
510 there is no item at that point. The (x,y) coordinates in pt correspond
511 to the client coordinates of the window using the sizer for
512 layout. (non-recursive)", "");
513
514
515
516 // DocDeclStr(
517 // wxGBSizerItem* , FindItemWithData(const wxObject* userData),
518 // "Return the sizer item that has a matching user data (it only compares
519 // pointer values) or None if not found. (non-recursive)", "");
520
521
522
523 // Look at all items and see if any intersect (or would overlap) the given
524 // item. Returns True if so, False if there would be no overlap. If an
525 // excludeItem is given then it will not be checked for intersection, for
526 // example it may be the item we are checking the position of.
527
528
529 DocDeclStr(
530 bool , CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL),
531 "Look at all items and see if any intersect (or would overlap) the
532 given *item*. Returns True if so, False if there would be no overlap.
533 If an *excludeItem* is given then it will not be checked for
534 intersection, for example it may be the item we are checking the
535 position of.
536 ", "");
537
538 DocDeclStrName(
539 bool , CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL),
540 "Look at all items and see if any intersect (or would overlap) the
541 given position and span. Returns True if so, False if there would be
542 no overlap. If an *excludeItem* is given then it will not be checked
543 for intersection, for example it may be the item we are checking the
544 position of.", "",
545 CheckForIntersectionPos);
546
547
548 };
549
550
551 //---------------------------------------------------------------------------