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
This commit is contained in:
Vadim Zeitlin
2006-05-26 02:21:38 +00:00
parent 851b88c310
commit b107e8d578
3 changed files with 42 additions and 4 deletions

View File

@@ -1983,17 +1983,28 @@ private:
class WXDLLIMPEXP_CORE wxHelpEvent : public wxCommandEvent class WXDLLIMPEXP_CORE wxHelpEvent : public wxCommandEvent
{ {
public: 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, wxHelpEvent(wxEventType type = wxEVT_NULL,
wxWindowID winid = 0, wxWindowID winid = 0,
const wxPoint& pt = wxDefaultPosition) const wxPoint& pt = wxDefaultPosition,
Origin origin = Origin_Unknown)
: wxCommandEvent(type, winid), : wxCommandEvent(type, winid),
m_pos(pt), m_target(), m_link() m_pos(pt),
m_origin(GuessOrigin(origin))
{ } { }
wxHelpEvent(const wxHelpEvent & event) wxHelpEvent(const wxHelpEvent & event)
: wxCommandEvent(event), : wxCommandEvent(event),
m_pos(event.m_pos), m_pos(event.m_pos),
m_target(event.m_target), 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) // Position of event (in screen coordinates)
@@ -2010,10 +2021,19 @@ public:
virtual wxEvent *Clone() const { return new wxHelpEvent(*this); } 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: protected:
wxPoint m_pos; wxPoint m_pos;
wxString m_target; wxString m_target;
wxString m_link; 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: private:
DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHelpEvent) DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHelpEvent)

View File

@@ -227,7 +227,8 @@ bool wxContextHelp::DispatchEvent(wxWindow* win, const wxPoint& pt)
bool eventProcessed = false; bool eventProcessed = false;
while (subjectOfHelp && !eventProcessed) while (subjectOfHelp && !eventProcessed)
{ {
wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), pt) ; wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), pt,
wxHelpEvent::Origin_HelpButton);
helpEvent.SetEventObject(subjectOfHelp); helpEvent.SetEventObject(subjectOfHelp);
eventProcessed = win->GetEventHandler()->ProcessEvent(helpEvent); eventProcessed = win->GetEventHandler()->ProcessEvent(helpEvent);

View File

@@ -768,6 +768,23 @@ wxChildFocusEvent::wxChildFocusEvent(wxWindow *win)
SetEventObject(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 #endif // wxUSE_GUI