]> git.saurik.com Git - wxWidgets.git/blob - include/wx/bookctrl.h
added wxArtProvider::InsertProvider to accompany PushProvider
[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 WXDLLEXPORT wxImageList;
29
30 // ----------------------------------------------------------------------------
31 // constants
32 // ----------------------------------------------------------------------------
33
34 // wxBookCtrl hit results
35 enum
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 };
43
44 // ----------------------------------------------------------------------------
45 // wxBookCtrlBase
46 // ----------------------------------------------------------------------------
47
48 class WXDLLEXPORT wxBookCtrlBase : public wxControl
49 {
50 public:
51 // construction
52 // ------------
53
54 wxBookCtrlBase()
55 {
56 Init();
57 }
58
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)
65 {
66 Init();
67
68 (void)Create(parent, winid, pos, size, style, name);
69 }
70
71 // quasi ctor
72 bool Create(wxWindow *parent,
73 wxWindowID winid,
74 const wxPoint& pos = wxDefaultPosition,
75 const wxSize& size = wxDefaultSize,
76 long style = 0,
77 const wxString& name = wxEmptyString);
78
79 // dtor
80 virtual ~wxBookCtrlBase();
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
90 wxWindow *GetPage(size_t n) { return m_pages[n]; }
91 wxWindow *GetPage(size_t n) const { return m_pages[n]; }
92
93 // get the current page or NULL if none
94 wxWindow *GetCurrentPage() const
95 {
96 const int n = GetSelection();
97 return n == wxNOT_FOUND ? NULL : GetPage(n);
98 }
99
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
135 // get/set size of area between book control area and page area
136 unsigned int GetInternalBorder() const { return m_internalBorder; }
137 void SetInternalBorder(unsigned int border) { m_internalBorder = border; }
138
139 // Sets/gets the margin around the controller
140 void SetControlMargin(int margin) { m_controlMargin = margin; }
141 int GetControlMargin() const { return m_controlMargin; }
142
143 // returns true if we have wxBK_TOP or wxBK_BOTTOM style
144 bool IsVertical() const { return HasFlag(wxBK_BOTTOM | wxBK_TOP); }
145
146 // set/get option to shrink to fit current page
147 void SetFitToCurrentPage(bool fit) { m_fitToCurrentPage = fit; }
148 bool GetFitToCurrentPage() const { return m_fitToCurrentPage; }
149
150 // returns the sizer containing the control, if any
151 wxSizer* GetControlSizer() const { return m_controlSizer; }
152
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
160 virtual bool RemovePage(size_t n)
161 {
162 InvalidateBestSize();
163 return DoRemovePage(n) != NULL;
164 }
165
166 // remove all pages and delete them
167 virtual bool DeleteAllPages()
168 {
169 InvalidateBestSize();
170 WX_CLEAR_ARRAY(m_pages);
171 return true;
172 }
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 {
180 InvalidateBestSize();
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 //
194 // NB: this function will generate PAGE_CHANGING/ED events
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
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
216
217 // we do have multiple pages
218 virtual bool HasMultiplePages() const { return true; }
219
220 protected:
221 // Should we accept NULL page pointers in Add/InsertPage()?
222 //
223 // Default is no but derived classes may override it if they can treat NULL
224 // pages in some sensible way (e.g. wxTreebook overrides this to allow
225 // having nodes without any associated page)
226 virtual bool AllowNullPage() const { return false; }
227
228 // remove the page and return a pointer to it
229 virtual wxWindow *DoRemovePage(size_t page) = 0;
230
231 // our best size is the size which fits all our pages
232 virtual wxSize DoGetBestSize() const;
233
234 // helper: get the next page wrapping if we reached the end
235 int GetNextPage(bool forward) const;
236
237 // Always rely on GetBestSize, which will look at all the pages
238 virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
239
240 // Lay out controls
241 void DoSize();
242
243 #if wxUSE_HELP
244 // Show the help for the corresponding page
245 void OnHelp(wxHelpEvent& event);
246 #endif // wxUSE_HELP
247
248
249 // the array of all pages of this control
250 wxArrayPages m_pages;
251
252 // the associated image list or NULL
253 wxImageList *m_imageList;
254
255 // true if we must delete m_imageList
256 bool m_ownsImageList;
257
258 // get the page area
259 wxRect GetPageRect() const;
260
261 // event handlers
262 virtual wxSize GetControllerSize() const;
263 void OnSize(wxSizeEvent& event);
264
265 // controller buddy if available, NULL otherwise (usually for native book controls like wxNotebook)
266 wxControl *m_bookctrl;
267
268 // Whether to shrink to fit current page
269 bool m_fitToCurrentPage;
270
271 // the sizer containing the choice control
272 wxSizer* m_controlSizer;
273
274 // the margin around the choice control
275 int m_controlMargin;
276
277 private:
278
279 // common part of all ctors
280 void Init();
281
282 // internal border
283 unsigned int m_internalBorder;
284
285 DECLARE_ABSTRACT_CLASS(wxBookCtrlBase)
286 DECLARE_NO_COPY_CLASS(wxBookCtrlBase)
287 DECLARE_EVENT_TABLE()
288 };
289
290 // ----------------------------------------------------------------------------
291 // wxBookCtrlBaseEvent: page changing events generated by derived classes
292 // ----------------------------------------------------------------------------
293
294 class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent
295 {
296 public:
297 wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
298 int nSel = -1, int nOldSel = -1)
299 : wxNotifyEvent(commandType, winid)
300 {
301 m_nSel = nSel;
302 m_nOldSel = nOldSel;
303 }
304
305 wxBookCtrlBaseEvent(const wxBookCtrlBaseEvent& event)
306 : wxNotifyEvent(event)
307 {
308 m_nSel = event.m_nSel;
309 m_nOldSel = event.m_nOldSel;
310 }
311
312 // accessors
313 // the currently selected page (-1 if none)
314 int GetSelection() const { return m_nSel; }
315 void SetSelection(int nSel) { m_nSel = nSel; }
316 // the page that was selected before the change (-1 if none)
317 int GetOldSelection() const { return m_nOldSel; }
318 void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
319
320 private:
321 int m_nSel, // currently selected page
322 m_nOldSel; // previously selected page
323 };
324
325 // make a default book control for given platform
326 #if wxUSE_NOTEBOOK
327 // dedicated to majority of desktops
328 #include "wx/notebook.h"
329 #define wxBookCtrl wxNotebook
330 #define wxBookCtrlEvent wxNotebookEvent
331 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
332 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
333 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
334 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
335 #else
336 // dedicated to Smartphones
337 #include "wx/choicebk.h"
338 #define wxBookCtrl wxChoicebook
339 #define wxBookCtrlEvent wxChoicebookEvent
340 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
341 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
342 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
343 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
344 #endif
345
346 #if WXWIN_COMPATIBILITY_2_6
347 #define wxBC_TOP wxBK_TOP
348 #define wxBC_BOTTOM wxBK_BOTTOM
349 #define wxBC_LEFT wxBK_LEFT
350 #define wxBC_RIGHT wxBK_RIGHT
351 #define wxBC_DEFAULT wxBK_DEFAULT
352 #endif
353
354 #endif // wxUSE_BOOKCTRL
355
356 #endif // _WX_BOOKCTRL_H_