]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_sizers.i
Premultiply the alpha on wxMSW in the BitmapFromBuffer* functions so
[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
RD
610
611 DocAStr(Remove,
612 "Remove(self, item) -> bool",
613 "Removes an item from the sizer and destroys it. This method does not
614cause any layout or resizing to take place, call `Layout` to update
615the layout on screen after removing a child from the sizer. The
616*item* parameter can be either a window, a sizer, or the zero-based
617index of an item to remove. Returns True if the child item was found
618and removed.", "
619
620:note: For historical reasons calling this method with a `wx.Window`
621 parameter is depreacted, as it will not be able to destroy the
622 window since it is owned by its parent. You should use `Detach`
623 instead.
624");
d14a1e28 625 bool Remove(PyObject* item) {
6e6b3557 626 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 627 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
da32eb53 628 wxPyEndBlockThreads(blocked);
d14a1e28
RD
629 if ( info.window )
630 return self->Remove(info.window);
631 else if ( info.sizer )
632 return self->Remove(info.sizer);
633 else if ( info.gotPos )
634 return self->Remove(info.pos);
7e8f0df9 635 else
a72f4631 636 return false;
d14a1e28
RD
637 }
638
3ea6e0ec
RD
639
640 DocAStr(Detach,
641 "Detach(self, item) -> bool",
642 "Detaches an item from the sizer without destroying it. This method
643does not cause any layout or resizing to take place, call `Layout` to
644do so. The *item* parameter can be either a window, a sizer, or the
645zero-based index of the item to be detached. Returns True if the child item
646was found and detached.", "");
60a71c29 647 bool Detach(PyObject* item) {
6e6b3557 648 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 649 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
60a71c29
RD
650 wxPyEndBlockThreads(blocked);
651 if ( info.window )
652 return self->Detach(info.window);
653 else if ( info.sizer )
654 return self->Detach(info.sizer);
655 else if ( info.gotPos )
656 return self->Detach(info.pos);
7e8f0df9 657 else
a72f4631 658 return false;
60a71c29
RD
659 }
660
7e8f0df9 661
7aada1e0
RD
662 DocAStr(GetItem,
663 "GetItem(self, item) -> wx.SizerItem",
664 "Returns the `wx.SizerItem` which holds the *item* given. The *item*
665parameter can be either a window, a sizer, or the zero-based index of
aae5d34f 666the item to be found.", "");
7aada1e0 667 wxSizerItem* GetItem(PyObject* item) {
6e6b3557 668 wxPyBlock_t blocked = wxPyBeginBlockThreads();
7aada1e0
RD
669 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
670 wxPyEndBlockThreads(blocked);
671 if ( info.window )
672 return self->GetItem(info.window);
673 else if ( info.sizer )
674 return self->GetItem(info.sizer);
675 else if ( info.gotPos )
676 return self->GetItem(info.pos);
677 else
678 return NULL;
679 }
680
7e8f0df9 681
dd9f7fea 682 void _SetItemMinSize(PyObject* item, const wxSize& size) {
6e6b3557 683 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 684 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
da32eb53 685 wxPyEndBlockThreads(blocked);
d14a1e28
RD
686 if ( info.window )
687 self->SetItemMinSize(info.window, size);
688 else if ( info.sizer )
689 self->SetItemMinSize(info.sizer, size);
690 else if ( info.gotPos )
691 self->SetItemMinSize(info.pos, size);
692 }
693 }
694
3ea6e0ec
RD
695 %pythoncode {
696 def SetItemMinSize(self, item, *args):
697 """
698 SetItemMinSize(self, item, Size size)
699
700 Sets the minimum size that will be allocated for an item in the sizer.
701 The *item* parameter can be either a window, a sizer, or the
702 zero-based index of the item. If a window or sizer is given then it
703 will be searched for recursivly in subsizers if neccessary.
704 """
705 if len(args) == 2:
706 %# for backward compatibility accept separate width,height args too
707 return self._SetItemMinSize(item, args)
708 else:
709 return self._SetItemMinSize(item, args[0])
710 }
7e8f0df9 711
214c4fbe
RD
712
713 %disownarg( wxSizerItem *item );
714
3ea6e0ec 715 DocDeclAStrName(
7aada1e0 716 wxSizerItem* , Add( wxSizerItem *item ),
3ea6e0ec
RD
717 "AddItem(self, SizerItem item)",
718 "Adds a `wx.SizerItem` to the sizer.", "",
719 AddItem);
7e8f0df9 720
3ea6e0ec 721 DocDeclAStrName(
7aada1e0 722 wxSizerItem* , Insert( size_t index, wxSizerItem *item ),
3ea6e0ec
RD
723 "InsertItem(self, int index, SizerItem item)",
724 "Inserts a `wx.SizerItem` to the sizer at the position given by *index*.", "",
725 InsertItem);
7e8f0df9 726
3ea6e0ec 727 DocDeclAStrName(
7aada1e0 728 wxSizerItem* , Prepend( wxSizerItem *item ),
3ea6e0ec
RD
729 "PrependItem(self, SizerItem item)",
730 "Prepends a `wx.SizerItem` to the sizer.", "",
731 PrependItem);
7e8f0df9 732
214c4fbe 733 %cleardisown( wxSizerItem *item );
d14a1e28
RD
734
735
736 %pythoncode {
3ea6e0ec 737 def AddMany(self, items):
dce2bd22
RD
738 """
739 AddMany is a convenience method for adding several items
740 to a sizer at one time. Simply pass it a list of tuples,
741 where each tuple consists of the parameters that you
742 would normally pass to the `Add` method.
743 """
3ea6e0ec
RD
744 for item in items:
745 if type(item) != type(()) or (len(item) == 2 and type(item[0]) == type(1)):
746 item = (item, )
747 self.Add(*item)
d14a1e28 748
d147c724 749 %# for backwards compatibility only, please do not use in new code
7e8f0df9
RD
750 def AddWindow(self, *args, **kw):
751 """Compatibility alias for `Add`."""
752 return self.Add(*args, **kw)
753 def AddSizer(self, *args, **kw):
754 """Compatibility alias for `Add`."""
755 return self.Add(*args, **kw)
756 def AddSpacer(self, *args, **kw):
757 """Compatibility alias for `Add`."""
758 return self.Add(*args, **kw)
759
760 def PrependWindow(self, *args, **kw):
761 """Compatibility alias for `Prepend`."""
762 return self.Prepend(*args, **kw)
763 def PrependSizer(self, *args, **kw):
764 """Compatibility alias for `Prepend`."""
765 return self.Prepend(*args, **kw)
766 def PrependSpacer(self, *args, **kw):
767 """Compatibility alias for `Prepend`."""
768 return self.Prepend(*args, **kw)
769
770 def InsertWindow(self, *args, **kw):
771 """Compatibility alias for `Insert`."""
772 return self.Insert(*args, **kw)
773 def InsertSizer(self, *args, **kw):
774 """Compatibility alias for `Insert`."""
775 return self.Insert(*args, **kw)
776 def InsertSpacer(self, *args, **kw):
777 """Compatibility alias for `Insert`."""
778 return self.Insert(*args, **kw)
779
780 def RemoveWindow(self, *args, **kw):
781 """Compatibility alias for `Remove`."""
782 return self.Remove(*args, **kw)
783 def RemoveSizer(self, *args, **kw):
784 """Compatibility alias for `Remove`."""
785 return self.Remove(*args, **kw)
786 def RemovePos(self, *args, **kw):
787 """Compatibility alias for `Remove`."""
788 return self.Remove(*args, **kw)
d14a1e28 789
d14a1e28
RD
790 }
791
792
3ea6e0ec
RD
793 DocDeclStr(
794 void , SetDimension( int x, int y, int width, int height ),
795 "Call this to force the sizer to take the given dimension and thus
796force the items owned by the sizer to resize themselves according to
797the rules defined by the parameter in the `Add`, `Insert` or `Prepend`
798methods.", "");
7e8f0df9 799
3ea6e0ec
RD
800 DocDeclStr(
801 void , SetMinSize( const wxSize &size ),
802 "Call this to give the sizer a minimal size. Normally, the sizer will
803calculate its minimal size based purely on how much space its children
804need. After calling this method `GetMinSize` will return either the
805minimal size as requested by its children or the minimal size set
806here, depending on which is bigger.", "");
7e8f0df9 807
d14a1e28 808
3ea6e0ec
RD
809 DocDeclStr(
810 wxSize , GetSize(),
811 "Returns the current size of the space managed by the sizer.", "");
7e8f0df9 812
3ea6e0ec
RD
813 DocDeclStr(
814 wxPoint , GetPosition(),
815 "Returns the current position of the sizer's managed space.", "");
7e8f0df9 816
3ea6e0ec
RD
817 DocDeclStr(
818 wxSize , GetMinSize(),
819 "Returns the minimal size of the sizer. This is either the combined
820minimal size of all the children and their borders or the minimal size
821set by SetMinSize, depending on which is bigger.", "");
7e8f0df9 822
d14a1e28
RD
823
824 %pythoncode {
825 def GetSizeTuple(self):
60a71c29 826 return self.GetSize().Get()
d14a1e28 827 def GetPositionTuple(self):
60a71c29 828 return self.GetPosition().Get()
d14a1e28 829 def GetMinSizeTuple(self):
60a71c29 830 return self.GetMinSize().Get()
d14a1e28
RD
831 }
832
3ea6e0ec
RD
833 DocDeclStr(
834 virtual void , RecalcSizes(),
835 "Using the sizes calculated by `CalcMin` reposition and resize all the
836items managed by this sizer. You should not need to call this directly as
837it is called by `Layout`.", "");
7e8f0df9 838
3ea6e0ec
RD
839 DocDeclStr(
840 virtual wxSize , CalcMin(),
841 "This method is where the sizer will do the actual calculation of its
842children's minimal sizes. You should not need to call this directly as
843it is called by `Layout`.", "");
7e8f0df9 844
3ea6e0ec
RD
845
846 DocDeclStr(
847 void , Layout(),
848 "This method will force the recalculation and layout of the items
849controlled by the sizer using the current space allocated to the
850sizer. Normally this is called automatically from the owning window's
851EVT_SIZE handler, but it is also useful to call it from user code when
852one of the items in a sizer change size, or items are added or
853removed.", "");
7e8f0df9 854
d14a1e28 855
3ea6e0ec
RD
856 DocDeclStr(
857 wxSize , Fit( wxWindow *window ),
858 "Tell the sizer to resize the *window* to match the sizer's minimal
859size. This is commonly done in the constructor of the window itself in
860order to set its initial size to match the needs of the children as
861determined by the sizer. Returns the new size.
d14a1e28 862
3ea6e0ec 863For a top level window this is the total window size, not the client size.", "");
7e8f0df9 864
3ea6e0ec
RD
865 DocDeclStr(
866 void , FitInside( wxWindow *window ),
867 "Tell the sizer to resize the *virtual size* of the *window* to match the
868sizer's minimal size. This will not alter the on screen size of the
869window, but may cause the addition/removal/alteration of scrollbars
870required to view the virtual area in windows which manage it.
871
872:see: `wx.ScrolledWindow.SetScrollbars`, `SetVirtualSizeHints`
873", "");
7e8f0df9 874
d14a1e28 875
3ea6e0ec
RD
876 DocDeclStr(
877 void , SetSizeHints( wxWindow *window ),
878 "Tell the sizer to set (and `Fit`) the minimal size of the *window* to
879match the sizer's minimal size. This is commonly done in the
880constructor of the window itself if the window is resizable (as are
881many dialogs under Unix and frames on probably all platforms) in order
882to prevent the window from being sized smaller than the minimal size
883required by the sizer.", "");
7e8f0df9 884
3ea6e0ec
RD
885 DocDeclStr(
886 void , SetVirtualSizeHints( wxWindow *window ),
887 "Tell the sizer to set the minimal size of the window virtual area to
888match the sizer's minimal size. For windows with managed scrollbars
889this will set them appropriately.
890
891:see: `wx.ScrolledWindow.SetScrollbars`
892", "");
7e8f0df9 893
d14a1e28 894
3ea6e0ec 895 DocDeclStr(
a72f4631 896 void , Clear( bool deleteWindows=false ),
3ea6e0ec
RD
897 "Clear all items from the sizer, optionally destroying the window items
898as well.", "");
7e8f0df9 899
3ea6e0ec
RD
900 DocDeclStr(
901 void , DeleteWindows(),
902 "Destroy all windows managed by the sizer.", "");
7e8f0df9 903
d14a1e28
RD
904
905
906 // wxList& GetChildren();
907 %extend {
3ea6e0ec 908 DocAStr(GetChildren,
50ed1e35 909 "GetChildren(self) -> list",
3ea6e0ec 910 "Returns a list of all the `wx.SizerItem` objects managed by the sizer.", "");
d14a1e28
RD
911 PyObject* GetChildren() {
912 wxSizerItemList& list = self->GetChildren();
913 return wxPy_ConvertList(&list);
914 }
915 }
916
917
3ea6e0ec 918 // Manage whether individual windows or subsizers are considered
d14a1e28
RD
919 // in the layout calculations or not.
920
921 %extend {
3ea6e0ec 922 DocAStr(Show,
a72f4631 923 "Show(self, item, bool show=True, bool recursive=false) -> bool",
3ea6e0ec
RD
924 "Shows or hides an item managed by the sizer. To make a sizer item
925disappear or reappear, use Show followed by `Layout`. The *item*
926parameter can be either a window, a sizer, or the zero-based index of
8f214674
RD
927the item. Use the recursive parameter to show or hide an item in a
928subsizer. Returns True if the item was found.", "");
a72f4631 929 bool Show(PyObject* item, bool show = true, bool recursive=false) {
6e6b3557 930 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 931 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, true);
019fd9d3 932 wxPyEndBlockThreads(blocked);
d14a1e28 933 if ( info.window )
8f214674 934 return self->Show(info.window, show, recursive);
d14a1e28 935 else if ( info.sizer )
8f214674 936 return self->Show(info.sizer, show, recursive);
3ea6e0ec 937 else if ( info.gotPos )
8f214674 938 return self->Show(info.pos, show);
5f476690
RD
939 else
940 return false;
d14a1e28 941 }
7e8f0df9 942
3ea6e0ec
RD
943 DocAStr(IsShown,
944 "IsShown(self, item)",
95109042 945 "Determines if the item is currently shown. To make a sizer
3ea6e0ec
RD
946item disappear or reappear, use Show followed by `Layout`. The *item*
947parameter can be either a window, a sizer, or the zero-based index of
948the item.", "");
d14a1e28 949 bool IsShown(PyObject* item) {
6e6b3557 950 wxPyBlock_t blocked = wxPyBeginBlockThreads();
a72f4631 951 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, false, false);
019fd9d3 952 wxPyEndBlockThreads(blocked);
7e8f0df9 953 if ( info.window )
d14a1e28 954 return self->IsShown(info.window);
7e8f0df9 955 else if ( info.sizer )
d14a1e28 956 return self->IsShown(info.sizer);
3ea6e0ec
RD
957 else if ( info.gotPos )
958 return self->IsShown(info.pos);
d14a1e28 959 else
a72f4631 960 return false;
d14a1e28
RD
961 }
962 }
963
3ea6e0ec 964 %pythoncode {
41b78a7a 965 def Hide(self, item, recursive=False):
3ea6e0ec 966 """
d5a7caf6 967 A convenience method for `Show` (item, False, recursive).
3ea6e0ec 968 """
9dcf02b4 969 return self.Show(item, False, recursive)
3ea6e0ec 970 }
d14a1e28 971
7e8f0df9 972
3ea6e0ec
RD
973 DocDeclStr(
974 void , ShowItems(bool show),
e2837d11 975 "Recursively call `wx.SizerItem.Show` on all sizer items.", "");
7e8f0df9 976
d14a1e28
RD
977};
978
979
980//---------------------------------------------------------------------------
981// Use this one for deriving Python classes from
982%{
7e8f0df9 983// See pyclasses.h
d14a1e28
RD
984IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
985IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
986IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
987%}
988
989
3ea6e0ec
RD
990DocStr(wxPySizer,
991"wx.PySizer is a special version of `wx.Sizer` that has been
992instrumented to allow the C++ virtual methods to be overloaded in
993Python derived classes. You would derive from this class if you are
994wanting to implement a custom sizer in Python code. Simply implement
995`CalcMin` and `RecalcSizes` in the derived class and you're all set.
996For example::
997
998 class MySizer(wx.PySizer):
999 def __init__(self):
1000 wx.PySizer.__init__(self)
1001
1002 def CalcMin(self):
1003 for item in self.GetChildren():
1004 # calculate the total minimum width and height needed
1005 # by all items in the sizer according to this sizer's
1006 # layout algorithm.
1007 ...
1008 return wx.Size(width, height)
1009
1010 def RecalcSizes(self):
1011 # find the space allotted to this sizer
1012 pos = self.GetPosition()
1013 size = self.GetSize()
1014 for item in self.GetChildren():
1015 # Recalculate (if necessary) the position and size of
1016 # each item and then call item.SetDimension to do the
1017 # actual positioning and sizing of the items within the
1018 # space alloted to this sizer.
1019 ...
1020 item.SetDimension(itemPos, itemSize)
1021
1022
1023When `Layout` is called it first calls `CalcMin` followed by
1024`RecalcSizes` so you can optimize a bit by saving the results of
9283228f 1025`CalcMin` and reusing them in `RecalcSizes`.
3ea6e0ec
RD
1026
1027:see: `wx.SizerItem`, `wx.Sizer.GetChildren`
1028
1029", "");
d14a1e28
RD
1030class wxPySizer : public wxSizer {
1031public:
2b9048c5 1032 %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)"
d14a1e28 1033
3ea6e0ec
RD
1034 DocCtorStr(
1035 wxPySizer(),
1036 "Creates a wx.PySizer. Must be called from the __init__ in the derived
1037class.", "");
7e8f0df9 1038
d14a1e28
RD
1039 void _setCallbackInfo(PyObject* self, PyObject* _class);
1040};
1041
1042
1043//---------------------------------------------------------------------------
1044%newgroup;
1045
3ea6e0ec
RD
1046
1047DocStr(wxBoxSizer,
1048"The basic idea behind a box sizer is that windows will most often be
1049laid out in rather simple basic geometry, typically in a row or a
1050column or nested hierarchies of either. A wx.BoxSizer will lay out
1051its items in a simple row or column, depending on the orientation
1052parameter passed to the constructor.", "
1053
1054It is the unique feature of a box sizer, that it can grow in both
1055directions (height and width) but can distribute its growth in the
1056main direction (horizontal for a row) *unevenly* among its children.
1057This is determined by the proportion parameter give to items when they
1058are added to the sizer. It is interpreted as a weight factor, i.e. it
1059can be zero, indicating that the window may not be resized at all, or
1060above zero. If several windows have a value above zero, the value is
1061interpreted relative to the sum of all weight factors of the sizer, so
1062when adding two windows with a value of 1, they will both get resized
1063equally and each will receive half of the available space after the
1064fixed size items have been sized. If the items have unequal
1065proportion settings then they will receive a coresondingly unequal
1066allotment of the free space.
1067
1068:see: `wx.StaticBoxSizer`
1069");
1070
d14a1e28
RD
1071class wxBoxSizer : public wxSizer {
1072public:
2b9048c5 1073 %pythonAppend wxBoxSizer "self._setOORInfo(self)"
d14a1e28 1074
3ea6e0ec
RD
1075 DocCtorStr(
1076 wxBoxSizer(int orient = wxHORIZONTAL),
1077 "Constructor for a wx.BoxSizer. *orient* may be one of ``wx.VERTICAL``
1078or ``wx.HORIZONTAL`` for creating either a column sizer or a row
1079sizer.", "");
d14a1e28 1080
7e8f0df9 1081
3ea6e0ec
RD
1082 DocDeclStr(
1083 int , GetOrientation(),
1084 "Returns the current orientation of the sizer.", "");
7e8f0df9 1085
3ea6e0ec
RD
1086 DocDeclStr(
1087 void , SetOrientation(int orient),
1088 "Resets the orientation of the sizer.", "");
7e8f0df9 1089
d14a1e28
RD
1090};
1091
1092//---------------------------------------------------------------------------
1093%newgroup;
1094
3ea6e0ec
RD
1095
1096DocStr(wxStaticBoxSizer,
1097"wx.StaticBoxSizer derives from and functions identically to the
1098`wx.BoxSizer` and adds a `wx.StaticBox` around the items that the sizer
1099manages. Note that this static box must be created separately and
1100passed to the sizer constructor.", "");
1101
d14a1e28
RD
1102class wxStaticBoxSizer : public wxBoxSizer {
1103public:
2b9048c5 1104 %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)"
d14a1e28 1105
3ea6e0ec
RD
1106 DocCtorStr(
1107 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL),
1108 "Constructor. It takes an associated static box and the orientation
1109*orient* as parameters - orient can be either of ``wx.VERTICAL`` or
1110``wx.HORIZONTAL``.", "");
39d160c3
RD
1111
1112 // TODO: wxStaticBoxSizer(int orient, wxWindow *win, const wxString& label = wxEmptyString);
7e8f0df9 1113
39d160c3
RD
1114 DocDeclStr(
1115 wxStaticBox *, GetStaticBox(),
1116 "Returns the static box associated with this sizer.", "");
7e8f0df9 1117
d14a1e28
RD
1118};
1119
1120//---------------------------------------------------------------------------
1121%newgroup;
1122
3ea6e0ec
RD
1123
1124DocStr(wxGridSizer,
1125"A grid sizer is a sizer which lays out its children in a
1126two-dimensional table with all cells having the same size. In other
1127words, the width of each cell within the grid is the width of the
1128widest item added to the sizer and the height of each grid cell is the
1129height of the tallest item. An optional vertical and/or horizontal
1130gap between items can also be specified (in pixels.)
1131
1132Items are placed in the cells of the grid in the order they are added,
1133in row-major order. In other words, the first row is filled first,
1134then the second, and so on until all items have been added. (If
1135neccessary, additional rows will be added as items are added.) If you
1136need to have greater control over the cells that items are placed in
1137then use the `wx.GridBagSizer`.
1138", "");
1139
d14a1e28
RD
1140class wxGridSizer: public wxSizer
1141{
1142public:
2b9048c5 1143 %pythonAppend wxGridSizer "self._setOORInfo(self)"
d14a1e28 1144
3ea6e0ec
RD
1145 DocCtorStr(
1146 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ),
1147 "Constructor for a wx.GridSizer. *rows* and *cols* determine the number
1148of columns and rows in the sizer - if either of the parameters is
1149zero, it will be calculated to from the total number of children in
1150the sizer, thus making the sizer grow dynamically. *vgap* and *hgap*
1151define extra space between all children.", "");
1152
1153 DocDeclStr(
1154 void , SetCols( int cols ),
1155 "Sets the number of columns in the sizer.", "");
7e8f0df9 1156
3ea6e0ec
RD
1157 DocDeclStr(
1158 void , SetRows( int rows ),
1159 "Sets the number of rows in the sizer.", "");
7e8f0df9 1160
3ea6e0ec
RD
1161 DocDeclStr(
1162 void , SetVGap( int gap ),
1163 "Sets the vertical gap (in pixels) between the cells in the sizer.", "");
7e8f0df9 1164
3ea6e0ec
RD
1165 DocDeclStr(
1166 void , SetHGap( int gap ),
1167 "Sets the horizontal gap (in pixels) between cells in the sizer", "");
7e8f0df9 1168
3ea6e0ec
RD
1169 DocDeclStr(
1170 int , GetCols(),
1171 "Returns the number of columns in the sizer.", "");
7e8f0df9 1172
3ea6e0ec
RD
1173 DocDeclStr(
1174 int , GetRows(),
1175 "Returns the number of rows in the sizer.", "");
7e8f0df9 1176
3ea6e0ec
RD
1177 DocDeclStr(
1178 int , GetVGap(),
1179 "Returns the vertical gap (in pixels) between the cells in the sizer.", "");
7e8f0df9 1180
3ea6e0ec
RD
1181 DocDeclStr(
1182 int , GetHGap(),
1183 "Returns the horizontal gap (in pixels) between cells in the sizer.", "");
7e8f0df9 1184
c86fa5a1
RD
1185 %pythoncode {
1186 def CalcRowsCols(self):
1187 """
1188 CalcRowsCols() -> (rows, cols)
1189
1190 Calculates how many rows and columns will be in the sizer based
1191 on the current number of items and also the rows, cols specified
1192 in the constructor.
1193 """
1194 nitems = len(self.GetChildren())
1195 rows = self.GetRows()
1196 cols = self.GetCols()
1197 assert rows != 0 or cols != 0, "Grid sizer must have either rows or columns fixed"
1198 if cols != 0:
1199 rows = (nitems + cols - 1) / cols
1200 elif rows != 0:
1201 cols = (nitems + rows - 1) / rows
1202 return (rows, cols)
1203 }
d14a1e28
RD
1204};
1205
1206//---------------------------------------------------------------------------
1207%newgroup;
1208
1209enum wxFlexSizerGrowMode
1210{
1211 // don't resize the cells in non-flexible direction at all
1212 wxFLEX_GROWMODE_NONE,
1213
1214 // uniformly resize only the specified ones (default)
1215 wxFLEX_GROWMODE_SPECIFIED,
1216
1217 // uniformly resize all cells
1218 wxFLEX_GROWMODE_ALL
1219};
1220
1221
3ea6e0ec
RD
1222
1223
1224
1225DocStr(wxFlexGridSizer,
1226"A flex grid sizer is a sizer which lays out its children in a
1227two-dimensional table with all table cells in one row having the same
1228height and all cells in one column having the same width, but all
1229rows or all columns are not necessarily the same height or width as in
1230the `wx.GridSizer`.
1231
1232wx.FlexGridSizer can also size items equally in one direction but
1233unequally (\"flexibly\") in the other. If the sizer is only flexible
1234in one direction (this can be changed using `SetFlexibleDirection`), it
1235needs to be decided how the sizer should grow in the other (\"non
1236flexible\") direction in order to fill the available space. The
1237`SetNonFlexibleGrowMode` method serves this purpose.
1238
1239", "");
1240
d14a1e28
RD
1241class wxFlexGridSizer: public wxGridSizer
1242{
1243public:
2b9048c5 1244 %pythonAppend wxFlexGridSizer "self._setOORInfo(self)"
d14a1e28 1245
3ea6e0ec
RD
1246 DocCtorStr(
1247 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 ),
1248 "Constructor for a wx.FlexGridSizer. *rows* and *cols* determine the
1249number of columns and rows in the sizer - if either of the parameters
1250is zero, it will be calculated to from the total number of children in
1251the sizer, thus making the sizer grow dynamically. *vgap* and *hgap*
1252define extra space between all children.", "");
7e8f0df9 1253
3ea6e0ec
RD
1254
1255 DocDeclStr(
1256 void , AddGrowableRow( size_t idx, int proportion = 0 ),
1257 "Specifies that row *idx* (starting from zero) should be grown if there
1258is extra space available to the sizer.
1259
1260The *proportion* parameter has the same meaning as the stretch factor
1261for the box sizers except that if all proportions are 0, then all
1262columns are resized equally (instead of not being resized at all).", "");
7e8f0df9 1263
3ea6e0ec
RD
1264 DocDeclStr(
1265 void , RemoveGrowableRow( size_t idx ),
1266 "Specifies that row *idx* is no longer growable.", "");
7e8f0df9 1267
3ea6e0ec
RD
1268 DocDeclStr(
1269 void , AddGrowableCol( size_t idx, int proportion = 0 ),
1270 "Specifies that column *idx* (starting from zero) should be grown if
1271there is extra space available to the sizer.
1272
1273The *proportion* parameter has the same meaning as the stretch factor
1274for the box sizers except that if all proportions are 0, then all
1275columns are resized equally (instead of not being resized at all).", "");
7e8f0df9 1276
3ea6e0ec
RD
1277 DocDeclStr(
1278 void , RemoveGrowableCol( size_t idx ),
1279 "Specifies that column *idx* is no longer growable.", "");
7e8f0df9 1280
3ea6e0ec
RD
1281
1282 DocDeclStr(
1283 void , SetFlexibleDirection(int direction),
1284 "Specifies whether the sizer should flexibly resize its columns, rows,
1285or both. Argument *direction* can be one of the following values. Any
1286other value is ignored.
1287
1288 ============== =======================================
1289 wx.VERTICAL Rows are flexibly sized.
1290 wx.HORIZONTAL Columns are flexibly sized.
1291 wx.BOTH Both rows and columns are flexibly sized
1292 (this is the default value).
1293 ============== =======================================
1294
1295Note that this method does not trigger relayout.
1296", "");
7e8f0df9 1297
3ea6e0ec
RD
1298 DocDeclStr(
1299 int , GetFlexibleDirection(),
1300 "Returns a value that specifies whether the sizer
1301flexibly resizes its columns, rows, or both (default).
d14a1e28 1302
3ea6e0ec 1303:see: `SetFlexibleDirection`", "");
d14a1e28 1304
7e8f0df9 1305
d14a1e28 1306
3ea6e0ec
RD
1307 DocDeclStr(
1308 void , SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode),
1309 "Specifies how the sizer should grow in the non-flexible direction if
1310there is one (so `SetFlexibleDirection` must have been called
1311previously). Argument *mode* can be one of the following values:
1312
1313 ========================== =================================================
1314 wx.FLEX_GROWMODE_NONE Sizer doesn't grow in the non flexible direction.
1315 wx.FLEX_GROWMODE_SPECIFIED Sizer honors growable columns/rows set with
1316 `AddGrowableCol` and `AddGrowableRow`. In this
1317 case equal sizing applies to minimum sizes of
1318 columns or rows (this is the default value).
1319 wx.FLEX_GROWMODE_ALL Sizer equally stretches all columns or rows in
1320 the non flexible direction, whether they are
1321 growable or not in the flexbile direction.
1322 ========================== =================================================
1323
1324Note that this method does not trigger relayout.
1325
1326", "");
7e8f0df9 1327
3ea6e0ec
RD
1328 DocDeclStr(
1329 wxFlexSizerGrowMode , GetNonFlexibleGrowMode(),
1330 "Returns the value that specifies how the sizer grows in the
1331non-flexible direction if there is one.
d14a1e28 1332
3ea6e0ec 1333:see: `SetNonFlexibleGrowMode`", "");
7e8f0df9 1334
dd9f7fea
RD
1335
1336 // Read-only access to the row heights and col widths arrays
3ea6e0ec
RD
1337 DocDeclAStr(
1338 const wxArrayInt& , GetRowHeights() const,
1339 "GetRowHeights(self) -> list",
1340 "Returns a list of integers representing the heights of each of the
1341rows in the sizer.", "");
7e8f0df9 1342
3ea6e0ec
RD
1343 DocDeclAStr(
1344 const wxArrayInt& , GetColWidths() const,
1345 "GetColWidths(self) -> list",
1346 "Returns a list of integers representing the widths of each of the
1347columns in the sizer.", "");
7e8f0df9 1348
d14a1e28
RD
1349};
1350
9283228f
RD
1351//---------------------------------------------------------------------------
1352
1353DocStr(wxStdDialogButtonSizer,
1354"A special sizer that knows how to order and position standard buttons
1355in order to conform to the current platform's standards. You simply
1356need to add each `wx.Button` to the sizer, and be sure to create the
718903fe 1357buttons using the standard ID's. Then call `Realize` and the sizer
9283228f
RD
1358will take care of the rest.
1359", "");
1360
1361class wxStdDialogButtonSizer: public wxBoxSizer
1362{
1363public:
1364 DocCtorStr(
1365 wxStdDialogButtonSizer(),
1366 "", "");
1367
1368 DocDeclStr(
1369 void , AddButton(wxButton *button),
1370 "Use this to add the buttons to this sizer. Do not use the `Add`
1371method in the base class.", "");
7e8f0df9 1372
9283228f 1373 DocDeclStr(
718903fe 1374 void , Realize(),
9283228f
RD
1375 "This funciton needs to be called after all the buttons have been added
1376to the sizer. It will reorder them and position them in a platform
1377specifc manner.", "");
3ba93175
RD
1378
1379 void SetAffirmativeButton( wxButton *button );
1380 void SetNegativeButton( wxButton *button );
1381 void SetCancelButton( wxButton *button );
7e8f0df9 1382
9283228f
RD
1383 wxButton* GetAffirmativeButton() const;
1384 wxButton* GetApplyButton() const;
1385 wxButton* GetNegativeButton() const;
1386 wxButton* GetCancelButton() const;
1387 wxButton* GetHelpButton() const;
1388};
1389
1390
d14a1e28 1391//---------------------------------------------------------------------------