]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/_sizers.i
fixed some docstrings
[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
24
25class wxSizerItem : public wxObject {
26public:
27 wxSizerItem();
28
29 %name(SizerItemSpacer) wxSizerItem( int width, int height, int proportion, int flag, int border, wxObject* userData);
30 %name(SizerItemWindow) wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData );
31 %name(SizerItemSizer) wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData );
32
33 void DeleteWindows();
34 void DetachSizer();
35
36 wxSize GetSize();
37 wxSize CalcMin();
38 void SetDimension( wxPoint pos, wxSize size );
39
40 wxSize GetMinSize();
41 void SetInitSize( int x, int y );
42
43 %name(SetRatioWH) void SetRatio( int width, int height );
44 %name(SetRatioSize) void SetRatio( wxSize size );
45 void SetRatio( float ratio );
46 float GetRatio();
47
48 bool IsWindow();
49 bool IsSizer();
50 bool IsSpacer();
51
52 void SetProportion( int proportion );
53 int GetProportion();
54
55 void SetFlag( int flag );
56 int GetFlag();
57
58 void SetBorder( int border );
59 int GetBorder();
60
61 wxWindow *GetWindow();
62 void SetWindow( wxWindow *window );
63
64 wxSizer *GetSizer();
65 void SetSizer( wxSizer *sizer );
66
67 const wxSize& GetSpacer();
68 void SetSpacer( const wxSize &size );
69
70 void Show( bool show );
71 bool IsShown();
72
73 wxPoint GetPosition();
74
75 // wxObject* GetUserData();
76 %extend {
77 // Assume that the user data is a wxPyUserData object and return the contents
78 PyObject* GetUserData() {
79 wxPyUserData* data = (wxPyUserData*)self->GetUserData();
80 if (data) {
81 Py_INCREF(data->m_obj);
82 return data->m_obj;
83 } else {
84 Py_INCREF(Py_None);
85 return Py_None;
86 }
87 }
88 }
89};
90
91
92//---------------------------------------------------------------------------
93
94%{
95// Figure out the type of the sizer item
96
97struct wxPySizerItemInfo {
98 wxPySizerItemInfo()
dd9f7fea
RD
99 : window(NULL), sizer(NULL), gotSize(False),
100 size(wxDefaultSize), gotPos(False), pos(-1)
d14a1e28
RD
101 {}
102
103 wxWindow* window;
104 wxSizer* sizer;
105 bool gotSize;
106 wxSize size;
107 bool gotPos;
108 int pos;
109};
110
111static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) {
112
113 wxPySizerItemInfo info;
114 wxSize size;
115 wxSize* sizePtr = &size;
116
117 // Find out what the type of the item is
118 // try wxWindow
119 if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) {
120 PyErr_Clear();
121 info.window = NULL;
122
123 // try wxSizer
124 if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) {
125 PyErr_Clear();
126 info.sizer = NULL;
127
128 // try wxSize or (w,h)
129 if ( checkSize && wxSize_helper(item, &sizePtr)) {
130 info.size = *sizePtr;
dd9f7fea 131 info.gotSize = True;
d14a1e28
RD
132 }
133
134 // or a single int
135 if (checkIdx && PyInt_Check(item)) {
136 info.pos = PyInt_AsLong(item);
dd9f7fea 137 info.gotPos = True;
d14a1e28
RD
138 }
139 }
140 }
141
142 if ( !(info.window || info.sizer || (checkSize && info.gotSize) || (checkIdx && info.gotPos)) ) {
143 // no expected type, figure out what kind of error message to generate
144 if ( !checkSize && !checkIdx )
145 PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected for item");
146 else if ( checkSize && !checkIdx )
147 PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
148 else if ( !checkSize && checkIdx)
149 PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer or int (position) expected for item");
150 else
151 // can this one happen?
152 PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer, wxSize, or (w,h) or int (position) expected for item");
153 }
154
155 return info;
156}
157%}
158
159
160
161
162class wxSizer : public wxObject {
163public:
164 // wxSizer(); **** abstract, can't instantiate
165 // ~wxSizer();
166
167 %extend {
168 void _setOORInfo(PyObject* _self) {
169 self->SetClientObject(new wxPyOORClientData(_self));
170 }
171
172
173 void Add(PyObject* item, int proportion=0, int flag=0, int border=0,
174 PyObject* userData=NULL) {
175
176 wxPyUserData* data = NULL;
177 wxPyBeginBlockThreads();
dd9f7fea 178 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
d14a1e28
RD
179 if ( userData && (info.window || info.sizer || info.gotSize) )
180 data = new wxPyUserData(userData);
181 wxPyEndBlockThreads();
182
183 // Now call the real Add method if a valid item type was found
184 if ( info.window )
185 self->Add(info.window, proportion, flag, border, data);
186 else if ( info.sizer )
187 self->Add(info.sizer, proportion, flag, border, data);
188 else if (info.gotSize)
189 self->Add(info.size.GetWidth(), info.size.GetHeight(),
190 proportion, flag, border, data);
191 }
192
193
194 void Insert(int before, PyObject* item, int proportion=0, int flag=0,
195 int border=0, PyObject* userData=NULL) {
196
197 wxPyUserData* data = NULL;
198 wxPyBeginBlockThreads();
dd9f7fea 199 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
d14a1e28
RD
200 if ( userData && (info.window || info.sizer || info.gotSize) )
201 data = new wxPyUserData(userData);
202 wxPyEndBlockThreads();
203
204 // Now call the real Insert method if a valid item type was found
205 if ( info.window )
206 self->Insert(before, info.window, proportion, flag, border, data);
207 else if ( info.sizer )
208 self->Insert(before, info.sizer, proportion, flag, border, data);
209 else if (info.gotSize)
210 self->Insert(before, info.size.GetWidth(), info.size.GetHeight(),
211 proportion, flag, border, data);
212 }
213
214
215
216 void Prepend(PyObject* item, int proportion=0, int flag=0, int border=0,
217 PyObject* userData=NULL) {
218
219 wxPyUserData* data = NULL;
220 wxPyBeginBlockThreads();
dd9f7fea 221 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
d14a1e28
RD
222 if ( userData && (info.window || info.sizer || info.gotSize) )
223 data = new wxPyUserData(userData);
224 wxPyEndBlockThreads();
225
226 // Now call the real Prepend method if a valid item type was found
227 if ( info.window )
228 self->Prepend(info.window, proportion, flag, border, data);
229 else if ( info.sizer )
230 self->Prepend(info.sizer, proportion, flag, border, data);
231 else if (info.gotSize)
232 self->Prepend(info.size.GetWidth(), info.size.GetHeight(),
233 proportion, flag, border, data);
234 }
235
236
237 bool Remove(PyObject* item) {
238 wxPyBeginBlockThreads();
dd9f7fea 239 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, True);
d14a1e28
RD
240 wxPyEndBlockThreads();
241 if ( info.window )
242 return self->Remove(info.window);
243 else if ( info.sizer )
244 return self->Remove(info.sizer);
245 else if ( info.gotPos )
246 return self->Remove(info.pos);
247 else
dd9f7fea 248 return False;
d14a1e28
RD
249 }
250
251
dd9f7fea 252 void _SetItemMinSize(PyObject* item, const wxSize& size) {
d14a1e28 253 wxPyBeginBlockThreads();
dd9f7fea 254 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, True);
d14a1e28
RD
255 wxPyEndBlockThreads();
256 if ( info.window )
257 self->SetItemMinSize(info.window, size);
258 else if ( info.sizer )
259 self->SetItemMinSize(info.sizer, size);
260 else if ( info.gotPos )
261 self->SetItemMinSize(info.pos, size);
262 }
263 }
264
265 %name(AddItem) void Add( wxSizerItem *item );
266 %name(InsertItem) void Insert( size_t index, wxSizerItem *item );
267 %name(PrependItem) void Prepend( wxSizerItem *item );
268
269
270 %pythoncode {
271 def AddMany(self, widgets):
272 for childinfo in widgets:
dd9f7fea 273 if type(childinfo) != type(()) or (len(childinfo) == 2 and type(childinfo[0]) == type(1)):
d14a1e28
RD
274 childinfo = (childinfo, )
275 self.Add(*childinfo)
276
d147c724 277 %# for backwards compatibility only, please do not use in new code
d14a1e28
RD
278 AddWindow = AddSizer = AddSpacer = Add
279 PrependWindow = PrependSizer = PrependSpacer = Prepend
280 InsertWindow = InsertSizer = InsertSpacer = Insert
281 RemoveWindow = RemoveSizer = RemovePos = Remove
282
283
284 def SetItemMinSize(self, item, *args):
285 if len(args) == 2:
286 return self._SetItemMinSize(item, args)
287 else:
288 return self._SetItemMinSize(item, args[0])
289 }
290
291
292 void SetDimension( int x, int y, int width, int height );
e5e66a2d 293 void SetMinSize( const wxSize &size );
d14a1e28
RD
294
295 wxSize GetSize();
296 wxPoint GetPosition();
297 wxSize GetMinSize();
298
299 %pythoncode {
300 def GetSizeTuple(self):
301 return self.GetSize().asTuple()
302 def GetPositionTuple(self):
303 return self.GetPosition().asTuple()
304 def GetMinSizeTuple(self):
305 return self.GetMinSize().asTuple()
306 }
307
308 virtual void RecalcSizes();
309 virtual wxSize CalcMin();
310
311 void Layout();
312
313 wxSize Fit( wxWindow *window );
314 void FitInside( wxWindow *window );
315
316 void SetSizeHints( wxWindow *window );
317 void SetVirtualSizeHints( wxWindow *window );
318
dd9f7fea 319 void Clear( bool delete_windows=False );
d14a1e28
RD
320 void DeleteWindows();
321
322
323 // wxList& GetChildren();
324 %extend {
325 PyObject* GetChildren() {
326 wxSizerItemList& list = self->GetChildren();
327 return wxPy_ConvertList(&list);
328 }
329 }
330
331
332 // Manage whether individual windows or sub-sizers are considered
333 // in the layout calculations or not.
334
335 %extend {
dd9f7fea
RD
336 void Show(PyObject* item, bool show = True) {
337 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
d14a1e28
RD
338 if ( info.window )
339 self->Show(info.window, show);
340 else if ( info.sizer )
341 self->Show(info.sizer, show);
342 }
343
344
345 void Hide(PyObject* item) {
dd9f7fea 346 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
d14a1e28
RD
347 if ( info.window )
348 self->Hide(info.window);
349 else if ( info.sizer )
350 self->Hide(info.sizer);
351 }
352
353
354 bool IsShown(PyObject* item) {
dd9f7fea 355 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
d14a1e28
RD
356 if ( info.window )
357 return self->IsShown(info.window);
358 else if ( info.sizer )
359 return self->IsShown(info.sizer);
360 else
dd9f7fea 361 return False;
d14a1e28
RD
362 }
363 }
364
365
366 // Recursively call wxWindow::Show() on all sizer items.
367 void ShowItems(bool show);
368
369};
370
371
372//---------------------------------------------------------------------------
373// Use this one for deriving Python classes from
374%{
375// See pyclasses.h
376IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
377IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
378IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
379%}
380
381
382
383class wxPySizer : public wxSizer {
384public:
2b9048c5 385 %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)"
d14a1e28
RD
386
387 wxPySizer();
388 void _setCallbackInfo(PyObject* self, PyObject* _class);
389};
390
391
392//---------------------------------------------------------------------------
393%newgroup;
394
395class wxBoxSizer : public wxSizer {
396public:
2b9048c5 397 %pythonAppend wxBoxSizer "self._setOORInfo(self)"
d14a1e28
RD
398
399 wxBoxSizer(int orient = wxHORIZONTAL);
400
401 int GetOrientation();
402 void SetOrientation(int orient);
403 void RecalcSizes();
404 wxSize CalcMin();
405};
406
407//---------------------------------------------------------------------------
408%newgroup;
409
410class wxStaticBoxSizer : public wxBoxSizer {
411public:
2b9048c5 412 %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)"
d14a1e28
RD
413
414 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
415
416 wxStaticBox *GetStaticBox();
417 void RecalcSizes();
418 wxSize CalcMin();
419};
420
421//---------------------------------------------------------------------------
422%newgroup;
423
424class wxGridSizer: public wxSizer
425{
426public:
2b9048c5 427 %pythonAppend wxGridSizer "self._setOORInfo(self)"
d14a1e28
RD
428
429 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
430
431 void RecalcSizes();
432 wxSize CalcMin();
433
434 void SetCols( int cols );
435 void SetRows( int rows );
436 void SetVGap( int gap );
437 void SetHGap( int gap );
438 int GetCols();
439 int GetRows();
440 int GetVGap();
441 int GetHGap();
442};
443
444//---------------------------------------------------------------------------
445%newgroup;
446
447enum wxFlexSizerGrowMode
448{
449 // don't resize the cells in non-flexible direction at all
450 wxFLEX_GROWMODE_NONE,
451
452 // uniformly resize only the specified ones (default)
453 wxFLEX_GROWMODE_SPECIFIED,
454
455 // uniformly resize all cells
456 wxFLEX_GROWMODE_ALL
457};
458
459
460class wxFlexGridSizer: public wxGridSizer
461{
462public:
2b9048c5 463 %pythonAppend wxFlexGridSizer "self._setOORInfo(self)"
d14a1e28
RD
464
465 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
466
467 void RecalcSizes();
468 wxSize CalcMin();
469
470 void AddGrowableRow( size_t idx, int proportion = 0 );
471 void RemoveGrowableRow( size_t idx );
472 void AddGrowableCol( size_t idx, int proportion = 0 );
473 void RemoveGrowableCol( size_t idx );
474
475 // the sizer cells may grow in both directions, not grow at all or only
476 // grow in one direction but not the other
477
478 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
479 void SetFlexibleDirection(int direction);
480 int GetFlexibleDirection();
481
482 // note that the grow mode only applies to the direction which is not
483 // flexible
484 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
485 wxFlexSizerGrowMode GetNonFlexibleGrowMode();
dd9f7fea
RD
486
487 // Read-only access to the row heights and col widths arrays
488 const wxArrayInt& GetRowHeights() const;
489 const wxArrayInt& GetColWidths() const;
d14a1e28
RD
490};
491
492//---------------------------------------------------------------------------