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