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 //---------------------------------------------------------------------------
 
 104 class wxSizer : public wxObject {
 
 106     // wxSizer();      ****  abstract, can't instantiate
 
 110         void _setOORInfo(PyObject* _self) {
 
 111             self->SetClientObject(new wxPyOORClientData(_self));
 
 116         void Destroy() { delete self; }
 
 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);
 
 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);
 
 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);
 
 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);
 
 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);
 
 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);
 
 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);
 
 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);
 
 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);
 
 176         // TODO:  AddItem, InsertItem, PrependItem
 
 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 );
 
 184     %name(DetachWindow)bool Detach( wxWindow *window );
 
 185     %name(DetachSizer)bool Detach( wxSizer *sizer );
 
 186     %name(DetachPos)bool Detach( int pos );
 
 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)
 
 198             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 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)
 
 208             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 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)
 
 218             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 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)
 
 228             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 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)
 
 238             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 240     def AddMany(self, widgets):
 
 241         for childinfo in widgets:
 
 242             if type(childinfo) != type(()):
 
 243                 childinfo = (childinfo, )
 
 244             apply(self.Add, childinfo)
 
 247     void Clear( bool delete_windows = false );
 
 248     void DeleteWindows();
 
 250     void SetMinSize(wxSize size);
 
 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);
 
 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)
 
 268             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 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)
 
 278             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 282     wxPoint GetPosition();
 
 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()
 
 294     // void RecalcSizes() = 0;
 
 295     // wxSize CalcMin() = 0;
 
 299     wxSize Fit( wxWindow *window );
 
 300     void FitInside( wxWindow *window );
 
 302     void SetSizeHints( wxWindow *window );
 
 303     void SetVirtualSizeHints( wxWindow *window );
 
 306     // wxList& GetChildren();
 
 308         PyObject* GetChildren() {
 
 309             wxSizerItemList& list = self->GetChildren();
 
 310             return wxPy_ConvertList(&list, "wxSizerItem");
 
 314     void SetDimension( int x, int y, int width, int height );
 
 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 );
 
 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)
 
 337             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 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)
 
 347             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 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)
 
 357             raise TypeError, 'Expected int, wxSizer or wxWindow parameter'
 
 360     // Recursively call wxWindow::Show () on all sizer items.
 
 361     void ShowItems (bool show);
 
 366 //---------------------------------------------------------------------------
 
 367 // Use this one for deriving Python classes from
 
 369 class wxPySizer : public wxSizer {
 
 370     DECLARE_DYNAMIC_CLASS(wxPySizer);
 
 372     wxPySizer() : wxSizer() {};
 
 374     DEC_PYCALLBACK___pure(RecalcSizes);
 
 375     DEC_PYCALLBACK_wxSize__pure(CalcMin);
 
 380 IMP_PYCALLBACK___pure(wxPySizer, wxSizer, RecalcSizes);
 
 381 IMP_PYCALLBACK_wxSize__pure(wxPySizer, wxSizer, CalcMin);
 
 383 IMPLEMENT_DYNAMIC_CLASS(wxPySizer, wxSizer);
 
 388 class wxPySizer : public wxSizer {
 
 391     void _setCallbackInfo(PyObject* self, PyObject* _class);
 
 392     %pragma(python) addtomethod = "__init__:self._setCallbackInfo(self, wxPySizer)"
 
 393     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 397 //---------------------------------------------------------------------------
 
 399 class  wxBoxSizer : public wxSizer {
 
 401     wxBoxSizer(int orient = wxHORIZONTAL);
 
 402     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 403     int GetOrientation();
 
 404     void SetOrientation(int orient);
 
 409 //---------------------------------------------------------------------------
 
 411 class  wxStaticBoxSizer : public wxBoxSizer {
 
 413     wxStaticBoxSizer(wxStaticBox *box, int orient = wxHORIZONTAL);
 
 414     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 415     wxStaticBox *GetStaticBox();
 
 420 //---------------------------------------------------------------------------
 
 422 class wxNotebookSizer: public wxSizer {
 
 424     wxNotebookSizer( wxNotebook *nb );
 
 425     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 428     wxNotebook *GetNotebook();
 
 431 //---------------------------------------------------------------------------
 
 433 class wxGridSizer: public wxSizer
 
 436     wxGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
 
 437     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 442     void SetCols( int cols );
 
 443     void SetRows( int rows );
 
 444     void SetVGap( int gap );
 
 445     void SetHGap( int gap );
 
 452 //---------------------------------------------------------------------------
 
 454 enum wxFlexSizerGrowMode
 
 456     // don't resize the cells in non-flexible direction at all
 
 457     wxFLEX_GROWMODE_NONE,
 
 459     // uniformly resize only the specified ones (default)
 
 460     wxFLEX_GROWMODE_SPECIFIED,
 
 462     // uniformly resize all cells
 
 467 class wxFlexGridSizer: public wxGridSizer
 
 470     wxFlexGridSizer( int rows=1, int cols=0, int vgap=0, int hgap=0 );
 
 471     %pragma(python) addtomethod = "__init__:self._setOORInfo(self)"
 
 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 );
 
 481     // the sizer cells may grow in both directions, not grow at all or only
 
 482     // grow in one direction but not the other
 
 484     // the direction may be wxVERTICAL, wxHORIZONTAL or wxBOTH (default)
 
 485     void SetFlexibleDirection(int direction);
 
 486     int GetFlexibleDirection();
 
 488     // note that the grow mode only applies to the direction which is not
 
 490     void SetNonFlexibleGrowMode(wxFlexSizerGrowMode mode);
 
 491     wxFlexSizerGrowMode GetNonFlexibleGrowMode();
 
 494 //---------------------------------------------------------------------------