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