]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_notebook.i
More properties
[wxWidgets.git] / wxPython / src / _notebook.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _notebook.i
3 // Purpose: SWIG interface defs for wxNotebook and such
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 2-June-1998
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17
18 MAKE_CONST_WXSTRING(NotebookNameStr);
19
20 //---------------------------------------------------------------------------
21 %newgroup
22
23
24 enum {
25 wxBK_DEFAULT,
26 wxBK_TOP,
27 wxBK_BOTTOM,
28 wxBK_LEFT,
29 wxBK_RIGHT,
30 wxBK_ALIGN_MASK,
31 wxBK_BUTTONBAR,
32
33 // hittest flags
34 wxBK_HITTEST_NOWHERE = 1, // not on tab
35 wxBK_HITTEST_ONICON = 2, // on icon
36 wxBK_HITTEST_ONLABEL = 4, // on label
37 wxBK_HITTEST_ONITEM = wxBK_HITTEST_ONICON | wxBK_HITTEST_ONLABEL,
38 wxBK_HITTEST_ONPAGE = 8, // not on tab control, but over the selected page
39 };
40
41
42 // TODO: Virtualize this class so other book controls can be derived in Python
43
44 MustHaveApp(wxBookCtrlBase);
45
46 // Common base class for wxList/Tree/Notebook
47 class wxBookCtrlBase : public wxControl
48 {
49 public:
50 // This is an ABC, it can't be constructed...
51
52 // wxBookCtrlBase(wxWindow *parent,
53 // wxWindowID id,
54 // const wxPoint& pos = wxDefaultPosition,
55 // const wxSize& size = wxDefaultSize,
56 // long style = 0,
57 // const wxString& name = wxPyEmptyString);
58 // %RenameCtor(PreBookCtrlBase, wxBookCtrlBase());
59 // bool Create(wxWindow *parent,
60 // wxWindowID id,
61 // const wxPoint& pos = wxDefaultPosition,
62 // const wxSize& size = wxDefaultSize,
63 // long style = 0,
64 // const wxString& name = wxPyEmptyString);
65
66
67 // get number of pages in the dialog
68 virtual size_t GetPageCount() const;
69
70 // get the panel which represents the given page
71 virtual wxWindow *GetPage(size_t n);
72
73 // get the current page or NULL if none
74 wxWindow* GetCurrentPage() const;
75
76 // get the currently selected page or wxNOT_FOUND if none
77 virtual int GetSelection() const/* = 0*/;
78
79 // set/get the title of a page
80 virtual bool SetPageText(size_t n, const wxString& strText)/* = 0*/;
81 virtual wxString GetPageText(size_t n) const/* = 0*/;
82
83
84 // image list stuff: each page may have an image associated with it (all
85 // images belong to the same image list)
86
87 // sets the image list to use, it is *not* deleted by the control
88 virtual void SetImageList(wxImageList *imageList);
89
90 // as SetImageList() but we will delete the image list ourselves
91 %disownarg( wxImageList *imageList );
92 void AssignImageList(wxImageList *imageList);
93 %cleardisown( wxImageList *imageList );
94
95 // get pointer (may be NULL) to the associated image list
96 wxImageList* GetImageList() const;
97
98 // sets/returns item's image index in the current image list
99 virtual int GetPageImage(size_t n) const/* = 0*/;
100 virtual bool SetPageImage(size_t n, int imageId)/* = 0*/;
101
102
103 // resize the notebook so that all pages will have the specified size
104 virtual void SetPageSize(const wxSize& size);
105
106 // calculate the size of the control from the size of its page
107 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const/* = 0*/;
108
109
110 // get/set size of area between book control area and page area
111 unsigned int GetInternalBorder() const;
112 void SetInternalBorder(unsigned int internalBorder);
113
114 // returns true if we have wxCHB_TOP or wxCHB_BOTTOM style
115 bool IsVertical() const;
116
117 // Sets/gets the margin around the controller
118 void SetControlMargin(int margin);
119 int GetControlMargin() const;
120
121 // set/get option to shrink to fit current page
122 void SetFitToCurrentPage(bool fit);
123 bool GetFitToCurrentPage() const;
124
125 // returns the sizer containing the control, if any
126 wxSizer* GetControlSizer() const;
127
128
129 // remove one page from the control and delete it
130 virtual bool DeletePage(size_t n);
131
132 // remove one page from the notebook, without deleting it
133 virtual bool RemovePage(size_t n);
134
135 // remove all pages and delete them
136 virtual bool DeleteAllPages();
137
138 // adds a new page to the control
139 virtual bool AddPage(wxWindow *page,
140 const wxString& text,
141 bool select = false,
142 int imageId = -1);
143
144 // the same as AddPage(), but adds the page at the specified position
145 virtual bool InsertPage(size_t n,
146 wxWindow *page,
147 const wxString& text,
148 bool select = false,
149 int imageId = -1)/* = 0*/;
150
151 // set the currently selected page, return the index of the previously
152 // selected one (or -1 on error)
153 //
154 // NB: this function will _not_ generate PAGE_CHANGING/ED events
155 virtual int SetSelection(size_t n)/* = 0*/;
156
157
158 // cycle thru the pages
159 void AdvanceSelection(bool forward = true);
160
161 DocDeclAStr(
162 virtual int, HitTest(const wxPoint& pt, long* OUTPUT) const,
163 "HitTest(Point pt) -> (tab, where)",
164 "Returns the page/tab which is hit, and flags indicating where using
165 wx.NB_HITTEST flags.", "");
166
167 static wxVisualAttributes
168 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
169
170 %property(ControlMargin, GetControlMargin, SetControlMargin, doc="See `GetControlMargin` and `SetControlMargin`");
171 %property(ControlSizer, GetControlSizer, doc="See `GetControlSizer`");
172 %property(CurrentPage, GetCurrentPage, doc="See `GetCurrentPage`");
173 %property(FitToCurrentPage, GetFitToCurrentPage, SetFitToCurrentPage, doc="See `GetFitToCurrentPage` and `SetFitToCurrentPage`");
174 %property(ImageList, GetImageList, SetImageList, doc="See `GetImageList` and `SetImageList`");
175 %property(InternalBorder, GetInternalBorder, SetInternalBorder, doc="See `GetInternalBorder` and `SetInternalBorder`");
176 %property(Page, GetPage, doc="See `GetPage`");
177 %property(PageCount, GetPageCount, doc="See `GetPageCount`");
178 %property(PageImage, GetPageImage, SetPageImage, doc="See `GetPageImage` and `SetPageImage`");
179 %property(PageText, GetPageText, SetPageText, doc="See `GetPageText` and `SetPageText`");
180 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
181
182 };
183
184
185
186 class wxBookCtrlBaseEvent : public wxNotifyEvent
187 {
188 public:
189 wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
190 int nSel = -1, int nOldSel = -1);
191
192 // the currently selected page (-1 if none)
193 int GetSelection() const;
194 void SetSelection(int nSel);
195 // the page that was selected before the change (-1 if none)
196 int GetOldSelection() const;
197 void SetOldSelection(int nOldSel);
198
199 %property(OldSelection, GetOldSelection, SetOldSelection, doc="See `GetOldSelection` and `SetOldSelection`");
200 %property(Selection, GetSelection, SetSelection, doc="See `GetSelection` and `SetSelection`");
201
202 };
203
204
205
206 //---------------------------------------------------------------------------
207 %newgroup
208
209 enum {
210 // styles
211 wxNB_FIXEDWIDTH,
212 wxNB_TOP,
213 wxNB_LEFT,
214 wxNB_RIGHT,
215 wxNB_BOTTOM,
216 wxNB_MULTILINE,
217 wxNB_NOPAGETHEME,
218
219 // for backwards compatibility only
220 wxNB_HITTEST_NOWHERE,
221 wxNB_HITTEST_ONICON,
222 wxNB_HITTEST_ONLABEL,
223 wxNB_HITTEST_ONITEM,
224 wxNB_HITTEST_ONPAGE,
225 };
226
227
228
229 MustHaveApp(wxNotebook);
230
231 class wxNotebook : public wxBookCtrlBase {
232 public:
233 %pythonAppend wxNotebook "self._setOORInfo(self)"
234 %pythonAppend wxNotebook() ""
235 %typemap(out) wxNotebook*; // turn off this typemap
236
237 wxNotebook(wxWindow *parent,
238 wxWindowID id=-1,
239 const wxPoint& pos = wxDefaultPosition,
240 const wxSize& size = wxDefaultSize,
241 long style = 0,
242 const wxString& name = wxPyNotebookNameStr);
243 %RenameCtor(PreNotebook, wxNotebook());
244
245 // Turn it back on again
246 %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, $owner); }
247
248 bool Create(wxWindow *parent,
249 wxWindowID id=-1,
250 const wxPoint& pos = wxDefaultPosition,
251 const wxSize& size = wxDefaultSize,
252 long style = 0,
253 const wxString& name = wxPyNotebookNameStr);
254
255
256 // get the number of rows for a control with wxNB_MULTILINE style (not all
257 // versions support it - they will always return 1 then)
258 virtual int GetRowCount() const;
259
260 // set the padding between tabs (in pixels)
261 virtual void SetPadding(const wxSize& padding);
262
263 // set the size of the tabs for wxNB_FIXEDWIDTH controls
264 virtual void SetTabSize(const wxSize& sz);
265
266 // implement some base class functions
267 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
268
269 // On platforms that support it, get the theme page background colour,
270 // else invalid colour
271 wxColour GetThemeBackgroundColour() const;
272
273 static wxVisualAttributes
274 GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
275 };
276
277
278
279 class wxNotebookEvent : public wxBookCtrlBaseEvent
280 {
281 public:
282 wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
283 int nSel = -1, int nOldSel = -1);
284
285 };
286
287 // notebook control event types
288 %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED;
289 %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING;
290
291
292 %pythoncode {
293 %# wxNotebook events
294 EVT_NOTEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, 1 )
295 EVT_NOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, 1 )
296 }
297
298
299 %pythoncode {
300 %#----------------------------------------------------------------------------
301
302 class NotebookPage(wx.Panel):
303 """
304 There is an old (and apparently unsolvable) bug when placing a
305 window with a nonstandard background colour in a wx.Notebook on
306 wxGTK1, as the notbooks's background colour would always be used
307 when the window is refreshed. The solution is to place a panel in
308 the notbook and the coloured window on the panel, sized to cover
309 the panel. This simple class does that for you, just put an
310 instance of this in the notebook and make your regular window a
311 child of this one and it will handle the resize for you.
312 """
313 def __init__(self, parent, id=-1,
314 pos=wx.DefaultPosition, size=wx.DefaultSize,
315 style=wx.TAB_TRAVERSAL, name="panel"):
316 wx.Panel.__init__(self, parent, id, pos, size, style, name)
317 self.child = None
318 self.Bind(wx.EVT_SIZE, self.OnSize)
319
320 def OnSize(self, evt):
321 if self.child is None:
322 children = self.GetChildren()
323 if len(children):
324 self.child = children[0]
325 if self.child:
326 self.child.SetPosition((0,0))
327 self.child.SetSize(self.GetSize())
328
329 }
330
331 //---------------------------------------------------------------------------
332 %newgroup
333
334
335 enum
336 {
337 // default alignment: left everywhere except Mac where it is top
338 wxLB_DEFAULT = 0,
339
340 // put the list control to the left/right/top/bottom of the page area
341 wxLB_TOP = 0x1,
342 wxLB_BOTTOM = 0x2,
343 wxLB_LEFT = 0x4,
344 wxLB_RIGHT = 0x8,
345
346 // the mask which can be used to extract the alignment from the style
347 wxLB_ALIGN_MASK = 0xf,
348 };
349
350
351
352 MustHaveApp(wxListbook);
353
354 // wxListCtrl and wxNotebook combination
355 class wxListbook : public wxBookCtrlBase
356 {
357 public:
358 %pythonAppend wxListbook "self._setOORInfo(self)"
359 %pythonAppend wxListbook() ""
360
361 wxListbook(wxWindow *parent,
362 wxWindowID id=-1,
363 const wxPoint& pos = wxDefaultPosition,
364 const wxSize& size = wxDefaultSize,
365 long style = 0,
366 const wxString& name = wxPyEmptyString);
367 %RenameCtor(PreListbook, wxListbook());
368
369 bool Create(wxWindow *parent,
370 wxWindowID id=-1,
371 const wxPoint& pos = wxDefaultPosition,
372 const wxSize& size = wxDefaultSize,
373 long style = 0,
374 const wxString& name = wxPyEmptyString);
375
376 wxListView* GetListView();
377 %property(ListView, GetListView, doc="See `GetListView`");
378 };
379
380
381
382 class wxListbookEvent : public wxBookCtrlBaseEvent
383 {
384 public:
385 wxListbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
386 int nSel = -1, int nOldSel = -1);
387 };
388
389
390 %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED;
391 %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING;
392
393 %pythoncode {
394 EVT_LISTBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, 1 )
395 EVT_LISTBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, 1 )
396 }
397
398
399 //---------------------------------------------------------------------------
400
401
402 /*
403 * wxChoicebook flags
404 */
405 enum {
406 wxCHB_DEFAULT,
407 wxCHB_TOP,
408 wxCHB_BOTTOM,
409 wxCHB_LEFT,
410 wxCHB_RIGHT,
411 wxCHB_ALIGN_MASK
412 };
413
414
415 MustHaveApp(wxChoicebook);
416
417 class wxChoicebook : public wxBookCtrlBase
418 {
419 public:
420 %pythonAppend wxChoicebook "self._setOORInfo(self)"
421 %pythonAppend wxChoicebook() ""
422
423 wxChoicebook(wxWindow *parent,
424 wxWindowID id,
425 const wxPoint& pos = wxDefaultPosition,
426 const wxSize& size = wxDefaultSize,
427 long style = 0,
428 const wxString& name = wxPyEmptyString);
429 %RenameCtor(PreChoicebook, wxChoicebook());
430
431 // quasi ctor
432 bool Create(wxWindow *parent,
433 wxWindowID id,
434 const wxPoint& pos = wxDefaultPosition,
435 const wxSize& size = wxDefaultSize,
436 long style = 0,
437 const wxString& name = wxPyEmptyString);
438
439
440 // returns the choice control
441 wxChoice* GetChoiceCtrl() const;
442
443 virtual bool DeleteAllPages();
444
445 %property(ChoiceCtrl, GetChoiceCtrl, doc="See `GetChoiceCtrl`");
446
447 };
448
449
450 class wxChoicebookEvent : public wxBookCtrlBaseEvent
451 {
452 public:
453 wxChoicebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
454 int nSel = -1, int nOldSel = -1);
455 };
456
457 %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED;
458 %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING;
459
460 %pythoncode {
461 EVT_CHOICEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, 1 )
462 EVT_CHOICEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, 1 )
463 }
464
465 //---------------------------------------------------------------------------
466 %newgroup;
467
468 MustHaveApp(wxTreebook);
469
470 class wxTreebook : public wxBookCtrlBase
471 {
472 public:
473 %pythonAppend wxTreebook "self._setOORInfo(self)"
474 %pythonAppend wxTreebook() ""
475
476
477 // This ctor creates the tree book control
478 wxTreebook(wxWindow *parent,
479 wxWindowID id,
480 const wxPoint& pos = wxDefaultPosition,
481 const wxSize& size = wxDefaultSize,
482 long style = wxBK_DEFAULT,
483 const wxString& name = wxPyEmptyString);
484
485 %RenameCtor(PreTreebook, wxTreebook());
486
487
488 // Really creates the control
489 bool Create(wxWindow *parent,
490 wxWindowID id,
491 const wxPoint& pos = wxDefaultPosition,
492 const wxSize& size = wxDefaultSize,
493 long style = wxBK_DEFAULT,
494 const wxString& name = wxPyEmptyString);
495
496
497 // Notice that page pointer may be NULL in which case the next non NULL
498 // page (usually the first child page of a node) is shown when this page is
499 // selected
500
501 // Inserts a new page just before the page indicated by page.
502 // The new page is placed on the same level as page.
503 virtual bool InsertPage(size_t pos,
504 wxWindow *page,
505 const wxString& text,
506 bool select = false,
507 int imageId = wxNOT_FOUND);
508
509 // Inserts a new sub-page to the end of children of the page at given pos.
510 virtual bool InsertSubPage(size_t pos,
511 wxWindow *page,
512 const wxString& text,
513 bool select = false,
514 int imageId = wxNOT_FOUND);
515
516 // Adds a new page at top level after all other pages.
517 virtual bool AddPage(wxWindow *page,
518 const wxString& text,
519 bool select = false,
520 int imageId = wxNOT_FOUND);
521
522 // Adds a new child-page to the last top-level page inserted.
523 // Useful when constructing 1 level tree structure.
524 virtual bool AddSubPage(wxWindow *page,
525 const wxString& text,
526 bool select = false,
527 int imageId = wxNOT_FOUND);
528
529 // Deletes the page and ALL its children. Could trigger page selection
530 // change in a case when selected page is removed. In that case its parent
531 // is selected (or the next page if no parent).
532 virtual bool DeletePage(size_t pos);
533
534
535 // Tree operations
536 // ---------------
537
538 // Gets the page node state -- node is expanded or collapsed
539 virtual bool IsNodeExpanded(size_t pos) const;
540
541 // Expands or collapses the page node. Returns the previous state.
542 // May generate page changing events (if selected page
543 // is under the collapsed branch, then parent is autoselected).
544 virtual bool ExpandNode(size_t pos, bool expand = true);
545
546 // shortcut for ExpandNode(pos, false)
547 bool CollapseNode(size_t pos);
548
549 // get the parent page or wxNOT_FOUND if this is a top level page
550 int GetPageParent(size_t pos) const;
551
552 // the tree control we use for showing the pages index tree
553 wxPyTreeCtrl* GetTreeCtrl() const;
554
555 };
556
557
558 class wxTreebookEvent : public wxBookCtrlBaseEvent
559 {
560 public:
561 wxTreebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
562 int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND);
563 };
564
565 %constant wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED;
566 %constant wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING;
567 %constant wxEventType wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED;
568 %constant wxEventType wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED;
569
570
571 %pythoncode {
572 EVT_TREEBOOK_PAGE_CHANGED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, 1 )
573 EVT_TREEBOOK_PAGE_CHANGING= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, 1)
574 EVT_TREEBOOK_NODE_COLLAPSED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED, 1 )
575 EVT_TREEBOOK_NODE_EXPANDED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED, 1 )
576 }
577
578 //---------------------------------------------------------------------------
579 %newgroup;
580
581 MustHaveApp(wxTreebook);
582
583 class wxToolbook : public wxBookCtrlBase
584 {
585 public:
586 %pythonAppend wxToolbook "self._setOORInfo(self)"
587 %pythonAppend wxToolbook() ""
588
589
590 // This ctor creates the tree book control
591 wxToolbook(wxWindow *parent,
592 wxWindowID id,
593 const wxPoint& pos = wxDefaultPosition,
594 const wxSize& size = wxDefaultSize,
595 long style = wxBK_DEFAULT,
596 const wxString& name = wxPyEmptyString);
597
598 %RenameCtor(PreToolbook, wxToolbook());
599
600 // quasi ctor
601 bool Create(wxWindow *parent,
602 wxWindowID id,
603 const wxPoint& pos = wxDefaultPosition,
604 const wxSize& size = wxDefaultSize,
605 long style = 0,
606 const wxString& name = wxEmptyString);
607
608
609 wxToolBarBase* GetToolBar() const;
610
611 // Not part of the wxBookctrl API, but must be called in OnIdle or
612 // by application to realize the toolbar and select the initial page.
613 void Realize();
614 };
615
616
617 class wxToolbookEvent : public wxBookCtrlBaseEvent
618 {
619 public:
620 wxToolbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
621 int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND);
622 };
623
624
625 %constant wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED;
626 %constant wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING;
627
628
629 %pythoncode {
630 EVT_TOOLBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED, 1)
631 EVT_TOOLBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING, 1)
632 }
633
634 //---------------------------------------------------------------------------