From 3f19e2147891cdb643cd6ae57e4c9e12f1f3a22c Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Wed, 16 Apr 2014 09:15:31 +0400 Subject: [PATCH] support mouse wheel in lists --- src/dlangui/platforms/windows/winapp.d | 2 +- src/dlangui/widgets/controls.d | 15 +++++++++++++++ src/dlangui/widgets/lists.d | 4 ++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/dlangui/platforms/windows/winapp.d b/src/dlangui/platforms/windows/winapp.d index cac1548d..903a916c 100644 --- a/src/dlangui/platforms/windows/winapp.d +++ b/src/dlangui/platforms/windows/winapp.d @@ -737,7 +737,7 @@ LRESULT WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) case WM_RBUTTONUP: case WM_MOUSEWHEEL: if (window !is null) { - if (window.onMouse(message, cast(ushort)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF))) + if (window.onMouse(message, cast(uint)wParam, cast(short)(lParam & 0xFFFF), cast(short)((lParam >> 16) & 0xFFFF))) return 0; // processed } // not processed - default handling diff --git a/src/dlangui/widgets/controls.d b/src/dlangui/widgets/controls.d index 3c1eae9e..67cfea97 100644 --- a/src/dlangui/widgets/controls.d +++ b/src/dlangui/widgets/controls.d @@ -584,6 +584,21 @@ class ScrollBar : AbstractSlider, OnClickHandler { return true; } + /// handle mouse wheel events + override bool onMouseEvent(MouseEvent event) { + if (visibility != Visibility.Visible) + return false; + if (event.action == MouseAction.Wheel) { + int delta = event.wheelDelta; + if (delta > 0) + sendScrollEvent(ScrollAction.LineUp, position); + else if (delta < 0) + sendScrollEvent(ScrollAction.LineDown, position); + return true; + } + return super.onMouseEvent(event); + } + /// Draw widget at its position to buffer override void onDraw(DrawBuf buf) { if (visibility != Visibility.Visible) diff --git a/src/dlangui/widgets/lists.d b/src/dlangui/widgets/lists.d index 1b1891b6..5c659932 100644 --- a/src/dlangui/widgets/lists.d +++ b/src/dlangui/widgets/lists.d @@ -519,6 +519,10 @@ class ListWidget : WidgetGroup, OnScrollHandler { setHoverItem(-1); return true; } + // delegate processing of mouse wheel to scrollbar widget + if (event.action == MouseAction.Wheel && _needScrollbar) { + return _scrollbar.onMouseEvent(event); + } // support onClick Rect rc = _pos; applyMargins(rc);