1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxNotebook interface
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1996-2000 wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_NOTEBOOK_H_BASE_
13 #define _WX_NOTEBOOK_H_BASE_
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
23 #include "wx/control.h"
24 #include "wx/dynarray.h"
26 class WXDLLEXPORT wxImageList
;
28 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
32 // array of notebook pages
33 typedef wxWindow wxNotebookPage
; // so far, any window can be a page
35 WX_DEFINE_EXPORTED_ARRAY(wxNotebookPage
*, wxArrayPages
);
37 #define wxNOTEBOOK_NAME _T("notebook")
39 // ----------------------------------------------------------------------------
40 // wxNotebookBase: define wxNotebook interface
41 // ----------------------------------------------------------------------------
43 class WXDLLEXPORT wxNotebookBase
: public wxControl
53 bool Create(wxWindow
*parent
,
55 const wxPoint
& pos
= wxDefaultPosition
,
56 const wxSize
& size
= wxDefaultSize
,
58 const wxString
& name
= wxNOTEBOOK_NAME
);
63 // get number of pages in the dialog
64 int GetPageCount() const { return m_pages
.GetCount(); }
66 // get the panel which represents the given page
67 wxNotebookPage
*GetPage(int nPage
) { return m_pages
[nPage
]; }
69 // get the currently selected page
70 virtual int GetSelection() const = 0;
72 // set/get the title of a page
73 virtual bool SetPageText(int nPage
, const wxString
& strText
) = 0;
74 virtual wxString
GetPageText(int nPage
) const = 0;
76 // image list stuff: each page may have an image associated with it (all
77 // images belong to the same image list)
78 virtual void SetImageList(wxImageList
* imageList
)
80 m_imageList
= imageList
;
83 // get pointer (may be NULL) to the associated image list
84 wxImageList
* GetImageList() const { return m_imageList
; }
86 // sets/returns item's image index in the current image list
87 virtual int GetPageImage(int nPage
) const = 0;
88 virtual bool SetPageImage(int nPage
, int nImage
) = 0;
90 // get the number of rows for a control with wxNB_MULTILINE style (not all
91 // versions support it - they will always return 1 then)
92 virtual int GetRowCount() const { return 1; }
94 // set the size (the same for all pages)
95 virtual void SetPageSize(const wxSize
& size
) = 0;
97 // set the padding between tabs (in pixels)
98 virtual void SetPadding(const wxSize
& padding
) = 0;
100 // set the size of the tabs for wxNB_FIXEDWIDTH controls
101 virtual void SetTabSize(const wxSize
& sz
) = 0;
103 // calculate the size of the notebook from the size of its page
104 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
)
106 // this was just taken from wxNotebookSizer::CalcMin() and is, of
107 // course, totally bogus - just like the original code was
108 wxSize sizeTotal
= sizePage
;
109 if ( HasFlag(wxNB_LEFT
) || HasFlag(wxNB_RIGHT
) )
120 // remove one page from the notebook and delete it
121 virtual bool DeletePage(int nPage
)
123 wxNotebookPage
*page
= DoRemovePage(nPage
);
132 // remove one page from the notebook, without deleting it
133 virtual bool RemovePage(int nPage
) { return DoRemovePage(nPage
) != NULL
; }
135 // remove all pages and delete them
136 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages
); return TRUE
; }
138 // adds a new page to the notebook (it will be deleted by the notebook,
139 // don't delete it yourself) and make it the current one if bSelect
140 virtual bool AddPage(wxNotebookPage
*pPage
,
141 const wxString
& strText
,
142 bool bSelect
= FALSE
,
145 return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
);
148 // the same as AddPage(), but adds the page at the specified position
149 virtual bool InsertPage(int nPage
,
150 wxNotebookPage
*pPage
,
151 const wxString
& strText
,
152 bool bSelect
= FALSE
,
153 int imageId
= -1) = 0;
155 // set the currently selected page, return the index of the previously
156 // selected one (or -1 on error)
158 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
159 virtual int SetSelection(int nPage
) = 0;
161 // cycle thru the tabs
162 void AdvanceSelection(bool forward
= TRUE
)
164 int nPage
= GetNextPage(forward
);
170 // remove the page and return a pointer to it
171 virtual wxNotebookPage
*DoRemovePage(int page
) = 0;
173 // get the next page wrapping if we reached the end
174 int GetNextPage(bool forward
) const
178 int nMax
= GetPageCount();
179 if ( nMax
-- ) // decrement it to get the last valid index
181 int nSel
= GetSelection();
183 // change selection wrapping if it becomes invalid
184 nPage
= forward
? nSel
== nMax
? 0
189 else // notebook is empty, no next page
197 wxImageList
*m_imageList
; // we can have an associated image list
198 wxArrayPages m_pages
; // array of pages
201 // ----------------------------------------------------------------------------
202 // notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
203 // ----------------------------------------------------------------------------
205 class WXDLLEXPORT wxNotebookEvent
: public wxNotifyEvent
208 wxNotebookEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0,
209 int nSel
= -1, int nOldSel
= -1)
210 : wxNotifyEvent(commandType
, id
)
217 // the currently selected page (-1 if none)
218 int GetSelection() const { return m_nSel
; }
219 void SetSelection(int nSel
) { m_nSel
= nSel
; }
220 // the page that was selected before the change (-1 if none)
221 int GetOldSelection() const { return m_nOldSel
; }
222 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
225 int m_nSel
, // currently selected page
226 m_nOldSel
; // previously selected page
228 DECLARE_DYNAMIC_CLASS(wxNotebookEvent
)
231 // ----------------------------------------------------------------------------
232 // event types and macros for them
233 // ----------------------------------------------------------------------------
235 #if defined(__BORLANDC__) && defined(__WIN16__)
236 // For 16-bit BC++, these 2 would be identical otherwise (truncated)
237 #define wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED wxEVT_COMMAND_NB_PAGE_CHANGED
238 #define wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING wxEVT_COMMAND_NB_PAGE_CHANGING
241 BEGIN_DECLARE_EVENT_TYPES()
242 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, 802)
243 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, 803)
244 END_DECLARE_EVENT_TYPES()
246 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
248 // Truncation in 16-bit BC++ means we need to define these differently
249 #if defined(__BORLANDC__) && defined(__WIN16__)
250 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
251 DECLARE_EVENT_TABLE_ENTRY( \
252 wxEVT_COMMAND_NB_PAGE_CHANGED, \
255 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
259 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
260 DECLARE_EVENT_TABLE_ENTRY( \
261 wxEVT_COMMAND_NB_PAGE_CHANGING, \
264 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
270 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
271 DECLARE_EVENT_TABLE_ENTRY( \
272 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
275 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
279 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
280 DECLARE_EVENT_TABLE_ENTRY( \
281 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
284 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
290 // ----------------------------------------------------------------------------
291 // wxNotebook class itself
292 // ----------------------------------------------------------------------------
294 #if defined(__WXUNIVERSAL__)
295 #include "wx/univ/notebook.h"
296 #elif defined(__WXMSW__)
298 #include "wx/generic/notebook.h"
300 #include "wx/msw/notebook.h"
302 #elif defined(__WXMOTIF__)
303 #include "wx/generic/notebook.h"
304 #elif defined(__WXGTK__)
305 #include "wx/gtk/notebook.h"
306 #elif defined(__WXQT__)
307 #include "wx/qt/notebook.h"
308 #elif defined(__WXMAC__)
309 #include "wx/mac/notebook.h"
310 #elif defined(__WXPM__)
311 #include "wx/os2/notebook.h"
312 #elif defined(__WXSTUBS__)
313 #include "wx/stubs/notebook.h"
316 #endif // wxUSE_NOTEBOOK
319 // _WX_NOTEBOOK_H_BASE_