X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1c36c09cd5f591c3b047a7c7367e7ce91d069cdd..ca21c76b2a55252b483a3fe7e426211c229b50dc:/src/generic/notebook.cpp diff --git a/src/generic/notebook.cpp b/src/generic/notebook.cpp index 1d62732c1a..560ea1000f 100644 --- a/src/generic/notebook.cpp +++ b/src/generic/notebook.cpp @@ -49,10 +49,7 @@ // event table // ---------------------------------------------------------------------------- -DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED) -DEFINE_EVENT_TYPE(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING) - -BEGIN_EVENT_TABLE(wxNotebook, wxControl) +BEGIN_EVENT_TABLE(wxNotebook, wxBookCtrlBase) EVT_NOTEBOOK_PAGE_CHANGED(wxID_ANY, wxNotebook::OnSelChange) EVT_SIZE(wxNotebook::OnSize) EVT_PAINT(wxNotebook::OnPaint) @@ -61,9 +58,6 @@ BEGIN_EVENT_TABLE(wxNotebook, wxControl) EVT_NAVIGATION_KEY(wxNotebook::OnNavigationKey) END_EVENT_TABLE() -IMPLEMENT_DYNAMIC_CLASS(wxNotebook, wxControl) -IMPLEMENT_DYNAMIC_CLASS(wxNotebookEvent, wxCommandEvent) - // ============================================================================ // implementation // ============================================================================ @@ -106,7 +100,7 @@ private: static int GetPageId(wxTabView *tabview, wxNotebookPage *page) { - return wx_static_cast(wxNotebookTabView*, tabview)->GetId(page); + return static_cast(tabview)->GetId(page); } // ---------------------------------------------------------------------------- @@ -116,8 +110,8 @@ static int GetPageId(wxTabView *tabview, wxNotebookPage *page) // common part of all ctors void wxNotebook::Init() { - m_tabView = (wxNotebookTabView*) NULL; - m_nSelection = -1; + m_tabView = NULL; + m_selection = -1; } // default for dynamic class @@ -152,14 +146,12 @@ bool wxNotebook::Create(wxWindow *parent, if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT ) style |= wxBK_TOP; - + m_windowId = id == wxID_ANY ? NewControlId() : id; if (!wxControl::Create(parent, id, pos, size, style|wxNO_BORDER, wxDefaultValidator, name)) return false; - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); - SetTabView(new wxNotebookTabView(this)); return true; @@ -192,6 +184,12 @@ int wxNotebook::SetSelection(size_t nPage) return 0; } +int wxNotebook::ChangeSelection(size_t nPage) +{ + // FIXME: currently it does generate events too + return SetSelection(nPage); +} + #if 0 void wxNotebook::AdvanceSelection(bool bForward) { @@ -274,10 +272,10 @@ bool wxNotebook::DeletePage(size_t nPage) { wxCHECK( IS_VALID_PAGE(nPage), false ); - if (m_nSelection != -1) + if (m_selection != -1) { - m_pages[m_nSelection]->Show(false); - m_pages[m_nSelection]->Lower(); + m_pages[m_selection]->Show(false); + m_pages[m_selection]->Lower(); } wxNotebookPage* pPage = GetPage(nPage); @@ -289,16 +287,16 @@ bool wxNotebook::DeletePage(size_t nPage) if (m_pages.GetCount() == 0) { - m_nSelection = -1; + m_selection = -1; m_tabView->SetTabSelection(-1, false); } - else if (m_nSelection > -1) + else if (m_selection > -1) { - m_nSelection = -1; + m_selection = -1; m_tabView->SetTabSelection(GetPageId(m_tabView, GetPage(0)), false); - if (m_nSelection != 0) + if (m_selection != 0) ChangePage(-1, 0); } @@ -337,16 +335,16 @@ wxWindow* wxNotebook::DoRemovePage(size_t nPage) if (m_pages.GetCount() == 0) { - m_nSelection = -1; + m_selection = -1; m_tabView->SetTabSelection(-1, true); } - else if (m_nSelection > -1) + else if (m_selection > -1) { // Only change the selection if the page we // deleted was the selection. - if (nPage == (size_t)m_nSelection) + if (nPage == (size_t)m_selection) { - m_nSelection = -1; + m_selection = -1; // Select the first tab. Generates a ChangePage. m_tabView->SetTabSelection(0, true); } @@ -355,8 +353,8 @@ wxWindow* wxNotebook::DoRemovePage(size_t nPage) // We must adjust which tab we think is selected. // If greater than the page we deleted, it must be moved down // a notch. - if (size_t(m_nSelection) > nPage) - m_nSelection -- ; + if (size_t(m_selection) > nPage) + m_selection -- ; } } @@ -427,7 +425,7 @@ bool wxNotebook::InsertPage(size_t nPage, // some page must be selected: either this one or the first one if there is // still no selection - if ( m_nSelection == -1 ) + if ( m_selection == -1 ) ChangePage(-1, 0); RefreshLayout(false); @@ -541,12 +539,12 @@ bool wxNotebook::RefreshLayout(bool force) return true; } -void wxNotebook::OnSelChange(wxNotebookEvent& event) +void wxNotebook::OnSelChange(wxBookCtrlEvent& event) { // is it our tab control? if ( event.GetEventObject() == this ) { - if (event.GetSelection() != m_nSelection) + if (event.GetSelection() != m_selection) ChangePage(event.GetOldSelection(), event.GetSelection()); } @@ -557,23 +555,25 @@ void wxNotebook::OnSelChange(wxNotebookEvent& event) void wxNotebook::OnSetFocus(wxFocusEvent& event) { // set focus to the currently selected page if any - if ( m_nSelection != -1 ) - m_pages[m_nSelection]->SetFocus(); + if ( m_selection != -1 ) + m_pages[m_selection]->SetFocus(); event.Skip(); } void wxNotebook::OnNavigationKey(wxNavigationKeyEvent& event) { - if ( event.IsWindowChange() ) { + if ( event.IsWindowChange() ) + { // change pages AdvanceSelection(event.GetDirection()); } else { // pass to the parent - if ( GetParent() ) { + if ( GetParent() ) + { event.SetCurrentFocus(this); - GetParent()->ProcessEvent(event); + GetParent()->ProcessWindowEvent(event); } } } @@ -626,7 +626,7 @@ void wxNotebook::ChangePage(int nOldSel, int nSel) pPage->Raise(); pPage->SetFocus(); - m_nSelection = nSel; + m_selection = nSel; } void wxNotebook::OnMouseEvent(wxMouseEvent& event) @@ -709,7 +709,7 @@ void wxNotebookTabView::OnTabActivate(int activateId, int deactivateId) if (!m_notebook) return; - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId()); + wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, m_notebook->GetId()); // Translate from wxTabView's ids (which aren't position-dependent) // to wxNotebook's (which are). @@ -732,7 +732,7 @@ bool wxNotebookTabView::OnTabPreActivate(int activateId, int deactivateId) if (m_notebook) { - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId()); + wxBookCtrlEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_notebook->GetId()); // Translate from wxTabView's ids (which aren't position-dependent) // to wxNotebook's (which are).