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
; }
52 void SetSelection(int sel
) { m_nSel
= sel
; }
53 void SetOldSelection(int oldSel
) { m_nOldSel
= oldSel
; }
56 int m_nSel
, // currently selected page
57 m_nOldSel
; // previously selected page
59 DECLARE_DYNAMIC_CLASS(wxNotebookEvent
)
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 class WXDLLEXPORT wxNotebook
;
68 // This reuses wxTabView to draw the tabs.
69 class WXDLLEXPORT wxNotebookTabView
: public wxTabView
71 DECLARE_DYNAMIC_CLASS(wxNotebookTabView
)
73 wxNotebookTabView(wxNotebook
* notebook
, long style
= wxTAB_STYLE_DRAW_BOX
| wxTAB_STYLE_COLOUR_INTERIOR
);
74 ~wxNotebookTabView(void);
76 // Called when a tab is activated
77 virtual void OnTabActivate(int activateId
, int deactivateId
);
80 wxNotebook
* m_notebook
;
83 class wxNotebook
: public wxControl
88 // default for dynamic class
90 // the same arguments as for wxControl (@@@ any special styles?)
91 wxNotebook(wxWindow
*parent
,
93 const wxPoint
& pos
= wxDefaultPosition
,
94 const wxSize
& size
= wxDefaultSize
,
96 const wxString
& name
= "notebook");
98 bool Create(wxWindow
*parent
,
100 const wxPoint
& pos
= wxDefaultPosition
,
101 const wxSize
& size
= wxDefaultSize
,
103 const wxString
& name
= "notebook");
109 // get number of pages in the dialog
110 int GetPageCount() const;
112 // Find the position of the wxNotebookPage, -1 if not found.
113 int FindPagePosition(wxNotebookPage
* page
) const;
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
; }
124 // set/get the title of a page
125 bool SetPageText(int nPage
, const wxString
& strText
);
126 wxString
GetPageText(int nPage
) const;
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
; }
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
);
142 // currently it's always 1 because wxGTK doesn't support multi-row
144 int GetRowCount() const;
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
);
152 // Sets the size of the tabs (assumes all tabs are the same size)
153 void SetTabSize(const wxSize
& sz
);
157 // remove one page from the notebook, and delete the page.
158 bool DeletePage(int nPage
);
159 bool DeletePage(wxNotebookPage
* page
);
160 // remove one page from the notebook, without deleting the page.
161 bool RemovePage(int nPage
);
162 bool RemovePage(wxNotebookPage
* page
);
164 bool DeleteAllPages();
165 // adds a new page to the notebook (it will be deleted ny the notebook,
166 // don't delete it yourself). If bSelect, this page becomes active.
167 bool AddPage(wxNotebookPage
*pPage
,
168 const wxString
& strText
,
169 bool bSelect
= FALSE
,
171 // the same as AddPage(), but adds it at the specified position
172 bool InsertPage(int nPage
,
173 wxNotebookPage
*pPage
,
174 const wxString
& strText
,
175 bool bSelect
= FALSE
,
177 // get the panel which represents the given page
178 wxNotebookPage
*GetPage(int nPage
) { return m_aPages
[nPage
]; }
182 void OnSize(wxSizeEvent
& event
);
183 void OnIdle(wxIdleEvent
& event
);
184 void OnSelChange(wxNotebookEvent
& event
);
185 void OnSetFocus(wxFocusEvent
& event
);
186 void OnNavigationKey(wxNavigationKeyEvent
& event
);
188 // base class virtuals
189 // -------------------
190 virtual void Command(wxCommandEvent
& event
);
191 virtual void SetConstraintSizes(bool recurse
= TRUE
);
192 virtual bool DoPhase(int nPhase
);
196 // wxNotebook on Motif uses a generic wxTabView to implement itself.
197 inline wxTabView
*GetTabView() const { return m_tabView
; }
198 inline void SetTabView(wxTabView
*v
) { m_tabView
= v
; }
200 void OnMouseEvent(wxMouseEvent
& event
);
201 void OnPaint(wxPaintEvent
& event
);
203 virtual wxRect
GetAvailableClientSize();
205 // Implementation: calculate the layout of the view rect
206 // and resize the children if required
207 bool RefreshLayout(bool force
= TRUE
);
210 // common part of all ctors
214 void ChangePage(int nOldSel
, int nSel
); // change pages
216 wxImageList
*m_pImageList
; // we can have an associated image list
217 wxArrayPages m_aPages
; // array of pages
219 int m_nSelection
; // the current selection (-1 if none)
221 wxTabView
* m_tabView
;
223 DECLARE_DYNAMIC_CLASS(wxNotebook
)
224 DECLARE_EVENT_TABLE()
227 // ----------------------------------------------------------------------------
229 // ----------------------------------------------------------------------------
230 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
232 // Because of name truncation!
233 #if defined(__BORLANDC__) && defined(__WIN16__)
235 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
237 wxEVT_COMMAND_NB_PAGE_CHANGED, \
240 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
244 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
246 wxEVT_COMMAND_NB_PAGE_CHANGING, \ \
249 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
255 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
257 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
260 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
264 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
266 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \
269 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
275 #endif // _WX_NOTEBOOK_H_