1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface stuff for wxGBGridBagSizer and etc.
7 // Created: 05-Nov-2003
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
23 %typemap(in) wxGBPosition& (wxGBPosition temp) {
25 if ( ! wxGBPosition_helper($input, &$1)) SWIG_fail;
27 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBPosition& {
28 $1 = wxPySimple_typecheck($input, wxT("wxGBPosition"), 2);
31 %typemap(in) wxGBSpan& (wxGBSpan temp) {
33 if ( ! wxGBSpan_helper($input, &$1)) SWIG_fail;
35 %typemap(typecheck, precedence=SWIG_TYPECHECK_POINTER) wxGBSpan& {
36 $1 = wxPySimple_typecheck($input, wxT("wxGBSpan"), 2);
41 bool wxGBPosition_helper(PyObject* source, wxGBPosition** obj)
43 if (source == Py_None) {
44 **obj = wxGBPosition(-1,-1);
47 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBPosition"));
50 bool wxGBSpan_helper(PyObject* source, wxGBSpan** obj)
52 if (source == Py_None) {
53 **obj = wxGBSpan(-1,-1);
56 return wxPyTwoIntItem_helper(source, obj, wxT("wxGBSpan"));
62 //---------------------------------------------------------------------------
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.", "");
75 wxGBPosition(int row=0, int col=0);
86 DocStr(__eq__, "Compare GBPosition for equality.", "");
87 bool __eq__(PyObject* other) {
88 wxGBPosition temp, *obj = &temp;
89 if ( other == Py_None ) return false;
90 if ( ! wxGBPosition_helper(other, &obj) ) {
94 return self->operator==(*obj);
99 DocStr(__ne__, "Compare GBPosition for inequality.", "");
100 bool __ne__(PyObject* other) {
101 wxGBPosition temp, *obj = &temp;
102 if ( other == Py_None ) return true;
103 if ( ! wxGBPosition_helper(other, &obj)) {
107 return self->operator!=(*obj);
113 void Set(int row=0, int col=0) {
119 wxPyBlock_t blocked = wxPyBeginBlockThreads();
120 PyObject* tup = PyTuple_New(2);
121 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
122 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
123 wxPyEndBlockThreads(blocked);
128 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
129 def __str__(self): return str(self.Get())
130 def __repr__(self): return 'wx.GBPosition'+str(self.Get())
131 def __len__(self): return len(self.Get())
132 def __getitem__(self, index): return self.Get()[index]
133 def __setitem__(self, index, val):
134 if index == 0: self.SetRow(val)
135 elif index == 1: self.SetCol(val)
136 else: raise IndexError
137 def __nonzero__(self): return self.Get() != (0,0)
138 __safe_for_unpickling__ = True
139 def __reduce__(self): return (wx.GBPosition, self.Get())
143 row = property(GetRow, SetRow)
144 col = property(GetCol, SetCol)
152 "This class is used to hold the row and column spanning attributes of
153 items in a `wx.GridBagSizer`. wxPython has typemaps that will
154 automatically convert from a 2-element sequence of integers to a
155 wx.GBSpan, so you can use the more pythonic representation of the span
156 nearly transparently in Python code.
163 wxGBSpan(int rowspan=1, int colspan=1),
164 "Construct a new wxGBSpan, optionally setting the rowspan and
165 colspan. The default is (1,1). (Meaning that the item occupies one
166 cell in each direction.", "");
170 int GetRowspan() const;
171 int GetColspan() const;
172 void SetRowspan(int rowspan);
173 void SetColspan(int colspan);
178 DocStr(__eq__, "Compare wxGBSpan for equality.", "");
179 bool __eq__(PyObject* other) {
180 wxGBSpan temp, *obj = &temp;
181 if ( other == Py_None ) return false;
182 if ( ! wxGBSpan_helper(other, &obj) ) {
186 return self->operator==(*obj);
191 DocStr(__ne__, "Compare GBSpan for inequality.", "");
192 bool __ne__(PyObject* other) {
193 wxGBSpan temp, *obj = &temp;
194 if ( other == Py_None ) return true;
195 if ( ! wxGBSpan_helper(other, &obj)) {
199 return self->operator!=(*obj);
205 void Set(int rowspan=1, int colspan=1) {
206 self->SetRowspan(rowspan);
207 self->SetColspan(colspan);
211 wxPyBlock_t blocked = wxPyBeginBlockThreads();
212 PyObject* tup = PyTuple_New(2);
213 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan()));
214 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan()));
215 wxPyEndBlockThreads(blocked);
220 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
221 def __str__(self): return str(self.Get())
222 def __repr__(self): return 'wx.GBSpan'+str(self.Get())
223 def __len__(self): return len(self.Get())
224 def __getitem__(self, index): return self.Get()[index]
225 def __setitem__(self, index, val):
226 if index == 0: self.SetRowspan(val)
227 elif index == 1: self.SetColspan(val)
228 else: raise IndexError
229 def __nonzero__(self): return self.Get() != (0,0)
230 __safe_for_unpickling__ = True
231 def __reduce__(self): return (wx.GBSpan, self.Get())
235 rowspan = property(GetRowspan, SetRowspan)
236 colspan = property(GetColspan, SetColspan)
242 const wxGBSpan wxDefaultSpan;
246 //---------------------------------------------------------------------------
249 DocStr(wxGBSizerItem,
250 "The wx.GBSizerItem class is used to track the additional data about
251 items in a `wx.GridBagSizer` such as the item's position in the grid
252 and how many rows or columns it spans.
254 class wxGBSizerItem : public wxSizerItem
259 "Constructs an empty wx.GBSizerItem. Either a window, sizer or spacer
260 size will need to be set, as well as a position and span before this
261 item can be used in a Sizer.
263 You will probably never need to create a wx.GBSizerItem directly as they
264 are created automatically when the sizer's Add method is called.", "");
270 DocStr(wxGBSizerItem( wxWindow *window, const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
271 "Construct a `wx.GBSizerItem` for a window.", "");
273 %RenameCtor(GBSizerItemWindow, wxGBSizerItem( wxWindow *window,
274 const wxGBPosition& pos,
275 const wxGBSpan& span,
278 PyObject* userData=NULL ))
280 wxPyUserData* data = NULL;
282 wxPyBlock_t blocked = wxPyBeginBlockThreads();
283 data = new wxPyUserData(userData);
284 wxPyEndBlockThreads(blocked);
286 return new wxGBSizerItem(window, pos, span, flag, border, data);
290 DocStr(wxGBSizerItem( wxSizer *sizer,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
291 "Construct a `wx.GBSizerItem` for a sizer", "");
292 %disownarg( wxSizer *sizer );
293 %RenameCtor(GBSizerItemSizer, wxGBSizerItem( wxSizer *sizer,
294 const wxGBPosition& pos,
295 const wxGBSpan& span,
298 PyObject* userData=NULL ))
300 wxPyUserData* data = NULL;
302 wxPyBlock_t blocked = wxPyBeginBlockThreads();
303 data = new wxPyUserData(userData);
304 wxPyEndBlockThreads(blocked);
306 return new wxGBSizerItem(sizer, pos, span, flag, border, data);
308 %cleardisown( wxSizer *sizer );
311 DocStr(wxGBSizerItem( int width,int height,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL),
312 "Construct a `wx.GBSizerItem` for a spacer.", "");
313 %RenameCtor(GBSizerItemSpacer, wxGBSizerItem( int width,
315 const wxGBPosition& pos,
316 const wxGBSpan& span,
319 PyObject* userData=NULL))
321 wxPyUserData* data = NULL;
323 wxPyBlock_t blocked = wxPyBeginBlockThreads();
324 data = new wxPyUserData(userData);
325 wxPyEndBlockThreads(blocked);
327 return new wxGBSizerItem(width, height, pos, span, flag, border, data);
333 wxGBPosition , GetPos() const,
334 "Get the grid position of the item", "");
336 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
341 wxGBSpan , GetSpan() const,
342 "Get the row and column spanning of the item", "");
344 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
349 bool , SetPos( const wxGBPosition& pos ),
350 "If the item is already a member of a sizer then first ensure that
351 there is no other item that would intersect with this one at the new
352 position, then set the new position. Returns True if the change is
353 successful and after the next Layout() the item will be moved.", "");
357 bool , SetSpan( const wxGBSpan& span ),
358 "If the item is already a member of a sizer then first ensure that
359 there is no other item that would intersect with this one with its new
360 spanning size, then set the new spanning. Returns True if the change
361 is successful and after the next Layout() the item will be resized.
367 bool , Intersects(const wxGBSizerItem& other),
368 "Returns True if this item and the other item instersect.", "");
372 bool , Intersects(const wxGBPosition& pos, const wxGBSpan& span),
373 "Returns True if the given pos/span would intersect with this item.", "",
379 "Get the row and column of the endpoint of this item.", "");
380 wxGBPosition GetEndPos() {
382 self->GetEndPos(row, col);
383 return wxGBPosition(row, col);
389 wxGridBagSizer* , GetGBSizer() const,
390 "Get the sizer this item is a member of.", "");
393 void , SetGBSizer(wxGridBagSizer* sizer),
394 "Set the sizer this item is a member of.", "");
399 //---------------------------------------------------------------------------
401 DocStr(wxGridBagSizer,
402 "A `wx.Sizer` that can lay out items in a virtual grid like a
403 `wx.FlexGridSizer` but in this case explicit positioning of the items
404 is allowed using `wx.GBPosition`, and items can optionally span more
405 than one row and/or column using `wx.GBSpan`. The total size of the
406 virtual grid is determined by the largest row and column that items are
407 positioned at, adjusted for spanning.
410 class wxGridBagSizer : public wxFlexGridSizer
413 %pythonAppend wxGridBagSizer "self._setOORInfo(self)"
416 wxGridBagSizer(int vgap = 0, int hgap = 0 ),
417 "Constructor, with optional parameters to specify the gap between the
418 rows and columns.", "");
423 "Add(self, item, GBPosition pos, GBSpan span=DefaultSpan, int flag=0,
424 int border=0, userData=None) -> wx.GBSizerItem",
426 "Adds an item to the sizer at the grid cell *pos*, optionally spanning
427 more than one row or column as specified with *span*. The remaining
428 args behave similarly to `wx.Sizer.Add`.
430 Returns True if the item was successfully placed at the given cell
431 position, False if something was already there.
433 wxGBSizerItem* Add( PyObject* item,
434 const wxGBPosition& pos,
435 const wxGBSpan& span = wxDefaultSpan,
438 PyObject* userData = NULL ) {
440 wxPyUserData* data = NULL;
441 wxPyBlock_t blocked = wxPyBeginBlockThreads();
442 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
443 if ( userData && (info.window || info.sizer || info.gotSize) )
444 data = new wxPyUserData(userData);
446 PyObject_SetAttrString(item,"thisown",Py_False);
447 wxPyEndBlockThreads(blocked);
449 // Now call the real Add method if a valid item type was found
451 return (wxGBSizerItem*)self->Add(info.window, pos, span, flag, border, data);
452 else if ( info.sizer )
453 return (wxGBSizerItem*)self->Add(info.sizer, pos, span, flag, border, data);
454 else if (info.gotSize)
455 return (wxGBSizerItem*)self->Add(info.size.GetWidth(), info.size.GetHeight(),
456 pos, span, flag, border, data);
461 %disownarg( wxGBSizerItem *item );
463 wxGBSizerItem* , Add( wxGBSizerItem *item ),
464 "Add(self, GBSizerItem item) -> wx.GBSizerItem",
465 "Add an item to the sizer using a `wx.GBSizerItem`. Returns True if
466 the item was successfully placed at its given cell position, False if
467 something was already there.", "",
469 %cleardisown( wxGBSizerItem *item );
472 wxSize , GetCellSize(int row, int col) const,
473 "Get the size of the specified cell, including hgap and
474 vgap. Only valid after a Layout.", "");
477 wxSize , GetEmptyCellSize() const,
478 "Get the size used for cells in the grid with no item.", "");
481 void , SetEmptyCellSize(const wxSize& sz),
482 "Set the size used for cells in the grid with no item.", "");
486 %nokwargs GetItemPosition;
487 %noautodoc GetItemPosition;
488 DocStr(GetItemPosition,
489 "GetItemPosition(self, item) -> GBPosition
491 Get the grid position of the specified *item* where *item* is either a
492 window or subsizer that is a member of this sizer, or a zero-based
493 index of an item.", "");
494 wxGBPosition GetItemPosition(wxWindow *window);
495 wxGBPosition GetItemPosition(wxSizer *sizer);
496 wxGBPosition GetItemPosition(size_t index);
499 %nokwargs SetItemPosition;
500 %noautodoc SetItemPosition;
501 DocStr(SetItemPosition,
502 "SetItemPosition(self, item, GBPosition pos) -> bool
504 Set the grid position of the specified *item* where *item* is either a
505 window or subsizer that is a member of this sizer, or a zero-based
506 index of an item. Returns True on success. If the move is not
507 allowed (because an item is already there) then False is returned.
509 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
510 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
511 bool SetItemPosition(size_t index, const wxGBPosition& pos);
515 %nokwargs GetItemSpan;
516 %noautodoc GetItemSpan;
518 "GetItemSpan(self, item) -> GBSpan
520 Get the row/col spanning of the specified *item* where *item* is
521 either a window or subsizer that is a member of this sizer, or a
522 zero-based index of an item.", "");
523 wxGBSpan GetItemSpan(wxWindow *window);
524 wxGBSpan GetItemSpan(wxSizer *sizer);
525 wxGBSpan GetItemSpan(size_t index);
529 %nokwargs SetItemSpan;
530 %noautodoc SetItemSpan;
532 "SetItemSpan(self, item, GBSpan span) -> bool
534 Set the row/col spanning of the specified *item* where *item* is
535 either a window or subsizer that is a member of this sizer, or a
536 zero-based index of an item. Returns True on success. If the move is
537 not allowed (because an item is already there) then False is returned.", "");
538 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
539 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
540 bool SetItemSpan(size_t index, const wxGBSpan& span);
547 "FindItem(self, item) -> GBSizerItem
549 Find the sizer item for the given window or subsizer, returns None if
550 not found. (non-recursive)", "");
551 wxGBSizerItem* FindItem(wxWindow* window);
552 wxGBSizerItem* FindItem(wxSizer* sizer);
556 wxGBSizerItem* , FindItemAtPosition(const wxGBPosition& pos),
557 "Return the sizer item for the given grid cell, or None if there is no
558 item at that position. (non-recursive)", "");
563 wxGBSizerItem* , FindItemAtPoint(const wxPoint& pt),
564 "Return the sizer item located at the point given in *pt*, or None if
565 there is no item at that point. The (x,y) coordinates in pt correspond
566 to the client coordinates of the window using the sizer for
567 layout. (non-recursive)", "");
572 // wxGBSizerItem* , FindItemWithData(const wxObject* userData),
573 // "Return the sizer item that has a matching user data (it only compares
574 // pointer values) or None if not found. (non-recursive)", "");
578 // Look at all items and see if any intersect (or would overlap) the given
579 // item. Returns True if so, False if there would be no overlap. If an
580 // excludeItem is given then it will not be checked for intersection, for
581 // example it may be the item we are checking the position of.
585 bool , CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL),
586 "Look at all items and see if any intersect (or would overlap) the
587 given *item*. Returns True if so, False if there would be no overlap.
588 If an *excludeItem* is given then it will not be checked for
589 intersection, for example it may be the item we are checking the
594 bool , CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL),
595 "Look at all items and see if any intersect (or would overlap) the
596 given position and span. Returns True if so, False if there would be
597 no overlap. If an *excludeItem* is given then it will not be checked
598 for intersection, for example it may be the item we are checking the
600 CheckForIntersectionPos);
606 //---------------------------------------------------------------------------