Clean up for NSSlider and NSSliderCell

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29022 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2009-11-16 12:26:38 +00:00
parent 40a81ac812
commit 73f0d0ca88
3 changed files with 56 additions and 44 deletions

View file

@ -26,13 +26,12 @@
Boston, MA 02110-1301, USA.
*/
#include <Foundation/NSRunLoop.h>
#include "math.h" // fabs
#import <Foundation/NSString.h>
#include "AppKit/NSEvent.h"
#include "AppKit/NSSlider.h"
#include "AppKit/NSSliderCell.h"
#include "AppKit/NSWindow.h"
#include "math.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSSlider.h"
#import "AppKit/NSSliderCell.h"
/**
<unit>
@ -92,7 +91,9 @@ static Class cellClass;
- (id) initWithFrame: (NSRect)frameRect
{
[super initWithFrame: frameRect];
self = [super initWithFrame: frameRect];
if (self == nil)
return nil;
[_cell setState: 1];
[_cell setContinuous: YES];
@ -262,7 +263,7 @@ static Class cellClass;
return YES;
}
- (void) keyDown:(NSEvent *)ev
- (void) keyDown: (NSEvent *)ev
{
NSString *characters = [ev characters];
int i, length = [characters length];
@ -284,8 +285,8 @@ static Class cellClass;
{
if ([_cell numberOfTickMarks])
{
double tick0 = [_cell tickMarkValueAtIndex:0];
double tick1 = [_cell tickMarkValueAtIndex:1];
double tick0 = [_cell tickMarkValueAtIndex: 0];
double tick1 = [_cell tickMarkValueAtIndex: 1];
diff = tick1 - tick0;
}
else
@ -300,7 +301,7 @@ static Class cellClass;
for (i = 0; i < length; i++)
{
switch([characters characterAtIndex:i])
switch ([characters characterAtIndex: i])
{
case NSLeftArrowFunctionKey:
case NSDownArrowFunctionKey:
@ -334,7 +335,7 @@ static Class cellClass;
if (valueChanged)
{
if (only_ticks)
value = [_cell closestTickMarkValueToValue:value];
value = [_cell closestTickMarkValueToValue: value];
if (value < min)
{
@ -345,12 +346,12 @@ static Class cellClass;
value = max;
}
[self setDoubleValue:value];
[self sendAction:[self action] to:[self target]];
[self setDoubleValue: value];
[self sendAction: [self action] to: [self target]];
return;
}
[super keyDown:ev];
[super keyDown: ev];
}
// ticks

View file

@ -28,18 +28,18 @@
#include <math.h> // (float)rintf(float x)
#include "config.h"
#include <Foundation/NSString.h>
#include <Foundation/NSException.h>
#import <Foundation/NSString.h>
#import <Foundation/NSException.h>
#include "AppKit/NSApplication.h"
#include "AppKit/NSColor.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"
#import "AppKit/NSApplication.h"
#import "AppKit/NSColor.h"
#import "AppKit/NSControl.h"
#import "AppKit/NSEvent.h"
#import "AppKit/NSGraphics.h"
#import "AppKit/NSImage.h"
#import "AppKit/NSSliderCell.h"
#import "AppKit/NSTextFieldCell.h"
#import "AppKit/NSWindow.h"
DEFINE_RINT_IF_MISSING
@ -132,12 +132,15 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
- (id) init
{
self = [self initImageCell: nil];
if (self == nil)
return nil;
_altIncrementValue = -1;
_isVertical = -1;
_minValue = 0;
_maxValue = 1;
_cell.is_bordered = YES;
_cell.is_bezeled = YES;
_cell.is_bezeled = NO;
_knobCell = [NSCell new];
_titleCell = [NSTextFieldCell new];
@ -157,19 +160,18 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
- (id) copyWithZone:(NSZone *)zone
{
NSSliderCell *cpy = [super copyWithZone:zone];
NSSliderCell *cpy = [super copyWithZone: zone];
if (cpy != nil)
{
/* since NSCells call to NSCopyObject only copies object addresses */
cpy->_titleCell = [_titleCell copyWithZone: zone];
cpy->_knobCell = [_knobCell copyWithZone: zone];
}
/* since NSCells call to NSCopyObject only copies object addresses */
RETAIN(cpy->_titleCell);
RETAIN(cpy->_knobCell);
return cpy;
}
- (BOOL) isFlipped
{
return YES;
}
/** <p>Draws the slider's track, not including the bezel, in <var>aRect</var>
<var>flipped</var> indicates whether the control view has a flipped
coordinate system.</p>
@ -193,10 +195,10 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
only.</p> */
- (NSRect) knobRectFlipped: (BOOL)flipped
{
NSImage *image = [_knobCell image];
NSSize size;
NSPoint origin;
float floatValue = [self floatValue];
NSImage *image = [_knobCell image];
NSSize size;
NSPoint origin;
float floatValue = [self floatValue];
if (_isVertical && flipped)
{
@ -259,9 +261,9 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{
BOOL vertical = (cellFrame.size.height > cellFrame.size.width);
NSImage *image;
NSSize size;
BOOL vertical = (cellFrame.size.height > cellFrame.size.width);
NSImage *image;
NSSize size;
cellFrame = [self drawingRectForBounds: cellFrame];
@ -325,7 +327,7 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
}
else
{
return 0;
return 0;
}
return _isVertical ? size.height : size.width;
@ -744,6 +746,9 @@ float _floatValueForMousePoint (NSPoint point, NSRect knobRect,
- (id) initWithCoder: (NSCoder*)decoder
{
self = [super initWithCoder: decoder];
if (self == nil)
return nil;
if ([decoder allowsKeyedCoding])
{
_allowsTickMarkValuesOnly = [decoder decodeBoolForKey: @"NSAllowsTickMarkValuesOnly"];