]>
Commit | Line | Data |
---|---|---|
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 | 26 | WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow *, wxArrayPages); |
15aad3b9 VZ |
27 | |
28 | class WXDLLEXPORT wxImageList; | |
9804d540 WS |
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 | }; | |
15aad3b9 VZ |
43 | |
44 | // ---------------------------------------------------------------------------- | |
61c083e7 | 45 | // wxBookCtrlBase |
15aad3b9 VZ |
46 | // ---------------------------------------------------------------------------- |
47 | ||
61c083e7 | 48 | class WXDLLEXPORT wxBookCtrlBase : public wxControl |
15aad3b9 VZ |
49 | { |
50 | public: | |
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 | ||
e71c530e VZ |
216 | |
217 | // we do have multiple pages | |
218 | virtual bool HasMultiplePages() const { return true; } | |
219 | ||
15aad3b9 | 220 | protected: |
eca15c0d VZ |
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 | ||
15aad3b9 VZ |
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 | ||
6457949e RD |
237 | // Always rely on GetBestSize, which will look at all the pages |
238 | virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { } | |
15aad3b9 | 239 | |
233387bd JS |
240 | // Lay out controls |
241 | void DoSize(); | |
242 | ||
a18c21f0 VZ |
243 | #if wxUSE_HELP |
244 | // Show the help for the corresponding page | |
245 | void OnHelp(wxHelpEvent& event); | |
246 | #endif // wxUSE_HELP | |
247 | ||
248 | ||
15aad3b9 VZ |
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 | ||
d8fd7acb WS |
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 | ||
93bfe545 | 268 | // Whether to shrink to fit current page |
da817fa6 | 269 | bool m_fitToCurrentPage; |
93bfe545 | 270 | |
87cf52d8 JS |
271 | // the sizer containing the choice control |
272 | wxSizer* m_controlSizer; | |
273 | ||
274 | // the margin around the choice control | |
275 | int m_controlMargin; | |
276 | ||
159e6235 WS |
277 | private: |
278 | ||
279 | // common part of all ctors | |
280 | void Init(); | |
281 | ||
282 | // internal border | |
a5325ad6 | 283 | unsigned int m_internalBorder; |
15aad3b9 | 284 | |
d8fd7acb | 285 | DECLARE_ABSTRACT_CLASS(wxBookCtrlBase) |
61c083e7 | 286 | DECLARE_NO_COPY_CLASS(wxBookCtrlBase) |
d8fd7acb | 287 | DECLARE_EVENT_TABLE() |
15aad3b9 VZ |
288 | }; |
289 | ||
290 | // ---------------------------------------------------------------------------- | |
61c083e7 | 291 | // wxBookCtrlBaseEvent: page changing events generated by derived classes |
15aad3b9 VZ |
292 | // ---------------------------------------------------------------------------- |
293 | ||
61c083e7 | 294 | class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent |
15aad3b9 VZ |
295 | { |
296 | public: | |
61c083e7 WS |
297 | wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0, |
298 | int nSel = -1, int nOldSel = -1) | |
aa6f64c7 | 299 | : wxNotifyEvent(commandType, winid) |
b2f8e75a VZ |
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 | } | |
15aad3b9 VZ |
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 | ||
61c083e7 | 325 | // make a default book control for given platform |
311131d3 WS |
326 | #if wxUSE_NOTEBOOK |
327 | // dedicated to majority of desktops | |
36b79d44 | 328 | #include "wx/notebook.h" |
61c083e7 WS |
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) | |
311131d3 WS |
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) | |
d8fd7acb WS |
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 | |
61c083e7 WS |
352 | #endif |
353 | ||
15aad3b9 VZ |
354 | #endif // wxUSE_BOOKCTRL |
355 | ||
356 | #endif // _WX_BOOKCTRL_H_ |