]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_notebook.i
Add wx.Dialog.Get/SetAffirmativeId and Get/SetEscapeId
[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 SetFitToCurrentPage(bool fit);
111 bool GetFitToCurrentPage() 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 virtual bool InsertSubPage(size_t pos,
477 wxWindow *page,
478 const wxString& text,
479 bool select = false,
480 int imageId = wxNOT_FOUND);
481
482 // Adds a new page at top level after all other pages.
483 virtual bool AddPage(wxWindow *page,
484 const wxString& text,
485 bool select = false,
486 int imageId = wxNOT_FOUND);
487
488 // Adds a new child-page to the last top-level page inserted.
489 // Useful when constructing 1 level tree structure.
490 virtual bool AddSubPage(wxWindow *page,
491 const wxString& text,
492 bool select = false,
493 int imageId = wxNOT_FOUND);
494
495 // Deletes the page and ALL its children. Could trigger page selection
496 // change in a case when selected page is removed. In that case its parent
497 // is selected (or the next page if no parent).
498 virtual bool DeletePage(size_t pos);
499
500
501 // Tree operations
502 // ---------------
503
504 // Gets the page node state -- node is expanded or collapsed
505 virtual bool IsNodeExpanded(size_t pos) const;
506
507 // Expands or collapses the page node. Returns the previous state.
508 // May generate page changing events (if selected page
509 // is under the collapsed branch, then parent is autoselected).
510 virtual bool ExpandNode(size_t pos, bool expand = true);
511
512 // shortcut for ExpandNode(pos, false)
513 bool CollapseNode(size_t pos);
514
515 // get the parent page or wxNOT_FOUND if this is a top level page
516 int GetPageParent(size_t pos) const;
517
518 // the tree control we use for showing the pages index tree
519 wxTreeCtrl* GetTreeCtrl() const;
520
521 };
522
523
524 class wxTreebookEvent : public wxBookCtrlBaseEvent
525 {
526 public:
527 wxTreebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
528 int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND);
529 };
530
531 %constant wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED;
532 %constant wxEventType wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING;
533 %constant wxEventType wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED;
534 %constant wxEventType wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED;
535
536
537 %pythoncode {
538 EVT_TREEBOOK_PAGE_CHANGED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED, 1 )
539 EVT_TREEBOOK_PAGE_CHANGING= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_PAGE_CHANGING, 1)
540 EVT_TREEBOOK_NODE_COLLAPSED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_NODE_COLLAPSED, 1 )
541 EVT_TREEBOOK_NODE_EXPANDED= wx.PyEventBinder( wxEVT_COMMAND_TREEBOOK_NODE_EXPANDED, 1 )
542 }
543
544 //---------------------------------------------------------------------------
545 %newgroup;
546
547 MustHaveApp(wxTreebook);
548
549 class wxToolbook : public wxBookCtrlBase
550 {
551 public:
552 %pythonAppend wxToolbook "self._setOORInfo(self)"
553 %pythonAppend wxToolbook() ""
554
555
556 // This ctor creates the tree book control
557 wxToolbook(wxWindow *parent,
558 wxWindowID id,
559 const wxPoint& pos = wxDefaultPosition,
560 const wxSize& size = wxDefaultSize,
561 long style = wxBK_DEFAULT,
562 const wxString& name = wxPyEmptyString);
563
564 %RenameCtor(PreToolbook, wxToolbook());
565
566 // quasi ctor
567 bool Create(wxWindow *parent,
568 wxWindowID id,
569 const wxPoint& pos = wxDefaultPosition,
570 const wxSize& size = wxDefaultSize,
571 long style = 0,
572 const wxString& name = wxEmptyString);
573
574
575 wxToolBarBase* GetToolBar() const;
576
577 // Not part of the wxBookctrl API, but must be called in OnIdle or
578 // by application to realize the toolbar and select the initial page.
579 void Realize();
580 };
581
582
583 class wxToolbookEvent : public wxBookCtrlBaseEvent
584 {
585 public:
586 wxToolbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
587 int nSel = wxNOT_FOUND, int nOldSel = wxNOT_FOUND);
588 };
589
590
591 %constant wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED;
592 %constant wxEventType wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING;
593
594
595 %pythoncode {
596 EVT_TOOLBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGED, 1)
597 EVT_TOOLBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_TOOLBOOK_PAGE_CHANGING, 1)
598 }
599
600 //---------------------------------------------------------------------------