]> git.saurik.com Git - wxWidgets.git/commitdiff
Added mouse wheel support for MSW. It generates a wxMouseEvent with a
authorRobin Dunn <robin@alldunn.com>
Fri, 4 May 2001 07:26:30 +0000 (07:26 +0000)
committerRobin Dunn <robin@alldunn.com>
Fri, 4 May 2001 07:26:30 +0000 (07:26 +0000)
type of wxEVT_MOUSEWHEEL.

wxMouseEvent has new members and accessors to transport mouse wheel
rotation data.  New members and accessors are documented.

wxGenericScrolledWindow modified to turn mouse wheel events into
scroll actions.

Added wxUSE_MOUSEWHEEL to setup0.h to allow disabling the platform
specific parts.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9990 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/mouseevt.tex
include/wx/event.h
include/wx/generic/scrolwin.h
include/wx/msw/setup0.h
include/wx/msw/window.h
src/common/event.cpp
src/generic/scrolwin.cpp
src/msw/window.cpp

index 423811a297d65b1094248c72d7ca3bb8cc331f65..eff02f8b6d0907b66b62f0ffe0ae6abc2f8acf9c 100644 (file)
@@ -9,15 +9,15 @@ drawbacks: the LEAVE\_WINDOW event might be received some time after the mouse
 left the window and the state variables for it may have changed during this
 time.
 
-{\bf NB: } Note the difference between methods like 
-\helpref{LeftDown}{wxmouseeventleftdown} and 
+{\bf NB: } Note the difference between methods like
+\helpref{LeftDown}{wxmouseeventleftdown} and
 \helpref{LeftIsDown}{wxmouseeventleftisdown}: the formet returns {\tt TRUE}
 when the event corresponds to the left mouse button click while the latter
 returns {\tt TRUE} if the left mouse button is currently being pressed. For
-example, when the user is dragging the mouse you can use 
+example, when the user is dragging the mouse you can use
 \helpref{LeftIsDown}{wxmouseeventleftisdown} to test
 whether the left mouse button is (still) depressed. Also, by convention, if
-\helpref{LeftDown}{wxmouseeventleftdown} returns {\tt TRUE}, 
+\helpref{LeftDown}{wxmouseeventleftdown} returns {\tt TRUE},
 \helpref{LeftIsDown}{wxmouseeventleftisdown} will also return {\tt TRUE} in
 wxWindows whatever the underlying GUI behaviour is (which is
 platform-dependent). The same applies, of course, to other mouse buttons as
@@ -50,6 +50,7 @@ functions that take a wxMouseEvent argument.
 \twocolitem{{\bf EVT\_MOTION(func)}}{Process a wxEVT\_MOTION event.}
 \twocolitem{{\bf EVT\_ENTER\_WINDOW(func)}}{Process a wxEVT\_ENTER\_WINDOW event.}
 \twocolitem{{\bf EVT\_LEAVE\_WINDOW(func)}}{Process a wxEVT\_LEAVE\_WINDOW event.}
+\twocolitem{{\bf EVT\_MOUSEWHEEL(func)}}{Process a wxEVT\_MOUSEWHEEL event.}
 \twocolitem{{\bf EVT\_MOUSE\_EVENTS(func)}}{Process all mouse events.}
 \end{twocollist}%
 
@@ -85,12 +86,6 @@ TRUE if the middle mouse button is currently pressed down.
 
 TRUE if the right mouse button is currently pressed down.
 
-\membersection{wxMouseEvent::m\_leftDown}
-
-\member{bool}{m\_leftDown}
-
-TRUE if the left mouse button is currently pressed down.
-
 \membersection{wxMouseEvent::m\_metaDown}
 
 \member{bool}{m\_metaDown}
@@ -115,6 +110,26 @@ X-coordinate of the event.
 
 Y-coordinate of the event.
 
+\membersection{wxMouseEvent::m\_wheelRotation}
+
+\member{int}{m\_wheelRotation}
+
+The distance the mouse wheel is rotated.
+
+\membersection{wxMouseEvent::m\_wheelDelta}
+
+\member{int}{m\_wheelDelta}
+
+The wheel delta, normally 120.
+
+\membersection{wxMouseEvent::m\_linesPerAction}
+
+\member{int}{m\_linesPerAction}
+
+The configured number of lines (or whatever) to be scrolled per wheel
+action.
+
+
 \membersection{wxMouseEvent::wxMouseEvent}
 
 \func{}{wxMouseEvent}{\param{WXTYPE}{ mouseEventType = 0}, \param{int}{ id = 0}}
@@ -135,6 +150,7 @@ Constructor. Valid event types are:
 \item {\bf wxEVT\_RIGHT\_UP}
 \item {\bf wxEVT\_RIGHT\_DCLICK}
 \item {\bf wxEVT\_MOTION}
+\item {\bf wxEVT\_MOUSEWHEEL}
 \end{itemize}
 
 \membersection{wxMouseEvent::AltDown}
@@ -217,6 +233,34 @@ Returns the physical mouse position in pixels.
 Returns the logical mouse position in pixels (i.e. translated according to the
 translation set for the DC, which usually indicates that the window has been scrolled).
 
+
+\membersection{wxMouseEvent::GetLinesPerAction}\label{wxmouseeventgetlinesperaction}
+
+\constfunc{int}{GetLinesPerAction}{\void}
+
+Returns the configured number of lines (or whatever) to be scrolled per
+wheel action.  Defaults to one.
+
+\membersection{wxMouseEvent::GetWheelRotation}\label{wxmouseeventgetwheelrotation}
+
+\constfunc{int}{GetWheelRotation}{\void}
+
+Get wheel rotation, positive or negative indicates direction of
+rotation.  Current devices all send an event when rotation is equal to
++/-WheelDelta, but this allows for finer resolution devices to be
+created in the future.  Because of this you shouldn't assume that one
+event is equal to 1 line or whatever, but you should be able to either
+do partial line scrolling or wait until +/-WheelDelta rotation values
+have been accumulated before scrolling.
+
+\membersection{wxMouseEvent::GetWheelDelta}\label{wxmouseeventgetwheeldelta}
+
+\constfunc{int}{GetWheelDelta}{\void}
+
+Get wheel delta, normally 120.  This is the threshold for action to be
+taken, and one such action (for example, scrolling one increment)
+should occur for each delta.
+
 \membersection{wxMouseEvent::GetX}\label{wxmouseeventgetx}
 
 \constfunc{long}{GetX}{\void}
@@ -263,7 +307,7 @@ Returns TRUE if the left mouse button changed to down.
 Returns TRUE if the left mouse button is currently down, independent
 of the current event type.
 
-Please notice that it is {\bf not} the same as 
+Please notice that it is {\bf not} the same as
 \helpref{LeftDown}{wxmouseeventleftdown} which returns TRUE if the left mouse
 button was just pressed. Rather, it describes the state of the mouse button
 before the event happened.
index ca452cf8499dc34dae58cd473dd7a4df56e20be9..f7bddba9b73a45d2168bfef1204a09c80e3455b8 100644 (file)
@@ -151,6 +151,7 @@ BEGIN_DECLARE_EVENT_TYPES()
     DECLARE_EVENT_TYPE(wxEVT_RIGHT_DCLICK, 111)
     DECLARE_EVENT_TYPE(wxEVT_SET_FOCUS, 112)
     DECLARE_EVENT_TYPE(wxEVT_KILL_FOCUS, 113)
+    DECLARE_EVENT_TYPE(wxEVT_MOUSEWHEEL, 114)
 
         // Non-client mouse events
     DECLARE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN, 200)
@@ -669,6 +670,25 @@ public:
     // Get Y position
     wxCoord GetY() const { return m_y; }
 
+    // Get wheel rotation, positive or negative indicates direction of
+    // rotation.  Current devices all send an event when rotation is equal to
+    // +/-WheelDelta, but this allows for finer resolution devices to be
+    // created in the future.  Because of this you shouldn't assume that one
+    // event is equal to 1 line or whatever, but you should be able to either
+    // do partial line scrolling or wait until +/-WheelDelta rotation values
+    // have been accumulated before scrolling.
+    int GetWheelRotation() const { return m_wheelRotation; }
+
+    // Get wheel delta, normally 120.  This is the threshold for action to be
+    // taken, and one such action (for example, scrolling one increment)
+    // should occur for each delta.
+    int GetWheelDelta() const { return m_wheelDelta; }
+
+    // Returns the configured number of lines (or whatever) to be scrolled per
+    // wheel action.  Defaults to one.
+    int GetLinesPerAction() const { return m_linesPerAction; }
+
+
     void CopyObject(wxObject& obj) const;
 
 public:
@@ -682,6 +702,10 @@ public:
     bool          m_shiftDown;
     bool          m_altDown;
     bool          m_metaDown;
+
+    int           m_wheelRotation;
+    int           m_wheelDelta;
+    int           m_linesPerAction;
 };
 
 // Cursor set event
@@ -1756,6 +1780,7 @@ typedef void (wxEvtHandler::*wxHelpEventFunction)(wxHelpEvent&);
 #define EVT_RIGHT_DCLICK(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),
 #define EVT_LEAVE_WINDOW(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_LEAVE_WINDOW, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),
 #define EVT_ENTER_WINDOW(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_ENTER_WINDOW, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),
+#define EVT_MOUSEWHEEL(func) DECLARE_EVENT_TABLE_ENTRY( wxEVT_MOUSEWHEEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),
 
 // All mouse events
 #define EVT_MOUSE_EVENTS(func) \
@@ -1770,7 +1795,8 @@ typedef void (wxEvtHandler::*wxHelpEventFunction)(wxHelpEvent&);
  DECLARE_EVENT_TABLE_ENTRY( wxEVT_MIDDLE_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),\
  DECLARE_EVENT_TABLE_ENTRY( wxEVT_RIGHT_DCLICK, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),\
  DECLARE_EVENT_TABLE_ENTRY( wxEVT_ENTER_WINDOW, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),\
- DECLARE_EVENT_TABLE_ENTRY( wxEVT_LEAVE_WINDOW, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),
+ DECLARE_EVENT_TABLE_ENTRY( wxEVT_LEAVE_WINDOW, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),\
+ DECLARE_EVENT_TABLE_ENTRY( wxEVT_MOUSEWHEEL, -1, -1, (wxObjectEventFunction) (wxEventFunction) (wxMouseEventFunction) & func, (wxObject *) NULL ),
 
 // EVT_COMMAND
 #define EVT_COMMAND(id, event, fn)  DECLARE_EVENT_TABLE_ENTRY( event, id, -1, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) & fn, (wxObject *) NULL ),
index 1c9d92168ba88aee88fa1955ed4c6d1f3deabbfb..0af1fc66c4e1e472d5a02b77a73b2f51e464964a 100644 (file)
@@ -126,6 +126,7 @@ public:
     void OnSize(wxSizeEvent& event);
     void OnPaint(wxPaintEvent& event);
     void OnChar(wxKeyEvent& event);
+    void OnMouseWheel(wxMouseEvent& event);
 
     // Calculate scroll increment
     virtual int CalcScrollInc(wxScrollWinEvent& event);
@@ -144,6 +145,7 @@ protected:
     int                   m_yScrollLinesPerPage;
     double                m_scaleX;
     double                m_scaleY;
+    int                   m_wheelRotation;
 
 private:
     DECLARE_EVENT_TABLE()
index b88647d7e054cb423d28c999004b8a64b45ca9fb..6e1c1de4b6cc599a7a4833841171baeab0dc3f30 100644 (file)
 #define wxUSE_WX_RESOURCES        1
                                 // Use .wxr resource mechanism (requires PrologIO library)
 
+#define wxUSE_MOUSEWHEEL        1
+                                // Include mouse wheel support
+
 // ----------------------------------------------------------------------------
 // postscript support settings
 // ----------------------------------------------------------------------------
 
 // For backward compatibility reasons, this parameter now only controls the
 // default scrolling method used by cursors.  This default behavior can be
-// overriden by setting the second param of wxDB::wxDbGetConnection() or 
+// overriden by setting the second param of wxDB::wxDbGetConnection() or
 // wxDb() constructor to indicate whether the connection (and any wxDbTable()s
-// that use the connection) should support forward only scrolling of cursors, 
-// or both forward and backward support for backward scrolling cursors is 
+// that use the connection) should support forward only scrolling of cursors,
+// or both forward and backward support for backward scrolling cursors is
 // dependent on the data source as well as the ODBC driver being used.
 #define wxODBC_FWD_ONLY_CURSORS         1
 
index a19f12da285f4b78ab09db0b9ef6d5974a203a1b..538051007b20a28a3473fb86c181ad7909071e69 100644 (file)
@@ -327,6 +327,7 @@ public:
 
     bool HandleMouseEvent(WXUINT msg, int x, int y, WXUINT flags);
     bool HandleMouseMove(int x, int y, WXUINT flags);
+    bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
 
     bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = FALSE);
     bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
index 0939c4dcc259d0bccdd935781dcc549a4e63994c..301ae910822019a37c3ab10f1224a5685187139b 100644 (file)
@@ -150,6 +150,7 @@ DEFINE_EVENT_TYPE(wxEVT_MIDDLE_DCLICK)
 DEFINE_EVENT_TYPE(wxEVT_RIGHT_DCLICK)
 DEFINE_EVENT_TYPE(wxEVT_SET_FOCUS)
 DEFINE_EVENT_TYPE(wxEVT_KILL_FOCUS)
+DEFINE_EVENT_TYPE(wxEVT_MOUSEWHEEL)
 
 // Non-client mouse events
 DEFINE_EVENT_TYPE(wxEVT_NC_LEFT_DOWN)
@@ -414,6 +415,9 @@ wxMouseEvent::wxMouseEvent(wxEventType commandType)
     m_middleDown = FALSE;
     m_x = 0;
     m_y = 0;
+    m_wheelRotation = 0;
+    m_wheelDelta = 0;
+    m_linesPerAction = 0;
 }
 
 void wxMouseEvent::CopyObject(wxObject& obj_d) const
index d28dc6fb3b18e19fc886e83de5a770c556e53bd8..7cd7722062a273c044c7f7da2df08bd1801b7eb2 100644 (file)
@@ -68,6 +68,7 @@ BEGIN_EVENT_TABLE(wxGenericScrolledWindow, wxPanel)
     EVT_SIZE(wxGenericScrolledWindow::OnSize)
     EVT_PAINT(wxGenericScrolledWindow::OnPaint)
     EVT_CHAR(wxGenericScrolledWindow::OnChar)
+    EVT_MOUSEWHEEL(wxGenericScrolledWindow::OnMouseWheel)
 END_EVENT_TABLE()
 
 IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel)
@@ -94,6 +95,7 @@ wxGenericScrolledWindow::wxGenericScrolledWindow()
     m_yScrollLinesPerPage = 0;
     m_scaleX = 1.0;
     m_scaleY = 1.0;
+    m_wheelRotation = 0;
     m_targetWindow = (wxWindow*) NULL;
 }
 
@@ -116,6 +118,7 @@ bool wxGenericScrolledWindow::Create(wxWindow *parent,
     m_yScrollLinesPerPage = 0;
     m_scaleX = 1.0;
     m_scaleY = 1.0;
+    m_wheelRotation = 0;
 
     m_targetWindow = this;
 
@@ -151,7 +154,7 @@ void wxGenericScrolledWindow::SetScrollbars (int pixelsPerUnitX, int pixelsPerUn
     bool do_refresh =
     (
       (noUnitsX != 0 && m_xScrollLines == 0) ||
-      (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX*noUnitsX) || 
+      (noUnitsX < m_xScrollLines && xpos > pixelsPerUnitX*noUnitsX) ||
 
       (noUnitsY != 0 && m_yScrollLines == 0) ||
       (noUnitsY < m_yScrollLines && ypos > pixelsPerUnitY*noUnitsY) ||
@@ -548,7 +551,7 @@ void wxGenericScrolledWindow::Scroll( int x_pos, int y_pos )
         // the visible portion of it or if below zero
         m_yScrollPosition = wxMin( m_yScrollLines-noPagePositions, m_yScrollPosition );
         m_yScrollPosition = wxMax( 0, m_yScrollPosition );
-        
+
         if (old_y != m_yScrollPosition) {
             m_targetWindow->SetScrollPos( wxVERTICAL, m_yScrollPosition, TRUE );
             m_targetWindow->ScrollWindow( 0, (old_y-m_yScrollPosition)*m_yScrollPixelsPerLine );
@@ -702,3 +705,24 @@ void wxGenericScrolledWindow::OnChar(wxKeyEvent& event)
             event.Skip();
     }
 }
+
+
+void wxGenericScrolledWindow::OnMouseWheel(wxMouseEvent& event)
+{
+    int lines;
+    int vsx, vsy;
+
+    m_wheelRotation += event.GetWheelRotation();
+    lines = m_wheelRotation / event.GetWheelDelta();
+    m_wheelRotation -= lines * event.GetWheelDelta();
+
+    if (lines != 0) {
+        lines *= event.GetLinesPerAction();
+        GetViewStart(&vsx, &vsy);
+        Scroll(-1, vsy - lines);
+    }
+}
+
+
+
+
index 3864f654d423865f9a86d24e43310c62bee0ed03..dadffe9b6af176b29eec0ba93893a43c73e567de 100644 (file)
 #define SIF_TRACKPOS 16
 #endif
 
+#if wxUSE_MOUSEWHEEL
+    #ifndef WM_MOUSEWHEEL
+        #define WM_MOUSEWHEEL           0x020A
+        #define WHEEL_DELTA             120
+        #define SPI_GETWHEELSCROLLLINES 104
+    #endif
+#endif
+
+
 // ---------------------------------------------------------------------------
 // global variables
 // ---------------------------------------------------------------------------
@@ -1910,6 +1919,12 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam)
                                         wParam);
             break;
 
+#if wxUSE_MOUSEWHEEL
+        case WM_MOUSEWHEEL:
+            processed = HandleMouseWheel(wParam, lParam);
+            break;
+#endif
+
         case WM_LBUTTONDOWN:
            // set focus to this window
            if (AcceptsFocus())
@@ -3347,6 +3362,31 @@ bool wxWindow::HandleMouseMove(int x, int y, WXUINT flags)
     return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
 }
 
+
+bool wxWindow::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
+{
+#if wxUSE_MOUSEWHEEL
+    wxMouseEvent event(wxEVT_MOUSEWHEEL);
+    InitMouseEvent(event,
+                   GET_X_LPARAM(lParam),
+                   GET_Y_LPARAM(lParam),
+                   LOWORD(wParam));
+
+    event.m_wheelRotation = (short)HIWORD(wParam);
+    event.m_wheelDelta = WHEEL_DELTA;
+
+    int linesPer;
+    if (!SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, &linesPer, 0))
+        linesPer = 1;
+    event.m_linesPerAction = linesPer;
+
+    return GetEventHandler()->ProcessEvent(event);
+#else
+    return FALSE;
+#endif
+}
+
+
 // ---------------------------------------------------------------------------
 // keyboard handling
 // ---------------------------------------------------------------------------
@@ -4098,6 +4138,7 @@ const char *wxGetMessageName(int message)
         case 0x0207: return "WM_MBUTTONDOWN";
         case 0x0208: return "WM_MBUTTONUP";
         case 0x0209: return "WM_MBUTTONDBLCLK";
+        case 0x020A: return "WM_MOUSEWHEEL";
         case 0x0210: return "WM_PARENTNOTIFY";
         case 0x0211: return "WM_ENTERMENULOOP";
         case 0x0212: return "WM_EXITMENULOOP";