From 9f5864ab093a8e363d1eba0405c57f0e2596b83a Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Sun, 24 Jun 2012 10:46:17 -0400 Subject: [PATCH] Handle the scroll wheel changing over scrollbars. * Extract the scrollbar change based on the mouse wheel delta into a protected method of BView. * Call that method from BScrollBar's MessageReceived. With this change it is now a bit easier to scroll horizontally around the system by putting the mouse cursor over a horizontal scrollbar and using the wheel. Fixes #8631. --- headers/os/interface/View.h | 2 ++ src/kits/interface/ScrollBar.cpp | 16 ++++++++++++ src/kits/interface/View.cpp | 43 ++++++++++++++++---------------- 3 files changed, 40 insertions(+), 21 deletions(-) diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h index 8418f03e21..4471ddd1a6 100644 --- a/headers/os/interface/View.h +++ b/headers/os/interface/View.h @@ -584,6 +584,8 @@ protected: virtual void LayoutChanged(); + void ScrollWithMouseWheelDelta(BScrollBar*, float); + private: void _Layout(bool force, BLayoutContext* context); void _LayoutLeft(BLayout* deleted); diff --git a/src/kits/interface/ScrollBar.cpp b/src/kits/interface/ScrollBar.cpp index bf8fa2dc75..a12fdd3b9d 100644 --- a/src/kits/interface/ScrollBar.cpp +++ b/src/kits/interface/ScrollBar.cpp @@ -642,6 +642,22 @@ BScrollBar::MessageReceived(BMessage* message) ValueChanged(value); break; } + case B_MOUSE_WHEEL_CHANGED: + { + // Must handle this here since BView checks for the existence of + // scrollbars, which a scrollbar itself does not have + float deltaX = 0.0f, deltaY = 0.0f; + message->FindFloat("be:wheel_delta_x", &deltaX); + message->FindFloat("be:wheel_delta_y", &deltaY); + + if (deltaX == 0.0f && deltaY == 0.0f) + break; + + if (deltaX != 0.0f && deltaY == 0.0f) + deltaY = deltaX; + + ScrollWithMouseWheelDelta(this, deltaY); + } default: BView::MessageReceived(message); break; diff --git a/src/kits/interface/View.cpp b/src/kits/interface/View.cpp index 87fa465557..efbe9549a6 100644 --- a/src/kits/interface/View.cpp +++ b/src/kits/interface/View.cpp @@ -4350,31 +4350,12 @@ BView::MessageReceived(BMessage* msg) if (deltaX == 0.0f && deltaY == 0.0f) break; - float smallStep, largeStep; if (horizontal != NULL) { - horizontal->GetSteps(&smallStep, &largeStep); - - // pressing the option/command/control key scrolls faster - if (modifiers() - & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) { - deltaX *= largeStep; - } else - deltaX *= smallStep * 3; - - horizontal->SetValue(horizontal->Value() + deltaX); + ScrollWithMouseWheelDelta(horizontal, deltaX); } if (vertical != NULL) { - vertical->GetSteps(&smallStep, &largeStep); - - // pressing the option/command/control key scrolls faster - if (modifiers() - & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) { - deltaY *= largeStep; - } else - deltaY *= smallStep * 3; - - vertical->SetValue(vertical->Value() + deltaY); + ScrollWithMouseWheelDelta(vertical, deltaY); } break; } @@ -5721,6 +5702,26 @@ BView::_SwitchServerCurrentView() const } +void +BView::ScrollWithMouseWheelDelta(BScrollBar* scrollBar, float delta) +{ + if (scrollBar == NULL || delta == 0.0f) + return; + + float smallStep, largeStep; + scrollBar->GetSteps(&smallStep, &largeStep); + + // pressing the option/command/control key scrolls faster + if (modifiers() + & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY)) { + delta *= largeStep; + } else + delta *= smallStep * 3; + + scrollBar->SetValue(scrollBar->Value() + delta); +} + + #if __GNUC__ == 2