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