]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/src/sizers.i
Corrected a return type
[wxWidgets.git] / wxPython / src / sizers.i
... / ...
CommitLineData
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$
9// Copyright: (c) 1999 by Total Control Software
10// Licence: wxWindows license
11/////////////////////////////////////////////////////////////////////////////
12
13%module sizers
14
15%{
16#include "helpers.h"
17
18#include <wx/notebook.h>
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"
33
34//---------------------------------------------------------------------------
35
36
37class wxSizerItem : public wxObject {
38public:
39 // No need to ever create one directly in Python...
40
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 );
44
45 void DeleteWindows();
46 void DetachSizer();
47
48 wxSize GetSize();
49 wxSize CalcMin();
50 void SetDimension( wxPoint pos, wxSize size );
51
52 wxSize GetMinSize();
53 void SetInitSize( int x, int y );
54
55 %name(SetRatioWH) void SetRatio( int width, int height );
56 %name(SetRatioSize) void SetRatio( wxSize size );
57 void SetRatio( float ratio );
58 float GetRatio();
59
60 bool IsWindow();
61 bool IsSizer();
62 bool IsSpacer();
63
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
73 wxWindow *GetWindow();
74 void SetWindow( wxWindow *window );
75 wxSizer *GetSizer();
76 void SetSizer( wxSizer *sizer );
77 const wxSize& GetSpacer();
78 void SetSpacer( const wxSize &size );
79
80 void Show( bool show );
81 bool IsShown();
82
83 wxPoint GetPosition();
84
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
104
105class wxSizer : public wxObject {
106public:
107 // wxSizer(); **** abstract, can't instantiate
108 // ~wxSizer();
109
110 %addmethods {
111 void _setOORInfo(PyObject* _self) {
112 self->SetClientObject(new wxPyOORClientData(_self));
113 }
114 }
115
116 %addmethods {
117 void Destroy() { delete self; }
118
119
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;
131 wxPyUserData* data = NULL;
132 if (userData) data = new wxPyUserData(userData);
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 }
149 }
150
151
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;
163 wxPyUserData* data = NULL;
164 if (userData) data = new wxPyUserData(userData);
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 }
181 }
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;
196 wxPyUserData* data = NULL;
197 if (userData) data = new wxPyUserData(userData);
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 }
214 }
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 }
236 }
237
238 void _SetItemMinSize(PyObject* item, wxSize size) {
239 wxWindow* window;
240 wxSizer* sizer;
241
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);
248
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 }
257
258 }
259
260
261 %pragma(python) addtoclass = "
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)
267
268 def AddMany(self, widgets):
269 for childinfo in widgets:
270 if type(childinfo) != type(()):
271 childinfo = (childinfo, )
272 self.Add(*childinfo)
273
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)
279
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)
285
286
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)
297 else:
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);
305
306 wxSize GetSize();
307 wxPoint GetPosition();
308 wxSize GetMinSize();
309
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
319 // void RecalcSizes() = 0;
320 // wxSize CalcMin() = 0;
321
322 void Layout();
323
324 wxSize Fit( wxWindow *window );
325 void FitInside( wxWindow *window );
326
327 void SetSizeHints( wxWindow *window );
328 void SetVirtualSizeHints( wxWindow *window );
329
330 void Clear( bool delete_windows=FALSE );
331 void DeleteWindows();
332
333
334 // wxList& GetChildren();
335 %addmethods {
336 PyObject* GetChildren() {
337 wxList& list = self->GetChildren();
338 return wxPy_ConvertList(&list, "wxSizerItem");
339 }
340 }
341
342
343 // Manage whether individual windows or sub-sizers are considered
344 // in the layout calculations or not.
345
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
386
387 // Recursively call wxWindow::Show() on all sizer items.
388 void ShowItems(bool show);
389
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();
418 void _setCallbackInfo(PyObject* self, PyObject* _class);
419 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPySizer)"
420 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
421};
422
423
424//---------------------------------------------------------------------------
425
426class wxBoxSizer : public wxSizer {
427public:
428 wxBoxSizer(int orient = wxHORIZONTAL);
429 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
430 int GetOrientation();
431 void SetOrientation(int orient);
432 void RecalcSizes();
433 wxSize CalcMin();
434};
435
436//---------------------------------------------------------------------------
437
438class wxStaticBoxSizer : public wxBoxSizer {
439public:
440 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
441 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
442 wxStaticBox *GetStaticBox();
443 void RecalcSizes();
444 wxSize CalcMin();
445};
446
447//---------------------------------------------------------------------------
448
449class wxNotebookSizer: public wxSizer {
450public:
451 wxNotebookSizer( wxNotebook *nb );
452 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
453 void RecalcSizes();
454 wxSize CalcMin();
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 );
464 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
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
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
494class wxFlexGridSizer: public wxGridSizer
495{
496public:
497 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
498 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
499
500 void RecalcSizes();
501 wxSize CalcMin();
502
503 void AddGrowableRow( size_t idx, int proportion = 0 );
504 void RemoveGrowableRow( size_t idx );
505 void AddGrowableCol( size_t idx, int proportion = 0 );
506 void RemoveGrowableCol( size_t idx );
507
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();
519};
520
521//---------------------------------------------------------------------------