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