1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: MSW/GTK compatible notebook (a.k.a. property sheet)
7 // Copyright: (c) AUTHOR
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 // ----------------------------------------------------------------------------
25 // ----------------------------------------------------------------------------
28 class WXDLLEXPORT wxImageList
;
29 class WXDLLEXPORT wxWindow
;
31 // array of notebook pages
32 typedef wxWindow wxNotebookPage
; // so far, any window can be a page
33 WX_DEFINE_ARRAY(wxNotebookPage
*, wxArrayPages
);
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
38 class WXDLLEXPORT wxNotebookEvent
: public wxCommandEvent
41 wxNotebookEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0,
42 int nSel
= -1, int nOldSel
= -1)
43 : wxCommandEvent(commandType
, id
) { m_nSel
= nSel
; m_nOldSel
= nOldSel
; }
46 int GetSelection() const { return m_nSel
; }
47 int GetOldSelection() const { return m_nOldSel
; }
50 int m_nSel
, // currently selected page
51 m_nOldSel
; // previously selected page
53 DECLARE_DYNAMIC_CLASS(wxNotebookEvent
)
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 // @@@ this class should really derive from wxTabCtrl, but the interface is not
61 // exactly the same, so I can't do it right now and instead we reimplement
62 // part of wxTabCtrl here
63 class wxNotebook
: public wxControl
68 // default for dynamic class
70 // the same arguments as for wxControl (@@@ any special styles?)
71 wxNotebook(wxWindow
*parent
,
73 const wxPoint
& pos
= wxDefaultPosition
,
74 const wxSize
& size
= wxDefaultSize
,
76 const wxString
& name
= "notebook");
78 bool Create(wxWindow
*parent
,
80 const wxPoint
& pos
= wxDefaultPosition
,
81 const wxSize
& size
= wxDefaultSize
,
83 const wxString
& name
= "notebook");
89 // get number of pages in the dialog
90 int GetPageCount() const;
92 // set the currently selected page, return the index of the previously
93 // selected one (or -1 on error)
94 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
95 int SetSelection(int nPage
);
96 // cycle thru the tabs
97 void AdvanceSelection(bool bForward
= TRUE
);
98 // get the currently selected page
99 int GetSelection() const { return m_nSelection
; }
101 // set/get the title of a page
102 bool SetPageText(int nPage
, const wxString
& strText
);
103 wxString
GetPageText(int nPage
) const;
105 // image list stuff: each page may have an image associated with it. All
106 // the images belong to an image list, so you have to
107 // 1) create an image list
108 // 2) associate it with the notebook
109 // 3) set for each page it's image
110 // associate image list with a control
111 void SetImageList(wxImageList
* imageList
);
112 // get pointer (may be NULL) to the associated image list
113 wxImageList
* GetImageList() const { return m_pImageList
; }
115 // sets/returns item's image index in the current image list
116 int GetPageImage(int nPage
) const;
117 bool SetPageImage(int nPage
, int nImage
);
119 // currently it's always 1 because wxGTK doesn't support multi-row
121 int GetRowCount() const;
123 // control the appearance of the notebook pages
124 // set the size (the same for all pages)
125 void SetPageSize(const wxSize
& size
);
126 // set the padding between tabs (in pixels)
127 void SetPadding(const wxSize
& padding
);
131 // remove one page from the notebook
132 bool DeletePage(int nPage
);
134 bool DeleteAllPages();
135 // adds a new page to the notebook (it will be deleted ny the notebook,
136 // don't delete it yourself). If bSelect, this page becomes active.
137 bool AddPage(wxNotebookPage
*pPage
,
138 const wxString
& strText
,
139 bool bSelect
= FALSE
,
141 // the same as AddPage(), but adds it at the specified position
142 bool InsertPage(int nPage
,
143 wxNotebookPage
*pPage
,
144 const wxString
& strText
,
145 bool bSelect
= FALSE
,
147 // get the panel which represents the given page
148 wxNotebookPage
*GetPage(int nPage
) { return m_aPages
[nPage
]; }
152 void OnSize(wxSizeEvent
& event
);
153 void OnSelChange(wxNotebookEvent
& event
);
154 void OnSetFocus(wxFocusEvent
& event
);
155 void OnNavigationKey(wxNavigationKeyEvent
& event
);
157 // base class virtuals
158 // -------------------
159 virtual void Command(wxCommandEvent
& event
);
160 virtual void SetConstraintSizes(bool recurse
= TRUE
);
161 virtual bool DoPhase(int nPhase
);
164 // common part of all ctors
168 void ChangePage(int nOldSel
, int nSel
); // change pages
170 wxImageList
*m_pImageList
; // we can have an associated image list
171 wxArrayPages m_aPages
; // array of pages
173 int m_nSelection
; // the current selection (-1 if none)
175 DECLARE_DYNAMIC_CLASS(wxNotebook
)
176 DECLARE_EVENT_TABLE()
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
182 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
184 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
186 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
189 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
193 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
195 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \
198 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
202 #endif // _WX_NOTEBOOK_H_