]>
Commit | Line | Data |
---|---|---|
15aad3b9 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/bookctrl.h | |
61c083e7 | 3 | // Purpose: wxBookCtrlBase: common base class for wxList/Tree/Notebook |
15aad3b9 VZ |
4 | // Author: Vadim Zeitlin |
5 | // Modified by: | |
6 | // Created: 19.08.03 | |
7 | // RCS-ID: $Id$ | |
77ffb593 | 8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org> |
65571936 | 9 | // Licence: wxWindows licence |
15aad3b9 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_BOOKCTRL_H_ | |
13 | #define _WX_BOOKCTRL_H_ | |
14 | ||
15aad3b9 VZ |
15 | // ---------------------------------------------------------------------------- |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
19 | #include "wx/defs.h" | |
20 | ||
21 | #if wxUSE_BOOKCTRL | |
22 | ||
23 | #include "wx/control.h" | |
24 | #include "wx/dynarray.h" | |
25 | ||
d5d29b8a | 26 | WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow *, wxArrayPages); |
15aad3b9 VZ |
27 | |
28 | class WXDLLEXPORT wxImageList; | |
1d6fcbcc | 29 | class WXDLLEXPORT wxBookCtrlBaseEvent; |
9804d540 WS |
30 | |
31 | // ---------------------------------------------------------------------------- | |
32 | // constants | |
33 | // ---------------------------------------------------------------------------- | |
34 | ||
35 | // wxBookCtrl hit results | |
36 | enum | |
37 | { | |
38 | wxBK_HITTEST_NOWHERE = 1, // not on tab | |
39 | wxBK_HITTEST_ONICON = 2, // on icon | |
40 | wxBK_HITTEST_ONLABEL = 4, // on label | |
41 | wxBK_HITTEST_ONITEM = wxBK_HITTEST_ONICON | wxBK_HITTEST_ONLABEL, | |
42 | wxBK_HITTEST_ONPAGE = 8 // not on tab control, but over the selected page | |
43 | }; | |
15aad3b9 VZ |
44 | |
45 | // ---------------------------------------------------------------------------- | |
61c083e7 | 46 | // wxBookCtrlBase |
15aad3b9 VZ |
47 | // ---------------------------------------------------------------------------- |
48 | ||
61c083e7 | 49 | class WXDLLEXPORT wxBookCtrlBase : public wxControl |
15aad3b9 VZ |
50 | { |
51 | public: | |
52 | // construction | |
53 | // ------------ | |
54 | ||
61c083e7 | 55 | wxBookCtrlBase() |
6463b9f5 JS |
56 | { |
57 | Init(); | |
58 | } | |
15aad3b9 | 59 | |
61c083e7 WS |
60 | wxBookCtrlBase(wxWindow *parent, |
61 | wxWindowID winid, | |
62 | const wxPoint& pos = wxDefaultPosition, | |
63 | const wxSize& size = wxDefaultSize, | |
64 | long style = 0, | |
65 | const wxString& name = wxEmptyString) | |
6463b9f5 JS |
66 | { |
67 | Init(); | |
68 | ||
69 | (void)Create(parent, winid, pos, size, style, name); | |
70 | } | |
15aad3b9 VZ |
71 | |
72 | // quasi ctor | |
73 | bool Create(wxWindow *parent, | |
aa6f64c7 | 74 | wxWindowID winid, |
15aad3b9 VZ |
75 | const wxPoint& pos = wxDefaultPosition, |
76 | const wxSize& size = wxDefaultSize, | |
77 | long style = 0, | |
78 | const wxString& name = wxEmptyString); | |
79 | ||
80 | // dtor | |
61c083e7 | 81 | virtual ~wxBookCtrlBase(); |
15aad3b9 VZ |
82 | |
83 | ||
84 | // accessors | |
85 | // --------- | |
86 | ||
87 | // get number of pages in the dialog | |
88 | virtual size_t GetPageCount() const { return m_pages.size(); } | |
89 | ||
90 | // get the panel which represents the given page | |
97c58531 VZ |
91 | wxWindow *GetPage(size_t n) { return m_pages[n]; } |
92 | wxWindow *GetPage(size_t n) const { return m_pages[n]; } | |
15aad3b9 | 93 | |
21db32c1 VZ |
94 | // get the current page or NULL if none |
95 | wxWindow *GetCurrentPage() const | |
96 | { | |
97c58531 VZ |
97 | const int n = GetSelection(); |
98 | return n == wxNOT_FOUND ? NULL : GetPage(n); | |
21db32c1 VZ |
99 | } |
100 | ||
15aad3b9 VZ |
101 | // get the currently selected page or wxNOT_FOUND if none |
102 | virtual int GetSelection() const = 0; | |
103 | ||
104 | // set/get the title of a page | |
105 | virtual bool SetPageText(size_t n, const wxString& strText) = 0; | |
106 | virtual wxString GetPageText(size_t n) const = 0; | |
107 | ||
108 | ||
109 | // image list stuff: each page may have an image associated with it (all | |
110 | // images belong to the same image list) | |
111 | // --------------------------------------------------------------------- | |
112 | ||
113 | // sets the image list to use, it is *not* deleted by the control | |
114 | virtual void SetImageList(wxImageList *imageList); | |
115 | ||
116 | // as SetImageList() but we will delete the image list ourselves | |
117 | void AssignImageList(wxImageList *imageList); | |
118 | ||
119 | // get pointer (may be NULL) to the associated image list | |
120 | wxImageList* GetImageList() const { return m_imageList; } | |
121 | ||
122 | // sets/returns item's image index in the current image list | |
123 | virtual int GetPageImage(size_t n) const = 0; | |
124 | virtual bool SetPageImage(size_t n, int imageId) = 0; | |
125 | ||
126 | ||
127 | // geometry | |
128 | // -------- | |
129 | ||
130 | // resize the notebook so that all pages will have the specified size | |
131 | virtual void SetPageSize(const wxSize& size); | |
132 | ||
133 | // calculate the size of the control from the size of its page | |
134 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0; | |
135 | ||
159e6235 | 136 | // get/set size of area between book control area and page area |
851b88c3 VZ |
137 | unsigned int GetInternalBorder() const { return m_internalBorder; } |
138 | void SetInternalBorder(unsigned int border) { m_internalBorder = border; } | |
15aad3b9 | 139 | |
87cf52d8 JS |
140 | // Sets/gets the margin around the controller |
141 | void SetControlMargin(int margin) { m_controlMargin = margin; } | |
142 | int GetControlMargin() const { return m_controlMargin; } | |
143 | ||
e0d5d9af | 144 | // returns true if we have wxBK_TOP or wxBK_BOTTOM style |
90f9b8ef | 145 | bool IsVertical() const { return HasFlag(wxBK_BOTTOM | wxBK_TOP); } |
d8fd7acb | 146 | |
93bfe545 | 147 | // set/get option to shrink to fit current page |
da817fa6 JS |
148 | void SetFitToCurrentPage(bool fit) { m_fitToCurrentPage = fit; } |
149 | bool GetFitToCurrentPage() const { return m_fitToCurrentPage; } | |
93bfe545 | 150 | |
87cf52d8 JS |
151 | // returns the sizer containing the control, if any |
152 | wxSizer* GetControlSizer() const { return m_controlSizer; } | |
153 | ||
15aad3b9 VZ |
154 | // operations |
155 | // ---------- | |
156 | ||
157 | // remove one page from the control and delete it | |
158 | virtual bool DeletePage(size_t n); | |
159 | ||
160 | // remove one page from the notebook, without deleting it | |
37144cf0 RD |
161 | virtual bool RemovePage(size_t n) |
162 | { | |
163 | InvalidateBestSize(); | |
164 | return DoRemovePage(n) != NULL; | |
165 | } | |
15aad3b9 VZ |
166 | |
167 | // remove all pages and delete them | |
37144cf0 RD |
168 | virtual bool DeleteAllPages() |
169 | { | |
170 | InvalidateBestSize(); | |
171 | WX_CLEAR_ARRAY(m_pages); | |
172 | return true; | |
173 | } | |
15aad3b9 VZ |
174 | |
175 | // adds a new page to the control | |
176 | virtual bool AddPage(wxWindow *page, | |
177 | const wxString& text, | |
178 | bool bSelect = false, | |
179 | int imageId = -1) | |
180 | { | |
37144cf0 | 181 | InvalidateBestSize(); |
15aad3b9 VZ |
182 | return InsertPage(GetPageCount(), page, text, bSelect, imageId); |
183 | } | |
184 | ||
185 | // the same as AddPage(), but adds the page at the specified position | |
186 | virtual bool InsertPage(size_t n, | |
187 | wxWindow *page, | |
188 | const wxString& text, | |
189 | bool bSelect = false, | |
190 | int imageId = -1) = 0; | |
191 | ||
192 | // set the currently selected page, return the index of the previously | |
193 | // selected one (or -1 on error) | |
194 | // | |
1f30c176 | 195 | // NB: this function will generate PAGE_CHANGING/ED events |
15aad3b9 VZ |
196 | virtual int SetSelection(size_t n) = 0; |
197 | ||
1d6fcbcc VZ |
198 | // acts as SetSelection but does not generate events |
199 | virtual int ChangeSelection(size_t n) = 0; | |
200 | ||
15aad3b9 VZ |
201 | |
202 | // cycle thru the pages | |
203 | void AdvanceSelection(bool forward = true) | |
204 | { | |
205 | int nPage = GetNextPage(forward); | |
206 | if ( nPage != -1 ) | |
207 | { | |
208 | // cast is safe because of the check above | |
209 | SetSelection((size_t)nPage); | |
210 | } | |
211 | } | |
212 | ||
851b88c3 VZ |
213 | // hit test: returns which page is hit and, optionally, where (icon, label) |
214 | virtual int HitTest(const wxPoint& WXUNUSED(pt), | |
215 | long * WXUNUSED(flags) = NULL) const | |
216 | { | |
217 | return wxNOT_FOUND; | |
218 | } | |
219 | ||
e71c530e VZ |
220 | |
221 | // we do have multiple pages | |
222 | virtual bool HasMultiplePages() const { return true; } | |
223 | ||
15aad3b9 | 224 | protected: |
1d6fcbcc VZ |
225 | // typically, wxBookCtrl-derived classes will use DoSetSelection() function |
226 | // to implement SetSelection() and ChangeSelection() functions. | |
227 | // these flags make DoSetSelection() more readable | |
228 | enum | |
229 | { | |
230 | SetSelection_SendEvent = 1 | |
231 | }; | |
232 | ||
233 | // if using DoSetSelection() for implementing [Set|Change]Selection, | |
234 | // then override UpdateSelectedPage() and MakeChangedEvent() | |
235 | virtual int DoSetSelection(size_t nPage, int flags, wxBookCtrlBaseEvent &event); | |
236 | virtual void UpdateSelectedPage(size_t WXUNUSED(newsel)) | |
237 | { wxFAIL_MSG(wxT("Override this function!")); } | |
238 | virtual void MakeChangedEvent(wxBookCtrlBaseEvent &WXUNUSED(event)) | |
239 | { wxFAIL_MSG(wxT("Override this function!")); } | |
240 | ||
eca15c0d VZ |
241 | // Should we accept NULL page pointers in Add/InsertPage()? |
242 | // | |
243 | // Default is no but derived classes may override it if they can treat NULL | |
244 | // pages in some sensible way (e.g. wxTreebook overrides this to allow | |
245 | // having nodes without any associated page) | |
246 | virtual bool AllowNullPage() const { return false; } | |
247 | ||
15aad3b9 VZ |
248 | // remove the page and return a pointer to it |
249 | virtual wxWindow *DoRemovePage(size_t page) = 0; | |
250 | ||
251 | // our best size is the size which fits all our pages | |
252 | virtual wxSize DoGetBestSize() const; | |
253 | ||
254 | // helper: get the next page wrapping if we reached the end | |
255 | int GetNextPage(bool forward) const; | |
256 | ||
6457949e RD |
257 | // Always rely on GetBestSize, which will look at all the pages |
258 | virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { } | |
15aad3b9 | 259 | |
233387bd JS |
260 | // Lay out controls |
261 | void DoSize(); | |
262 | ||
a18c21f0 VZ |
263 | #if wxUSE_HELP |
264 | // Show the help for the corresponding page | |
265 | void OnHelp(wxHelpEvent& event); | |
266 | #endif // wxUSE_HELP | |
267 | ||
268 | ||
15aad3b9 VZ |
269 | // the array of all pages of this control |
270 | wxArrayPages m_pages; | |
271 | ||
272 | // the associated image list or NULL | |
273 | wxImageList *m_imageList; | |
274 | ||
275 | // true if we must delete m_imageList | |
276 | bool m_ownsImageList; | |
277 | ||
d8fd7acb WS |
278 | // get the page area |
279 | wxRect GetPageRect() const; | |
280 | ||
281 | // event handlers | |
282 | virtual wxSize GetControllerSize() const; | |
283 | void OnSize(wxSizeEvent& event); | |
284 | ||
285 | // controller buddy if available, NULL otherwise (usually for native book controls like wxNotebook) | |
286 | wxControl *m_bookctrl; | |
287 | ||
93bfe545 | 288 | // Whether to shrink to fit current page |
da817fa6 | 289 | bool m_fitToCurrentPage; |
93bfe545 | 290 | |
87cf52d8 JS |
291 | // the sizer containing the choice control |
292 | wxSizer* m_controlSizer; | |
293 | ||
294 | // the margin around the choice control | |
295 | int m_controlMargin; | |
296 | ||
159e6235 WS |
297 | private: |
298 | ||
299 | // common part of all ctors | |
300 | void Init(); | |
301 | ||
302 | // internal border | |
a5325ad6 | 303 | unsigned int m_internalBorder; |
15aad3b9 | 304 | |
d8fd7acb | 305 | DECLARE_ABSTRACT_CLASS(wxBookCtrlBase) |
61c083e7 | 306 | DECLARE_NO_COPY_CLASS(wxBookCtrlBase) |
d8fd7acb | 307 | DECLARE_EVENT_TABLE() |
15aad3b9 VZ |
308 | }; |
309 | ||
310 | // ---------------------------------------------------------------------------- | |
61c083e7 | 311 | // wxBookCtrlBaseEvent: page changing events generated by derived classes |
15aad3b9 VZ |
312 | // ---------------------------------------------------------------------------- |
313 | ||
61c083e7 | 314 | class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent |
15aad3b9 VZ |
315 | { |
316 | public: | |
61c083e7 WS |
317 | wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0, |
318 | int nSel = -1, int nOldSel = -1) | |
aa6f64c7 | 319 | : wxNotifyEvent(commandType, winid) |
b2f8e75a VZ |
320 | { |
321 | m_nSel = nSel; | |
322 | m_nOldSel = nOldSel; | |
323 | } | |
324 | ||
325 | wxBookCtrlBaseEvent(const wxBookCtrlBaseEvent& event) | |
326 | : wxNotifyEvent(event) | |
327 | { | |
328 | m_nSel = event.m_nSel; | |
329 | m_nOldSel = event.m_nOldSel; | |
330 | } | |
15aad3b9 VZ |
331 | |
332 | // accessors | |
333 | // the currently selected page (-1 if none) | |
334 | int GetSelection() const { return m_nSel; } | |
335 | void SetSelection(int nSel) { m_nSel = nSel; } | |
336 | // the page that was selected before the change (-1 if none) | |
337 | int GetOldSelection() const { return m_nOldSel; } | |
338 | void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; } | |
339 | ||
340 | private: | |
341 | int m_nSel, // currently selected page | |
342 | m_nOldSel; // previously selected page | |
343 | }; | |
344 | ||
61c083e7 | 345 | // make a default book control for given platform |
311131d3 WS |
346 | #if wxUSE_NOTEBOOK |
347 | // dedicated to majority of desktops | |
36b79d44 | 348 | #include "wx/notebook.h" |
61c083e7 WS |
349 | #define wxBookCtrl wxNotebook |
350 | #define wxBookCtrlEvent wxNotebookEvent | |
351 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED | |
352 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING | |
353 | #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn) | |
354 | #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn) | |
f41cf371 | 355 | #define wxBookctrlEventHandler(func) wxNotebookEventHandler(func) |
311131d3 WS |
356 | #else |
357 | // dedicated to Smartphones | |
358 | #include "wx/choicebk.h" | |
359 | #define wxBookCtrl wxChoicebook | |
360 | #define wxBookCtrlEvent wxChoicebookEvent | |
361 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED | |
362 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING | |
363 | #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn) | |
364 | #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn) | |
f41cf371 | 365 | #define wxBookctrlEventHandler(func) wxChoicebookEventHandler(func) |
d8fd7acb WS |
366 | #endif |
367 | ||
368 | #if WXWIN_COMPATIBILITY_2_6 | |
369 | #define wxBC_TOP wxBK_TOP | |
370 | #define wxBC_BOTTOM wxBK_BOTTOM | |
371 | #define wxBC_LEFT wxBK_LEFT | |
372 | #define wxBC_RIGHT wxBK_RIGHT | |
373 | #define wxBC_DEFAULT wxBK_DEFAULT | |
61c083e7 WS |
374 | #endif |
375 | ||
15aad3b9 VZ |
376 | #endif // wxUSE_BOOKCTRL |
377 | ||
378 | #endif // _WX_BOOKCTRL_H_ |