X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/90f9b8ef0c83c09f80c2f60ad65407ba16f11a3c..6d7b547184bfdcdf67790755deb0122050b1d728:/src/common/bookctrl.cpp?ds=sidebyside diff --git a/src/common/bookctrl.cpp b/src/common/bookctrl.cpp index 2ee818f20c..c0b1eedd9c 100644 --- a/src/common/bookctrl.cpp +++ b/src/common/bookctrl.cpp @@ -162,32 +162,61 @@ wxSize wxBookCtrlBase::DoGetBestSize() const } #if wxUSE_HELP + void wxBookCtrlBase::OnHelp(wxHelpEvent& event) { - // find the corresponding page - wxWindow *page = NULL; + // determine where does this even originate from to avoid redirecting it + // back to the page which generated it (resulting in an infinite loop) + + // notice that we have to check in the hard(er) way instead of just testing + // if the event object == this because the book control can have other + // subcontrols inside it (e.g. wxSpinButton in case of a notebook in wxUniv) + wxWindow *source = wxStaticCast(event.GetEventObject(), wxWindow); + while ( source && source != this && source->GetParent() != this ) + { + source = source->GetParent(); + } - if ( event.GetOrigin() == wxHelpEvent::Origin_HelpButton ) + if ( source && m_pages.Index(source) == wxNOT_FOUND ) { - // show help for the page under the mouse - const int pagePos = HitTest(ScreenToClient(event.GetPosition())); + // this event is for the book control itself, redirect it to the + // corresponding page + wxWindow *page = NULL; - if ( pagePos != wxNOT_FOUND) + if ( event.GetOrigin() == wxHelpEvent::Origin_HelpButton ) { - page = GetPage((size_t)pagePos); + // show help for the page under the mouse + const int pagePos = HitTest(ScreenToClient(event.GetPosition())); + + if ( pagePos != wxNOT_FOUND) + { + page = GetPage((size_t)pagePos); + } + } + else // event from keyboard or unknown source + { + // otherwise show the current page help + page = GetCurrentPage(); } - } - if ( !page ) - { - page = GetCurrentPage(); + if ( page ) + { + // change event object to the page to avoid infinite recursion if + // we get this event ourselves if the page doesn't handle it + event.SetEventObject(page); + + if ( page->GetEventHandler()->ProcessEvent(event) ) + { + // don't call event.Skip() + return; + } + } } + //else: event coming from one of our pages already - if ( !page || !page->GetEventHandler()->ProcessEvent(event) ) - { - event.Skip(); - } + event.Skip(); } + #endif // wxUSE_HELP // ----------------------------------------------------------------------------