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 // wxNotebook hit results
38 wxNB_HITTEST_NOWHERE
= 1, // not on tab
39 wxNB_HITTEST_ONICON
= 2, // on icon
40 wxNB_HITTEST_ONLABEL
= 4, // on label
41 wxNB_HITTEST_ONITEM
= wxNB_HITTEST_ONICON
| wxNB_HITTEST_ONLABEL
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // array of notebook pages
49 typedef wxWindow wxNotebookPage
; // so far, any window can be a page
51 WX_DEFINE_EXPORTED_ARRAY_NO_PTR(wxNotebookPage
*, wxArrayPages
);
53 #define wxNOTEBOOK_NAME _T("notebook")
55 // ----------------------------------------------------------------------------
56 // wxNotebookBase: define wxNotebook interface
57 // ----------------------------------------------------------------------------
59 class WXDLLEXPORT wxNotebookBase
: public wxControl
69 bool Create(wxWindow
*parent
,
71 const wxPoint
& pos
= wxDefaultPosition
,
72 const wxSize
& size
= wxDefaultSize
,
74 const wxString
& name
= wxNOTEBOOK_NAME
);
77 virtual ~wxNotebookBase();
82 // get number of pages in the dialog
83 int GetPageCount() const { return (int) m_pages
.GetCount(); }
85 // get the panel which represents the given page
86 wxNotebookPage
*GetPage(int nPage
) { return m_pages
[nPage
]; }
88 // get the currently selected page
89 virtual int GetSelection() const = 0;
91 // set/get the title of a page
92 virtual bool SetPageText(int nPage
, const wxString
& strText
) = 0;
93 virtual wxString
GetPageText(int nPage
) const = 0;
95 // image list stuff: each page may have an image associated with it (all
96 // images belong to the same image list)
97 virtual void SetImageList(wxImageList
* imageList
);
99 // as SetImageList() but we will delete the image list ourselves
100 void AssignImageList(wxImageList
* imageList
);
102 // get pointer (may be NULL) to the associated image list
103 wxImageList
* GetImageList() const { return m_imageList
; }
105 // sets/returns item's image index in the current image list
106 virtual int GetPageImage(int nPage
) const = 0;
107 virtual bool SetPageImage(int nPage
, int nImage
) = 0;
109 // get the number of rows for a control with wxNB_MULTILINE style (not all
110 // versions support it - they will always return 1 then)
111 virtual int GetRowCount() const { return 1; }
113 // set the size (the same for all pages)
114 virtual void SetPageSize(const wxSize
& size
) = 0;
116 // set the padding between tabs (in pixels)
117 virtual void SetPadding(const wxSize
& padding
) = 0;
119 // set the size of the tabs for wxNB_FIXEDWIDTH controls
120 virtual void SetTabSize(const wxSize
& sz
) = 0;
122 // calculate the size of the notebook from the size of its page
123 virtual wxSize
CalcSizeFromPage(const wxSize
& sizePage
) const;
128 // remove one page from the notebook and delete it
129 virtual bool DeletePage(int nPage
);
131 // remove one page from the notebook, without deleting it
132 virtual bool RemovePage(int nPage
) { return DoRemovePage(nPage
) != NULL
; }
134 // remove all pages and delete them
135 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages
); return TRUE
; }
137 // adds a new page to the notebook (it will be deleted by the notebook,
138 // don't delete it yourself) and make it the current one if bSelect
139 virtual bool AddPage(wxNotebookPage
*pPage
,
140 const wxString
& strText
,
141 bool bSelect
= FALSE
,
144 return InsertPage(GetPageCount(), pPage
, strText
, bSelect
, imageId
);
147 // the same as AddPage(), but adds the page at the specified position
148 virtual bool InsertPage(int nPage
,
149 wxNotebookPage
*pPage
,
150 const wxString
& strText
,
151 bool bSelect
= FALSE
,
152 int imageId
= -1) = 0;
154 // set the currently selected page, return the index of the previously
155 // selected one (or -1 on error)
157 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
158 virtual int SetSelection(int nPage
) = 0;
160 // hit test, returns which tab is hit and, optionally, where (icon, label)
161 // (not implemented on all platforms)
162 virtual int HitTest(const wxPoint
& WXUNUSED(pt
),
163 long * WXUNUSED(flags
) = NULL
) const
168 // cycle thru the tabs
169 void AdvanceSelection(bool forward
= TRUE
)
171 int nPage
= GetNextPage(forward
);
177 // remove the page and return a pointer to it
178 virtual wxNotebookPage
*DoRemovePage(int page
);
179 // return the minimum size large enough to display the largest page entirely
180 virtual wxSize
DoGetBestSize() const;
182 // common part of all ctors
185 // get the next page wrapping if we reached the end
186 int GetNextPage(bool forward
) const;
188 wxArrayPages m_pages
; // array of pages
189 wxImageList
*m_imageList
; // we can have an associated image list
190 bool m_ownsImageList
; // true if we must delete m_imageList
192 DECLARE_NO_COPY_CLASS(wxNotebookBase
)
195 // ----------------------------------------------------------------------------
196 // notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
197 // ----------------------------------------------------------------------------
199 class WXDLLEXPORT wxNotebookEvent
: public wxNotifyEvent
202 wxNotebookEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0,
203 int nSel
= -1, int nOldSel
= -1)
204 : wxNotifyEvent(commandType
, id
)
211 // the currently selected page (-1 if none)
212 int GetSelection() const { return m_nSel
; }
213 void SetSelection(int nSel
) { m_nSel
= nSel
; }
214 // the page that was selected before the change (-1 if none)
215 int GetOldSelection() const { return m_nOldSel
; }
216 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
219 int m_nSel
, // currently selected page
220 m_nOldSel
; // previously selected page
222 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNotebookEvent
)
225 // ----------------------------------------------------------------------------
226 // event types and macros for them
227 // ----------------------------------------------------------------------------
229 BEGIN_DECLARE_EVENT_TYPES()
230 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, 802)
231 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, 803)
232 END_DECLARE_EVENT_TYPES()
234 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
236 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
237 DECLARE_EVENT_TABLE_ENTRY( \
238 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
241 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
245 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
246 DECLARE_EVENT_TABLE_ENTRY( \
247 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
250 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
254 // ----------------------------------------------------------------------------
255 // wxNotebook class itself
256 // ----------------------------------------------------------------------------
258 #if defined(__WXUNIVERSAL__)
259 #include "wx/univ/notebook.h"
260 #elif defined(__WXMSW__)
261 #include "wx/msw/notebook.h"
262 #elif defined(__WXMOTIF__)
263 #include "wx/generic/notebook.h"
264 #elif defined(__WXGTK__)
265 #include "wx/gtk/notebook.h"
266 #elif defined(__WXMAC__)
267 #include "wx/mac/notebook.h"
268 #elif defined(__WXCOCOA__)
269 #include "wx/generic/notebook.h"
270 #elif defined(__WXPM__)
271 #include "wx/os2/notebook.h"
274 #endif // wxUSE_NOTEBOOK
277 // _WX_NOTEBOOK_H_BASE_