mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-29 22:17:39 +00:00
Moved tracking code from controll to cell class to allow the use in a
matrix. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23255 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
bad637ff8e
commit
ccc72cc74f
3 changed files with 173 additions and 156 deletions
|
@ -1,3 +1,11 @@
|
|||
2006-08-11 Fred Kiefer <FredKiefer@gmx.de>
|
||||
|
||||
* Source/NSSlider.m (mouseDown:, trackKnob:knobRect:,
|
||||
_floatValueForMousePoint()): Moved all track related code to cell class.
|
||||
* Source/NSSliderCell.m (_floatValueForMousePoint(),
|
||||
trackMouse:...untilMouseUp:): Code previously in the NSSlider class.
|
||||
Reworked slightly to be more similar to [NSCell trackMouse:...untilMouseUp:].
|
||||
|
||||
2006-08-11 01:50-EDT Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Source/GSNibCompatibility.m: Assign copies of the parameters to
|
||||
|
|
|
@ -30,62 +30,6 @@
|
|||
#include "AppKit/NSSlider.h"
|
||||
#include "AppKit/NSSliderCell.h"
|
||||
#include "AppKit/NSWindow.h"
|
||||
#include "AppKit/NSApplication.h"
|
||||
|
||||
static inline
|
||||
float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
||||
NSRect slotRect, BOOL isVertical,
|
||||
float minValue, float maxValue,
|
||||
NSSliderCell *theCell, BOOL flipped)
|
||||
{
|
||||
float floatValue = 0;
|
||||
float position;
|
||||
|
||||
// Adjust the point to lie inside the knob slot. We don't
|
||||
// have to worry whether the view is flipped or not.
|
||||
if (isVertical)
|
||||
{
|
||||
if (point.y < slotRect.origin.y + knobRect.size.height / 2)
|
||||
{
|
||||
position = slotRect.origin.y + knobRect.size.height / 2;
|
||||
}
|
||||
else if (point.y > slotRect.origin.y + slotRect.size.height
|
||||
- knobRect.size.height / 2)
|
||||
{
|
||||
position = slotRect.origin.y + slotRect.size.height
|
||||
- knobRect.size.height / 2;
|
||||
}
|
||||
else
|
||||
position = point.y;
|
||||
// Compute the float value
|
||||
floatValue = (position - (slotRect.origin.y + knobRect.size.height/2))
|
||||
/ (slotRect.size.height - knobRect.size.height);
|
||||
if (flipped)
|
||||
floatValue = 1 - floatValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (point.x < slotRect.origin.x + knobRect.size.width / 2)
|
||||
{
|
||||
position = slotRect.origin.x + knobRect.size.width / 2;
|
||||
}
|
||||
else if (point.x > slotRect.origin.x + slotRect.size.width
|
||||
- knobRect.size.width / 2)
|
||||
{
|
||||
position = slotRect.origin.x + slotRect.size.width
|
||||
- knobRect.size.width / 2;
|
||||
}
|
||||
else
|
||||
position = point.x;
|
||||
|
||||
// Compute the float value given the knob size
|
||||
floatValue = (position - (slotRect.origin.x + knobRect.size.width / 2))
|
||||
/ (slotRect.size.width - knobRect.size.width);
|
||||
}
|
||||
|
||||
return floatValue * (maxValue - minValue) + minValue;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
<unit>
|
||||
|
@ -361,102 +305,4 @@ static Class cellClass;
|
|||
return [_cell tickMarkValueAtIndex: index];
|
||||
}
|
||||
|
||||
|
||||
- (void) trackKnob: (NSEvent*)theEvent knobRect: (NSRect)knobRect
|
||||
{
|
||||
NSApplication *app = [NSApplication sharedApplication];
|
||||
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
|
||||
| NSLeftMouseDraggedMask | NSMouseMovedMask
|
||||
| NSPeriodicMask;
|
||||
NSPoint point = [self convertPoint: [theEvent locationInWindow]
|
||||
fromView: nil];
|
||||
NSEventType eventType = [theEvent type];
|
||||
BOOL isContinuous = [_cell isContinuous];
|
||||
float oldFloatValue = [_cell floatValue];
|
||||
id target = [_cell target];
|
||||
SEL action = [_cell action];
|
||||
NSDate *distantFuture = [NSDate distantFuture];
|
||||
NSRect slotRect = [_cell trackRect];
|
||||
BOOL isVertical = [_cell isVertical];
|
||||
float minValue = [_cell minValue];
|
||||
float maxValue = [_cell maxValue];
|
||||
|
||||
[NSEvent startPeriodicEventsAfterDelay: 0.05 withPeriod: 0.05];
|
||||
[[NSRunLoop currentRunLoop] limitDateForMode: NSEventTrackingRunLoopMode];
|
||||
|
||||
while (eventType != NSLeftMouseUp)
|
||||
{
|
||||
theEvent = [app nextEventMatchingMask: eventMask
|
||||
untilDate: distantFuture
|
||||
inMode: NSEventTrackingRunLoopMode
|
||||
dequeue: YES];
|
||||
eventType = [theEvent type];
|
||||
|
||||
if (eventType != NSPeriodic)
|
||||
{
|
||||
point = [self convertPoint: [theEvent locationInWindow]
|
||||
fromView: nil];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (point.x != knobRect.origin.x || point.y != knobRect.origin.y)
|
||||
{
|
||||
float floatValue;
|
||||
floatValue = _floatValueForMousePoint (point, knobRect,
|
||||
slotRect, isVertical,
|
||||
minValue, maxValue,
|
||||
_cell,
|
||||
_rFlags.flipped_view);
|
||||
if (floatValue != oldFloatValue)
|
||||
{
|
||||
[_cell setFloatValue: floatValue];
|
||||
if (isContinuous)
|
||||
{
|
||||
[self sendAction: action to: target];
|
||||
}
|
||||
oldFloatValue = floatValue;
|
||||
}
|
||||
knobRect.origin = point;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the control is not continuous send the action at the end of the drag
|
||||
if (!isContinuous)
|
||||
{
|
||||
[self sendAction: action to: target];
|
||||
}
|
||||
[NSEvent stopPeriodicEvents];
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent *)theEvent
|
||||
{
|
||||
if ([_cell isEnabled])
|
||||
{
|
||||
NSPoint location = [self convertPoint: [theEvent locationInWindow]
|
||||
fromView: nil];
|
||||
NSRect rect;
|
||||
|
||||
rect = [_cell knobRectFlipped: _rFlags.flipped_view];
|
||||
if (![self mouse: location inRect: rect])
|
||||
{
|
||||
// Mouse is not on the knob, move the knob to the mouse position
|
||||
float floatValue;
|
||||
floatValue = _floatValueForMousePoint (location, rect,
|
||||
[_cell trackRect],
|
||||
[_cell isVertical],
|
||||
[_cell minValue],
|
||||
[_cell maxValue], _cell,
|
||||
_rFlags.flipped_view);
|
||||
[_cell setFloatValue: floatValue];
|
||||
if ([_cell isContinuous])
|
||||
{
|
||||
[self sendAction: [_cell action] to: [_cell target]];
|
||||
}
|
||||
}
|
||||
|
||||
[self trackKnob: theEvent knobRect: rect];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -29,15 +29,72 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSException.h>
|
||||
|
||||
#include "AppKit/NSSliderCell.h"
|
||||
#include "AppKit/NSApplication.h"
|
||||
#include "AppKit/NSColor.h"
|
||||
#include "AppKit/NSGraphics.h"
|
||||
#include "AppKit/NSControl.h"
|
||||
#include "AppKit/NSEvent.h"
|
||||
#include "AppKit/NSGraphics.h"
|
||||
#include "AppKit/NSImage.h"
|
||||
#include "AppKit/NSSliderCell.h"
|
||||
#include "AppKit/NSTextFieldCell.h"
|
||||
#include "AppKit/NSWindow.h"
|
||||
|
||||
DEFINE_RINT_IF_MISSING
|
||||
|
||||
static inline
|
||||
float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
|
||||
NSRect slotRect, BOOL isVertical,
|
||||
float minValue, float maxValue,
|
||||
NSSliderCell *theCell, BOOL flipped)
|
||||
{
|
||||
float floatValue = 0;
|
||||
float position;
|
||||
|
||||
// Adjust the point to lie inside the knob slot. We don't
|
||||
// have to worry whether the view is flipped or not.
|
||||
if (isVertical)
|
||||
{
|
||||
if (point.y < slotRect.origin.y + knobRect.size.height / 2)
|
||||
{
|
||||
position = slotRect.origin.y + knobRect.size.height / 2;
|
||||
}
|
||||
else if (point.y > slotRect.origin.y + slotRect.size.height
|
||||
- knobRect.size.height / 2)
|
||||
{
|
||||
position = slotRect.origin.y + slotRect.size.height
|
||||
- knobRect.size.height / 2;
|
||||
}
|
||||
else
|
||||
position = point.y;
|
||||
// Compute the float value
|
||||
floatValue = (position - (slotRect.origin.y + knobRect.size.height/2))
|
||||
/ (slotRect.size.height - knobRect.size.height);
|
||||
if (flipped)
|
||||
floatValue = 1 - floatValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (point.x < slotRect.origin.x + knobRect.size.width / 2)
|
||||
{
|
||||
position = slotRect.origin.x + knobRect.size.width / 2;
|
||||
}
|
||||
else if (point.x > slotRect.origin.x + slotRect.size.width
|
||||
- knobRect.size.width / 2)
|
||||
{
|
||||
position = slotRect.origin.x + slotRect.size.width
|
||||
- knobRect.size.width / 2;
|
||||
}
|
||||
else
|
||||
position = point.x;
|
||||
|
||||
// Compute the float value given the knob size
|
||||
floatValue = (position - (slotRect.origin.x + knobRect.size.width / 2))
|
||||
/ (slotRect.size.width - knobRect.size.width);
|
||||
}
|
||||
|
||||
return floatValue * (maxValue - minValue) + minValue;
|
||||
}
|
||||
|
||||
/**
|
||||
<unit>
|
||||
<heading>Class Description</heading>
|
||||
|
@ -561,6 +618,112 @@ DEFINE_RINT_IF_MISSING
|
|||
return _minValue + index * (_maxValue - _minValue) / _numberOfTickMarks;
|
||||
}
|
||||
|
||||
- (BOOL) trackMouse: (NSEvent*)theEvent
|
||||
inRect: (NSRect)cellFrame
|
||||
ofView: (NSView*)controlView
|
||||
untilMouseUp: (BOOL)flag
|
||||
{
|
||||
float delay;
|
||||
float interval;
|
||||
id target = [self target];
|
||||
SEL action = [self action];
|
||||
unsigned int 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];
|
||||
float minValue = [self minValue];
|
||||
float 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])
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
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);
|
||||
[self setFloatValue: floatValue];
|
||||
if (isContinuous)
|
||||
{
|
||||
[(NSControl*)controlView sendAction: action to: target];
|
||||
}
|
||||
}
|
||||
|
||||
if (isContinuous)
|
||||
{
|
||||
[self getPeriodicDelay: &delay interval: &interval];
|
||||
[NSEvent startPeriodicEventsAfterDelay: delay withPeriod: interval];
|
||||
eventMask |= NSPeriodicMask;
|
||||
}
|
||||
|
||||
while (eventType != NSLeftMouseUp)
|
||||
{
|
||||
theEvent = [NSApp nextEventMatchingMask: eventMask
|
||||
untilDate: nil
|
||||
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);
|
||||
if (floatValue != oldFloatValue)
|
||||
{
|
||||
[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];
|
||||
}
|
||||
else
|
||||
{
|
||||
[NSEvent stopPeriodicEvents];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)decoder
|
||||
{
|
||||
self = [super initWithCoder: decoder];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue