]> git.saurik.com Git - wxWidgets.git/blame - wxPython/src/sizers.i
Corrected a return type
[wxWidgets.git] / wxPython / src / sizers.i
CommitLineData
2f90df85
RD
1/////////////////////////////////////////////////////////////////////////////
2// Name: sizers.i
3// Purpose: SWIG definitions of the wxSizer family of classes
4//
5// Author: Robin Dunn
6//
7// Created: 18-Sept-1999
8// RCS-ID: $Id$
f0261a72 9// Copyright: (c) 1999 by Total Control Software
2f90df85
RD
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13%module sizers
14
15%{
16#include "helpers.h"
9416aa89
RD
17
18#include <wx/notebook.h>
2f90df85
RD
19%}
20
21//----------------------------------------------------------------------
22
23%include typemaps.i
24%include my_typemaps.i
25
26// Import some definitions of other classes, etc.
27%import _defs.i
28%import misc.i
29%import windows.i
30%import controls.i
31
32%pragma(python) code = "import wx"
2f90df85
RD
33
34//---------------------------------------------------------------------------
35
2f90df85 36
9416aa89 37class wxSizerItem : public wxObject {
2f90df85
RD
38public:
39 // No need to ever create one directly in Python...
40
1e4a197e
RD
41 //wxSizerItem( int width, int height, int proportion, int flag, int border, wxObject* userData);
42 //wxSizerItem( wxWindow *window, int proportion, int flag, int border, wxObject* userData );
43 //wxSizerItem( wxSizer *sizer, int proportion, int flag, int border, wxObject* userData );
2f90df85 44
101dd79a 45 void DeleteWindows();
1e4a197e 46 void DetachSizer();
101dd79a 47
2f90df85
RD
48 wxSize GetSize();
49 wxSize CalcMin();
50 void SetDimension( wxPoint pos, wxSize size );
1e4a197e
RD
51
52 wxSize GetMinSize();
53 void SetInitSize( int x, int y );
54
f6bcfd97
BP
55 %name(SetRatioWH) void SetRatio( int width, int height );
56 %name(SetRatioSize) void SetRatio( wxSize size );
57 void SetRatio( float ratio );
58 float GetRatio();
2f90df85
RD
59
60 bool IsWindow();
61 bool IsSizer();
62 bool IsSpacer();
63
1e4a197e
RD
64 void SetProportion( int proportion );
65 int GetProportion();
66 %pragma(python) addtoclass = "SetOption = SetProportion"
67 %pragma(python) addtoclass = "GetOption = GetProportion"
68 void SetFlag( int flag );
69 int GetFlag();
70 void SetBorder( int border );
71 int GetBorder();
72
2f90df85 73 wxWindow *GetWindow();
f6bcfd97 74 void SetWindow( wxWindow *window );
2f90df85 75 wxSizer *GetSizer();
f6bcfd97 76 void SetSizer( wxSizer *sizer );
1e4a197e
RD
77 const wxSize& GetSpacer();
78 void SetSpacer( const wxSize &size );
2f90df85 79
1e4a197e
RD
80 void Show( bool show );
81 bool IsShown();
82
83 wxPoint GetPosition();
9b3d3bc4 84
2f90df85
RD
85 // wxObject* GetUserData();
86 %addmethods {
87 // Assume that the user data is a wxPyUserData object and return the contents
88 PyObject* GetUserData() {
89 wxPyUserData* data = (wxPyUserData*)self->GetUserData();
90 if (data) {
91 Py_INCREF(data->m_obj);
92 return data->m_obj;
93 } else {
94 Py_INCREF(Py_None);
95 return Py_None;
96 }
97 }
98 }
99};
100
101
102//---------------------------------------------------------------------------
103
1fded56b 104
9416aa89 105class wxSizer : public wxObject {
2f90df85
RD
106public:
107 // wxSizer(); **** abstract, can't instantiate
108 // ~wxSizer();
109
2aab8f16
RD
110 %addmethods {
111 void _setOORInfo(PyObject* _self) {
4acff284 112 self->SetClientObject(new wxPyOORClientData(_self));
2aab8f16
RD
113 }
114 }
115
2f90df85
RD
116 %addmethods {
117 void Destroy() { delete self; }
118
2f90df85 119
1fded56b
RD
120 void _Add(PyObject* item, int proportion=0, int flag=0, int border=0,
121 PyObject* userData=NULL, int option=-1) {
122 // The option parameter is only for backwards compatibility
123 // with keyword args, all new code should use "proportion"
124 // instead. This can be removed eventually.
125 if (option != -1) proportion = option;
126
127 wxWindow* window;
128 wxSizer* sizer;
129 wxSize size;
130 wxSize* sizePtr = &size;
f6bcfd97
BP
131 wxPyUserData* data = NULL;
132 if (userData) data = new wxPyUserData(userData);
1fded56b
RD
133
134 // Find out what type the item is and call the real Add method
135 if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
136 self->Add(window, proportion, flag, border, data);
137
138 else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
139 self->Add(sizer, proportion, flag, border, data);
140
141 else if (wxSize_helper(item, &sizePtr))
142 self->Add(sizePtr->GetWidth(), sizePtr->GetHeight(),
143 proportion, flag, border, data);
144 else {
145 if (data) delete data;
146 PyErr_SetString(PyExc_TypeError,
147 "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
148 }
f6bcfd97
BP
149 }
150
151
1fded56b
RD
152 void _Insert(int before, PyObject* item, int proportion=0, int flag=0,
153 int border=0, PyObject* userData=NULL, int option=-1) {
154 // The option parameter is only for backwards compatibility
155 // with keyword args, all new code should use "proportion"
156 // instead. This can be removed eventually.
157 if (option != -1) proportion = option;
158
159 wxWindow* window;
160 wxSizer* sizer;
161 wxSize size;
162 wxSize* sizePtr = &size;
2f90df85
RD
163 wxPyUserData* data = NULL;
164 if (userData) data = new wxPyUserData(userData);
1fded56b
RD
165
166 // Find out what type the item is and call the real Insert method
167 if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
168 self->Insert(before, window, proportion, flag, border, data);
169
170 else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
171 self->Insert(before, sizer, proportion, flag, border, data);
172
173 else if (wxSize_helper(item, &sizePtr))
174 self->Insert(before, sizePtr->GetWidth(), sizePtr->GetHeight(),
175 proportion, flag, border, data);
176 else {
177 if (data) delete data;
178 PyErr_SetString(PyExc_TypeError,
179 "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
180 }
2f90df85 181 }
1fded56b
RD
182
183
184
185 void _Prepend(PyObject* item, int proportion=0, int flag=0, int border=0,
186 PyObject* userData=NULL, int option=-1) {
187 // The option parameter is only for backwards compatibility
188 // with keyword args, all new code should use "proportion"
189 // instead. This can be removed eventually.
190 if (option != -1) proportion = option;
191
192 wxWindow* window;
193 wxSizer* sizer;
194 wxSize size;
195 wxSize* sizePtr = &size;
2f90df85
RD
196 wxPyUserData* data = NULL;
197 if (userData) data = new wxPyUserData(userData);
1fded56b
RD
198
199 // Find out what type the item is and call the real Prepend method
200 if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
201 self->Prepend(window, proportion, flag, border, data);
202
203 else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
204 self->Prepend(sizer, proportion, flag, border, data);
205
206 else if (wxSize_helper(item, &sizePtr))
207 self->Prepend(sizePtr->GetWidth(), sizePtr->GetHeight(),
208 proportion, flag, border, data);
209 else {
210 if (data) delete data;
211 PyErr_SetString(PyExc_TypeError,
212 "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
213 }
2f90df85 214 }
1fded56b
RD
215
216 bool Remove(PyObject* item) {
217 wxWindow* window;
218 wxSizer* sizer;
219
220 // Find out what type the item is and call the real Remove method
221 if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
222 return self->Remove(window);
223
224 else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
225 return self->Remove(sizer);
226
227 else if (PyInt_Check(item)) {
228 int pos = PyInt_AsLong(item);
229 return self->Remove(pos);
230 }
231 else {
232 PyErr_SetString(PyExc_TypeError,
233 "wxWindow, wxSizer or int (position) expected.");
234 return FALSE;
235 }
2f90df85 236 }
1e4a197e 237
1fded56b
RD
238 void _SetItemMinSize(PyObject* item, wxSize size) {
239 wxWindow* window;
240 wxSizer* sizer;
1e4a197e 241
1fded56b
RD
242 // Find out what type the item is and call the real Remove method
243 if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
244 self->SetItemMinSize(window, size);
245
246 else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
247 self->SetItemMinSize(sizer, size);
2f90df85 248
1fded56b
RD
249 else if (PyInt_Check(item)) {
250 int pos = PyInt_AsLong(item);
251 self->SetItemMinSize(pos, size);
252 }
253 else
254 PyErr_SetString(PyExc_TypeError,
255 "wxWindow, wxSizer or int (position) expected.");
256 }
2f90df85 257
1fded56b 258 }
1e4a197e 259
2f90df85
RD
260
261 %pragma(python) addtoclass = "
1fded56b
RD
262 def Add(self, item, *args, **kw):
263 if type(item) == type(1):
264 item = (item, args[0]) # backwards compatibility, args are width, height
265 args = args[1:]
266 self._Add(item, *args, **kw)
2f90df85
RD
267
268 def AddMany(self, widgets):
269 for childinfo in widgets:
270 if type(childinfo) != type(()):
271 childinfo = (childinfo, )
1fded56b 272 self.Add(*childinfo)
2f90df85 273
1fded56b
RD
274 def Prepend(self, item, *args, **kw):
275 if type(item) == type(1):
276 item = (item, args[0]) # backwards compatibility, args are width, height
277 args = args[1:]
278 self._Prepend(item, *args, **kw)
2f90df85 279
1fded56b
RD
280 def Insert(self, before, item, *args, **kw):
281 if type(item) == type(1):
282 item = (item, args[0]) # backwards compatibility, args are width, height
283 args = args[1:]
284 self._Insert(before, item, *args, **kw)
f6bcfd97 285
f6bcfd97 286
1fded56b
RD
287 # for backwards compatibility only
288 AddWindow = AddSizer = AddSpacer = Add
289 PrependWindow = PrependSizer = PrependSpacer = Prepend
290 InsertWindow = InsertSizer = InsertSpacer = Insert
291 RemoveWindow = RemoveSizer = RemovePos = Remove
292
293
294 def SetItemMinSize(self, item, *args):
295 if len(args) == 2:
296 return self._SetItemMinSize(item, args)
1e4a197e 297 else:
1fded56b
RD
298 return self._SetItemMinSize(item, args[0])
299
300"
301
302
303 void SetDimension( int x, int y, int width, int height );
304 void SetMinSize(wxSize size);
2f90df85
RD
305
306 wxSize GetSize();
307 wxPoint GetPosition();
308 wxSize GetMinSize();
309
82550f23
RD
310 %pragma(python) addtoclass = "
311 def GetSizeTuple(self):
312 return self.GetSize().asTuple()
313 def GetPositionTuple(self):
314 return self.GetPosition().asTuple()
315 def GetMinSizeTuple(self):
316 return self.GetMinSize().asTuple()
317 "
318
2f90df85
RD
319 // void RecalcSizes() = 0;
320 // wxSize CalcMin() = 0;
321
322 void Layout();
323
72797a7d 324 wxSize Fit( wxWindow *window );
2a74d141
RD
325 void FitInside( wxWindow *window );
326
2f90df85 327 void SetSizeHints( wxWindow *window );
2a74d141 328 void SetVirtualSizeHints( wxWindow *window );
2f90df85 329
1fded56b
RD
330 void Clear( bool delete_windows=FALSE );
331 void DeleteWindows();
332
101dd79a 333
2f90df85
RD
334 // wxList& GetChildren();
335 %addmethods {
336 PyObject* GetChildren() {
1fded56b 337 wxList& list = self->GetChildren();
2f90df85
RD
338 return wxPy_ConvertList(&list, "wxSizerItem");
339 }
340 }
1e4a197e 341
1e4a197e
RD
342
343 // Manage whether individual windows or sub-sizers are considered
344 // in the layout calculations or not.
1e4a197e 345
1fded56b
RD
346 %addmethods {
347 void Show(PyObject* item, bool show = TRUE) {
348 wxWindow* window;
349 wxSizer* sizer;
350 // Find out what type the item is and call the real method
351 if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
352 self->Show(window, show);
353 else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
354 self->Show(sizer, show);
355 else
356 PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
357 }
358
359 void Hide(PyObject* item) {
360 wxWindow* window;
361 wxSizer* sizer;
362 // Find out what type the item is and call the real method
363 if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
364 self->Hide(window);
365 else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
366 self->Hide(sizer);
367 else
368 PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
369 }
370
371 bool IsShown(PyObject* item) {
372 wxWindow* window;
373 wxSizer* sizer;
374 // Find out what type the item is and call the real method
375 if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
376 return self->IsShown(window);
377 else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
378 return self->IsShown(sizer);
379 else {
380 PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
381 return FALSE;
382 }
383 }
384 }
385
1e4a197e 386
1fded56b
RD
387 // Recursively call wxWindow::Show() on all sizer items.
388 void ShowItems(bool show);
1e4a197e 389
2f90df85
RD
390};
391
392
393//---------------------------------------------------------------------------
394// Use this one for deriving Python classes from
395%{
396class wxPySizer : public wxSizer {
397 DECLARE_DYNAMIC_CLASS(wxPySizer);
398public:
399 wxPySizer() : wxSizer() {};
400
401 DEC_PYCALLBACK___pure(RecalcSizes);
402 DEC_PYCALLBACK_wxSize__pure(CalcMin);
403 PYPRIVATE;
404};
405
406
407IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
408IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
409
410IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
411%}
412
413
414
415class wxPySizer : public wxSizer {
416public:
417 wxPySizer();
0122b7e3
RD
418 void _setCallbackInfo(PyObject* self, PyObject* _class);
419 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPySizer)"
2aab8f16 420 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
2f90df85
RD
421};
422
423
424//---------------------------------------------------------------------------
425
426class wxBoxSizer : public wxSizer {
427public:
428 wxBoxSizer(int orient = wxHORIZONTAL);
2aab8f16 429 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
2f90df85 430 int GetOrientation();
1e4a197e 431 void SetOrientation(int orient);
f6bcfd97
BP
432 void RecalcSizes();
433 wxSize CalcMin();
2f90df85
RD
434};
435
436//---------------------------------------------------------------------------
437
438class wxStaticBoxSizer : public wxBoxSizer {
439public:
440 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
2aab8f16 441 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
2f90df85 442 wxStaticBox *GetStaticBox();
f6bcfd97
BP
443 void RecalcSizes();
444 wxSize CalcMin();
445};
446
447//---------------------------------------------------------------------------
448
449class wxNotebookSizer: public wxSizer {
450public:
451 wxNotebookSizer( wxNotebook *nb );
2aab8f16 452 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
f6bcfd97
BP
453 void RecalcSizes();
454 wxSize CalcMin();
f6bcfd97
BP
455 wxNotebook *GetNotebook();
456};
457
458//---------------------------------------------------------------------------
459
460class wxGridSizer: public wxSizer
461{
462public:
463 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
2aab8f16 464 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
f6bcfd97
BP
465
466 void RecalcSizes();
467 wxSize CalcMin();
468
469 void SetCols( int cols );
470 void SetRows( int rows );
471 void SetVGap( int gap );
472 void SetHGap( int gap );
473 int GetCols();
474 int GetRows();
475 int GetVGap();
476 int GetHGap();
477};
478
479//---------------------------------------------------------------------------
480
1e4a197e
RD
481enum wxFlexSizerGrowMode
482{
483 // don't resize the cells in non-flexible direction at all
484 wxFLEX_GROWMODE_NONE,
485
486 // uniformly resize only the specified ones (default)
487 wxFLEX_GROWMODE_SPECIFIED,
488
489 // uniformly resize all cells
490 wxFLEX_GROWMODE_ALL
491};
492
493
f6bcfd97
BP
494class wxFlexGridSizer: public wxGridSizer
495{
496public:
497 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
2aab8f16 498 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
f6bcfd97
BP
499
500 void RecalcSizes();
501 wxSize CalcMin();
502
1e4a197e 503 void AddGrowableRow( size_t idx, int proportion = 0 );
f6bcfd97 504 void RemoveGrowableRow( size_t idx );
1e4a197e 505 void AddGrowableCol( size_t idx, int proportion = 0 );
f6bcfd97
BP
506 void RemoveGrowableCol( size_t idx );
507
1e4a197e
RD
508 // the sizer cells may grow in both directions, not grow at all or only
509 // grow in one direction but not the other
510
511 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
512 void SetFlexibleDirection(int direction);
513 int GetFlexibleDirection();
514
515 // note that the grow mode only applies to the direction which is not
516 // flexible
517 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
518 wxFlexSizerGrowMode GetNonFlexibleGrowMode();
2f90df85
RD
519};
520
521//---------------------------------------------------------------------------