From f05dfd55c334e38a9a02daa1ae388fb0067bbe57 Mon Sep 17 00:00:00 2001 From: fredkiefer Date: Fri, 16 Oct 2015 22:01:41 +0000 Subject: [PATCH] * Source/NSCell.m (-trackMouse:...untilMouseUp:): Check enabled and use isContinuous method. * Source/NSSliderCell.m: Replace specific implementation of -trackMouse:...untilMouseUp: with super class one and move specific code into helper methods. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@39077 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 +++ Source/NSCell.m | 17 +++-- Source/NSSliderCell.m | 161 ++++++++++++++++-------------------------- 3 files changed, 82 insertions(+), 104 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9fbfe4813..8bff5637e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2015-10-16 Fred Kiefer + + * Source/NSCell.m (-trackMouse:...untilMouseUp:): Check enabled + and use isContinuous method. + * Source/NSSliderCell.m: Replace specific implementation of + -trackMouse:...untilMouseUp: with super class one and move + specific code into helper methods. + 2015-10-15 Riccardo Mottola * Headers/AppKit/AppKit.h diff --git a/Source/NSCell.m b/Source/NSCell.m index d8ddbe4ea..f7a05f7fa 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -1643,8 +1643,15 @@ static NSColor *dtxtCol; NSStringFromRect(cellFrame), point.x, point.y); _mouse_down_flags = [theEvent modifierFlags]; + if (![self isEnabled]) + { + return NO; + } + if (![self startTrackingAt: point inView: controlView]) - return NO; + { + return NO; + } if (![controlView mouse: point inRect: cellFrame]) return NO; // point is not in cell @@ -1653,7 +1660,7 @@ static NSColor *dtxtCol; && [theEvent type] == NSLeftMouseDown) [self _sendActionFrom: controlView]; - if (_action_mask & NSPeriodicMask) + if ([self isContinuous]) { [self getPeriodicDelay: &delay interval: &interval]; [NSEvent startPeriodicEventsAfterDelay: delay withPeriod: interval]; @@ -1759,8 +1766,10 @@ static NSColor *dtxtCol; inView: controlView mouseIsUp: mouseWentUp]; - if (_action_mask & NSPeriodicMask) - [NSEvent stopPeriodicEvents]; + if ([self isContinuous]) + { + [NSEvent stopPeriodicEvents]; + } if (mouseWentUp) { diff --git a/Source/NSSliderCell.m b/Source/NSSliderCell.m index a20cc0251..e0afcc2f4 100644 --- a/Source/NSSliderCell.m +++ b/Source/NSSliderCell.m @@ -848,116 +848,77 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect, return 0.0; } -- (BOOL) trackMouse: (NSEvent*)theEvent - inRect: (NSRect)cellFrame - ofView: (NSView*)controlView - untilMouseUp: (BOOL)flag +- (BOOL) startTrackingAt: (NSPoint)startPoint inView: (NSView*)controlView { - float delay; - float interval; - id target = [self target]; - SEL action = [self action]; - NSUInteger eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask - | NSLeftMouseDraggedMask | NSMouseMovedMask; - NSEventType eventType = [theEvent type]; - BOOL isContinuous = [self isContinuous]; - float oldFloatValue = [self floatValue]; - NSRect slotRect = [self trackRect]; - BOOL isVertical = [self isVertical]; - double minValue = [self minValue]; - double maxValue = [self maxValue]; - BOOL isFlipped = [controlView isFlipped]; - NSPoint location = [theEvent locationInWindow]; - NSPoint point = [controlView convertPoint: location fromView: nil]; - NSRect knobRect = [self knobRectFlipped: isFlipped]; - - _mouse_down_flags = [theEvent modifierFlags]; - if (![self isEnabled]) + // If the point is in the view then yes start tracking + if ([controlView mouse: startPoint inRect: [controlView bounds]]) { - return NO; - } + BOOL isFlipped = [controlView isFlipped]; + NSRect knobRect = [self knobRectFlipped: isFlipped]; - if (![controlView mouse: point inRect: knobRect]) - { - // Mouse is not on the knob, move the knob to the mouse position - float floatValue; - - floatValue = _floatValueForMousePoint(point, knobRect, - slotRect, isVertical, - minValue, maxValue, - self, isFlipped, - (_type == NSCircularSlider)); - [self setFloatValue: floatValue]; - if (isContinuous) + if (![controlView mouse: startPoint inRect: knobRect]) { - [(NSControl*)controlView sendAction: action to: target]; - } - } - - if (isContinuous) - { - [self getPeriodicDelay: &delay interval: &interval]; - [NSEvent startPeriodicEventsAfterDelay: delay withPeriod: interval]; - eventMask |= NSPeriodicMask; - } + // Mouse is not on the knob, move the knob to the mouse position + float floatValue; + NSRect slotRect = [self trackRect]; + BOOL isVertical = [self isVertical]; + double minValue = [self minValue]; + double maxValue = [self maxValue]; + + floatValue = _floatValueForMousePoint(startPoint, knobRect, + slotRect, isVertical, + minValue, maxValue, + self, isFlipped, + (_type == NSCircularSlider)); + if (_allowsTickMarkValuesOnly) + { + floatValue = [self closestTickMarkValueToValue: floatValue]; + } + [self setFloatValue: floatValue]; + if ([self isContinuous]) + { + [(NSControl*)controlView sendAction: [self action] to: [self target]]; + } + } - while (eventType != NSLeftMouseUp) - { - theEvent = [NSApp nextEventMatchingMask: eventMask - untilDate: [NSDate distantFuture] - inMode: NSEventTrackingRunLoopMode - dequeue: YES]; - eventType = [theEvent type]; - - if (eventType == NSPeriodic) - { - NSWindow *w = [controlView window]; - - location = [w mouseLocationOutsideOfEventStream]; - } - else - { - location = [theEvent locationInWindow]; - } - point = [controlView convertPoint: location fromView: nil]; - - if (point.x != knobRect.origin.x || point.y != knobRect.origin.y) - { - float floatValue; - - floatValue = _floatValueForMousePoint(point, knobRect, - slotRect, isVertical, - minValue, maxValue, - self, isFlipped, - (_type == NSCircularSlider)); - if (floatValue != oldFloatValue) - { - if (_allowsTickMarkValuesOnly) - { - floatValue = [self closestTickMarkValueToValue:floatValue]; - } - - [self setFloatValue: floatValue]; - if (isContinuous) - { - [(NSControl*)controlView sendAction: action to: target]; - } - oldFloatValue = floatValue; - } - knobRect.origin = point; - } - } - - // If the cell is not continuous send the action at the end of the drag - if (!isContinuous) - { - [(NSControl*)controlView sendAction: action to: target]; + return YES; } else { - [NSEvent stopPeriodicEvents]; + return NO; } +} +- (BOOL) continueTracking: (NSPoint)lastPoint + at: (NSPoint)currentPoint + inView: (NSView*)controlView +{ + if (currentPoint.x != lastPoint.x || currentPoint.y != lastPoint.y) + { + float floatValue; + BOOL isFlipped = [controlView isFlipped]; + NSRect knobRect = [self knobRectFlipped: isFlipped]; + float oldFloatValue = [self floatValue]; + NSRect slotRect = [self trackRect]; + BOOL isVertical = [self isVertical]; + double minValue = [self minValue]; + double maxValue = [self maxValue]; + + floatValue = _floatValueForMousePoint(currentPoint, knobRect, + slotRect, isVertical, + minValue, maxValue, + self, isFlipped, + (_type == NSCircularSlider)); + if (_allowsTickMarkValuesOnly) + { + floatValue = [self closestTickMarkValueToValue: floatValue]; + } + if (floatValue != oldFloatValue) + { + [self setFloatValue: floatValue]; + // The action gets triggered in trackMouse:...untilMouseUp: + } + } return YES; }