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 //---------------------------------------------------------------------------
35 // TODO: Virtualize this class so other book controls can be derived in Python
37 MustHaveApp(wxBookCtrlBase);
39 // Common base class for wxList/Tree/Notebook
40 class wxBookCtrlBase : public wxControl
43 // This is an ABC, it can't be constructed...
45 // wxBookCtrlBase(wxWindow *parent,
47 // const wxPoint& pos = wxDefaultPosition,
48 // const wxSize& size = wxDefaultSize,
50 // const wxString& name = wxPyEmptyString);
51 // %RenameCtor(PreBookCtrlBase, wxBookCtrlBase());
52 // bool Create(wxWindow *parent,
54 // const wxPoint& pos = wxDefaultPosition,
55 // const wxSize& size = wxDefaultSize,
57 // const wxString& name = wxPyEmptyString);
60 // get number of pages in the dialog
61 virtual size_t GetPageCount() const;
63 // get the panel which represents the given page
64 virtual wxWindow *GetPage(size_t n);
66 // get the current page or NULL if none
67 wxWindow* GetCurrentPage() const;
69 // get the currently selected page or wxNOT_FOUND if none
70 virtual int GetSelection() const/* = 0*/;
72 // set/get the title of a page
73 virtual bool SetPageText(size_t n, const wxString& strText)/* = 0*/;
74 virtual wxString GetPageText(size_t n) const/* = 0*/;
77 // image list stuff: each page may have an image associated with it (all
78 // images belong to the same image list)
80 // sets the image list to use, it is *not* deleted by the control
81 virtual void SetImageList(wxImageList *imageList);
83 // as SetImageList() but we will delete the image list ourselves
84 %disownarg( wxImageList *imageList );
85 void AssignImageList(wxImageList *imageList);
86 %cleardisown( wxImageList *imageList );
88 // get pointer (may be NULL) to the associated image list
89 wxImageList* GetImageList() const;
91 // sets/returns item's image index in the current image list
92 virtual int GetPageImage(size_t n) const/* = 0*/;
93 virtual bool SetPageImage(size_t n, int imageId)/* = 0*/;
96 // resize the notebook so that all pages will have the specified size
97 virtual void SetPageSize(const wxSize& size);
99 // calculate the size of the control from the size of its page
100 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const/* = 0*/;
103 // get/set size of area between book control area and page area
104 unsigned int GetInternalBorder() const;
105 void SetInternalBorder(unsigned int internalBorder);
107 // returns true if we have wxCHB_TOP or wxCHB_BOTTOM style
108 bool IsVertical() const;
110 // Sets/gets the margin around the controller
111 void SetControlMargin(int margin);
112 int GetControlMargin() const;
114 // set/get option to shrink to fit current page
115 void SetFitToCurrentPage(bool fit);
116 bool GetFitToCurrentPage() const;
118 // returns the sizer containing the control, if any
119 wxSizer* GetControlSizer() const;
122 // remove one page from the control and delete it
123 virtual bool DeletePage(size_t n);
125 // remove one page from the notebook, without deleting it
126 virtual bool RemovePage(size_t n);
128 // remove all pages and delete them
129 virtual bool DeleteAllPages();
131 // adds a new page to the control
132 virtual bool AddPage(wxWindow *page,
133 const wxString& text,
137 // the same as AddPage(), but adds the page at the specified position
138 virtual bool InsertPage(size_t n,
140 const wxString& text,
142 int imageId = -1)/* = 0*/;
144 // set the currently selected page, return the index of the previously
145 // selected one (or -1 on error)
147 // NB: this function will _not_ generate PAGE_CHANGING/ED events
148 virtual int SetSelection(size_t n)/* = 0*/;
151 // cycle thru the pages
152 void AdvanceSelection(bool forward = true);
155 virtual int, HitTest(const wxPoint& pt, long* OUTPUT) const,
156 "HitTest(Point pt) -> (tab, where)",
157 "Returns the page/tab which is hit, and flags indicating where using
158 wx.NB_HITTEST flags.", "");
160 static wxVisualAttributes
161 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
166 class wxBookCtrlBaseEvent : public wxNotifyEvent
169 wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
170 int nSel = -1, int nOldSel = -1);
172 // the currently selected page (-1 if none)
173 int GetSelection() const;
174 void SetSelection(int nSel);
175 // the page that was selected before the change (-1 if none)
176 int GetOldSelection() const;
177 void SetOldSelection(int nOldSel);
182 //---------------------------------------------------------------------------
196 wxNB_HITTEST_NOWHERE = 1, // not on tab
197 wxNB_HITTEST_ONICON = 2, // on icon
198 wxNB_HITTEST_ONLABEL = 4, // on label
199 wxNB_HITTEST_ONITEM = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL,
200 wxNB_HITTEST_ONPAGE = 8
205 MustHaveApp(wxNotebook);
207 class wxNotebook : public wxBookCtrlBase {
209 %pythonAppend wxNotebook "self._setOORInfo(self)"
210 %pythonAppend wxNotebook() ""
211 %typemap(out) wxNotebook*; // turn off this typemap
213 wxNotebook(wxWindow *parent,
215 const wxPoint& pos = wxDefaultPosition,
216 const wxSize& size = wxDefaultSize,
218 const wxString& name = wxPyNotebookNameStr);
219 %RenameCtor(PreNotebook, wxNotebook());
221 // Turn it back on again
222 %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, $owner); }
224 bool Create(wxWindow *parent,
226 const wxPoint& pos = wxDefaultPosition,
227 const wxSize& size = wxDefaultSize,
229 const wxString& name = wxPyNotebookNameStr);
232 // get the number of rows for a control with wxNB_MULTILINE style (not all
233 // versions support it - they will always return 1 then)
234 virtual int GetRowCount() const;
236 // set the padding between tabs (in pixels)
237 virtual void SetPadding(const wxSize& padding);
239 // set the size of the tabs for wxNB_FIXEDWIDTH controls
240 virtual void SetTabSize(const wxSize& sz);
242 // implement some base class functions
243 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
245 // On platforms that support it, get the theme page background colour,
246 // else invalid colour
247 wxColour GetThemeBackgroundColour() const;
249 static wxVisualAttributes
250 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
255 class wxNotebookEvent : public wxBookCtrlBaseEvent
258 wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
259 int nSel = -1, int nOldSel = -1);
263 // notebook control event types
264 %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED;
265 %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING;
270 EVT_NOTEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, 1 )
271 EVT_NOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, 1 )
276 %#----------------------------------------------------------------------------
278 class NotebookPage(wx.Panel):
280 There is an old (and apparently unsolvable) bug when placing a
281 window with a nonstandard background colour in a wx.Notebook on
282 wxGTK1, as the notbooks's background colour would always be used
283 when the window is refreshed. The solution is to place a panel in
284 the notbook and the coloured window on the panel, sized to cover
285 the panel. This simple class does that for you, just put an
286 instance of this in the notebook and make your regular window a
287 child of this one and it will handle the resize for you.
289 def __init__(self, parent, id=-1,
290 pos=wx.DefaultPosition, size=wx.DefaultSize,
291 style=wx.TAB_TRAVERSAL, name="panel"):
292 wx.Panel.__init__(self, parent, id, pos, size, style, name)
294 self.Bind(wx.EVT_SIZE, self.OnSize)
296 def OnSize(self, evt):
297 if self.child is None:
298 children = self.GetChildren()
300 self.child = children[0]
302 self.child.SetPosition((0,0))
303 self.child.SetSize(self.GetSize())
307 //---------------------------------------------------------------------------
313 // default alignment: left everywhere except Mac where it is top
316 // put the list control to the left/right/top/bottom of the page area
322 // the mask which can be used to extract the alignment from the style
323 wxLB_ALIGN_MASK = 0xf,
328 MustHaveApp(wxListbook);
330 // wxListCtrl and wxNotebook combination
331 class wxListbook : public wxBookCtrlBase
334 %pythonAppend wxListbook "self._setOORInfo(self)"
335 %pythonAppend wxListbook() ""
337 wxListbook(wxWindow *parent,
339 const wxPoint& pos = wxDefaultPosition,
340 const wxSize& size = wxDefaultSize,
342 const wxString& name = wxPyEmptyString);
343 %RenameCtor(PreListbook, wxListbook());
345 bool Create(wxWindow *parent,
347 const wxPoint& pos = wxDefaultPosition,
348 const wxSize& size = wxDefaultSize,
350 const wxString& name = wxPyEmptyString);
352 wxListView* GetListView();
357 class wxListbookEvent : public wxBookCtrlBaseEvent
360 wxListbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
361 int nSel = -1, int nOldSel = -1);
365 %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED;
366 %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING;
369 EVT_LISTBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, 1 )
370 EVT_LISTBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, 1 )
374 //---------------------------------------------------------------------------
390 MustHaveApp(wxChoicebook);
392 class wxChoicebook : public wxBookCtrlBase
395 %pythonAppend wxChoicebook "self._setOORInfo(self)"
396 %pythonAppend wxChoicebook() ""
398 wxChoicebook(wxWindow *parent,
400 const wxPoint& pos = wxDefaultPosition,
401 const wxSize& size = wxDefaultSize,
403 const wxString& name = wxPyEmptyString);
404 %RenameCtor(PreChoicebook, wxChoicebook());
407 bool Create(wxWindow *parent,
409 const wxPoint& pos = wxDefaultPosition,
410 const wxSize& size = wxDefaultSize,
412 const wxString& name = wxPyEmptyString);
415 // returns the choice control
416 wxChoice* GetChoiceCtrl() const;
418 virtual bool DeleteAllPages();
422 class wxChoicebookEvent : public wxBookCtrlBaseEvent
425 wxChoicebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
426 int nSel = -1, int nOldSel = -1);
429 %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED;
430 %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING;
433 EVT_CHOICEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, 1 )
434 EVT_CHOICEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, 1 )
437 //---------------------------------------------------------------------------
440 MustHaveApp(wxTreebook);
442 class wxTreebook : public wxBookCtrlBase
445 %pythonAppend wxTreebook "self._setOORInfo(self)"
446 %pythonAppend wxTreebook() ""
449 // This ctor creates the tree book control
450 wxTreebook(wxWindow *parent,
452 const wxPoint& pos = wxDefaultPosition,
453 const wxSize& size = wxDefaultSize,
454 long style = wxBK_DEFAULT,
455 const wxString& name = wxPyEmptyString);
457 %RenameCtor(PreTreebook, wxTreebook());
460 // Really creates the control
461 bool Create(wxWindow *parent,
463 const wxPoint& pos = wxDefaultPosition,
464 const wxSize& size = wxDefaultSize,
465 long style = wxBK_DEFAULT,
466 const wxString& name = wxPyEmptyString);
469 // Notice that page pointer may be NULL in which case the next non NULL
470 // page (usually the first child page of a node) is shown when this page is
473 // Inserts a new page just before the page indicated by page.
474 // The new page is placed on the same level as page.
475 virtual bool InsertPage(size_t pos,
477 const wxString& text,
479 int imageId = wxNOT_FOUND);
481 // Inserts a new sub-page to the end of children of the page at given pos.
482 virtual bool InsertSubPage(size_t pos,
484 const wxString& text,
486 int imageId = wxNOT_FOUND);
488 // Adds a new page at top level after all other pages.
489 virtual bool AddPage(wxWindow *page,
490 const wxString& text,
492 int imageId = wxNOT_FOUND);
494 // Adds a new child-page to the last top-level page inserted.
495 // Useful when constructing 1 level tree structure.
496 virtual bool AddSubPage(wxWindow *page,
497 const wxString& text,
499 int imageId = wxNOT_FOUND);
501 // Deletes the page and ALL its children. Could trigger page selection
502 // change in a case when selected page is removed. In that case its parent
503 // is selected (or the next page if no parent).
504 virtual bool DeletePage(size_t pos);
510 // Gets the page node state -- node is expanded or collapsed
511 virtual bool IsNodeExpanded(size_t pos) const;
513 // Expands or collapses the page node. Returns the previous state.
514 // May generate page changing events (if selected page
515 // is under the collapsed branch, then parent is autoselected).
516 virtual bool ExpandNode(size_t pos, bool expand = true);
518 // shortcut for ExpandNode(pos, false)
519 bool CollapseNode(size_t pos);
521 // get the parent page or wxNOT_FOUND if this is a top level page
522 int GetPageParent(size_t pos) const;
524 // the tree control we use for showing the pages index tree
525 wxTreeCtrl* GetTreeCtrl() const;
530 class wxTreebookEvent : public wxBookCtrlBaseEvent
533 wxTreebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
534 int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND);
537 %constant wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED;
538 %constant wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING;
539 %constant wxEventType wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED;
540 %constant wxEventType wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED;
544 EVT_TREEBOOK_PAGE_CHANGED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, 1 )
545 EVT_TREEBOOK_PAGE_CHANGING= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, 1)
546 EVT_TREEBOOK_NODE_COLLAPSED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED, 1 )
547 EVT_TREEBOOK_NODE_EXPANDED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED, 1 )
550 //---------------------------------------------------------------------------
553 MustHaveApp(wxTreebook);
555 class wxToolbook : public wxBookCtrlBase
558 %pythonAppend wxToolbook "self._setOORInfo(self)"
559 %pythonAppend wxToolbook() ""
562 // This ctor creates the tree book control
563 wxToolbook(wxWindow *parent,
565 const wxPoint& pos = wxDefaultPosition,
566 const wxSize& size = wxDefaultSize,
567 long style = wxBK_DEFAULT,
568 const wxString& name = wxPyEmptyString);
570 %RenameCtor(PreToolbook, wxToolbook());
573 bool Create(wxWindow *parent,
575 const wxPoint& pos = wxDefaultPosition,
576 const wxSize& size = wxDefaultSize,
578 const wxString& name = wxEmptyString);
581 wxToolBarBase* GetToolBar() const;
583 // Not part of the wxBookctrl API, but must be called in OnIdle or
584 // by application to realize the toolbar and select the initial page.
589 class wxToolbookEvent : public wxBookCtrlBaseEvent
592 wxToolbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
593 int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND);
597 %constant wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED;
598 %constant wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING;
602 EVT_TOOLBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED, 1)
603 EVT_TOOLBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING, 1)
606 //---------------------------------------------------------------------------