added NO_PTR versions of ARRAY macros to suppress warnings (based on patch 770983)
[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 #if defined(__GNUG__) && !defined(__APPLE__)
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 #include "wx/imaglist.h"
30
31 // ----------------------------------------------------------------------------
32 // constants
33 // ----------------------------------------------------------------------------
34
35 // wxNotebook hit results
36 enum
37 {
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
42 };
43
44 // ----------------------------------------------------------------------------
45 // types
46 // ----------------------------------------------------------------------------
47
48 // array of notebook pages
49 typedef wxWindow wxNotebookPage; // so far, any window can be a page
50
51 WX_DEFINE_EXPORTED_ARRAY_NO_PTR(wxNotebookPage *, wxArrayPages);
52
53 #define wxNOTEBOOK_NAME _T("notebook")
54
55 // ----------------------------------------------------------------------------
56 // wxNotebookBase: define wxNotebook interface
57 // ----------------------------------------------------------------------------
58
59 class WXDLLEXPORT wxNotebookBase : public wxControl
60 {
61 public:
62 // ctor
63 wxNotebookBase()
64 {
65 Init();
66 }
67
68 // quasi ctor
69 bool Create(wxWindow *parent,
70 wxWindowID id,
71 const wxPoint& pos = wxDefaultPosition,
72 const wxSize& size = wxDefaultSize,
73 long style = 0,
74 const wxString& name = wxNOTEBOOK_NAME);
75
76 // dtor
77 virtual ~wxNotebookBase();
78
79 // accessors
80 // ---------
81
82 // get number of pages in the dialog
83 int GetPageCount() const { return (int) m_pages.GetCount(); }
84
85 // get the panel which represents the given page
86 wxNotebookPage *GetPage(int nPage) { return m_pages[nPage]; }
87
88 // get the currently selected page
89 virtual int GetSelection() const = 0;
90
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;
94
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);
98
99 // as SetImageList() but we will delete the image list ourselves
100 void AssignImageList(wxImageList* imageList);
101
102 // get pointer (may be NULL) to the associated image list
103 wxImageList* GetImageList() const { return m_imageList; }
104
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;
108
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; }
112
113 // set the size (the same for all pages)
114 virtual void SetPageSize(const wxSize& size) = 0;
115
116 // set the padding between tabs (in pixels)
117 virtual void SetPadding(const wxSize& padding) = 0;
118
119 // set the size of the tabs for wxNB_FIXEDWIDTH controls
120 virtual void SetTabSize(const wxSize& sz) = 0;
121
122 // calculate the size of the notebook from the size of its page
123 virtual wxSize CalcSizeFromPage(const wxSize& sizePage) const;
124
125 // operations
126 // ----------
127
128 // remove one page from the notebook and delete it
129 virtual bool DeletePage(int nPage);
130
131 // remove one page from the notebook, without deleting it
132 virtual bool RemovePage(int nPage) { return DoRemovePage(nPage) != NULL; }
133
134 // remove all pages and delete them
135 virtual bool DeleteAllPages() { WX_CLEAR_ARRAY(m_pages); return TRUE; }
136
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,
142 int imageId = -1)
143 {
144 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
145 }
146
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;
153
154 // set the currently selected page, return the index of the previously
155 // selected one (or -1 on error)
156 //
157 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
158 virtual int SetSelection(int nPage) = 0;
159
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
163 {
164 return wxNOT_FOUND;
165 }
166
167 // cycle thru the tabs
168 void AdvanceSelection(bool forward = TRUE)
169 {
170 int nPage = GetNextPage(forward);
171 if ( nPage != -1 )
172 SetSelection(nPage);
173 }
174
175 protected:
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;
180
181 // common part of all ctors
182 void Init();
183
184 // get the next page wrapping if we reached the end
185 int GetNextPage(bool forward) const;
186
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
190
191 DECLARE_NO_COPY_CLASS(wxNotebookBase)
192 };
193
194 // ----------------------------------------------------------------------------
195 // notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
196 // ----------------------------------------------------------------------------
197
198 class WXDLLEXPORT wxNotebookEvent : public wxNotifyEvent
199 {
200 public:
201 wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
202 int nSel = -1, int nOldSel = -1)
203 : wxNotifyEvent(commandType, id)
204 {
205 m_nSel = nSel;
206 m_nOldSel = nOldSel;
207 }
208
209 // accessors
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; }
216
217 private:
218 int m_nSel, // currently selected page
219 m_nOldSel; // previously selected page
220
221 DECLARE_DYNAMIC_CLASS(wxNotebookEvent)
222 };
223
224 // ----------------------------------------------------------------------------
225 // event types and macros for them
226 // ----------------------------------------------------------------------------
227
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()
232
233 typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
234
235 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
236 DECLARE_EVENT_TABLE_ENTRY( \
237 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
238 id, \
239 -1, \
240 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
241 NULL \
242 ),
243
244 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
245 DECLARE_EVENT_TABLE_ENTRY( \
246 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
247 id, \
248 -1, \
249 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
250 NULL \
251 ),
252
253 // ----------------------------------------------------------------------------
254 // wxNotebook class itself
255 // ----------------------------------------------------------------------------
256
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"
271 #endif
272
273 #endif // wxUSE_NOTEBOOK
274
275 #endif
276 // _WX_NOTEBOOK_H_BASE_