]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/notebook.cpp
Maybe negative wxWindowId are better than just -1.
[wxWidgets.git] / src / stubs / notebook.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: notebook.cpp
3 // Purpose: implementation of wxNotebook
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
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 one page from the notebook, without deleting the window
206 bool wxNotebook::RemovePage(int nPage)
207 {
208 wxCHECK( IS_VALID_PAGE(nPage), FALSE );
209
210 m_aPages.Remove(nPage);
211
212 return TRUE;
213 }
214
215 // remove all pages
216 bool wxNotebook::DeleteAllPages()
217 {
218 // TODO: delete native widget pages
219
220 int nPageCount = GetPageCount();
221 int nPage;
222 for ( nPage = 0; nPage < nPageCount; nPage++ )
223 delete m_aPages[nPage];
224
225 m_aPages.Clear();
226
227 return TRUE;
228 }
229
230 // add a page to the notebook
231 bool wxNotebook::AddPage(wxNotebookPage *pPage,
232 const wxString& strText,
233 bool bSelect,
234 int imageId)
235 {
236 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
237 }
238
239 // same as AddPage() but does it at given position
240 bool wxNotebook::InsertPage(int nPage,
241 wxNotebookPage *pPage,
242 const wxString& strText,
243 bool bSelect,
244 int imageId)
245 {
246 wxASSERT( pPage != NULL );
247 wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), FALSE );
248
249 // TODO: insert native widget page
250
251 // save the pointer to the page
252 m_aPages.Insert(pPage, nPage);
253
254 // some page must be selected: either this one or the first one if there is
255 // still no selection
256 if ( bSelect )
257 m_nSelection = nPage;
258 else if ( m_nSelection == -1 )
259 m_nSelection = 0;
260
261 return TRUE;
262 }
263
264 // ----------------------------------------------------------------------------
265 // wxNotebook callbacks
266 // ----------------------------------------------------------------------------
267
268 // @@@ OnSize() is used for setting the font when it's called for the first
269 // time because doing it in ::Create() doesn't work (for unknown reasons)
270 void wxNotebook::OnSize(wxSizeEvent& event)
271 {
272 static bool s_bFirstTime = TRUE;
273 if ( s_bFirstTime ) {
274 // TODO: any first-time-size processing.
275 s_bFirstTime = FALSE;
276 }
277
278 // TODO: all this may or may not be necessary for your platform
279
280 // emulate page change (it's esp. important to do it first time because
281 // otherwise our page would stay invisible)
282 int nSel = m_nSelection;
283 m_nSelection = -1;
284 SetSelection(nSel);
285
286 // fit the notebook page to the tab control's display area
287 int w, h;
288 GetSize(&w, &h);
289
290 unsigned int nCount = m_aPages.Count();
291 for ( unsigned int nPage = 0; nPage < nCount; nPage++ ) {
292 wxNotebookPage *pPage = m_aPages[nPage];
293 pPage->SetSize(0, 0, w, h);
294 if ( pPage->GetAutoLayout() )
295 pPage->Layout();
296 }
297
298 // Processing continues to next OnSize
299 event.Skip();
300 }
301
302 void wxNotebook::OnSelChange(wxNotebookEvent& event)
303 {
304 // is it our tab control?
305 if ( event.GetEventObject() == this )
306 ChangePage(event.GetOldSelection(), event.GetSelection());
307
308 // we want to give others a chance to process this message as well
309 event.Skip();
310 }
311
312 void wxNotebook::OnSetFocus(wxFocusEvent& event)
313 {
314 // set focus to the currently selected page if any
315 if ( m_nSelection != -1 )
316 m_aPages[m_nSelection]->SetFocus();
317
318 event.Skip();
319 }
320
321 void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
322 {
323 if ( event.IsWindowChange() ) {
324 // change pages
325 AdvanceSelection(event.GetDirection());
326 }
327 else {
328 // pass to the parent
329 if ( GetParent() ) {
330 event.SetCurrentFocus(this);
331 GetParent()->ProcessEvent(event);
332 }
333 }
334 }
335
336 // ----------------------------------------------------------------------------
337 // wxNotebook base class virtuals
338 // ----------------------------------------------------------------------------
339
340 // override these 2 functions to do nothing: everything is done in OnSize
341
342 void wxNotebook::SetConstraintSizes(bool /* recurse */)
343 {
344 // don't set the sizes of the pages - their correct size is not yet known
345 wxControl::SetConstraintSizes(FALSE);
346 }
347
348 bool wxNotebook::DoPhase(int /* nPhase */)
349 {
350 return TRUE;
351 }
352
353 void wxNotebook::Command(wxCommandEvent& event)
354 {
355 wxFAIL_MSG("wxNotebook::Command not implemented");
356 }
357
358 // ----------------------------------------------------------------------------
359 // wxNotebook helper functions
360 // ----------------------------------------------------------------------------
361
362 // hide the currently active panel and show the new one
363 void wxNotebook::ChangePage(int nOldSel, int nSel)
364 {
365 wxASSERT( nOldSel != nSel ); // impossible
366
367 if ( nOldSel != -1 ) {
368 m_aPages[nOldSel]->Show(FALSE);
369 }
370
371 wxNotebookPage *pPage = m_aPages[nSel];
372 pPage->Show(TRUE);
373 pPage->SetFocus();
374
375 m_nSelection = nSel;
376 }
377
378 void wxNotebook::SetTabSize(const wxSize& sz)
379 {
380 // TODO
381 }
382