darling-cocotron/AppKit/NSStepper.m

127 lines
3.2 KiB
Mathematica
Raw Normal View History

/* Copyright (c) 2006-2007 Christopher J. W. Lloyd
2006-12-22 04:41:44 +00:00
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
#import <AppKit/NSImage.h>
2006-12-22 04:41:44 +00:00
#import <AppKit/NSStepper.h>
#import <AppKit/NSStepperCell.h>
#import <AppKit/NSWindow.h>
@interface NSStepperCell (NSStepperCell_private)
- (NSImage *) _stepUpImage;
- (NSImage *) _stepDownImage;
2006-12-22 04:41:44 +00:00
@end
@implementation NSStepper
+ (Class) cellClass {
2006-12-22 04:41:44 +00:00
return [NSStepperCell class];
}
- (double) minValue {
2006-12-22 04:41:44 +00:00
return [_cell minValue];
}
- (double) increment {
2006-12-22 04:41:44 +00:00
return [_cell increment];
}
- (double) maxValue {
2006-12-22 04:41:44 +00:00
return [_cell maxValue];
}
- (BOOL) autorepeat {
2006-12-22 04:41:44 +00:00
return [_cell autorepeat];
}
- (BOOL) valueWraps {
2006-12-22 04:41:44 +00:00
return [_cell valueWraps];
}
- (void) setMinValue: (double) value {
[_cell setMinValue: value];
2006-12-22 04:41:44 +00:00
}
- (void) setIncrement: (double) value {
[_cell setIncrement: value];
2006-12-22 04:41:44 +00:00
}
- (void) setMaxValue: (double) value {
[_cell setMaxValue: value];
2006-12-22 04:41:44 +00:00
}
- (void) setAutorepeat: (BOOL) flag {
[_cell setAutorepeat: flag];
2006-12-22 04:41:44 +00:00
}
- (void) setValueWraps: (BOOL) flag {
[_cell setValueWraps: flag];
2006-12-22 04:41:44 +00:00
}
- (void) sizeToFit {
NSSize size = _bounds.size;
NSSize size1 = [[_cell _stepUpImage] size];
NSSize size2 = [[_cell _stepDownImage] size];
2006-12-22 04:41:44 +00:00
size.width = MAX(size1.width, size2.width);
size.width += 12;
size.height = size1.height + size.height;
size.height += 4;
[self setBoundsSize: size];
2006-12-22 04:41:44 +00:00
}
- (void) mouseDown: (NSEvent *) event {
BOOL sendAction = NO;
2006-12-22 04:41:44 +00:00
if (![self isEnabled])
return;
[self lockFocus];
sendAction = [_cell trackMouse: event
inRect: [self bounds]
ofView: self
untilMouseUp: YES];
2006-12-22 04:41:44 +00:00
[self unlockFocus];
if (sendAction == YES)
[self sendAction: [self action] to: [self target]];
2006-12-22 04:41:44 +00:00
[self setNeedsDisplay: YES];
2006-12-22 04:41:44 +00:00
}
- (void) keyDown: (NSEvent *) event {
[self interpretKeyEvents: [NSArray arrayWithObject: event]];
2006-12-22 04:41:44 +00:00
}
- (void) moveUp: (id) sender {
2006-12-22 04:41:44 +00:00
[self lockFocus];
[[self selectedCell] moveUp: sender];
2006-12-22 04:41:44 +00:00
[self unlockFocus];
[self setNeedsDisplay: YES];
2006-12-22 04:41:44 +00:00
}
- (void) moveDown: (id) sender {
2006-12-22 04:41:44 +00:00
[self lockFocus];
[[self selectedCell] moveDown: sender];
2006-12-22 04:41:44 +00:00
[self unlockFocus];
[self setNeedsDisplay: YES];
2006-12-22 04:41:44 +00:00
}
@end