* Source/NSSlider.m (-keyDown:): Implement, Fixes bug #14000.

* Source/NSSliderCell.m (-trackMouse:...): Fix allows tick marks
        only mouse tracking.



git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@24031 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Matt Rice 2006-11-05 19:22:00 +00:00
parent ef92c9d9b9
commit 49923f47c7
3 changed files with 100 additions and 0 deletions

View file

@ -1,3 +1,9 @@
2006-11-05 Matt Rice <ratmice@yahoo.com>
* Source/NSSlider.m (-keyDown:): Implement, Fixes bug #14000.
* Source/NSSliderCell.m (-trackMouse:...): Fix allows tick marks
only mouse tracking.
2006-11-05 Matt Rice <ratmice@yahoo.com>
* Source/NSColorPanel.m: Implement -worksWhenModal:. Fixes bug #9417.

View file

@ -30,6 +30,7 @@
#include "AppKit/NSSlider.h"
#include "AppKit/NSSliderCell.h"
#include "AppKit/NSWindow.h"
#include "math.h"
/**
<unit>
@ -254,6 +255,94 @@ static Class cellClass;
return YES;
}
- (void) keyDown:(NSEvent *)ev
{
NSString *characters = [ev characters];
int i, length = [characters length];
double value = [self doubleValue];
double min = [_cell minValue];
double max = [_cell maxValue];
double altValue = [_cell altIncrementValue];
int alt_down = ([ev modifierFlags] & NSAlternateKeyMask);
BOOL only_ticks = [_cell allowsTickMarkValuesOnly];
BOOL valueChanged = NO;
double diff;
if (alt_down && altValue != -1)
{
diff = altValue;
}
else if (only_ticks)
{
if ([_cell numberOfTickMarks])
{
double tick0 = [_cell tickMarkValueAtIndex:0];
double tick1 = [_cell tickMarkValueAtIndex:1];
diff = tick1 - tick0;
}
else
{
diff = 0.0;
}
}
else
{
diff = fabs(min - max) / 20;
}
for (i = 0; i < length; i++)
{
switch([characters characterAtIndex:i])
{
case NSLeftArrowFunctionKey:
case NSDownArrowFunctionKey:
value -= diff;
valueChanged = YES;
break;
case NSUpArrowFunctionKey:
case NSRightArrowFunctionKey:
value += diff;
valueChanged = YES;
break;
case NSPageDownFunctionKey:
value -= diff * 2;
valueChanged = YES;
break;
case NSPageUpFunctionKey:
value += diff * 2;
valueChanged = YES;
break;
case NSHomeFunctionKey:
value = min;
valueChanged = YES;
break;
case NSEndFunctionKey:
value = max;
valueChanged = YES;
break;
}
}
if (valueChanged)
{
if (only_ticks)
value = [_cell closestTickMarkValueToValue:value];
if (value < min)
{
value = min;
}
else if (value > max)
{
value = max;
}
[self setDoubleValue:value];
[self sendAction:[self action] to:[self target]];
}
}
// ticks
- (BOOL) allowsTickMarkValuesOnly
{

View file

@ -700,6 +700,11 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
self, isFlipped);
if (floatValue != oldFloatValue)
{
if (_allowsTickMarkValuesOnly)
{
floatValue = [self closestTickMarkValueToValue:floatValue];
}
[self setFloatValue: floatValue];
if (isContinuous)
{