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(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
& pt
, long *flags
= NULL
) const
167 // cycle thru the tabs
168 void AdvanceSelection(bool forward
= TRUE
)
170 int nPage
= GetNextPage(forward
);
176 // remove the page and return a pointer to it
177 virtual wxNotebookPage
*DoRemovePage(int page
);
178 // return the minimum size large enough to display the largest page entirely
179 virtual wxSize
DoGetBestSize() const;
181 // common part of all ctors
184 // get the next page wrapping if we reached the end
185 int GetNextPage(bool forward
) const;
187 wxArrayPages m_pages
; // array of pages
188 wxImageList
*m_imageList
; // we can have an associated image list
189 bool m_ownsImageList
; // true if we must delete m_imageList
191 DECLARE_NO_COPY_CLASS(wxNotebookBase
)
194 // ----------------------------------------------------------------------------
195 // notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
196 // ----------------------------------------------------------------------------
198 class WXDLLEXPORT wxNotebookEvent
: public wxNotifyEvent
201 wxNotebookEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0,
202 int nSel
= -1, int nOldSel
= -1)
203 : wxNotifyEvent(commandType
, id
)
210 // the currently selected page (-1 if none)
211 int GetSelection() const { return m_nSel
; }
212 void SetSelection(int nSel
) { m_nSel
= nSel
; }
213 // the page that was selected before the change (-1 if none)
214 int GetOldSelection() const { return m_nOldSel
; }
215 void SetOldSelection(int nOldSel
) { m_nOldSel
= nOldSel
; }
218 int m_nSel
, // currently selected page
219 m_nOldSel
; // previously selected page
221 DECLARE_DYNAMIC_CLASS(wxNotebookEvent
)
224 // ----------------------------------------------------------------------------
225 // event types and macros for them
226 // ----------------------------------------------------------------------------
228 BEGIN_DECLARE_EVENT_TYPES()
229 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED
, 802)
230 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING
, 803)
231 END_DECLARE_EVENT_TYPES()
233 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
235 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
236 DECLARE_EVENT_TABLE_ENTRY( \
237 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
240 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
244 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
245 DECLARE_EVENT_TABLE_ENTRY( \
246 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
249 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
253 // ----------------------------------------------------------------------------
254 // wxNotebook class itself
255 // ----------------------------------------------------------------------------
257 #if defined(__WXUNIVERSAL__)
258 #include "wx/univ/notebook.h"
259 #elif defined(__WXMSW__)
260 #include "wx/msw/notebook.h"
261 #elif defined(__WXMOTIF__)
262 #include "wx/generic/notebook.h"
263 #elif defined(__WXGTK__)
264 #include "wx/gtk/notebook.h"
265 #elif defined(__WXMAC__)
266 #include "wx/mac/notebook.h"
267 #elif defined(__WXCOCOA__)
268 #include "wx/generic/notebook.h"
269 #elif defined(__WXPM__)
270 #include "wx/os2/notebook.h"
273 #endif // wxUSE_NOTEBOOK
276 // _WX_NOTEBOOK_H_BASE_