]> git.saurik.com Git - wxWidgets.git/blob - include/wx/bookctrl.h
removed duplicated members which have been moved to wxTreeCtrlBase
[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 // wxBookCtrlBase
32 // ----------------------------------------------------------------------------
33
34 class WXDLLEXPORT wxBookCtrlBase : public wxControl
35 {
36 public:
37 // construction
38 // ------------
39
40 wxBookCtrlBase()
41 {
42 Init();
43 }
44
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)
51 {
52 Init();
53
54 (void)Create(parent, winid, pos, size, style, name);
55 }
56
57 // quasi ctor
58 bool Create(wxWindow *parent,
59 wxWindowID winid,
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = 0,
63 const wxString& name = wxEmptyString);
64
65 // dtor
66 virtual ~wxBookCtrlBase();
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
76 wxWindow *GetPage(size_t n) { return m_pages[n]; }
77 wxWindow *GetPage(size_t n) const { return m_pages[n]; }
78
79 // get the current page or NULL if none
80 wxWindow *GetCurrentPage() const
81 {
82 const int n = GetSelection();
83 return n == wxNOT_FOUND ? NULL : GetPage(n);
84 }
85
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
121
122 // operations
123 // ----------
124
125 // remove one page from the control and delete it
126 virtual bool DeletePage(size_t n);
127
128 // remove one page from the notebook, without deleting it
129 virtual bool RemovePage(size_t n)
130 {
131 InvalidateBestSize();
132 return DoRemovePage(n) != NULL;
133 }
134
135 // remove all pages and delete them
136 virtual bool DeleteAllPages()
137 {
138 InvalidateBestSize();
139 WX_CLEAR_ARRAY(m_pages);
140 return true;
141 }
142
143 // adds a new page to the control
144 virtual bool AddPage(wxWindow *page,
145 const wxString& text,
146 bool bSelect = false,
147 int imageId = -1)
148 {
149 InvalidateBestSize();
150 return InsertPage(GetPageCount(), page, text, bSelect, imageId);
151 }
152
153 // the same as AddPage(), but adds the page at the specified position
154 virtual bool InsertPage(size_t n,
155 wxWindow *page,
156 const wxString& text,
157 bool bSelect = false,
158 int imageId = -1) = 0;
159
160 // set the currently selected page, return the index of the previously
161 // selected one (or -1 on error)
162 //
163 // NB: this function will generate PAGE_CHANGING/ED events
164 virtual int SetSelection(size_t n) = 0;
165
166
167 // cycle thru the pages
168 void AdvanceSelection(bool forward = true)
169 {
170 int nPage = GetNextPage(forward);
171 if ( nPage != -1 )
172 {
173 // cast is safe because of the check above
174 SetSelection((size_t)nPage);
175 }
176 }
177
178 protected:
179 // Should we accept NULL page pointers in Add/InsertPage()?
180 //
181 // Default is no but derived classes may override it if they can treat NULL
182 // pages in some sensible way (e.g. wxTreebook overrides this to allow
183 // having nodes without any associated page)
184 virtual bool AllowNullPage() const { return false; }
185
186 // remove the page and return a pointer to it
187 virtual wxWindow *DoRemovePage(size_t page) = 0;
188
189 // our best size is the size which fits all our pages
190 virtual wxSize DoGetBestSize() const;
191
192 // helper: get the next page wrapping if we reached the end
193 int GetNextPage(bool forward) const;
194
195 // common part of all ctors
196 void Init();
197
198 // Always rely on GetBestSize, which will look at all the pages
199 virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
200
201
202 // the array of all pages of this control
203 wxArrayPages m_pages;
204
205 // the associated image list or NULL
206 wxImageList *m_imageList;
207
208 // true if we must delete m_imageList
209 bool m_ownsImageList;
210
211
212 DECLARE_NO_COPY_CLASS(wxBookCtrlBase)
213 };
214
215 // ----------------------------------------------------------------------------
216 // wxBookCtrlBaseEvent: page changing events generated by derived classes
217 // ----------------------------------------------------------------------------
218
219 class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent
220 {
221 public:
222 wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
223 int nSel = -1, int nOldSel = -1)
224 : wxNotifyEvent(commandType, winid)
225 {
226 m_nSel = nSel;
227 m_nOldSel = nOldSel;
228 }
229
230 // accessors
231 // the currently selected page (-1 if none)
232 int GetSelection() const { return m_nSel; }
233 void SetSelection(int nSel) { m_nSel = nSel; }
234 // the page that was selected before the change (-1 if none)
235 int GetOldSelection() const { return m_nOldSel; }
236 void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
237
238 private:
239 int m_nSel, // currently selected page
240 m_nOldSel; // previously selected page
241 };
242
243 // make a default book control for given platform
244 #if wxUSE_NOTEBOOK
245 // dedicated to majority of desktops
246 #include "wx/notebook.h"
247 #define wxBookCtrl wxNotebook
248 #define wxBookCtrlEvent wxNotebookEvent
249 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
250 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
251 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
252 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
253 #define wxBC_TOP wxNB_TOP
254 #define wxBC_BOTTOM wxNB_BOTTOM
255 #define wxBC_LEFT wxNB_LEFT
256 #define wxBC_RIGHT wxNB_RIGHT
257 #define wxBC_DEFAULT wxNB_DEFAULT
258 #else
259 // dedicated to Smartphones
260 #include "wx/choicebk.h"
261 #define wxBookCtrl wxChoicebook
262 #define wxBookCtrlEvent wxChoicebookEvent
263 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
264 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
265 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
266 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
267 #define wxBC_TOP wxCHB_TOP
268 #define wxBC_BOTTOM wxCHB_BOTTOM
269 #define wxBC_LEFT wxCHB_LEFT
270 #define wxBC_RIGHT wxCHB_RIGHT
271 #define wxBC_DEFAULT wxCHB_DEFAULT
272 #endif
273
274 #endif // wxUSE_BOOKCTRL
275
276 #endif // _WX_BOOKCTRL_H_