]>
Commit | Line | Data |
---|---|---|
4bb6408c JS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: notebook.cpp | |
3 | // Purpose: implementation of wxNotebook | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 17/09/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | #ifdef __GNUG__ | |
20 | #pragma implementation "notebook.h" | |
21 | #endif | |
22 | ||
23 | #include <wx/string.h> | |
24 | #include <wx/log.h> | |
25 | #include <wx/imaglist.h> | |
26 | #include <wx/notebook.h> | |
27 | ||
28 | // ---------------------------------------------------------------------------- | |
29 | // macros | |
30 | // ---------------------------------------------------------------------------- | |
31 | ||
32 | // check that the page index is valid | |
33 | #define IS_VALID_PAGE(nPage) (((nPage) >= 0) && ((nPage) < GetPageCount())) | |
34 | ||
35 | // ---------------------------------------------------------------------------- | |
36 | // event table | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
39 | #if !USE_SHARED_LIBRARIES | |
40 | BEGIN_EVENT_TABLE(wxNotebook, wxControl) | |
41 | EVT_NOTEBOOK_PAGE_CHANGED(-1, wxNotebook::OnSelChange) | |
42 | ||
43 | EVT_SIZE(wxNotebook::OnSize) | |
44 | EVT_SET_FOCUS(wxNotebook::OnSetFocus) | |
45 | EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) | |
46 | END_EVENT_TABLE() | |
47 | ||
48 | IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) | |
49 | IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) | |
50 | #endif | |
51 | ||
52 | // ============================================================================ | |
53 | // implementation | |
54 | // ============================================================================ | |
55 | ||
56 | // ---------------------------------------------------------------------------- | |
57 | // wxNotebook construction | |
58 | // ---------------------------------------------------------------------------- | |
59 | ||
60 | // common part of all ctors | |
61 | void wxNotebook::Init() | |
62 | { | |
63 | m_pImageList = NULL; | |
64 | m_nSelection = -1; | |
65 | } | |
66 | ||
67 | // default for dynamic class | |
68 | wxNotebook::wxNotebook() | |
69 | { | |
70 | Init(); | |
71 | } | |
72 | ||
73 | // the same arguments as for wxControl | |
74 | wxNotebook::wxNotebook(wxWindow *parent, | |
75 | wxWindowID id, | |
76 | const wxPoint& pos, | |
77 | const wxSize& size, | |
78 | long style, | |
79 | const wxString& name) | |
80 | { | |
81 | Init(); | |
82 | ||
83 | Create(parent, id, pos, size, style, name); | |
84 | } | |
85 | ||
86 | // Create() function | |
87 | bool wxNotebook::Create(wxWindow *parent, | |
88 | wxWindowID id, | |
89 | const wxPoint& pos, | |
90 | const wxSize& size, | |
91 | long style, | |
92 | const wxString& name) | |
93 | { | |
94 | // base init | |
95 | SetName(name); | |
96 | SetParent(parent); | |
97 | ||
98 | m_windowId = id == -1 ? NewControlId() : id; | |
99 | ||
100 | // style | |
101 | m_windowStyle = style; | |
102 | ||
103 | if ( parent != NULL ) | |
104 | parent->AddChild(this); | |
105 | ||
106 | // TODO | |
107 | ||
108 | return FALSE; | |
109 | } | |
110 | ||
111 | // dtor | |
112 | wxNotebook::~wxNotebook() | |
113 | { | |
114 | } | |
115 | ||
116 | // ---------------------------------------------------------------------------- | |
117 | // wxNotebook accessors | |
118 | // ---------------------------------------------------------------------------- | |
119 | int wxNotebook::GetPageCount() const | |
120 | { | |
121 | return m_aPages.Count(); | |
122 | } | |
123 | ||
124 | int wxNotebook::GetRowCount() const | |
125 | { | |
126 | // TODO | |
127 | return 0; | |
128 | } | |
129 | ||
130 | int wxNotebook::SetSelection(int nPage) | |
131 | { | |
132 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
133 | ||
134 | ChangePage(m_nSelection, nPage); | |
135 | ||
136 | // TODO | |
137 | return 0; | |
138 | } | |
139 | ||
140 | void wxNotebook::AdvanceSelection(bool bForward) | |
141 | { | |
142 | int nSel = GetSelection(); | |
143 | int nMax = GetPageCount() - 1; | |
144 | if ( bForward ) | |
145 | SetSelection(nSel == nMax ? 0 : nSel + 1); | |
146 | else | |
147 | SetSelection(nSel == 0 ? nMax : nSel - 1); | |
148 | } | |
149 | ||
150 | bool wxNotebook::SetPageText(int nPage, const wxString& strText) | |
151 | { | |
152 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
153 | ||
154 | // TODO | |
155 | return FALSE; | |
156 | } | |
157 | ||
158 | wxString wxNotebook::GetPageText(int nPage) const | |
159 | { | |
160 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
161 | ||
162 | // TODO | |
163 | return wxString(""); | |
164 | } | |
165 | ||
166 | int wxNotebook::GetPageImage(int nPage) const | |
167 | { | |
168 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
169 | ||
170 | // TODO | |
171 | return 0; | |
172 | } | |
173 | ||
174 | bool wxNotebook::SetPageImage(int nPage, int nImage) | |
175 | { | |
176 | wxASSERT( IS_VALID_PAGE(nPage) ); | |
177 | ||
178 | // TODO | |
179 | return FALSE; | |
180 | } | |
181 | ||
182 | void wxNotebook::SetImageList(wxImageList* imageList) | |
183 | { | |
184 | m_pImageList = imageList; | |
185 | // TODO | |
186 | } | |
187 | ||
188 | // ---------------------------------------------------------------------------- | |
189 | // wxNotebook operations | |
190 | // ---------------------------------------------------------------------------- | |
191 | ||
192 | // remove one page from the notebook | |
193 | bool wxNotebook::DeletePage(int nPage) | |
194 | { | |
195 | wxCHECK( IS_VALID_PAGE(nPage), FALSE ); | |
196 | ||
197 | // TODO: delete native widget page | |
198 | ||
199 | delete m_aPages[nPage]; | |
200 | m_aPages.Remove(nPage); | |
201 | ||
202 | return TRUE; | |
203 | } | |
204 | ||
205 | // remove all pages | |
206 | bool wxNotebook::DeleteAllPages() | |
207 | { | |
208 | // TODO: delete native widget pages | |
209 | ||
210 | int nPageCount = GetPageCount(); | |
211 | int nPage; | |
212 | for ( nPage = 0; nPage < nPageCount; nPage++ ) | |
213 | delete m_aPages[nPage]; | |
214 | ||
215 | m_aPages.Clear(); | |
216 | ||
217 | return TRUE; | |
218 | } | |
219 | ||
220 | // add a page to the notebook | |
221 | bool wxNotebook::AddPage(wxNotebookPage *pPage, | |
222 | const wxString& strText, | |
223 | bool bSelect, | |
224 | int imageId) | |
225 | { | |
226 | return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId); | |
227 | } | |
228 | ||
229 | // same as AddPage() but does it at given position | |
230 | bool wxNotebook::InsertPage(int nPage, | |
231 | wxNotebookPage *pPage, | |
232 | const wxString& strText, | |
233 | bool bSelect, | |
234 | int imageId) | |
235 | { | |
236 | wxASSERT( pPage != NULL ); | |
237 | wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE ); | |
238 | ||
239 | // TODO: insert native widget page | |
240 | ||
241 | // save the pointer to the page | |
242 | m_aPages.Insert(pPage, nPage); | |
243 | ||
244 | // some page must be selected: either this one or the first one if there is | |
245 | // still no selection | |
246 | if ( bSelect ) | |
247 | m_nSelection = nPage; | |
248 | else if ( m_nSelection == -1 ) | |
249 | m_nSelection = 0; | |
250 | ||
251 | return TRUE; | |
252 | } | |
253 | ||
254 | // ---------------------------------------------------------------------------- | |
255 | // wxNotebook callbacks | |
256 | // ---------------------------------------------------------------------------- | |
257 | ||
258 | // @@@ OnSize() is used for setting the font when it's called for the first | |
259 | // time because doing it in ::Create() doesn't work (for unknown reasons) | |
260 | void wxNotebook::OnSize(wxSizeEvent& event) | |
261 | { | |
262 | static bool s_bFirstTime = TRUE; | |
263 | if ( s_bFirstTime ) { | |
264 | // TODO: any first-time-size processing. | |
265 | s_bFirstTime = FALSE; | |
266 | } | |
267 | ||
268 | // TODO: all this may or may not be necessary for your platform | |
269 | ||
270 | // emulate page change (it's esp. important to do it first time because | |
271 | // otherwise our page would stay invisible) | |
272 | int nSel = m_nSelection; | |
273 | m_nSelection = -1; | |
274 | SetSelection(nSel); | |
275 | ||
276 | // fit the notebook page to the tab control's display area | |
277 | int w, h; | |
278 | GetSize(&w, &h); | |
279 | ||
280 | unsigned int nCount = m_aPages.Count(); | |
281 | for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) { | |
282 | wxNotebookPage *pPage = m_aPages[nPage]; | |
283 | pPage->SetSize(0, 0, w, h); | |
284 | if ( pPage->GetAutoLayout() ) | |
285 | pPage->Layout(); | |
286 | } | |
287 | ||
288 | // Processing continues to next OnSize | |
289 | event.Skip(); | |
290 | } | |
291 | ||
292 | void wxNotebook::OnSelChange(wxNotebookEvent& event) | |
293 | { | |
294 | // is it our tab control? | |
295 | if ( event.GetEventObject() == this ) | |
296 | ChangePage(event.GetOldSelection(), event.GetSelection()); | |
297 | ||
298 | // we want to give others a chance to process this message as well | |
299 | event.Skip(); | |
300 | } | |
301 | ||
302 | void wxNotebook::OnSetFocus(wxFocusEvent& event) | |
303 | { | |
304 | // set focus to the currently selected page if any | |
305 | if ( m_nSelection != -1 ) | |
306 | m_aPages[m_nSelection]->SetFocus(); | |
307 | ||
308 | event.Skip(); | |
309 | } | |
310 | ||
311 | void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) | |
312 | { | |
313 | if ( event.IsWindowChange() ) { | |
314 | // change pages | |
315 | AdvanceSelection(event.GetDirection()); | |
316 | } | |
317 | else { | |
318 | // pass to the parent | |
319 | if ( GetParent() ) { | |
320 | event.SetCurrentFocus(this); | |
321 | GetParent()->ProcessEvent(event); | |
322 | } | |
323 | } | |
324 | } | |
325 | ||
326 | // ---------------------------------------------------------------------------- | |
327 | // wxNotebook base class virtuals | |
328 | // ---------------------------------------------------------------------------- | |
329 | ||
330 | // override these 2 functions to do nothing: everything is done in OnSize | |
331 | ||
332 | void wxNotebook::SetConstraintSizes(bool /* recurse */) | |
333 | { | |
334 | // don't set the sizes of the pages - their correct size is not yet known | |
335 | wxControl::SetConstraintSizes(FALSE); | |
336 | } | |
337 | ||
338 | bool wxNotebook::DoPhase(int /* nPhase */) | |
339 | { | |
340 | return TRUE; | |
341 | } | |
342 | ||
343 | void wxNotebook::Command(wxCommandEvent& event) | |
344 | { | |
345 | wxFAIL_MSG("wxNotebook::Command not implemented"); | |
346 | } | |
347 | ||
348 | // ---------------------------------------------------------------------------- | |
349 | // wxNotebook helper functions | |
350 | // ---------------------------------------------------------------------------- | |
351 | ||
352 | // hide the currently active panel and show the new one | |
353 | void wxNotebook::ChangePage(int nOldSel, int nSel) | |
354 | { | |
355 | wxASSERT( nOldSel != nSel ); // impossible | |
356 | ||
357 | if ( nOldSel != -1 ) { | |
358 | m_aPages[nOldSel]->Show(FALSE); | |
359 | } | |
360 | ||
361 | wxNotebookPage *pPage = m_aPages[nSel]; | |
362 | pPage->Show(TRUE); | |
363 | pPage->SetFocus(); | |
364 | ||
365 | m_nSelection = nSel; | |
366 | } | |
367 | ||
0d57be45 JS |
368 | void wxNotebook::ChangeFont() |
369 | { | |
370 | // TODO | |
371 | } | |
372 | ||
373 | void wxNotebook::ChangeBackgroundColour() | |
374 | { | |
375 | // TODO | |
376 | } | |
377 | ||
378 | void wxNotebook::ChangeForegroundColour() | |
379 | { | |
380 | // TODO | |
381 | } | |
382 |