From 3c77d43e03ef8efee86971bfc67c41d0fa97493a Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Fri, 28 Jan 2011 23:37:11 +0100 Subject: [PATCH] implement mousewheel support for CPMenu --- AppKit/CPMenu/_CPMenuManager.j | 5 ++++- AppKit/CPMenu/_CPMenuWindow.j | 23 ++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/AppKit/CPMenu/_CPMenuManager.j b/AppKit/CPMenu/_CPMenuManager.j index 5d35d1674..fca561867 100644 --- a/AppKit/CPMenu/_CPMenuManager.j +++ b/AppKit/CPMenu/_CPMenuManager.j @@ -96,7 +96,7 @@ var STICKY_TIME_INTERVAL = 500, if (type === CPAppKitDefined) return [self completeTracking]; - [CPApp setTarget:self selector:@selector(trackEvent:) forNextEventMatchingMask:CPKeyDownMask | CPPeriodicMask | CPMouseMovedMask | CPLeftMouseDraggedMask | CPLeftMouseUpMask | CPAppKitDefinedMask untilDate:nil inMode:nil dequeue:YES]; + [CPApp setTarget:self selector:@selector(trackEvent:) forNextEventMatchingMask:CPKeyDownMask | CPPeriodicMask | CPMouseMovedMask | CPLeftMouseDraggedMask | CPLeftMouseUpMask | CPAppKitDefinedMask | CPScrollWheelMask untilDate:nil inMode:nil dequeue:YES]; if (type === CPKeyDown) { @@ -146,6 +146,9 @@ var STICKY_TIME_INTERVAL = 500, var mouseOverMenuView = [activeItem view]; + if (type === CPScrollWheel) + [activeMenuContainer scrollByDelta:[anEvent deltaY]]; + if (type === CPPeriodic) { if (_scrollingState === _CPMenuManagerScrollingStateUp) diff --git a/AppKit/CPMenu/_CPMenuWindow.j b/AppKit/CPMenu/_CPMenuWindow.j index 19c6144a5..cb52e9822 100644 --- a/AppKit/CPMenu/_CPMenuWindow.j +++ b/AppKit/CPMenu/_CPMenuWindow.j @@ -352,24 +352,29 @@ var STICKY_TIME_INTERVAL = 500, return [self canScrollUp] || [self canScrollDown]; } -- (void)scrollUp +- (void)scrollByDelta:(float)theDelta { - if (CGRectGetMinY(_unconstrainedFrame) >= CGRectGetMinY(_constraintRect)) + if (theDelta === 0.0) return; - _unconstrainedFrame.origin.y += 10; + if (theDelta > 0.0 && ![self canScrollDown]) + return; + if (theDelta < 0.0 && ![self canScrollUp]) + return; + + _unconstrainedFrame.origin.y -= theDelta; [self setFrame:_unconstrainedFrame]; } +- (void)scrollUp +{ + [self scrollByDelta:-10.0]; +} + - (void)scrollDown { - if (CGRectGetMaxY(_unconstrainedFrame) <= CGRectGetHeight(_constraintRect)) - return; - - _unconstrainedFrame.origin.y -= 10; - - [self setFrame:_unconstrainedFrame]; + [self scrollByDelta:10.0]; } @end