]> git.saurik.com Git - wxWidgets.git/blame - include/wx/notebook.h
removed useless ; to allow smart preprocessing under Mac OS X
[wxWidgets.git] / include / wx / notebook.h
CommitLineData
1e6feb95
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/notebook.h
3// Purpose: wxNotebook interface
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 01.02.01
7// RCS-ID: $Id$
8// Copyright: (c) 1996-2000 wxWindows team
9// Licence: wxWindows licence
10///////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_NOTEBOOK_H_BASE_
13#define _WX_NOTEBOOK_H_BASE_
53b28675 14
4d0f3cd6
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
1e6feb95
VZ
19#include "wx/defs.h"
20
21#if wxUSE_NOTEBOOK
22
23#include "wx/control.h"
24#include "wx/dynarray.h"
25
26class WXDLLEXPORT wxImageList;
27
28// ----------------------------------------------------------------------------
29// types
30// ----------------------------------------------------------------------------
31
32// array of notebook pages
33typedef wxWindow wxNotebookPage; // so far, any window can be a page
34
35WX_DEFINE_EXPORTED_ARRAY(wxNotebookPage *, wxArrayPages);
36
37#define wxNOTEBOOK_NAME _T("notebook")
38
39// ----------------------------------------------------------------------------
40// wxNotebookBase: define wxNotebook interface
41// ----------------------------------------------------------------------------
42
43class WXDLLEXPORT wxNotebookBase : public wxControl
44{
45public:
46 // ctor
47 wxNotebookBase()
48 {
49 m_imageList = NULL;
50 }
51
52 // quasi ctor
53 bool Create(wxWindow *parent,
54 wxWindowID id,
55 const wxPoint& pos = wxDefaultPosition,
56 const wxSize& size = wxDefaultSize,
57 long style = 0,
58 const wxString& name = wxNOTEBOOK_NAME);
59
60 // accessors
61 // ---------
62
63 // get number of pages in the dialog
64 int GetPageCount() const { return m_pages.GetCount(); }
65
66 // get the panel which represents the given page
67 wxNotebookPage *GetPage(int nPage) { return m_pages[nPage]; }
68
69 // get the currently selected page
70 virtual int GetSelection() const = 0;
71
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;
75
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)
79 {
80 m_imageList = imageList;
81 }
82
83 // get pointer (may be NULL) to the associated image list
84 wxImageList* GetImageList() const { return m_imageList; }
85
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;
89
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; }
93
94 // set the size (the same for all pages)
95 virtual void SetPageSize(const wxSize& size) = 0;
96
97 // set the padding between tabs (in pixels)
98 virtual void SetPadding(const wxSize& padding) = 0;
99
100 // set the size of the tabs for wxNB_FIXEDWIDTH controls
101 virtual void SetTabSize(const wxSize& sz) = 0;
102
103 // calculate the size of the notebook from the size of its page
104 virtual wxSize CalcSizeFromPage(const wxSize& sizePage)
105 {
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) )
110 sizeTotal.x += 90;
111 else
112 sizeTotal.y += 40;
113
114 return sizeTotal;
115 }
116
117 // operations
118 // ----------
119
120 // remove one page from the notebook and delete it
121 virtual bool DeletePage(int nPage)
122 {
123 wxNotebookPage *page = DoRemovePage(nPage);
124 if ( !page )
125 return FALSE;
126
127 delete page;
128
129 return TRUE;
130 }
131
132 // remove one page from the notebook, without deleting it
133 virtual bool RemovePage(int nPage) { return DoRemovePage(nPage) != NULL; }
134
135 // remove all pages and delete them
136 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages); return TRUE; }
137
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,
143 int imageId = -1)
144 {
145 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
146 }
147
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;
154
155 // set the currently selected page, return the index of the previously
156 // selected one (or -1 on error)
157 //
158 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
159 virtual int SetSelection(int nPage) = 0;
160
161 // cycle thru the tabs
162 void AdvanceSelection(bool forward = TRUE)
163 {
164 int nPage = GetNextPage(forward);
165 if ( nPage != -1 )
166 SetSelection(nPage);
167 }
168
169protected:
170 // remove the page and return a pointer to it
171 virtual wxNotebookPage *DoRemovePage(int page) = 0;
172
173 // get the next page wrapping if we reached the end
174 int GetNextPage(bool forward) const
175 {
176 int nPage;
177
178 int nMax = GetPageCount();
179 if ( nMax-- ) // decrement it to get the last valid index
180 {
181 int nSel = GetSelection();
182
183 // change selection wrapping if it becomes invalid
184 nPage = forward ? nSel == nMax ? 0
185 : nSel + 1
186 : nSel == 0 ? nMax
187 : nSel - 1;
188 }
189 else // notebook is empty, no next page
190 {
191 nPage = -1;
192 }
193
194 return nPage;
195 }
196
197 wxImageList *m_imageList; // we can have an associated image list
198 wxArrayPages m_pages; // array of pages
199};
4d0f3cd6
VZ
200
201// ----------------------------------------------------------------------------
202// notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
203// ----------------------------------------------------------------------------
204
205class WXDLLEXPORT wxNotebookEvent : public wxNotifyEvent
206{
207public:
208 wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
209 int nSel = -1, int nOldSel = -1)
210 : wxNotifyEvent(commandType, id)
211 {
212 m_nSel = nSel;
213 m_nOldSel = nOldSel;
214 }
215
216 // accessors
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; }
223
224private:
225 int m_nSel, // currently selected page
226 m_nOldSel; // previously selected page
227
228 DECLARE_DYNAMIC_CLASS(wxNotebookEvent)
229};
230
231// ----------------------------------------------------------------------------
2e4df4bf 232// event types and macros for them
4d0f3cd6
VZ
233// ----------------------------------------------------------------------------
234
2e4df4bf
VZ
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
239#endif
240
241BEGIN_DECLARE_EVENT_TYPES()
242 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, 802)
243 DECLARE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, 803)
244END_DECLARE_EVENT_TYPES()
245
4d0f3cd6
VZ
246typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
247
25889d3c
JS
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) \
2e4df4bf 251 DECLARE_EVENT_TABLE_ENTRY( \
82a5f02c 252 wxEVT_COMMAND_NB_PAGE_CHANGED, \
25889d3c
JS
253 id, \
254 -1, \
255 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
256 NULL \
82a5f02c 257 ),
25889d3c
JS
258
259#define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
2e4df4bf 260 DECLARE_EVENT_TABLE_ENTRY( \
82a5f02c 261 wxEVT_COMMAND_NB_PAGE_CHANGING, \
25889d3c
JS
262 id, \
263 -1, \
264 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
265 NULL \
82a5f02c 266 ),
25889d3c
JS
267
268#else
269
4d0f3cd6 270#define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
2e4df4bf 271 DECLARE_EVENT_TABLE_ENTRY( \
4d0f3cd6
VZ
272 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
273 id, \
274 -1, \
275 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
276 NULL \
82a5f02c 277 ),
4d0f3cd6
VZ
278
279#define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
2e4df4bf 280 DECLARE_EVENT_TABLE_ENTRY( \
4d0f3cd6
VZ
281 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
282 id, \
283 -1, \
284 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
285 NULL \
82a5f02c 286 ),
4d0f3cd6 287
25889d3c
JS
288#endif
289
4d0f3cd6
VZ
290// ----------------------------------------------------------------------------
291// wxNotebook class itself
292// ----------------------------------------------------------------------------
293
1e6feb95
VZ
294#if defined(__WXUNIVERSAL__)
295 #include "wx/univ/notebook.h"
296#elif defined(__WXMSW__)
297 #ifdef __WIN16__
298 #include "wx/generic/notebook.h"
299 #else
300 #include "wx/msw/notebook.h"
301 #endif
2049ba38 302#elif defined(__WXMOTIF__)
1e6feb95 303 #include "wx/generic/notebook.h"
2049ba38 304#elif defined(__WXGTK__)
1e6feb95 305 #include "wx/gtk/notebook.h"
b4e76e0d 306#elif defined(__WXQT__)
1e6feb95 307 #include "wx/qt/notebook.h"
34138703 308#elif defined(__WXMAC__)
1e6feb95 309 #include "wx/mac/notebook.h"
1777b9bb 310#elif defined(__WXPM__)
1e6feb95 311 #include "wx/os2/notebook.h"
34138703 312#elif defined(__WXSTUBS__)
1e6feb95 313 #include "wx/stubs/notebook.h"
53b28675
RR
314#endif
315
1e6feb95
VZ
316#endif // wxUSE_NOTEBOOK
317
53b28675 318#endif
34138703 319 // _WX_NOTEBOOK_H_BASE_