]> git.saurik.com Git - wxWidgets.git/blame - include/wx/bookctrl.h
set m_encoding in wxCSConv ctor from name
[wxWidgets.git] / include / wx / bookctrl.h
CommitLineData
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
15aad3b9
VZ
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
d5d29b8a 26WX_DEFINE_EXPORTED_ARRAY_PTR(wxWindow *, wxArrayPages);
15aad3b9
VZ
27
28class WXDLLEXPORT wxImageList;
29
30// ----------------------------------------------------------------------------
61c083e7 31// wxBookCtrlBase
15aad3b9
VZ
32// ----------------------------------------------------------------------------
33
61c083e7 34class WXDLLEXPORT wxBookCtrlBase : public wxControl
15aad3b9
VZ
35{
36public:
37 // construction
38 // ------------
39
61c083e7 40 wxBookCtrlBase()
6463b9f5
JS
41 {
42 Init();
43 }
15aad3b9 44
61c083e7
WS
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)
6463b9f5
JS
51 {
52 Init();
53
54 (void)Create(parent, winid, pos, size, style, name);
55 }
15aad3b9
VZ
56
57 // quasi ctor
58 bool Create(wxWindow *parent,
aa6f64c7 59 wxWindowID winid,
15aad3b9
VZ
60 const wxPoint& pos = wxDefaultPosition,
61 const wxSize& size = wxDefaultSize,
62 long style = 0,
63 const wxString& name = wxEmptyString);
64
65 // dtor
61c083e7 66 virtual ~wxBookCtrlBase();
15aad3b9
VZ
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
97c58531
VZ
76 wxWindow *GetPage(size_t n) { return m_pages[n]; }
77 wxWindow *GetPage(size_t n) const { return m_pages[n]; }
15aad3b9 78
21db32c1
VZ
79 // get the current page or NULL if none
80 wxWindow *GetCurrentPage() const
81 {
97c58531
VZ
82 const int n = GetSelection();
83 return n == wxNOT_FOUND ? NULL : GetPage(n);
21db32c1
VZ
84 }
85
15aad3b9
VZ
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
159e6235
WS
121 // get/set size of area between book control area and page area
122 inline unsigned int GetInternalBorder() const
123 {
124 return m_internalBorder;
125 }
126 void SetInternalBorder(unsigned int internalBorder)
127 {
128 m_internalBorder = internalBorder;
129 }
15aad3b9 130
d8fd7acb
WS
131 // returns true if we have wxCHB_TOP or wxCHB_BOTTOM style
132 bool IsVertical() const { return HasFlag(wxBK_BOTTOM | wxBK_TOP); }
133
93bfe545 134 // set/get option to shrink to fit current page
da817fa6
JS
135 void SetFitToCurrentPage(bool fit) { m_fitToCurrentPage = fit; }
136 bool GetFitToCurrentPage() const { return m_fitToCurrentPage; }
93bfe545 137
15aad3b9
VZ
138 // operations
139 // ----------
140
141 // remove one page from the control and delete it
142 virtual bool DeletePage(size_t n);
143
144 // remove one page from the notebook, without deleting it
37144cf0
RD
145 virtual bool RemovePage(size_t n)
146 {
147 InvalidateBestSize();
148 return DoRemovePage(n) != NULL;
149 }
15aad3b9
VZ
150
151 // remove all pages and delete them
37144cf0
RD
152 virtual bool DeleteAllPages()
153 {
154 InvalidateBestSize();
155 WX_CLEAR_ARRAY(m_pages);
156 return true;
157 }
15aad3b9
VZ
158
159 // adds a new page to the control
160 virtual bool AddPage(wxWindow *page,
161 const wxString& text,
162 bool bSelect = false,
163 int imageId = -1)
164 {
37144cf0 165 InvalidateBestSize();
15aad3b9
VZ
166 return InsertPage(GetPageCount(), page, text, bSelect, imageId);
167 }
168
169 // the same as AddPage(), but adds the page at the specified position
170 virtual bool InsertPage(size_t n,
171 wxWindow *page,
172 const wxString& text,
173 bool bSelect = false,
174 int imageId = -1) = 0;
175
176 // set the currently selected page, return the index of the previously
177 // selected one (or -1 on error)
178 //
1f30c176 179 // NB: this function will generate PAGE_CHANGING/ED events
15aad3b9
VZ
180 virtual int SetSelection(size_t n) = 0;
181
182
183 // cycle thru the pages
184 void AdvanceSelection(bool forward = true)
185 {
186 int nPage = GetNextPage(forward);
187 if ( nPage != -1 )
188 {
189 // cast is safe because of the check above
190 SetSelection((size_t)nPage);
191 }
192 }
193
194protected:
eca15c0d
VZ
195 // Should we accept NULL page pointers in Add/InsertPage()?
196 //
197 // Default is no but derived classes may override it if they can treat NULL
198 // pages in some sensible way (e.g. wxTreebook overrides this to allow
199 // having nodes without any associated page)
200 virtual bool AllowNullPage() const { return false; }
201
15aad3b9
VZ
202 // remove the page and return a pointer to it
203 virtual wxWindow *DoRemovePage(size_t page) = 0;
204
205 // our best size is the size which fits all our pages
206 virtual wxSize DoGetBestSize() const;
207
208 // helper: get the next page wrapping if we reached the end
209 int GetNextPage(bool forward) const;
210
6457949e
RD
211 // Always rely on GetBestSize, which will look at all the pages
212 virtual void SetInitialBestSize(const wxSize& WXUNUSED(size)) { }
15aad3b9 213
233387bd
JS
214 // Lay out controls
215 void DoSize();
216
15aad3b9
VZ
217 // the array of all pages of this control
218 wxArrayPages m_pages;
219
220 // the associated image list or NULL
221 wxImageList *m_imageList;
222
223 // true if we must delete m_imageList
224 bool m_ownsImageList;
225
d8fd7acb
WS
226 // get the page area
227 wxRect GetPageRect() const;
228
229 // event handlers
230 virtual wxSize GetControllerSize() const;
231 void OnSize(wxSizeEvent& event);
232
233 // controller buddy if available, NULL otherwise (usually for native book controls like wxNotebook)
234 wxControl *m_bookctrl;
235
93bfe545 236 // Whether to shrink to fit current page
da817fa6 237 bool m_fitToCurrentPage;
93bfe545 238
159e6235
WS
239private:
240
241 // common part of all ctors
242 void Init();
243
244 // internal border
245 unsigned int m_internalBorder;
15aad3b9 246
d8fd7acb 247 DECLARE_ABSTRACT_CLASS(wxBookCtrlBase)
61c083e7 248 DECLARE_NO_COPY_CLASS(wxBookCtrlBase)
d8fd7acb 249 DECLARE_EVENT_TABLE()
15aad3b9
VZ
250};
251
252// ----------------------------------------------------------------------------
61c083e7 253// wxBookCtrlBaseEvent: page changing events generated by derived classes
15aad3b9
VZ
254// ----------------------------------------------------------------------------
255
61c083e7 256class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent
15aad3b9
VZ
257{
258public:
61c083e7
WS
259 wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
260 int nSel = -1, int nOldSel = -1)
aa6f64c7 261 : wxNotifyEvent(commandType, winid)
b2f8e75a
VZ
262 {
263 m_nSel = nSel;
264 m_nOldSel = nOldSel;
265 }
266
267 wxBookCtrlBaseEvent(const wxBookCtrlBaseEvent& event)
268 : wxNotifyEvent(event)
269 {
270 m_nSel = event.m_nSel;
271 m_nOldSel = event.m_nOldSel;
272 }
15aad3b9
VZ
273
274 // accessors
275 // the currently selected page (-1 if none)
276 int GetSelection() const { return m_nSel; }
277 void SetSelection(int nSel) { m_nSel = nSel; }
278 // the page that was selected before the change (-1 if none)
279 int GetOldSelection() const { return m_nOldSel; }
280 void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
281
282private:
283 int m_nSel, // currently selected page
284 m_nOldSel; // previously selected page
285};
286
61c083e7 287// make a default book control for given platform
311131d3
WS
288#if wxUSE_NOTEBOOK
289 // dedicated to majority of desktops
36b79d44 290 #include "wx/notebook.h"
61c083e7
WS
291 #define wxBookCtrl wxNotebook
292 #define wxBookCtrlEvent wxNotebookEvent
293 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
294 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
295 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
296 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
311131d3
WS
297#else
298 // dedicated to Smartphones
299 #include "wx/choicebk.h"
300 #define wxBookCtrl wxChoicebook
301 #define wxBookCtrlEvent wxChoicebookEvent
302 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
303 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
304 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
305 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
d8fd7acb
WS
306#endif
307
308#if WXWIN_COMPATIBILITY_2_6
309 #define wxBC_TOP wxBK_TOP
310 #define wxBC_BOTTOM wxBK_BOTTOM
311 #define wxBC_LEFT wxBK_LEFT
312 #define wxBC_RIGHT wxBK_RIGHT
313 #define wxBC_DEFAULT wxBK_DEFAULT
61c083e7
WS
314#endif
315
15aad3b9
VZ
316#endif // wxUSE_BOOKCTRL
317
318#endif // _WX_BOOKCTRL_H_