1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: SWIG interface defs for the Sizers
7 // Created: 18-Sept-1999
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
16 //---------------------------------------------------------------------------
21 //---------------------------------------------------------------------------
25 class wxSizerItem : public wxObject {
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 );
38 void SetDimension( wxPoint pos, wxSize size );
41 void SetInitSize( int x, int y );
43 %name(SetRatioWH) void SetRatio( int width, int height );
44 %name(SetRatioSize) void SetRatio( wxSize size );
45 void SetRatio( float ratio );
52 void SetProportion( int proportion );
55 void SetFlag( int flag );
58 void SetBorder( int border );
61 wxWindow *GetWindow();
62 void SetWindow( wxWindow *window );
65 void SetSizer( wxSizer *sizer );
67 const wxSize& GetSpacer();
68 void SetSpacer( const wxSize &size );
70 void Show( bool show );
73 wxPoint GetPosition();
75 // wxObject* GetUserData();
77 // Assume that the user data is a wxPyUserData object and return the contents
78 PyObject* GetUserData() {
79 wxPyUserData* data = (wxPyUserData*)self->GetUserData();
81 Py_INCREF(data->m_obj);
92 //---------------------------------------------------------------------------
95 // Figure out the type of the sizer item
97 struct wxPySizerItemInfo {
99 : window(NULL), sizer(NULL), gotSize(False),
100 size(wxDefaultSize), gotPos(False), pos(-1)
111 static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) {
113 wxPySizerItemInfo info;
115 wxSize* sizePtr = &size;
117 // Find out what the type of the item is
119 if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) {
124 if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) {
128 // try wxSize or (w,h)
129 if ( checkSize && wxSize_helper(item, &sizePtr)) {
130 info.size = *sizePtr;
135 if (checkIdx && PyInt_Check(item)) {
136 info.pos = PyInt_AsLong(item);
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");
151 // can this one happen?
152 PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer, wxSize, or (w,h) or int (position) expected for item");
162 class wxSizer : public wxObject {
164 // wxSizer(); **** abstract, can't instantiate
168 void _setOORInfo(PyObject* _self) {
169 self->SetClientObject(new wxPyOORClientData(_self));
173 void Add(PyObject* item, int proportion=0, int flag=0, int border=0,
174 PyObject* userData=NULL) {
176 wxPyUserData* data = NULL;
177 wxPyBeginBlockThreads();
178 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
179 if ( userData && (info.window || info.sizer || info.gotSize) )
180 data = new wxPyUserData(userData);
181 wxPyEndBlockThreads();
183 // Now call the real Add method if a valid item type was found
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);
194 void Insert(int before, PyObject* item, int proportion=0, int flag=0,
195 int border=0, PyObject* userData=NULL) {
197 wxPyUserData* data = NULL;
198 wxPyBeginBlockThreads();
199 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
200 if ( userData && (info.window || info.sizer || info.gotSize) )
201 data = new wxPyUserData(userData);
202 wxPyEndBlockThreads();
204 // Now call the real Insert method if a valid item type was found
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);
216 void Prepend(PyObject* item, int proportion=0, int flag=0, int border=0,
217 PyObject* userData=NULL) {
219 wxPyUserData* data = NULL;
220 wxPyBeginBlockThreads();
221 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
222 if ( userData && (info.window || info.sizer || info.gotSize) )
223 data = new wxPyUserData(userData);
224 wxPyEndBlockThreads();
226 // Now call the real Prepend method if a valid item type was found
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);
237 bool Remove(PyObject* item) {
238 wxPyBeginBlockThreads();
239 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, True);
240 wxPyEndBlockThreads();
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);
252 void _SetItemMinSize(PyObject* item, const wxSize& size) {
253 wxPyBeginBlockThreads();
254 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, True);
255 wxPyEndBlockThreads();
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);
265 %name(AddItem) void Add( wxSizerItem *item );
266 %name(InsertItem) void Insert( size_t index, wxSizerItem *item );
267 %name(PrependItem) void Prepend( wxSizerItem *item );
271 def AddMany(self, widgets):
272 for childinfo in widgets:
273 if type(childinfo) != type(()) or (len(childinfo) == 2 and type(childinfo[0]) == type(1)):
274 childinfo = (childinfo, )
277 %# for backwards compatibility only, please do not use in new code
278 AddWindow = AddSizer = AddSpacer = Add
279 PrependWindow = PrependSizer = PrependSpacer = Prepend
280 InsertWindow = InsertSizer = InsertSpacer = Insert
281 RemoveWindow = RemoveSizer = RemovePos = Remove
284 def SetItemMinSize(self, item, *args):
286 return self._SetItemMinSize(item, args)
288 return self._SetItemMinSize(item, args[0])
292 void SetDimension( int x, int y, int width, int height );
293 void SetMinSize( const wxSize &size );
296 wxPoint GetPosition();
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()
308 virtual void RecalcSizes();
309 virtual wxSize CalcMin();
313 wxSize Fit( wxWindow *window );
314 void FitInside( wxWindow *window );
316 void SetSizeHints( wxWindow *window );
317 void SetVirtualSizeHints( wxWindow *window );
319 void Clear( bool delete_windows=False );
320 void DeleteWindows();
323 // wxList& GetChildren();
325 PyObject* GetChildren() {
326 wxSizerItemList& list = self->GetChildren();
327 return wxPy_ConvertList(&list);
332 // Manage whether individual windows or sub-sizers are considered
333 // in the layout calculations or not.
336 void Show(PyObject* item, bool show = True) {
337 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
339 self->Show(info.window, show);
340 else if ( info.sizer )
341 self->Show(info.sizer, show);
345 void Hide(PyObject* item) {
346 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
348 self->Hide(info.window);
349 else if ( info.sizer )
350 self->Hide(info.sizer);
354 bool IsShown(PyObject* item) {
355 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
357 return self->IsShown(info.window);
358 else if ( info.sizer )
359 return self->IsShown(info.sizer);
366 // Recursively call wxWindow::Show() on all sizer items.
367 void ShowItems(bool show);
372 //---------------------------------------------------------------------------
373 // Use this one for deriving Python classes from
376 IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
377 IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
378 IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
383 class wxPySizer : public wxSizer {
385 %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)"
388 void _setCallbackInfo(PyObject* self, PyObject* _class);
392 //---------------------------------------------------------------------------
395 class wxBoxSizer : public wxSizer {
397 %pythonAppend wxBoxSizer "self._setOORInfo(self)"
399 wxBoxSizer(int orient = wxHORIZONTAL);
401 int GetOrientation();
402 void SetOrientation(int orient);
407 //---------------------------------------------------------------------------
410 class wxStaticBoxSizer : public wxBoxSizer {
412 %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)"
414 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
416 wxStaticBox *GetStaticBox();
421 //---------------------------------------------------------------------------
424 class wxGridSizer: public wxSizer
427 %pythonAppend wxGridSizer "self._setOORInfo(self)"
429 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
434 void SetCols( int cols );
435 void SetRows( int rows );
436 void SetVGap( int gap );
437 void SetHGap( int gap );
444 //---------------------------------------------------------------------------
447 enum wxFlexSizerGrowMode
449 // don't resize the cells in non-flexible direction at all
450 wxFLEX_GROWMODE_NONE,
452 // uniformly resize only the specified ones (default)
453 wxFLEX_GROWMODE_SPECIFIED,
455 // uniformly resize all cells
460 class wxFlexGridSizer: public wxGridSizer
463 %pythonAppend wxFlexGridSizer "self._setOORInfo(self)"
465 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
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 );
475 // the sizer cells may grow in both directions, not grow at all or only
476 // grow in one direction but not the other
478 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
479 void SetFlexibleDirection(int direction);
480 int GetFlexibleDirection();
482 // note that the grow mode only applies to the direction which is not
484 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
485 wxFlexSizerGrowMode GetNonFlexibleGrowMode();
487 // Read-only access to the row heights and col widths arrays
488 const wxArrayInt& GetRowHeights() const;
489 const wxArrayInt& GetColWidths() const;
492 //---------------------------------------------------------------------------