]> git.saurik.com Git - wxWidgets.git/blame - src/qt/notebook.cpp
fixed à parsing (here too)
[wxWidgets.git] / src / qt / notebook.cpp
CommitLineData
01b2eeec 1///////////////////////////////////////////////////////////////////////////////
7c78e7c7 2// Name: notebook.cpp
01b2eeec
KB
3// Purpose: implementation of wxNotebook
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
7c78e7c7 9// Licence: wxWindows licence
01b2eeec 10///////////////////////////////////////////////////////////////////////////////
7c78e7c7 11
01b2eeec
KB
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
7c78e7c7
RR
19#ifdef __GNUG__
20#pragma implementation "notebook.h"
21#endif
22
01b2eeec
KB
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
01b2eeec
KB
39BEGIN_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)
45END_EVENT_TABLE()
46
47IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
48IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
01b2eeec
KB
49
50// ============================================================================
51// implementation
52// ============================================================================
7c78e7c7 53
01b2eeec
KB
54// ----------------------------------------------------------------------------
55// wxNotebook construction
56// ----------------------------------------------------------------------------
57
58// common part of all ctors
7c78e7c7
RR
59void wxNotebook::Init()
60{
01b2eeec
KB
61 m_pImageList = NULL;
62 m_nSelection = -1;
7c78e7c7
RR
63}
64
01b2eeec 65// default for dynamic class
7c78e7c7
RR
66wxNotebook::wxNotebook()
67{
01b2eeec
KB
68 Init();
69}
7c78e7c7 70
01b2eeec
KB
71// the same arguments as for wxControl
72wxNotebook::wxNotebook(wxWindow *parent,
73 wxWindowID id,
74 const wxPoint& pos,
75 const wxSize& size,
76 long style,
77 const wxString& name)
7c78e7c7 78{
01b2eeec 79 Init();
7c78e7c7 80
01b2eeec
KB
81 Create(parent, id, pos, size, style, name);
82}
7c78e7c7 83
01b2eeec
KB
84// Create() function
85bool wxNotebook::Create(wxWindow *parent,
86 wxWindowID id,
87 const wxPoint& pos,
88 const wxSize& size,
89 long style,
90 const wxString& name)
7c78e7c7 91{
01b2eeec
KB
92 // base init
93 SetName(name);
94 SetParent(parent);
7c78e7c7 95
01b2eeec 96 m_windowId = id == -1 ? NewControlId() : id;
7c78e7c7 97
01b2eeec
KB
98 // colors and font
99 m_backgroundColour = wxColour(GetSysColor(COLOR_BTNFACE));
100 m_foregroundColour = *wxBLACK ;
7c78e7c7 101
01b2eeec
KB
102 // style
103 m_windowStyle = style;
104
105 if ( parent != NULL )
106 parent->AddChild(this);
107
108 // TODO
109
110 return FALSE;
111}
7c78e7c7 112
01b2eeec
KB
113// dtor
114wxNotebook::~wxNotebook()
7c78e7c7 115{
01b2eeec 116}
7c78e7c7 117
01b2eeec
KB
118// ----------------------------------------------------------------------------
119// wxNotebook accessors
120// ----------------------------------------------------------------------------
7c78e7c7
RR
121int wxNotebook::GetPageCount() const
122{
01b2eeec
KB
123 return m_aPages.Count();
124}
7c78e7c7
RR
125
126int wxNotebook::GetRowCount() const
127{
01b2eeec
KB
128 // TODO
129 return 0;
130}
7c78e7c7 131
01b2eeec 132int wxNotebook::SetSelection(int nPage)
7c78e7c7 133{
01b2eeec 134 wxASSERT( IS_VALID_PAGE(nPage) );
7c78e7c7 135
01b2eeec 136 ChangePage(m_nSelection, nPage);
7c78e7c7 137
01b2eeec
KB
138 // TODO
139 return 0;
140}
141
142void wxNotebook::AdvanceSelection(bool bForward)
7c78e7c7 143{
01b2eeec
KB
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}
7c78e7c7 151
01b2eeec 152bool wxNotebook::SetPageText(int nPage, const wxString& strText)
7c78e7c7 153{
01b2eeec 154 wxASSERT( IS_VALID_PAGE(nPage) );
7c78e7c7 155
01b2eeec
KB
156 // TODO
157 return FALSE;
158}
159
160wxString wxNotebook::GetPageText(int nPage) const
7c78e7c7 161{
01b2eeec
KB
162 wxASSERT( IS_VALID_PAGE(nPage) );
163
164 // TODO
165 return wxString("");
7c78e7c7
RR
166}
167
01b2eeec 168int wxNotebook::GetPageImage(int nPage) const
7c78e7c7 169{
01b2eeec 170 wxASSERT( IS_VALID_PAGE(nPage) );
7c78e7c7 171
01b2eeec
KB
172 // TODO
173 return 0;
174}
175
176bool wxNotebook::SetPageImage(int nPage, int nImage)
7c78e7c7 177{
01b2eeec
KB
178 wxASSERT( IS_VALID_PAGE(nPage) );
179
180 // TODO
181 return FALSE;
182}
183
184void wxNotebook::SetImageList(wxImageList* imageList)
185{
186 m_pImageList = imageList;
187 // TODO
188}
189
190// ----------------------------------------------------------------------------
191// wxNotebook operations
192// ----------------------------------------------------------------------------
7c78e7c7 193
01b2eeec
KB
194// remove one page from the notebook
195bool wxNotebook::DeletePage(int nPage)
7c78e7c7 196{
01b2eeec
KB
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}
7c78e7c7 206
01b2eeec
KB
207// remove all pages
208bool wxNotebook::DeleteAllPages()
7c78e7c7 209{
01b2eeec
KB
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];
7c78e7c7 216
01b2eeec
KB
217 m_aPages.Clear();
218
219 return TRUE;
220}
221
222// add a page to the notebook
223bool wxNotebook::AddPage(wxNotebookPage *pPage,
224 const wxString& strText,
225 bool bSelect,
226 int imageId)
7c78e7c7 227{
01b2eeec
KB
228 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
229}
7c78e7c7 230
01b2eeec
KB
231// same as AddPage() but does it at given position
232bool wxNotebook::InsertPage(int nPage,
233 wxNotebookPage *pPage,
234 const wxString& strText,
235 bool bSelect,
236 int imageId)
7c78e7c7 237{
01b2eeec
KB
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// ----------------------------------------------------------------------------
7c78e7c7 259
01b2eeec
KB
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)
262void wxNotebook::OnSize(wxSizeEvent& event)
7c78e7c7 263{
01b2eeec
KB
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}
7c78e7c7 293
01b2eeec 294void wxNotebook::OnSelChange(wxNotebookEvent& event)
7c78e7c7 295{
01b2eeec
KB
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}
7c78e7c7 303
01b2eeec 304void wxNotebook::OnSetFocus(wxFocusEvent& event)
7c78e7c7 305{
01b2eeec
KB
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}
7c78e7c7 312
01b2eeec 313void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
7c78e7c7 314{
01b2eeec
KB
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// ----------------------------------------------------------------------------
7c78e7c7
RR
331
332// override these 2 functions to do nothing: everything is done in OnSize
01b2eeec
KB
333
334void 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
340bool wxNotebook::DoPhase(int /* nPhase */)
7c78e7c7 341{
01b2eeec 342 return TRUE;
7c78e7c7
RR
343}
344
01b2eeec 345void wxNotebook::Command(wxCommandEvent& event)
7c78e7c7 346{
01b2eeec 347 wxFAIL_MSG("wxNotebook::Command not implemented");
7c78e7c7
RR
348}
349
01b2eeec
KB
350// ----------------------------------------------------------------------------
351// wxNotebook helper functions
352// ----------------------------------------------------------------------------
353
354// hide the currently active panel and show the new one
355void 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}
7c78e7c7 369