]>
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 | 27 | |
b5dbe15d | 28 | class WXDLLIMPEXP_FWD_CORE wxImageList; |
3e97a905 | 29 | class WXDLLIMPEXP_FWD_CORE wxBookCtrlEvent; |
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 | 44 | |
73a0b98c VZ |
45 | // wxBookCtrl flags (common for wxNotebook, wxListbook, wxChoicebook, wxTreebook) |
46 | #define wxBK_DEFAULT 0x0000 | |
47 | #define wxBK_TOP 0x0010 | |
48 | #define wxBK_BOTTOM 0x0020 | |
49 | #define wxBK_LEFT 0x0040 | |
50 | #define wxBK_RIGHT 0x0080 | |
51 | #define wxBK_ALIGN_MASK (wxBK_TOP | wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT) | |
52 | ||
15aad3b9 | 53 | // ---------------------------------------------------------------------------- |
61c083e7 | 54 | // wxBookCtrlBase |
15aad3b9 VZ |
55 | // ---------------------------------------------------------------------------- |
56 | ||
53a2db12 | 57 | class WXDLLIMPEXP_CORE wxBookCtrlBase : public wxControl |
15aad3b9 VZ |
58 | { |
59 | public: | |
60 | // construction | |
61 | // ------------ | |
62 | ||
61c083e7 | 63 | wxBookCtrlBase() |
6463b9f5 JS |
64 | { |
65 | Init(); | |
66 | } | |
15aad3b9 | 67 | |
61c083e7 WS |
68 | wxBookCtrlBase(wxWindow *parent, |
69 | wxWindowID winid, | |
70 | const wxPoint& pos = wxDefaultPosition, | |
71 | const wxSize& size = wxDefaultSize, | |
72 | long style = 0, | |
73 | const wxString& name = wxEmptyString) | |
6463b9f5 JS |
74 | { |
75 | Init(); | |
76 | ||
77 | (void)Create(parent, winid, pos, size, style, name); | |
78 | } | |
15aad3b9 VZ |
79 | |
80 | // quasi ctor | |
81 | bool Create(wxWindow *parent, | |
aa6f64c7 | 82 | wxWindowID winid, |
15aad3b9 VZ |
83 | const wxPoint& pos = wxDefaultPosition, |
84 | const wxSize& size = wxDefaultSize, | |
85 | long style = 0, | |
86 | const wxString& name = wxEmptyString); | |
87 | ||
88 | // dtor | |
61c083e7 | 89 | virtual ~wxBookCtrlBase(); |
15aad3b9 VZ |
90 | |
91 | ||
92 | // accessors | |
93 | // --------- | |
94 | ||
95 | // get number of pages in the dialog | |
96 | virtual size_t GetPageCount() const { return m_pages.size(); } | |
97 | ||
98 | // get the panel which represents the given page | |
97c58531 | 99 | wxWindow *GetPage(size_t n) const { return m_pages[n]; } |
15aad3b9 | 100 | |
21db32c1 VZ |
101 | // get the current page or NULL if none |
102 | wxWindow *GetCurrentPage() const | |
103 | { | |
97c58531 VZ |
104 | const int n = GetSelection(); |
105 | return n == wxNOT_FOUND ? NULL : GetPage(n); | |
21db32c1 VZ |
106 | } |
107 | ||
15aad3b9 VZ |
108 | // get the currently selected page or wxNOT_FOUND if none |
109 | virtual int GetSelection() const = 0; | |
110 | ||
111 | // set/get the title of a page | |
112 | virtual bool SetPageText(size_t n, const wxString& strText) = 0; | |
113 | virtual wxString GetPageText(size_t n) const = 0; | |
114 | ||
115 | ||
116 | // image list stuff: each page may have an image associated with it (all | |
117 | // images belong to the same image list) | |
118 | // --------------------------------------------------------------------- | |
119 | ||
120 | // sets the image list to use, it is *not* deleted by the control | |
121 | virtual void SetImageList(wxImageList *imageList); | |
122 | ||
123 | // as SetImageList() but we will delete the image list ourselves | |
124 | void AssignImageList(wxImageList *imageList); | |
125 | ||
126 | // get pointer (may be NULL) to the associated image list | |
127 | wxImageList* GetImageList() const { return m_imageList; } | |
128 | ||
129 | // sets/returns item's image index in the current image list | |
130 | virtual int GetPageImage(size_t n) const = 0; | |
131 | virtual bool SetPageImage(size_t n, int imageId) = 0; | |
132 | ||
133 | ||
134 | // geometry | |
135 | // -------- | |
136 | ||
137 | // resize the notebook so that all pages will have the specified size | |
138 | virtual void SetPageSize(const wxSize& size); | |
139 | ||
140 | // calculate the size of the control from the size of its page | |
141 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0; | |
142 | ||
159e6235 | 143 | // get/set size of area between book control area and page area |
851b88c3 VZ |
144 | unsigned int GetInternalBorder() const { return m_internalBorder; } |
145 | void SetInternalBorder(unsigned int border) { m_internalBorder = border; } | |
15aad3b9 | 146 | |
87cf52d8 JS |
147 | // Sets/gets the margin around the controller |
148 | void SetControlMargin(int margin) { m_controlMargin = margin; } | |
149 | int GetControlMargin() const { return m_controlMargin; } | |
150 | ||
e0d5d9af | 151 | // returns true if we have wxBK_TOP or wxBK_BOTTOM style |
90f9b8ef | 152 | bool IsVertical() const { return HasFlag(wxBK_BOTTOM | wxBK_TOP); } |
d8fd7acb | 153 | |
93bfe545 | 154 | // set/get option to shrink to fit current page |
da817fa6 JS |
155 | void SetFitToCurrentPage(bool fit) { m_fitToCurrentPage = fit; } |
156 | bool GetFitToCurrentPage() const { return m_fitToCurrentPage; } | |
93bfe545 | 157 | |
87cf52d8 JS |
158 | // returns the sizer containing the control, if any |
159 | wxSizer* GetControlSizer() const { return m_controlSizer; } | |
160 | ||
3368424a | 161 | |
15aad3b9 VZ |
162 | // operations |
163 | // ---------- | |
164 | ||
165 | // remove one page from the control and delete it | |
166 | virtual bool DeletePage(size_t n); | |
167 | ||
168 | // remove one page from the notebook, without deleting it | |
37144cf0 RD |
169 | virtual bool RemovePage(size_t n) |
170 | { | |
e8a147a6 | 171 | DoInvalidateBestSize(); |
37144cf0 RD |
172 | return DoRemovePage(n) != NULL; |
173 | } | |
15aad3b9 VZ |
174 | |
175 | // remove all pages and delete them | |
37144cf0 RD |
176 | virtual bool DeleteAllPages() |
177 | { | |
e8a147a6 | 178 | DoInvalidateBestSize(); |
37144cf0 RD |
179 | WX_CLEAR_ARRAY(m_pages); |
180 | return true; | |
181 | } | |
15aad3b9 VZ |
182 | |
183 | // adds a new page to the control | |
184 | virtual bool AddPage(wxWindow *page, | |
185 | const wxString& text, | |
186 | bool bSelect = false, | |
187 | int imageId = -1) | |
188 | { | |
e8a147a6 | 189 | DoInvalidateBestSize(); |
15aad3b9 VZ |
190 | return InsertPage(GetPageCount(), page, text, bSelect, imageId); |
191 | } | |
192 | ||
193 | // the same as AddPage(), but adds the page at the specified position | |
194 | virtual bool InsertPage(size_t n, | |
195 | wxWindow *page, | |
196 | const wxString& text, | |
197 | bool bSelect = false, | |
198 | int imageId = -1) = 0; | |
199 | ||
200 | // set the currently selected page, return the index of the previously | |
201 | // selected one (or -1 on error) | |
202 | // | |
1f30c176 | 203 | // NB: this function will generate PAGE_CHANGING/ED events |
15aad3b9 VZ |
204 | virtual int SetSelection(size_t n) = 0; |
205 | ||
1d6fcbcc VZ |
206 | // acts as SetSelection but does not generate events |
207 | virtual int ChangeSelection(size_t n) = 0; | |
208 | ||
15aad3b9 VZ |
209 | |
210 | // cycle thru the pages | |
211 | void AdvanceSelection(bool forward = true) | |
212 | { | |
213 | int nPage = GetNextPage(forward); | |
214 | if ( nPage != -1 ) | |
215 | { | |
216 | // cast is safe because of the check above | |
217 | SetSelection((size_t)nPage); | |
218 | } | |
219 | } | |
220 | ||
851b88c3 VZ |
221 | // hit test: returns which page is hit and, optionally, where (icon, label) |
222 | virtual int HitTest(const wxPoint& WXUNUSED(pt), | |
223 | long * WXUNUSED(flags) = NULL) const | |
224 | { | |
225 | return wxNOT_FOUND; | |
226 | } | |
227 | ||
e71c530e VZ |
228 | |
229 | // we do have multiple pages | |
230 | virtual bool HasMultiplePages() const { return true; } | |
231 | ||
3368424a VZ |
232 | // we don't want focus for ourselves |
233 | virtual bool AcceptsFocus() const { return false; } | |
e8a147a6 | 234 | |
a047aff2 JS |
235 | // returns true if the platform should explicitly apply a theme border |
236 | virtual bool CanApplyThemeBorder() const { return false; } | |
237 | ||
15aad3b9 | 238 | protected: |
deb325e3 | 239 | // flags for DoSetSelection() |
1d6fcbcc VZ |
240 | enum |
241 | { | |
242 | SetSelection_SendEvent = 1 | |
243 | }; | |
244 | ||
dc797d8e JS |
245 | // choose the default border for this window |
246 | virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } | |
247 | ||
deb325e3 VZ |
248 | // set the selection to the given page, sending the events (which can |
249 | // possibly prevent the page change from taking place) if SendEvent flag is | |
250 | // included | |
251 | virtual int DoSetSelection(size_t nPage, int flags = 0); | |
252 | ||
253 | // if the derived class uses DoSetSelection() for implementing | |
254 | // [Set|Change]Selection, it must override UpdateSelectedPage(), | |
255 | // CreatePageChangingEvent() and MakeChangedEvent(), but as it might not | |
256 | // use it, these functions are not pure virtual | |
257 | ||
258 | // called to notify the control about a new current page | |
1d6fcbcc VZ |
259 | virtual void UpdateSelectedPage(size_t WXUNUSED(newsel)) |
260 | { wxFAIL_MSG(wxT("Override this function!")); } | |
deb325e3 VZ |
261 | |
262 | // create a new "page changing" event | |
3e97a905 | 263 | virtual wxBookCtrlEvent* CreatePageChangingEvent() const |
deb325e3 VZ |
264 | { wxFAIL_MSG(wxT("Override this function!")); return NULL; } |
265 | ||
266 | // modify the event created by CreatePageChangingEvent() to "page changed" | |
267 | // event, usually by just calling SetEventType() on it | |
3e97a905 | 268 | virtual void MakeChangedEvent(wxBookCtrlEvent& WXUNUSED(event)) |
1d6fcbcc VZ |
269 | { wxFAIL_MSG(wxT("Override this function!")); } |
270 | ||
deb325e3 | 271 | |
eca15c0d VZ |
272 | // Should we accept NULL page pointers in Add/InsertPage()? |
273 | // | |
274 | // Default is no but derived classes may override it if they can treat NULL | |
275 | // pages in some sensible way (e.g. wxTreebook overrides this to allow | |
276 | // having nodes without any associated page) | |
277 | virtual bool AllowNullPage() const { return false; } | |
278 | ||
15aad3b9 VZ |
279 | // remove the page and return a pointer to it |
280 | virtual wxWindow *DoRemovePage(size_t page) = 0; | |
281 | ||
282 | // our best size is the size which fits all our pages | |
283 | virtual wxSize DoGetBestSize() const; | |
284 | ||
285 | // helper: get the next page wrapping if we reached the end | |
286 | int GetNextPage(bool forward) const; | |
287 | ||
233387bd JS |
288 | // Lay out controls |
289 | void DoSize(); | |
290 | ||
e8a147a6 VZ |
291 | // This method also invalidates the size of the controller and should be |
292 | // called instead of just InvalidateBestSize() whenever pages are added or | |
293 | // removed as this also affects the controller | |
294 | void DoInvalidateBestSize(); | |
295 | ||
a18c21f0 VZ |
296 | #if wxUSE_HELP |
297 | // Show the help for the corresponding page | |
298 | void OnHelp(wxHelpEvent& event); | |
299 | #endif // wxUSE_HELP | |
300 | ||
301 | ||
15aad3b9 VZ |
302 | // the array of all pages of this control |
303 | wxArrayPages m_pages; | |
304 | ||
305 | // the associated image list or NULL | |
306 | wxImageList *m_imageList; | |
307 | ||
308 | // true if we must delete m_imageList | |
309 | bool m_ownsImageList; | |
310 | ||
d8fd7acb WS |
311 | // get the page area |
312 | wxRect GetPageRect() const; | |
313 | ||
314 | // event handlers | |
315 | virtual wxSize GetControllerSize() const; | |
316 | void OnSize(wxSizeEvent& event); | |
317 | ||
318 | // controller buddy if available, NULL otherwise (usually for native book controls like wxNotebook) | |
319 | wxControl *m_bookctrl; | |
320 | ||
93bfe545 | 321 | // Whether to shrink to fit current page |
da817fa6 | 322 | bool m_fitToCurrentPage; |
93bfe545 | 323 | |
87cf52d8 | 324 | // the sizer containing the choice control |
e8a147a6 | 325 | wxSizer *m_controlSizer; |
87cf52d8 JS |
326 | |
327 | // the margin around the choice control | |
e8a147a6 | 328 | int m_controlMargin; |
87cf52d8 | 329 | |
159e6235 WS |
330 | private: |
331 | ||
332 | // common part of all ctors | |
333 | void Init(); | |
334 | ||
335 | // internal border | |
a5325ad6 | 336 | unsigned int m_internalBorder; |
15aad3b9 | 337 | |
d8fd7acb | 338 | DECLARE_ABSTRACT_CLASS(wxBookCtrlBase) |
c0c133e1 | 339 | wxDECLARE_NO_COPY_CLASS(wxBookCtrlBase); |
d8fd7acb | 340 | DECLARE_EVENT_TABLE() |
15aad3b9 VZ |
341 | }; |
342 | ||
343 | // ---------------------------------------------------------------------------- | |
3e97a905 | 344 | // wxBookCtrlEvent: page changing events generated by book classes |
15aad3b9 VZ |
345 | // ---------------------------------------------------------------------------- |
346 | ||
3e97a905 | 347 | class WXDLLIMPEXP_CORE wxBookCtrlEvent : public wxNotifyEvent |
15aad3b9 VZ |
348 | { |
349 | public: | |
3e97a905 | 350 | wxBookCtrlEvent(wxEventType commandType = wxEVT_NULL, int winid = 0, |
61c083e7 | 351 | int nSel = -1, int nOldSel = -1) |
aa6f64c7 | 352 | : wxNotifyEvent(commandType, winid) |
b2f8e75a VZ |
353 | { |
354 | m_nSel = nSel; | |
355 | m_nOldSel = nOldSel; | |
356 | } | |
357 | ||
3e97a905 | 358 | wxBookCtrlEvent(const wxBookCtrlEvent& event) |
b2f8e75a VZ |
359 | : wxNotifyEvent(event) |
360 | { | |
361 | m_nSel = event.m_nSel; | |
362 | m_nOldSel = event.m_nOldSel; | |
363 | } | |
15aad3b9 | 364 | |
3e97a905 VZ |
365 | virtual wxEvent *Clone() const { return new wxBookCtrlEvent(*this); } |
366 | ||
15aad3b9 VZ |
367 | // accessors |
368 | // the currently selected page (-1 if none) | |
369 | int GetSelection() const { return m_nSel; } | |
370 | void SetSelection(int nSel) { m_nSel = nSel; } | |
371 | // the page that was selected before the change (-1 if none) | |
372 | int GetOldSelection() const { return m_nOldSel; } | |
373 | void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; } | |
374 | ||
375 | private: | |
376 | int m_nSel, // currently selected page | |
377 | m_nOldSel; // previously selected page | |
3e97a905 VZ |
378 | |
379 | DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxBookCtrlEvent) | |
15aad3b9 VZ |
380 | }; |
381 | ||
3e97a905 VZ |
382 | typedef void (wxEvtHandler::*wxBookCtrlEventFunction)(wxBookCtrlEvent&); |
383 | ||
384 | #define wxBookCtrlEventHandler(func) \ | |
3c778901 | 385 | wxEVENT_HANDLER_CAST(wxBookCtrlEventFunction, func) |
3e97a905 VZ |
386 | |
387 | // obsolete name, defined for compatibility only | |
388 | #define wxBookCtrlBaseEvent wxBookCtrlEvent | |
389 | ||
61c083e7 | 390 | // make a default book control for given platform |
311131d3 WS |
391 | #if wxUSE_NOTEBOOK |
392 | // dedicated to majority of desktops | |
36b79d44 | 393 | #include "wx/notebook.h" |
61c083e7 | 394 | #define wxBookCtrl wxNotebook |
61c083e7 WS |
395 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED |
396 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING | |
397 | #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn) | |
398 | #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn) | |
311131d3 WS |
399 | #else |
400 | // dedicated to Smartphones | |
401 | #include "wx/choicebk.h" | |
402 | #define wxBookCtrl wxChoicebook | |
311131d3 WS |
403 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED |
404 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING | |
405 | #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn) | |
406 | #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn) | |
d8fd7acb WS |
407 | #endif |
408 | ||
409 | #if WXWIN_COMPATIBILITY_2_6 | |
410 | #define wxBC_TOP wxBK_TOP | |
411 | #define wxBC_BOTTOM wxBK_BOTTOM | |
412 | #define wxBC_LEFT wxBK_LEFT | |
413 | #define wxBC_RIGHT wxBK_RIGHT | |
414 | #define wxBC_DEFAULT wxBK_DEFAULT | |
61c083e7 WS |
415 | #endif |
416 | ||
15aad3b9 VZ |
417 | #endif // wxUSE_BOOKCTRL |
418 | ||
419 | #endif // _WX_BOOKCTRL_H_ |