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
\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}%
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}
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}}
\item {\bf wxEVT\_RIGHT\_UP}
\item {\bf wxEVT\_RIGHT\_DCLICK}
\item {\bf wxEVT\_MOTION}
+\item {\bf wxEVT\_MOUSEWHEEL}
\end{itemize}
\membersection{wxMouseEvent::AltDown}
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}
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.
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)
// 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:
bool m_shiftDown;
bool m_altDown;
bool m_metaDown;
+
+ int m_wheelRotation;
+ int m_wheelDelta;
+ int m_linesPerAction;
};
// Cursor set event
#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) \
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 ),
void OnSize(wxSizeEvent& event);
void OnPaint(wxPaintEvent& event);
void OnChar(wxKeyEvent& event);
+ void OnMouseWheel(wxMouseEvent& event);
// Calculate scroll increment
virtual int CalcScrollInc(wxScrollWinEvent& event);
int m_yScrollLinesPerPage;
double m_scaleX;
double m_scaleY;
+ int m_wheelRotation;
private:
DECLARE_EVENT_TABLE()
#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
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);
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)
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
EVT_SIZE(wxGenericScrolledWindow::OnSize)
EVT_PAINT(wxGenericScrolledWindow::OnPaint)
EVT_CHAR(wxGenericScrolledWindow::OnChar)
+ EVT_MOUSEWHEEL(wxGenericScrolledWindow::OnMouseWheel)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxGenericScrolledWindow, wxPanel)
m_yScrollLinesPerPage = 0;
m_scaleX = 1.0;
m_scaleY = 1.0;
+ m_wheelRotation = 0;
m_targetWindow = (wxWindow*) NULL;
}
m_yScrollLinesPerPage = 0;
m_scaleX = 1.0;
m_scaleY = 1.0;
+ m_wheelRotation = 0;
m_targetWindow = this;
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) ||
// 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 );
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);
+ }
+}
+
+
+
+
#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
// ---------------------------------------------------------------------------
wParam);
break;
+#if wxUSE_MOUSEWHEEL
+ case WM_MOUSEWHEEL:
+ processed = HandleMouseWheel(wParam, lParam);
+ break;
+#endif
+
case WM_LBUTTONDOWN:
// set focus to this window
if (AcceptsFocus())
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
// ---------------------------------------------------------------------------
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";