From a570e8f8febd7213e789647478298293df4519db Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Oct 2006 23:41:52 +0000 Subject: [PATCH] added SendPageChanging/ChangedEvent() functions; fixed wxCocoa build broken by wxNotebook::ChangePage() change git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41764 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/notebook.h | 1 - include/wx/notebook.h | 11 +++++++++++ src/cocoa/notebook.mm | 17 ++++++++++++++++- src/common/nbkbase.cpp | 22 ++++++++++++++++++++++ src/gtk/notebook.cpp | 14 +++----------- src/mac/carbon/notebmac.cpp | 9 ++------- src/msw/notebook.cpp | 13 ++++--------- src/univ/notebook.cpp | 14 ++++---------- 8 files changed, 62 insertions(+), 39 deletions(-) diff --git a/include/wx/cocoa/notebook.h b/include/wx/cocoa/notebook.h index 97cfd33c4c..9ff89def28 100644 --- a/include/wx/cocoa/notebook.h +++ b/include/wx/cocoa/notebook.h @@ -57,7 +57,6 @@ protected: public: // set the currently selected page, return the index of the previously // selected one (or -1 on error) - // NB: this function will _not_ generate wxEVT_NOTEBOOK_PAGE_xxx events int SetSelection(size_t nPage); // get the currently selected page int GetSelection() const; diff --git a/include/wx/notebook.h b/include/wx/notebook.h index 88551e2f23..7fdb284892 100644 --- a/include/wx/notebook.h +++ b/include/wx/notebook.h @@ -89,6 +89,17 @@ public: // On platforms that support it, get the theme page background colour, else invalid colour virtual wxColour GetThemeBackgroundColour() const { return wxNullColour; } + + // send wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING/ED events + + // returns false if the change to nPage is vetoed by the program + bool SendPageChangingEvent(int nPage); + + // sends the event about page change from old to new (or GetSelection() if + // new is -1) + void SendPageChangedEvent(int nPageOld, int nPageNew = -1); + + protected: DECLARE_NO_COPY_CLASS(wxNotebookBase) }; diff --git a/src/cocoa/notebook.mm b/src/cocoa/notebook.mm index d79c9bd875..9cc3241b65 100644 --- a/src/cocoa/notebook.mm +++ b/src/cocoa/notebook.mm @@ -261,8 +261,23 @@ bool wxNotebook::SetPageImage(size_t nPage, int nImage) return true; } - int wxNotebook::SetSelection(size_t nPage) +{ + const int pageOld = GetSelection(); + + if ( !SendPageChangingEvent(nPage) ) + return pageOld; + + int page = ChangeSelection(nPage); + if ( page != wxNOT_FOUND ) + { + SendPageChangedEvent(pageOld); + } + + return page; +} + +int wxNotebook::ChangeSelection(size_t nPage) { wxAutoNSAutoreleasePool pool; [GetNSTabView() selectTabViewItemAtIndex:nPage]; diff --git a/src/common/nbkbase.cpp b/src/common/nbkbase.cpp index 47011be703..ec391bb57f 100644 --- a/src/common/nbkbase.cpp +++ b/src/common/nbkbase.cpp @@ -59,4 +59,26 @@ wxSize wxNotebookBase::CalcSizeFromPage(const wxSize& sizePage) const return sizeTotal; } +// ---------------------------------------------------------------------------- +// events +// ---------------------------------------------------------------------------- + +bool wxNotebookBase::SendPageChangingEvent(int nPage) +{ + wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, GetId()); + event.SetSelection(nPage); + event.SetOldSelection(GetSelection()); + event.SetEventObject(this); + return !GetEventHandler()->ProcessEvent(event) || event.IsAllowed(); +} + +void wxNotebookBase::SendPageChangedEvent(int nPageOld, int nPageNew) +{ + wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, GetId()); + event.SetSelection(nPageNew == -1 ? GetSelection() : nPageNew); + event.SetOldSelection(nPageOld); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); +} + #endif // wxUSE_NOTEBOOK diff --git a/src/gtk/notebook.cpp b/src/gtk/notebook.cpp index 27105979a5..74e3465b81 100644 --- a/src/gtk/notebook.cpp +++ b/src/gtk/notebook.cpp @@ -89,7 +89,7 @@ WX_DEFINE_LIST(wxGtkNotebookPagesList) extern "C" { static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), - GtkNotebookPage *WXUNUSED(page), + GtkNotebookPage *WXUNUSED(gpage), guint page, wxNotebook *notebook ) { @@ -118,12 +118,7 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), } else { - wxNotebookEvent eventChanging( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, - notebook->GetId(), page, old ); - eventChanging.SetEventObject( notebook ); - - if ( (notebook->GetEventHandler()->ProcessEvent(eventChanging)) && - !eventChanging.IsAllowed() ) + if ( !notebook->SendPageChangingEvent(page) ) { /* program doesn't allow the page change */ g_signal_stop_emission_by_name (notebook->m_widget, @@ -136,10 +131,7 @@ static void gtk_notebook_page_change_callback(GtkNotebook *WXUNUSED(widget), // not really changed in GTK+ notebook->m_selection = page; - wxNotebookEvent eventChanged( wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, - notebook->GetId(), page, old ); - eventChanged.SetEventObject( notebook ); - notebook->GetEventHandler()->ProcessEvent( eventChanged ); + notebook->SendPageChangedEvent(old); } } diff --git a/src/mac/carbon/notebmac.cpp b/src/mac/carbon/notebmac.cpp index 3406606bb8..6daf1bd791 100644 --- a/src/mac/carbon/notebmac.cpp +++ b/src/mac/carbon/notebmac.cpp @@ -168,19 +168,14 @@ int wxNotebook::DoSetSelection(size_t nPage, int flags) { if ( flags & SetSelection_SendEvent ) { - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); - event.SetSelection(nPage); - event.SetOldSelection(m_nSelection); - event.SetEventObject(this); - if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() ) + if ( !SendPageChangingEvent(nPage) ) { // vetoed by program return m_nSelection; } //else: program allows the page change - event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); - (void)GetEventHandler()->ProcessEvent(event); + SendPageChangedEvent(m_nSelection, nPage); } ChangePage(m_nSelection, nPage); diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 1efd29f383..7bab57b959 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -443,19 +443,14 @@ int wxNotebook::SetSelection(size_t nPage) { wxCHECK_MSG( IS_VALID_PAGE(nPage), wxNOT_FOUND, wxT("notebook page out of range") ); - if ( int(nPage) != m_nSelection ) + if ( m_nSelection == wxNOT_FOUND || nPage != (size_t)m_nSelection ) { - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); - event.SetSelection(nPage); - event.SetOldSelection(m_nSelection); - event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) || event.IsAllowed() ) + if ( SendPageChangingEvent(nPage) ) { // program allows the page change - event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); - (void)GetEventHandler()->ProcessEvent(event); + SendPageChangedEvent(m_nSelection, nPage); - TabCtrl_SetCurSel(GetHwnd(), nPage); + TabCtrl_SetCurSel(GetHwnd(), nPage); } } diff --git a/src/univ/notebook.cpp b/src/univ/notebook.cpp index 7ec0981b86..ebe2c8bb58 100644 --- a/src/univ/notebook.cpp +++ b/src/univ/notebook.cpp @@ -243,14 +243,9 @@ int wxNotebook::DoSetSelection(size_t nPage, int flags) return m_sel; } - wxNotebookEvent event(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGING, m_windowId); - if (flags & SetSelection_SendEvent) + if ( flags & SetSelection_SendEvent ) { - // event handling - event.SetSelection(nPage); - event.SetOldSelection(m_sel); - event.SetEventObject(this); - if ( GetEventHandler()->ProcessEvent(event) && !event.IsAllowed() ) + if ( !SendPageChangingEvent(nPage) ) { // program doesn't allow the page change return m_sel; @@ -300,11 +295,10 @@ int wxNotebook::DoSetSelection(size_t nPage, int flags) m_pages[m_sel]->Show(); } - if (flags & SetSelection_SendEvent) + if ( flags & SetSelection_SendEvent ) { // event handling - event.SetEventType(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED); - GetEventHandler()->ProcessEvent(event); + SendPageChangedEvent(selOld); } return selOld; -- 2.45.2