]> git.saurik.com Git - wxWidgets.git/blame - include/wx/bookctrl.h
Removed unused files.
[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
VZ
27
28class WXDLLEXPORT wxImageList;
9804d540
WS
29
30// ----------------------------------------------------------------------------
31// constants
32// ----------------------------------------------------------------------------
33
34// wxBookCtrl hit results
35enum
36{
37 wxBK_HITTEST_NOWHERE = 1, // not on tab
38 wxBK_HITTEST_ONICON = 2, // on icon
39 wxBK_HITTEST_ONLABEL = 4, // on label
40 wxBK_HITTEST_ONITEM = wxBK_HITTEST_ONICON | wxBK_HITTEST_ONLABEL,
41 wxBK_HITTEST_ONPAGE = 8 // not on tab control, but over the selected page
42};
15aad3b9
VZ
43
44// ----------------------------------------------------------------------------
61c083e7 45// wxBookCtrlBase
15aad3b9
VZ
46// ----------------------------------------------------------------------------
47
61c083e7 48class WXDLLEXPORT wxBookCtrlBase : public wxControl
15aad3b9
VZ
49{
50public:
51 // construction
52 // ------------
53
61c083e7 54 wxBookCtrlBase()
6463b9f5
JS
55 {
56 Init();
57 }
15aad3b9 58
61c083e7
WS
59 wxBookCtrlBase(wxWindow *parent,
60 wxWindowID winid,
61 const wxPoint& pos = wxDefaultPosition,
62 const wxSize& size = wxDefaultSize,
63 long style = 0,
64 const wxString& name = wxEmptyString)
6463b9f5
JS
65 {
66 Init();
67
68 (void)Create(parent, winid, pos, size, style, name);
69 }
15aad3b9
VZ
70
71 // quasi ctor
72 bool Create(wxWindow *parent,
aa6f64c7 73 wxWindowID winid,
15aad3b9
VZ
74 const wxPoint& pos = wxDefaultPosition,
75 const wxSize& size = wxDefaultSize,
76 long style = 0,
77 const wxString& name = wxEmptyString);
78
79 // dtor
61c083e7 80 virtual ~wxBookCtrlBase();
15aad3b9
VZ
81
82
83 // accessors
84 // ---------
85
86 // get number of pages in the dialog
87 virtual size_t GetPageCount() const { return m_pages.size(); }
88
89 // get the panel which represents the given page
97c58531
VZ
90 wxWindow *GetPage(size_t n) { return m_pages[n]; }
91 wxWindow *GetPage(size_t n) const { return m_pages[n]; }
15aad3b9 92
21db32c1
VZ
93 // get the current page or NULL if none
94 wxWindow *GetCurrentPage() const
95 {
97c58531
VZ
96 const int n = GetSelection();
97 return n == wxNOT_FOUND ? NULL : GetPage(n);
21db32c1
VZ
98 }
99
15aad3b9
VZ
100 // get the currently selected page or wxNOT_FOUND if none
101 virtual int GetSelection() const = 0;
102
103 // set/get the title of a page
104 virtual bool SetPageText(size_t n, const wxString& strText) = 0;
105 virtual wxString GetPageText(size_t n) const = 0;
106
107
108 // image list stuff: each page may have an image associated with it (all
109 // images belong to the same image list)
110 // ---------------------------------------------------------------------
111
112 // sets the image list to use, it is *not* deleted by the control
113 virtual void SetImageList(wxImageList *imageList);
114
115 // as SetImageList() but we will delete the image list ourselves
116 void AssignImageList(wxImageList *imageList);
117
118 // get pointer (may be NULL) to the associated image list
119 wxImageList* GetImageList() const { return m_imageList; }
120
121 // sets/returns item's image index in the current image list
122 virtual int GetPageImage(size_t n) const = 0;
123 virtual bool SetPageImage(size_t n, int imageId) = 0;
124
125
126 // geometry
127 // --------
128
129 // resize the notebook so that all pages will have the specified size
130 virtual void SetPageSize(const wxSize& size);
131
132 // calculate the size of the control from the size of its page
133 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0;
134
159e6235 135 // get/set size of area between book control area and page area
851b88c3
VZ
136 unsigned int GetInternalBorder() const { return m_internalBorder; }
137 void SetInternalBorder(unsigned int border) { m_internalBorder = border; }
15aad3b9 138
87cf52d8
JS
139 // Sets/gets the margin around the controller
140 void SetControlMargin(int margin) { m_controlMargin = margin; }
141 int GetControlMargin() const { return m_controlMargin; }
142
e0d5d9af 143 // returns true if we have wxBK_TOP or wxBK_BOTTOM style
90f9b8ef 144 bool IsVertical() const { return HasFlag(wxBK_BOTTOM | wxBK_TOP); }
d8fd7acb 145
93bfe545 146 // set/get option to shrink to fit current page
da817fa6
JS
147 void SetFitToCurrentPage(bool fit) { m_fitToCurrentPage = fit; }
148 bool GetFitToCurrentPage() const { return m_fitToCurrentPage; }
93bfe545 149
87cf52d8
JS
150 // returns the sizer containing the control, if any
151 wxSizer* GetControlSizer() const { return m_controlSizer; }
152
15aad3b9
VZ
153 // operations
154 // ----------
155
156 // remove one page from the control and delete it
157 virtual bool DeletePage(size_t n);
158
159 // remove one page from the notebook, without deleting it
37144cf0
RD
160 virtual bool RemovePage(size_t n)
161 {
162 InvalidateBestSize();
163 return DoRemovePage(n) != NULL;
164 }
15aad3b9
VZ
165
166 // remove all pages and delete them
37144cf0
RD
167 virtual bool DeleteAllPages()
168 {
169 InvalidateBestSize();
170 WX_CLEAR_ARRAY(m_pages);
171 return true;
172 }
15aad3b9
VZ
173
174 // adds a new page to the control
175 virtual bool AddPage(wxWindow *page,
176 const wxString& text,
177 bool bSelect = false,
178 int imageId = -1)
179 {
37144cf0 180 InvalidateBestSize();
15aad3b9
VZ
181 return InsertPage(GetPageCount(), page, text, bSelect, imageId);
182 }
183
184 // the same as AddPage(), but adds the page at the specified position
185 virtual bool InsertPage(size_t n,
186 wxWindow *page,
187 const wxString& text,
188 bool bSelect = false,
189 int imageId = -1) = 0;
190
191 // set the currently selected page, return the index of the previously
192 // selected one (or -1 on error)
193 //
1f30c176 194 // NB: this function will generate PAGE_CHANGING/ED events
15aad3b9
VZ
195 virtual int SetSelection(size_t n) = 0;
196
197
198 // cycle thru the pages
199 void AdvanceSelection(bool forward = true)
200 {
201 int nPage = GetNextPage(forward);
202 if ( nPage != -1 )
203 {
204 // cast is safe because of the check above
205 SetSelection((size_t)nPage);
206 }
207 }
208
851b88c3
VZ
209 // hit test: returns which page is hit and, optionally, where (icon, label)
210 virtual int HitTest(const wxPoint& WXUNUSED(pt),
211 long * WXUNUSED(flags) = NULL) const
212 {
213 return wxNOT_FOUND;
214 }
215
15aad3b9 216protected:
eca15c0d
VZ
217 // Should we accept NULL page pointers in Add/InsertPage()?
218 //
219 // Default is no but derived classes may override it if they can treat NULL
220 // pages in some sensible way (e.g. wxTreebook overrides this to allow
221 // having nodes without any associated page)
222 virtual bool AllowNullPage() const { return false; }
223
15aad3b9
VZ
224 // remove the page and return a pointer to it
225 virtual wxWindow *DoRemovePage(size_t page) = 0;
226
227 // our best size is the size which fits all our pages
228 virtual wxSize DoGetBestSize() const;
229
230 // helper: get the next page wrapping if we reached the end
231 int GetNextPage(bool forward) const;
232
6457949e
RD
233 // Always rely on GetBestSize, which will look at all the pages
234 virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
15aad3b9 235
233387bd
JS
236 // Lay out controls
237 void DoSize();
238
a18c21f0
VZ
239#if wxUSE_HELP
240 // Show the help for the corresponding page
241 void OnHelp(wxHelpEvent& event);
242#endif // wxUSE_HELP
243
244
15aad3b9
VZ
245 // the array of all pages of this control
246 wxArrayPages m_pages;
247
248 // the associated image list or NULL
249 wxImageList *m_imageList;
250
251 // true if we must delete m_imageList
252 bool m_ownsImageList;
253
d8fd7acb
WS
254 // get the page area
255 wxRect GetPageRect() const;
256
257 // event handlers
258 virtual wxSize GetControllerSize() const;
259 void OnSize(wxSizeEvent& event);
260
261 // controller buddy if available, NULL otherwise (usually for native book controls like wxNotebook)
262 wxControl *m_bookctrl;
263
93bfe545 264 // Whether to shrink to fit current page
da817fa6 265 bool m_fitToCurrentPage;
93bfe545 266
87cf52d8
JS
267 // the sizer containing the choice control
268 wxSizer* m_controlSizer;
269
270 // the margin around the choice control
271 int m_controlMargin;
272
159e6235
WS
273private:
274
275 // common part of all ctors
276 void Init();
277
278 // internal border
a5325ad6 279 unsigned int m_internalBorder;
15aad3b9 280
d8fd7acb 281 DECLARE_ABSTRACT_CLASS(wxBookCtrlBase)
61c083e7 282 DECLARE_NO_COPY_CLASS(wxBookCtrlBase)
d8fd7acb 283 DECLARE_EVENT_TABLE()
15aad3b9
VZ
284};
285
286// ----------------------------------------------------------------------------
61c083e7 287// wxBookCtrlBaseEvent: page changing events generated by derived classes
15aad3b9
VZ
288// ----------------------------------------------------------------------------
289
61c083e7 290class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent
15aad3b9
VZ
291{
292public:
61c083e7
WS
293 wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
294 int nSel = -1, int nOldSel = -1)
aa6f64c7 295 : wxNotifyEvent(commandType, winid)
b2f8e75a
VZ
296 {
297 m_nSel = nSel;
298 m_nOldSel = nOldSel;
299 }
300
301 wxBookCtrlBaseEvent(const wxBookCtrlBaseEvent& event)
302 : wxNotifyEvent(event)
303 {
304 m_nSel = event.m_nSel;
305 m_nOldSel = event.m_nOldSel;
306 }
15aad3b9
VZ
307
308 // accessors
309 // the currently selected page (-1 if none)
310 int GetSelection() const { return m_nSel; }
311 void SetSelection(int nSel) { m_nSel = nSel; }
312 // the page that was selected before the change (-1 if none)
313 int GetOldSelection() const { return m_nOldSel; }
314 void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
315
316private:
317 int m_nSel, // currently selected page
318 m_nOldSel; // previously selected page
319};
320
61c083e7 321// make a default book control for given platform
311131d3
WS
322#if wxUSE_NOTEBOOK
323 // dedicated to majority of desktops
36b79d44 324 #include "wx/notebook.h"
61c083e7
WS
325 #define wxBookCtrl wxNotebook
326 #define wxBookCtrlEvent wxNotebookEvent
327 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
328 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
329 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
330 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
311131d3
WS
331#else
332 // dedicated to Smartphones
333 #include "wx/choicebk.h"
334 #define wxBookCtrl wxChoicebook
335 #define wxBookCtrlEvent wxChoicebookEvent
336 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
337 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
338 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
339 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
d8fd7acb
WS
340#endif
341
342#if WXWIN_COMPATIBILITY_2_6
343 #define wxBC_TOP wxBK_TOP
344 #define wxBC_BOTTOM wxBK_BOTTOM
345 #define wxBC_LEFT wxBK_LEFT
346 #define wxBC_RIGHT wxBK_RIGHT
347 #define wxBC_DEFAULT wxBK_DEFAULT
61c083e7
WS
348#endif
349
15aad3b9
VZ
350#endif // wxUSE_BOOKCTRL
351
352#endif // _WX_BOOKCTRL_H_