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