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