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