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