]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/notebook.h
wxNotebook interface (it may change!), implementation file is not yet
[wxWidgets.git] / include / wx / msw / notebook.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/notebook.h
3 // Purpose: MSW/GTK compatible notebook (a.k.a. property sheet)
4 // Author: Robert Roebling
5 // Modified by: Vadim Zeitlin for Windows version
6 // RCS-ID: $Id$
7 // Copyright: (c) Julian Smart and Markus Holzem
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _NOTEBOOK_H
12 #define _NOTEBOOK_H
13
14 #ifdef __GNUG__
15 #pragma interface "notebook.h"
16 #endif
17
18 // ----------------------------------------------------------------------------
19 // headers
20 // ----------------------------------------------------------------------------
21 #ifndef _DYNARRAY_H
22 #include <wx/dynarray.h>
23 #endif //_DYNARRAY_H
24
25 // ----------------------------------------------------------------------------
26 // types
27 // ----------------------------------------------------------------------------
28
29 // fwd declarations
30 class wxImageList;
31 class wxWindow;
32
33 // array of notebook pages
34 typedef wxWindow wxNotebookPage; // so far, any window can be a page
35 WX_DEFINE_ARRAY(wxNotebookPage *, wxArrayPages);
36
37 // ----------------------------------------------------------------------------
38 // notebook events
39 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxNotebookEvent : public wxCommandEvent
41 {
42 public:
43 wxNotebookEvent(WXTYPE commandType = 0, int id = 0,
44 int nSel = -1, int nOldSel = -1)
45 : wxCommandEvent(commandType, id) { m_nSel = nSel; m_nOldSel = nOldSel; }
46
47 // accessors
48 int GetSelection() const { return m_nSel; }
49 int GetOldSelection() const { return m_nOldSel; }
50
51 private:
52 int m_nSel, // currently selected page
53 m_nOldSel; // previously selected page
54
55 DECLARE_DYNAMIC_CLASS(wxNotebookEvent)
56 };
57
58 // ----------------------------------------------------------------------------
59 // wxNotebook
60 // ----------------------------------------------------------------------------
61
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
66 {
67 public:
68 // ctors
69 // -----
70 // default for dynamic class
71 wxNotebook();
72 // the same arguments as for wxControl (@@@ any special styles?)
73 wxNotebook(wxWindow *parent,
74 const wxWindowID id,
75 const wxPoint& pos = wxDefaultPosition,
76 const wxSize& size = wxDefaultSize,
77 const long style = 0,
78 const wxString& name = "notebook");
79 // Create() function
80 bool Create(wxWindow *parent,
81 const wxWindowID id,
82 const wxPoint& pos = wxDefaultPosition,
83 const wxSize& size = wxDefaultSize,
84 const long style = 0,
85 const wxString& name = "notebook");
86 // dtor
87 ~wxNotebook();
88
89 // accessors
90 // ---------
91 // get number of pages in the dialog
92 int GetPageCount() const;
93
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; }
102
103 // set/get the title of a page
104 bool SetPageText(int nPage, const wxString& strText);
105 wxString GetPageText(int nPage) const;
106
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; }
116
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);
120
121 // each page can have some user-defined data associated with it:
122 // set/retrieve this pointer
123 bool SetPageData(int nPage, void* data);
124 void* GetPageData(int nPage) const;
125
126 // currently it's always 1 because wxGTK doesn't support multi-row
127 // tab controls
128 int GetRowCount() const;
129
130 // control the appearance of the notebook pages
131 // set the size (the same for all pages)
132 void SetPageSize(const wxSize& size);
133 // set the padding between tabs (in pixels)
134 void SetPadding(const wxSize& padding);
135
136 // operations
137 // ----------
138 // remove one page from the notebook
139 bool DeletePage(int nPage);
140 // remove all pages
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,
147 int imageId = -1,
148 void* data = NULL);
149 // the same as AddPage(), but adds it at the specified position
150 bool InsertPage(int nPage,
151 wxNotebookPage *pPage,
152 const wxString& strText,
153 bool bSelect = FALSE,
154 int imageId = -1,
155 void* data = NULL);
156 // get the panel which represents the given page
157 wxNotebookPage *GetPage(int nPage) { return m_aPages[nPage]; }
158
159 // callbacks
160 // ---------
161 void OnSize(wxSizeEvent& event);
162 void OnSelChange(wxNotebookEvent& event);
163
164 // base class virtuals
165 // -------------------
166 virtual void Command(wxCommandEvent& event);
167 virtual bool MSWNotify(const WXWPARAM wParam, const WXLPARAM lParam);
168
169 protected:
170 // common part of all ctors
171 void Init();
172
173 // helper functions
174 void ChangePage(int nOldSel, int nSel); // change pages
175 void FitPage(wxNotebookPage *pPage); // fit a page in the tab control
176
177 wxImageList *m_pImageList; // we can have an associated image list
178 wxArrayPages m_aPages; // array of pages
179
180 int m_nSelection; // the current selection (-1 if none)
181
182 DECLARE_DYNAMIC_CLASS(wxNotebook)
183 DECLARE_EVENT_TABLE()
184 };
185
186 // ----------------------------------------------------------------------------
187 // event macros
188 // ----------------------------------------------------------------------------
189 typedef void (wxEvtHandler::*wxNotebookEventFunction)(wxNotebookEvent&);
190
191 #define EVT_NOTEBOOK_PAGE_CHANGED(id, fn) \
192 { \
193 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, \
194 id, \
195 -1, \
196 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
197 NULL \
198 },
199
200 #define EVT_NOTEBOOK_PAGE_CHANGING(id, fn) \
201 { \
202 wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, \ \
203 id, \
204 -1, \
205 (wxObjectEventFunction)(wxEventFunction)(wxNotebookEventFunction) &fn, \
206 NULL \
207 },
208
209 #endif // _NOTEBOOK_H