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 wxWindow
*GetPage(size_t n
) { return m_pages
[n
]; }
77 wxWindow
*GetPage(size_t n
) const { return m_pages
[n
]; }
79 // get the current page or NULL if none
80 wxWindow
*GetCurrentPage() const
82 const int n
= GetSelection();
83 return n
== wxNOT_FOUND
? NULL
: 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;
121 // get/set size of area between book control area and page area
122 unsigned int GetInternalBorder() const { return m_internalBorder
; }
123 void SetInternalBorder(unsigned int border
) { m_internalBorder
= border
; }
125 // Sets/gets the margin around the controller
126 void SetControlMargin(int margin
) { m_controlMargin
= margin
; }
127 int GetControlMargin() const { return m_controlMargin
; }
129 // returns true if we have wxBK_TOP or wxBK_BOTTOM style
130 bool IsVertical() const { return HasFlag(wxBK_BOTTOM
| wxBK_TOP
); }
132 // set/get option to shrink to fit current page
133 void SetFitToCurrentPage(bool fit
) { m_fitToCurrentPage
= fit
; }
134 bool GetFitToCurrentPage() const { return m_fitToCurrentPage
; }
136 // returns the sizer containing the control, if any
137 wxSizer
* GetControlSizer() const { return m_controlSizer
; }
142 // remove one page from the control and delete it
143 virtual bool DeletePage(size_t n
);
145 // remove one page from the notebook, without deleting it
146 virtual bool RemovePage(size_t n
)
148 InvalidateBestSize();
149 return DoRemovePage(n
) != NULL
;
152 // remove all pages and delete them
153 virtual bool DeleteAllPages()
155 InvalidateBestSize();
156 WX_CLEAR_ARRAY(m_pages
);
160 // adds a new page to the control
161 virtual bool AddPage(wxWindow
*page
,
162 const wxString
& text
,
163 bool bSelect
= false,
166 InvalidateBestSize();
167 return InsertPage(GetPageCount(), page
, text
, bSelect
, imageId
);
170 // the same as AddPage(), but adds the page at the specified position
171 virtual bool InsertPage(size_t n
,
173 const wxString
& text
,
174 bool bSelect
= false,
175 int imageId
= -1) = 0;
177 // set the currently selected page, return the index of the previously
178 // selected one (or -1 on error)
180 // NB: this function will generate PAGE_CHANGING/ED events
181 virtual int SetSelection(size_t n
) = 0;
184 // cycle thru the pages
185 void AdvanceSelection(bool forward
= true)
187 int nPage
= GetNextPage(forward
);
190 // cast is safe because of the check above
191 SetSelection((size_t)nPage
);
195 // hit test: returns which page is hit and, optionally, where (icon, label)
196 virtual int HitTest(const wxPoint
& WXUNUSED(pt
),
197 long * WXUNUSED(flags
) = NULL
) const
203 // Should we accept NULL page pointers in Add/InsertPage()?
205 // Default is no but derived classes may override it if they can treat NULL
206 // pages in some sensible way (e.g. wxTreebook overrides this to allow
207 // having nodes without any associated page)
208 virtual bool AllowNullPage() const { return false; }
210 // remove the page and return a pointer to it
211 virtual wxWindow
*DoRemovePage(size_t page
) = 0;
213 // our best size is the size which fits all our pages
214 virtual wxSize
DoGetBestSize() const;
216 // helper: get the next page wrapping if we reached the end
217 int GetNextPage(bool forward
) const;
219 // Always rely on GetBestSize, which will look at all the pages
220 virtual void SetInitialBestSize(const wxSize
& WXUNUSED(size
)) { }
226 // Show the help for the corresponding page
227 void OnHelp(wxHelpEvent
& event
);
231 // the array of all pages of this control
232 wxArrayPages m_pages
;
234 // the associated image list or NULL
235 wxImageList
*m_imageList
;
237 // true if we must delete m_imageList
238 bool m_ownsImageList
;
241 wxRect
GetPageRect() const;
244 virtual wxSize
GetControllerSize() const;
245 void OnSize(wxSizeEvent
& event
);
247 // controller buddy if available, NULL otherwise (usually for native book controls like wxNotebook)
248 wxControl
*m_bookctrl
;
250 // Whether to shrink to fit current page
251 bool m_fitToCurrentPage
;
253 // the sizer containing the choice control
254 wxSizer
* m_controlSizer
;
256 // the margin around the choice control
261 // common part of all ctors
265 unsigned int m_internalBorder
;
267 DECLARE_ABSTRACT_CLASS(wxBookCtrlBase
)
268 DECLARE_NO_COPY_CLASS(wxBookCtrlBase
)
269 DECLARE_EVENT_TABLE()
272 // ----------------------------------------------------------------------------
273 // wxBookCtrlBaseEvent: page changing events generated by derived classes
274 // ----------------------------------------------------------------------------
276 class WXDLLEXPORT wxBookCtrlBaseEvent
: public wxNotifyEvent
279 wxBookCtrlBaseEvent(wxEventType commandType
= wxEVT_NULL
, int winid
= 0,
280 int nSel
= -1, int nOldSel
= -1)
281 : wxNotifyEvent(commandType
, winid
)
287 wxBookCtrlBaseEvent(const wxBookCtrlBaseEvent
& event
)
288 : wxNotifyEvent(event
)
290 m_nSel
= event
.m_nSel
;
291 m_nOldSel
= event
.m_nOldSel
;
295 // the currently selected page (-1 if none)
296 int GetSelection() const { return m_nSel
; }
297 void SetSelection(int nSel
) { m_nSel
= nSel
; }
298 // the page that was selected before the change (-1 if none)
299 int GetOldSelection() const { return m_nOldSel
; }
300 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
303 int m_nSel
, // currently selected page
304 m_nOldSel
; // previously selected page
307 // make a default book control for given platform
309 // dedicated to majority of desktops
310 #include "wx/notebook.h"
311 #define wxBookCtrl wxNotebook
312 #define wxBookCtrlEvent wxNotebookEvent
313 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
314 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
315 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
316 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
318 // dedicated to Smartphones
319 #include "wx/choicebk.h"
320 #define wxBookCtrl wxChoicebook
321 #define wxBookCtrlEvent wxChoicebookEvent
322 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
323 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
324 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
325 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
328 #if WXWIN_COMPATIBILITY_2_6
329 #define wxBC_TOP wxBK_TOP
330 #define wxBC_BOTTOM wxBK_BOTTOM
331 #define wxBC_LEFT wxBK_LEFT
332 #define wxBC_RIGHT wxBK_RIGHT
333 #define wxBC_DEFAULT wxBK_DEFAULT
336 #endif // wxUSE_BOOKCTRL
338 #endif // _WX_BOOKCTRL_H_