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