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