]>
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 WS |
121 | // get/set size of area between book control area and page area |
122 | inline unsigned int GetInternalBorder() const | |
123 | { | |
124 | return m_internalBorder; | |
125 | } | |
126 | void SetInternalBorder(unsigned int internalBorder) | |
127 | { | |
128 | m_internalBorder = internalBorder; | |
129 | } | |
15aad3b9 VZ |
130 | |
131 | // operations | |
132 | // ---------- | |
133 | ||
134 | // remove one page from the control and delete it | |
135 | virtual bool DeletePage(size_t n); | |
136 | ||
137 | // remove one page from the notebook, without deleting it | |
37144cf0 RD |
138 | virtual bool RemovePage(size_t n) |
139 | { | |
140 | InvalidateBestSize(); | |
141 | return DoRemovePage(n) != NULL; | |
142 | } | |
15aad3b9 VZ |
143 | |
144 | // remove all pages and delete them | |
37144cf0 RD |
145 | virtual bool DeleteAllPages() |
146 | { | |
147 | InvalidateBestSize(); | |
148 | WX_CLEAR_ARRAY(m_pages); | |
149 | return true; | |
150 | } | |
15aad3b9 VZ |
151 | |
152 | // adds a new page to the control | |
153 | virtual bool AddPage(wxWindow *page, | |
154 | const wxString& text, | |
155 | bool bSelect = false, | |
156 | int imageId = -1) | |
157 | { | |
37144cf0 | 158 | InvalidateBestSize(); |
15aad3b9 VZ |
159 | return InsertPage(GetPageCount(), page, text, bSelect, imageId); |
160 | } | |
161 | ||
162 | // the same as AddPage(), but adds the page at the specified position | |
163 | virtual bool InsertPage(size_t n, | |
164 | wxWindow *page, | |
165 | const wxString& text, | |
166 | bool bSelect = false, | |
167 | int imageId = -1) = 0; | |
168 | ||
169 | // set the currently selected page, return the index of the previously | |
170 | // selected one (or -1 on error) | |
171 | // | |
1f30c176 | 172 | // NB: this function will generate PAGE_CHANGING/ED events |
15aad3b9 VZ |
173 | virtual int SetSelection(size_t n) = 0; |
174 | ||
175 | ||
176 | // cycle thru the pages | |
177 | void AdvanceSelection(bool forward = true) | |
178 | { | |
179 | int nPage = GetNextPage(forward); | |
180 | if ( nPage != -1 ) | |
181 | { | |
182 | // cast is safe because of the check above | |
183 | SetSelection((size_t)nPage); | |
184 | } | |
185 | } | |
186 | ||
187 | protected: | |
eca15c0d VZ |
188 | // Should we accept NULL page pointers in Add/InsertPage()? |
189 | // | |
190 | // Default is no but derived classes may override it if they can treat NULL | |
191 | // pages in some sensible way (e.g. wxTreebook overrides this to allow | |
192 | // having nodes without any associated page) | |
193 | virtual bool AllowNullPage() const { return false; } | |
194 | ||
15aad3b9 VZ |
195 | // remove the page and return a pointer to it |
196 | virtual wxWindow *DoRemovePage(size_t page) = 0; | |
197 | ||
198 | // our best size is the size which fits all our pages | |
199 | virtual wxSize DoGetBestSize() const; | |
200 | ||
201 | // helper: get the next page wrapping if we reached the end | |
202 | int GetNextPage(bool forward) const; | |
203 | ||
6457949e RD |
204 | // Always rely on GetBestSize, which will look at all the pages |
205 | virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { } | |
15aad3b9 VZ |
206 | |
207 | // the array of all pages of this control | |
208 | wxArrayPages m_pages; | |
209 | ||
210 | // the associated image list or NULL | |
211 | wxImageList *m_imageList; | |
212 | ||
213 | // true if we must delete m_imageList | |
214 | bool m_ownsImageList; | |
215 | ||
159e6235 WS |
216 | private: |
217 | ||
218 | // common part of all ctors | |
219 | void Init(); | |
220 | ||
221 | // internal border | |
222 | unsigned int m_internalBorder; | |
15aad3b9 | 223 | |
61c083e7 | 224 | DECLARE_NO_COPY_CLASS(wxBookCtrlBase) |
15aad3b9 VZ |
225 | }; |
226 | ||
227 | // ---------------------------------------------------------------------------- | |
61c083e7 | 228 | // wxBookCtrlBaseEvent: page changing events generated by derived classes |
15aad3b9 VZ |
229 | // ---------------------------------------------------------------------------- |
230 | ||
61c083e7 | 231 | class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent |
15aad3b9 VZ |
232 | { |
233 | public: | |
61c083e7 WS |
234 | wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0, |
235 | int nSel = -1, int nOldSel = -1) | |
aa6f64c7 | 236 | : wxNotifyEvent(commandType, winid) |
15aad3b9 VZ |
237 | { |
238 | m_nSel = nSel; | |
239 | m_nOldSel = nOldSel; | |
240 | } | |
241 | ||
242 | // accessors | |
243 | // the currently selected page (-1 if none) | |
244 | int GetSelection() const { return m_nSel; } | |
245 | void SetSelection(int nSel) { m_nSel = nSel; } | |
246 | // the page that was selected before the change (-1 if none) | |
247 | int GetOldSelection() const { return m_nOldSel; } | |
248 | void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; } | |
249 | ||
250 | private: | |
251 | int m_nSel, // currently selected page | |
252 | m_nOldSel; // previously selected page | |
253 | }; | |
254 | ||
61c083e7 | 255 | // make a default book control for given platform |
311131d3 WS |
256 | #if wxUSE_NOTEBOOK |
257 | // dedicated to majority of desktops | |
36b79d44 | 258 | #include "wx/notebook.h" |
61c083e7 WS |
259 | #define wxBookCtrl wxNotebook |
260 | #define wxBookCtrlEvent wxNotebookEvent | |
261 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED | |
262 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING | |
263 | #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn) | |
264 | #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn) | |
1af34108 WS |
265 | #define wxBC_TOP wxNB_TOP |
266 | #define wxBC_BOTTOM wxNB_BOTTOM | |
267 | #define wxBC_LEFT wxNB_LEFT | |
268 | #define wxBC_RIGHT wxNB_RIGHT | |
269 | #define wxBC_DEFAULT wxNB_DEFAULT | |
311131d3 WS |
270 | #else |
271 | // dedicated to Smartphones | |
272 | #include "wx/choicebk.h" | |
273 | #define wxBookCtrl wxChoicebook | |
274 | #define wxBookCtrlEvent wxChoicebookEvent | |
275 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED | |
276 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING | |
277 | #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn) | |
278 | #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn) | |
279 | #define wxBC_TOP wxCHB_TOP | |
280 | #define wxBC_BOTTOM wxCHB_BOTTOM | |
281 | #define wxBC_LEFT wxCHB_LEFT | |
282 | #define wxBC_RIGHT wxCHB_RIGHT | |
283 | #define wxBC_DEFAULT wxCHB_DEFAULT | |
61c083e7 WS |
284 | #endif |
285 | ||
15aad3b9 VZ |
286 | #endif // wxUSE_BOOKCTRL |
287 | ||
288 | #endif // _WX_BOOKCTRL_H_ |