]> git.saurik.com Git - wxWidgets.git/commitdiff
added help event origin field: indicates if the help was requested using the mouse...
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 26 May 2006 02:21:38 +0000 (02:21 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 26 May 2006 02:21:38 +0000 (02:21 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39340 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/event.h
src/common/cshelp.cpp
src/common/event.cpp

index acdf448c41fc515e19f1e0aa917ee8567f17e496..6fce7406bd4eba43baa5898158953862a1e07783 100644 (file)
@@ -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)
index 82f3383652a62e70bbb41441248757007d6fe52c..f1433c3bed7d53f257da13537b61ea78239717e2 100644 (file)
@@ -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);
index f200ea664ca09754622933d66f94116fa1458f27..b270601e5e0b20d1e01d1b952a6bd2717b82d7e0 100644 (file)
@@ -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