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 );
54 %pythoncode { SetOption = SetProportion}
55 %pythoncode { GetOption = GetProportion}
57 void SetFlag( int flag );
60 void SetBorder( int border );
63 wxWindow *GetWindow();
64 void SetWindow( wxWindow *window );
67 void SetSizer( wxSizer *sizer );
69 const wxSize& GetSpacer();
70 void SetSpacer( const wxSize &size );
72 void Show( bool show );
75 wxPoint GetPosition();
77 // wxObject* GetUserData();
79 // Assume that the user data is a wxPyUserData object and return the contents
80 PyObject* GetUserData() {
81 wxPyUserData* data = (wxPyUserData*)self->GetUserData();
83 Py_INCREF(data->m_obj);
94 //---------------------------------------------------------------------------
97 // Figure out the type of the sizer item
99 struct wxPySizerItemInfo {
101 : window(NULL), sizer(NULL), gotSize(False),
102 size(wxDefaultSize), gotPos(False), pos(-1)
113 static wxPySizerItemInfo wxPySizerItemTypeHelper(PyObject* item, bool checkSize, bool checkIdx ) {
115 wxPySizerItemInfo info;
117 wxSize* sizePtr = &size;
119 // Find out what the type of the item is
121 if ( ! wxPyConvertSwigPtr(item, (void**)&info.window, wxT("wxWindow")) ) {
126 if ( ! wxPyConvertSwigPtr(item, (void**)&info.sizer, wxT("wxSizer")) ) {
130 // try wxSize or (w,h)
131 if ( checkSize && wxSize_helper(item, &sizePtr)) {
132 info.size = *sizePtr;
137 if (checkIdx && PyInt_Check(item)) {
138 info.pos = PyInt_AsLong(item);
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");
153 // can this one happen?
154 PyErr_SetString(PyExc_TypeError, "wxWindow, wxSizer, wxSize, or (w,h) or int (position) expected for item");
164 class wxSizer : public wxObject {
166 // wxSizer(); **** abstract, can't instantiate
170 void _setOORInfo(PyObject* _self) {
171 self->SetClientObject(new wxPyOORClientData(_self));
175 void Add(PyObject* item, int proportion=0, int flag=0, int border=0,
176 PyObject* userData=NULL) {
178 wxPyUserData* data = NULL;
179 bool blocked = wxPyBeginBlockThreads();
180 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
181 if ( userData && (info.window || info.sizer || info.gotSize) )
182 data = new wxPyUserData(userData);
183 wxPyEndBlockThreads(blocked);
185 // Now call the real Add method if a valid item type was found
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);
196 void Insert(int before, PyObject* item, int proportion=0, int flag=0,
197 int border=0, PyObject* userData=NULL) {
199 wxPyUserData* data = NULL;
200 bool blocked = wxPyBeginBlockThreads();
201 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
202 if ( userData && (info.window || info.sizer || info.gotSize) )
203 data = new wxPyUserData(userData);
204 wxPyEndBlockThreads(blocked);
206 // Now call the real Insert method if a valid item type was found
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);
218 void Prepend(PyObject* item, int proportion=0, int flag=0, int border=0,
219 PyObject* userData=NULL) {
221 wxPyUserData* data = NULL;
222 bool blocked = wxPyBeginBlockThreads();
223 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, True, False);
224 if ( userData && (info.window || info.sizer || info.gotSize) )
225 data = new wxPyUserData(userData);
226 wxPyEndBlockThreads(blocked);
228 // Now call the real Prepend method if a valid item type was found
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);
239 bool Remove(PyObject* item) {
240 bool blocked = wxPyBeginBlockThreads();
241 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, True);
242 wxPyEndBlockThreads(blocked);
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);
254 void _SetItemMinSize(PyObject* item, const wxSize& size) {
255 bool blocked = wxPyBeginBlockThreads();
256 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, True);
257 wxPyEndBlockThreads(blocked);
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);
267 %name(AddItem) void Add( wxSizerItem *item );
268 %name(InsertItem) void Insert( size_t index, wxSizerItem *item );
269 %name(PrependItem) void Prepend( wxSizerItem *item );
273 def AddMany(self, widgets):
275 AddMany is a convenience method for adding several items
276 to a sizer at one time. Simply pass it a list of tuples,
277 where each tuple consists of the parameters that you
278 would normally pass to the `Add` method.
280 for childinfo in widgets:
281 if type(childinfo) != type(()) or (len(childinfo) == 2 and type(childinfo[0]) == type(1)):
282 childinfo = (childinfo, )
285 %# for backwards compatibility only, please do not use in new code
286 AddWindow = wx._deprecated(Add, "AddWindow is deprecated, use `Add` instead.")
287 AddSizer = wx._deprecated(Add, "AddSizer is deprecated, use `Add` instead.")
288 AddSpacer = wx._deprecated(Add, "AddSpacer is deprecated, use `Add` instead.")
289 PrependWindow = wx._deprecated(Prepend, "PrependWindow is deprecated, use `Prepend` instead.")
290 PrependSizer = wx._deprecated(Prepend, "PrependSizer is deprecated, use `Prepend` instead.")
291 PrependSpacer = wx._deprecated(Prepend, "PrependSpacer is deprecated, use `Prepend` instead.")
292 InsertWindow = wx._deprecated(Insert, "InsertWindow is deprecated, use `Insert` instead.")
293 InsertSizer = wx._deprecated(Insert, "InsertSizer is deprecated, use `Insert` instead.")
294 InsertSpacer = wx._deprecated(Insert, "InsertSpacer is deprecated, use `Insert` instead.")
295 RemoveWindow = wx._deprecated(Remove, "RemoveWindow is deprecated, use `Remove` instead.")
296 RemoveSizer = wx._deprecated(Remove, "RemoveSizer is deprecated, use `Remove` instead.")
297 RemovePos = wx._deprecated(Remove, "RemovePos is deprecated, use `Remove` instead.")
300 def SetItemMinSize(self, item, *args):
302 return self._SetItemMinSize(item, args)
304 return self._SetItemMinSize(item, args[0])
308 void SetDimension( int x, int y, int width, int height );
309 void SetMinSize( const wxSize &size );
312 wxPoint GetPosition();
316 def GetSizeTuple(self):
317 return self.GetSize().asTuple()
318 def GetPositionTuple(self):
319 return self.GetPosition().asTuple()
320 def GetMinSizeTuple(self):
321 return self.GetMinSize().asTuple()
324 virtual void RecalcSizes();
325 virtual wxSize CalcMin();
329 wxSize Fit( wxWindow *window );
330 void FitInside( wxWindow *window );
332 void SetSizeHints( wxWindow *window );
333 void SetVirtualSizeHints( wxWindow *window );
335 void Clear( bool delete_windows=False );
336 void DeleteWindows();
339 // wxList& GetChildren();
341 PyObject* GetChildren() {
342 wxSizerItemList& list = self->GetChildren();
343 return wxPy_ConvertList(&list);
348 // Manage whether individual windows or sub-sizers are considered
349 // in the layout calculations or not.
352 void Show(PyObject* item, bool show = True) {
353 bool blocked = wxPyBeginBlockThreads();
354 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
355 wxPyEndBlockThreads(blocked);
357 self->Show(info.window, show);
358 else if ( info.sizer )
359 self->Show(info.sizer, show);
363 void Hide(PyObject* item) {
364 bool blocked = wxPyBeginBlockThreads();
365 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
366 wxPyEndBlockThreads(blocked);
368 self->Hide(info.window);
369 else if ( info.sizer )
370 self->Hide(info.sizer);
374 bool IsShown(PyObject* item) {
375 bool blocked = wxPyBeginBlockThreads();
376 wxPySizerItemInfo info = wxPySizerItemTypeHelper(item, False, False);
377 wxPyEndBlockThreads(blocked);
379 return self->IsShown(info.window);
380 else if ( info.sizer )
381 return self->IsShown(info.sizer);
388 // Recursively call wxWindow::Show() on all sizer items.
389 void ShowItems(bool show);
394 //---------------------------------------------------------------------------
395 // Use this one for deriving Python classes from
398 IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
399 IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
400 IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
405 class wxPySizer : public wxSizer {
407 %pythonAppend wxPySizer "self._setCallbackInfo(self, PySizer);self._setOORInfo(self)"
410 void _setCallbackInfo(PyObject* self, PyObject* _class);
414 //---------------------------------------------------------------------------
417 class wxBoxSizer : public wxSizer {
419 %pythonAppend wxBoxSizer "self._setOORInfo(self)"
421 wxBoxSizer(int orient = wxHORIZONTAL);
423 int GetOrientation();
424 void SetOrientation(int orient);
429 //---------------------------------------------------------------------------
432 class wxStaticBoxSizer : public wxBoxSizer {
434 %pythonAppend wxStaticBoxSizer "self._setOORInfo(self)"
436 wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
438 wxStaticBox *GetStaticBox();
443 //---------------------------------------------------------------------------
446 class wxGridSizer: public wxSizer
449 %pythonAppend wxGridSizer "self._setOORInfo(self)"
451 wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
456 void SetCols( int cols );
457 void SetRows( int rows );
458 void SetVGap( int gap );
459 void SetHGap( int gap );
466 //---------------------------------------------------------------------------
469 enum wxFlexSizerGrowMode
471 // don't resize the cells in non-flexible direction at all
472 wxFLEX_GROWMODE_NONE,
474 // uniformly resize only the specified ones (default)
475 wxFLEX_GROWMODE_SPECIFIED,
477 // uniformly resize all cells
482 class wxFlexGridSizer: public wxGridSizer
485 %pythonAppend wxFlexGridSizer "self._setOORInfo(self)"
487 wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
492 void AddGrowableRow( size_t idx, int proportion = 0 );
493 void RemoveGrowableRow( size_t idx );
494 void AddGrowableCol( size_t idx, int proportion = 0 );
495 void RemoveGrowableCol( size_t idx );
497 // the sizer cells may grow in both directions, not grow at all or only
498 // grow in one direction but not the other
500 // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
501 void SetFlexibleDirection(int direction);
502 int GetFlexibleDirection();
504 // note that the grow mode only applies to the direction which is not
506 void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
507 wxFlexSizerGrowMode GetNonFlexibleGrowMode();
509 // Read-only access to the row heights and col widths arrays
510 const wxArrayInt& GetRowHeights() const;
511 const wxArrayInt& GetColWidths() const;
514 //---------------------------------------------------------------------------