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);
84 // bool __eq__(const wxGBPosition* other) { return other ? (*self == *other) : false; }
85 // bool __ne__(const wxGBPosition* other) { return other ? (*self != *other) : true; }
88 bool operator==(const wxGBPosition& other);
89 bool operator!=(const wxGBPosition& other);
92 void Set(int row=0, int col=0) {
98 wxPyBlock_t blocked = wxPyBeginBlockThreads();
99 PyObject* tup = PyTuple_New(2);
100 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRow()));
101 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetCol()));
102 wxPyEndBlockThreads(blocked);
107 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
108 def __str__(self): return str(self.Get())
109 def __repr__(self): return 'wx.GBPosition'+str(self.Get())
110 def __len__(self): return len(self.Get())
111 def __getitem__(self, index): return self.Get()[index]
112 def __setitem__(self, index, val):
113 if index == 0: self.SetRow(val)
114 elif index == 1: self.SetCol(val)
115 else: raise IndexError
116 def __nonzero__(self): return self.Get() != (0,0)
117 __safe_for_unpickling__ = True
118 def __reduce__(self): return (wx.GBPosition, self.Get())
122 row = property(GetRow, SetRow)
123 col = property(GetCol, SetCol)
131 "This class is used to hold the row and column spanning attributes of
132 items in a `wx.GridBagSizer`. wxPython has typemaps that will
133 automatically convert from a 2-element sequence of integers to a
134 wx.GBSpan, so you can use the more pythonic representation of the span
135 nearly transparently in Python code.
142 wxGBSpan(int rowspan=1, int colspan=1),
143 "Construct a new wxGBSpan, optionally setting the rowspan and
144 colspan. The default is (1,1). (Meaning that the item occupies one
145 cell in each direction.", "");
149 int GetRowspan() const;
150 int GetColspan() const;
151 void SetRowspan(int rowspan);
152 void SetColspan(int colspan);
155 // bool __eq__(const wxGBSpan* other) { return other ? (*self == *other) : false; }
156 // bool __ne__(const wxGBSpan* other) { return other ? (*self != *other) : true; }
158 bool operator==(const wxGBSpan& other);
159 bool operator!=(const wxGBSpan& other);
163 void Set(int rowspan=1, int colspan=1) {
164 self->SetRowspan(rowspan);
165 self->SetColspan(colspan);
169 wxPyBlock_t blocked = wxPyBeginBlockThreads();
170 PyObject* tup = PyTuple_New(2);
171 PyTuple_SET_ITEM(tup, 0, PyInt_FromLong(self->GetRowspan()));
172 PyTuple_SET_ITEM(tup, 1, PyInt_FromLong(self->GetColspan()));
173 wxPyEndBlockThreads(blocked);
178 asTuple = wx._deprecated(Get, "asTuple is deprecated, use `Get` instead")
179 def __str__(self): return str(self.Get())
180 def __repr__(self): return 'wx.GBSpan'+str(self.Get())
181 def __len__(self): return len(self.Get())
182 def __getitem__(self, index): return self.Get()[index]
183 def __setitem__(self, index, val):
184 if index == 0: self.SetRowspan(val)
185 elif index == 1: self.SetColspan(val)
186 else: raise IndexError
187 def __nonzero__(self): return self.Get() != (0,0)
188 __safe_for_unpickling__ = True
189 def __reduce__(self): return (wx.GBSpan, self.Get())
193 rowspan = property(GetRowspan, SetRowspan)
194 colspan = property(GetColspan, SetColspan)
200 const wxGBSpan wxDefaultSpan;
204 //---------------------------------------------------------------------------
207 DocStr(wxGBSizerItem,
208 "The wx.GBSizerItem class is used to track the additional data about
209 items in a `wx.GridBagSizer` such as the item's position in the grid
210 and how many rows or columns it spans.
212 class wxGBSizerItem : public wxSizerItem
217 "Constructs an empty wx.GBSizerItem. Either a window, sizer or spacer
218 size will need to be set, as well as a position and span before this
219 item can be used in a Sizer.
221 You will probably never need to create a wx.GBSizerItem directly as they
222 are created automatically when the sizer's Add method is called.", "");
228 DocStr(wxGBSizerItem( wxWindow *window, const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
229 "Construct a `wx.GBSizerItem` for a window.", "");
231 %RenameCtor(GBSizerItemWindow, wxGBSizerItem( wxWindow *window,
232 const wxGBPosition& pos,
233 const wxGBSpan& span,
236 PyObject* userData=NULL ))
238 wxPyUserData* data = NULL;
240 wxPyBlock_t blocked = wxPyBeginBlockThreads();
241 data = new wxPyUserData(userData);
242 wxPyEndBlockThreads(blocked);
244 return new wxGBSizerItem(window, pos, span, flag, border, data);
248 DocStr(wxGBSizerItem( wxSizer *sizer,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
249 "Construct a `wx.GBSizerItem` for a sizer", "");
250 %disownarg( wxSizer *sizer );
251 %RenameCtor(GBSizerItemSizer, wxGBSizerItem( wxSizer *sizer,
252 const wxGBPosition& pos,
253 const wxGBSpan& span,
256 PyObject* userData=NULL ))
258 wxPyUserData* data = NULL;
260 wxPyBlock_t blocked = wxPyBeginBlockThreads();
261 data = new wxPyUserData(userData);
262 wxPyEndBlockThreads(blocked);
264 return new wxGBSizerItem(sizer, pos, span, flag, border, data);
266 %cleardisown( wxSizer *sizer );
269 DocStr(wxGBSizerItem( int width,int height,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL),
270 "Construct a `wx.GBSizerItem` for a spacer.", "");
271 %RenameCtor(GBSizerItemSpacer, wxGBSizerItem( int width,
273 const wxGBPosition& pos,
274 const wxGBSpan& span,
277 PyObject* userData=NULL))
279 wxPyUserData* data = NULL;
281 wxPyBlock_t blocked = wxPyBeginBlockThreads();
282 data = new wxPyUserData(userData);
283 wxPyEndBlockThreads(blocked);
285 return new wxGBSizerItem(width, height, pos, span, flag, border, data);
291 wxGBPosition , GetPos() const,
292 "Get the grid position of the item", "");
294 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
299 wxGBSpan , GetSpan() const,
300 "Get the row and column spanning of the item", "");
302 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
307 bool , SetPos( const wxGBPosition& pos ),
308 "If the item is already a member of a sizer then first ensure that
309 there is no other item that would intersect with this one at the new
310 position, then set the new position. Returns True if the change is
311 successful and after the next Layout() the item will be moved.", "");
315 bool , SetSpan( const wxGBSpan& span ),
316 "If the item is already a member of a sizer then first ensure that
317 there is no other item that would intersect with this one with its new
318 spanning size, then set the new spanning. Returns True if the change
319 is successful and after the next Layout() the item will be resized.
325 bool , Intersects(const wxGBSizerItem& other),
326 "Returns True if this item and the other item instersect.", "");
330 bool , Intersects(const wxGBPosition& pos, const wxGBSpan& span),
331 "Returns True if the given pos/span would intersect with this item.", "",
337 "Get the row and column of the endpoint of this item.", "");
338 wxGBPosition GetEndPos() {
340 self->GetEndPos(row, col);
341 return wxGBPosition(row, col);
347 wxGridBagSizer* , GetGBSizer() const,
348 "Get the sizer this item is a member of.", "");
351 void , SetGBSizer(wxGridBagSizer* sizer),
352 "Set the sizer this item is a member of.", "");
357 //---------------------------------------------------------------------------
359 DocStr(wxGridBagSizer,
360 "A `wx.Sizer` that can lay out items in a virtual grid like a
361 `wx.FlexGridSizer` but in this case explicit positioning of the items
362 is allowed using `wx.GBPosition`, and items can optionally span more
363 than one row and/or column using `wx.GBSpan`. The total size of the
364 virtual grid is determined by the largest row and column that items are
365 positioned at, adjusted for spanning.
368 class wxGridBagSizer : public wxFlexGridSizer
371 %pythonAppend wxGridBagSizer "self._setOORInfo(self)"
374 wxGridBagSizer(int vgap = 0, int hgap = 0 ),
375 "Constructor, with optional parameters to specify the gap between the
376 rows and columns.", "");
381 "Add(self, item, GBPosition pos, GBSpan span=DefaultSpan, int flag=0,
382 int border=0, userData=None) -> wx.GBSizerItem",
384 "Adds an item to the sizer at the grid cell *pos*, optionally spanning
385 more than one row or column as specified with *span*. The remaining
386 args behave similarly to `wx.Sizer.Add`.
388 Returns True if the item was successfully placed at the given cell
389 position, False if something was already there.
391 wxGBSizerItem* Add( PyObject* item,
392 const wxGBPosition& pos,
393 const wxGBSpan& span = wxDefaultSpan,
396 PyObject* userData = NULL ) {
398 wxPyUserData* data = NULL;
399 wxPyBlock_t blocked = wxPyBeginBlockThreads();
400 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
401 if ( userData && (info.window || info.sizer || info.gotSize) )
402 data = new wxPyUserData(userData);
404 PyObject_SetAttrString(item,"thisown",Py_False);
405 wxPyEndBlockThreads(blocked);
407 // Now call the real Add method if a valid item type was found
409 return (wxGBSizerItem*)self->Add(info.window, pos, span, flag, border, data);
410 else if ( info.sizer )
411 return (wxGBSizerItem*)self->Add(info.sizer, pos, span, flag, border, data);
412 else if (info.gotSize)
413 return (wxGBSizerItem*)self->Add(info.size.GetWidth(), info.size.GetHeight(),
414 pos, span, flag, border, data);
419 %disownarg( wxGBSizerItem *item );
421 wxGBSizerItem* , Add( wxGBSizerItem *item ),
422 "Add(self, GBSizerItem item) -> wx.GBSizerItem",
423 "Add an item to the sizer using a `wx.GBSizerItem`. Returns True if
424 the item was successfully placed at its given cell position, False if
425 something was already there.", "",
427 %cleardisown( wxGBSizerItem *item );
430 wxSize , GetCellSize(int row, int col) const,
431 "Get the size of the specified cell, including hgap and
432 vgap. Only valid after a Layout.", "");
435 wxSize , GetEmptyCellSize() const,
436 "Get the size used for cells in the grid with no item.", "");
439 void , SetEmptyCellSize(const wxSize& sz),
440 "Set the size used for cells in the grid with no item.", "");
444 %nokwargs GetItemPosition;
445 %noautodoc GetItemPosition;
446 DocStr(GetItemPosition,
447 "GetItemPosition(self, item) -> GBPosition
449 Get 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.", "");
452 wxGBPosition GetItemPosition(wxWindow *window);
453 wxGBPosition GetItemPosition(wxSizer *sizer);
454 wxGBPosition GetItemPosition(size_t index);
457 %nokwargs SetItemPosition;
458 %noautodoc SetItemPosition;
459 DocStr(SetItemPosition,
460 "SetItemPosition(self, item, GBPosition pos) -> bool
462 Set the grid position of the specified *item* where *item* is either a
463 window or subsizer that is a member of this sizer, or a zero-based
464 index of an item. Returns True on success. If the move is not
465 allowed (because an item is already there) then False is returned.
467 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
468 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
469 bool SetItemPosition(size_t index, const wxGBPosition& pos);
473 %nokwargs GetItemSpan;
474 %noautodoc GetItemSpan;
476 "GetItemSpan(self, item) -> GBSpan
478 Get the row/col spanning of the specified *item* where *item* is
479 either a window or subsizer that is a member of this sizer, or a
480 zero-based index of an item.", "");
481 wxGBSpan GetItemSpan(wxWindow *window);
482 wxGBSpan GetItemSpan(wxSizer *sizer);
483 wxGBSpan GetItemSpan(size_t index);
487 %nokwargs SetItemSpan;
488 %noautodoc SetItemSpan;
490 "SetItemSpan(self, item, GBSpan span) -> bool
492 Set the row/col spanning of the specified *item* where *item* is
493 either a window or subsizer that is a member of this sizer, or a
494 zero-based index of an item. Returns True on success. If the move is
495 not allowed (because an item is already there) then False is returned.", "");
496 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
497 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
498 bool SetItemSpan(size_t index, const wxGBSpan& span);
505 "FindItem(self, item) -> GBSizerItem
507 Find the sizer item for the given window or subsizer, returns None if
508 not found. (non-recursive)", "");
509 wxGBSizerItem* FindItem(wxWindow* window);
510 wxGBSizerItem* FindItem(wxSizer* sizer);
514 wxGBSizerItem* , FindItemAtPosition(const wxGBPosition& pos),
515 "Return the sizer item for the given grid cell, or None if there is no
516 item at that position. (non-recursive)", "");
521 wxGBSizerItem* , FindItemAtPoint(const wxPoint& pt),
522 "Return the sizer item located at the point given in *pt*, or None if
523 there is no item at that point. The (x,y) coordinates in pt correspond
524 to the client coordinates of the window using the sizer for
525 layout. (non-recursive)", "");
530 // wxGBSizerItem* , FindItemWithData(const wxObject* userData),
531 // "Return the sizer item that has a matching user data (it only compares
532 // pointer values) or None if not found. (non-recursive)", "");
536 // Look at all items and see if any intersect (or would overlap) the given
537 // item. Returns True if so, False if there would be no overlap. If an
538 // excludeItem is given then it will not be checked for intersection, for
539 // example it may be the item we are checking the position of.
543 bool , CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL),
544 "Look at all items and see if any intersect (or would overlap) the
545 given *item*. Returns True if so, False if there would be no overlap.
546 If an *excludeItem* is given then it will not be checked for
547 intersection, for example it may be the item we are checking the
552 bool , CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL),
553 "Look at all items and see if any intersect (or would overlap) the
554 given position and span. Returns True if so, False if there would be
555 no overlap. If an *excludeItem* is given then it will not be checked
556 for intersection, for example it may be the item we are checking the
558 CheckForIntersectionPos);
564 //---------------------------------------------------------------------------