]> git.saurik.com Git - wxWidgets.git/blame - src/generic/notebook.cpp
use const arrays for wxDC array parameters, closes #10712
[wxWidgets.git] / src / generic / notebook.cpp
CommitLineData
1e6d9499 1///////////////////////////////////////////////////////////////////////////////
7fc65a03
WS
2// Name: src/generic/notebook.cpp
3// Purpose: generic implementation of wxNotebook
1e6d9499
JS
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
1e6d9499
JS
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
ffecfa5a 19
1e6d9499
JS
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
df91131c 24 #pragma hdrstop
1e6d9499
JS
25#endif
26
bc5a5239
WS
27#if wxUSE_NOTEBOOK
28
df91131c
WS
29#include "wx/notebook.h"
30
31#ifndef WX_PRECOMP
32 #include "wx/string.h"
e4db172a 33 #include "wx/log.h"
ed4b0fdc 34 #include "wx/dcclient.h"
9eddec69 35 #include "wx/settings.h"
df91131c 36#endif
4055ed82 37
1c36c09c 38#include "wx/imaglist.h"
00dd3b18 39#include "wx/generic/tabg.h"
1e6d9499
JS
40
41// ----------------------------------------------------------------------------
42// macros
43// ----------------------------------------------------------------------------
44
45// check that the page index is valid
0ea23391 46#define IS_VALID_PAGE(nPage) ((nPage) < GetPageCount())
1e6d9499
JS
47
48// ----------------------------------------------------------------------------
49// event table
50// ----------------------------------------------------------------------------
51
8dba4c72 52BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase)
ca65c044 53 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
1e6d9499
JS
54 EVT_SIZE(wxNotebook::OnSize)
55 EVT_PAINT(wxNotebook::OnPaint)
56 EVT_MOUSE_EVENTS(wxNotebook::OnMouseEvent)
57 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
58 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
1e6d9499
JS
59END_EVENT_TABLE()
60
1e6d9499
JS
61// ============================================================================
62// implementation
63// ============================================================================
64
00dd3b18
MB
65// ============================================================================
66// Private class
67// ============================================================================
68
dd5e8687
MW
69WX_DECLARE_HASH_MAP(int, wxNotebookPage*, wxIntegerHash, wxIntegerEqual,
70 wxIntToNotebookPageHashMap);
71
72WX_DECLARE_HASH_MAP(wxNotebookPage*, int, wxPointerHash, wxPointerEqual,
73 wxNotebookPageToIntHashMap);
74
00dd3b18
MB
75// This reuses wxTabView to draw the tabs.
76class WXDLLEXPORT wxNotebookTabView: public wxTabView
77{
78DECLARE_DYNAMIC_CLASS(wxNotebookTabView)
79public:
bc5a5239 80 wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
d3c7fc99 81 virtual ~wxNotebookTabView(void);
00dd3b18 82
bc5a5239
WS
83 // Called when a tab is activated
84 virtual void OnTabActivate(int activateId, int deactivateId);
85 // Allows vetoing
86 virtual bool OnTabPreActivate(int activateId, int deactivateId);
00dd3b18 87
dd5e8687
MW
88 // map integer ids used by wxTabView to wxNotebookPage pointers
89 int GetId(wxNotebookPage *page);
90 wxNotebookPage *GetPage(int id) { return m_idToPage[id]; }
91
00dd3b18 92protected:
dd5e8687
MW
93 wxNotebook* m_notebook;
94
95private:
96 wxIntToNotebookPageHashMap m_idToPage;
97 wxNotebookPageToIntHashMap m_pageToId;
98 int m_nextid;
00dd3b18
MB
99};
100
dd5e8687
MW
101static int GetPageId(wxTabView *tabview, wxNotebookPage *page)
102{
5c33522f 103 return static_cast<wxNotebookTabView*>(tabview)->GetId(page);
dd5e8687
MW
104}
105
1e6d9499
JS
106// ----------------------------------------------------------------------------
107// wxNotebook construction
108// ----------------------------------------------------------------------------
109
110// common part of all ctors
111void wxNotebook::Init()
112{
d3b9f782 113 m_tabView = NULL;
a987bdfa 114 m_selection = -1;
1e6d9499
JS
115}
116
117// default for dynamic class
118wxNotebook::wxNotebook()
119{
120 Init();
121}
122
123// the same arguments as for wxControl
124wxNotebook::wxNotebook(wxWindow *parent,
125 wxWindowID id,
126 const wxPoint& pos,
127 const wxSize& size,
128 long style,
129 const wxString& name)
130{
131 Init();
132
133 Create(parent, id, pos, size, style, name);
134}
135
136// Create() function
137bool wxNotebook::Create(wxWindow *parent,
138 wxWindowID id,
139 const wxPoint& pos,
140 const wxSize& size,
141 long style,
142 const wxString& name)
143{
144 // base init
145 SetName(name);
146
90f9b8ef
JS
147 if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
148 style |= wxBK_TOP;
6e271798 149
ca65c044 150 m_windowId = id == wxID_ANY ? NewControlId() : id;
1e6d9499 151
b4f8693c 152 if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
ca65c044 153 return false;
1e6d9499
JS
154
155 SetTabView(new wxNotebookTabView(this));
156
ca65c044 157 return true;
1e6d9499
JS
158}
159
160// dtor
161wxNotebook::~wxNotebook()
162{
163 delete m_tabView;
164}
165
166// ----------------------------------------------------------------------------
167// wxNotebook accessors
168// ----------------------------------------------------------------------------
1e6d9499
JS
169int wxNotebook::GetRowCount() const
170{
171 // TODO
172 return 0;
173}
174
15aad3b9 175int wxNotebook::SetSelection(size_t nPage)
1e6d9499 176{
1e6d9499
JS
177 wxASSERT( IS_VALID_PAGE(nPage) );
178
179 wxNotebookPage* pPage = GetPage(nPage);
180
dd5e8687 181 m_tabView->SetTabSelection(GetPageId(m_tabView, pPage));
3a5bcc4d 182
1e6d9499
JS
183 // TODO
184 return 0;
185}
186
6e271798
VZ
187int wxNotebook::ChangeSelection(size_t nPage)
188{
189 // FIXME: currently it does generate events too
190 return SetSelection(nPage);
191}
192
45f22d48 193#if 0
1e6d9499
JS
194void wxNotebook::AdvanceSelection(bool bForward)
195{
196 int nSel = GetSelection();
197 int nMax = GetPageCount() - 1;
198 if ( bForward )
199 SetSelection(nSel == nMax ? 0 : nSel + 1);
200 else
201 SetSelection(nSel == 0 ? nMax : nSel - 1);
202}
45f22d48 203#endif
1e6d9499 204
15aad3b9 205bool wxNotebook::SetPageText(size_t nPage, const wxString& strText)
1e6d9499
JS
206{
207 wxASSERT( IS_VALID_PAGE(nPage) );
3a5bcc4d 208
1e6d9499
JS
209 wxNotebookPage* page = GetPage(nPage);
210 if (page)
211 {
dd5e8687 212 m_tabView->SetTabText(GetPageId(m_tabView, page), strText);
1e6d9499 213 Refresh();
ca65c044 214 return true;
1e6d9499 215 }
3a5bcc4d 216
ca65c044 217 return false;
1e6d9499
JS
218}
219
15aad3b9 220wxString wxNotebook::GetPageText(size_t nPage) const
1e6d9499
JS
221{
222 wxASSERT( IS_VALID_PAGE(nPage) );
223
224 wxNotebookPage* page = ((wxNotebook*)this)->GetPage(nPage);
225 if (page)
dd5e8687 226 return m_tabView->GetTabText(GetPageId(m_tabView, page));
1e6d9499
JS
227 else
228 return wxEmptyString;
229}
230
3f9ee1cd 231int wxNotebook::GetPageImage(size_t WXUNUSED_UNLESS_DEBUG(nPage)) const
1e6d9499
JS
232{
233 wxASSERT( IS_VALID_PAGE(nPage) );
234
235 // TODO
236 return 0;
237}
238
3f9ee1cd
VZ
239bool wxNotebook::SetPageImage(size_t WXUNUSED_UNLESS_DEBUG(nPage),
240 int WXUNUSED(nImage))
1e6d9499
JS
241{
242 wxASSERT( IS_VALID_PAGE(nPage) );
243
244 // TODO
ca65c044 245 return false;
1e6d9499
JS
246}
247
9806a47c 248// set the size (the same for all pages)
7fc65a03 249void wxNotebook::SetPageSize(const wxSize& WXUNUSED(size))
9806a47c
JS
250{
251 // TODO
252}
253
254// set the padding between tabs (in pixels)
7fc65a03 255void wxNotebook::SetPadding(const wxSize& WXUNUSED(padding))
9806a47c
JS
256{
257 // TODO
258}
259
260// set the size of the tabs for wxNB_FIXEDWIDTH controls
7fc65a03 261void wxNotebook::SetTabSize(const wxSize& WXUNUSED(sz))
9806a47c
JS
262{
263 // TODO
264}
265
1e6d9499
JS
266// ----------------------------------------------------------------------------
267// wxNotebook operations
268// ----------------------------------------------------------------------------
269
270// remove one page from the notebook and delete it
15aad3b9 271bool wxNotebook::DeletePage(size_t nPage)
1e6d9499 272{
ca65c044 273 wxCHECK( IS_VALID_PAGE(nPage), false );
1e6d9499 274
a987bdfa 275 if (m_selection != -1)
1e6d9499 276 {
a987bdfa
JJ
277 m_pages[m_selection]->Show(false);
278 m_pages[m_selection]->Lower();
1e6d9499
JS
279 }
280
281 wxNotebookPage* pPage = GetPage(nPage);
3a5bcc4d 282
dd5e8687 283 m_tabView->RemoveTab(GetPageId(m_tabView, pPage));
1e6d9499 284
45f22d48
JS
285 m_pages.Remove(pPage);
286 delete pPage;
1e6d9499 287
45f22d48 288 if (m_pages.GetCount() == 0)
1e6d9499 289 {
a987bdfa 290 m_selection = -1;
bc5a5239 291 m_tabView->SetTabSelection(-1, false);
1e6d9499 292 }
a987bdfa 293 else if (m_selection > -1)
1e6d9499 294 {
a987bdfa 295 m_selection = -1;
3a5bcc4d 296
dd5e8687 297 m_tabView->SetTabSelection(GetPageId(m_tabView, GetPage(0)), false);
3a5bcc4d 298
a987bdfa 299 if (m_selection != 0)
bc5a5239 300 ChangePage(-1, 0);
1e6d9499
JS
301 }
302
ca65c044 303 RefreshLayout(false);
1e6d9499 304
ca65c044 305 return true;
1e6d9499
JS
306}
307
308bool wxNotebook::DeletePage(wxNotebookPage* page)
309{
310 int pagePos = FindPagePosition(page);
311 if (pagePos > -1)
312 return DeletePage(pagePos);
313 else
ca65c044 314 return false;
1e6d9499
JS
315}
316
15aad3b9 317bool wxNotebook::RemovePage(size_t nPage)
64b090c7
MB
318{
319 return DoRemovePage(nPage) != NULL;
320}
321
322// remove one page from the notebook
323wxWindow* wxNotebook::DoRemovePage(size_t nPage)
1e6d9499 324{
10f2222c 325 wxCHECK( IS_VALID_PAGE(nPage), NULL );
1e6d9499 326
ca65c044 327 m_pages[nPage]->Show(false);
45f22d48 328 // m_pages[nPage]->Lower();
1e6d9499
JS
329
330 wxNotebookPage* pPage = GetPage(nPage);
3a5bcc4d 331
dd5e8687 332 m_tabView->RemoveTab(GetPageId(m_tabView, pPage));
1e6d9499 333
45f22d48 334 m_pages.Remove(pPage);
1e6d9499 335
45f22d48 336 if (m_pages.GetCount() == 0)
1e6d9499 337 {
a987bdfa 338 m_selection = -1;
ca65c044 339 m_tabView->SetTabSelection(-1, true);
1e6d9499 340 }
a987bdfa 341 else if (m_selection > -1)
1e6d9499
JS
342 {
343 // Only change the selection if the page we
344 // deleted was the selection.
a987bdfa 345 if (nPage == (size_t)m_selection)
1e6d9499 346 {
a987bdfa 347 m_selection = -1;
1e6d9499 348 // Select the first tab. Generates a ChangePage.
ca65c044 349 m_tabView->SetTabSelection(0, true);
1e6d9499
JS
350 }
351 else
352 {
ca65c044 353 // We must adjust which tab we think is selected.
1e6d9499
JS
354 // If greater than the page we deleted, it must be moved down
355 // a notch.
a987bdfa
JJ
356 if (size_t(m_selection) > nPage)
357 m_selection -- ;
1e6d9499
JS
358 }
359 }
360
ca65c044 361 RefreshLayout(false);
1e6d9499 362
64b090c7 363 return pPage;
1e6d9499
JS
364}
365
366bool wxNotebook::RemovePage(wxNotebookPage* page)
367{
368 int pagePos = FindPagePosition(page);
369 if (pagePos > -1)
370 return RemovePage(pagePos);
371 else
ca65c044 372 return false;
1e6d9499
JS
373}
374
375// Find the position of the wxNotebookPage, -1 if not found.
376int wxNotebook::FindPagePosition(wxNotebookPage* page) const
377{
15aad3b9
VZ
378 size_t nPageCount = GetPageCount();
379 size_t nPage;
1e6d9499 380 for ( nPage = 0; nPage < nPageCount; nPage++ )
45f22d48 381 if (m_pages[nPage] == page)
1e6d9499
JS
382 return nPage;
383 return -1;
384}
385
386// remove all pages
387bool wxNotebook::DeleteAllPages()
388{
ca65c044 389 m_tabView->ClearTabs(true);
1e6d9499 390
15aad3b9
VZ
391 size_t nPageCount = GetPageCount();
392 size_t nPage;
1e6d9499 393 for ( nPage = 0; nPage < nPageCount; nPage++ )
45f22d48 394 delete m_pages[nPage];
1e6d9499 395
45f22d48 396 m_pages.Clear();
1e6d9499 397
ca65c044 398 return true;
1e6d9499
JS
399}
400
1e6d9499 401// same as AddPage() but does it at given position
15aad3b9 402bool wxNotebook::InsertPage(size_t nPage,
1e6d9499
JS
403 wxNotebookPage *pPage,
404 const wxString& strText,
405 bool bSelect,
7fc65a03 406 int WXUNUSED(imageId))
1e6d9499
JS
407{
408 wxASSERT( pPage != NULL );
ca65c044 409 wxCHECK( IS_VALID_PAGE(nPage) || nPage == GetPageCount(), false );
1e6d9499 410
dd5e8687 411 m_tabView->AddTab(GetPageId(m_tabView, pPage), strText);
3a5bcc4d 412
1e6d9499 413 if (!bSelect)
ca65c044 414 pPage->Show(false);
1e6d9499
JS
415
416 // save the pointer to the page
45f22d48 417 m_pages.Insert(pPage, nPage);
1e6d9499
JS
418
419 if (bSelect)
420 {
421 // This will cause ChangePage to be called, via OnSelPage
3a5bcc4d 422
dd5e8687 423 m_tabView->SetTabSelection(GetPageId(m_tabView, pPage), true);
1e6d9499
JS
424 }
425
426 // some page must be selected: either this one or the first one if there is
427 // still no selection
a987bdfa 428 if ( m_selection == -1 )
1e6d9499
JS
429 ChangePage(-1, 0);
430
ca65c044 431 RefreshLayout(false);
1e6d9499 432
ca65c044 433 return true;
1e6d9499
JS
434}
435
436// ----------------------------------------------------------------------------
437// wxNotebook callbacks
438// ----------------------------------------------------------------------------
439
440// @@@ OnSize() is used for setting the font when it's called for the first
441// time because doing it in ::Create() doesn't work (for unknown reasons)
442void wxNotebook::OnSize(wxSizeEvent& event)
443{
ca65c044 444 static bool s_bFirstTime = true;
1e6d9499
JS
445 if ( s_bFirstTime ) {
446 // TODO: any first-time-size processing.
ca65c044 447 s_bFirstTime = false;
1e6d9499
JS
448 }
449
450 RefreshLayout();
451
452 // Processing continues to next OnSize
453 event.Skip();
454}
455
456// This was supposed to cure the non-display of the notebook
457// until the user resizes the window.
458// What's going on?
5180055b 459void wxNotebook::OnInternalIdle()
1e6d9499 460{
5180055b
JS
461 wxWindow::OnInternalIdle();
462
ca65c044
WS
463#if 0
464 static bool s_bFirstTime = true;
1e6d9499
JS
465 if ( s_bFirstTime ) {
466 /*
467 wxSize sz(GetSize());
468 sz.x ++;
469 SetSize(sz);
470 sz.x --;
471 SetSize(sz);
472 */
473
474 /*
475 wxSize sz(GetSize());
476 wxSizeEvent sizeEvent(sz, GetId());
477 sizeEvent.SetEventObject(this);
478 GetEventHandler()->ProcessEvent(sizeEvent);
479 Refresh();
480 */
ca65c044 481 s_bFirstTime = false;
1e6d9499 482 }
5180055b 483#endif
1e6d9499
JS
484}
485
486// Implementation: calculate the layout of the view rect
487// and resize the children if required
488bool wxNotebook::RefreshLayout(bool force)
489{
490 if (m_tabView)
491 {
492 wxRect oldRect = m_tabView->GetViewRect();
493
494 int cw, ch;
495 GetClientSize(& cw, & ch);
496
497 int tabHeight = m_tabView->GetTotalTabHeight();
498 wxRect rect;
499 rect.x = 4;
500 rect.y = tabHeight + 4;
501 rect.width = cw - 8;
502 rect.height = ch - 4 - rect.y ;
2e4df4bf 503
1e6d9499
JS
504 m_tabView->SetViewRect(rect);
505
25889d3c 506 m_tabView->LayoutTabs();
1e6d9499
JS
507
508 // Need to do it a 2nd time to get the tab height with
509 // the new view width, since changing the view width changes the
510 // tab layout.
511 tabHeight = m_tabView->GetTotalTabHeight();
512 rect.x = 4;
513 rect.y = tabHeight + 4;
514 rect.width = cw - 8;
515 rect.height = ch - 4 - rect.y ;
2e4df4bf 516
1e6d9499
JS
517 m_tabView->SetViewRect(rect);
518
25889d3c 519 m_tabView->LayoutTabs();
1e6d9499
JS
520
521 if (!force && (rect == oldRect))
ca65c044 522 return false;
1e6d9499
JS
523
524 // fit the notebook page to the tab control's display area
525
15aad3b9
VZ
526 size_t nCount = m_pages.Count();
527 for ( size_t nPage = 0; nPage < nCount; nPage++ ) {
45f22d48 528 wxNotebookPage *pPage = m_pages[nPage];
10d1f413 529 wxRect clientRect = GetAvailableClientSize();
1e6d9499
JS
530 if (pPage->IsShown())
531 {
1e6d9499
JS
532 pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
533 if ( pPage->GetAutoLayout() )
534 pPage->Layout();
535 }
536 }
537 Refresh();
538 }
ca65c044 539 return true;
1e6d9499
JS
540}
541
3e97a905 542void wxNotebook::OnSelChange(wxBookCtrlEvent& event)
1e6d9499
JS
543{
544 // is it our tab control?
545 if ( event.GetEventObject() == this )
546 {
a987bdfa 547 if (event.GetSelection() != m_selection)
1e6d9499
JS
548 ChangePage(event.GetOldSelection(), event.GetSelection());
549 }
550
551 // we want to give others a chance to process this message as well
552 event.Skip();
553}
554
555void wxNotebook::OnSetFocus(wxFocusEvent& event)
556{
557 // set focus to the currently selected page if any
a987bdfa
JJ
558 if ( m_selection != -1 )
559 m_pages[m_selection]->SetFocus();
1e6d9499
JS
560
561 event.Skip();
562}
563
564void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
565{
3b7fa206
VZ
566 if ( event.IsWindowChange() )
567 {
1e6d9499
JS
568 // change pages
569 AdvanceSelection(event.GetDirection());
570 }
571 else {
572 // pass to the parent
3b7fa206
VZ
573 if ( GetParent() )
574 {
1e6d9499 575 event.SetCurrentFocus(this);
3b7fa206 576 GetParent()->ProcessWindowEvent(event);
1e6d9499
JS
577 }
578 }
579}
580
581// ----------------------------------------------------------------------------
582// wxNotebook base class virtuals
583// ----------------------------------------------------------------------------
584
585// override these 2 functions to do nothing: everything is done in OnSize
586
587void wxNotebook::SetConstraintSizes(bool /* recurse */)
588{
589 // don't set the sizes of the pages - their correct size is not yet known
ca65c044 590 wxControl::SetConstraintSizes(false);
1e6d9499
JS
591}
592
593bool wxNotebook::DoPhase(int /* nPhase */)
594{
ca65c044 595 return true;
1e6d9499
JS
596}
597
af111fc3 598void wxNotebook::Command(wxCommandEvent& WXUNUSED(event))
1e6d9499 599{
b0c0a393 600 wxFAIL_MSG(wxT("wxNotebook::Command not implemented"));
1e6d9499
JS
601}
602
603// ----------------------------------------------------------------------------
604// wxNotebook helper functions
605// ----------------------------------------------------------------------------
606
607// hide the currently active panel and show the new one
608void wxNotebook::ChangePage(int nOldSel, int nSel)
609{
610 // cout << "ChangePage: " << nOldSel << ", " << nSel << "\n";
611 wxASSERT( nOldSel != nSel ); // impossible
612
613 if ( nOldSel != -1 ) {
ca65c044 614 m_pages[nOldSel]->Show(false);
45f22d48 615 m_pages[nOldSel]->Lower();
1e6d9499
JS
616 }
617
45f22d48 618 wxNotebookPage *pPage = m_pages[nSel];
1e6d9499
JS
619
620 wxRect clientRect = GetAvailableClientSize();
621 pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
622
f6bcfd97
BP
623 Refresh();
624
ca65c044 625 pPage->Show(true);
1e6d9499
JS
626 pPage->Raise();
627 pPage->SetFocus();
628
a987bdfa 629 m_selection = nSel;
1e6d9499
JS
630}
631
632void wxNotebook::OnMouseEvent(wxMouseEvent& event)
633{
634 if (m_tabView)
635 m_tabView->OnEvent(event);
636}
637
638void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event) )
639{
640 wxPaintDC dc(this);
641 if (m_tabView)
642 m_tabView->Draw(dc);
643}
644
6bae6726
MB
645wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
646{
647 // MBN: since the total tab height is really a function of the
648 // width, this should really call
649 // GetTotalTabHeightPretendingWidthIs(), but the current
650 // implementation will suffice, provided the wxNotebook has been
651 // created with a sensible initial width.
652 return wxSize( sizePage.x + 12,
653 sizePage.y + m_tabView->GetTotalTabHeight() + 6 + 4 );
654}
655
1e6d9499
JS
656wxRect wxNotebook::GetAvailableClientSize()
657{
658 int cw, ch;
659 GetClientSize(& cw, & ch);
660
661 int tabHeight = m_tabView->GetTotalTabHeight();
662
663 // TODO: these margins should be configurable.
664 wxRect rect;
665 rect.x = 6;
666 rect.y = tabHeight + 6;
667 rect.width = cw - 12;
668 rect.height = ch - 4 - rect.y ;
669
670 return rect;
671}
672
673/*
674 * wxNotebookTabView
675 */
2e4df4bf 676
1e6d9499
JS
677IMPLEMENT_CLASS(wxNotebookTabView, wxTabView)
678
dd5e8687
MW
679wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style)
680 : wxTabView(style), m_nextid(1)
1e6d9499
JS
681{
682 m_notebook = notebook;
683
684 m_notebook->SetTabView(this);
685
686 SetWindow(m_notebook);
687}
688
689wxNotebookTabView::~wxNotebookTabView(void)
690{
691}
692
dd5e8687
MW
693int wxNotebookTabView::GetId(wxNotebookPage *page)
694{
695 int& id = m_pageToId[page];
696
697 if (!id)
698 {
699 id = m_nextid++;
700 m_idToPage[id] = page;
701 }
702
703 return id;
704}
705
1e6d9499
JS
706// Called when a tab is activated
707void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
708{
709 if (!m_notebook)
710 return;
711
3e97a905 712 wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
1e6d9499
JS
713
714 // Translate from wxTabView's ids (which aren't position-dependent)
715 // to wxNotebook's (which are).
dd5e8687
MW
716 wxNotebookPage* pActive = GetPage(activateId);
717 wxNotebookPage* pDeactive = GetPage(deactivateId);
1e6d9499
JS
718
719 int activatePos = m_notebook->FindPagePosition(pActive);
720 int deactivatePos = m_notebook->FindPagePosition(pDeactive);
721
722 event.SetEventObject(m_notebook);
723 event.SetSelection(activatePos);
724 event.SetOldSelection(deactivatePos);
725 m_notebook->GetEventHandler()->ProcessEvent(event);
726}
727
1c507b17
JS
728// Allows Vetoing
729bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId)
730{
ca65c044
WS
731 bool retval = true;
732
1c507b17
JS
733 if (m_notebook)
734 {
3e97a905 735 wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId());
1c507b17 736
1c507b17
JS
737 // Translate from wxTabView's ids (which aren't position-dependent)
738 // to wxNotebook's (which are).
dd5e8687
MW
739 wxNotebookPage* pActive = GetPage(activateId);
740 wxNotebookPage* pDeactive = GetPage(deactivateId);
1c507b17
JS
741
742 int activatePos = m_notebook->FindPagePosition(pActive);
743 int deactivatePos = m_notebook->FindPagePosition(pDeactive);
744
1c507b17
JS
745 event.SetEventObject(m_notebook);
746 event.SetSelection(activatePos);
747 event.SetOldSelection(deactivatePos);
748 if (m_notebook->GetEventHandler()->ProcessEvent(event))
749 {
750 retval = event.IsAllowed();
751 }
752 }
753 return retval;
ca65c044 754}
bc5a5239
WS
755
756#endif // wxUSE_NOTEBOOK