]> git.saurik.com Git - wxWidgets.git/blob - include/wx/motif/notebook.h
Motif and other mods
[wxWidgets.git] / include / wx / motif / notebook.h
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 private:
53 int m_nSel, // currently selected page
54 m_nOldSel; // previously selected page
55
56 DECLARE_DYNAMIC_CLASS(wxNotebookEvent)
57 };
58
59 // ----------------------------------------------------------------------------
60 // wxNotebook
61 // ----------------------------------------------------------------------------
62
63 class WXDLLEXPORT wxNotebook;
64
65 // This reuses wxTabView to draw the tabs.
66 class WXDLLEXPORT wxNotebookTabView: public wxTabView
67 {
68 DECLARE_DYNAMIC_CLASS(wxNotebookTabView)
69 public:
70 wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
71 ~wxNotebookTabView(void);
72
73 // Called when a tab is activated
74 virtual void OnTabActivate(int activateId, int deactivateId);
75
76 /*
77 // Specific to this class
78 void AddTabWindow(int id, wxWindow *window);
79 wxWindow *GetTabWindow(int id) const ;
80 void ClearWindows(bool deleteWindows = TRUE);
81 inline wxWindow *GetCurrentWindow() const { return m_currentWindow; }
82 void ShowWindowForTab(int id);
83 */
84
85 protected:
86 /*
87 // List of panels, one for each tab. Indexed
88 // by tab ID.
89 wxList m_tabWindows;
90 wxWindow* m_currentWindow;
91 */
92 wxNotebook* m_notebook;
93 };
94
95 class wxNotebook : public wxControl
96 {
97 public:
98 // ctors
99 // -----
100 // default for dynamic class
101 wxNotebook();
102 // the same arguments as for wxControl (@@@ any special styles?)
103 wxNotebook(wxWindow *parent,
104 wxWindowID id,
105 const wxPoint& pos = wxDefaultPosition,
106 const wxSize& size = wxDefaultSize,
107 long style = 0,
108 const wxString& name = "notebook");
109 // Create() function
110 bool Create(wxWindow *parent,
111 wxWindowID id,
112 const wxPoint& pos = wxDefaultPosition,
113 const wxSize& size = wxDefaultSize,
114 long style = 0,
115 const wxString& name = "notebook");
116 // dtor
117 ~wxNotebook();
118
119 // accessors
120 // ---------
121 // get number of pages in the dialog
122 int GetPageCount() const;
123
124 // set the currently selected page, return the index of the previously
125 // selected one (or -1 on error)
126 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
127 int SetSelection(int nPage);
128 // cycle thru the tabs
129 void AdvanceSelection(bool bForward = TRUE);
130 // get the currently selected page
131 int GetSelection() const { return m_nSelection; }
132
133 // set/get the title of a page
134 bool SetPageText(int nPage, const wxString& strText);
135 wxString GetPageText(int nPage) const;
136
137 // image list stuff: each page may have an image associated with it. All
138 // the images belong to an image list, so you have to
139 // 1) create an image list
140 // 2) associate it with the notebook
141 // 3) set for each page it's image
142 // associate image list with a control
143 void SetImageList(wxImageList* imageList);
144 // get pointer (may be NULL) to the associated image list
145 wxImageList* GetImageList() const { return m_pImageList; }
146
147 // sets/returns item's image index in the current image list
148 int GetPageImage(int nPage) const;
149 bool SetPageImage(int nPage, int nImage);
150
151 // currently it's always 1 because wxGTK doesn't support multi-row
152 // tab controls
153 int GetRowCount() const;
154
155 // control the appearance of the notebook pages
156 // set the size (the same for all pages)
157 void SetPageSize(const wxSize& size);
158 // set the padding between tabs (in pixels)
159 void SetPadding(const wxSize& padding);
160
161 // operations
162 // ----------
163 // remove one page from the notebook
164 bool DeletePage(int nPage);
165 // remove all pages
166 bool DeleteAllPages();
167 // adds a new page to the notebook (it will be deleted ny the notebook,
168 // don't delete it yourself). If bSelect, this page becomes active.
169 bool AddPage(wxNotebookPage *pPage,
170 const wxString& strText,
171 bool bSelect = FALSE,
172 int imageId = -1);
173 // the same as AddPage(), but adds it at the specified position
174 bool InsertPage(int nPage,
175 wxNotebookPage *pPage,
176 const wxString& strText,
177 bool bSelect = FALSE,
178 int imageId = -1);
179 // get the panel which represents the given page
180 wxNotebookPage *GetPage(int nPage) { return m_aPages[nPage]; }
181
182 // callbacks
183 // ---------
184 void OnSize(wxSizeEvent& event);
185 void OnSelChange(wxNotebookEvent& event);
186 void OnSetFocus(wxFocusEvent& event);
187 void OnNavigationKey(wxNavigationKeyEvent& event);
188
189 // base class virtuals
190 // -------------------
191 virtual void Command(wxCommandEvent& event);
192 virtual void SetConstraintSizes(bool recurse = TRUE);
193 virtual bool DoPhase(int nPhase);
194
195 // Implementation
196
197 // wxNotebook on Motif uses a generic wxTabView to implement itself.
198 inline wxTabView *GetTabView() const { return m_tabView; }
199 inline void SetTabView(wxTabView *v) { m_tabView = v; }
200
201 void OnMouseEvent(wxMouseEvent& event);
202 void OnPaint(wxPaintEvent& event);
203
204 virtual void ChangeFont(bool keepOriginalSize = TRUE);
205 virtual void ChangeBackgroundColour();
206 virtual void ChangeForegroundColour();
207
208 protected:
209 // common part of all ctors
210 void Init();
211
212 // helper functions
213 void ChangePage(int nOldSel, int nSel); // change pages
214
215 wxImageList *m_pImageList; // we can have an associated image list
216 wxArrayPages m_aPages; // array of pages
217
218 int m_nSelection; // the current selection (-1 if none)
219
220 wxTabView* m_tabView;
221
222 DECLARE_DYNAMIC_CLASS(wxNotebook)
223 DECLARE_EVENT_TABLE()
224 };
225
226 // ----------------------------------------------------------------------------
227 // event macros
228 // ----------------------------------------------------------------------------
229 typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
230
231 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
232 { \
233 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
234 id, \
235 -1, \
236 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
237 NULL \
238 },
239
240 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
241 { \
242 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \
243 id, \
244 -1, \
245 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
246 NULL \
247 },
248
249 #endif // _WX_NOTEBOOK_H_