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 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
23 #include "wx/control.h"
24 #include "wx/dynarray.h"
26 WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow
*, wxArrayPages
);
28 class WXDLLEXPORT wxImageList
;
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
34 class WXDLLEXPORT wxBookCtrlBase
: public wxControl
45 wxBookCtrlBase(wxWindow
*parent
,
47 const wxPoint
& pos
= wxDefaultPosition
,
48 const wxSize
& size
= wxDefaultSize
,
50 const wxString
& name
= wxEmptyString
)
54 (void)Create(parent
, winid
, pos
, size
, style
, name
);
58 bool Create(wxWindow
*parent
,
60 const wxPoint
& pos
= wxDefaultPosition
,
61 const wxSize
& size
= wxDefaultSize
,
63 const wxString
& name
= wxEmptyString
);
66 virtual ~wxBookCtrlBase();
72 // get number of pages in the dialog
73 virtual size_t GetPageCount() const { return m_pages
.size(); }
75 // get the panel which represents the given page
76 virtual wxWindow
*GetPage(size_t n
) { return m_pages
[n
]; }
78 // get the current page or NULL if none
79 wxWindow
*GetCurrentPage() const
81 int n
= GetSelection();
82 return n
== wxNOT_FOUND
? NULL
83 : wx_const_cast(wxBookCtrlBase
*, this)->GetPage(n
);
86 // get the currently selected page or wxNOT_FOUND if none
87 virtual int GetSelection() const = 0;
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;
94 // image list stuff: each page may have an image associated with it (all
95 // images belong to the same image list)
96 // ---------------------------------------------------------------------
98 // sets the image list to use, it is *not* deleted by the control
99 virtual void SetImageList(wxImageList
*imageList
);
101 // as SetImageList() but we will delete the image list ourselves
102 void AssignImageList(wxImageList
*imageList
);
104 // get pointer (may be NULL) to the associated image list
105 wxImageList
* GetImageList() const { return m_imageList
; }
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;
115 // resize the notebook so that all pages will have the specified size
116 virtual void SetPageSize(const wxSize
& size
);
118 // calculate the size of the control from the size of its page
119 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
) const = 0;
125 // remove one page from the control and delete it
126 virtual bool DeletePage(size_t n
);
128 // remove one page from the notebook, without deleting it
129 virtual bool RemovePage(size_t n
)
131 InvalidateBestSize();
132 return DoRemovePage(n
) != NULL
;
135 // remove all pages and delete them
136 virtual bool DeleteAllPages()
138 InvalidateBestSize();
139 WX_CLEAR_ARRAY(m_pages
);
143 // adds a new page to the control
144 virtual bool AddPage(wxWindow
*page
,
145 const wxString
& text
,
146 bool bSelect
= false,
149 InvalidateBestSize();
150 return InsertPage(GetPageCount(), page
, text
, bSelect
, imageId
);
153 // the same as AddPage(), but adds the page at the specified position
154 virtual bool InsertPage(size_t n
,
156 const wxString
& text
,
157 bool bSelect
= false,
158 int imageId
= -1) = 0;
160 // set the currently selected page, return the index of the previously
161 // selected one (or -1 on error)
163 // NB: this function will generate PAGE_CHANGING/ED events
164 virtual int SetSelection(size_t n
) = 0;
167 // cycle thru the pages
168 void AdvanceSelection(bool forward
= true)
170 int nPage
= GetNextPage(forward
);
173 // cast is safe because of the check above
174 SetSelection((size_t)nPage
);
179 // remove the page and return a pointer to it
180 virtual wxWindow
*DoRemovePage(size_t page
) = 0;
182 // our best size is the size which fits all our pages
183 virtual wxSize
DoGetBestSize() const;
185 // helper: get the next page wrapping if we reached the end
186 int GetNextPage(bool forward
) const;
188 // common part of all ctors
191 // Always rely on GetBestSize, which will look at all the pages
192 virtual void SetInitialBestSize(const wxSize
& WXUNUSED(size
)) { }
194 // the array of all pages of this control
195 wxArrayPages m_pages
;
197 // the associated image list or NULL
198 wxImageList
*m_imageList
;
200 // true if we must delete m_imageList
201 bool m_ownsImageList
;
204 DECLARE_NO_COPY_CLASS(wxBookCtrlBase
)
207 // ----------------------------------------------------------------------------
208 // wxBookCtrlBaseEvent: page changing events generated by derived classes
209 // ----------------------------------------------------------------------------
211 class WXDLLEXPORT wxBookCtrlBaseEvent
: public wxNotifyEvent
214 wxBookCtrlBaseEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0,
215 int nSel
= -1, int nOldSel
= -1)
216 : wxNotifyEvent(commandType
, winid
)
223 // the currently selected page (-1 if none)
224 int GetSelection() const { return m_nSel
; }
225 void SetSelection(int nSel
) { m_nSel
= nSel
; }
226 // the page that was selected before the change (-1 if none)
227 int GetOldSelection() const { return m_nOldSel
; }
228 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
231 int m_nSel
, // currently selected page
232 m_nOldSel
; // previously selected page
235 // make a default book control for given platform
237 // dedicated to majority of desktops
238 #include "wx/notebook.h"
239 #define wxBookCtrl wxNotebook
240 #define wxBookCtrlEvent wxNotebookEvent
241 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
242 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
243 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
244 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
245 #define wxBC_TOP wxNB_TOP
246 #define wxBC_BOTTOM wxNB_BOTTOM
247 #define wxBC_LEFT wxNB_LEFT
248 #define wxBC_RIGHT wxNB_RIGHT
249 #define wxBC_DEFAULT wxNB_DEFAULT
251 // dedicated to Smartphones
252 #include "wx/choicebk.h"
253 #define wxBookCtrl wxChoicebook
254 #define wxBookCtrlEvent wxChoicebookEvent
255 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
256 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
257 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
258 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
259 #define wxBC_TOP wxCHB_TOP
260 #define wxBC_BOTTOM wxCHB_BOTTOM
261 #define wxBC_LEFT wxCHB_LEFT
262 #define wxBC_RIGHT wxCHB_RIGHT
263 #define wxBC_DEFAULT wxCHB_DEFAULT
266 #endif // wxUSE_BOOKCTRL
268 #endif // _WX_BOOKCTRL_H_