mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-03 17:00:42 +00:00
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:
parent
54509f6229
commit
2998c54fed
6 changed files with 346 additions and 316 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
||||||
|
2006-08-09 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Headers/AppKit/NSStepper.h
|
||||||
|
* Headers/AppKit/NSStepperCell.h: Removed private method declarations.
|
||||||
|
* Source/NSStepper.m: Moved code from mouseDown: method to the cell
|
||||||
|
method trackMouse:...untilMouseUp:. Also moved the _increment and
|
||||||
|
_decrement methods to the cell class.
|
||||||
|
* Source/NSStepperCell.m: Rewrote mouse tracking to be more
|
||||||
|
similar to NSCell's implementation and not use any direct
|
||||||
|
drawing. Do not use hard coded colour values in the drawing
|
||||||
|
methods, implemented keyed encoding and cleaned up the rest of the
|
||||||
|
class.
|
||||||
|
* Source/NSCell.m (trackMouse:...untilMouseUp:): Moved
|
||||||
|
initialisation of periodCount out of the loop. In the old version
|
||||||
|
the value stayed always 0.
|
||||||
|
|
||||||
2006-08-07 Fred Kiefer <FredKiefer@gmx.de>
|
2006-08-07 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSCell.m (-setBezeled:, -setBordered:): Switch border off,
|
* Source/NSCell.m (-setBezeled:, -setBordered:): Switch border off,
|
||||||
|
|
|
@ -31,8 +31,6 @@
|
||||||
|
|
||||||
#include <AppKit/NSControl.h>
|
#include <AppKit/NSControl.h>
|
||||||
|
|
||||||
@class NSEvent;
|
|
||||||
|
|
||||||
@interface NSStepper : NSControl
|
@interface NSStepper : NSControl
|
||||||
{
|
{
|
||||||
// Attributes
|
// Attributes
|
||||||
|
@ -44,18 +42,11 @@
|
||||||
- (double) increment;
|
- (double) increment;
|
||||||
- (void) setIncrement: (double)increment;
|
- (void) setIncrement: (double)increment;
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)autorepeat;
|
- (BOOL)autorepeat;
|
||||||
- (void)setAutorepeat: (BOOL)autorepeat;
|
- (void)setAutorepeat: (BOOL)autorepeat;
|
||||||
- (BOOL)valueWraps;
|
- (BOOL)valueWraps;
|
||||||
- (void)setValueWraps: (BOOL)valueWraps;
|
- (void)setValueWraps: (BOOL)valueWraps;
|
||||||
|
|
||||||
- (void)mouseDown:(NSEvent*)event;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@interface NSStepper (Private)
|
|
||||||
- (void)_increment;
|
|
||||||
- (void)_decrement;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif // _GNUstep_H_NSStepper
|
#endif // _GNUstep_H_NSStepper
|
||||||
|
|
|
@ -29,8 +29,7 @@
|
||||||
|
|
||||||
#include <AppKit/NSActionCell.h>
|
#include <AppKit/NSActionCell.h>
|
||||||
|
|
||||||
|
@interface NSStepperCell : NSActionCell
|
||||||
@interface NSStepperCell : NSActionCell <NSCoding>
|
|
||||||
{
|
{
|
||||||
// Think of the following ones as of two BOOL ivars
|
// Think of the following ones as of two BOOL ivars
|
||||||
#define _autorepeat _cell.subclass_bool_one
|
#define _autorepeat _cell.subclass_bool_one
|
||||||
|
@ -50,29 +49,11 @@
|
||||||
- (double)increment;
|
- (double)increment;
|
||||||
- (void)setIncrement: (double)increment;
|
- (void)setIncrement: (double)increment;
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)autorepeat;
|
- (BOOL)autorepeat;
|
||||||
- (void)setAutorepeat: (BOOL)autorepeat;
|
- (void)setAutorepeat: (BOOL)autorepeat;
|
||||||
- (BOOL)valueWraps;
|
- (BOOL)valueWraps;
|
||||||
- (void)setValueWraps: (BOOL)valueWraps;
|
- (void)setValueWraps: (BOOL)valueWraps;
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// NSCoding protocol
|
|
||||||
//
|
|
||||||
- (void)encodeWithCoder: (NSCoder *)aCoder;
|
|
||||||
- initWithCoder: (NSCoder *)aDecoder;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSStepperCell (Private)
|
|
||||||
- (void) highlight: (BOOL) highlight
|
|
||||||
upButton: (BOOL) upButton
|
|
||||||
withFrame: (NSRect) frame
|
|
||||||
inView: (NSView*) controlView;
|
|
||||||
|
|
||||||
- (NSRect)upButtonRectWithFrame: (NSRect) frame;
|
|
||||||
- (NSRect)downButtonRectWithFrame: (NSRect) frame;
|
|
||||||
- (void)_drawText: (NSRect)aRect;
|
|
||||||
@end
|
|
||||||
#endif // _GNUstep_H_NSStepperCell
|
#endif // _GNUstep_H_NSStepperCell
|
||||||
|
|
|
@ -1522,6 +1522,7 @@ static NSColor *shadowCol;
|
||||||
NSPoint last_point = point;
|
NSPoint last_point = point;
|
||||||
BOOL done;
|
BOOL done;
|
||||||
BOOL mouseWentUp;
|
BOOL mouseWentUp;
|
||||||
|
unsigned periodCount = 0;
|
||||||
|
|
||||||
NSDebugLLog(@"NSCell", @"cell start tracking in rect %@ initial point %f %f",
|
NSDebugLLog(@"NSCell", @"cell start tracking in rect %@ initial point %f %f",
|
||||||
NSStringFromRect(cellFrame), point.x, point.y);
|
NSStringFromRect(cellFrame), point.x, point.y);
|
||||||
|
@ -1551,7 +1552,6 @@ static NSColor *shadowCol;
|
||||||
{
|
{
|
||||||
NSEventType eventType;
|
NSEventType eventType;
|
||||||
BOOL pointIsInCell;
|
BOOL pointIsInCell;
|
||||||
unsigned periodCount = 0;
|
|
||||||
|
|
||||||
theEvent = [theApp nextEventMatchingMask: event_mask
|
theEvent = [theApp nextEventMatchingMask: event_mask
|
||||||
untilDate: nil
|
untilDate: nil
|
||||||
|
|
|
@ -29,7 +29,6 @@
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include "AppKit/NSStepper.h"
|
#include "AppKit/NSStepper.h"
|
||||||
#include "AppKit/NSControl.h"
|
#include "AppKit/NSControl.h"
|
||||||
#include "AppKit/NSColor.h"
|
|
||||||
#include "AppKit/NSEvent.h"
|
#include "AppKit/NSEvent.h"
|
||||||
#include "AppKit/NSWindow.h"
|
#include "AppKit/NSWindow.h"
|
||||||
#include "AppKit/NSApplication.h"
|
#include "AppKit/NSApplication.h"
|
||||||
|
@ -71,11 +70,6 @@ id _nsstepperCellClass = nil;
|
||||||
// Instance methods
|
// Instance methods
|
||||||
//
|
//
|
||||||
|
|
||||||
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
|
|
||||||
{
|
|
||||||
return YES;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Determining the first responder
|
// Determining the first responder
|
||||||
//
|
//
|
||||||
|
@ -97,6 +91,8 @@ id _nsstepperCellClass = nil;
|
||||||
|
|
||||||
- (void) keyDown: (NSEvent*)theEvent
|
- (void) keyDown: (NSEvent*)theEvent
|
||||||
{
|
{
|
||||||
|
// FIXME
|
||||||
|
[super keyDown: theEvent];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (double) maxValue
|
- (double) maxValue
|
||||||
|
@ -129,8 +125,6 @@ id _nsstepperCellClass = nil;
|
||||||
[_cell setIncrement: increment];
|
[_cell setIncrement: increment];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)autorepeat
|
- (BOOL)autorepeat
|
||||||
{
|
{
|
||||||
return [_cell autorepeat];
|
return [_cell autorepeat];
|
||||||
|
@ -151,199 +145,4 @@ id _nsstepperCellClass = nil;
|
||||||
[_cell setValueWraps: valueWraps];
|
[_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
|
@end
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
|
Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
|
||||||
Date: 2001
|
Date: 2001
|
||||||
|
Author: Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
Date: August 2006
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
|
@ -24,17 +26,35 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "AppKit/NSGraphicsContext.h"
|
|
||||||
|
#include "AppKit/NSApplication.h"
|
||||||
#include "AppKit/NSColor.h"
|
#include "AppKit/NSColor.h"
|
||||||
#include "AppKit/DPSOperators.h"
|
#include "AppKit/NSControl.h"
|
||||||
#include "AppKit/PSOperators.h"
|
#include "AppKit/NSEvent.h"
|
||||||
#include "AppKit/NSFont.h"
|
|
||||||
#include "AppKit/NSGraphics.h"
|
#include "AppKit/NSGraphics.h"
|
||||||
|
#include "AppKit/NSGraphicsContext.h"
|
||||||
#include "AppKit/NSStepperCell.h"
|
#include "AppKit/NSStepperCell.h"
|
||||||
#include "AppKit/NSText.h"
|
#include "AppKit/NSWindow.h"
|
||||||
|
#include "AppKit/PSOperators.h"
|
||||||
#include "GNUstepGUI/GSDrawFunctions.h"
|
#include "GNUstepGUI/GSDrawFunctions.h"
|
||||||
|
|
||||||
|
// Hard coded values for button sizes
|
||||||
|
#define STEPPER_WIDTH 15
|
||||||
|
#define STEPPER_HEIGHT 11
|
||||||
|
|
||||||
|
@interface NSStepperCell (Private)
|
||||||
|
- (void) _increment;
|
||||||
|
- (void) _decrement;
|
||||||
|
- (void) setHighlighted: (BOOL)highlight
|
||||||
|
upButton: (BOOL)upButton
|
||||||
|
withFrame: (NSRect)frame
|
||||||
|
inView: (NSView*)controlView;
|
||||||
|
- (NSRect) upButtonRectWithFrame: (NSRect)frame;
|
||||||
|
- (NSRect) downButtonRectWithFrame: (NSRect)frame;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation NSStepperCell
|
@implementation NSStepperCell
|
||||||
|
|
||||||
+ (void) initialize
|
+ (void) initialize
|
||||||
{
|
{
|
||||||
if (self == [NSStepperCell class])
|
if (self == [NSStepperCell class])
|
||||||
|
@ -43,21 +63,30 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
+ (BOOL) prefersTrackingUntilMouseUp
|
||||||
|
{
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Initialization
|
// Initialization
|
||||||
//
|
//
|
||||||
- (id) init
|
- (id) init
|
||||||
{
|
{
|
||||||
|
self = [super init];
|
||||||
|
|
||||||
[self setIntValue: 0];
|
[self setIntValue: 0];
|
||||||
[super setAlignment: NSRightTextAlignment];
|
[self setAlignment: NSRightTextAlignment];
|
||||||
[super setWraps: NO];
|
[self setWraps: NO];
|
||||||
_autorepeat = YES;
|
_autorepeat = YES;
|
||||||
_valueWraps = YES;
|
_valueWraps = YES;
|
||||||
_maxValue = 59;
|
_maxValue = 59;
|
||||||
_minValue = 0;
|
_minValue = 0;
|
||||||
_increment = 1;
|
_increment = 1;
|
||||||
|
|
||||||
highlightUp = NO;
|
highlightUp = NO;
|
||||||
highlightDown = NO;
|
highlightDown = NO;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,8 +120,6 @@
|
||||||
_increment = increment;
|
_increment = increment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)autorepeat
|
- (BOOL)autorepeat
|
||||||
{
|
{
|
||||||
return _autorepeat;
|
return _autorepeat;
|
||||||
|
@ -113,18 +140,6 @@
|
||||||
_valueWraps = valueWraps;
|
_valueWraps = valueWraps;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) dealloc
|
|
||||||
{
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) copyWithZone: (NSZone*)zone
|
|
||||||
{
|
|
||||||
NSStepperCell *c = [super copyWithZone: zone];
|
|
||||||
|
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline NSRect DrawLightButton(NSRect border, NSRect clip)
|
static inline NSRect DrawLightButton(NSRect border, NSRect clip)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -151,21 +166,22 @@ static inline NSRect DrawLightButton(NSRect border, NSRect clip)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void DrawUpButton(NSRect aRect)
|
static inline void DrawUpButton(NSRect aRect)
|
||||||
{
|
{
|
||||||
NSRect unHighlightRect = DrawLightButton(aRect, NSZeroRect);
|
NSRect unHighlightRect = DrawLightButton(aRect, NSZeroRect);
|
||||||
[[NSColor controlBackgroundColor] set];
|
[[NSColor controlBackgroundColor] set];
|
||||||
NSRectFill(unHighlightRect);
|
NSRectFill(unHighlightRect);
|
||||||
|
|
||||||
PSsetgray(NSDarkGray);
|
PSsetlinewidth(1.0);
|
||||||
|
[[NSColor controlShadowColor] set];
|
||||||
PSmoveto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
PSmoveto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
||||||
PSlineto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
PSlineto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
PSsetgray(NSBlack);
|
[[NSColor controlDarkShadowColor] set];
|
||||||
PSmoveto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
PSmoveto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
||||||
PSlineto(NSMaxX(aRect) - 11, NSMinY(aRect) + 4);
|
PSlineto(NSMaxX(aRect) - 11, NSMinY(aRect) + 4);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
PSsetgray(NSWhite);
|
[[NSColor controlLightHighlightColor] set];
|
||||||
PSmoveto(NSMaxX(aRect) - 11, NSMinY(aRect) + 3);
|
PSmoveto(NSMaxX(aRect) - 11, NSMinY(aRect) + 3);
|
||||||
PSlineto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
PSlineto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
|
@ -177,15 +193,16 @@ static inline void HighlightUpButton(NSRect aRect)
|
||||||
[[NSColor selectedControlColor] set];
|
[[NSColor selectedControlColor] set];
|
||||||
NSRectFill(highlightRect);
|
NSRectFill(highlightRect);
|
||||||
|
|
||||||
PSsetgray(NSLightGray);
|
PSsetlinewidth(1.0);
|
||||||
|
[[NSColor controlHighlightColor] set];
|
||||||
PSmoveto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
PSmoveto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
||||||
PSlineto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
PSlineto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
PSsetgray(NSBlack);
|
[[NSColor controlDarkShadowColor] set];
|
||||||
PSmoveto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
PSmoveto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
||||||
PSlineto(NSMaxX(aRect) - 11, NSMinY(aRect) + 4);
|
PSlineto(NSMaxX(aRect) - 11, NSMinY(aRect) + 4);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
PSsetgray(NSLightGray);
|
[[NSColor controlHighlightColor] set];
|
||||||
PSmoveto(NSMaxX(aRect) - 11, NSMinY(aRect) + 3);
|
PSmoveto(NSMaxX(aRect) - 11, NSMinY(aRect) + 3);
|
||||||
PSlineto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
PSlineto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
|
@ -198,15 +215,15 @@ static inline void DrawDownButton(NSRect aRect)
|
||||||
NSRectFill(unHighlightRect);
|
NSRectFill(unHighlightRect);
|
||||||
|
|
||||||
PSsetlinewidth(1.0);
|
PSsetlinewidth(1.0);
|
||||||
PSsetgray(NSDarkGray);
|
[[NSColor controlShadowColor] set];
|
||||||
PSmoveto(NSMinX(aRect) + 4, NSMaxY(aRect) - 3);
|
PSmoveto(NSMinX(aRect) + 4, NSMaxY(aRect) - 3);
|
||||||
PSlineto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
PSlineto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
PSsetgray(NSWhite);
|
[[NSColor controlLightHighlightColor] set];
|
||||||
PSmoveto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
PSmoveto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
||||||
PSlineto(NSMinX(aRect) + 10, NSMaxY(aRect) - 3);
|
PSlineto(NSMinX(aRect) + 10, NSMaxY(aRect) - 3);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
PSsetgray(NSBlack);
|
[[NSColor controlDarkShadowColor] set];
|
||||||
PSmoveto(NSMinX(aRect) + 10, NSMaxY(aRect) - 2);
|
PSmoveto(NSMinX(aRect) + 10, NSMaxY(aRect) - 2);
|
||||||
PSlineto(NSMinX(aRect) + 4, NSMaxY(aRect) - 2);
|
PSlineto(NSMinX(aRect) + 4, NSMaxY(aRect) - 2);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
|
@ -219,15 +236,15 @@ static inline void HighlightDownButton(NSRect aRect)
|
||||||
NSRectFill(highlightRect);
|
NSRectFill(highlightRect);
|
||||||
|
|
||||||
PSsetlinewidth(1.0);
|
PSsetlinewidth(1.0);
|
||||||
PSsetgray(NSLightGray);
|
[[NSColor controlHighlightColor] set];
|
||||||
PSmoveto(NSMinX(aRect) + 4, NSMaxY(aRect) - 3);
|
PSmoveto(NSMinX(aRect) + 4, NSMaxY(aRect) - 3);
|
||||||
PSlineto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
PSlineto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
PSsetgray(NSLightGray);
|
[[NSColor controlHighlightColor] set];
|
||||||
PSmoveto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
PSmoveto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
||||||
PSlineto(NSMinX(aRect) + 10, NSMaxY(aRect) - 3);
|
PSlineto(NSMinX(aRect) + 10, NSMaxY(aRect) - 3);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
PSsetgray(NSBlack);
|
[[NSColor controlDarkShadowColor] set];
|
||||||
PSmoveto(NSMinX(aRect) + 10, NSMaxY(aRect) - 2);
|
PSmoveto(NSMinX(aRect) + 10, NSMaxY(aRect) - 2);
|
||||||
PSlineto(NSMinX(aRect) + 4, NSMaxY(aRect) - 2);
|
PSlineto(NSMinX(aRect) + 4, NSMaxY(aRect) - 2);
|
||||||
PSstroke();
|
PSstroke();
|
||||||
|
@ -246,7 +263,7 @@ static inline void HighlightDownButton(NSRect aRect)
|
||||||
twoButtons = downRect;
|
twoButtons = downRect;
|
||||||
twoButtons.origin.y--;
|
twoButtons.origin.y--;
|
||||||
twoButtons.size.width++;
|
twoButtons.size.width++;
|
||||||
twoButtons.size.height = 23;
|
twoButtons.size.height = 2 * STEPPER_HEIGHT + 1;
|
||||||
|
|
||||||
if (highlightUp)
|
if (highlightUp)
|
||||||
HighlightUpButton(upRect);
|
HighlightUpButton(upRect);
|
||||||
|
@ -260,49 +277,169 @@ static inline void HighlightDownButton(NSRect aRect)
|
||||||
|
|
||||||
{
|
{
|
||||||
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge};
|
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge};
|
||||||
float grays[] = {NSBlack, NSBlack};
|
NSColor *black = [NSColor controlDarkShadowColor];
|
||||||
|
NSColor *grays[] = {black, black};
|
||||||
|
|
||||||
NSDrawTiledRects(twoButtons, NSZeroRect,
|
NSDrawColorTiledRects(twoButtons, NSZeroRect,
|
||||||
up_sides, grays, 2);
|
up_sides, grays, 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) highlight: (BOOL) highlight
|
- (void) getPeriodicDelay: (float*)delay interval: (float*)interval
|
||||||
upButton: (BOOL) upButton
|
|
||||||
withFrame: (NSRect) frame
|
|
||||||
inView: (NSView*) controlView
|
|
||||||
{
|
{
|
||||||
if (upButton)
|
*delay = 0.5;
|
||||||
|
*interval = 0.025;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) trackMouse: (NSEvent*)theEvent
|
||||||
|
inRect: (NSRect)cellFrame
|
||||||
|
ofView: (NSView*)controlView
|
||||||
|
untilMouseUp: (BOOL)flag
|
||||||
|
{
|
||||||
|
NSPoint location = [theEvent locationInWindow];
|
||||||
|
NSPoint point = [controlView convertPoint: location fromView: nil];
|
||||||
|
NSRect upRect;
|
||||||
|
NSRect downRect;
|
||||||
|
NSRect rect;
|
||||||
|
float delay;
|
||||||
|
float interval;
|
||||||
|
BOOL overButton = YES;
|
||||||
|
unsigned int event_mask = NSLeftMouseUpMask | NSLeftMouseDraggedMask;
|
||||||
|
unsigned int periodCount = 0;
|
||||||
|
BOOL isDirectionUp;
|
||||||
|
BOOL autorepeat = [self autorepeat];
|
||||||
|
BOOL done = NO;
|
||||||
|
BOOL mouseWentUp = NO;
|
||||||
|
|
||||||
|
_mouse_down_flags = [theEvent modifierFlags];
|
||||||
|
if (![self startTrackingAt: point inView: controlView])
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
if (![controlView mouse: point inRect: cellFrame])
|
||||||
|
return NO; // point is not in cell
|
||||||
|
|
||||||
|
if ([self isEnabled] == NO)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
if ([theEvent type] != NSLeftMouseDown)
|
||||||
|
return NO;
|
||||||
|
|
||||||
|
upRect = [self upButtonRectWithFrame: cellFrame];
|
||||||
|
downRect = [self downButtonRectWithFrame: cellFrame];
|
||||||
|
|
||||||
|
// Did the mouse go down in the up or in the down part?
|
||||||
|
if (NSMouseInRect(point, upRect, NO))
|
||||||
{
|
{
|
||||||
highlightUp = highlight;
|
isDirectionUp = YES;
|
||||||
|
rect = upRect;
|
||||||
|
}
|
||||||
|
else if (NSMouseInRect(point, downRect, NO))
|
||||||
|
{
|
||||||
|
isDirectionUp = NO;
|
||||||
|
rect = downRect;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
highlightDown = highlight;
|
return mouseWentUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self drawWithFrame: frame inView: controlView];
|
[self setHighlighted: YES
|
||||||
}
|
upButton: isDirectionUp
|
||||||
|
withFrame: cellFrame
|
||||||
|
inView: controlView];
|
||||||
|
|
||||||
- (NSRect) upButtonRectWithFrame: (NSRect) frame
|
if (autorepeat)
|
||||||
{
|
{
|
||||||
NSRect upRect;
|
[self getPeriodicDelay: &delay interval: &interval];
|
||||||
upRect.size.width = 15;
|
[NSEvent startPeriodicEventsAfterDelay: delay withPeriod: interval];
|
||||||
upRect.size.height = 11;
|
event_mask |= NSPeriodicMask;
|
||||||
upRect.origin.x = NSMaxX(frame) - 16;
|
}
|
||||||
upRect.origin.y = NSMinY(frame) + ((int) frame.size.height / 2) + 1;
|
|
||||||
return upRect;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSRect) downButtonRectWithFrame: (NSRect) frame
|
while (!done)
|
||||||
{
|
{
|
||||||
NSRect downRect;
|
NSEventType eventType;
|
||||||
downRect.size.width = 15;
|
|
||||||
downRect.size.height = 11;
|
theEvent = [NSApp nextEventMatchingMask: event_mask
|
||||||
downRect.origin.x = NSMaxX(frame) - 16;
|
untilDate: nil
|
||||||
downRect.origin.y = NSMinY(frame) +
|
inMode: NSEventTrackingRunLoopMode
|
||||||
((int) frame.size.height / 2) - 10;
|
dequeue: YES];
|
||||||
return downRect;
|
eventType = [theEvent type];
|
||||||
|
|
||||||
|
// Did the mouse go up?
|
||||||
|
if (eventType == NSLeftMouseUp)
|
||||||
|
{
|
||||||
|
mouseWentUp = YES;
|
||||||
|
done = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventType == NSPeriodic)
|
||||||
|
{
|
||||||
|
periodCount++;
|
||||||
|
if (periodCount == 4)
|
||||||
|
periodCount = 0;
|
||||||
|
if (periodCount == 0)
|
||||||
|
{
|
||||||
|
if (isDirectionUp)
|
||||||
|
[self _increment];
|
||||||
|
else
|
||||||
|
[self _decrement];
|
||||||
|
[(NSControl*)controlView sendAction: [self action] to: [self target]];
|
||||||
|
}
|
||||||
|
location = [[controlView window] mouseLocationOutsideOfEventStream];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
location = [theEvent locationInWindow];
|
||||||
|
}
|
||||||
|
point = [controlView convertPoint: location fromView: nil];
|
||||||
|
|
||||||
|
if (![controlView mouse: point inRect: cellFrame])
|
||||||
|
{
|
||||||
|
if (flag == NO)
|
||||||
|
{
|
||||||
|
done = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NSMouseInRect(point, rect, NO) != overButton)
|
||||||
|
{
|
||||||
|
overButton = !overButton;
|
||||||
|
if (overButton && autorepeat)
|
||||||
|
{
|
||||||
|
[NSEvent startPeriodicEventsAfterDelay: delay withPeriod: interval];
|
||||||
|
periodCount = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[NSEvent stopPeriodicEvents];
|
||||||
|
}
|
||||||
|
[self setHighlighted: overButton
|
||||||
|
upButton: isDirectionUp
|
||||||
|
withFrame: cellFrame
|
||||||
|
inView: controlView];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overButton && autorepeat)
|
||||||
|
{
|
||||||
|
[NSEvent stopPeriodicEvents];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overButton)
|
||||||
|
{
|
||||||
|
if (isDirectionUp)
|
||||||
|
[self _increment];
|
||||||
|
else
|
||||||
|
[self _decrement];
|
||||||
|
[(NSControl*)controlView sendAction: [self action] to: [self target]];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self setHighlighted: NO
|
||||||
|
upButton: isDirectionUp
|
||||||
|
withFrame: cellFrame
|
||||||
|
inView: controlView];
|
||||||
|
|
||||||
|
return mouseWentUp;
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -310,9 +447,20 @@ static inline void HighlightDownButton(NSRect aRect)
|
||||||
//
|
//
|
||||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||||
{
|
{
|
||||||
int tmp1, tmp2;
|
|
||||||
[super encodeWithCoder: aCoder];
|
[super encodeWithCoder: aCoder];
|
||||||
|
|
||||||
|
if([aCoder allowsKeyedCoding])
|
||||||
|
{
|
||||||
|
[aCoder encodeDouble: [self increment] forKey: @"NSIncrement"];
|
||||||
|
[aCoder encodeDouble: [self maxValue] forKey: @"NSMaxValue"];
|
||||||
|
[aCoder encodeDouble: [self minValue] forKey: @"NSMinValue"];
|
||||||
|
[aCoder encodeBool: [self autorepeat] forKey: @"NSAutorepeat"];
|
||||||
|
[aCoder encodeBool: [self valueWraps] forKey: @"NSValueWraps"];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int tmp1, tmp2;
|
||||||
|
|
||||||
tmp1 = (int)_autorepeat;
|
tmp1 = (int)_autorepeat;
|
||||||
tmp2 = (int)_valueWraps;
|
tmp2 = (int)_valueWraps;
|
||||||
|
|
||||||
|
@ -326,26 +474,28 @@ static inline void HighlightDownButton(NSRect aRect)
|
||||||
at: &tmp1];
|
at: &tmp1];
|
||||||
[aCoder encodeValueOfObjCType: @encode(int)
|
[aCoder encodeValueOfObjCType: @encode(int)
|
||||||
at: &tmp2];
|
at: &tmp2];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||||
{
|
{
|
||||||
int tmp1, tmp2;
|
|
||||||
[super initWithCoder: aDecoder];
|
[super initWithCoder: aDecoder];
|
||||||
|
|
||||||
if([aDecoder allowsKeyedCoding])
|
if([aDecoder allowsKeyedCoding])
|
||||||
{
|
{
|
||||||
_autorepeat = [aDecoder decodeBoolForKey: @"NSAutorepeat"];
|
_autorepeat = [aDecoder decodeBoolForKey: @"NSAutorepeat"];
|
||||||
_valueWraps = [aDecoder decodeBoolForKey: @"NSValueWraps"];
|
_valueWraps = [aDecoder decodeBoolForKey: @"NSValueWraps"];
|
||||||
_increment = [aDecoder decodeIntForKey: @"NSIncrement"];
|
_increment = [aDecoder decodeDoubleForKey: @"NSIncrement"];
|
||||||
_maxValue = [aDecoder decodeIntForKey: @"NSMaxValue"];
|
_maxValue = [aDecoder decodeDoubleForKey: @"NSMaxValue"];
|
||||||
if([aDecoder containsValueForKey: @"NSMinValue"])
|
if([aDecoder containsValueForKey: @"NSMinValue"])
|
||||||
{
|
{
|
||||||
_minValue = [aDecoder decodeIntForKey: @"NSMinValue"];
|
_minValue = [aDecoder decodeDoubleForKey: @"NSMinValue"];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
int tmp1, tmp2;
|
||||||
|
|
||||||
[aDecoder decodeValueOfObjCType: @encode(double)
|
[aDecoder decodeValueOfObjCType: @encode(double)
|
||||||
at: &_maxValue];
|
at: &_maxValue];
|
||||||
[aDecoder decodeValueOfObjCType: @encode(double)
|
[aDecoder decodeValueOfObjCType: @encode(double)
|
||||||
|
@ -365,3 +515,96 @@ static inline void HighlightDownButton(NSRect aRect)
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@implementation NSStepperCell (Private)
|
||||||
|
|
||||||
|
- (void) _increment
|
||||||
|
{
|
||||||
|
double newValue;
|
||||||
|
double maxValue = [self maxValue];
|
||||||
|
double minValue = [self minValue];
|
||||||
|
double increment = [self increment];
|
||||||
|
|
||||||
|
newValue = [self doubleValue] + increment;
|
||||||
|
if ([self valueWraps])
|
||||||
|
{
|
||||||
|
if (newValue > maxValue)
|
||||||
|
newValue = newValue - maxValue + minValue - 1;
|
||||||
|
else if (newValue < minValue)
|
||||||
|
newValue = newValue + maxValue - minValue + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (newValue > maxValue)
|
||||||
|
newValue = maxValue;
|
||||||
|
else if (newValue < minValue)
|
||||||
|
newValue = minValue;
|
||||||
|
}
|
||||||
|
[self setDoubleValue: newValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _decrement
|
||||||
|
{
|
||||||
|
double newValue;
|
||||||
|
double maxValue = [self maxValue];
|
||||||
|
double minValue = [self minValue];
|
||||||
|
double increment = [self increment];
|
||||||
|
|
||||||
|
newValue = [self doubleValue] - increment;
|
||||||
|
if ([self valueWraps])
|
||||||
|
{
|
||||||
|
if (newValue > maxValue)
|
||||||
|
newValue = newValue - maxValue + minValue - 1;
|
||||||
|
else if (newValue < minValue)
|
||||||
|
newValue = newValue + maxValue - minValue + 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (newValue > maxValue)
|
||||||
|
newValue = maxValue;
|
||||||
|
else if (newValue < minValue)
|
||||||
|
newValue = minValue;
|
||||||
|
}
|
||||||
|
[self setDoubleValue: newValue];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) setHighlighted: (BOOL)highlight
|
||||||
|
upButton: (BOOL)upButton
|
||||||
|
withFrame: (NSRect)frame
|
||||||
|
inView: (NSView*)controlView
|
||||||
|
{
|
||||||
|
if (upButton)
|
||||||
|
{
|
||||||
|
highlightUp = highlight;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
highlightDown = highlight;
|
||||||
|
}
|
||||||
|
|
||||||
|
[controlView setNeedsDisplayInRect: frame];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSRect) upButtonRectWithFrame: (NSRect)frame
|
||||||
|
{
|
||||||
|
NSRect upRect;
|
||||||
|
|
||||||
|
upRect.size.width = STEPPER_WIDTH;
|
||||||
|
upRect.size.height = STEPPER_HEIGHT;
|
||||||
|
upRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1;
|
||||||
|
upRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) + 1;
|
||||||
|
return upRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSRect) downButtonRectWithFrame: (NSRect)frame
|
||||||
|
{
|
||||||
|
NSRect downRect;
|
||||||
|
|
||||||
|
downRect.size.width = STEPPER_WIDTH;
|
||||||
|
downRect.size.height = STEPPER_HEIGHT;
|
||||||
|
downRect.origin.x = NSMaxX(frame) - STEPPER_WIDTH - 1;
|
||||||
|
downRect.origin.y = NSMinY(frame) + ((int)frame.size.height / 2) - STEPPER_HEIGHT + 1;
|
||||||
|
return downRect;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue