fixed deleting pages from the notebook
[wxWidgets.git] / include / wx / notebook.h
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
12 #ifndef _WX_NOTEBOOK_H_BASE_
13 #define _WX_NOTEBOOK_H_BASE_
14
15 #ifdef __GNUG__
16 #pragma interface "notebookbase.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // headers
21 // ----------------------------------------------------------------------------
22
23 #include "wx/defs.h"
24
25 #if wxUSE_NOTEBOOK
26
27 #include "wx/control.h"
28 #include "wx/dynarray.h"
29
30 class WXDLLEXPORT wxImageList;
31
32 // ----------------------------------------------------------------------------
33 // types
34 // ----------------------------------------------------------------------------
35
36 // array of notebook pages
37 typedef wxWindow wxNotebookPage; // so far, any window can be a page
38
39 WX_DEFINE_EXPORTED_ARRAY(wxNotebookPage *, wxArrayPages);
40
41 #define wxNOTEBOOK_NAME _T("notebook")
42
43 // ----------------------------------------------------------------------------
44 // wxNotebookBase: define wxNotebook interface
45 // ----------------------------------------------------------------------------
46
47 class WXDLLEXPORT wxNotebookBase : public wxControl
48 {
49 public:
50 // ctor
51 wxNotebookBase()
52 {
53 Init();
54 }
55
56 // quasi ctor
57 bool Create(wxWindow *parent,
58 wxWindowID id,
59 const wxPoint& pos = wxDefaultPosition,
60 const wxSize& size = wxDefaultSize,
61 long style = 0,
62 const wxString& name = wxNOTEBOOK_NAME);
63
64 // dtor
65 virtual ~wxNotebookBase();
66
67 // accessors
68 // ---------
69
70 // get number of pages in the dialog
71 int GetPageCount() const { return m_pages.GetCount(); }
72
73 // get the panel which represents the given page
74 wxNotebookPage *GetPage(int nPage) { return m_pages[nPage]; }
75
76 // get the currently selected page
77 virtual int GetSelection() const = 0;
78
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;
82
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);
86
87 // as SetImageList() but we will delete the image list ourselves
88 void AssignImageList(wxImageList* imageList);
89
90 // get pointer (may be NULL) to the associated image list
91 wxImageList* GetImageList() const { return m_imageList; }
92
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;
96
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; }
100
101 // set the size (the same for all pages)
102 virtual void SetPageSize(const wxSize& size) = 0;
103
104 // set the padding between tabs (in pixels)
105 virtual void SetPadding(const wxSize& padding) = 0;
106
107 // set the size of the tabs for wxNB_FIXEDWIDTH controls
108 virtual void SetTabSize(const wxSize& sz) = 0;
109
110 // calculate the size of the notebook from the size of its page
111 virtual wxSize CalcSizeFromPage(const wxSize& sizePage);
112
113 // operations
114 // ----------
115
116 // remove one page from the notebook and delete it
117 virtual bool DeletePage(int nPage);
118
119 // remove one page from the notebook, without deleting it
120 virtual bool RemovePage(int nPage) { return DoRemovePage(nPage) != NULL; }
121
122 // remove all pages and delete them
123 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages); return TRUE; }
124
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,
130 int imageId = -1)
131 {
132 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
133 }
134
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;
141
142 // set the currently selected page, return the index of the previously
143 // selected one (or -1 on error)
144 //
145 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
146 virtual int SetSelection(int nPage) = 0;
147
148 // cycle thru the tabs
149 void AdvanceSelection(bool forward = TRUE)
150 {
151 int nPage = GetNextPage(forward);
152 if ( nPage != -1 )
153 SetSelection(nPage);
154 }
155
156 protected:
157 // remove the page and return a pointer to it
158 virtual wxNotebookPage *DoRemovePage(int page);
159
160 // common part of all ctors
161 void Init();
162
163 // get the next page wrapping if we reached the end
164 int GetNextPage(bool forward) const;
165
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
169 };
170
171 // ----------------------------------------------------------------------------
172 // notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
173 // ----------------------------------------------------------------------------
174
175 class WXDLLEXPORT wxNotebookEvent : public wxNotifyEvent
176 {
177 public:
178 wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
179 int nSel = -1, int nOldSel = -1)
180 : wxNotifyEvent(commandType, id)
181 {
182 m_nSel = nSel;
183 m_nOldSel = nOldSel;
184 }
185
186 // accessors
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; }
193
194 private:
195 int m_nSel, // currently selected page
196 m_nOldSel; // previously selected page
197
198 DECLARE_DYNAMIC_CLASS(wxNotebookEvent)
199 };
200
201 // ----------------------------------------------------------------------------
202 // event types and macros for them
203 // ----------------------------------------------------------------------------
204
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
209 #endif
210
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()
215
216 typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
217
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, \
223 id, \
224 -1, \
225 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
226 NULL \
227 ),
228
229 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
230 DECLARE_EVENT_TABLE_ENTRY( \
231 wxEVT_COMMAND_NB_PAGE_CHANGING, \
232 id, \
233 -1, \
234 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
235 NULL \
236 ),
237
238 #else
239
240 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
241 DECLARE_EVENT_TABLE_ENTRY( \
242 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
243 id, \
244 -1, \
245 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
246 NULL \
247 ),
248
249 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
250 DECLARE_EVENT_TABLE_ENTRY( \
251 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
252 id, \
253 -1, \
254 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
255 NULL \
256 ),
257
258 #endif
259
260 // ----------------------------------------------------------------------------
261 // wxNotebook class itself
262 // ----------------------------------------------------------------------------
263
264 #if defined(__WXUNIVERSAL__)
265 #include "wx/univ/notebook.h"
266 #elif defined(__WXMSW__)
267 #ifdef __WIN16__
268 #include "wx/generic/notebook.h"
269 #else
270 #include "wx/msw/notebook.h"
271 #endif
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"
284 #endif
285
286 #endif // wxUSE_NOTEBOOK
287
288 #endif
289 // _WX_NOTEBOOK_H_BASE_