From c7e94140cd436c6c234a382ad4e16ec5da65830c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 23 Apr 2011 16:19:15 +0000 Subject: [PATCH] Change wxNotebook selection before sending page changed event in wxMSW. wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED handler should see the new page selected in the control, not the old one as was the case if the page was changed using the mouse in wxMSW. This should have been done together with the other changes of r66224, see its commit message for more details. Closes 13145. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/notebook/notebook.cpp | 13 ++++++++----- src/msw/notebook.cpp | 4 +++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/samples/notebook/notebook.cpp b/samples/notebook/notebook.cpp index 7e1a3e0..3aceabb 100644 --- a/samples/notebook/notebook.cpp +++ b/samples/notebook/notebook.cpp @@ -972,6 +972,12 @@ void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent& event) nameControl, veto; const wxEventType eventType = event.GetEventType(); + + // NB: can't use wxStaticCast here as wxBookCtrlBase is not in + // wxRTTI + const wxBookCtrlBase * const + book = static_cast(event.GetEventObject()); + for ( size_t n = 0; n < WXSIZEOF(events); n++ ) { const EventInfo& ei = events[n]; @@ -983,10 +989,6 @@ void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent& event) { const int idx = event.GetOldSelection(); - // NB: can't use wxStaticCast here as wxBookCtrlBase is not in - // wxRTTI - const wxBookCtrlBase * const - book = static_cast(event.GetEventObject()); if ( idx != wxNOT_FOUND && book && book->GetPageText(idx) == VETO_PAGE_NAME ) { @@ -1017,13 +1019,14 @@ void MyFrame::OnBookCtrl(wxBookCtrlBaseEvent& event) static int s_num = 0; - wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d%s"), + wxLogMessage(wxT("Event #%d: %s: %s (%d) new sel %d, old %d, current %d%s"), ++s_num, nameControl.c_str(), nameEvent.c_str(), eventType, event.GetSelection(), event.GetOldSelection(), + book->GetSelection(), veto.c_str()); #if USE_LOG diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index db3df7f..1879bb2 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -1314,10 +1314,12 @@ bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) event.SetEventObject(this); event.SetInt(idCtrl); - bool processed = HandleWindowEvent(event); + // Change the selection before generating the event as its handler should + // already see the new page selected. if ( hdr->code == TCN_SELCHANGE ) UpdateSelection(event.GetSelection()); + bool processed = HandleWindowEvent(event); *result = !event.IsAllowed(); return processed; } -- 2.7.4