]>
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 | ||
15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
16 | #pragma interface "bookctrl.h" | |
17 | #endif | |
18 | ||
19 | // ---------------------------------------------------------------------------- | |
20 | // headers | |
21 | // ---------------------------------------------------------------------------- | |
22 | ||
23 | #include "wx/defs.h" | |
24 | ||
25 | #if wxUSE_BOOKCTRL | |
26 | ||
27 | #include "wx/control.h" | |
28 | #include "wx/dynarray.h" | |
29 | ||
d5d29b8a | 30 | WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow *, wxArrayPages); |
15aad3b9 VZ |
31 | |
32 | class WXDLLEXPORT wxImageList; | |
33 | ||
34 | // ---------------------------------------------------------------------------- | |
61c083e7 | 35 | // wxBookCtrlBase |
15aad3b9 VZ |
36 | // ---------------------------------------------------------------------------- |
37 | ||
61c083e7 | 38 | class WXDLLEXPORT wxBookCtrlBase : public wxControl |
15aad3b9 VZ |
39 | { |
40 | public: | |
41 | // construction | |
42 | // ------------ | |
43 | ||
61c083e7 | 44 | wxBookCtrlBase() |
6463b9f5 JS |
45 | { |
46 | Init(); | |
47 | } | |
15aad3b9 | 48 | |
61c083e7 WS |
49 | wxBookCtrlBase(wxWindow *parent, |
50 | wxWindowID winid, | |
51 | const wxPoint& pos = wxDefaultPosition, | |
52 | const wxSize& size = wxDefaultSize, | |
53 | long style = 0, | |
54 | const wxString& name = wxEmptyString) | |
6463b9f5 JS |
55 | { |
56 | Init(); | |
57 | ||
58 | (void)Create(parent, winid, pos, size, style, name); | |
59 | } | |
15aad3b9 VZ |
60 | |
61 | // quasi ctor | |
62 | bool Create(wxWindow *parent, | |
aa6f64c7 | 63 | wxWindowID winid, |
15aad3b9 VZ |
64 | const wxPoint& pos = wxDefaultPosition, |
65 | const wxSize& size = wxDefaultSize, | |
66 | long style = 0, | |
67 | const wxString& name = wxEmptyString); | |
68 | ||
69 | // dtor | |
61c083e7 | 70 | virtual ~wxBookCtrlBase(); |
15aad3b9 VZ |
71 | |
72 | ||
73 | // accessors | |
74 | // --------- | |
75 | ||
76 | // get number of pages in the dialog | |
77 | virtual size_t GetPageCount() const { return m_pages.size(); } | |
78 | ||
79 | // get the panel which represents the given page | |
80 | virtual wxWindow *GetPage(size_t n) { return m_pages[n]; } | |
81 | ||
21db32c1 VZ |
82 | // get the current page or NULL if none |
83 | wxWindow *GetCurrentPage() const | |
84 | { | |
85 | int n = GetSelection(); | |
86 | return n == wxNOT_FOUND ? NULL | |
61c083e7 | 87 | : wx_const_cast(wxBookCtrlBase *, this)->GetPage(n); |
21db32c1 VZ |
88 | } |
89 | ||
15aad3b9 VZ |
90 | // get the currently selected page or wxNOT_FOUND if none |
91 | virtual int GetSelection() const = 0; | |
92 | ||
93 | // set/get the title of a page | |
94 | virtual bool SetPageText(size_t n, const wxString& strText) = 0; | |
95 | virtual wxString GetPageText(size_t n) const = 0; | |
96 | ||
97 | ||
98 | // image list stuff: each page may have an image associated with it (all | |
99 | // images belong to the same image list) | |
100 | // --------------------------------------------------------------------- | |
101 | ||
102 | // sets the image list to use, it is *not* deleted by the control | |
103 | virtual void SetImageList(wxImageList *imageList); | |
104 | ||
105 | // as SetImageList() but we will delete the image list ourselves | |
106 | void AssignImageList(wxImageList *imageList); | |
107 | ||
108 | // get pointer (may be NULL) to the associated image list | |
109 | wxImageList* GetImageList() const { return m_imageList; } | |
110 | ||
111 | // sets/returns item's image index in the current image list | |
112 | virtual int GetPageImage(size_t n) const = 0; | |
113 | virtual bool SetPageImage(size_t n, int imageId) = 0; | |
114 | ||
115 | ||
116 | // geometry | |
117 | // -------- | |
118 | ||
119 | // resize the notebook so that all pages will have the specified size | |
120 | virtual void SetPageSize(const wxSize& size); | |
121 | ||
122 | // calculate the size of the control from the size of its page | |
123 | virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0; | |
124 | ||
125 | ||
126 | // operations | |
127 | // ---------- | |
128 | ||
129 | // remove one page from the control and delete it | |
130 | virtual bool DeletePage(size_t n); | |
131 | ||
132 | // remove one page from the notebook, without deleting it | |
37144cf0 RD |
133 | virtual bool RemovePage(size_t n) |
134 | { | |
135 | InvalidateBestSize(); | |
136 | return DoRemovePage(n) != NULL; | |
137 | } | |
15aad3b9 VZ |
138 | |
139 | // remove all pages and delete them | |
37144cf0 RD |
140 | virtual bool DeleteAllPages() |
141 | { | |
142 | InvalidateBestSize(); | |
143 | WX_CLEAR_ARRAY(m_pages); | |
144 | return true; | |
145 | } | |
15aad3b9 VZ |
146 | |
147 | // adds a new page to the control | |
148 | virtual bool AddPage(wxWindow *page, | |
149 | const wxString& text, | |
150 | bool bSelect = false, | |
151 | int imageId = -1) | |
152 | { | |
37144cf0 | 153 | InvalidateBestSize(); |
15aad3b9 VZ |
154 | return InsertPage(GetPageCount(), page, text, bSelect, imageId); |
155 | } | |
156 | ||
157 | // the same as AddPage(), but adds the page at the specified position | |
158 | virtual bool InsertPage(size_t n, | |
159 | wxWindow *page, | |
160 | const wxString& text, | |
161 | bool bSelect = false, | |
162 | int imageId = -1) = 0; | |
163 | ||
164 | // set the currently selected page, return the index of the previously | |
165 | // selected one (or -1 on error) | |
166 | // | |
1f30c176 | 167 | // NB: this function will generate PAGE_CHANGING/ED events |
15aad3b9 VZ |
168 | virtual int SetSelection(size_t n) = 0; |
169 | ||
170 | ||
171 | // cycle thru the pages | |
172 | void AdvanceSelection(bool forward = true) | |
173 | { | |
174 | int nPage = GetNextPage(forward); | |
175 | if ( nPage != -1 ) | |
176 | { | |
177 | // cast is safe because of the check above | |
178 | SetSelection((size_t)nPage); | |
179 | } | |
180 | } | |
181 | ||
4cc4e7b6 | 182 | // override some base class virtuals |
cc0bffac RD |
183 | virtual void ApplyParentThemeBackground(const wxColour& bg) |
184 | { SetBackgroundColour(bg); } | |
4cc4e7b6 | 185 | virtual bool ProvidesBackground() const { return true; } |
cc0bffac | 186 | |
15aad3b9 VZ |
187 | protected: |
188 | // remove the page and return a pointer to it | |
189 | virtual wxWindow *DoRemovePage(size_t page) = 0; | |
190 | ||
191 | // our best size is the size which fits all our pages | |
192 | virtual wxSize DoGetBestSize() const; | |
193 | ||
194 | // helper: get the next page wrapping if we reached the end | |
195 | int GetNextPage(bool forward) const; | |
196 | ||
197 | // common part of all ctors | |
198 | void Init(); | |
199 | ||
6457949e RD |
200 | // Always rely on GetBestSize, which will look at all the pages |
201 | virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { } | |
15aad3b9 VZ |
202 | |
203 | // the array of all pages of this control | |
204 | wxArrayPages m_pages; | |
205 | ||
206 | // the associated image list or NULL | |
207 | wxImageList *m_imageList; | |
208 | ||
209 | // true if we must delete m_imageList | |
210 | bool m_ownsImageList; | |
211 | ||
212 | ||
61c083e7 | 213 | DECLARE_NO_COPY_CLASS(wxBookCtrlBase) |
15aad3b9 VZ |
214 | }; |
215 | ||
216 | // ---------------------------------------------------------------------------- | |
61c083e7 | 217 | // wxBookCtrlBaseEvent: page changing events generated by derived classes |
15aad3b9 VZ |
218 | // ---------------------------------------------------------------------------- |
219 | ||
61c083e7 | 220 | class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent |
15aad3b9 VZ |
221 | { |
222 | public: | |
61c083e7 WS |
223 | wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0, |
224 | int nSel = -1, int nOldSel = -1) | |
aa6f64c7 | 225 | : wxNotifyEvent(commandType, winid) |
15aad3b9 VZ |
226 | { |
227 | m_nSel = nSel; | |
228 | m_nOldSel = nOldSel; | |
229 | } | |
230 | ||
231 | // accessors | |
232 | // the currently selected page (-1 if none) | |
233 | int GetSelection() const { return m_nSel; } | |
234 | void SetSelection(int nSel) { m_nSel = nSel; } | |
235 | // the page that was selected before the change (-1 if none) | |
236 | int GetOldSelection() const { return m_nOldSel; } | |
237 | void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; } | |
238 | ||
239 | private: | |
240 | int m_nSel, // currently selected page | |
241 | m_nOldSel; // previously selected page | |
242 | }; | |
243 | ||
61c083e7 | 244 | // make a default book control for given platform |
311131d3 WS |
245 | #if wxUSE_NOTEBOOK |
246 | // dedicated to majority of desktops | |
36b79d44 | 247 | #include "wx/notebook.h" |
61c083e7 WS |
248 | #define wxBookCtrl wxNotebook |
249 | #define wxBookCtrlEvent wxNotebookEvent | |
250 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED | |
251 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING | |
252 | #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn) | |
253 | #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn) | |
1af34108 WS |
254 | #define wxBC_TOP wxNB_TOP |
255 | #define wxBC_BOTTOM wxNB_BOTTOM | |
256 | #define wxBC_LEFT wxNB_LEFT | |
257 | #define wxBC_RIGHT wxNB_RIGHT | |
258 | #define wxBC_DEFAULT wxNB_DEFAULT | |
311131d3 WS |
259 | #else |
260 | // dedicated to Smartphones | |
261 | #include "wx/choicebk.h" | |
262 | #define wxBookCtrl wxChoicebook | |
263 | #define wxBookCtrlEvent wxChoicebookEvent | |
264 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED | |
265 | #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING | |
266 | #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn) | |
267 | #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn) | |
268 | #define wxBC_TOP wxCHB_TOP | |
269 | #define wxBC_BOTTOM wxCHB_BOTTOM | |
270 | #define wxBC_LEFT wxCHB_LEFT | |
271 | #define wxBC_RIGHT wxCHB_RIGHT | |
272 | #define wxBC_DEFAULT wxCHB_DEFAULT | |
61c083e7 WS |
273 | #endif |
274 | ||
15aad3b9 VZ |
275 | #endif // wxUSE_BOOKCTRL |
276 | ||
277 | #endif // _WX_BOOKCTRL_H_ |