1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxNotebook class (a.k.a. property sheet, tabbed dialog)
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_NOTEBOOK_H_
12 #define _WX_NOTEBOOK_H_
15 #pragma interface "notebook.h"
18 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
21 #include "wx/dynarray.h"
23 #include "wx/control.h"
24 #include "wx/generic/tabg.h"
26 // ----------------------------------------------------------------------------
28 // ----------------------------------------------------------------------------
31 class WXDLLEXPORT wxImageList
;
32 class WXDLLEXPORT wxWindow
;
34 // array of notebook pages
35 typedef wxWindow wxNotebookPage
; // so far, any window can be a page
36 WX_DEFINE_ARRAY(wxNotebookPage
*, wxArrayPages
);
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
41 class WXDLLEXPORT wxNotebookEvent
: public wxCommandEvent
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
; }
49 int GetSelection() const { return m_nSel
; }
50 int GetOldSelection() const { return m_nOldSel
; }
53 int m_nSel
, // currently selected page
54 m_nOldSel
; // previously selected page
56 DECLARE_DYNAMIC_CLASS(wxNotebookEvent
)
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 class WXDLLEXPORT wxNotebook
;
65 // This reuses wxTabView to draw the tabs.
66 class WXDLLEXPORT wxNotebookTabView
: public wxTabView
68 DECLARE_DYNAMIC_CLASS(wxNotebookTabView
)
70 wxNotebookTabView(wxNotebook
* notebook
, long style
= wxTAB_STYLE_DRAW_BOX
| wxTAB_STYLE_COLOUR_INTERIOR
);
71 ~wxNotebookTabView(void);
73 // Called when a tab is activated
74 virtual void OnTabActivate(int activateId
, int deactivateId
);
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);
87 // List of panels, one for each tab. Indexed
90 wxWindow* m_currentWindow;
92 wxNotebook
* m_notebook
;
95 class wxNotebook
: public wxControl
100 // default for dynamic class
102 // the same arguments as for wxControl (@@@ any special styles?)
103 wxNotebook(wxWindow
*parent
,
105 const wxPoint
& pos
= wxDefaultPosition
,
106 const wxSize
& size
= wxDefaultSize
,
108 const wxString
& name
= "notebook");
110 bool Create(wxWindow
*parent
,
112 const wxPoint
& pos
= wxDefaultPosition
,
113 const wxSize
& size
= wxDefaultSize
,
115 const wxString
& name
= "notebook");
121 // get number of pages in the dialog
122 int GetPageCount() const;
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
; }
133 // set/get the title of a page
134 bool SetPageText(int nPage
, const wxString
& strText
);
135 wxString
GetPageText(int nPage
) const;
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
; }
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
);
151 // currently it's always 1 because wxGTK doesn't support multi-row
153 int GetRowCount() const;
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
);
163 // remove one page from the notebook
164 bool DeletePage(int nPage
);
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
,
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
,
179 // get the panel which represents the given page
180 wxNotebookPage
*GetPage(int nPage
) { return m_aPages
[nPage
]; }
184 void OnSize(wxSizeEvent
& event
);
185 void OnSelChange(wxNotebookEvent
& event
);
186 void OnSetFocus(wxFocusEvent
& event
);
187 void OnNavigationKey(wxNavigationKeyEvent
& event
);
189 // base class virtuals
190 // -------------------
191 virtual void Command(wxCommandEvent
& event
);
192 virtual void SetConstraintSizes(bool recurse
= TRUE
);
193 virtual bool DoPhase(int nPhase
);
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
; }
201 void OnMouseEvent(wxMouseEvent
& event
);
202 void OnPaint(wxPaintEvent
& event
);
204 virtual void ChangeFont(bool keepOriginalSize
= TRUE
);
205 virtual void ChangeBackgroundColour();
206 virtual void ChangeForegroundColour();
209 // common part of all ctors
213 void ChangePage(int nOldSel
, int nSel
); // change pages
215 wxImageList
*m_pImageList
; // we can have an associated image list
216 wxArrayPages m_aPages
; // array of pages
218 int m_nSelection
; // the current selection (-1 if none)
220 wxTabView
* m_tabView
;
222 DECLARE_DYNAMIC_CLASS(wxNotebook
)
223 DECLARE_EVENT_TABLE()
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
229 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
231 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
233 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
236 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
240 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
242 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \
245 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
249 #endif // _WX_NOTEBOOK_H_