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