]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/sizers.i
include "wx/module.h" for wxModule
[wxWidgets.git] / wxPython / src / sizers.i
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
37 class wxSizerItem : public wxObject {
38 public:
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 class wxSizer : public wxObject {
105 public:
106 // wxSizer(); **** abstract, can't instantiate
107 // ~wxSizer();
108
109 %addmethods {
110 void _setOORInfo(PyObject* _self) {
111 self->SetClientObject(new wxPyOORClientData(_self));
112 }
113 }
114
115 %addmethods {
116 void Destroy() { delete self; }
117
118 void AddWindow(wxWindow *window, int proportion=0, int flag=0, int border=0,
119 PyObject* userData=NULL) {
120 wxPyUserData* data = NULL;
121 if (userData) data = new wxPyUserData(userData);
122 self->Add(window, proportion, flag, border, data);
123 }
124 void AddSizer(wxSizer *sizer, int proportion=0, int flag=0, int border=0,
125 PyObject* userData=NULL) {
126 wxPyUserData* data = NULL;
127 if (userData) data = new wxPyUserData(userData);
128 self->Add(sizer, proportion, flag, border, data);
129 }
130 void AddSpacer(int width, int height, int proportion=0, int flag=0,
131 int border=0, PyObject* userData=NULL) {
132 wxPyUserData* data = NULL;
133 if (userData) data = new wxPyUserData(userData);
134 self->Add(width, height, proportion, flag, border, data);
135 }
136
137 void InsertWindow(int before, wxWindow *window, int proportion=0, int flag=0,
138 int border=0, PyObject* userData=NULL) {
139 wxPyUserData* data = NULL;
140 if (userData) data = new wxPyUserData(userData);
141 self->Insert(before, window, proportion, flag, border, data);
142 }
143 void InsertSizer(int before, wxSizer *sizer, int proportion=0, int flag=0,
144 int border=0, PyObject* userData=NULL) {
145 wxPyUserData* data = NULL;
146 if (userData) data = new wxPyUserData(userData);
147 self->Insert(before, sizer, proportion, flag, border, data);
148 }
149 void InsertSpacer(int before, int width, int height, int proportion=0, int flag=0,
150 int border=0, PyObject* userData=NULL) {
151 wxPyUserData* data = NULL;
152 if (userData) data = new wxPyUserData(userData);
153 self->Insert(before, width, height, proportion, flag, border, data);
154 }
155
156
157 void PrependWindow(wxWindow *window, int proportion=0, int flag=0, int border=0,
158 PyObject* userData=NULL) {
159 wxPyUserData* data = NULL;
160 if (userData) data = new wxPyUserData(userData);
161 self->Prepend(window, proportion, flag, border, data);
162 }
163 void PrependSizer(wxSizer *sizer, int proportion=0, int flag=0, int border=0,
164 PyObject* userData=NULL) {
165 wxPyUserData* data = NULL;
166 if (userData) data = new wxPyUserData(userData);
167 self->Prepend(sizer, proportion, flag, border, data);
168 }
169 void PrependSpacer(int width, int height, int proportion=0, int flag=0,
170 int border=0, PyObject* userData=NULL) {
171 wxPyUserData* data = NULL;
172 if (userData) data = new wxPyUserData(userData);
173 self->Prepend(width, height, proportion, flag, border, data);
174 }
175
176 // TODO: AddItem, InsertItem, PrependItem
177
178 }
179
180 %name(RemoveWindow)bool Remove( wxWindow *window ); // TODO: This is DEPRECATED. Should all be removed?
181 %name(RemoveSizer)bool Remove( wxSizer *sizer );
182 %name(RemovePos)bool Remove( int pos );
183
184 %name(DetachWindow)bool Detach( wxWindow *window );
185 %name(DetachSizer)bool Detach( wxSizer *sizer );
186 %name(DetachPos)bool Detach( int pos );
187
188
189 %pragma(python) addtoclass = "
190 def Add(self, *args, **kw):
191 if type(args[0]) == type(1):
192 apply(self.AddSpacer, args, kw)
193 elif isinstance(args[0], wxSizerPtr):
194 apply(self.AddSizer, args, kw)
195 elif isinstance(args[0], wxWindowPtr):
196 apply(self.AddWindow, args, kw)
197 else:
198 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
199
200 def Insert(self, *args, **kw):
201 if type(args[1]) == type(1):
202 apply(self.InsertSpacer, args, kw)
203 elif isinstance(args[1], wxSizerPtr):
204 apply(self.InsertSizer, args, kw)
205 elif isinstance(args[1], wxWindowPtr):
206 apply(self.InsertWindow, args, kw)
207 else:
208 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
209
210 def Prepend(self, *args, **kw):
211 if type(args[0]) == type(1):
212 apply(self.PrependSpacer, args, kw)
213 elif isinstance(args[0], wxSizerPtr):
214 apply(self.PrependSizer, args, kw)
215 elif isinstance(args[0], wxWindowPtr):
216 apply(self.PrependWindow, args, kw)
217 else:
218 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
219
220 def Remove(self, *args, **kw):
221 if type(args[0]) == type(1):
222 return apply(self.RemovePos, args, kw)
223 elif isinstance(args[0], wxSizerPtr):
224 return apply(self.RemoveSizer, args, kw)
225 elif isinstance(args[0], wxWindowPtr):
226 return apply(self.RemoveWindow, args, kw)
227 else:
228 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
229
230 def Detach(self, *args, **kw):
231 if type(args[0]) == type(1):
232 return apply(self.DetachPos, args, kw)
233 elif isinstance(args[0], wxSizerPtr):
234 return apply(self.DetachSizer, args, kw)
235 elif isinstance(args[0], wxWindowPtr):
236 return apply(self.DetachWindow, args, kw)
237 else:
238 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
239
240 def AddMany(self, widgets):
241 for childinfo in widgets:
242 if type(childinfo) != type(()):
243 childinfo = (childinfo, )
244 apply(self.Add, childinfo)
245 "
246
247 void Clear( bool delete_windows = false );
248 void DeleteWindows();
249
250 void SetMinSize(wxSize size);
251
252 %name(SetItemMinSizeWindow) void SetItemMinSize(wxWindow* window, wxSize size);
253 %name(SetItemMinSizeSizer) void SetItemMinSize(wxSizer* sizer, wxSize size);
254 %name(SetItemMinSizePos) void SetItemMinSize(int pos, wxSize size);
255 %name(SetItemMinSizeWindowWH) void SetItemMinSize(wxWindow* window, int width, int height);
256 %name(SetItemMinSizeSizerWH) void SetItemMinSize(wxSizer* sizer, int width, int height);
257 %name(SetItemMinSizePosWH) void SetItemMinSize(int pos, int width, int height);
258
259 %pragma(python) addtoclass = "
260 def SetItemMinSize(self, *args):
261 if type(args[0]) == type(1):
262 apply(self.SetItemMinSizePos, args)
263 elif isinstance(args[0], wxSizerPtr):
264 apply(self.SetItemMinSizeSizer, args)
265 elif isinstance(args[0], wxWindowPtr):
266 apply(self.SetItemMinSizeWindow, args)
267 else:
268 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
269
270 def SetItemMinSizeWH(self, *args):
271 if type(args[0]) == type(1):
272 apply(self.SetItemMinSizePosWH, args)
273 elif isinstance(args[0], wxSizerPtr):
274 apply(self.SetItemMinSizeSizerWH, args)
275 elif isinstance(args[0], wxWindowPtr):
276 apply(self.SetItemMinSizeWindowWH, args)
277 else:
278 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
279 "
280
281 wxSize GetSize();
282 wxPoint GetPosition();
283 wxSize GetMinSize();
284
285 %pragma(python) addtoclass = "
286 def GetSizeTuple(self):
287 return self.GetSize().asTuple()
288 def GetPositionTuple(self):
289 return self.GetPosition().asTuple()
290 def GetMinSizeTuple(self):
291 return self.GetMinSize().asTuple()
292 "
293
294 // void RecalcSizes() = 0;
295 // wxSize CalcMin() = 0;
296
297 void Layout();
298
299 wxSize Fit( wxWindow *window );
300 void FitInside( wxWindow *window );
301
302 void SetSizeHints( wxWindow *window );
303 void SetVirtualSizeHints( wxWindow *window );
304
305
306 // wxList& GetChildren();
307 %addmethods {
308 PyObject* GetChildren() {
309 wxSizerItemList& list = self->GetChildren();
310 return wxPy_ConvertList(&list, "wxSizerItem");
311 }
312 }
313
314 void SetDimension( int x, int y, int width, int height );
315
316 // Manage whether individual windows or sub-sizers are considered
317 // in the layout calculations or not.
318 %name(ShowWindow)void Show( wxWindow *window, bool show = TRUE );
319 %name(ShowSizer)void Show( wxSizer *sizer, bool show = TRUE );
320 %name(ShowPos)void Show( size_t index, bool show = TRUE );
321 %name(HideWindow)void Hide( wxWindow *window );
322 %name(HideSizer)void Hide( wxSizer *sizer );
323 %name(HidePos)void Hide( size_t index );
324 %name(IsShownWindow)bool IsShown( wxWindow *window );
325 %name(IsShownSizer)bool IsShown( wxSizer *sizer );
326 %name(IsShownPos)bool IsShown( size_t index );
327
328 %pragma(python) addtoclass = "
329 def Show(self, *args):
330 if type(args[0]) == type(1):
331 apply(self.ShowPos, args)
332 elif isinstance(args[0], wxSizerPtr):
333 apply(self.ShowSizer, args)
334 elif isinstance(args[0], wxWindowPtr):
335 apply(self.ShowWindow, args)
336 else:
337 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
338
339 def Hide(self, *args):
340 if type(args[0]) == type(1):
341 apply(self.HidePos, args)
342 elif isinstance(args[0], wxSizerPtr):
343 apply(self.HideSizer, args)
344 elif isinstance(args[0], wxWindowPtr):
345 apply(self.HideWindow, args)
346 else:
347 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
348
349 def IsShown(self, *args):
350 if type(args[0]) == type(1):
351 return apply(self.IsShownPos, args)
352 elif isinstance(args[0], wxSizerPtr):
353 return apply(self.IsShownSizer, args)
354 elif isinstance(args[0], wxWindowPtr):
355 return apply(self.IsShownWindow, args)
356 else:
357 raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
358 "
359
360 // Recursively call wxWindow::Show () on all sizer items.
361 void ShowItems (bool show);
362
363 };
364
365
366 //---------------------------------------------------------------------------
367 // Use this one for deriving Python classes from
368 %{
369 class wxPySizer : public wxSizer {
370 DECLARE_DYNAMIC_CLASS(wxPySizer);
371 public:
372 wxPySizer() : wxSizer() {};
373
374 DEC_PYCALLBACK___pure(RecalcSizes);
375 DEC_PYCALLBACK_wxSize__pure(CalcMin);
376 PYPRIVATE;
377 };
378
379
380 IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
381 IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
382
383 IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
384 %}
385
386
387
388 class wxPySizer : public wxSizer {
389 public:
390 wxPySizer();
391 void _setCallbackInfo(PyObject* self, PyObject* _class);
392 %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPySizer)"
393 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
394 };
395
396
397 //---------------------------------------------------------------------------
398
399 class wxBoxSizer : public wxSizer {
400 public:
401 wxBoxSizer(int orient = wxHORIZONTAL);
402 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
403 int GetOrientation();
404 void SetOrientation(int orient);
405 void RecalcSizes();
406 wxSize CalcMin();
407 };
408
409 //---------------------------------------------------------------------------
410
411 class wxStaticBoxSizer : public wxBoxSizer {
412 public:
413 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
414 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
415 wxStaticBox *GetStaticBox();
416 void RecalcSizes();
417 wxSize CalcMin();
418 };
419
420 //---------------------------------------------------------------------------
421
422 class wxNotebookSizer: public wxSizer {
423 public:
424 wxNotebookSizer( wxNotebook *nb );
425 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
426 void RecalcSizes();
427 wxSize CalcMin();
428 wxNotebook *GetNotebook();
429 };
430
431 //---------------------------------------------------------------------------
432
433 class wxGridSizer: public wxSizer
434 {
435 public:
436 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
437 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
438
439 void RecalcSizes();
440 wxSize CalcMin();
441
442 void SetCols( int cols );
443 void SetRows( int rows );
444 void SetVGap( int gap );
445 void SetHGap( int gap );
446 int GetCols();
447 int GetRows();
448 int GetVGap();
449 int GetHGap();
450 };
451
452 //---------------------------------------------------------------------------
453
454 enum wxFlexSizerGrowMode
455 {
456 // don't resize the cells in non-flexible direction at all
457 wxFLEX_GROWMODE_NONE,
458
459 // uniformly resize only the specified ones (default)
460 wxFLEX_GROWMODE_SPECIFIED,
461
462 // uniformly resize all cells
463 wxFLEX_GROWMODE_ALL
464 };
465
466
467 class wxFlexGridSizer: public wxGridSizer
468 {
469 public:
470 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
471 %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
472
473 void RecalcSizes();
474 wxSize CalcMin();
475
476 void AddGrowableRow( size_t idx, int proportion = 0 );
477 void RemoveGrowableRow( size_t idx );
478 void AddGrowableCol( size_t idx, int proportion = 0 );
479 void RemoveGrowableCol( size_t idx );
480
481 // the sizer cells may grow in both directions, not grow at all or only
482 // grow in one direction but not the other
483
484 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
485 void SetFlexibleDirection(int direction);
486 int GetFlexibleDirection();
487
488 // note that the grow mode only applies to the direction which is not
489 // flexible
490 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
491 wxFlexSizerGrowMode GetNonFlexibleGrowMode();
492 };
493
494 //---------------------------------------------------------------------------