1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxBookCtrlBase: common base class for wxList/Tree/Notebook
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_BOOKCTRL_H_
13 #define _WX_BOOKCTRL_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "bookctrl.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
27 #include "wx/control.h"
28 #include "wx/dynarray.h"
30 WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow
*, wxArrayPages
);
32 class WXDLLEXPORT wxImageList
;
34 // ----------------------------------------------------------------------------
36 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxBookCtrlBase
: public wxControl
49 wxBookCtrlBase(wxWindow
*parent
,
51 const wxPoint
& pos
= wxDefaultPosition
,
52 const wxSize
& size
= wxDefaultSize
,
54 const wxString
& name
= wxEmptyString
)
58 (void)Create(parent
, winid
, pos
, size
, style
, name
);
62 bool Create(wxWindow
*parent
,
64 const wxPoint
& pos
= wxDefaultPosition
,
65 const wxSize
& size
= wxDefaultSize
,
67 const wxString
& name
= wxEmptyString
);
70 virtual ~wxBookCtrlBase();
76 // get number of pages in the dialog
77 virtual size_t GetPageCount() const { return m_pages
.size(); }
79 // get the panel which represents the given page
80 virtual wxWindow
*GetPage(size_t n
) { return m_pages
[n
]; }
82 // get the current page or NULL if none
83 wxWindow
*GetCurrentPage() const
85 int n
= GetSelection();
86 return n
== wxNOT_FOUND
? NULL
87 : wx_const_cast(wxBookCtrlBase
*, this)->GetPage(n
);
90 // get the currently selected page or wxNOT_FOUND if none
91 virtual int GetSelection() const = 0;
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;
98 // image list stuff: each page may have an image associated with it (all
99 // images belong to the same image list)
100 // ---------------------------------------------------------------------
102 // sets the image list to use, it is *not* deleted by the control
103 virtual void SetImageList(wxImageList
*imageList
);
105 // as SetImageList() but we will delete the image list ourselves
106 void AssignImageList(wxImageList
*imageList
);
108 // get pointer (may be NULL) to the associated image list
109 wxImageList
* GetImageList() const { return m_imageList
; }
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;
119 // resize the notebook so that all pages will have the specified size
120 virtual void SetPageSize(const wxSize
& size
);
122 // calculate the size of the control from the size of its page
123 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
) const = 0;
129 // remove one page from the control and delete it
130 virtual bool DeletePage(size_t n
);
132 // remove one page from the notebook, without deleting it
133 virtual bool RemovePage(size_t n
)
135 InvalidateBestSize();
136 return DoRemovePage(n
) != NULL
;
139 // remove all pages and delete them
140 virtual bool DeleteAllPages()
142 InvalidateBestSize();
143 WX_CLEAR_ARRAY(m_pages
);
147 // adds a new page to the control
148 virtual bool AddPage(wxWindow
*page
,
149 const wxString
& text
,
150 bool bSelect
= false,
153 InvalidateBestSize();
154 return InsertPage(GetPageCount(), page
, text
, bSelect
, imageId
);
157 // the same as AddPage(), but adds the page at the specified position
158 virtual bool InsertPage(size_t n
,
160 const wxString
& text
,
161 bool bSelect
= false,
162 int imageId
= -1) = 0;
164 // set the currently selected page, return the index of the previously
165 // selected one (or -1 on error)
167 // NB: this function will generate PAGE_CHANGING/ED events
168 virtual int SetSelection(size_t n
) = 0;
171 // cycle thru the pages
172 void AdvanceSelection(bool forward
= true)
174 int nPage
= GetNextPage(forward
);
177 // cast is safe because of the check above
178 SetSelection((size_t)nPage
);
183 // remove the page and return a pointer to it
184 virtual wxWindow
*DoRemovePage(size_t page
) = 0;
186 // our best size is the size which fits all our pages
187 virtual wxSize
DoGetBestSize() const;
189 // helper: get the next page wrapping if we reached the end
190 int GetNextPage(bool forward
) const;
192 // common part of all ctors
195 // Always rely on GetBestSize, which will look at all the pages
196 virtual void SetInitialBestSize(const wxSize
& WXUNUSED(size
)) { }
198 // the array of all pages of this control
199 wxArrayPages m_pages
;
201 // the associated image list or NULL
202 wxImageList
*m_imageList
;
204 // true if we must delete m_imageList
205 bool m_ownsImageList
;
208 DECLARE_NO_COPY_CLASS(wxBookCtrlBase
)
211 // ----------------------------------------------------------------------------
212 // wxBookCtrlBaseEvent: page changing events generated by derived classes
213 // ----------------------------------------------------------------------------
215 class WXDLLEXPORT wxBookCtrlBaseEvent
: public wxNotifyEvent
218 wxBookCtrlBaseEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0,
219 int nSel
= -1, int nOldSel
= -1)
220 : wxNotifyEvent(commandType
, winid
)
227 // the currently selected page (-1 if none)
228 int GetSelection() const { return m_nSel
; }
229 void SetSelection(int nSel
) { m_nSel
= nSel
; }
230 // the page that was selected before the change (-1 if none)
231 int GetOldSelection() const { return m_nOldSel
; }
232 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
235 int m_nSel
, // currently selected page
236 m_nOldSel
; // previously selected page
239 // make a default book control for given platform
241 // dedicated to majority of desktops
242 #include "wx/notebook.h"
243 #define wxBookCtrl wxNotebook
244 #define wxBookCtrlEvent wxNotebookEvent
245 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
246 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
247 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
248 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
249 #define wxBC_TOP wxNB_TOP
250 #define wxBC_BOTTOM wxNB_BOTTOM
251 #define wxBC_LEFT wxNB_LEFT
252 #define wxBC_RIGHT wxNB_RIGHT
253 #define wxBC_DEFAULT wxNB_DEFAULT
255 // dedicated to Smartphones
256 #include "wx/choicebk.h"
257 #define wxBookCtrl wxChoicebook
258 #define wxBookCtrlEvent wxChoicebookEvent
259 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
260 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
261 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
262 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
263 #define wxBC_TOP wxCHB_TOP
264 #define wxBC_BOTTOM wxCHB_BOTTOM
265 #define wxBC_LEFT wxCHB_LEFT
266 #define wxBC_RIGHT wxCHB_RIGHT
267 #define wxBC_DEFAULT wxCHB_DEFAULT
270 #endif // wxUSE_BOOKCTRL
272 #endif // _WX_BOOKCTRL_H_