Clean up of NSStepper and NSStepperCell.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23224 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2006-08-08 23:14:14 +00:00
parent 6bbbc9a062
commit dc4a427c47
6 changed files with 346 additions and 316 deletions

View file

@ -29,7 +29,6 @@
#include <Foundation/NSException.h>
#include "AppKit/NSStepper.h"
#include "AppKit/NSControl.h"
#include "AppKit/NSColor.h"
#include "AppKit/NSEvent.h"
#include "AppKit/NSWindow.h"
#include "AppKit/NSApplication.h"
@ -71,11 +70,6 @@ id _nsstepperCellClass = nil;
// Instance methods
//
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
{
return YES;
}
//
// Determining the first responder
//
@ -97,6 +91,8 @@ id _nsstepperCellClass = nil;
- (void) keyDown: (NSEvent*)theEvent
{
// FIXME
[super keyDown: theEvent];
}
- (double) maxValue
@ -129,8 +125,6 @@ id _nsstepperCellClass = nil;
[_cell setIncrement: increment];
}
- (BOOL)autorepeat
{
return [_cell autorepeat];
@ -151,199 +145,4 @@ id _nsstepperCellClass = nil;
[_cell setValueWraps: valueWraps];
}
- (void) mouseDown: (NSEvent *)event
{
NSPoint point = [event locationInWindow];
NSRect upRect;
NSRect downRect;
NSRect rect;
BOOL isDirectionUp;
BOOL autorepeat = [_cell autorepeat];
if ([_cell isEnabled] == NO)
return;
if ([event type] != NSLeftMouseDown)
return;
upRect = [_cell upButtonRectWithFrame: _bounds];
downRect = [_cell downButtonRectWithFrame: _bounds];
point = [self convertPoint: point fromView: nil];
if (NSMouseInRect(point, upRect, NO))
{
isDirectionUp = YES;
rect = upRect;
}
else if (NSMouseInRect(point, downRect, NO))
{
isDirectionUp = NO;
rect = downRect;
}
else
{
return;
}
[self lockFocus];
{
BOOL overButton = YES;
int ignore = 3;
unsigned int eventMask = NSLeftMouseUpMask
| NSLeftMouseDraggedMask
| NSPeriodicMask;
NSDate *farAway = [NSDate distantFuture];
[_window flushWindow];
[_cell highlight: YES
upButton: isDirectionUp
withFrame: _bounds
inView: self];
[_window _captureMouse: self];
if (autorepeat)
{
[NSEvent startPeriodicEventsAfterDelay: 0.5 withPeriod: 0.025];
if (isDirectionUp)
[self _increment];
else
[self _decrement];
[_cell drawWithFrame:_bounds
inView:self];
[_window flushWindow];
}
else
[_window flushWindow];
event = [NSApp nextEventMatchingMask: eventMask
untilDate: farAway
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
while ([event type] != NSLeftMouseUp)
{
if ([event type] == NSPeriodic)
{
ignore ++;
if (ignore == 4) ignore = 0;
if (ignore == 0)
{
if (isDirectionUp)
[self _increment];
else
[self _decrement];
[_cell drawWithFrame:_bounds
inView:self];
[_window flushWindow];
}
}
else if (NSMouseInRect(point, rect, NO) != overButton)
{
overButton = !overButton;
if (overButton && autorepeat)
{
[NSEvent startPeriodicEventsAfterDelay: 0.5
withPeriod: 0.025];
ignore = 3;
}
else
{
[NSEvent stopPeriodicEvents];
}
[_cell highlight: overButton
upButton: isDirectionUp
withFrame: _bounds
inView: self];
[_window flushWindow];
}
event = [NSApp nextEventMatchingMask: eventMask
untilDate: farAway
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
point = [self convertPoint: [event locationInWindow]
fromView: nil];
}
if (overButton && autorepeat)
[NSEvent stopPeriodicEvents];
if (overButton && !autorepeat)
{
if (isDirectionUp)
[self _increment];
else
[self _decrement];
[_cell drawWithFrame:_bounds
inView:self];
}
[_cell highlight: NO
upButton: isDirectionUp
withFrame: _bounds
inView: self];
[_window flushWindow];
[_window _releaseMouse: self];
}
[self unlockFocus];
}
- (void)_increment
{
double newValue;
double maxValue = [_cell maxValue];
double minValue = [_cell minValue];
double increment = [_cell increment];
newValue = [_cell doubleValue] + increment;
if ([_cell valueWraps])
{
if (newValue > maxValue)
[_cell setDoubleValue:
newValue - maxValue + minValue - 1];
else if (newValue < minValue)
[_cell setDoubleValue:
newValue + maxValue - minValue + 1];
else
[_cell setDoubleValue: newValue];
}
else
{
if (newValue > maxValue)
[_cell setDoubleValue: maxValue];
else if (newValue < minValue)
[_cell setDoubleValue: minValue];
else
[_cell setDoubleValue: newValue];
}
[self sendAction: [self action] to: [self target]];
}
- (void)_decrement
{
double newValue;
double maxValue = [_cell maxValue];
double minValue = [_cell minValue];
double increment = [_cell increment];
newValue = [_cell doubleValue] - increment;
if ([_cell valueWraps])
{
if (newValue > maxValue)
[_cell setDoubleValue:
newValue - maxValue + minValue - 1];
else if (newValue < minValue)
[_cell setDoubleValue:
newValue + maxValue - minValue + 1];
else
[_cell setDoubleValue: newValue];
}
else
{
if (newValue > maxValue)
[_cell setDoubleValue: maxValue];
else if (newValue < minValue)
[_cell setDoubleValue: minValue];
else
[_cell setDoubleValue: newValue];
}
[self sendAction: [self action] to: [self target]];
}
@end