]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_sizers.i
more warning fixes about empty if statement in helper classes in release build
[wxWidgets.git] / wxPython / src / _sizers.i
CommitLineData
d14a1e28
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: _sizers.i
3// Purpose: SWIG interface defs for the Sizers
4//
5// Author: Robin Dunn
6//
7// Created: 18-Sept-1999
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%newgroup;
23
3ea6e0ec
RD
24DocStr(wxSizerItem,
25"The wx.SizerItem class is used to track the position, size and other
4ba3af91
RD
26attributes of each item managed by a `wx.Sizer`. It is not usually
27necessary to use this class because the sizer elements can also be
28identified by their positions or window or sizer references but
29sometimes it may be more convenient to use wx.SizerItem directly.
30Also, custom classes derived from `wx.PySizer` will probably need to
31use the collection of wx.SizerItems held by wx.Sizer when calculating
32layout.
3ea6e0ec
RD
33
34:see: `wx.Sizer`, `wx.GBSizerItem`", "");
d14a1e28
RD
35
36class wxSizerItem : public wxObject {
37public:
3ea6e0ec
RD
38 DocCtorStr(
39 wxSizerItem(),
40 "Constructs an empty wx.SizerItem. Either a window, sizer or spacer
41size will need to be set before this item can be used in a Sizer.
42
43You will probably never need to create a wx.SizerItem directly as they
44are created automatically when the sizer's Add, Insert or Prepend
45methods are called.
46
47:see: `wx.SizerItemSpacer`, `wx.SizerItemWindow`, `wx.SizerItemSizer`", "");
48
214c4fbe
RD
49
50 ~wxSizerItem();
3ea6e0ec 51
7e8f0df9 52
3ea6e0ec
RD
53 %extend {
54 DocStr(
55 wxSizerItem( wxWindow *window, int proportion, int flag,
56 int border, PyObject* userData=NULL ),
7e8f0df9
RD
57 "Constructs a `wx.SizerItem` for tracking a window.", "");
58
1b8c7ba6
RD
59 %RenameCtor(SizerItemWindow, wxSizerItem( wxWindow *window, int proportion, int flag,
60 int border, PyObject* userData=NULL ))
61 {
3ea6e0ec
RD
62 wxPyUserData* data = NULL;
63 if ( userData ) {
6e6b3557 64 wxPyBlock_t blocked = wxPyBeginBlockThreads();
3ea6e0ec
RD
65 data = new wxPyUserData(userData);
66 wxPyEndBlockThreads(blocked);
67 }
68 return new wxSizerItem(window, proportion, flag, border, data);
69 }
70
7e8f0df9 71
3ea6e0ec
RD
72 DocStr(
73 wxSizerItem( int width, int height, int proportion, int flag,
74 int border, PyObject* userData=NULL),
75 "Constructs a `wx.SizerItem` for tracking a spacer.", "");
7e8f0df9 76
1b8c7ba6
RD
77 %RenameCtor(SizerItemSpacer, wxSizerItem( int width, int height, int proportion, int flag,
78 int border, PyObject* userData=NULL))
79 {
3ea6e0ec
RD
80 wxPyUserData* data = NULL;
81 if ( userData ) {
6e6b3557 82 wxPyBlock_t blocked = wxPyBeginBlockThreads();
3ea6e0ec
RD
83 data = new wxPyUserData(userData);
84 wxPyEndBlockThreads(blocked);
85 }
86 return new wxSizerItem(width, height, proportion, flag, border, data);
87 }
7e8f0df9 88
3ea6e0ec
RD
89 DocStr(
90 wxSizerItem( wxSizer *sizer, int proportion, int flag,
91 int border, PyObject* userData=NULL ),
1b8c7ba6 92 "Constructs a `wx.SizerItem` for tracking a subsizer", "");
7e8f0df9 93
214c4fbe 94 %disownarg( wxSizer *sizer );
1b8c7ba6
RD
95 %RenameCtor(SizerItemSizer, wxSizerItem( wxSizer *sizer, int proportion, int flag,
96 int border, PyObject* userData=NULL ))
97 {
3ea6e0ec
RD
98 wxPyUserData* data = NULL;
99 if ( userData ) {
6e6b3557 100 wxPyBlock_t blocked = wxPyBeginBlockThreads();
3ea6e0ec
RD
101 data = new wxPyUserData(userData);
102 wxPyEndBlockThreads(blocked);
103 }
104 return new wxSizerItem(sizer, proportion, flag, border, data);
105 }
214c4fbe 106 %cleardisown( wxSizer *sizer );
3ea6e0ec 107 }
d14a1e28 108
d14a1e28 109
7e8f0df9 110
3ea6e0ec
RD
111 DocDeclStr(
112 void , DeleteWindows(),
113 "Destroy the window or the windows in a subsizer, depending on the type
114of item.", "");
7e8f0df9 115
3ea6e0ec
RD
116 DocDeclStr(
117 void , DetachSizer(),
118 "Enable deleting the SizerItem without destroying the contained sizer.", "");
7e8f0df9 119
d14a1e28 120
3ea6e0ec
RD
121 DocDeclStr(
122 wxSize , GetSize(),
123 "Get the current size of the item, as set in the last Layout.", "");
7e8f0df9 124
3ea6e0ec
RD
125 DocDeclStr(
126 wxSize , CalcMin(),
127 "Calculates the minimum desired size for the item, including any space
128needed by borders.", "");
7e8f0df9 129
3ea6e0ec 130 DocDeclStr(
b6222be9 131 void , SetDimension( const wxPoint& pos, const wxSize& size ),
3ea6e0ec
RD
132 "Set the position and size of the space allocated for this item by the
133sizer, and adjust the position and size of the item (window or
134subsizer) to be within that space taking alignment and borders into
135account.", "");
7e8f0df9 136
3ea6e0ec
RD
137
138 DocDeclStr(
139 wxSize , GetMinSize(),
140 "Get the minimum size needed for the item.", "");
7e8f0df9 141
329b045c
RD
142 DocDeclStr(
143 wxSize , GetMinSizeWithBorder() const,
144 "Get the minimum size needed for the item with space for the borders
145added, if needed.", "");
146
3ea6e0ec
RD
147 DocDeclStr(
148 void , SetInitSize( int x, int y ),
149 "", "");
7e8f0df9 150
d14a1e28 151
3ea6e0ec
RD
152 DocStr(SetRatio,
153 "Set the ratio item attribute.", "");
1b8c7ba6 154 %Rename(SetRatioWH, void, SetRatio( int width, int height ));
f1e759d7 155 %Rename(SetRatioSize, void, SetRatio( const wxSize& size ));
d14a1e28 156 void SetRatio( float ratio );
7e8f0df9 157
3ea6e0ec
RD
158 DocDeclStr(
159 float , GetRatio(),
160 "Set the ratio item attribute.", "");
7aada1e0
RD
161
162 DocDeclStr(
163 wxRect , GetRect(),
164 "Returns the rectangle that the sizer item should occupy", "");
7e8f0df9 165
d14a1e28 166
3ea6e0ec
RD
167 DocDeclStr(
168 bool , IsWindow(),
169 "Is this sizer item a window?", "");
7e8f0df9 170
3ea6e0ec
RD
171 DocDeclStr(
172 bool , IsSizer(),
173 "Is this sizer item a subsizer?", "");
7e8f0df9 174
3ea6e0ec
RD
175 DocDeclStr(
176 bool , IsSpacer(),
177 "Is this sizer item a spacer?", "");
7e8f0df9 178
d14a1e28 179
3ea6e0ec
RD
180 DocDeclStr(
181 void , SetProportion( int proportion ),
182 "Set the proportion value for this item.", "");
7e8f0df9 183
3ea6e0ec
RD
184 DocDeclStr(
185 int , GetProportion(),
186 "Get the proportion value for this item.", "");
7e8f0df9 187
3ea6e0ec
RD
188 %pythoncode { SetOption = wx._deprecated(SetProportion, "Please use `SetProportion` instead.") }
189 %pythoncode { GetOption = wx._deprecated(GetProportion, "Please use `GetProportion` instead.") }
d14a1e28 190
7e8f0df9 191
3ea6e0ec
RD
192 DocDeclStr(
193 void , SetFlag( int flag ),
194 "Set the flag value for this item.", "");
7e8f0df9 195
3ea6e0ec
RD
196 DocDeclStr(
197 int , GetFlag(),
198 "Get the flag value for this item.", "");
7e8f0df9
RD
199
200
3ea6e0ec
RD
201 DocDeclStr(
202 void , SetBorder( int border ),
203 "Set the border value for this item.", "");
7e8f0df9 204
3ea6e0ec
RD
205 DocDeclStr(
206 int , GetBorder(),
207 "Get the border value for this item.", "");
d14a1e28 208
7e8f0df9
RD
209
210
3ea6e0ec
RD
211 DocDeclStr(
212 wxWindow *, GetWindow(),
213 "Get the window (if any) that is managed by this sizer item.", "");
7e8f0df9 214
3ea6e0ec
RD
215 DocDeclStr(
216 void , SetWindow( wxWindow *window ),
217 "Set the window to be managed by this sizer item.", "");
7e8f0df9
RD
218
219
3ea6e0ec
RD
220 DocDeclStr(
221 wxSizer *, GetSizer(),
222 "Get the subsizer (if any) that is managed by this sizer item.", "");
7e8f0df9 223
214c4fbe 224 %disownarg( wxSizer *sizer );
3ea6e0ec
RD
225 DocDeclStr(
226 void , SetSizer( wxSizer *sizer ),
227 "Set the subsizer to be managed by this sizer item.", "");
214c4fbe 228 %cleardisown( wxSizer *sizer );
7e8f0df9
RD
229
230
3ea6e0ec
RD
231 DocDeclStr(
232 const wxSize& , GetSpacer(),
233 "Get the size of the spacer managed by this sizer item.", "");
7e8f0df9 234
3ea6e0ec
RD
235 DocDeclStr(
236 void , SetSpacer( const wxSize &size ),
237 "Set the size of the spacer to be managed by this sizer item.", "");
7e8f0df9 238
d14a1e28 239
3ea6e0ec
RD
240 DocDeclStr(
241 void , Show( bool show ),
242 "Set the show item attribute, which sizers use to determine if the item
243is to be made part of the layout or not. If the item is tracking a
244window then it is shown or hidden as needed.", "");
7e8f0df9 245
3ea6e0ec
RD
246 DocDeclStr(
247 bool , IsShown(),
248 "Is the item to be shown in the layout?", "");
7e8f0df9 249
3ea6e0ec
RD
250
251 DocDeclStr(
252 wxPoint , GetPosition(),
253 "Returns the current position of the item, as set in the last Layout.", "");
7e8f0df9 254
d14a1e28
RD
255
256 // wxObject* GetUserData();
257 %extend {
258 // Assume that the user data is a wxPyUserData object and return the contents
3ea6e0ec
RD
259
260 DocStr(GetUserData,
261 "Returns the userData associated with this sizer item, or None if there
262isn't any.", "");
d14a1e28
RD
263 PyObject* GetUserData() {
264 wxPyUserData* data = (wxPyUserData*)self->GetUserData();
265 if (data) {
266 Py_INCREF(data->m_obj);
267 return data->m_obj;
268 } else {
269 Py_INCREF(Py_None);
270 return Py_None;
271 }
272 }
095315e2
RD
273
274 DocStr(SetUserData,
275 "Associate a Python object with this sizer item.", "");
276 void SetUserData(PyObject* userData) {
277 wxPyUserData* data = NULL;
278 if ( userData ) {
279 wxPyBlock_t blocked = wxPyBeginBlockThreads();
280 data = new wxPyUserData(userData);
281 wxPyEndBlockThreads(blocked);
282 }
283 self->SetUserData(data);
284 }
d14a1e28
RD
285 }
286};
287
288
289//---------------------------------------------------------------------------
290
291%{
292// Figure out the type of the sizer item
293
294struct wxPySizerItemInfo {
295 wxPySizerItemInfo()
a72f4631
RD
296 : window(NULL), sizer(NULL), gotSize(false),
297 size(wxDefaultSize), gotPos(false), pos(-1)
d14a1e28 298 {}
7e8f0df9 299
d14a1e28
RD
300 wxWindow* window;
301 wxSizer* sizer;
302 bool gotSize;
303 wxSize size;
304 bool gotPos;
305 int pos;
306};
7e8f0df9 307
d14a1e28
RD
308static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) {
309
310 wxPySizerItemInfo info;
311 wxSize size;
312 wxSize* sizePtr = &size;
313
314 // Find out what the type of the item is
315 // try wxWindow
316 if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) {
317 PyErr_Clear();
318 info.window = NULL;
7e8f0df9 319
d14a1e28
RD
320 // try wxSizer
321 if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) {
322 PyErr_Clear();
323 info.sizer = NULL;
7e8f0df9 324
d14a1e28
RD
325 // try wxSize or (w,h)
326 if ( checkSize && wxSize_helper(item, &sizePtr)) {
327 info.size = *sizePtr;
a72f4631 328 info.gotSize = true;
d14a1e28
RD
329 }
330
331 // or a single int
332 if (checkIdx && PyInt_Check(item)) {
333 info.pos = PyInt_AsLong(item);
a72f4631 334 info.gotPos = true;
d14a1e28
RD
335 }
336 }
337 }
338
339 if ( !(info.window || info.sizer || (checkSize && info.gotSize) || (checkIdx && info.gotPos)) ) {
340 // no expected type, figure out what kind of error message to generate
341 if ( !checkSize && !checkIdx )
02b800ce 342 PyErr_SetString(PyExc_TypeError, "wx.Window or wx.Sizer expected for item");
d14a1e28 343 else if ( checkSize && !checkIdx )
02b800ce 344 PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) expected for item");
d14a1e28 345 else if ( !checkSize && checkIdx)
02b800ce 346 PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer or int (position) expected for item");
d14a1e28
RD
347 else
348 // can this one happen?
02b800ce 349 PyErr_SetString(PyExc_TypeError, "wx.Window, wx.Sizer, wx.Size, or (w,h) or int (position) expected for item");
d14a1e28
RD
350 }
351
352 return info;
353}
354%}
355
356
357
358
3ea6e0ec
RD
359DocStr(wxSizer,
360"wx.Sizer is the abstract base class used for laying out subwindows in
361a window. You cannot use wx.Sizer directly; instead, you will have to
362use one of the sizer classes derived from it such as `wx.BoxSizer`,
a2cccbc3
RD
363`wx.StaticBoxSizer`, `wx.GridSizer`, `wx.FlexGridSizer` and
364`wx.GridBagSizer`.
3ea6e0ec
RD
365
366The concept implemented by sizers in wxWidgets is closely related to
367layout tools in other GUI toolkits, such as Java's AWT, the GTK
368toolkit or the Qt toolkit. It is based upon the idea of the individual
369subwindows reporting their minimal required size and their ability to
370get stretched if the size of the parent window has changed. This will
371most often mean that the programmer does not set the original size of
372a dialog in the beginning, rather the dialog will assigned a sizer and
373this sizer will be queried about the recommended size. The sizer in
374turn will query its children, which can be normal windows or contorls,
375empty space or other sizers, so that a hierarchy of sizers can be
376constructed. Note that wxSizer does not derive from wxWindow and thus
377do not interfere with tab ordering and requires very little resources
378compared to a real window on screen.
379
380What makes sizers so well fitted for use in wxWidgets is the fact that
381every control reports its own minimal size and the algorithm can
382handle differences in font sizes or different window (dialog item)
383sizes on different platforms without problems. If for example the
384standard font as well as the overall design of Mac widgets requires
385more space than on Windows, then the initial size of a dialog using a
386sizer will automatically be bigger on Mac than on Windows.", "
387
38260cce
RD
388Sizers may also be used to control the layout of custom drawn items on
389the window. The `Add`, `Insert`, and `Prepend` functions return a
390pointer to the newly added `wx.SizerItem`. Just add empty space of the
391desired size and attributes, and then use the `wx.SizerItem.GetRect`
392method to determine where the drawing operations should take place.
393
3ea6e0ec
RD
394:note: If you wish to create a custom sizer class in wxPython you
395 should derive the class from `wx.PySizer` in order to get
396 Python-aware capabilities for the various virtual methods.
397
398:see: `wx.SizerItem`
399
400:todo: More dscriptive text here along with some pictures...
401
402");
403
d14a1e28
RD
404class wxSizer : public wxObject {
405public:
406 // wxSizer(); **** abstract, can't instantiate
214c4fbe
RD
407
408 ~wxSizer();
d14a1e28
RD
409
410 %extend {
411 void _setOORInfo(PyObject* _self) {
a77bf68f
RD
412 if (!self->GetClientObject())
413 self->SetClientObject(new wxPyOORClientData(_self));
d14a1e28
RD
414 }
415
3ea6e0ec
RD
416 DocAStr(Add,
417 "Add(self, item, int proportion=0, int flag=0, int border=0,
7aada1e0 418 PyObject userData=None) -> wx.SizerItem",
3ea6e0ec
RD
419
420 "Appends a child item to the sizer.", "
421
422 :param item: The item can be one of three kinds of objects:
423
424 - **window**: A `wx.Window` to be managed by the sizer. Its
425 minimal size (either set explicitly by the user or
426 calculated internally when constructed with wx.DefaultSize)
427 is interpreted as the minimal size to use when laying out
428 item in the sizer. This is particularly useful in
429 connection with `wx.Window.SetSizeHints`.
430
431 - **sizer**: The (child-)sizer to be added to the sizer. This
432 allows placing a child sizer in a sizer and thus to create
433 hierarchies of sizers (typically a vertical box as the top
434 sizer and several horizontal boxes on the level beneath).
435
436 - **size**: A `wx.Size` or a 2-element sequence of integers
437 that represents the width and height of a spacer to be added
438 to the sizer. Adding spacers to sizers gives more
439 flexibility in the design of dialogs; imagine for example a
440 horizontal box with two buttons at the bottom of a dialog:
441 you might want to insert a space between the two buttons and
442 make that space stretchable using the *proportion* value and
443 the result will be that the left button will be aligned with
444 the left side of the dialog and the right button with the
445 right side - the space in between will shrink and grow with
446 the dialog.
447
448 :param proportion: Although the meaning of this parameter is
449 undefined in wx.Sizer, it is used in `wx.BoxSizer` to indicate
450 if a child of a sizer can change its size in the main
451 orientation of the wx.BoxSizer - where 0 stands for not
452 changeable and a value of more than zero is interpreted
453 relative (a proportion of the total) to the value of other
454 children of the same wx.BoxSizer. For example, you might have
455 a horizontal wx.BoxSizer with three children, two of which are
456 supposed to change their size with the sizer. Then the two
457 stretchable windows should each be given *proportion* value of
458 1 to make them grow and shrink equally with the sizer's
459 horizontal dimension. But if one of them had a *proportion*
460 value of 2 then it would get a double share of the space
461 available after the fixed size items are positioned.
462
463 :param flag: This parameter can be used to set a number of flags
464 which can be combined using the binary OR operator ``|``. Two
465 main behaviours are defined using these flags. One is the
466 border around a window: the *border* parameter determines the
467 border width whereas the flags given here determine which
468 side(s) of the item that the border will be added. The other
469 flags determine how the sizer item behaves when the space
470 allotted to the sizer changes, and is somewhat dependent on
471 the specific kind of sizer used.
472
473 +----------------------------+------------------------------------------+
474 |- wx.TOP |These flags are used to specify |
475 |- wx.BOTTOM |which side(s) of the sizer item that |
476 |- wx.LEFT |the *border* width will apply to. |
477 |- wx.RIGHT | |
478 |- wx.ALL | |
479 | | |
480 +----------------------------+------------------------------------------+
8b5895b0 481 |- wx.EXPAND |The item will be expanded to fill |
3ea6e0ec
RD
482 | |the space allotted to the item. |
483 +----------------------------+------------------------------------------+
484 |- wx.SHAPED |The item will be expanded as much as |
485 | |possible while also maintaining its |
486 | |aspect ratio |
487 +----------------------------+------------------------------------------+
488 |- wx.FIXED_MINSIZE |Normally wx.Sizers will use |
489 | |`wx.Window.GetMinSize` or |
490 | |`wx.Window.GetBestSize` to determine what |
491 | |the minimal size of window items should |
492 | |be, and will use that size to calculate |
493 | |the layout. This allows layouts to adjust |
494 | |when an item changes and it's best size |
495 | |becomes different. If you would rather |
496 | |have a window item stay the size it |
497 | |started with then use wx.FIXED_MINSIZE. |
498 +----------------------------+------------------------------------------+
499 |- wx.ALIGN_CENTER |The wx.ALIGN flags allow you to specify |
500 |- wx.ALIGN_LEFT |the alignment of the item within the space|
501 |- wx.ALIGN_RIGHT |allotted to it by the sizer, ajusted for |
502 |- wx.ALIGN_TOP |the border if any. |
503 |- wx.ALIGN_BOTTOM | |
504 |- wx.ALIGN_CENTER_VERTICAL | |
505 |- wx.ALIGN_CENTER_HORIZONTAL| |
506 +----------------------------+------------------------------------------+
507
508
509 :param border: Determines the border width, if the *flag*
510 parameter is set to include any border flag.
511
512 :param userData: Allows an extra object to be attached to the
513 sizer item, for use in derived classes when sizing information
514 is more complex than the *proportion* and *flag* will allow for.
515");
d14a1e28 516
7aada1e0
RD
517 wxSizerItem* Add(PyObject* item, int proportion=0, int flag=0, int border=0,
518 PyObject* userData=NULL) {
7e8f0df9 519
d14a1e28 520 wxPyUserData* data = NULL;
6e6b3557 521 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 522 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
d14a1e28
RD
523 if ( userData && (info.window || info.sizer || info.gotSize) )
524 data = new wxPyUserData(userData);
214c4fbe
RD
525 if ( info.sizer )
526 PyObject_SetAttrString(item,"thisown",Py_False);
da32eb53 527 wxPyEndBlockThreads(blocked);
7e8f0df9 528
d14a1e28
RD
529 // Now call the real Add method if a valid item type was found
530 if ( info.window )
7aada1e0 531 return self->Add(info.window, proportion, flag, border, data);
d14a1e28 532 else if ( info.sizer )
7aada1e0 533 return self->Add(info.sizer, proportion, flag, border, data);
d14a1e28 534 else if (info.gotSize)
7aada1e0
RD
535 return self->Add(info.size.GetWidth(), info.size.GetHeight(),
536 proportion, flag, border, data);
537 else
538 return NULL;
d14a1e28
RD
539 }
540
7aada1e0
RD
541// virtual wxSizerItem* AddSpacer(int size);
542// virtual wxSizerItem* AddStretchSpacer(int prop = 1);
d14a1e28 543
3ea6e0ec
RD
544 DocAStr(Insert,
545 "Insert(self, int before, item, int proportion=0, int flag=0, int border=0,
7aada1e0 546 PyObject userData=None) -> wx.SizerItem",
3ea6e0ec
RD
547
548 "Inserts a new item into the list of items managed by this sizer before
549the item at index *before*. See `Add` for a description of the parameters.", "");
7aada1e0
RD
550 wxSizerItem* Insert(int before, PyObject* item, int proportion=0, int flag=0,
551 int border=0, PyObject* userData=NULL) {
d14a1e28
RD
552
553 wxPyUserData* data = NULL;
6e6b3557 554 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 555 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
d14a1e28
RD
556 if ( userData && (info.window || info.sizer || info.gotSize) )
557 data = new wxPyUserData(userData);
214c4fbe
RD
558 if ( info.sizer )
559 PyObject_SetAttrString(item,"thisown",Py_False);
da32eb53 560 wxPyEndBlockThreads(blocked);
7e8f0df9 561
d14a1e28
RD
562 // Now call the real Insert method if a valid item type was found
563 if ( info.window )
7aada1e0 564 return self->Insert(before, info.window, proportion, flag, border, data);
d14a1e28 565 else if ( info.sizer )
7aada1e0 566 return self->Insert(before, info.sizer, proportion, flag, border, data);
d14a1e28 567 else if (info.gotSize)
7aada1e0
RD
568 return self->Insert(before, info.size.GetWidth(), info.size.GetHeight(),
569 proportion, flag, border, data);
570 else
571 return NULL;
d14a1e28
RD
572 }
573
574
7aada1e0
RD
575// virtual wxSizerItem* InsertSpacer(size_t index, int size);
576// virtual wxSizerItem* InsertStretchSpacer(size_t index, int prop = 1);
7e8f0df9 577
3ea6e0ec
RD
578 DocAStr(Prepend,
579 "Prepend(self, item, int proportion=0, int flag=0, int border=0,
7aada1e0 580 PyObject userData=None) -> wx.SizerItem",
d14a1e28 581
3ea6e0ec
RD
582 "Adds a new item to the begining of the list of sizer items managed by
583this sizer. See `Add` for a description of the parameters.", "");
7aada1e0
RD
584 wxSizerItem* Prepend(PyObject* item, int proportion=0, int flag=0, int border=0,
585 PyObject* userData=NULL) {
d14a1e28
RD
586
587 wxPyUserData* data = NULL;
6e6b3557 588 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 589 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, true, false);
d14a1e28
RD
590 if ( userData && (info.window || info.sizer || info.gotSize) )
591 data = new wxPyUserData(userData);
214c4fbe
RD
592 if ( info.sizer )
593 PyObject_SetAttrString(item,"thisown",Py_False);
da32eb53 594 wxPyEndBlockThreads(blocked);
7e8f0df9 595
d14a1e28
RD
596 // Now call the real Prepend method if a valid item type was found
597 if ( info.window )
7aada1e0 598 return self->Prepend(info.window, proportion, flag, border, data);
d14a1e28 599 else if ( info.sizer )
7aada1e0 600 return self->Prepend(info.sizer, proportion, flag, border, data);
d14a1e28 601 else if (info.gotSize)
7aada1e0
RD
602 return self->Prepend(info.size.GetWidth(), info.size.GetHeight(),
603 proportion, flag, border, data);
604 else
605 return NULL;
d14a1e28
RD
606 }
607
7aada1e0
RD
608// virtual wxSizerItem* PrependSpacer(int size);
609// virtual wxSizerItem* PrependStretchSpacer(int prop = 1);
3ea6e0ec 610
e81b607b 611
3ea6e0ec
RD
612 DocAStr(Remove,
613 "Remove(self, item) -> bool",
614 "Removes an item from the sizer and destroys it. This method does not
615cause any layout or resizing to take place, call `Layout` to update
616the layout on screen after removing a child from the sizer. The
617*item* parameter can be either a window, a sizer, or the zero-based
618index of an item to remove. Returns True if the child item was found
619and removed.", "
620
621:note: For historical reasons calling this method with a `wx.Window`
622 parameter is depreacted, as it will not be able to destroy the
623 window since it is owned by its parent. You should use `Detach`
624 instead.
625");
d14a1e28 626 bool Remove(PyObject* item) {
6e6b3557 627 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 628 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
da32eb53 629 wxPyEndBlockThreads(blocked);
d14a1e28
RD
630 if ( info.window )
631 return self->Remove(info.window);
632 else if ( info.sizer )
633 return self->Remove(info.sizer);
634 else if ( info.gotPos )
635 return self->Remove(info.pos);
7e8f0df9 636 else
a72f4631 637 return false;
d14a1e28
RD
638 }
639
3ea6e0ec
RD
640
641 DocAStr(Detach,
642 "Detach(self, item) -> bool",
643 "Detaches an item from the sizer without destroying it. This method
644does not cause any layout or resizing to take place, call `Layout` to
645do so. The *item* parameter can be either a window, a sizer, or the
646zero-based index of the item to be detached. Returns True if the child item
647was found and detached.", "");
60a71c29 648 bool Detach(PyObject* item) {
6e6b3557 649 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 650 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
60a71c29
RD
651 wxPyEndBlockThreads(blocked);
652 if ( info.window )
653 return self->Detach(info.window);
654 else if ( info.sizer )
655 return self->Detach(info.sizer);
656 else if ( info.gotPos )
657 return self->Detach(info.pos);
7e8f0df9 658 else
a72f4631 659 return false;
60a71c29
RD
660 }
661
7e8f0df9 662
7aada1e0
RD
663 DocAStr(GetItem,
664 "GetItem(self, item) -> wx.SizerItem",
665 "Returns the `wx.SizerItem` which holds the *item* given. The *item*
666parameter can be either a window, a sizer, or the zero-based index of
aae5d34f 667the item to be found.", "");
7aada1e0 668 wxSizerItem* GetItem(PyObject* item) {
6e6b3557 669 wxPyBlock_t blocked = wxPyBeginBlockThreads();
7aada1e0
RD
670 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
671 wxPyEndBlockThreads(blocked);
672 if ( info.window )
673 return self->GetItem(info.window);
674 else if ( info.sizer )
675 return self->GetItem(info.sizer);
676 else if ( info.gotPos )
677 return self->GetItem(info.pos);
678 else
679 return NULL;
680 }
681
7e8f0df9 682
dd9f7fea 683 void _SetItemMinSize(PyObject* item, const wxSize& size) {
6e6b3557 684 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 685 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
da32eb53 686 wxPyEndBlockThreads(blocked);
d14a1e28
RD
687 if ( info.window )
688 self->SetItemMinSize(info.window, size);
689 else if ( info.sizer )
690 self->SetItemMinSize(info.sizer, size);
691 else if ( info.gotPos )
692 self->SetItemMinSize(info.pos, size);
693 }
694 }
695
e81b607b
RD
696
697 %Rename(_ReplaceWin,
698 bool, Replace( wxWindow *oldwin, wxWindow *newwin, bool recursive = false ));
699 %Rename(_ReplaceSizer,
700 bool, Replace( wxSizer *oldsz, wxSizer *newsz, bool recursive = false ));
701 %Rename(_ReplaceItem,
702 bool, Replace( size_t index, wxSizerItem *newitem ));
703 %pythoncode {
704 def Replace(self, olditem, item, recursive=False):
705 """
706 Detaches the given ``olditem`` from the sizer and replaces it with
707 ``item`` which can be a window, sizer, or `wx.SizerItem`. The
708 detached child is destroyed only if it is not a window, (because
709 windows are owned by their parent, not the sizer.) The
710 ``recursive`` parameter can be used to search for the given
711 element recursivly in subsizers.
712
713 This method does not cause any layout or resizing to take place,
714 call `Layout` to do so.
715
716 Returns ``True`` if the child item was found and removed.
717 """
718 if isinstance(olditem, wx.Window):
719 return self._ReplaceWin(olditem, item, recursive)
720 elif isinstnace(olditem, wx.Sizer):
721 return self._ReplaceSizer(olditem, item, recursive)
722 elif isinstnace(olditem, int):
723 return self._ReplaceItem(olditem, item)
724 else:
725 raise TypeError("Expected Window, Sizer, or integer for first parameter.")
726 }
727
728
729 DocDeclStr(
730 void , SetContainingWindow(wxWindow *window),
731 "Set (or unset) the window this sizer is used in.", "");
732
733 DocDeclStr(
734 wxWindow *, GetContainingWindow() const,
735 "Get the window this sizer is used in.", "");
736
737
3ea6e0ec
RD
738 %pythoncode {
739 def SetItemMinSize(self, item, *args):
740 """
741 SetItemMinSize(self, item, Size size)
742
743 Sets the minimum size that will be allocated for an item in the sizer.
744 The *item* parameter can be either a window, a sizer, or the
745 zero-based index of the item. If a window or sizer is given then it
746 will be searched for recursivly in subsizers if neccessary.
747 """
748 if len(args) == 2:
749 %# for backward compatibility accept separate width,height args too
750 return self._SetItemMinSize(item, args)
751 else:
752 return self._SetItemMinSize(item, args[0])
753 }
7e8f0df9 754
214c4fbe
RD
755
756 %disownarg( wxSizerItem *item );
757
3ea6e0ec 758 DocDeclAStrName(
7aada1e0 759 wxSizerItem* , Add( wxSizerItem *item ),
3ea6e0ec
RD
760 "AddItem(self, SizerItem item)",
761 "Adds a `wx.SizerItem` to the sizer.", "",
762 AddItem);
7e8f0df9 763
3ea6e0ec 764 DocDeclAStrName(
7aada1e0 765 wxSizerItem* , Insert( size_t index, wxSizerItem *item ),
3ea6e0ec
RD
766 "InsertItem(self, int index, SizerItem item)",
767 "Inserts a `wx.SizerItem` to the sizer at the position given by *index*.", "",
768 InsertItem);
7e8f0df9 769
3ea6e0ec 770 DocDeclAStrName(
7aada1e0 771 wxSizerItem* , Prepend( wxSizerItem *item ),
3ea6e0ec
RD
772 "PrependItem(self, SizerItem item)",
773 "Prepends a `wx.SizerItem` to the sizer.", "",
774 PrependItem);
7e8f0df9 775
214c4fbe 776 %cleardisown( wxSizerItem *item );
d14a1e28
RD
777
778
779 %pythoncode {
3ea6e0ec 780 def AddMany(self, items):
dce2bd22
RD
781 """
782 AddMany is a convenience method for adding several items
783 to a sizer at one time. Simply pass it a list of tuples,
784 where each tuple consists of the parameters that you
785 would normally pass to the `Add` method.
786 """
3ea6e0ec
RD
787 for item in items:
788 if type(item) != type(()) or (len(item) == 2 and type(item[0]) == type(1)):
789 item = (item, )
790 self.Add(*item)
d14a1e28 791
d147c724 792 %# for backwards compatibility only, please do not use in new code
7e8f0df9
RD
793 def AddWindow(self, *args, **kw):
794 """Compatibility alias for `Add`."""
795 return self.Add(*args, **kw)
796 def AddSizer(self, *args, **kw):
797 """Compatibility alias for `Add`."""
798 return self.Add(*args, **kw)
799 def AddSpacer(self, *args, **kw):
800 """Compatibility alias for `Add`."""
801 return self.Add(*args, **kw)
802
803 def PrependWindow(self, *args, **kw):
804 """Compatibility alias for `Prepend`."""
805 return self.Prepend(*args, **kw)
806 def PrependSizer(self, *args, **kw):
807 """Compatibility alias for `Prepend`."""
808 return self.Prepend(*args, **kw)
809 def PrependSpacer(self, *args, **kw):
810 """Compatibility alias for `Prepend`."""
811 return self.Prepend(*args, **kw)
812
813 def InsertWindow(self, *args, **kw):
814 """Compatibility alias for `Insert`."""
815 return self.Insert(*args, **kw)
816 def InsertSizer(self, *args, **kw):
817 """Compatibility alias for `Insert`."""
818 return self.Insert(*args, **kw)
819 def InsertSpacer(self, *args, **kw):
820 """Compatibility alias for `Insert`."""
821 return self.Insert(*args, **kw)
822
823 def RemoveWindow(self, *args, **kw):
824 """Compatibility alias for `Remove`."""
825 return self.Remove(*args, **kw)
826 def RemoveSizer(self, *args, **kw):
827 """Compatibility alias for `Remove`."""
828 return self.Remove(*args, **kw)
829 def RemovePos(self, *args, **kw):
830 """Compatibility alias for `Remove`."""
831 return self.Remove(*args, **kw)
d14a1e28 832
d14a1e28
RD
833 }
834
835
3ea6e0ec
RD
836 DocDeclStr(
837 void , SetDimension( int x, int y, int width, int height ),
838 "Call this to force the sizer to take the given dimension and thus
839force the items owned by the sizer to resize themselves according to
840the rules defined by the parameter in the `Add`, `Insert` or `Prepend`
841methods.", "");
7e8f0df9 842
3ea6e0ec
RD
843 DocDeclStr(
844 void , SetMinSize( const wxSize &size ),
845 "Call this to give the sizer a minimal size. Normally, the sizer will
846calculate its minimal size based purely on how much space its children
847need. After calling this method `GetMinSize` will return either the
848minimal size as requested by its children or the minimal size set
849here, depending on which is bigger.", "");
7e8f0df9 850
d14a1e28 851
3ea6e0ec
RD
852 DocDeclStr(
853 wxSize , GetSize(),
854 "Returns the current size of the space managed by the sizer.", "");
7e8f0df9 855
3ea6e0ec
RD
856 DocDeclStr(
857 wxPoint , GetPosition(),
858 "Returns the current position of the sizer's managed space.", "");
7e8f0df9 859
3ea6e0ec
RD
860 DocDeclStr(
861 wxSize , GetMinSize(),
862 "Returns the minimal size of the sizer. This is either the combined
863minimal size of all the children and their borders or the minimal size
864set by SetMinSize, depending on which is bigger.", "");
7e8f0df9 865
d14a1e28
RD
866
867 %pythoncode {
868 def GetSizeTuple(self):
60a71c29 869 return self.GetSize().Get()
d14a1e28 870 def GetPositionTuple(self):
60a71c29 871 return self.GetPosition().Get()
d14a1e28 872 def GetMinSizeTuple(self):
60a71c29 873 return self.GetMinSize().Get()
d14a1e28
RD
874 }
875
3ea6e0ec
RD
876 DocDeclStr(
877 virtual void , RecalcSizes(),
878 "Using the sizes calculated by `CalcMin` reposition and resize all the
879items managed by this sizer. You should not need to call this directly as
880it is called by `Layout`.", "");
7e8f0df9 881
3ea6e0ec
RD
882 DocDeclStr(
883 virtual wxSize , CalcMin(),
884 "This method is where the sizer will do the actual calculation of its
885children's minimal sizes. You should not need to call this directly as
886it is called by `Layout`.", "");
7e8f0df9 887
3ea6e0ec
RD
888
889 DocDeclStr(
890 void , Layout(),
891 "This method will force the recalculation and layout of the items
892controlled by the sizer using the current space allocated to the
893sizer. Normally this is called automatically from the owning window's
894EVT_SIZE handler, but it is also useful to call it from user code when
895one of the items in a sizer change size, or items are added or
896removed.", "");
7e8f0df9 897
d14a1e28 898
3ea6e0ec
RD
899 DocDeclStr(
900 wxSize , Fit( wxWindow *window ),
901 "Tell the sizer to resize the *window* to match the sizer's minimal
902size. This is commonly done in the constructor of the window itself in
903order to set its initial size to match the needs of the children as
904determined by the sizer. Returns the new size.
d14a1e28 905
3ea6e0ec 906For a top level window this is the total window size, not the client size.", "");
7e8f0df9 907
3ea6e0ec
RD
908 DocDeclStr(
909 void , FitInside( wxWindow *window ),
910 "Tell the sizer to resize the *virtual size* of the *window* to match the
911sizer's minimal size. This will not alter the on screen size of the
912window, but may cause the addition/removal/alteration of scrollbars
913required to view the virtual area in windows which manage it.
914
915:see: `wx.ScrolledWindow.SetScrollbars`, `SetVirtualSizeHints`
916", "");
7e8f0df9 917
d14a1e28 918
3ea6e0ec
RD
919 DocDeclStr(
920 void , SetSizeHints( wxWindow *window ),
921 "Tell the sizer to set (and `Fit`) the minimal size of the *window* to
922match the sizer's minimal size. This is commonly done in the
923constructor of the window itself if the window is resizable (as are
924many dialogs under Unix and frames on probably all platforms) in order
925to prevent the window from being sized smaller than the minimal size
926required by the sizer.", "");
7e8f0df9 927
3ea6e0ec
RD
928 DocDeclStr(
929 void , SetVirtualSizeHints( wxWindow *window ),
930 "Tell the sizer to set the minimal size of the window virtual area to
931match the sizer's minimal size. For windows with managed scrollbars
932this will set them appropriately.
933
934:see: `wx.ScrolledWindow.SetScrollbars`
935", "");
7e8f0df9 936
d14a1e28 937
3ea6e0ec 938 DocDeclStr(
a72f4631 939 void , Clear( bool deleteWindows=false ),
3ea6e0ec
RD
940 "Clear all items from the sizer, optionally destroying the window items
941as well.", "");
7e8f0df9 942
3ea6e0ec
RD
943 DocDeclStr(
944 void , DeleteWindows(),
945 "Destroy all windows managed by the sizer.", "");
7e8f0df9 946
d14a1e28
RD
947
948
949 // wxList& GetChildren();
950 %extend {
3ea6e0ec 951 DocAStr(GetChildren,
50ed1e35 952 "GetChildren(self) -> list",
3ea6e0ec 953 "Returns a list of all the `wx.SizerItem` objects managed by the sizer.", "");
d14a1e28
RD
954 PyObject* GetChildren() {
955 wxSizerItemList& list = self->GetChildren();
956 return wxPy_ConvertList(&list);
957 }
958 }
959
960
3ea6e0ec 961 // Manage whether individual windows or subsizers are considered
d14a1e28
RD
962 // in the layout calculations or not.
963
964 %extend {
3ea6e0ec 965 DocAStr(Show,
a72f4631 966 "Show(self, item, bool show=True, bool recursive=false) -> bool",
3ea6e0ec
RD
967 "Shows or hides an item managed by the sizer. To make a sizer item
968disappear or reappear, use Show followed by `Layout`. The *item*
969parameter can be either a window, a sizer, or the zero-based index of
8f214674
RD
970the item. Use the recursive parameter to show or hide an item in a
971subsizer. Returns True if the item was found.", "");
a72f4631 972 bool Show(PyObject* item, bool show = true, bool recursive=false) {
6e6b3557 973 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 974 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
019fd9d3 975 wxPyEndBlockThreads(blocked);
d14a1e28 976 if ( info.window )
8f214674 977 return self->Show(info.window, show, recursive);
d14a1e28 978 else if ( info.sizer )
8f214674 979 return self->Show(info.sizer, show, recursive);
3ea6e0ec 980 else if ( info.gotPos )
8f214674 981 return self->Show(info.pos, show);
5f476690
RD
982 else
983 return false;
d14a1e28 984 }
7e8f0df9 985
3ea6e0ec
RD
986 DocAStr(IsShown,
987 "IsShown(self, item)",
95109042 988 "Determines if the item is currently shown. To make a sizer
3ea6e0ec
RD
989item disappear or reappear, use Show followed by `Layout`. The *item*
990parameter can be either a window, a sizer, or the zero-based index of
991the item.", "");
d14a1e28 992 bool IsShown(PyObject* item) {
6e6b3557 993 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 994 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, false);
019fd9d3 995 wxPyEndBlockThreads(blocked);
7e8f0df9 996 if ( info.window )
d14a1e28 997 return self->IsShown(info.window);
7e8f0df9 998 else if ( info.sizer )
d14a1e28 999 return self->IsShown(info.sizer);
3ea6e0ec
RD
1000 else if ( info.gotPos )
1001 return self->IsShown(info.pos);
d14a1e28 1002 else
a72f4631 1003 return false;
d14a1e28
RD
1004 }
1005 }
1006
3ea6e0ec 1007 %pythoncode {
41b78a7a 1008 def Hide(self, item, recursive=False):
3ea6e0ec 1009 """
d5a7caf6 1010 A convenience method for `Show` (item, False, recursive).
3ea6e0ec 1011 """
9dcf02b4 1012 return self.Show(item, False, recursive)
3ea6e0ec 1013 }
d14a1e28 1014
7e8f0df9 1015
3ea6e0ec
RD
1016 DocDeclStr(
1017 void , ShowItems(bool show),
e2837d11 1018 "Recursively call `wx.SizerItem.Show` on all sizer items.", "");
7e8f0df9 1019
d14a1e28
RD
1020};
1021
1022
1023//---------------------------------------------------------------------------
1024// Use this one for deriving Python classes from
1025%{
7e8f0df9 1026// See pyclasses.h
d14a1e28
RD
1027IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
1028IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
1029IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
1030%}
1031
1032
3ea6e0ec
RD
1033DocStr(wxPySizer,
1034"wx.PySizer is a special version of `wx.Sizer` that has been
1035instrumented to allow the C++ virtual methods to be overloaded in
1036Python derived classes. You would derive from this class if you are
1037wanting to implement a custom sizer in Python code. Simply implement
1038`CalcMin` and `RecalcSizes` in the derived class and you're all set.
1039For example::
1040
1041 class MySizer(wx.PySizer):
1042 def __init__(self):
1043 wx.PySizer.__init__(self)
1044
1045 def CalcMin(self):
1046 for item in self.GetChildren():
1047 # calculate the total minimum width and height needed
1048 # by all items in the sizer according to this sizer's
1049 # layout algorithm.
1050 ...
1051 return wx.Size(width, height)
1052
1053 def RecalcSizes(self):
1054 # find the space allotted to this sizer
1055 pos = self.GetPosition()
1056 size = self.GetSize()
1057 for item in self.GetChildren():
1058 # Recalculate (if necessary) the position and size of
1059 # each item and then call item.SetDimension to do the
1060 # actual positioning and sizing of the items within the
1061 # space alloted to this sizer.
1062 ...
1063 item.SetDimension(itemPos, itemSize)
1064
1065
1066When `Layout` is called it first calls `CalcMin` followed by
1067`RecalcSizes` so you can optimize a bit by saving the results of
9283228f 1068`CalcMin` and reusing them in `RecalcSizes`.
3ea6e0ec
RD
1069
1070:see: `wx.SizerItem`, `wx.Sizer.GetChildren`
1071
1072", "");
d14a1e28
RD
1073class wxPySizer : public wxSizer {
1074public:
2b9048c5 1075 %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)"
d14a1e28 1076
3ea6e0ec
RD
1077 DocCtorStr(
1078 wxPySizer(),
1079 "Creates a wx.PySizer. Must be called from the __init__ in the derived
1080class.", "");
7e8f0df9 1081
d14a1e28
RD
1082 void _setCallbackInfo(PyObject* self, PyObject* _class);
1083};
1084
1085
1086//---------------------------------------------------------------------------
1087%newgroup;
1088
3ea6e0ec
RD
1089
1090DocStr(wxBoxSizer,
1091"The basic idea behind a box sizer is that windows will most often be
1092laid out in rather simple basic geometry, typically in a row or a
1093column or nested hierarchies of either. A wx.BoxSizer will lay out
1094its items in a simple row or column, depending on the orientation
1095parameter passed to the constructor.", "
1096
1097It is the unique feature of a box sizer, that it can grow in both
1098directions (height and width) but can distribute its growth in the
1099main direction (horizontal for a row) *unevenly* among its children.
1100This is determined by the proportion parameter give to items when they
1101are added to the sizer. It is interpreted as a weight factor, i.e. it
1102can be zero, indicating that the window may not be resized at all, or
1103above zero. If several windows have a value above zero, the value is
1104interpreted relative to the sum of all weight factors of the sizer, so
1105when adding two windows with a value of 1, they will both get resized
1106equally and each will receive half of the available space after the
1107fixed size items have been sized. If the items have unequal
1108proportion settings then they will receive a coresondingly unequal
1109allotment of the free space.
1110
1111:see: `wx.StaticBoxSizer`
1112");
1113
d14a1e28
RD
1114class wxBoxSizer : public wxSizer {
1115public:
2b9048c5 1116 %pythonAppend wxBoxSizer "self._setOORInfo(self)"
d14a1e28 1117
3ea6e0ec
RD
1118 DocCtorStr(
1119 wxBoxSizer(int orient = wxHORIZONTAL),
1120 "Constructor for a wx.BoxSizer. *orient* may be one of ``wx.VERTICAL``
1121or ``wx.HORIZONTAL`` for creating either a column sizer or a row
1122sizer.", "");
d14a1e28 1123
7e8f0df9 1124
3ea6e0ec
RD
1125 DocDeclStr(
1126 int , GetOrientation(),
1127 "Returns the current orientation of the sizer.", "");
7e8f0df9 1128
3ea6e0ec
RD
1129 DocDeclStr(
1130 void , SetOrientation(int orient),
1131 "Resets the orientation of the sizer.", "");
7e8f0df9 1132
0eae5d09 1133 %property(Orientation, GetOrientation, SetOrientation, doc="See `GetOrientation` and `SetOrientation`");
d14a1e28
RD
1134};
1135
1136//---------------------------------------------------------------------------
1137%newgroup;
1138
3ea6e0ec
RD
1139
1140DocStr(wxStaticBoxSizer,
1141"wx.StaticBoxSizer derives from and functions identically to the
1142`wx.BoxSizer` and adds a `wx.StaticBox` around the items that the sizer
1143manages. Note that this static box must be created separately and
1144passed to the sizer constructor.", "");
1145
d14a1e28
RD
1146class wxStaticBoxSizer : public wxBoxSizer {
1147public:
2b9048c5 1148 %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)"
d14a1e28 1149
3ea6e0ec
RD
1150 DocCtorStr(
1151 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL),
1152 "Constructor. It takes an associated static box and the orientation
1153*orient* as parameters - orient can be either of ``wx.VERTICAL`` or
1154``wx.HORIZONTAL``.", "");
39d160c3
RD
1155
1156 // TODO: wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString);
7e8f0df9 1157
39d160c3
RD
1158 DocDeclStr(
1159 wxStaticBox *, GetStaticBox(),
1160 "Returns the static box associated with this sizer.", "");
7e8f0df9 1161
d14a1e28
RD
1162};
1163
1164//---------------------------------------------------------------------------
1165%newgroup;
1166
3ea6e0ec
RD
1167
1168DocStr(wxGridSizer,
1169"A grid sizer is a sizer which lays out its children in a
1170two-dimensional table with all cells having the same size. In other
1171words, the width of each cell within the grid is the width of the
1172widest item added to the sizer and the height of each grid cell is the
1173height of the tallest item. An optional vertical and/or horizontal
1174gap between items can also be specified (in pixels.)
1175
1176Items are placed in the cells of the grid in the order they are added,
1177in row-major order. In other words, the first row is filled first,
1178then the second, and so on until all items have been added. (If
1179neccessary, additional rows will be added as items are added.) If you
1180need to have greater control over the cells that items are placed in
1181then use the `wx.GridBagSizer`.
1182", "");
1183
d14a1e28
RD
1184class wxGridSizer: public wxSizer
1185{
1186public:
2b9048c5 1187 %pythonAppend wxGridSizer "self._setOORInfo(self)"
d14a1e28 1188
3ea6e0ec
RD
1189 DocCtorStr(
1190 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ),
1191 "Constructor for a wx.GridSizer. *rows* and *cols* determine the number
1192of columns and rows in the sizer - if either of the parameters is
1193zero, it will be calculated to from the total number of children in
1194the sizer, thus making the sizer grow dynamically. *vgap* and *hgap*
1195define extra space between all children.", "");
1196
1197 DocDeclStr(
1198 void , SetCols( int cols ),
1199 "Sets the number of columns in the sizer.", "");
7e8f0df9 1200
3ea6e0ec
RD
1201 DocDeclStr(
1202 void , SetRows( int rows ),
1203 "Sets the number of rows in the sizer.", "");
7e8f0df9 1204
3ea6e0ec
RD
1205 DocDeclStr(
1206 void , SetVGap( int gap ),
1207 "Sets the vertical gap (in pixels) between the cells in the sizer.", "");
7e8f0df9 1208
3ea6e0ec
RD
1209 DocDeclStr(
1210 void , SetHGap( int gap ),
1211 "Sets the horizontal gap (in pixels) between cells in the sizer", "");
7e8f0df9 1212
3ea6e0ec
RD
1213 DocDeclStr(
1214 int , GetCols(),
1215 "Returns the number of columns in the sizer.", "");
7e8f0df9 1216
3ea6e0ec
RD
1217 DocDeclStr(
1218 int , GetRows(),
1219 "Returns the number of rows in the sizer.", "");
7e8f0df9 1220
3ea6e0ec
RD
1221 DocDeclStr(
1222 int , GetVGap(),
1223 "Returns the vertical gap (in pixels) between the cells in the sizer.", "");
7e8f0df9 1224
3ea6e0ec
RD
1225 DocDeclStr(
1226 int , GetHGap(),
1227 "Returns the horizontal gap (in pixels) between cells in the sizer.", "");
7e8f0df9 1228
c86fa5a1
RD
1229 %pythoncode {
1230 def CalcRowsCols(self):
1231 """
1232 CalcRowsCols() -> (rows, cols)
1233
1234 Calculates how many rows and columns will be in the sizer based
1235 on the current number of items and also the rows, cols specified
1236 in the constructor.
1237 """
1238 nitems = len(self.GetChildren())
1239 rows = self.GetRows()
1240 cols = self.GetCols()
1241 assert rows != 0 or cols != 0, "Grid sizer must have either rows or columns fixed"
1242 if cols != 0:
1243 rows = (nitems + cols - 1) / cols
1244 elif rows != 0:
1245 cols = (nitems + rows - 1) / rows
1246 return (rows, cols)
1247 }
76b8fa1d
RD
1248
1249 %property(Cols, GetCols, SetCols, doc="See `GetCols` and `SetCols`");
1250 %property(HGap, GetHGap, SetHGap, doc="See `GetHGap` and `SetHGap`");
1251 %property(Rows, GetRows, SetRows, doc="See `GetRows` and `SetRows`");
1252 %property(VGap, GetVGap, SetVGap, doc="See `GetVGap` and `SetVGap`");
d14a1e28
RD
1253};
1254
1255//---------------------------------------------------------------------------
1256%newgroup;
1257
1258enum wxFlexSizerGrowMode
1259{
1260 // don't resize the cells in non-flexible direction at all
1261 wxFLEX_GROWMODE_NONE,
1262
1263 // uniformly resize only the specified ones (default)
1264 wxFLEX_GROWMODE_SPECIFIED,
1265
1266 // uniformly resize all cells
1267 wxFLEX_GROWMODE_ALL
1268};
1269
1270
3ea6e0ec
RD
1271
1272
1273
1274DocStr(wxFlexGridSizer,
1275"A flex grid sizer is a sizer which lays out its children in a
1276two-dimensional table with all table cells in one row having the same
1277height and all cells in one column having the same width, but all
1278rows or all columns are not necessarily the same height or width as in
1279the `wx.GridSizer`.
1280
1281wx.FlexGridSizer can also size items equally in one direction but
1282unequally (\"flexibly\") in the other. If the sizer is only flexible
1283in one direction (this can be changed using `SetFlexibleDirection`), it
1284needs to be decided how the sizer should grow in the other (\"non
1285flexible\") direction in order to fill the available space. The
1286`SetNonFlexibleGrowMode` method serves this purpose.
1287
1288", "");
1289
d14a1e28
RD
1290class wxFlexGridSizer: public wxGridSizer
1291{
1292public:
2b9048c5 1293 %pythonAppend wxFlexGridSizer "self._setOORInfo(self)"
d14a1e28 1294
3ea6e0ec
RD
1295 DocCtorStr(
1296 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ),
1297 "Constructor for a wx.FlexGridSizer. *rows* and *cols* determine the
1298number of columns and rows in the sizer - if either of the parameters
1299is zero, it will be calculated to from the total number of children in
1300the sizer, thus making the sizer grow dynamically. *vgap* and *hgap*
1301define extra space between all children.", "");
7e8f0df9 1302
3ea6e0ec
RD
1303
1304 DocDeclStr(
1305 void , AddGrowableRow( size_t idx, int proportion = 0 ),
1306 "Specifies that row *idx* (starting from zero) should be grown if there
1307is extra space available to the sizer.
1308
1309The *proportion* parameter has the same meaning as the stretch factor
1310for the box sizers except that if all proportions are 0, then all
1311columns are resized equally (instead of not being resized at all).", "");
7e8f0df9 1312
3ea6e0ec
RD
1313 DocDeclStr(
1314 void , RemoveGrowableRow( size_t idx ),
1315 "Specifies that row *idx* is no longer growable.", "");
7e8f0df9 1316
3ea6e0ec
RD
1317 DocDeclStr(
1318 void , AddGrowableCol( size_t idx, int proportion = 0 ),
1319 "Specifies that column *idx* (starting from zero) should be grown if
1320there is extra space available to the sizer.
1321
1322The *proportion* parameter has the same meaning as the stretch factor
1323for the box sizers except that if all proportions are 0, then all
1324columns are resized equally (instead of not being resized at all).", "");
7e8f0df9 1325
3ea6e0ec
RD
1326 DocDeclStr(
1327 void , RemoveGrowableCol( size_t idx ),
1328 "Specifies that column *idx* is no longer growable.", "");
7e8f0df9 1329
3ea6e0ec
RD
1330
1331 DocDeclStr(
1332 void , SetFlexibleDirection(int direction),
1333 "Specifies whether the sizer should flexibly resize its columns, rows,
1334or both. Argument *direction* can be one of the following values. Any
1335other value is ignored.
1336
1337 ============== =======================================
1338 wx.VERTICAL Rows are flexibly sized.
1339 wx.HORIZONTAL Columns are flexibly sized.
1340 wx.BOTH Both rows and columns are flexibly sized
1341 (this is the default value).
1342 ============== =======================================
1343
1344Note that this method does not trigger relayout.
1345", "");
7e8f0df9 1346
3ea6e0ec
RD
1347 DocDeclStr(
1348 int , GetFlexibleDirection(),
1349 "Returns a value that specifies whether the sizer
1350flexibly resizes its columns, rows, or both (default).
d14a1e28 1351
3ea6e0ec 1352:see: `SetFlexibleDirection`", "");
d14a1e28 1353
7e8f0df9 1354
d14a1e28 1355
3ea6e0ec
RD
1356 DocDeclStr(
1357 void , SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode),
1358 "Specifies how the sizer should grow in the non-flexible direction if
1359there is one (so `SetFlexibleDirection` must have been called
1360previously). Argument *mode* can be one of the following values:
1361
1362 ========================== =================================================
1363 wx.FLEX_GROWMODE_NONE Sizer doesn't grow in the non flexible direction.
1364 wx.FLEX_GROWMODE_SPECIFIED Sizer honors growable columns/rows set with
1365 `AddGrowableCol` and `AddGrowableRow`. In this
1366 case equal sizing applies to minimum sizes of
1367 columns or rows (this is the default value).
1368 wx.FLEX_GROWMODE_ALL Sizer equally stretches all columns or rows in
1369 the non flexible direction, whether they are
1370 growable or not in the flexbile direction.
1371 ========================== =================================================
1372
42e2bbb9 1373Note that this method does not trigger relayout.", "");
7e8f0df9 1374
3ea6e0ec
RD
1375 DocDeclStr(
1376 wxFlexSizerGrowMode , GetNonFlexibleGrowMode(),
1377 "Returns the value that specifies how the sizer grows in the
1378non-flexible direction if there is one.
d14a1e28 1379
3ea6e0ec 1380:see: `SetNonFlexibleGrowMode`", "");
7e8f0df9 1381
dd9f7fea
RD
1382
1383 // Read-only access to the row heights and col widths arrays
3ea6e0ec
RD
1384 DocDeclAStr(
1385 const wxArrayInt& , GetRowHeights() const,
1386 "GetRowHeights(self) -> list",
1387 "Returns a list of integers representing the heights of each of the
1388rows in the sizer.", "");
7e8f0df9 1389
3ea6e0ec
RD
1390 DocDeclAStr(
1391 const wxArrayInt& , GetColWidths() const,
1392 "GetColWidths(self) -> list",
1393 "Returns a list of integers representing the widths of each of the
1394columns in the sizer.", "");
7e8f0df9 1395
42e2bbb9
RD
1396
1397 %property(ColWidths, GetColWidths, doc="See `GetColWidths`");
1398 %property(FlexibleDirection, GetFlexibleDirection, SetFlexibleDirection, doc="See `GetFlexibleDirection` and `SetFlexibleDirection`");
1399 %property(NonFlexibleGrowMode, GetNonFlexibleGrowMode, SetNonFlexibleGrowMode, doc="See `GetNonFlexibleGrowMode` and `SetNonFlexibleGrowMode`");
1400 %property(RowHeights, GetRowHeights, doc="See `GetRowHeights`");
1401
d14a1e28
RD
1402};
1403
9283228f
RD
1404//---------------------------------------------------------------------------
1405
1406DocStr(wxStdDialogButtonSizer,
1407"A special sizer that knows how to order and position standard buttons
1408in order to conform to the current platform's standards. You simply
1409need to add each `wx.Button` to the sizer, and be sure to create the
718903fe 1410buttons using the standard ID's. Then call `Realize` and the sizer
9283228f
RD
1411will take care of the rest.
1412", "");
1413
1414class wxStdDialogButtonSizer: public wxBoxSizer
1415{
1416public:
1417 DocCtorStr(
1418 wxStdDialogButtonSizer(),
1419 "", "");
1420
1421 DocDeclStr(
1422 void , AddButton(wxButton *button),
1423 "Use this to add the buttons to this sizer. Do not use the `Add`
1424method in the base class.", "");
7e8f0df9 1425
9283228f 1426 DocDeclStr(
718903fe 1427 void , Realize(),
9283228f
RD
1428 "This funciton needs to be called after all the buttons have been added
1429to the sizer. It will reorder them and position them in a platform
1430specifc manner.", "");
3ba93175
RD
1431
1432 void SetAffirmativeButton( wxButton *button );
1433 void SetNegativeButton( wxButton *button );
1434 void SetCancelButton( wxButton *button );
7e8f0df9 1435
9283228f
RD
1436 wxButton* GetAffirmativeButton() const;
1437 wxButton* GetApplyButton() const;
1438 wxButton* GetNegativeButton() const;
1439 wxButton* GetCancelButton() const;
1440 wxButton* GetHelpButton() const;
1441};
1442
1443
d14a1e28 1444//---------------------------------------------------------------------------