1 /////////////////////////////////////////////////////////////////////////////
 
   3 // Purpose:     SWIG interface defs for wxNotebook and such
 
   7 // Created:     2-June-1998
 
   9 // Copyright:   (c) 2003 by Total Control Software
 
  10 // Licence:     wxWindows license
 
  11 /////////////////////////////////////////////////////////////////////////////
 
  16 //---------------------------------------------------------------------------
 
  18 MAKE_CONST_WXSTRING(NotebookNameStr);
 
  20 //---------------------------------------------------------------------------
 
  23 // TODO:  Virtualize this class so other book controls can be derived in Python
 
  25 MustHaveApp(wxBookCtrlBase);
 
  27 //  Common base class for wxList/Tree/Notebook
 
  28 class wxBookCtrlBase : public wxControl
 
  31     // This is an ABC, it can't be constructed...
 
  33 //     wxBookCtrlBase(wxWindow *parent,
 
  35 //                const wxPoint& pos = wxDefaultPosition,
 
  36 //                const wxSize& size = wxDefaultSize,
 
  38 //                const wxString& name = wxPyEmptyString);
 
  39 //     %RenameCtor(PreBookCtrlBase, wxBookCtrlBase());
 
  40 //     bool Create(wxWindow *parent,
 
  42 //                 const wxPoint& pos = wxDefaultPosition,
 
  43 //                 const wxSize& size = wxDefaultSize,
 
  45 //                 const wxString& name = wxPyEmptyString);
 
  48     // get number of pages in the dialog
 
  49     virtual size_t GetPageCount() const;
 
  51     // get the panel which represents the given page
 
  52     virtual wxWindow *GetPage(size_t n);
 
  54     // get the current page or NULL if none
 
  55     wxWindow* GetCurrentPage() const;
 
  57     // get the currently selected page or wxNOT_FOUND if none
 
  58     virtual int GetSelection() const/* = 0*/;
 
  60     // set/get the title of a page
 
  61     virtual bool SetPageText(size_t n, const wxString& strText)/* = 0*/;
 
  62     virtual wxString GetPageText(size_t n) const/* = 0*/;
 
  65     // image list stuff: each page may have an image associated with it (all
 
  66     // images belong to the same image list)
 
  68     // sets the image list to use, it is *not* deleted by the control
 
  69     virtual void SetImageList(wxImageList *imageList);
 
  71     // as SetImageList() but we will delete the image list ourselves
 
  72     %disownarg( wxImageList *imageList );
 
  73     void AssignImageList(wxImageList *imageList);
 
  74     %cleardisown( wxImageList *imageList );
 
  76     // get pointer (may be NULL) to the associated image list
 
  77     wxImageList* GetImageList() const;
 
  79     // sets/returns item's image index in the current image list
 
  80     virtual int GetPageImage(size_t n) const/* = 0*/;
 
  81     virtual bool SetPageImage(size_t n, int imageId)/* = 0*/;
 
  84     // resize the notebook so that all pages will have the specified size
 
  85     virtual void SetPageSize(const wxSize& size);
 
  87     // calculate the size of the control from the size of its page
 
  88     virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const/* = 0*/;
 
  92     // remove one page from the control and delete it
 
  93     virtual bool DeletePage(size_t n);
 
  95     // remove one page from the notebook, without deleting it
 
  96     virtual bool RemovePage(size_t n);
 
  98     // remove all pages and delete them
 
  99     virtual bool DeleteAllPages();
 
 101     // adds a new page to the control
 
 102     virtual bool AddPage(wxWindow *page,
 
 103                          const wxString& text,
 
 107     // the same as AddPage(), but adds the page at the specified position
 
 108     virtual bool InsertPage(size_t n,
 
 110                             const wxString& text,
 
 112                             int imageId = -1)/* = 0*/;
 
 114     // set the currently selected page, return the index of the previously
 
 115     // selected one (or -1 on error)
 
 117     // NB: this function will _not_ generate PAGE_CHANGING/ED events
 
 118     virtual int SetSelection(size_t n)/* = 0*/;
 
 121     // cycle thru the pages
 
 122     void AdvanceSelection(bool forward = true);
 
 124     static wxVisualAttributes
 
 125     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
 
 130 class wxBookCtrlBaseEvent : public wxNotifyEvent
 
 133     wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
 
 134                     int nSel = -1, int nOldSel = -1);
 
 136         // the currently selected page (-1 if none)
 
 137     int GetSelection() const;
 
 138     void SetSelection(int nSel);
 
 139         // the page that was selected before the change (-1 if none)
 
 140     int GetOldSelection() const;
 
 141     void SetOldSelection(int nOldSel);
 
 146 //---------------------------------------------------------------------------
 
 160     wxNB_HITTEST_NOWHERE = 1,   // not on tab
 
 161     wxNB_HITTEST_ONICON  = 2,   // on icon
 
 162     wxNB_HITTEST_ONLABEL = 4,   // on label
 
 163     wxNB_HITTEST_ONITEM  = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL,
 
 169 MustHaveApp(wxNotebook);
 
 171 class wxNotebook : public wxBookCtrlBase {
 
 173     %pythonAppend wxNotebook         "self._setOORInfo(self)"
 
 174     %pythonAppend wxNotebook()       ""
 
 175     %typemap(out) wxNotebook*;    // turn off this typemap
 
 177     wxNotebook(wxWindow *parent,
 
 179                const wxPoint& pos = wxDefaultPosition,
 
 180                const wxSize& size = wxDefaultSize,
 
 182                const wxString& name = wxPyNotebookNameStr);
 
 183     %RenameCtor(PreNotebook, wxNotebook());
 
 185     // Turn it back on again
 
 186     %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, $owner); }
 
 188     bool Create(wxWindow *parent,
 
 190                const wxPoint& pos = wxDefaultPosition,
 
 191                const wxSize& size = wxDefaultSize,
 
 193                const wxString& name = wxPyNotebookNameStr);
 
 196     // get the number of rows for a control with wxNB_MULTILINE style (not all
 
 197     // versions support it - they will always return 1 then)
 
 198     virtual int GetRowCount() const;
 
 200     // set the padding between tabs (in pixels)
 
 201     virtual void SetPadding(const wxSize& padding);
 
 203     // set the size of the tabs for wxNB_FIXEDWIDTH controls
 
 204     virtual void SetTabSize(const wxSize& sz);
 
 206     // hit test, returns which tab is hit and, optionally, where (icon, label)
 
 207     // (not implemented on all platforms)
 
 209         virtual int, HitTest(const wxPoint& pt, long* OUTPUT) const,
 
 210         "HitTest(Point pt) -> (tab, where)",
 
 211         "Returns the tab which is hit, and flags indicating where using
 
 212 wx.NB_HITTEST flags.", "");
 
 214     // implement some base class functions
 
 215     virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
 
 217     // On platforms that support it, get the theme page background colour,
 
 218     // else invalid colour
 
 219     wxColour GetThemeBackgroundColour() const;
 
 221     static wxVisualAttributes
 
 222     GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
 
 227 class wxNotebookEvent : public wxBookCtrlBaseEvent
 
 230     wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
 
 231                     int nSel = -1, int nOldSel = -1);
 
 235 // notebook control event types
 
 236 %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED;
 
 237 %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING;
 
 242     EVT_NOTEBOOK_PAGE_CHANGED  = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, 1 )
 
 243     EVT_NOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, 1 )
 
 248 %#----------------------------------------------------------------------------
 
 250 class NotebookPage(wx.Panel):
 
 252     There is an old (and apparently unsolvable) bug when placing a
 
 253     window with a nonstandard background colour in a wx.Notebook on
 
 254     wxGTK1, as the notbooks's background colour would always be used
 
 255     when the window is refreshed.  The solution is to place a panel in
 
 256     the notbook and the coloured window on the panel, sized to cover
 
 257     the panel.  This simple class does that for you, just put an
 
 258     instance of this in the notebook and make your regular window a
 
 259     child of this one and it will handle the resize for you.
 
 261     def __init__(self, parent, id=-1,
 
 262                  pos=wx.DefaultPosition, size=wx.DefaultSize,
 
 263                  style=wx.TAB_TRAVERSAL, name="panel"):
 
 264         wx.Panel.__init__(self, parent, id, pos, size, style, name)
 
 266         self.Bind(wx.EVT_SIZE, self.OnSize)
 
 268     def OnSize(self, evt):
 
 269         if self.child is None:
 
 270             children = self.GetChildren()
 
 272                 self.child = children[0]
 
 274             self.child.SetPosition((0,0))
 
 275             self.child.SetSize(self.GetSize())
 
 279 //---------------------------------------------------------------------------
 
 285     // default alignment: left everywhere except Mac where it is top
 
 288     // put the list control to the left/right/top/bottom of the page area
 
 294     // the mask which can be used to extract the alignment from the style
 
 295     wxLB_ALIGN_MASK = 0xf,
 
 300 MustHaveApp(wxListbook);
 
 302 //  wxListCtrl and wxNotebook combination
 
 303 class wxListbook : public wxBookCtrlBase
 
 306     %pythonAppend wxListbook         "self._setOORInfo(self)"
 
 307     %pythonAppend wxListbook()       ""
 
 309     wxListbook(wxWindow *parent,
 
 311                const wxPoint& pos = wxDefaultPosition,
 
 312                const wxSize& size = wxDefaultSize,
 
 314                const wxString& name = wxPyEmptyString);
 
 315     %RenameCtor(PreListbook, wxListbook());
 
 317     bool Create(wxWindow *parent,
 
 319                 const wxPoint& pos = wxDefaultPosition,
 
 320                 const wxSize& size = wxDefaultSize,
 
 322                 const wxString& name = wxPyEmptyString);
 
 324     // returns True if we have wxLB_TOP or wxLB_BOTTOM style
 
 325     bool IsVertical() const;
 
 327     wxListView* GetListView();
 
 332 class wxListbookEvent : public wxBookCtrlBaseEvent
 
 335     wxListbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
 
 336                     int nSel = -1, int nOldSel = -1);
 
 340 %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED;
 
 341 %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING;
 
 344     EVT_LISTBOOK_PAGE_CHANGED  = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, 1 )
 
 345     EVT_LISTBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, 1 )
 
 349 //---------------------------------------------------------------------------
 
 365 MustHaveApp(wxChoicebook);
 
 367 class wxChoicebook : public wxBookCtrlBase
 
 370     %pythonAppend wxChoicebook         "self._setOORInfo(self)"
 
 371     %pythonAppend wxChoicebook()       ""
 
 373     wxChoicebook(wxWindow *parent,
 
 375                  const wxPoint& pos = wxDefaultPosition,
 
 376                  const wxSize& size = wxDefaultSize,
 
 378                  const wxString& name = wxPyEmptyString);
 
 379     %RenameCtor(PreChoicebook, wxChoicebook());
 
 382     bool Create(wxWindow *parent,
 
 384                 const wxPoint& pos = wxDefaultPosition,
 
 385                 const wxSize& size = wxDefaultSize,
 
 387                 const wxString& name = wxPyEmptyString);
 
 390     // returns true if we have wxCHB_TOP or wxCHB_BOTTOM style
 
 391     bool IsVertical() const;
 
 393     // returns the choice control
 
 394     wxChoice* GetChoiceCtrl() const;
 
 396     virtual bool DeleteAllPages();
 
 400 class wxChoicebookEvent : public wxBookCtrlBaseEvent
 
 403     wxChoicebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
 
 404                       int nSel = -1, int nOldSel = -1);
 
 407 %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED;
 
 408 %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING;
 
 411     EVT_CHOICEBOOK_PAGE_CHANGED  = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, 1 )
 
 412     EVT_CHOICEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, 1 )
 
 415 //---------------------------------------------------------------------------
 
 418 // WXWIN_COMPATIBILITY_2_4
 
 420 class wxBookCtrlSizer: public wxSizer
 
 423     %pythonAppend wxBookCtrlSizer "self._setOORInfo(self)"
 
 425     wxBookCtrlSizer( wxBookCtrlBase *nb );
 
 429     wxBookCtrlBase *GetControl();
 
 433 class wxNotebookSizer: public wxSizer {
 
 435     %pythonAppend wxNotebookSizer "self._setOORInfo(self)"
 
 437     wxNotebookSizer( wxNotebook *nb );
 
 441     wxNotebook *GetNotebook();
 
 444 %pythoncode { NotebookSizer.__init__ = wx._deprecated(NotebookSizer.__init__, "NotebookSizer is no longer needed.") }
 
 445 %pythoncode { BookCtrlSizer.__init__ = wx._deprecated(BookCtrlSizer.__init__, "BookCtrlSizer is no longer needed.") }
 
 448 //---------------------------------------------------------------------------