]> git.saurik.com Git - wxWidgets.git/blob - include/wx/notebook.h
generate a text event even if SetValue() didn't really chaneg anything
[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& WXUNUSED(pt),
163 long * WXUNUSED(flags) = NULL) const
164 {
165 return wxNOT_FOUND;
166 }
167
168 // cycle thru the tabs
169 void AdvanceSelection(bool forward = TRUE)
170 {
171 int nPage = GetNextPage(forward);
172 if ( nPage != -1 )
173 SetSelection(nPage);
174 }
175
176 protected:
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;
181
182 // common part of all ctors
183 void Init();
184
185 // get the next page wrapping if we reached the end
186 int GetNextPage(bool forward) const;
187
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
191
192 DECLARE_NO_COPY_CLASS(wxNotebookBase)
193 };
194
195 // ----------------------------------------------------------------------------
196 // notebook event class (used by NOTEBOOK_PAGE_CHANGED/ING events)
197 // ----------------------------------------------------------------------------
198
199 class WXDLLEXPORT wxNotebookEvent : public wxNotifyEvent
200 {
201 public:
202 wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
203 int nSel = -1, int nOldSel = -1)
204 : wxNotifyEvent(commandType, id)
205 {
206 m_nSel = nSel;
207 m_nOldSel = nOldSel;
208 }
209
210 // accessors
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; }
217
218 private:
219 int m_nSel, // currently selected page
220 m_nOldSel; // previously selected page
221
222 DECLARE_DYNAMIC_CLASS_NO_COPY(wxNotebookEvent)
223 };
224
225 // ----------------------------------------------------------------------------
226 // event types and macros for them
227 // ----------------------------------------------------------------------------
228
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()
233
234 typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
235
236 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
237 DECLARE_EVENT_TABLE_ENTRY( \
238 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
239 id, \
240 -1, \
241 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
242 NULL \
243 ),
244
245 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
246 DECLARE_EVENT_TABLE_ENTRY( \
247 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \
248 id, \
249 -1, \
250 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
251 NULL \
252 ),
253
254 // ----------------------------------------------------------------------------
255 // wxNotebook class itself
256 // ----------------------------------------------------------------------------
257
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"
272 #endif
273
274 #endif // wxUSE_NOTEBOOK
275
276 #endif
277 // _WX_NOTEBOOK_H_BASE_