]>
Commit | Line | Data |
---|---|---|
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 | // TODO: Virtualize this class so other book controls can be derived in Python | |
24 | ||
25 | MustHaveApp(wxBookCtrlBase); | |
26 | ||
27 | // Common base class for wxList/Tree/Notebook | |
28 | class wxBookCtrlBase : public wxControl | |
29 | { | |
30 | public: | |
31 | // This is an ABC, it can't be constructed... | |
32 | ||
33 | // wxBookCtrlBase(wxWindow *parent, | |
34 | // wxWindowID id, | |
35 | // const wxPoint& pos = wxDefaultPosition, | |
36 | // const wxSize& size = wxDefaultSize, | |
37 | // long style = 0, | |
38 | // const wxString& name = wxPyEmptyString); | |
39 | // %RenameCtor(PreBookCtrlBase, wxBookCtrlBase()); | |
40 | // bool Create(wxWindow *parent, | |
41 | // wxWindowID id, | |
42 | // const wxPoint& pos = wxDefaultPosition, | |
43 | // const wxSize& size = wxDefaultSize, | |
44 | // long style = 0, | |
45 | // const wxString& name = wxPyEmptyString); | |
46 | ||
47 | ||
48 | // get number of pages in the dialog | |
49 | virtual size_t GetPageCount() const; | |
50 | ||
51 | // get the panel which represents the given page | |
52 | virtual wxWindow *GetPage(size_t n); | |
53 | ||
54 | // get the current page or NULL if none | |
55 | wxWindow* GetCurrentPage() const; | |
56 | ||
57 | // get the currently selected page or wxNOT_FOUND if none | |
58 | virtual int GetSelection() const/* = 0*/; | |
59 | ||
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*/; | |
63 | ||
64 | ||
65 | // image list stuff: each page may have an image associated with it (all | |
66 | // images belong to the same image list) | |
67 | ||
68 | // sets the image list to use, it is *not* deleted by the control | |
69 | virtual void SetImageList(wxImageList *imageList); | |
70 | ||
71 | // as SetImageList() but we will delete the image list ourselves | |
72 | %apply SWIGTYPE *DISOWN { wxImageList *imageList }; | |
73 | void AssignImageList(wxImageList *imageList); | |
74 | %clear wxImageList *imageList; | |
75 | ||
76 | // get pointer (may be NULL) to the associated image list | |
77 | wxImageList* GetImageList() const; | |
78 | ||
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*/; | |
82 | ||
83 | ||
84 | // resize the notebook so that all pages will have the specified size | |
85 | virtual void SetPageSize(const wxSize& size); | |
86 | ||
87 | // calculate the size of the control from the size of its page | |
88 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const/* = 0*/; | |
89 | ||
90 | ||
91 | ||
92 | // remove one page from the control and delete it | |
93 | virtual bool DeletePage(size_t n); | |
94 | ||
95 | // remove one page from the notebook, without deleting it | |
96 | virtual bool RemovePage(size_t n); | |
97 | ||
98 | // remove all pages and delete them | |
99 | virtual bool DeleteAllPages(); | |
100 | ||
101 | // adds a new page to the control | |
102 | virtual bool AddPage(wxWindow *page, | |
103 | const wxString& text, | |
104 | bool select = false, | |
105 | int imageId = -1); | |
106 | ||
107 | // the same as AddPage(), but adds the page at the specified position | |
108 | virtual bool InsertPage(size_t n, | |
109 | wxWindow *page, | |
110 | const wxString& text, | |
111 | bool select = false, | |
112 | int imageId = -1)/* = 0*/; | |
113 | ||
114 | // set the currently selected page, return the index of the previously | |
115 | // selected one (or -1 on error) | |
116 | // | |
117 | // NB: this function will _not_ generate PAGE_CHANGING/ED events | |
118 | virtual int SetSelection(size_t n)/* = 0*/; | |
119 | ||
120 | ||
121 | // cycle thru the pages | |
122 | void AdvanceSelection(bool forward = true); | |
123 | ||
124 | static wxVisualAttributes | |
125 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
126 | }; | |
127 | ||
128 | ||
129 | ||
130 | class wxBookCtrlBaseEvent : public wxNotifyEvent | |
131 | { | |
132 | public: | |
133 | wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int id = 0, | |
134 | int nSel = -1, int nOldSel = -1); | |
135 | ||
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); | |
142 | }; | |
143 | ||
144 | ||
145 | ||
146 | //--------------------------------------------------------------------------- | |
147 | %newgroup | |
148 | ||
149 | enum { | |
150 | // styles | |
151 | wxNB_FIXEDWIDTH, | |
152 | wxNB_TOP, | |
153 | wxNB_LEFT, | |
154 | wxNB_RIGHT, | |
155 | wxNB_BOTTOM, | |
156 | wxNB_MULTILINE, | |
157 | wxNB_NOPAGETHEME, | |
158 | ||
159 | // hittest flags | |
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, | |
164 | ||
165 | }; | |
166 | ||
167 | ||
168 | ||
169 | MustHaveApp(wxNotebook); | |
170 | ||
171 | class wxNotebook : public wxBookCtrlBase { | |
172 | public: | |
173 | %pythonAppend wxNotebook "self._setOORInfo(self)" | |
174 | %pythonAppend wxNotebook() "" | |
175 | %typemap(out) wxNotebook*; // turn off this typemap | |
176 | ||
177 | wxNotebook(wxWindow *parent, | |
178 | wxWindowID id=-1, | |
179 | const wxPoint& pos = wxDefaultPosition, | |
180 | const wxSize& size = wxDefaultSize, | |
181 | long style = 0, | |
182 | const wxString& name = wxPyNotebookNameStr); | |
183 | %RenameCtor(PreNotebook, wxNotebook()); | |
184 | ||
185 | // Turn it back on again | |
186 | %typemap(out) wxNotebook* { $result = wxPyMake_wxObject($1, $owner); } | |
187 | ||
188 | bool Create(wxWindow *parent, | |
189 | wxWindowID id=-1, | |
190 | const wxPoint& pos = wxDefaultPosition, | |
191 | const wxSize& size = wxDefaultSize, | |
192 | long style = 0, | |
193 | const wxString& name = wxPyNotebookNameStr); | |
194 | ||
195 | ||
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; | |
199 | ||
200 | // set the padding between tabs (in pixels) | |
201 | virtual void SetPadding(const wxSize& padding); | |
202 | ||
203 | // set the size of the tabs for wxNB_FIXEDWIDTH controls | |
204 | virtual void SetTabSize(const wxSize& sz); | |
205 | ||
206 | // hit test, returns which tab is hit and, optionally, where (icon, label) | |
207 | // (not implemented on all platforms) | |
208 | DocDeclAStr( | |
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.", ""); | |
213 | ||
214 | // implement some base class functions | |
215 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; | |
216 | ||
217 | // On platforms that support it, get the theme page background colour, | |
218 | // else invalid colour | |
219 | wxColour GetThemeBackgroundColour() const; | |
220 | ||
221 | static wxVisualAttributes | |
222 | GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); | |
223 | }; | |
224 | ||
225 | ||
226 | ||
227 | class wxNotebookEvent : public wxBookCtrlBaseEvent | |
228 | { | |
229 | public: | |
230 | wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, | |
231 | int nSel = -1, int nOldSel = -1); | |
232 | ||
233 | }; | |
234 | ||
235 | // notebook control event types | |
236 | %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED; | |
237 | %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING; | |
238 | ||
239 | ||
240 | %pythoncode { | |
241 | %# wxNotebook events | |
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 ) | |
244 | } | |
245 | ||
246 | ||
247 | %pythoncode { | |
248 | %#---------------------------------------------------------------------------- | |
249 | ||
250 | class NotebookPage(wx.Panel): | |
251 | """ | |
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 | wxGTK, 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. | |
260 | """ | |
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) | |
265 | self.child = None | |
266 | self.Bind(wx.EVT_SIZE, self.OnSize) | |
267 | ||
268 | def OnSize(self, evt): | |
269 | if self.child is None: | |
270 | children = self.GetChildren() | |
271 | if len(children): | |
272 | self.child = children[0] | |
273 | if self.child: | |
274 | self.child.SetPosition((0,0)) | |
275 | self.child.SetSize(self.GetSize()) | |
276 | ||
277 | } | |
278 | ||
279 | //--------------------------------------------------------------------------- | |
280 | %newgroup | |
281 | ||
282 | ||
283 | enum | |
284 | { | |
285 | // default alignment: left everywhere except Mac where it is top | |
286 | wxLB_DEFAULT = 0, | |
287 | ||
288 | // put the list control to the left/right/top/bottom of the page area | |
289 | wxLB_TOP = 0x1, | |
290 | wxLB_BOTTOM = 0x2, | |
291 | wxLB_LEFT = 0x4, | |
292 | wxLB_RIGHT = 0x8, | |
293 | ||
294 | // the mask which can be used to extract the alignment from the style | |
295 | wxLB_ALIGN_MASK = 0xf, | |
296 | }; | |
297 | ||
298 | ||
299 | ||
300 | MustHaveApp(wxListbook); | |
301 | ||
302 | // wxListCtrl and wxNotebook combination | |
303 | class wxListbook : public wxBookCtrlBase | |
304 | { | |
305 | public: | |
306 | %pythonAppend wxListbook "self._setOORInfo(self)" | |
307 | %pythonAppend wxListbook() "" | |
308 | ||
309 | wxListbook(wxWindow *parent, | |
310 | wxWindowID id=-1, | |
311 | const wxPoint& pos = wxDefaultPosition, | |
312 | const wxSize& size = wxDefaultSize, | |
313 | long style = 0, | |
314 | const wxString& name = wxPyEmptyString); | |
315 | %RenameCtor(PreListbook, wxListbook()); | |
316 | ||
317 | bool Create(wxWindow *parent, | |
318 | wxWindowID id=-1, | |
319 | const wxPoint& pos = wxDefaultPosition, | |
320 | const wxSize& size = wxDefaultSize, | |
321 | long style = 0, | |
322 | const wxString& name = wxPyEmptyString); | |
323 | ||
324 | // returns True if we have wxLB_TOP or wxLB_BOTTOM style | |
325 | bool IsVertical() const; | |
326 | ||
327 | wxListView* GetListView(); | |
328 | }; | |
329 | ||
330 | ||
331 | ||
332 | class wxListbookEvent : public wxBookCtrlBaseEvent | |
333 | { | |
334 | public: | |
335 | wxListbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, | |
336 | int nSel = -1, int nOldSel = -1); | |
337 | }; | |
338 | ||
339 | ||
340 | %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED; | |
341 | %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING; | |
342 | ||
343 | %pythoncode { | |
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 ) | |
346 | } | |
347 | ||
348 | ||
349 | //--------------------------------------------------------------------------- | |
350 | ||
351 | ||
352 | /* | |
353 | * wxChoicebook flags | |
354 | */ | |
355 | enum { | |
356 | wxCHB_DEFAULT, | |
357 | wxCHB_TOP, | |
358 | wxCHB_BOTTOM, | |
359 | wxCHB_LEFT, | |
360 | wxCHB_RIGHT, | |
361 | wxCHB_ALIGN_MASK | |
362 | }; | |
363 | ||
364 | ||
365 | MustHaveApp(wxChoicebook); | |
366 | ||
367 | class wxChoicebook : public wxBookCtrlBase | |
368 | { | |
369 | public: | |
370 | %pythonAppend wxChoicebook "self._setOORInfo(self)" | |
371 | %pythonAppend wxChoicebook() "" | |
372 | ||
373 | wxChoicebook(wxWindow *parent, | |
374 | wxWindowID id, | |
375 | const wxPoint& pos = wxDefaultPosition, | |
376 | const wxSize& size = wxDefaultSize, | |
377 | long style = 0, | |
378 | const wxString& name = wxPyEmptyString); | |
379 | %RenameCtor(PreChoicebook, wxChoicebook()); | |
380 | ||
381 | // quasi ctor | |
382 | bool Create(wxWindow *parent, | |
383 | wxWindowID id, | |
384 | const wxPoint& pos = wxDefaultPosition, | |
385 | const wxSize& size = wxDefaultSize, | |
386 | long style = 0, | |
387 | const wxString& name = wxPyEmptyString); | |
388 | ||
389 | ||
390 | // returns true if we have wxCHB_TOP or wxCHB_BOTTOM style | |
391 | bool IsVertical() const { return HasFlag(wxCHB_BOTTOM | wxCHB_TOP); } | |
392 | ||
393 | virtual bool DeleteAllPages(); | |
394 | }; | |
395 | ||
396 | ||
397 | class wxChoicebookEvent : public wxBookCtrlBaseEvent | |
398 | { | |
399 | public: | |
400 | wxChoicebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, | |
401 | int nSel = -1, int nOldSel = -1); | |
402 | }; | |
403 | ||
404 | %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED; | |
405 | %constant wxEventType wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING; | |
406 | ||
407 | %pythoncode { | |
408 | EVT_CHOICEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED, 1 ) | |
409 | EVT_CHOICEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING, 1 ) | |
410 | } | |
411 | ||
412 | //--------------------------------------------------------------------------- | |
413 | %newgroup; | |
414 | ||
415 | // WXWIN_COMPATIBILITY_2_4 | |
416 | ||
417 | class wxBookCtrlSizer: public wxSizer | |
418 | { | |
419 | public: | |
420 | %pythonAppend wxBookCtrlSizer "self._setOORInfo(self)" | |
421 | ||
422 | wxBookCtrlSizer( wxBookCtrlBase *nb ); | |
423 | ||
424 | void RecalcSizes(); | |
425 | wxSize CalcMin(); | |
426 | wxBookCtrlBase *GetControl(); | |
427 | }; | |
428 | ||
429 | ||
430 | class wxNotebookSizer: public wxSizer { | |
431 | public: | |
432 | %pythonAppend wxNotebookSizer "self._setOORInfo(self)" | |
433 | ||
434 | wxNotebookSizer( wxNotebook *nb ); | |
435 | ||
436 | void RecalcSizes(); | |
437 | wxSize CalcMin(); | |
438 | wxNotebook *GetNotebook(); | |
439 | }; | |
440 | ||
441 | ||
442 | %pythoncode { NotebookSizer = wx._deprecated(NotebookSizer, "NotebookSizer is no longer needed.") } | |
443 | %pythoncode { BookCtrlSizer = wx._deprecated(BookCtrlSizer, "BookCtrlSizer is no longer needed.") } | |
444 | ||
445 | ||
446 | //--------------------------------------------------------------------------- |