]>
Commit | Line | Data |
---|---|---|
1e6d9499 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: notebook.h | |
3 | // Purpose: wxNotebook class (a.k.a. property sheet, tabbed dialog) | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) Julian Smart | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_NOTEBOOK_H_ | |
12 | #define _WX_NOTEBOOK_H_ | |
13 | ||
14 | #ifdef __GNUG__ | |
15 | #pragma interface "notebook.h" | |
16 | #endif | |
17 | ||
18 | // ---------------------------------------------------------------------------- | |
19 | // headers | |
20 | // ---------------------------------------------------------------------------- | |
21 | #include "wx/dynarray.h" | |
22 | #include "wx/event.h" | |
23 | #include "wx/control.h" | |
24 | #include "wx/generic/tabg.h" | |
25 | ||
26 | // ---------------------------------------------------------------------------- | |
27 | // types | |
28 | // ---------------------------------------------------------------------------- | |
29 | ||
30 | // fwd declarations | |
31 | class WXDLLEXPORT wxImageList; | |
32 | class WXDLLEXPORT wxWindow; | |
33 | ||
34 | // array of notebook pages | |
35 | typedef wxWindow wxNotebookPage; // so far, any window can be a page | |
36 | WX_DEFINE_ARRAY(wxNotebookPage *, wxArrayPages); | |
37 | ||
38 | // ---------------------------------------------------------------------------- | |
39 | // notebook events | |
40 | // ---------------------------------------------------------------------------- | |
41 | class WXDLLEXPORT wxNotebookEvent : public wxCommandEvent | |
42 | { | |
43 | public: | |
44 | wxNotebookEvent(wxEventType commandType = wxEVT_NULL, int id = 0, | |
45 | int nSel = -1, int nOldSel = -1) | |
46 | : wxCommandEvent(commandType, id) { m_nSel = nSel; m_nOldSel = nOldSel; } | |
47 | ||
48 | // accessors | |
49 | int GetSelection() const { return m_nSel; } | |
50 | int GetOldSelection() const { return m_nOldSel; } | |
51 | ||
52 | void SetSelection(int sel) { m_nSel = sel; } | |
53 | void SetOldSelection(int oldSel) { m_nOldSel = oldSel; } | |
54 | ||
55 | private: | |
56 | int m_nSel, // currently selected page | |
57 | m_nOldSel; // previously selected page | |
58 | ||
59 | DECLARE_DYNAMIC_CLASS(wxNotebookEvent) | |
60 | }; | |
61 | ||
62 | // ---------------------------------------------------------------------------- | |
63 | // wxNotebook | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
66 | class WXDLLEXPORT wxNotebook; | |
67 | ||
68 | // This reuses wxTabView to draw the tabs. | |
69 | class WXDLLEXPORT wxNotebookTabView: public wxTabView | |
70 | { | |
71 | DECLARE_DYNAMIC_CLASS(wxNotebookTabView) | |
72 | public: | |
73 | wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR); | |
74 | ~wxNotebookTabView(void); | |
75 | ||
76 | // Called when a tab is activated | |
77 | virtual void OnTabActivate(int activateId, int deactivateId); | |
78 | ||
79 | protected: | |
80 | wxNotebook* m_notebook; | |
81 | }; | |
82 | ||
83 | class wxNotebook : public wxControl | |
84 | { | |
85 | public: | |
86 | // ctors | |
87 | // ----- | |
88 | // default for dynamic class | |
89 | wxNotebook(); | |
90 | // the same arguments as for wxControl (@@@ any special styles?) | |
91 | wxNotebook(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 | // Create() function | |
98 | bool Create(wxWindow *parent, | |
99 | wxWindowID id, | |
100 | const wxPoint& pos = wxDefaultPosition, | |
101 | const wxSize& size = wxDefaultSize, | |
102 | long style = 0, | |
103 | const wxString& name = "notebook"); | |
104 | // dtor | |
105 | ~wxNotebook(); | |
106 | ||
107 | // accessors | |
108 | // --------- | |
109 | // get number of pages in the dialog | |
110 | int GetPageCount() const; | |
111 | ||
112 | // Find the position of the wxNotebookPage, -1 if not found. | |
113 | int FindPagePosition(wxNotebookPage* page) const; | |
114 | ||
115 | // set the currently selected page, return the index of the previously | |
116 | // selected one (or -1 on error) | |
117 | // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events | |
118 | int SetSelection(int nPage); | |
119 | // cycle thru the tabs | |
120 | void AdvanceSelection(bool bForward = TRUE); | |
121 | // get the currently selected page | |
122 | int GetSelection() const { return m_nSelection; } | |
123 | ||
124 | // set/get the title of a page | |
125 | bool SetPageText(int nPage, const wxString& strText); | |
126 | wxString GetPageText(int nPage) const; | |
127 | ||
128 | // image list stuff: each page may have an image associated with it. All | |
129 | // the images belong to an image list, so you have to | |
130 | // 1) create an image list | |
131 | // 2) associate it with the notebook | |
132 | // 3) set for each page it's image | |
133 | // associate image list with a control | |
134 | void SetImageList(wxImageList* imageList); | |
135 | // get pointer (may be NULL) to the associated image list | |
136 | wxImageList* GetImageList() const { return m_pImageList; } | |
137 | ||
138 | // sets/returns item's image index in the current image list | |
139 | int GetPageImage(int nPage) const; | |
140 | bool SetPageImage(int nPage, int nImage); | |
141 | ||
142 | // currently it's always 1 because wxGTK doesn't support multi-row | |
143 | // tab controls | |
144 | int GetRowCount() const; | |
145 | ||
146 | // control the appearance of the notebook pages | |
147 | // set the size (the same for all pages) | |
148 | void SetPageSize(const wxSize& size); | |
149 | // set the padding between tabs (in pixels) | |
150 | void SetPadding(const wxSize& padding); | |
151 | ||
152 | // operations | |
153 | // ---------- | |
154 | // remove one page from the notebook, and delete the page. | |
155 | bool DeletePage(int nPage); | |
156 | bool DeletePage(wxNotebookPage* page); | |
157 | // remove one page from the notebook, without deleting the page. | |
158 | bool RemovePage(int nPage); | |
159 | bool RemovePage(wxNotebookPage* page); | |
160 | // remove all pages | |
161 | bool DeleteAllPages(); | |
162 | // adds a new page to the notebook (it will be deleted ny the notebook, | |
163 | // don't delete it yourself). If bSelect, this page becomes active. | |
164 | bool AddPage(wxNotebookPage *pPage, | |
165 | const wxString& strText, | |
166 | bool bSelect = FALSE, | |
167 | int imageId = -1); | |
168 | // the same as AddPage(), but adds it at the specified position | |
169 | bool InsertPage(int nPage, | |
170 | wxNotebookPage *pPage, | |
171 | const wxString& strText, | |
172 | bool bSelect = FALSE, | |
173 | int imageId = -1); | |
174 | // get the panel which represents the given page | |
175 | wxNotebookPage *GetPage(int nPage) { return m_aPages[nPage]; } | |
176 | ||
177 | // callbacks | |
178 | // --------- | |
179 | void OnSize(wxSizeEvent& event); | |
180 | void OnIdle(wxIdleEvent& event); | |
181 | void OnSelChange(wxNotebookEvent& event); | |
182 | void OnSetFocus(wxFocusEvent& event); | |
183 | void OnNavigationKey(wxNavigationKeyEvent& event); | |
184 | ||
185 | // base class virtuals | |
186 | // ------------------- | |
187 | virtual void Command(wxCommandEvent& event); | |
188 | virtual void SetConstraintSizes(bool recurse = TRUE); | |
189 | virtual bool DoPhase(int nPhase); | |
190 | ||
191 | // Implementation | |
192 | ||
193 | // wxNotebook on Motif uses a generic wxTabView to implement itself. | |
194 | inline wxTabView *GetTabView() const { return m_tabView; } | |
195 | inline void SetTabView(wxTabView *v) { m_tabView = v; } | |
196 | ||
197 | void OnMouseEvent(wxMouseEvent& event); | |
198 | void OnPaint(wxPaintEvent& event); | |
199 | ||
200 | virtual wxRect GetAvailableClientSize(); | |
201 | ||
202 | // Implementation: calculate the layout of the view rect | |
203 | // and resize the children if required | |
204 | bool RefreshLayout(bool force = TRUE); | |
205 | ||
206 | protected: | |
207 | // common part of all ctors | |
208 | void Init(); | |
209 | ||
210 | // helper functions | |
211 | void ChangePage(int nOldSel, int nSel); // change pages | |
212 | ||
213 | wxImageList *m_pImageList; // we can have an associated image list | |
214 | wxArrayPages m_aPages; // array of pages | |
215 | ||
216 | int m_nSelection; // the current selection (-1 if none) | |
217 | ||
218 | wxTabView* m_tabView; | |
219 | ||
220 | DECLARE_DYNAMIC_CLASS(wxNotebook) | |
221 | DECLARE_EVENT_TABLE() | |
222 | }; | |
223 | ||
224 | // ---------------------------------------------------------------------------- | |
225 | // event macros | |
226 | // ---------------------------------------------------------------------------- | |
227 | typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&); | |
228 | ||
62448488 JS |
229 | // Because of name truncation! |
230 | #if defined(__BORLANDC__) && defined(__WIN16__) | |
231 | ||
232 | #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \ | |
233 | { \ | |
234 | wxEVT_COMMAND_NB_PAGE_CHANGED, \ | |
235 | id, \ | |
236 | -1, \ | |
237 | (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \ | |
238 | NULL \ | |
239 | }, | |
240 | ||
241 | #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \ | |
242 | { \ | |
243 | wxEVT_COMMAND_NB_PAGE_CHANGING, \ \ | |
244 | id, \ | |
245 | -1, \ | |
246 | (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \ | |
247 | NULL \ | |
248 | }, | |
249 | ||
250 | #else | |
251 | ||
1e6d9499 JS |
252 | #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \ |
253 | { \ | |
254 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \ | |
255 | id, \ | |
256 | -1, \ | |
257 | (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \ | |
258 | NULL \ | |
259 | }, | |
260 | ||
261 | #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \ | |
262 | { \ | |
263 | wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \ | |
264 | id, \ | |
265 | -1, \ | |
266 | (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \ | |
267 | NULL \ | |
268 | }, | |
269 | ||
62448488 JS |
270 | #endif |
271 | ||
1e6d9499 | 272 | #endif // _WX_NOTEBOOK_H_ |