]>
Commit | Line | Data |
---|---|---|
d14a1e28 RD |
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 | %{ | |
19 | DECLARE_DEF_STRING(NOTEBOOK_NAME); | |
20 | %} | |
21 | ||
22 | //--------------------------------------------------------------------------- | |
23 | %newgroup | |
24 | ||
25 | // TODO: Virtualize this class so other book controls can be derived in Python | |
26 | ||
27 | // Common base class for wxList/Tree/Notebook | |
28 | class wxBookCtrl : public wxControl | |
29 | { | |
30 | public: | |
31 | // This is an ABC, it can't be constructed... | |
32 | ||
33 | // wxBookCtrl(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 | // %name(PreBookCtrl)wxBookCtrl(); | |
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 currently selected page or wxNOT_FOUND if none | |
55 | virtual int GetSelection() const/* = 0*/; | |
56 | ||
57 | // set/get the title of a page | |
58 | virtual bool SetPageText(size_t n, const wxString& strText)/* = 0*/; | |
59 | virtual wxString GetPageText(size_t n) const/* = 0*/; | |
60 | ||
61 | ||
62 | // image list stuff: each page may have an image associated with it (all | |
63 | // images belong to the same image list) | |
64 | ||
65 | // sets the image list to use, it is *not* deleted by the control | |
66 | virtual void SetImageList(wxImageList *imageList); | |
67 | ||
68 | // as SetImageList() but we will delete the image list ourselves | |
69 | %addtofunc AssignImageList "args[1].thisown = 0" | |
70 | void AssignImageList(wxImageList *imageList); | |
71 | ||
72 | // get pointer (may be NULL) to the associated image list | |
73 | wxImageList* GetImageList() const; | |
74 | ||
75 | // sets/returns item's image index in the current image list | |
76 | virtual int GetPageImage(size_t n) const/* = 0*/; | |
77 | virtual bool SetPageImage(size_t n, int imageId)/* = 0*/; | |
78 | ||
79 | ||
80 | // resize the notebook so that all pages will have the specified size | |
81 | virtual void SetPageSize(const wxSize& size); | |
82 | ||
83 | // calculate the size of the control from the size of its page | |
84 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const/* = 0*/; | |
85 | ||
86 | ||
87 | ||
88 | // remove one page from the control and delete it | |
89 | virtual bool DeletePage(size_t n); | |
90 | ||
91 | // remove one page from the notebook, without deleting it | |
92 | virtual bool RemovePage(size_t n); | |
93 | ||
94 | // remove all pages and delete them | |
95 | virtual bool DeleteAllPages(); | |
96 | ||
97 | // adds a new page to the control | |
98 | virtual bool AddPage(wxWindow *page, | |
99 | const wxString& text, | |
dd9f7fea | 100 | bool select = False, |
d14a1e28 RD |
101 | int imageId = -1); |
102 | ||
103 | // the same as AddPage(), but adds the page at the specified position | |
104 | virtual bool InsertPage(size_t n, | |
105 | wxWindow *page, | |
106 | const wxString& text, | |
dd9f7fea | 107 | bool select = False, |
d14a1e28 RD |
108 | int imageId = -1)/* = 0*/; |
109 | ||
110 | // set the currently selected page, return the index of the previously | |
111 | // selected one (or -1 on error) | |
112 | // | |
113 | // NB: this function will _not_ generate PAGE_CHANGING/ED events | |
114 | virtual int SetSelection(size_t n)/* = 0*/; | |
115 | ||
116 | ||
117 | // cycle thru the pages | |
dd9f7fea | 118 | void AdvanceSelection(bool forward = True); |
d14a1e28 RD |
119 | }; |
120 | ||
121 | ||
122 | ||
123 | class wxBookCtrlEvent : public wxNotifyEvent | |
124 | { | |
125 | public: | |
126 | wxBookCtrlEvent(wxEventType commandType = wxEVT_NULL, int id = 0, | |
127 | int nSel = -1, int nOldSel = -1); | |
128 | ||
129 | // the currently selected page (-1 if none) | |
130 | int GetSelection() const; | |
131 | void SetSelection(int nSel); | |
132 | // the page that was selected before the change (-1 if none) | |
133 | int GetOldSelection() const; | |
134 | void SetOldSelection(int nOldSel); | |
135 | }; | |
136 | ||
137 | ||
138 | ||
139 | //--------------------------------------------------------------------------- | |
140 | %newgroup | |
141 | ||
142 | enum { | |
143 | // styles | |
144 | wxNB_FIXEDWIDTH, | |
145 | wxNB_TOP, | |
146 | wxNB_LEFT, | |
147 | wxNB_RIGHT, | |
148 | wxNB_BOTTOM, | |
149 | wxNB_MULTILINE, | |
150 | ||
151 | // hittest flags | |
152 | wxNB_HITTEST_NOWHERE = 1, // not on tab | |
153 | wxNB_HITTEST_ONICON = 2, // on icon | |
154 | wxNB_HITTEST_ONLABEL = 4, // on label | |
155 | wxNB_HITTEST_ONITEM = wxNB_HITTEST_ONICON | wxNB_HITTEST_ONLABEL, | |
156 | ||
157 | }; | |
158 | ||
159 | ||
160 | ||
161 | class wxNotebook : public wxBookCtrl { | |
162 | public: | |
163 | %addtofunc wxNotebook "self._setOORInfo(self)" | |
164 | %addtofunc wxNotebook() "" | |
165 | ||
166 | wxNotebook(wxWindow *parent, | |
167 | wxWindowID id, | |
168 | const wxPoint& pos = wxDefaultPosition, | |
169 | const wxSize& size = wxDefaultSize, | |
170 | long style = 0, | |
171 | const wxString& name = wxPyNOTEBOOK_NAME); | |
172 | %name(PreNotebook)wxNotebook(); | |
173 | ||
174 | bool Create(wxWindow *parent, | |
175 | wxWindowID id, | |
176 | const wxPoint& pos = wxDefaultPosition, | |
177 | const wxSize& size = wxDefaultSize, | |
178 | long style = 0, | |
179 | const wxString& name = wxPyNOTEBOOK_NAME); | |
180 | ||
181 | ||
182 | // get the number of rows for a control with wxNB_MULTILINE style (not all | |
183 | // versions support it - they will always return 1 then) | |
184 | virtual int GetRowCount() const; | |
185 | ||
186 | // set the padding between tabs (in pixels) | |
187 | virtual void SetPadding(const wxSize& padding); | |
188 | ||
189 | // set the size of the tabs for wxNB_FIXEDWIDTH controls | |
190 | virtual void SetTabSize(const wxSize& sz); | |
191 | ||
192 | // hit test, returns which tab is hit and, optionally, where (icon, label) | |
193 | // (not implemented on all platforms) | |
322913ce RD |
194 | DocDeclAStr( |
195 | virtual int, HitTest(const wxPoint& pt, long* OUTPUT) const, | |
196 | "HitTest(Point pt) -> (tab, where)", | |
197 | "Returns the tab which is hit, and flags indicating where using wxNB_HITTEST_ flags."); | |
d14a1e28 RD |
198 | |
199 | // implement some base class functions | |
200 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const; | |
201 | ||
202 | #ifdef __WXMSW__ | |
203 | // Windows only: attempts to apply the UX theme page background to this page | |
204 | void ApplyThemeBackground(wxWindow* window, const wxColour& colour); | |
205 | #endif | |
206 | }; | |
207 | ||
208 | ||
209 | ||
210 | class wxNotebookEvent : public wxBookCtrlEvent | |
211 | { | |
212 | public: | |
213 | wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, | |
214 | int nSel = -1, int nOldSel = -1); | |
215 | ||
216 | }; | |
217 | ||
218 | // notebook control event types | |
219 | %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED; | |
220 | %constant wxEventType wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING; | |
221 | ||
222 | ||
223 | %pythoncode { | |
224 | %# wxNotebook events | |
225 | EVT_NOTEBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, 1 ) | |
226 | EVT_NOTEBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, 1 ) | |
227 | } | |
228 | ||
229 | ||
230 | %pythoncode { | |
231 | %#---------------------------------------------------------------------------- | |
232 | ||
233 | class NotebookPage(wx.Panel): | |
234 | """ | |
235 | There is an old (and apparently unsolvable) bug when placing a | |
236 | window with a nonstandard background colour in a wxNotebook on | |
237 | wxGTK, as the notbooks's background colour would always be used | |
238 | when the window is refreshed. The solution is to place a panel in | |
239 | the notbook and the coloured window on the panel, sized to cover | |
240 | the panel. This simple class does that for you, just put an | |
241 | instance of this in the notebook and make your regular window a | |
242 | child of this one and it will handle the resize for you. | |
243 | """ | |
244 | def __init__(self, parent, id=-1, | |
245 | pos=wx.DefaultPosition, size=wx.DefaultSize, | |
246 | style=wx.TAB_TRAVERSAL, name="panel"): | |
247 | wx.Panel.__init__(self, parent, id, pos, size, style, name) | |
248 | self.child = None | |
249 | EVT_SIZE(self, self.OnSize) | |
250 | ||
251 | def OnSize(self, evt): | |
252 | if self.child is None: | |
253 | children = self.GetChildren() | |
254 | if len(children): | |
255 | self.child = children[0] | |
256 | if self.child: | |
257 | self.child.SetPosition((0,0)) | |
258 | self.child.SetSize(self.GetSize()) | |
259 | ||
260 | } | |
261 | ||
262 | //--------------------------------------------------------------------------- | |
263 | %newgroup | |
264 | ||
265 | ||
266 | enum | |
267 | { | |
268 | // default alignment: left everywhere except Mac where it is top | |
269 | wxLB_DEFAULT = 0, | |
270 | ||
271 | // put the list control to the left/right/top/bottom of the page area | |
272 | wxLB_TOP = 0x1, | |
273 | wxLB_BOTTOM = 0x2, | |
274 | wxLB_LEFT = 0x4, | |
275 | wxLB_RIGHT = 0x8, | |
276 | ||
277 | // the mask which can be used to extract the alignment from the style | |
278 | wxLB_ALIGN_MASK = 0xf, | |
279 | }; | |
280 | ||
281 | ||
282 | ||
283 | // wxListCtrl and wxNotebook combination | |
284 | class wxListbook : public wxBookCtrl | |
285 | { | |
286 | public: | |
287 | %addtofunc wxListbook "self._setOORInfo(self)" | |
288 | %addtofunc wxListbook() "" | |
289 | ||
290 | wxListbook(wxWindow *parent, | |
291 | wxWindowID id, | |
292 | const wxPoint& pos = wxDefaultPosition, | |
293 | const wxSize& size = wxDefaultSize, | |
294 | long style = 0, | |
295 | const wxString& name = wxPyEmptyString); | |
296 | %name(PreListbook)wxListbook(); | |
297 | ||
298 | bool Create(wxWindow *parent, | |
299 | wxWindowID id, | |
300 | const wxPoint& pos = wxDefaultPosition, | |
301 | const wxSize& size = wxDefaultSize, | |
302 | long style = 0, | |
303 | const wxString& name = wxPyEmptyString); | |
304 | ||
dd9f7fea | 305 | // returns True if we have wxLB_TOP or wxLB_BOTTOM style |
d14a1e28 RD |
306 | bool IsVertical() const; |
307 | ||
308 | }; | |
309 | ||
310 | ||
311 | ||
312 | class wxListbookEvent : public wxBookCtrlEvent | |
313 | { | |
314 | public: | |
315 | wxListbookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, | |
316 | int nSel = -1, int nOldSel = -1); | |
317 | }; | |
318 | ||
319 | ||
320 | %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED; | |
321 | %constant wxEventType wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING; | |
322 | ||
323 | %pythoncode { | |
324 | EVT_LISTBOOK_PAGE_CHANGED = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGED, 1 ) | |
325 | EVT_LISTBOOK_PAGE_CHANGING = wx.PyEventBinder( wxEVT_COMMAND_LISTBOOK_PAGE_CHANGING, 1 ) | |
326 | } | |
327 | ||
328 | ||
329 | //--------------------------------------------------------------------------- | |
330 | %newgroup; | |
331 | ||
332 | ||
333 | class wxBookCtrlSizer: public wxSizer | |
334 | { | |
335 | public: | |
336 | %addtofunc wxBookCtrlSizer "self._setOORInfo(self)" | |
337 | ||
338 | wxBookCtrlSizer( wxBookCtrl *nb ); | |
339 | ||
340 | void RecalcSizes(); | |
341 | wxSize CalcMin(); | |
342 | wxBookCtrl *GetControl(); | |
343 | }; | |
344 | ||
345 | ||
346 | class wxNotebookSizer: public wxSizer { | |
347 | public: | |
348 | %addtofunc wxNotebookSizer "self._setOORInfo(self)" | |
349 | ||
350 | wxNotebookSizer( wxNotebook *nb ); | |
351 | ||
352 | void RecalcSizes(); | |
353 | wxSize CalcMin(); | |
354 | wxNotebook *GetNotebook(); | |
355 | }; | |
356 | ||
357 | //--------------------------------------------------------------------------- |