]> git.saurik.com Git - wxWidgets.git/blame - src/generic/notebook.cpp
correct painting of the items with custom colours in TVIS_DROPHILITED state (patch...
[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
ed58dbea 38#include "wx/generic/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
2e4df4bf
VZ
52DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED)
53DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING)
54
1e6d9499 55BEGIN_EVENT_TABLE(wxNotebook, wxControl)
ca65c044 56 EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange)
1e6d9499
JS
57 EVT_SIZE(wxNotebook::OnSize)
58 EVT_PAINT(wxNotebook::OnPaint)
59 EVT_MOUSE_EVENTS(wxNotebook::OnMouseEvent)
60 EVT_SET_FOCUS(wxNotebook::OnSetFocus)
61 EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey)
1e6d9499
JS
62END_EVENT_TABLE()
63
64IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl)
65IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent)
1e6d9499
JS
66
67// ============================================================================
68// implementation
69// ============================================================================
70
00dd3b18
MB
71// ============================================================================
72// Private class
73// ============================================================================
74
dd5e8687
MW
75WX_DECLARE_HASH_MAP(int, wxNotebookPage*, wxIntegerHash, wxIntegerEqual,
76 wxIntToNotebookPageHashMap);
77
78WX_DECLARE_HASH_MAP(wxNotebookPage*, int, wxPointerHash, wxPointerEqual,
79 wxNotebookPageToIntHashMap);
80
00dd3b18
MB
81// This reuses wxTabView to draw the tabs.
82class WXDLLEXPORT wxNotebookTabView: public wxTabView
83{
84DECLARE_DYNAMIC_CLASS(wxNotebookTabView)
85public:
bc5a5239
WS
86 wxNotebookTabView(wxNotebook* notebook, long style = wxTAB_STYLE_DRAW_BOX | wxTAB_STYLE_COLOUR_INTERIOR);
87 ~wxNotebookTabView(void);
00dd3b18 88
bc5a5239
WS
89 // Called when a tab is activated
90 virtual void OnTabActivate(int activateId, int deactivateId);
91 // Allows vetoing
92 virtual bool OnTabPreActivate(int activateId, int deactivateId);
00dd3b18 93
dd5e8687
MW
94 // map integer ids used by wxTabView to wxNotebookPage pointers
95 int GetId(wxNotebookPage *page);
96 wxNotebookPage *GetPage(int id) { return m_idToPage[id]; }
97
00dd3b18 98protected:
dd5e8687
MW
99 wxNotebook* m_notebook;
100
101private:
102 wxIntToNotebookPageHashMap m_idToPage;
103 wxNotebookPageToIntHashMap m_pageToId;
104 int m_nextid;
00dd3b18
MB
105};
106
dd5e8687
MW
107static int GetPageId(wxTabView *tabview, wxNotebookPage *page)
108{
98b9b5ea 109 return wx_static_cast(wxNotebookTabView*, tabview)->GetId(page);
dd5e8687
MW
110}
111
1e6d9499
JS
112// ----------------------------------------------------------------------------
113// wxNotebook construction
114// ----------------------------------------------------------------------------
115
116// common part of all ctors
117void wxNotebook::Init()
118{
119 m_tabView = (wxNotebookTabView*) NULL;
1e6d9499
JS
120 m_nSelection = -1;
121}
122
123// default for dynamic class
124wxNotebook::wxNotebook()
125{
126 Init();
127}
128
129// the same arguments as for wxControl
130wxNotebook::wxNotebook(wxWindow *parent,
131 wxWindowID id,
132 const wxPoint& pos,
133 const wxSize& size,
134 long style,
135 const wxString& name)
136{
137 Init();
138
139 Create(parent, id, pos, size, style, name);
140}
141
142// Create() function
143bool wxNotebook::Create(wxWindow *parent,
144 wxWindowID id,
145 const wxPoint& pos,
146 const wxSize& size,
147 long style,
148 const wxString& name)
149{
150 // base init
151 SetName(name);
152
ca65c044 153 m_windowId = id == wxID_ANY ? NewControlId() : id;
1e6d9499 154
b4f8693c 155 if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name))
ca65c044 156 return false;
1e6d9499 157
a756f210 158 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE));
f60d0f94 159
1e6d9499
JS
160 SetTabView(new wxNotebookTabView(this));
161
ca65c044 162 return true;
1e6d9499
JS
163}
164
165// dtor
166wxNotebook::~wxNotebook()
167{
168 delete m_tabView;
169}
170
171// ----------------------------------------------------------------------------
172// wxNotebook accessors
173// ----------------------------------------------------------------------------
1e6d9499
JS
174int wxNotebook::GetRowCount() const
175{
176 // TODO
177 return 0;
178}
179
15aad3b9 180int wxNotebook::SetSelection(size_t nPage)
1e6d9499 181{
1e6d9499
JS
182 wxASSERT( IS_VALID_PAGE(nPage) );
183
184 wxNotebookPage* pPage = GetPage(nPage);
185
dd5e8687 186 m_tabView->SetTabSelection(GetPageId(m_tabView, pPage));
3a5bcc4d 187
1e6d9499
JS
188 // TODO
189 return 0;
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
JS
273
274 if (m_nSelection != -1)
275 {
ca65c044 276 m_pages[m_nSelection]->Show(false);
45f22d48 277 m_pages[m_nSelection]->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 {
bc5a5239
WS
289 m_nSelection = -1;
290 m_tabView->SetTabSelection(-1, false);
1e6d9499
JS
291 }
292 else if (m_nSelection > -1)
293 {
bc5a5239 294 m_nSelection = -1;
3a5bcc4d 295
dd5e8687 296 m_tabView->SetTabSelection(GetPageId(m_tabView, GetPage(0)), false);
3a5bcc4d 297
bc5a5239
WS
298 if (m_nSelection != 0)
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
JS
336 {
337 m_nSelection = -1;
ca65c044 338 m_tabView->SetTabSelection(-1, true);
1e6d9499
JS
339 }
340 else if (m_nSelection > -1)
341 {
342 // Only change the selection if the page we
343 // deleted was the selection.
30d2b71d 344 if (nPage == (size_t)m_nSelection)
1e6d9499
JS
345 {
346 m_nSelection = -1;
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.
30d2b71d 355 if (size_t(m_nSelection) > nPage)
1e6d9499
JS
356 m_nSelection -- ;
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
427 if ( m_nSelection == -1 )
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
541void wxNotebook::OnSelChange(wxNotebookEvent& event)
542{
543 // is it our tab control?
544 if ( event.GetEventObject() == this )
545 {
546 if (event.GetSelection() != m_nSelection)
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
557 if ( m_nSelection != -1 )
45f22d48 558 m_pages[m_nSelection]->SetFocus();
1e6d9499
JS
559
560 event.Skip();
561}
562
563void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event)
564{
565 if ( event.IsWindowChange() ) {
566 // change pages
567 AdvanceSelection(event.GetDirection());
568 }
569 else {
570 // pass to the parent
571 if ( GetParent() ) {
572 event.SetCurrentFocus(this);
573 GetParent()->ProcessEvent(event);
574 }
575 }
576}
577
578// ----------------------------------------------------------------------------
579// wxNotebook base class virtuals
580// ----------------------------------------------------------------------------
581
582// override these 2 functions to do nothing: everything is done in OnSize
583
584void wxNotebook::SetConstraintSizes(bool /* recurse */)
585{
586 // don't set the sizes of the pages - their correct size is not yet known
ca65c044 587 wxControl::SetConstraintSizes(false);
1e6d9499
JS
588}
589
590bool wxNotebook::DoPhase(int /* nPhase */)
591{
ca65c044 592 return true;
1e6d9499
JS
593}
594
af111fc3 595void wxNotebook::Command(wxCommandEvent& WXUNUSED(event))
1e6d9499 596{
b0c0a393 597 wxFAIL_MSG(wxT("wxNotebook::Command not implemented"));
1e6d9499
JS
598}
599
600// ----------------------------------------------------------------------------
601// wxNotebook helper functions
602// ----------------------------------------------------------------------------
603
604// hide the currently active panel and show the new one
605void wxNotebook::ChangePage(int nOldSel, int nSel)
606{
607 // cout << "ChangePage: " << nOldSel << ", " << nSel << "\n";
608 wxASSERT( nOldSel != nSel ); // impossible
609
610 if ( nOldSel != -1 ) {
ca65c044 611 m_pages[nOldSel]->Show(false);
45f22d48 612 m_pages[nOldSel]->Lower();
1e6d9499
JS
613 }
614
45f22d48 615 wxNotebookPage *pPage = m_pages[nSel];
1e6d9499
JS
616
617 wxRect clientRect = GetAvailableClientSize();
618 pPage->SetSize(clientRect.x, clientRect.y, clientRect.width, clientRect.height);
619
f6bcfd97
BP
620 Refresh();
621
ca65c044 622 pPage->Show(true);
1e6d9499
JS
623 pPage->Raise();
624 pPage->SetFocus();
625
1e6d9499
JS
626 m_nSelection = nSel;
627}
628
629void wxNotebook::OnMouseEvent(wxMouseEvent& event)
630{
631 if (m_tabView)
632 m_tabView->OnEvent(event);
633}
634
635void wxNotebook::OnPaint(wxPaintEvent& WXUNUSED(event) )
636{
637 wxPaintDC dc(this);
638 if (m_tabView)
639 m_tabView->Draw(dc);
640}
641
6bae6726
MB
642wxSize wxNotebook::CalcSizeFromPage(const wxSize& sizePage) const
643{
644 // MBN: since the total tab height is really a function of the
645 // width, this should really call
646 // GetTotalTabHeightPretendingWidthIs(), but the current
647 // implementation will suffice, provided the wxNotebook has been
648 // created with a sensible initial width.
649 return wxSize( sizePage.x + 12,
650 sizePage.y + m_tabView->GetTotalTabHeight() + 6 + 4 );
651}
652
1e6d9499
JS
653wxRect wxNotebook::GetAvailableClientSize()
654{
655 int cw, ch;
656 GetClientSize(& cw, & ch);
657
658 int tabHeight = m_tabView->GetTotalTabHeight();
659
660 // TODO: these margins should be configurable.
661 wxRect rect;
662 rect.x = 6;
663 rect.y = tabHeight + 6;
664 rect.width = cw - 12;
665 rect.height = ch - 4 - rect.y ;
666
667 return rect;
668}
669
670/*
671 * wxNotebookTabView
672 */
2e4df4bf 673
1e6d9499
JS
674IMPLEMENT_CLASS(wxNotebookTabView, wxTabView)
675
dd5e8687
MW
676wxNotebookTabView::wxNotebookTabView(wxNotebook *notebook, long style)
677 : wxTabView(style), m_nextid(1)
1e6d9499
JS
678{
679 m_notebook = notebook;
680
681 m_notebook->SetTabView(this);
682
683 SetWindow(m_notebook);
684}
685
686wxNotebookTabView::~wxNotebookTabView(void)
687{
688}
689
dd5e8687
MW
690int wxNotebookTabView::GetId(wxNotebookPage *page)
691{
692 int& id = m_pageToId[page];
693
694 if (!id)
695 {
696 id = m_nextid++;
697 m_idToPage[id] = page;
698 }
699
700 return id;
701}
702
1e6d9499
JS
703// Called when a tab is activated
704void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId)
705{
706 if (!m_notebook)
707 return;
708
709 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId());
710
711 // Translate from wxTabView's ids (which aren't position-dependent)
712 // to wxNotebook's (which are).
dd5e8687
MW
713 wxNotebookPage* pActive = GetPage(activateId);
714 wxNotebookPage* pDeactive = GetPage(deactivateId);
1e6d9499
JS
715
716 int activatePos = m_notebook->FindPagePosition(pActive);
717 int deactivatePos = m_notebook->FindPagePosition(pDeactive);
718
719 event.SetEventObject(m_notebook);
720 event.SetSelection(activatePos);
721 event.SetOldSelection(deactivatePos);
722 m_notebook->GetEventHandler()->ProcessEvent(event);
723}
724
1c507b17
JS
725// Allows Vetoing
726bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId)
727{
ca65c044
WS
728 bool retval = true;
729
1c507b17
JS
730 if (m_notebook)
731 {
732 wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId());
733
1c507b17
JS
734 // Translate from wxTabView's ids (which aren't position-dependent)
735 // to wxNotebook's (which are).
dd5e8687
MW
736 wxNotebookPage* pActive = GetPage(activateId);
737 wxNotebookPage* pDeactive = GetPage(deactivateId);
1c507b17
JS
738
739 int activatePos = m_notebook->FindPagePosition(pActive);
740 int deactivatePos = m_notebook->FindPagePosition(pDeactive);
741
1c507b17
JS
742 event.SetEventObject(m_notebook);
743 event.SetSelection(activatePos);
744 event.SetOldSelection(deactivatePos);
745 if (m_notebook->GetEventHandler()->ProcessEvent(event))
746 {
747 retval = event.IsAllowed();
748 }
749 }
750 return retval;
ca65c044 751}
bc5a5239
WS
752
753#endif // wxUSE_NOTEBOOK