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_
16 #pragma interface "notebookbase.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
27 #include "wx/control.h"
28 #include "wx/dynarray.h"
30 class WXDLLEXPORT wxImageList
;
32 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 // array of notebook pages
37 typedef wxWindow wxNotebookPage
; // so far, any window can be a page
39 WX_DEFINE_EXPORTED_ARRAY(wxNotebookPage
*, wxArrayPages
);
41 #define wxNOTEBOOK_NAME _T("notebook")
43 // ----------------------------------------------------------------------------
44 // wxNotebookBase: define wxNotebook interface
45 // ----------------------------------------------------------------------------
47 class WXDLLEXPORT wxNotebookBase
: public wxControl
57 bool Create(wxWindow
*parent
,
59 const wxPoint
& pos
= wxDefaultPosition
,
60 const wxSize
& size
= wxDefaultSize
,
62 const wxString
& name
= wxNOTEBOOK_NAME
);
65 virtual ~wxNotebookBase();
70 // get number of pages in the dialog
71 int GetPageCount() const { return m_pages
.GetCount(); }
73 // get the panel which represents the given page
74 wxNotebookPage
*GetPage(int nPage
) { return m_pages
[nPage
]; }
76 // get the currently selected page
77 virtual int GetSelection() const = 0;
79 // set/get the title of a page
80 virtual bool SetPageText(int nPage
, const wxString
& strText
) = 0;
81 virtual wxString
GetPageText(int nPage
) const = 0;
83 // image list stuff: each page may have an image associated with it (all
84 // images belong to the same image list)
85 virtual void SetImageList(wxImageList
* imageList
);
87 // as SetImageList() but we will delete the image list ourselves
88 void AssignImageList(wxImageList
* imageList
);
90 // get pointer (may be NULL) to the associated image list
91 wxImageList
* GetImageList() const { return m_imageList
; }
93 // sets/returns item's image index in the current image list
94 virtual int GetPageImage(int nPage
) const = 0;
95 virtual bool SetPageImage(int nPage
, int nImage
) = 0;
97 // get the number of rows for a control with wxNB_MULTILINE style (not all
98 // versions support it - they will always return 1 then)
99 virtual int GetRowCount() const { return 1; }
101 // set the size (the same for all pages)
102 virtual void SetPageSize(const wxSize
& size
) = 0;
104 // set the padding between tabs (in pixels)
105 virtual void SetPadding(const wxSize
& padding
) = 0;
107 // set the size of the tabs for wxNB_FIXEDWIDTH controls
108 virtual void SetTabSize(const wxSize
& sz
) = 0;
110 // calculate the size of the notebook from the size of its page
111 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
);
116 // remove one page from the notebook and delete it
117 virtual bool DeletePage(int nPage
);
119 // remove one page from the notebook, without deleting it
120 virtual bool RemovePage(int nPage
) { return DoRemovePage(nPage
) != NULL
; }
122 // remove all pages and delete them
123 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages
); return TRUE
; }
125 // adds a new page to the notebook (it will be deleted by the notebook,
126 // don't delete it yourself) and make it the current one if bSelect
127 virtual bool AddPage(wxNotebookPage
*pPage
,
128 const wxString
& strText
,
129 bool bSelect
= FALSE
,
132 return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
);
135 // the same as AddPage(), but adds the page at the specified position
136 virtual bool InsertPage(int nPage
,
137 wxNotebookPage
*pPage
,
138 const wxString
& strText
,
139 bool bSelect
= FALSE
,
140 int imageId
= -1) = 0;
142 // set the currently selected page, return the index of the previously
143 // selected one (or -1 on error)
145 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
146 virtual int SetSelection(int nPage
) = 0;
148 // cycle thru the tabs
149 void AdvanceSelection(bool forward
= TRUE
)
151 int nPage
= GetNextPage(forward
);
157 // remove the page and return a pointer to it
158 virtual wxNotebookPage
*DoRemovePage(int page
);
160 // common part of all ctors
163 // get the next page wrapping if we reached the end
164 int GetNextPage(bool forward
) const;
166 wxArrayPages m_pages
; // array of pages
167 wxImageList
*m_imageList
; // we can have an associated image list
168 bool m_ownsImageList
; // true if we must delete m_imageList
171 // ----------------------------------------------------------------------------
172 // notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
173 // ----------------------------------------------------------------------------
175 class WXDLLEXPORT wxNotebookEvent
: public wxNotifyEvent
178 wxNotebookEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0,
179 int nSel
= -1, int nOldSel
= -1)
180 : wxNotifyEvent(commandType
, id
)
187 // the currently selected page (-1 if none)
188 int GetSelection() const { return m_nSel
; }
189 void SetSelection(int nSel
) { m_nSel
= nSel
; }
190 // the page that was selected before the change (-1 if none)
191 int GetOldSelection() const { return m_nOldSel
; }
192 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
195 int m_nSel
, // currently selected page
196 m_nOldSel
; // previously selected page
198 DECLARE_DYNAMIC_CLASS(wxNotebookEvent
)
201 // ----------------------------------------------------------------------------
202 // event types and macros for them
203 // ----------------------------------------------------------------------------
205 #if defined(__BORLANDC__) && defined(__WIN16__)
206 // For 16-bit BC++, these 2 would be identical otherwise (truncated)
207 #define wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED wxEVT_COMMAND_NB_PAGE_CHANGED
208 #define wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING wxEVT_COMMAND_NB_PAGE_CHANGING
211 BEGIN_DECLARE_EVENT_TYPES()
212 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, 802)
213 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, 803)
214 END_DECLARE_EVENT_TYPES()
216 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
218 // Truncation in 16-bit BC++ means we need to define these differently
219 #if defined(__BORLANDC__) && defined(__WIN16__)
220 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
221 DECLARE_EVENT_TABLE_ENTRY( \
222 wxEVT_COMMAND_NB_PAGE_CHANGED, \
225 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
229 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
230 DECLARE_EVENT_TABLE_ENTRY( \
231 wxEVT_COMMAND_NB_PAGE_CHANGING, \
234 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
240 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
241 DECLARE_EVENT_TABLE_ENTRY( \
242 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
245 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
249 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
250 DECLARE_EVENT_TABLE_ENTRY( \
251 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
254 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
260 // ----------------------------------------------------------------------------
261 // wxNotebook class itself
262 // ----------------------------------------------------------------------------
264 #if defined(__WXUNIVERSAL__)
265 #include "wx/univ/notebook.h"
266 #elif defined(__WXMSW__)
268 #include "wx/generic/notebook.h"
270 #include "wx/msw/notebook.h"
272 #elif defined(__WXMOTIF__)
273 #include "wx/generic/notebook.h"
274 #elif defined(__WXGTK__)
275 #include "wx/gtk/notebook.h"
276 #elif defined(__WXQT__)
277 #include "wx/qt/notebook.h"
278 #elif defined(__WXMAC__)
279 #include "wx/mac/notebook.h"
280 #elif defined(__WXPM__)
281 #include "wx/os2/notebook.h"
282 #elif defined(__WXSTUBS__)
283 #include "wx/stubs/notebook.h"
286 #endif // wxUSE_NOTEBOOK
289 // _WX_NOTEBOOK_H_BASE_