]> git.saurik.com Git - wxWidgets.git/blame - src/qt/notebook.cpp
Added lots of files. Enough now so that all wxHTML samples link.
[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
39#if !USE_SHARED_LIBRARIES
40BEGIN_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)
46END_EVENT_TABLE()
47
48IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
49IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
50#endif
51
52// ============================================================================
53// implementation
54// ============================================================================
7c78e7c7 55
01b2eeec
KB
56// ----------------------------------------------------------------------------
57// wxNotebook construction
58// ----------------------------------------------------------------------------
59
60// common part of all ctors
7c78e7c7
RR
61void wxNotebook::Init()
62{
01b2eeec
KB
63 m_pImageList = NULL;
64 m_nSelection = -1;
7c78e7c7
RR
65}
66
01b2eeec 67// default for dynamic class
7c78e7c7
RR
68wxNotebook::wxNotebook()
69{
01b2eeec
KB
70 Init();
71}
7c78e7c7 72
01b2eeec
KB
73// the same arguments as for wxControl
74wxNotebook::wxNotebook(wxWindow *parent,
75 wxWindowID id,
76 const wxPoint& pos,
77 const wxSize& size,
78 long style,
79 const wxString& name)
7c78e7c7 80{
01b2eeec 81 Init();
7c78e7c7 82
01b2eeec
KB
83 Create(parent, id, pos, size, style, name);
84}
7c78e7c7 85
01b2eeec
KB
86// Create() function
87bool wxNotebook::Create(wxWindow *parent,
88 wxWindowID id,
89 const wxPoint& pos,
90 const wxSize& size,
91 long style,
92 const wxString& name)
7c78e7c7 93{
01b2eeec
KB
94 // base init
95 SetName(name);
96 SetParent(parent);
7c78e7c7 97
01b2eeec 98 m_windowId = id == -1 ? NewControlId() : id;
7c78e7c7 99
01b2eeec
KB
100 // colors and font
101 m_backgroundColour = wxColour(GetSysColor(COLOR_BTNFACE));
102 m_foregroundColour = *wxBLACK ;
7c78e7c7 103
01b2eeec
KB
104 // style
105 m_windowStyle = style;
106
107 if ( parent != NULL )
108 parent->AddChild(this);
109
110 // TODO
111
112 return FALSE;
113}
7c78e7c7 114
01b2eeec
KB
115// dtor
116wxNotebook::~wxNotebook()
7c78e7c7 117{
01b2eeec 118}
7c78e7c7 119
01b2eeec
KB
120// ----------------------------------------------------------------------------
121// wxNotebook accessors
122// ----------------------------------------------------------------------------
7c78e7c7
RR
123int wxNotebook::GetPageCount() const
124{
01b2eeec
KB
125 return m_aPages.Count();
126}
7c78e7c7
RR
127
128int wxNotebook::GetRowCount() const
129{
01b2eeec
KB
130 // TODO
131 return 0;
132}
7c78e7c7 133
01b2eeec 134int wxNotebook::SetSelection(int nPage)
7c78e7c7 135{
01b2eeec 136 wxASSERT( IS_VALID_PAGE(nPage) );
7c78e7c7 137
01b2eeec 138 ChangePage(m_nSelection, nPage);
7c78e7c7 139
01b2eeec
KB
140 // TODO
141 return 0;
142}
143
144void wxNotebook::AdvanceSelection(bool bForward)
7c78e7c7 145{
01b2eeec
KB
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}
7c78e7c7 153
01b2eeec 154bool wxNotebook::SetPageText(int nPage, const wxString& strText)
7c78e7c7 155{
01b2eeec 156 wxASSERT( IS_VALID_PAGE(nPage) );
7c78e7c7 157
01b2eeec
KB
158 // TODO
159 return FALSE;
160}
161
162wxString wxNotebook::GetPageText(int nPage) const
7c78e7c7 163{
01b2eeec
KB
164 wxASSERT( IS_VALID_PAGE(nPage) );
165
166 // TODO
167 return wxString("");
7c78e7c7
RR
168}
169
01b2eeec 170int wxNotebook::GetPageImage(int nPage) const
7c78e7c7 171{
01b2eeec 172 wxASSERT( IS_VALID_PAGE(nPage) );
7c78e7c7 173
01b2eeec
KB
174 // TODO
175 return 0;
176}
177
178bool wxNotebook::SetPageImage(int nPage, int nImage)
7c78e7c7 179{
01b2eeec
KB
180 wxASSERT( IS_VALID_PAGE(nPage) );
181
182 // TODO
183 return FALSE;
184}
185
186void wxNotebook::SetImageList(wxImageList* imageList)
187{
188 m_pImageList = imageList;
189 // TODO
190}
191
192// ----------------------------------------------------------------------------
193// wxNotebook operations
194// ----------------------------------------------------------------------------
7c78e7c7 195
01b2eeec
KB
196// remove one page from the notebook
197bool wxNotebook::DeletePage(int nPage)
7c78e7c7 198{
01b2eeec
KB
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}
7c78e7c7 208
01b2eeec
KB
209// remove all pages
210bool wxNotebook::DeleteAllPages()
7c78e7c7 211{
01b2eeec
KB
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];
7c78e7c7 218
01b2eeec
KB
219 m_aPages.Clear();
220
221 return TRUE;
222}
223
224// add a page to the notebook
225bool wxNotebook::AddPage(wxNotebookPage *pPage,
226 const wxString& strText,
227 bool bSelect,
228 int imageId)
7c78e7c7 229{
01b2eeec
KB
230 return InsertPage(GetPageCount(), pPage, strText, bSelect, imageId);
231}
7c78e7c7 232
01b2eeec
KB
233// same as AddPage() but does it at given position
234bool wxNotebook::InsertPage(int nPage,
235 wxNotebookPage *pPage,
236 const wxString& strText,
237 bool bSelect,
238 int imageId)
7c78e7c7 239{
01b2eeec
KB
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// ----------------------------------------------------------------------------
7c78e7c7 261
01b2eeec
KB
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)
264void wxNotebook::OnSize(wxSizeEvent& event)
7c78e7c7 265{
01b2eeec
KB
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}
7c78e7c7 295
01b2eeec 296void wxNotebook::OnSelChange(wxNotebookEvent& event)
7c78e7c7 297{
01b2eeec
KB
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}
7c78e7c7 305
01b2eeec 306void wxNotebook::OnSetFocus(wxFocusEvent& event)
7c78e7c7 307{
01b2eeec
KB
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}
7c78e7c7 314
01b2eeec 315void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
7c78e7c7 316{
01b2eeec
KB
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// ----------------------------------------------------------------------------
7c78e7c7
RR
333
334// override these 2 functions to do nothing: everything is done in OnSize
01b2eeec
KB
335
336void 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
342bool wxNotebook::DoPhase(int /* nPhase */)
7c78e7c7 343{
01b2eeec 344 return TRUE;
7c78e7c7
RR
345}
346
01b2eeec 347void wxNotebook::Command(wxCommandEvent& event)
7c78e7c7 348{
01b2eeec 349 wxFAIL_MSG("wxNotebook::Command not implemented");
7c78e7c7
RR
350}
351
01b2eeec
KB
352// ----------------------------------------------------------------------------
353// wxNotebook helper functions
354// ----------------------------------------------------------------------------
355
356// hide the currently active panel and show the new one
357void 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}
7c78e7c7 371