/[pcsx2_0.9.7]/trunk/3rdparty/wxWidgets/include/wx/bookctrl.h
ViewVC logotype

Contents of /trunk/3rdparty/wxWidgets/include/wx/bookctrl.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 10 - (show annotations) (download)
Mon Sep 6 11:40:06 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 14113 byte(s)
exported r3113 from ./upstream/trunk
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: bookctrl.h 49563 2007-10-31 20:46:21Z VZ $
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 WXDLLIMPEXP_FWD_CORE wxImageList;
29 class WXDLLIMPEXP_FWD_CORE wxBookCtrlBaseEvent;
30
31 // ----------------------------------------------------------------------------
32 // constants
33 // ----------------------------------------------------------------------------
34
35 // wxBookCtrl hit results
36 enum
37 {
38 wxBK_HITTEST_NOWHERE = 1, // not on tab
39 wxBK_HITTEST_ONICON = 2, // on icon
40 wxBK_HITTEST_ONLABEL = 4, // on label
41 wxBK_HITTEST_ONITEM = wxBK_HITTEST_ONICON | wxBK_HITTEST_ONLABEL,
42 wxBK_HITTEST_ONPAGE = 8 // not on tab control, but over the selected page
43 };
44
45 // wxBookCtrl flags (common for wxNotebook, wxListbook, wxChoicebook, wxTreebook)
46 #define wxBK_DEFAULT 0x0000
47 #define wxBK_TOP 0x0010
48 #define wxBK_BOTTOM 0x0020
49 #define wxBK_LEFT 0x0040
50 #define wxBK_RIGHT 0x0080
51 #define wxBK_ALIGN_MASK (wxBK_TOP | wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT)
52
53 // ----------------------------------------------------------------------------
54 // wxBookCtrlBase
55 // ----------------------------------------------------------------------------
56
57 class WXDLLEXPORT wxBookCtrlBase : public wxControl
58 {
59 public:
60 // construction
61 // ------------
62
63 wxBookCtrlBase()
64 {
65 Init();
66 }
67
68 wxBookCtrlBase(wxWindow *parent,
69 wxWindowID winid,
70 const wxPoint& pos = wxDefaultPosition,
71 const wxSize& size = wxDefaultSize,
72 long style = 0,
73 const wxString& name = wxEmptyString)
74 {
75 Init();
76
77 (void)Create(parent, winid, pos, size, style, name);
78 }
79
80 // quasi ctor
81 bool Create(wxWindow *parent,
82 wxWindowID winid,
83 const wxPoint& pos = wxDefaultPosition,
84 const wxSize& size = wxDefaultSize,
85 long style = 0,
86 const wxString& name = wxEmptyString);
87
88 // dtor
89 virtual ~wxBookCtrlBase();
90
91
92 // accessors
93 // ---------
94
95 // get number of pages in the dialog
96 virtual size_t GetPageCount() const { return m_pages.size(); }
97
98 // get the panel which represents the given page
99 wxWindow *GetPage(size_t n) { return m_pages[n]; }
100 wxWindow *GetPage(size_t n) const { return m_pages[n]; }
101
102 // get the current page or NULL if none
103 wxWindow *GetCurrentPage() const
104 {
105 const int n = GetSelection();
106 return n == wxNOT_FOUND ? NULL : GetPage(n);
107 }
108
109 // get the currently selected page or wxNOT_FOUND if none
110 virtual int GetSelection() const = 0;
111
112 // set/get the title of a page
113 virtual bool SetPageText(size_t n, const wxString& strText) = 0;
114 virtual wxString GetPageText(size_t n) const = 0;
115
116
117 // image list stuff: each page may have an image associated with it (all
118 // images belong to the same image list)
119 // ---------------------------------------------------------------------
120
121 // sets the image list to use, it is *not* deleted by the control
122 virtual void SetImageList(wxImageList *imageList);
123
124 // as SetImageList() but we will delete the image list ourselves
125 void AssignImageList(wxImageList *imageList);
126
127 // get pointer (may be NULL) to the associated image list
128 wxImageList* GetImageList() const { return m_imageList; }
129
130 // sets/returns item's image index in the current image list
131 virtual int GetPageImage(size_t n) const = 0;
132 virtual bool SetPageImage(size_t n, int imageId) = 0;
133
134
135 // geometry
136 // --------
137
138 // resize the notebook so that all pages will have the specified size
139 virtual void SetPageSize(const wxSize& size);
140
141 // calculate the size of the control from the size of its page
142 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const = 0;
143
144 // get/set size of area between book control area and page area
145 unsigned int GetInternalBorder() const { return m_internalBorder; }
146 void SetInternalBorder(unsigned int border) { m_internalBorder = border; }
147
148 // Sets/gets the margin around the controller
149 void SetControlMargin(int margin) { m_controlMargin = margin; }
150 int GetControlMargin() const { return m_controlMargin; }
151
152 // returns true if we have wxBK_TOP or wxBK_BOTTOM style
153 bool IsVertical() const { return HasFlag(wxBK_BOTTOM | wxBK_TOP); }
154
155 // set/get option to shrink to fit current page
156 void SetFitToCurrentPage(bool fit) { m_fitToCurrentPage = fit; }
157 bool GetFitToCurrentPage() const { return m_fitToCurrentPage; }
158
159 // returns the sizer containing the control, if any
160 wxSizer* GetControlSizer() const { return m_controlSizer; }
161
162 // operations
163 // ----------
164
165 // remove one page from the control and delete it
166 virtual bool DeletePage(size_t n);
167
168 // remove one page from the notebook, without deleting it
169 virtual bool RemovePage(size_t n)
170 {
171 DoInvalidateBestSize();
172 return DoRemovePage(n) != NULL;
173 }
174
175 // remove all pages and delete them
176 virtual bool DeleteAllPages()
177 {
178 DoInvalidateBestSize();
179 WX_CLEAR_ARRAY(m_pages);
180 return true;
181 }
182
183 // adds a new page to the control
184 virtual bool AddPage(wxWindow *page,
185 const wxString& text,
186 bool bSelect = false,
187 int imageId = -1)
188 {
189 DoInvalidateBestSize();
190 return InsertPage(GetPageCount(), page, text, bSelect, imageId);
191 }
192
193 // the same as AddPage(), but adds the page at the specified position
194 virtual bool InsertPage(size_t n,
195 wxWindow *page,
196 const wxString& text,
197 bool bSelect = false,
198 int imageId = -1) = 0;
199
200 // set the currently selected page, return the index of the previously
201 // selected one (or -1 on error)
202 //
203 // NB: this function will generate PAGE_CHANGING/ED events
204 virtual int SetSelection(size_t n) = 0;
205
206 // acts as SetSelection but does not generate events
207 virtual int ChangeSelection(size_t n) = 0;
208
209
210 // cycle thru the pages
211 void AdvanceSelection(bool forward = true)
212 {
213 int nPage = GetNextPage(forward);
214 if ( nPage != -1 )
215 {
216 // cast is safe because of the check above
217 SetSelection((size_t)nPage);
218 }
219 }
220
221 // hit test: returns which page is hit and, optionally, where (icon, label)
222 virtual int HitTest(const wxPoint& WXUNUSED(pt),
223 long * WXUNUSED(flags) = NULL) const
224 {
225 return wxNOT_FOUND;
226 }
227
228
229 // we do have multiple pages
230 virtual bool HasMultiplePages() const { return true; }
231
232
233 protected:
234 // flags for DoSetSelection()
235 enum
236 {
237 SetSelection_SendEvent = 1
238 };
239
240 // set the selection to the given page, sending the events (which can
241 // possibly prevent the page change from taking place) if SendEvent flag is
242 // included
243 virtual int DoSetSelection(size_t nPage, int flags = 0);
244
245 // if the derived class uses DoSetSelection() for implementing
246 // [Set|Change]Selection, it must override UpdateSelectedPage(),
247 // CreatePageChangingEvent() and MakeChangedEvent(), but as it might not
248 // use it, these functions are not pure virtual
249
250 // called to notify the control about a new current page
251 virtual void UpdateSelectedPage(size_t WXUNUSED(newsel))
252 { wxFAIL_MSG(wxT("Override this function!")); }
253
254 // create a new "page changing" event
255 virtual wxBookCtrlBaseEvent* CreatePageChangingEvent() const
256 { wxFAIL_MSG(wxT("Override this function!")); return NULL; }
257
258 // modify the event created by CreatePageChangingEvent() to "page changed"
259 // event, usually by just calling SetEventType() on it
260 virtual void MakeChangedEvent(wxBookCtrlBaseEvent& WXUNUSED(event))
261 { wxFAIL_MSG(wxT("Override this function!")); }
262
263
264 // Should we accept NULL page pointers in Add/InsertPage()?
265 //
266 // Default is no but derived classes may override it if they can treat NULL
267 // pages in some sensible way (e.g. wxTreebook overrides this to allow
268 // having nodes without any associated page)
269 virtual bool AllowNullPage() const { return false; }
270
271 // remove the page and return a pointer to it
272 virtual wxWindow *DoRemovePage(size_t page) = 0;
273
274 // our best size is the size which fits all our pages
275 virtual wxSize DoGetBestSize() const;
276
277 // helper: get the next page wrapping if we reached the end
278 int GetNextPage(bool forward) const;
279
280 // Lay out controls
281 void DoSize();
282
283 // This method also invalidates the size of the controller and should be
284 // called instead of just InvalidateBestSize() whenever pages are added or
285 // removed as this also affects the controller
286 void DoInvalidateBestSize();
287
288 #if wxUSE_HELP
289 // Show the help for the corresponding page
290 void OnHelp(wxHelpEvent& event);
291 #endif // wxUSE_HELP
292
293
294 // the array of all pages of this control
295 wxArrayPages m_pages;
296
297 // the associated image list or NULL
298 wxImageList *m_imageList;
299
300 // true if we must delete m_imageList
301 bool m_ownsImageList;
302
303 // get the page area
304 wxRect GetPageRect() const;
305
306 // event handlers
307 virtual wxSize GetControllerSize() const;
308 void OnSize(wxSizeEvent& event);
309
310 // controller buddy if available, NULL otherwise (usually for native book controls like wxNotebook)
311 wxControl *m_bookctrl;
312
313 // Whether to shrink to fit current page
314 bool m_fitToCurrentPage;
315
316 // the sizer containing the choice control
317 wxSizer *m_controlSizer;
318
319 // the margin around the choice control
320 int m_controlMargin;
321
322 private:
323
324 // common part of all ctors
325 void Init();
326
327 // internal border
328 unsigned int m_internalBorder;
329
330 DECLARE_ABSTRACT_CLASS(wxBookCtrlBase)
331 DECLARE_NO_COPY_CLASS(wxBookCtrlBase)
332 DECLARE_EVENT_TABLE()
333 };
334
335 // ----------------------------------------------------------------------------
336 // wxBookCtrlBaseEvent: page changing events generated by derived classes
337 // ----------------------------------------------------------------------------
338
339 class WXDLLEXPORT wxBookCtrlBaseEvent : public wxNotifyEvent
340 {
341 public:
342 wxBookCtrlBaseEvent(wxEventType commandType = wxEVT_NULL, int winid = 0,
343 int nSel = -1, int nOldSel = -1)
344 : wxNotifyEvent(commandType, winid)
345 {
346 m_nSel = nSel;
347 m_nOldSel = nOldSel;
348 }
349
350 wxBookCtrlBaseEvent(const wxBookCtrlBaseEvent& event)
351 : wxNotifyEvent(event)
352 {
353 m_nSel = event.m_nSel;
354 m_nOldSel = event.m_nOldSel;
355 }
356
357 // accessors
358 // the currently selected page (-1 if none)
359 int GetSelection() const { return m_nSel; }
360 void SetSelection(int nSel) { m_nSel = nSel; }
361 // the page that was selected before the change (-1 if none)
362 int GetOldSelection() const { return m_nOldSel; }
363 void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
364
365 private:
366 int m_nSel, // currently selected page
367 m_nOldSel; // previously selected page
368 };
369
370 // make a default book control for given platform
371 #if wxUSE_NOTEBOOK
372 // dedicated to majority of desktops
373 #include "wx/notebook.h"
374 #define wxBookCtrl wxNotebook
375 #define wxBookCtrlEvent wxNotebookEvent
376 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
377 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
378 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_NOTEBOOK_PAGE_CHANGED(id, fn)
379 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_NOTEBOOK_PAGE_CHANGING(id, fn)
380 #define wxBookctrlEventHandler(func) wxNotebookEventHandler(func)
381 #else
382 // dedicated to Smartphones
383 #include "wx/choicebk.h"
384 #define wxBookCtrl wxChoicebook
385 #define wxBookCtrlEvent wxChoicebookEvent
386 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGED
387 #define wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGING wxEVT_COMMAND_CHOICEBOOK_PAGE_CHANGING
388 #define EVT_BOOKCTRL_PAGE_CHANGED(id, fn) EVT_CHOICEBOOK_PAGE_CHANGED(id, fn)
389 #define EVT_BOOKCTRL_PAGE_CHANGING(id, fn) EVT_CHOICEBOOK_PAGE_CHANGING(id, fn)
390 #define wxBookctrlEventHandler(func) wxChoicebookEventHandler(func)
391 #endif
392
393 #if WXWIN_COMPATIBILITY_2_6
394 #define wxBC_TOP wxBK_TOP
395 #define wxBC_BOTTOM wxBK_BOTTOM
396 #define wxBC_LEFT wxBK_LEFT
397 #define wxBC_RIGHT wxBK_RIGHT
398 #define wxBC_DEFAULT wxBK_DEFAULT
399 #endif
400
401 #endif // wxUSE_BOOKCTRL
402
403 #endif // _WX_BOOKCTRL_H_

  ViewVC Help
Powered by ViewVC 1.1.22