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