1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     SWIG definitions of the wxSizer family of classes
 
   7 // Created:     18-Sept-1999
 
   9 // Copyright:   (c) 1999 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  18 #include <wx/notebook.h>
 
  21 //----------------------------------------------------------------------
 
  24 %include my_typemaps.i
 
  26 // Import some definitions of other classes, etc.
 
  32 %pragma(python) code = "import wx"
 
  34 //---------------------------------------------------------------------------
 
  37 class wxSizerItem : public wxObject {
 
  39     // No need to ever create one directly in Python...
 
  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 );
 
  50     void SetDimension( wxPoint pos, wxSize size );
 
  53     void SetInitSize( int x, int y );
 
  55     %name(SetRatioWH) void SetRatio( int width, int height );
 
  56     %name(SetRatioSize) void SetRatio( wxSize size );
 
  57     void SetRatio( float ratio );
 
  64     void SetProportion( int proportion );
 
  66     %pragma(python) addtoclass = "SetOption = SetProportion"
 
  67     %pragma(python) addtoclass = "GetOption = GetProportion"
 
  68     void SetFlag( int flag );
 
  70     void SetBorder( int border );
 
  73     wxWindow *GetWindow();
 
  74     void SetWindow( wxWindow *window );
 
  76     void SetSizer( wxSizer *sizer );
 
  77     const wxSize& GetSpacer();
 
  78     void SetSpacer( const wxSize &size );
 
  80     void Show( bool show );
 
  83     wxPoint GetPosition();
 
  85     // wxObject* GetUserData();
 
  87         // Assume that the user data is a wxPyUserData object and return the contents
 
  88         PyObject* GetUserData() {
 
  89             wxPyUserData* data = (wxPyUserData*)self->GetUserData();
 
  91                 Py_INCREF(data->m_obj);
 
 102 //---------------------------------------------------------------------------
 
 105 class wxSizer : public wxObject {
 
 107     // wxSizer();      ****  abstract, can't instantiate
 
 111         void _setOORInfo(PyObject* _self) {
 
 112             self->SetClientObject(new wxPyOORClientData(_self));
 
 117         void Destroy() { delete self; }
 
 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;
 
 130             wxSize*   sizePtr = &size;
 
 131             wxPyUserData* data = NULL;
 
 132             if (userData) data = new wxPyUserData(userData);
 
 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);
 
 138             else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
 
 139                 self->Add(sizer, proportion, flag, border, data);
 
 141             else if (wxSize_helper(item, &sizePtr))
 
 142                 self->Add(sizePtr->GetWidth(), sizePtr->GetHeight(),
 
 143                           proportion, flag, border, data);
 
 145                 if (data) delete data;
 
 146                 PyErr_SetString(PyExc_TypeError,
 
 147                                 "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
 
 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;
 
 162             wxSize*   sizePtr = &size;
 
 163             wxPyUserData* data = NULL;
 
 164             if (userData) data = new wxPyUserData(userData);
 
 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);
 
 170             else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
 
 171                 self->Insert(before, sizer, proportion, flag, border, data);
 
 173             else if (wxSize_helper(item, &sizePtr))
 
 174                 self->Insert(before, sizePtr->GetWidth(), sizePtr->GetHeight(),
 
 175                           proportion, flag, border, data);
 
 177                 if (data) delete data;
 
 178                 PyErr_SetString(PyExc_TypeError,
 
 179                                 "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
 
 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;
 
 195             wxSize*   sizePtr = &size;
 
 196             wxPyUserData* data = NULL;
 
 197             if (userData) data = new wxPyUserData(userData);
 
 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);
 
 203             else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
 
 204                 self->Prepend(sizer, proportion, flag, border, data);
 
 206             else if (wxSize_helper(item, &sizePtr))
 
 207                 self->Prepend(sizePtr->GetWidth(), sizePtr->GetHeight(),
 
 208                               proportion, flag, border, data);
 
 210                 if (data) delete data;
 
 211                 PyErr_SetString(PyExc_TypeError,
 
 212                                 "wxWindow, wxSizer, wxSize, or (w,h) expected for item");
 
 216         bool Remove(PyObject* item) {
 
 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);
 
 224             else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
 
 225                 return self->Remove(sizer);
 
 227             else if (PyInt_Check(item)) {
 
 228                 int pos = PyInt_AsLong(item);
 
 229                 return self->Remove(pos);
 
 232                 PyErr_SetString(PyExc_TypeError,
 
 233                                 "wxWindow, wxSizer or int (position) expected.");
 
 238         void _SetItemMinSize(PyObject* item, wxSize size) {
 
 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);
 
 246             else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
 
 247                 self->SetItemMinSize(sizer, size);
 
 249             else if (PyInt_Check(item)) {
 
 250                 int pos = PyInt_AsLong(item);
 
 251                 self->SetItemMinSize(pos, size);
 
 254                 PyErr_SetString(PyExc_TypeError,
 
 255                                 "wxWindow, wxSizer or int (position) expected.");
 
 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
 
 266         self._Add(item, *args, **kw)
 
 268     def AddMany(self, widgets):
 
 269         for childinfo in widgets:
 
 270             if type(childinfo) != type(()):
 
 271                 childinfo = (childinfo, )
 
 274     def Prepend(self, item, *args, **kw):
 
 275         if type(item) == type(1):
 
 276             item = (item, args[0])  # backwards compatibility, args are width, height
 
 278         self._Prepend(item, *args, **kw)
 
 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
 
 284         self._Insert(before, item, *args, **kw)
 
 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
 
 294     def SetItemMinSize(self, item, *args):
 
 296             return self._SetItemMinSize(item, args)
 
 298             return self._SetItemMinSize(item, args[0])
 
 303     void SetDimension( int x, int y, int width, int height );
 
 304     void SetMinSize(wxSize size);
 
 307     wxPoint GetPosition();
 
 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()
 
 319     // void RecalcSizes() = 0;
 
 320     // wxSize CalcMin() = 0;
 
 324     wxSize Fit( wxWindow *window );
 
 325     void FitInside( wxWindow *window );
 
 327     void SetSizeHints( wxWindow *window );
 
 328     void SetVirtualSizeHints( wxWindow *window );
 
 330     void Clear( bool delete_windows=FALSE );
 
 331     void DeleteWindows();
 
 334     // wxList& GetChildren();
 
 336         PyObject* GetChildren() {
 
 337             wxList& list = self->GetChildren();
 
 338             return wxPy_ConvertList(&list, "wxSizerItem");
 
 343     // Manage whether individual windows or sub-sizers are considered
 
 344     // in the layout calculations or not.
 
 347         void Show(PyObject* item, bool show = TRUE) {
 
 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);
 
 356                 PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
 
 359         void Hide(PyObject* item) {
 
 362             // Find out what type the item is and call the real method
 
 363             if (! SWIG_GetPtrObj(item, (void**)&window, "_wxWindow_p"))
 
 365             else if (!SWIG_GetPtrObj(item, (void**)&sizer, "_wxSizer_p"))
 
 368                 PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
 
 371         bool IsShown(PyObject* item) {
 
 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);
 
 380                 PyErr_SetString(PyExc_TypeError, "wxWindow or wxSizer expected.");
 
 387     // Recursively call wxWindow::Show() on all sizer items.
 
 388     void ShowItems(bool show);
 
 393 //---------------------------------------------------------------------------
 
 394 // Use this one for deriving Python classes from
 
 396 class wxPySizer : public wxSizer {
 
 397     DECLARE_DYNAMIC_CLASS(wxPySizer);
 
 399     wxPySizer() : wxSizer() {};
 
 401     DEC_PYCALLBACK___pure(RecalcSizes);
 
 402     DEC_PYCALLBACK_wxSize__pure(CalcMin);
 
 407 IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
 
 408 IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
 
 410 IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
 
 415 class wxPySizer : public wxSizer {
 
 418     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 419     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPySizer)"
 
 420     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 424 //---------------------------------------------------------------------------
 
 426 class  wxBoxSizer : public wxSizer {
 
 428     wxBoxSizer(int orient = wxHORIZONTAL);
 
 429     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 430     int GetOrientation();
 
 431     void SetOrientation(int orient);
 
 436 //---------------------------------------------------------------------------
 
 438 class  wxStaticBoxSizer : public wxBoxSizer {
 
 440     wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
 
 441     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 442     wxStaticBox *GetStaticBox();
 
 447 //---------------------------------------------------------------------------
 
 449 class wxNotebookSizer: public wxSizer {
 
 451     wxNotebookSizer( wxNotebook *nb );
 
 452     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 455     wxNotebook *GetNotebook();
 
 458 //---------------------------------------------------------------------------
 
 460 class wxGridSizer: public wxSizer
 
 463     wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
 
 464     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 469     void SetCols( int cols );
 
 470     void SetRows( int rows );
 
 471     void SetVGap( int gap );
 
 472     void SetHGap( int gap );
 
 479 //---------------------------------------------------------------------------
 
 481 enum wxFlexSizerGrowMode
 
 483     // don't resize the cells in non-flexible direction at all
 
 484     wxFLEX_GROWMODE_NONE,
 
 486     // uniformly resize only the specified ones (default)
 
 487     wxFLEX_GROWMODE_SPECIFIED,
 
 489     // uniformly resize all cells
 
 494 class wxFlexGridSizer: public wxGridSizer
 
 497     wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
 
 498     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 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 );
 
 508     // the sizer cells may grow in both directions, not grow at all or only
 
 509     // grow in one direction but not the other
 
 511     // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
 
 512     void SetFlexibleDirection(int direction);
 
 513     int GetFlexibleDirection();
 
 515     // note that the grow mode only applies to the direction which is not
 
 517     void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
 
 518     wxFlexSizerGrowMode GetNonFlexibleGrowMode();
 
 521 //---------------------------------------------------------------------------