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);
83 // bool __eq__(const wxGBPosition* other) { return other ? (*self == *other) : false; }
84 // bool __ne__(const wxGBPosition* other) { return other ? (*self != *other) : true; }
87 bool operator==(const wxGBPosition& other);
88 bool operator!=(const wxGBPosition& other);
91 void Set(int row=0, int col=0) {
97 wxPyBlock_t 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);
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())
121 row = property(GetRow, SetRow)
122 col = property(GetCol, SetCol)
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.
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.", "");
146 int GetRowspan() const;
147 int GetColspan() const;
148 void SetRowspan(int rowspan);
149 void SetColspan(int colspan);
152 // bool __eq__(const wxGBSpan* other) { return other ? (*self == *other) : false; }
153 // bool __ne__(const wxGBSpan* other) { return other ? (*self != *other) : true; }
155 bool operator==(const wxGBSpan& other);
156 bool operator!=(const wxGBSpan& other);
160 void Set(int rowspan=1, int colspan=1) {
161 self->SetRowspan(rowspan);
162 self->SetColspan(colspan);
166 wxPyBlock_t 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);
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())
190 rowspan = property(GetRowspan, SetRowspan)
191 colspan = property(GetColspan, SetColspan)
197 const wxGBSpan wxDefaultSpan;
201 //---------------------------------------------------------------------------
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.
209 class wxGBSizerItem : public wxSizerItem
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.
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.", "");
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.", "");
225 %RenameCtor(GBSizerItemWindow, wxGBSizerItem( wxWindow *window,
226 const wxGBPosition& pos,
227 const wxGBSpan& span,
230 PyObject* userData=NULL ))
232 wxPyUserData* data = NULL;
234 wxPyBlock_t blocked = wxPyBeginBlockThreads();
235 data = new wxPyUserData(userData);
236 wxPyEndBlockThreads(blocked);
238 return new wxGBSizerItem(window, pos, span, flag, border, data);
242 DocStr(wxGBSizerItem( wxSizer *sizer,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL ),
243 "Construct a `wx.GBSizerItem` for a sizer", "");
244 %RenameCtor(GBSizerItemSizer, wxGBSizerItem( wxSizer *sizer,
245 const wxGBPosition& pos,
246 const wxGBSpan& span,
249 PyObject* userData=NULL ))
251 wxPyUserData* data = NULL;
253 wxPyBlock_t blocked = wxPyBeginBlockThreads();
254 data = new wxPyUserData(userData);
255 wxPyEndBlockThreads(blocked);
257 return new wxGBSizerItem(sizer, pos, span, flag, border, data);
261 DocStr(wxGBSizerItem( int width,int height,const wxGBPosition& pos,const wxGBSpan& span,int flag,int border,PyObject* userData=NULL),
262 "Construct a `wx.GBSizerItem` for a spacer.", "");
263 %RenameCtor(GBSizerItemSpacer, wxGBSizerItem( int width,
265 const wxGBPosition& pos,
266 const wxGBSpan& span,
269 PyObject* userData=NULL))
271 wxPyUserData* data = NULL;
273 wxPyBlock_t blocked = wxPyBeginBlockThreads();
274 data = new wxPyUserData(userData);
275 wxPyEndBlockThreads(blocked);
277 return new wxGBSizerItem(width, height, pos, span, flag, border, data);
283 wxGBPosition , GetPos() const,
284 "Get the grid position of the item", "");
286 %pythoncode { def GetPosTuple(self): return self.GetPos().Get() }
291 wxGBSpan , GetSpan() const,
292 "Get the row and column spanning of the item", "");
294 %pythoncode { def GetSpanTuple(self): return self.GetSpan().Get() }
299 bool , SetPos( const wxGBPosition& pos ),
300 "If the item is already a member of a sizer then first ensure that
301 there is no other item that would intersect with this one at the new
302 position, then set the new position. Returns True if the change is
303 successful and after the next Layout() the item will be moved.", "");
307 bool , SetSpan( const wxGBSpan& span ),
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 with its new
310 spanning size, then set the new spanning. Returns True if the change
311 is successful and after the next Layout() the item will be resized.
317 bool , Intersects(const wxGBSizerItem& other),
318 "Returns True if this item and the other item instersect.", "");
322 bool , Intersects(const wxGBPosition& pos, const wxGBSpan& span),
323 "Returns True if the given pos/span would intersect with this item.", "",
329 "Get the row and column of the endpoint of this item.", "");
330 wxGBPosition GetEndPos() {
332 self->GetEndPos(row, col);
333 return wxGBPosition(row, col);
339 wxGridBagSizer* , GetGBSizer() const,
340 "Get the sizer this item is a member of.", "");
343 void , SetGBSizer(wxGridBagSizer* sizer),
344 "Set the sizer this item is a member of.", "");
349 //---------------------------------------------------------------------------
351 DocStr(wxGridBagSizer,
352 "A `wx.Sizer` that can lay out items in a virtual grid like a
353 `wx.FlexGridSizer` but in this case explicit positioning of the items
354 is allowed using `wx.GBPosition`, and items can optionally span more
355 than one row and/or column using `wx.GBSpan`. The total size of the
356 virtual grid is determined by the largest row and column that items are
357 positioned at, adjusted for spanning.
360 class wxGridBagSizer : public wxFlexGridSizer
363 %pythonAppend wxGridBagSizer "self._setOORInfo(self)"
366 wxGridBagSizer(int vgap = 0, int hgap = 0 ),
367 "Constructor, with optional parameters to specify the gap between the
368 rows and columns.", "");
373 "Add(self, item, GBPosition pos, GBSpan span=DefaultSpan, int flag=0,
374 int border=0, userData=None) -> wx.GBSizerItem",
376 "Adds an item to the sizer at the grid cell *pos*, optionally spanning
377 more than one row or column as specified with *span*. The remaining
378 args behave similarly to `wx.Sizer.Add`.
380 Returns True if the item was successfully placed at the given cell
381 position, False if something was already there.
383 wxGBSizerItem* Add( PyObject* item,
384 const wxGBPosition& pos,
385 const wxGBSpan& span = wxDefaultSpan,
388 PyObject* userData = NULL ) {
390 wxPyUserData* data = NULL;
391 wxPyBlock_t blocked = wxPyBeginBlockThreads();
392 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
393 if ( userData && (info.window || info.sizer || info.gotSize) )
394 data = new wxPyUserData(userData);
395 wxPyEndBlockThreads(blocked);
397 // Now call the real Add method if a valid item type was found
399 return (wxGBSizerItem*)self->Add(info.window, pos, span, flag, border, data);
400 else if ( info.sizer )
401 return (wxGBSizerItem*)self->Add(info.sizer, pos, span, flag, border, data);
402 else if (info.gotSize)
403 return (wxGBSizerItem*)self->Add(info.size.GetWidth(), info.size.GetHeight(),
404 pos, span, flag, border, data);
410 wxGBSizerItem* , Add( wxGBSizerItem *item ),
411 "Add(self, GBSizerItem item) -> wx.GBSizerItem",
412 "Add an item to the sizer using a `wx.GBSizerItem`. Returns True if
413 the item was successfully placed at its given cell position, False if
414 something was already there.", "",
418 wxSize , GetCellSize(int row, int col) const,
419 "Get the size of the specified cell, including hgap and
420 vgap. Only valid after a Layout.", "");
423 wxSize , GetEmptyCellSize() const,
424 "Get the size used for cells in the grid with no item.", "");
427 void , SetEmptyCellSize(const wxSize& sz),
428 "Set the size used for cells in the grid with no item.", "");
432 %nokwargs GetItemPosition;
433 %noautodoc GetItemPosition;
434 DocStr(GetItemPosition,
435 "GetItemPosition(self, item) -> GBPosition
437 Get the grid position of the specified *item* where *item* is either a
438 window or subsizer that is a member of this sizer, or a zero-based
439 index of an item.", "");
440 wxGBPosition GetItemPosition(wxWindow *window);
441 wxGBPosition GetItemPosition(wxSizer *sizer);
442 wxGBPosition GetItemPosition(size_t index);
445 %nokwargs SetItemPosition;
446 %noautodoc SetItemPosition;
447 DocStr(SetItemPosition,
448 "SetItemPosition(self, item, GBPosition pos) -> bool
450 Set the grid position of the specified *item* where *item* is either a
451 window or subsizer that is a member of this sizer, or a zero-based
452 index of an item. Returns True on success. If the move is not
453 allowed (because an item is already there) then False is returned.
455 bool SetItemPosition(wxWindow *window, const wxGBPosition& pos);
456 bool SetItemPosition(wxSizer *sizer, const wxGBPosition& pos);
457 bool SetItemPosition(size_t index, const wxGBPosition& pos);
461 %nokwargs GetItemSpan;
462 %noautodoc GetItemSpan;
464 "GetItemSpan(self, item) -> GBSpan
466 Get the row/col spanning of the specified *item* where *item* is
467 either a window or subsizer that is a member of this sizer, or a
468 zero-based index of an item.", "");
469 wxGBSpan GetItemSpan(wxWindow *window);
470 wxGBSpan GetItemSpan(wxSizer *sizer);
471 wxGBSpan GetItemSpan(size_t index);
475 %nokwargs SetItemSpan;
476 %noautodoc SetItemSpan;
478 "SetItemSpan(self, item, GBSpan span) -> bool
480 Set the row/col spanning of the specified *item* where *item* is
481 either a window or subsizer that is a member of this sizer, or a
482 zero-based index of an item. Returns True on success. If the move is
483 not allowed (because an item is already there) then False is returned.", "");
484 bool SetItemSpan(wxWindow *window, const wxGBSpan& span);
485 bool SetItemSpan(wxSizer *sizer, const wxGBSpan& span);
486 bool SetItemSpan(size_t index, const wxGBSpan& span);
493 "FindItem(self, item) -> GBSizerItem
495 Find the sizer item for the given window or subsizer, returns None if
496 not found. (non-recursive)", "");
497 wxGBSizerItem* FindItem(wxWindow* window);
498 wxGBSizerItem* FindItem(wxSizer* sizer);
502 wxGBSizerItem* , FindItemAtPosition(const wxGBPosition& pos),
503 "Return the sizer item for the given grid cell, or None if there is no
504 item at that position. (non-recursive)", "");
509 wxGBSizerItem* , FindItemAtPoint(const wxPoint& pt),
510 "Return the sizer item located at the point given in *pt*, or None if
511 there is no item at that point. The (x,y) coordinates in pt correspond
512 to the client coordinates of the window using the sizer for
513 layout. (non-recursive)", "");
518 // wxGBSizerItem* , FindItemWithData(const wxObject* userData),
519 // "Return the sizer item that has a matching user data (it only compares
520 // pointer values) or None if not found. (non-recursive)", "");
524 // Look at all items and see if any intersect (or would overlap) the given
525 // item. Returns True if so, False if there would be no overlap. If an
526 // excludeItem is given then it will not be checked for intersection, for
527 // example it may be the item we are checking the position of.
531 bool , CheckForIntersection(wxGBSizerItem* item, wxGBSizerItem* excludeItem = NULL),
532 "Look at all items and see if any intersect (or would overlap) the
533 given *item*. Returns True if so, False if there would be no overlap.
534 If an *excludeItem* is given then it will not be checked for
535 intersection, for example it may be the item we are checking the
540 bool , CheckForIntersection(const wxGBPosition& pos, const wxGBSpan& span, wxGBSizerItem* excludeItem = NULL),
541 "Look at all items and see if any intersect (or would overlap) the
542 given position and span. Returns True if so, False if there would be
543 no overlap. If an *excludeItem* is given then it will not be checked
544 for intersection, for example it may be the item we are checking the
546 CheckForIntersectionPos);
552 //---------------------------------------------------------------------------