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 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "notebookbase.h"
19 // ----------------------------------------------------------------------------
21 // ----------------------------------------------------------------------------
27 #include "wx/control.h"
28 #include "wx/dynarray.h"
29 #include "wx/imaglist.h"
31 // ----------------------------------------------------------------------------
33 // ----------------------------------------------------------------------------
35 // array of notebook pages
36 typedef wxWindow wxNotebookPage
; // so far, any window can be a page
38 WX_DEFINE_EXPORTED_ARRAY(wxNotebookPage
*, wxArrayPages
);
40 #define wxNOTEBOOK_NAME _T("notebook")
42 // ----------------------------------------------------------------------------
43 // wxNotebookBase: define wxNotebook interface
44 // ----------------------------------------------------------------------------
46 class WXDLLEXPORT wxNotebookBase
: public wxControl
56 bool Create(wxWindow
*parent
,
58 const wxPoint
& pos
= wxDefaultPosition
,
59 const wxSize
& size
= wxDefaultSize
,
61 const wxString
& name
= wxNOTEBOOK_NAME
);
64 virtual ~wxNotebookBase();
69 // get number of pages in the dialog
70 int GetPageCount() const { return (int) m_pages
.GetCount(); }
72 // get the panel which represents the given page
73 wxNotebookPage
*GetPage(int nPage
) { return m_pages
[nPage
]; }
75 // get the currently selected page
76 virtual int GetSelection() const = 0;
78 // set/get the title of a page
79 virtual bool SetPageText(int nPage
, const wxString
& strText
) = 0;
80 virtual wxString
GetPageText(int nPage
) const = 0;
82 // image list stuff: each page may have an image associated with it (all
83 // images belong to the same image list)
84 virtual void SetImageList(wxImageList
* imageList
);
86 // as SetImageList() but we will delete the image list ourselves
87 void AssignImageList(wxImageList
* imageList
);
89 // get pointer (may be NULL) to the associated image list
90 wxImageList
* GetImageList() const { return m_imageList
; }
92 // sets/returns item's image index in the current image list
93 virtual int GetPageImage(int nPage
) const = 0;
94 virtual bool SetPageImage(int nPage
, int nImage
) = 0;
96 // get the number of rows for a control with wxNB_MULTILINE style (not all
97 // versions support it - they will always return 1 then)
98 virtual int GetRowCount() const { return 1; }
100 // set the size (the same for all pages)
101 virtual void SetPageSize(const wxSize
& size
) = 0;
103 // set the padding between tabs (in pixels)
104 virtual void SetPadding(const wxSize
& padding
) = 0;
106 // set the size of the tabs for wxNB_FIXEDWIDTH controls
107 virtual void SetTabSize(const wxSize
& sz
) = 0;
109 // calculate the size of the notebook from the size of its page
110 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
);
115 // remove one page from the notebook and delete it
116 virtual bool DeletePage(int nPage
);
118 // remove one page from the notebook, without deleting it
119 virtual bool RemovePage(int nPage
) { return DoRemovePage(nPage
) != NULL
; }
121 // remove all pages and delete them
122 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages
); return TRUE
; }
124 // adds a new page to the notebook (it will be deleted by the notebook,
125 // don't delete it yourself) and make it the current one if bSelect
126 virtual bool AddPage(wxNotebookPage
*pPage
,
127 const wxString
& strText
,
128 bool bSelect
= FALSE
,
131 return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
);
134 // the same as AddPage(), but adds the page at the specified position
135 virtual bool InsertPage(int nPage
,
136 wxNotebookPage
*pPage
,
137 const wxString
& strText
,
138 bool bSelect
= FALSE
,
139 int imageId
= -1) = 0;
141 // set the currently selected page, return the index of the previously
142 // selected one (or -1 on error)
144 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
145 virtual int SetSelection(int nPage
) = 0;
147 // cycle thru the tabs
148 void AdvanceSelection(bool forward
= TRUE
)
150 int nPage
= GetNextPage(forward
);
156 // remove the page and return a pointer to it
157 virtual wxNotebookPage
*DoRemovePage(int page
);
159 // common part of all ctors
162 // get the next page wrapping if we reached the end
163 int GetNextPage(bool forward
) const;
165 wxArrayPages m_pages
; // array of pages
166 wxImageList
*m_imageList
; // we can have an associated image list
167 bool m_ownsImageList
; // true if we must delete m_imageList
169 DECLARE_NO_COPY_CLASS(wxNotebookBase
)
172 // ----------------------------------------------------------------------------
173 // notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
174 // ----------------------------------------------------------------------------
176 class WXDLLEXPORT wxNotebookEvent
: public wxNotifyEvent
179 wxNotebookEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0,
180 int nSel
= -1, int nOldSel
= -1)
181 : wxNotifyEvent(commandType
, id
)
188 // the currently selected page (-1 if none)
189 int GetSelection() const { return m_nSel
; }
190 void SetSelection(int nSel
) { m_nSel
= nSel
; }
191 // the page that was selected before the change (-1 if none)
192 int GetOldSelection() const { return m_nOldSel
; }
193 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
196 int m_nSel
, // currently selected page
197 m_nOldSel
; // previously selected page
199 DECLARE_DYNAMIC_CLASS(wxNotebookEvent
)
202 // ----------------------------------------------------------------------------
203 // event types and macros for them
204 // ----------------------------------------------------------------------------
206 #if defined(__BORLANDC__) && defined(__WIN16__)
207 // For 16-bit BC++, these 2 would be identical otherwise (truncated)
208 #define wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED wxEVT_COMMAND_NB_PAGE_CHANGED
209 #define wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING wxEVT_COMMAND_NB_PAGE_CHANGING
212 BEGIN_DECLARE_EVENT_TYPES()
213 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, 802)
214 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, 803)
215 END_DECLARE_EVENT_TYPES()
217 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
219 // Truncation in 16-bit BC++ means we need to define these differently
220 #if defined(__BORLANDC__) && defined(__WIN16__)
221 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
222 DECLARE_EVENT_TABLE_ENTRY( \
223 wxEVT_COMMAND_NB_PAGE_CHANGED, \
226 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
230 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
231 DECLARE_EVENT_TABLE_ENTRY( \
232 wxEVT_COMMAND_NB_PAGE_CHANGING, \
235 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
241 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
242 DECLARE_EVENT_TABLE_ENTRY( \
243 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
246 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
250 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
251 DECLARE_EVENT_TABLE_ENTRY( \
252 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
255 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
261 // ----------------------------------------------------------------------------
262 // wxNotebook class itself
263 // ----------------------------------------------------------------------------
265 #if defined(__WXUNIVERSAL__)
266 #include "wx/univ/notebook.h"
267 #elif defined(__WXMSW__)
269 #include "wx/generic/notebook.h"
271 #include "wx/msw/notebook.h"
273 #elif defined(__WXMOTIF__)
274 #include "wx/generic/notebook.h"
275 #elif defined(__WXGTK__)
276 #include "wx/gtk/notebook.h"
277 #elif defined(__WXMAC__)
278 #include "wx/mac/notebook.h"
279 #elif defined(__WXCOCOA__)
280 #include "wx/generic/notebook.h"
281 #elif defined(__WXPM__)
282 #include "wx/os2/notebook.h"
285 #endif // wxUSE_NOTEBOOK
288 // _WX_NOTEBOOK_H_BASE_