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 #include "wx/control.h"
25 // ----------------------------------------------------------------------------
27 // ----------------------------------------------------------------------------
30 class WXDLLEXPORT wxImageList
;
31 class WXDLLEXPORT wxWindow
;
33 // array of notebook pages
34 typedef wxWindow wxNotebookPage
; // so far, any window can be a page
35 WX_DEFINE_ARRAY(wxNotebookPage
*, wxArrayPages
);
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxNotebookEvent
: public wxCommandEvent
43 wxNotebookEvent(wxEventType commandType
= wxEVT_NULL
, int id
= 0,
44 int nSel
= -1, int nOldSel
= -1)
45 : wxCommandEvent(commandType
, id
) { m_nSel
= nSel
; m_nOldSel
= nOldSel
; }
48 int GetSelection() const { return m_nSel
; }
49 int GetOldSelection() const { return m_nOldSel
; }
52 int m_nSel
, // currently selected page
53 m_nOldSel
; // previously selected page
55 DECLARE_DYNAMIC_CLASS(wxNotebookEvent
)
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 // @@@ this class should really derive from wxTabCtrl, but the interface is not
63 // exactly the same, so I can't do it right now and instead we reimplement
64 // part of wxTabCtrl here
65 class wxNotebook
: public wxControl
70 // default for dynamic class
72 // the same arguments as for wxControl (@@@ any special styles?)
73 wxNotebook(wxWindow
*parent
,
75 const wxPoint
& pos
= wxDefaultPosition
,
76 const wxSize
& size
= wxDefaultSize
,
78 const wxString
& name
= "notebook");
80 bool Create(wxWindow
*parent
,
82 const wxPoint
& pos
= wxDefaultPosition
,
83 const wxSize
& size
= wxDefaultSize
,
85 const wxString
& name
= "notebook");
91 // get number of pages in the dialog
92 int GetPageCount() const;
94 // set the currently selected page, return the index of the previously
95 // selected one (or -1 on error)
96 // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events
97 int SetSelection(int nPage
);
98 // cycle thru the tabs
99 void AdvanceSelection(bool bForward
= TRUE
);
100 // get the currently selected page
101 int GetSelection() const { return m_nSelection
; }
103 // set/get the title of a page
104 bool SetPageText(int nPage
, const wxString
& strText
);
105 wxString
GetPageText(int nPage
) const;
107 // image list stuff: each page may have an image associated with it. All
108 // the images belong to an image list, so you have to
109 // 1) create an image list
110 // 2) associate it with the notebook
111 // 3) set for each page it's image
112 // associate image list with a control
113 void SetImageList(wxImageList
* imageList
);
114 // get pointer (may be NULL) to the associated image list
115 wxImageList
* GetImageList() const { return m_pImageList
; }
117 // sets/returns item's image index in the current image list
118 int GetPageImage(int nPage
) const;
119 bool SetPageImage(int nPage
, int nImage
);
121 // currently it's always 1 because wxGTK doesn't support multi-row
123 int GetRowCount() const;
125 // control the appearance of the notebook pages
126 // set the size (the same for all pages)
127 void SetPageSize(const wxSize
& size
);
128 // set the padding between tabs (in pixels)
129 void SetPadding(const wxSize
& padding
);
131 // Sets the size of the tabs (assumes all tabs are the same size)
132 void SetTabSize(const wxSize
& sz
);
136 // remove one page from the notebook
137 bool DeletePage(int nPage
);
138 // remove one page from the notebook, without deleting
139 bool RemovePage(int nPage
);
141 bool DeleteAllPages();
142 // adds a new page to the notebook (it will be deleted ny the notebook,
143 // don't delete it yourself). If bSelect, this page becomes active.
144 bool AddPage(wxNotebookPage
*pPage
,
145 const wxString
& strText
,
146 bool bSelect
= FALSE
,
148 // the same as AddPage(), but adds it at the specified position
149 bool InsertPage(int nPage
,
150 wxNotebookPage
*pPage
,
151 const wxString
& strText
,
152 bool bSelect
= FALSE
,
154 // get the panel which represents the given page
155 wxNotebookPage
*GetPage(int nPage
) { return m_aPages
[nPage
]; }
159 void OnSize(wxSizeEvent
& event
);
160 void OnSelChange(wxNotebookEvent
& event
);
161 void OnSetFocus(wxFocusEvent
& event
);
162 void OnNavigationKey(wxNavigationKeyEvent
& event
);
164 // base class virtuals
165 // -------------------
166 virtual void Command(wxCommandEvent
& event
);
167 virtual void SetConstraintSizes(bool recurse
= TRUE
);
168 virtual bool DoPhase(int nPhase
);
171 // common part of all ctors
175 void ChangePage(int nOldSel
, int nSel
); // change pages
177 wxImageList
*m_pImageList
; // we can have an associated image list
178 wxArrayPages m_aPages
; // array of pages
180 int m_nSelection
; // the current selection (-1 if none)
182 DECLARE_DYNAMIC_CLASS(wxNotebook
)
183 DECLARE_EVENT_TABLE()
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
189 typedef void (wxEvtHandler::*wxNotebookEventFunction
)(wxNotebookEvent
&);
191 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
193 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
196 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
200 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
202 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \
205 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
209 #endif // _WX_NOTEBOOK_H_