]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/notebook.h
b75bc7f22833ac14b68d2c68b9143ba2fb88d1cf
[wxWidgets.git] / include / wx / msw / notebook.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/notebook.h
3 // Purpose: MSW/GTK compatible notebook (a.k.a. property sheet)
4 // Author: Robert Roebling
5 // Modified by: Vadim Zeitlin for Windows version
6 // RCS-ID: $Id$
7 // Copyright: (c) Julian Smart and Markus Holzem
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _NOTEBOOK_H
12 #define _NOTEBOOK_H
13
14 #ifdef __GNUG__
15 #pragma interface "notebook.h"
16 #endif
17
18 // ----------------------------------------------------------------------------
19 // headers
20 // ----------------------------------------------------------------------------
21 #ifndef _DYNARRAY_H
22 #include <wx/dynarray.h>
23 #endif //_DYNARRAY_H
24
25 // ----------------------------------------------------------------------------
26 // types
27 // ----------------------------------------------------------------------------
28
29 // fwd declarations
30 class WXDLLEXPORT wxImageList;
31 class WXDLLEXPORT wxWindow;
32
33 // array of notebook pages
34 typedef wxWindow WXDLLEXPORT wxNotebookPage; // so far, any window can be a page
35
36 #undef WXDLLEXPORTLOCAL
37 #define WXDLLEXPORTLOCAL WXDLLEXPORT
38
39 WX_DEFINE_ARRAY(wxNotebookPage *, wxArrayPages);
40
41 #undef WXDLLEXPORTLOCAL
42 #define WXDLLEXPORTLOCAL
43
44 // ----------------------------------------------------------------------------
45 // notebook events
46 // ----------------------------------------------------------------------------
47 class WXDLLEXPORT wxNotebookEvent : public wxCommandEvent
48 {
49 public:
50 wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0,
51 int nSel = -1, int nOldSel = -1)
52 : wxCommandEvent(commandType, id) { m_nSel = nSel; m_nOldSel = nOldSel; }
53
54 // accessors
55 // the currently selected page (-1 if none)
56 int GetSelection() const { return m_nSel; }
57 void SetSelection(int nSel) { m_nSel = nSel; }
58 // the page that was selected before the change (-1 if none)
59 int GetOldSelection() const { return m_nOldSel; }
60 void SetOldSelection(int nOldSel) { m_nOldSel = nOldSel; }
61
62 private:
63 int m_nSel, // currently selected page
64 m_nOldSel; // previously selected page
65
66 DECLARE_DYNAMIC_CLASS(wxNotebookEvent)
67 };
68
69 // ----------------------------------------------------------------------------
70 // wxNotebook
71 // ----------------------------------------------------------------------------
72
73 // @@@ this class should really derive from wxTabCtrl, but the interface is not
74 // exactly the same, so I can't do it right now and instead we reimplement
75 // part of wxTabCtrl here
76 class WXDLLEXPORT wxNotebook : public wxControl
77 {
78 public:
79 // ctors
80 // -----
81 // default for dynamic class
82 wxNotebook();
83 // the same arguments as for wxControl (@@@ any special styles?)
84 wxNotebook(wxWindow *parent,
85 wxWindowID id,
86 const wxPoint& pos = wxDefaultPosition,
87 const wxSize& size = wxDefaultSize,
88 long style = 0,
89 const wxString& name = "notebook");
90 // Create() function
91 bool Create(wxWindow *parent,
92 wxWindowID id,
93 const wxPoint& pos = wxDefaultPosition,
94 const wxSize& size = wxDefaultSize,
95 long style = 0,
96 const wxString& name = "notebook");
97 // dtor
98 ~wxNotebook();
99
100 // accessors
101 // ---------
102 // get number of pages in the dialog
103 int GetPageCount() const;
104
105 // set the currently selected page, return the index of the previously
106 // selected one (or -1 on error)
107 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
108 int SetSelection(int nPage);
109 // cycle thru the tabs
110 void AdvanceSelection(bool bForward = TRUE);
111 // get the currently selected page
112 int GetSelection() const { return m_nSelection; }
113
114 // set/get the title of a page
115 bool SetPageText(int nPage, const wxString& strText);
116 wxString GetPageText(int nPage) const;
117
118 // image list stuff: each page may have an image associated with it. All
119 // the images belong to an image list, so you have to
120 // 1) create an image list
121 // 2) associate it with the notebook
122 // 3) set for each page it's image
123 // associate image list with a control
124 void SetImageList(wxImageList* imageList);
125 // get pointer (may be NULL) to the associated image list
126 wxImageList* GetImageList() const { return m_pImageList; }
127
128 // sets/returns item's image index in the current image list
129 int GetPageImage(int nPage) const;
130 bool SetPageImage(int nPage, int nImage);
131
132 // currently it's always 1 because wxGTK doesn't support multi-row
133 // tab controls
134 int GetRowCount() const;
135
136 // control the appearance of the notebook pages
137 // set the size (the same for all pages)
138 void SetPageSize(const wxSize& size);
139 // set the padding between tabs (in pixels)
140 void SetPadding(const wxSize& padding);
141
142 // operations
143 // ----------
144 // remove one page from the notebook
145 bool DeletePage(int nPage);
146 // remove one page from the notebook, without deleting
147 bool RemovePage(int nPage);
148 // remove all pages
149 bool DeleteAllPages();
150 // adds a new page to the notebook (it will be deleted ny the notebook,
151 // don't delete it yourself). If bSelect, this page becomes active.
152 bool AddPage(wxNotebookPage *pPage,
153 const wxString& strText,
154 bool bSelect = FALSE,
155 int imageId = -1);
156 // the same as AddPage(), but adds it at the specified position
157 bool InsertPage(int nPage,
158 wxNotebookPage *pPage,
159 const wxString& strText,
160 bool bSelect = FALSE,
161 int imageId = -1);
162 // get the panel which represents the given page
163 wxNotebookPage *GetPage(int nPage) { return m_aPages[nPage]; }
164
165 // callbacks
166 // ---------
167 void OnSize(wxSizeEvent& event);
168 void OnSelChange(wxNotebookEvent& event);
169 void OnSetFocus(wxFocusEvent& event);
170 void OnNavigationKey(wxNavigationKeyEvent& event);
171 void OnEraseBackground(wxEraseEvent& event);
172
173 // base class virtuals
174 // -------------------
175 virtual void Command(wxCommandEvent& event);
176 virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam);
177 virtual void SetConstraintSizes(bool recurse = TRUE);
178 virtual bool DoPhase(int nPhase);
179
180 protected:
181 // common part of all ctors
182 void Init();
183
184 // helper functions
185 void ChangePage(int nOldSel, int nSel); // change pages
186
187 wxImageList *m_pImageList; // we can have an associated image list
188 wxArrayPages m_aPages; // array of pages
189
190 int m_nSelection; // the current selection (-1 if none)
191
192 DECLARE_DYNAMIC_CLASS(wxNotebook)
193 DECLARE_EVENT_TABLE()
194 };
195
196 // ----------------------------------------------------------------------------
197 // event macros
198 // ----------------------------------------------------------------------------
199 typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
200
201 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
202 { \
203 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
204 id, \
205 -1, \
206 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
207 NULL \
208 },
209
210 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
211 { \
212 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \
213 id, \
214 -1, \
215 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
216 NULL \
217 },
218
219 #endif // _NOTEBOOK_H