From: Vadim Zeitlin Date: Fri, 26 May 2006 02:21:38 +0000 (+0000) Subject: added help event origin field: indicates if the help was requested using the mouse... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b107e8d5786afd67550dde069513c80057424f91 added help event origin field: indicates if the help was requested using the mouse or from keyboard git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39340 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/event.h b/include/wx/event.h index acdf448c41..6fce7406bd 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -1983,17 +1983,28 @@ private: class WXDLLIMPEXP_CORE wxHelpEvent : public wxCommandEvent { public: + // how was this help event generated? + enum Origin + { + Origin_Unknown, // unrecognized event source + Origin_Keyboard, // event generated from F1 key press + Origin_HelpButton // event from [?] button on the title bar (Windows) + }; + wxHelpEvent(wxEventType type = wxEVT_NULL, wxWindowID winid = 0, - const wxPoint& pt = wxDefaultPosition) + const wxPoint& pt = wxDefaultPosition, + Origin origin = Origin_Unknown) : wxCommandEvent(type, winid), - m_pos(pt), m_target(), m_link() + m_pos(pt), + m_origin(GuessOrigin(origin)) { } wxHelpEvent(const wxHelpEvent & event) : wxCommandEvent(event), m_pos(event.m_pos), m_target(event.m_target), - m_link(event.m_link) + m_link(event.m_link), + m_origin(event.m_origin) { } // Position of event (in screen coordinates) @@ -2010,10 +2021,19 @@ public: virtual wxEvent *Clone() const { return new wxHelpEvent(*this); } + // optional indication of the event source + Origin GetOrigin() const { return m_origin; } + void SetOrigin(Origin origin) { m_origin = origin; } + protected: wxPoint m_pos; wxString m_target; wxString m_link; + Origin m_origin; + + // we can try to guess the event origin ourselves, even if none is + // specified in the ctor + static Origin GuessOrigin(Origin origin); private: DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHelpEvent) diff --git a/src/common/cshelp.cpp b/src/common/cshelp.cpp index 82f3383652..f1433c3bed 100644 --- a/src/common/cshelp.cpp +++ b/src/common/cshelp.cpp @@ -227,7 +227,8 @@ bool wxContextHelp::DispatchEvent(wxWindow* win, const wxPoint& pt) bool eventProcessed = false; while (subjectOfHelp && !eventProcessed) { - wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), pt) ; + wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), pt, + wxHelpEvent::Origin_HelpButton); helpEvent.SetEventObject(subjectOfHelp); eventProcessed = win->GetEventHandler()->ProcessEvent(helpEvent); diff --git a/src/common/event.cpp b/src/common/event.cpp index f200ea664c..b270601e5e 100644 --- a/src/common/event.cpp +++ b/src/common/event.cpp @@ -768,6 +768,23 @@ wxChildFocusEvent::wxChildFocusEvent(wxWindow *win) SetEventObject(win); } +// ---------------------------------------------------------------------------- +// wxHelpEvent +// ---------------------------------------------------------------------------- + +/* static */ +wxHelpEvent::Origin wxHelpEvent::GuessOrigin(Origin origin) +{ + if ( origin == Origin_Unknown ) + { + // assume that the event comes from the help button if it's not from + // keyboard and that pressing F1 always results in the help event + origin = wxGetKeyState(WXK_F1) ? Origin_Keyboard : Origin_HelpButton; + } + + return origin; +} + #endif // wxUSE_GUI