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