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