Added methods to handle ticks with a dummy implementation.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11291 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2001-11-02 13:06:20 +00:00
parent 18858f1cfe
commit 4796b2e906
4 changed files with 183 additions and 18 deletions

View file

@ -27,6 +27,7 @@
#define _GNUstep_H_NSSlider
#include <AppKit/NSControl.h>
#include <AppKit/NSSliderCell.h>
@class NSString;
@class NSImage;
@ -36,26 +37,48 @@
@class NSEvent;
@interface NSSlider : NSControl
// appearance
- (double) altIncrementValue;
- (NSImage*) image;
- (int) isVertical;
- (float) knobThickness;
- (void) setAltIncrementValue: (double)increment;
- (void) setImage: (NSImage*)backgroundImage;
- (void) setKnobThickness: (float)aFloat;
- (void) setTitle: (NSString*)aString;
- (void) setTitleCell: (NSCell*)aCell;
- (void) setTitleColor: (NSColor*)aColor;
- (void) setTitleFont: (NSFont*)fontObject;
// title
- (NSString*) title;
- (id) titleCell;
- (NSColor*) titleColor;
- (NSFont*) titleFont;
- (void) setTitle: (NSString*)aString;
- (void) setTitleCell: (NSCell*)aCell;
- (void) setTitleColor: (NSColor*)aColor;
- (void) setTitleFont: (NSFont*)fontObject;
// value limits
- (double) maxValue;
- (double) minValue;
- (void) setMaxValue: (double)aDouble;
- (void) setMinValue: (double)aDouble;
// mouse handling
- (BOOL) acceptsFirstMouse: (NSEvent*)theEvent;
#ifndef STRICT_OPENSTEP
// ticks
- (BOOL) allowsTickMarkValuesOnly;
- (double) closestTickMarkValueToValue: (double)aValue;
- (int) indexOfTickMarkAtPoint: (NSPoint)point;
- (int) numberOfTickMarks;
- (NSRect) rectOfTickMarkAtIndex: (int)index;
- (void) setAllowsTickMarkValuesOnly: (BOOL)flag;
- (void) setNumberOfTickMarks: (int)numberOfTickMarks;
- (void) setTickMarkPosition: (NSTickMarkPosition)position;
- (NSTickMarkPosition) tickMarkPosition;
- (double) tickMarkValueAtIndex: (int)index;
#endif
@end
#endif // _GNUstep_H_NSSlider

View file

@ -33,6 +33,14 @@
@class NSFont;
@class NSImage;
typedef enum _NSTickMarkPosition
{
NSTickMarkBelow = 0,
NSTickMarkAbove,
NSTickMarkLeft = 0,
NSTickMarkRight
} NSTickMarkPosition;
@interface NSSliderCell : NSActionCell <NSCoding>
{
float _minValue;
@ -42,6 +50,9 @@
id _knobCell;
NSRect _trackRect;
BOOL _isVertical;
BOOL _allowsTickMarkValuesOnly;
int _numberOfTickMarks;
NSTickMarkPosition _tickMarkPosition;
}
/* Asking about the cell's behavior */
@ -81,6 +92,20 @@
- (void) setMinValue: (double)aDouble;
- (void) setMaxValue: (double)aDouble;
#ifndef STRICT_OPENSTEP
// ticks
- (BOOL) allowsTickMarkValuesOnly;
- (double) closestTickMarkValueToValue: (double)aValue;
- (int) indexOfTickMarkAtPoint: (NSPoint)point;
- (int) numberOfTickMarks;
- (NSRect) rectOfTickMarkAtIndex: (int)index;
- (void) setAllowsTickMarkValuesOnly: (BOOL)flag;
- (void) setNumberOfTickMarks: (int)numberOfTickMarks;
- (void) setTickMarkPosition: (NSTickMarkPosition)position;
- (NSTickMarkPosition) tickMarkPosition;
- (double) tickMarkValueAtIndex: (int)index;
#endif
@end
#endif /* _GNUstep_H_NSSliderCell */

View file

@ -26,7 +26,7 @@
*/
#include <Foundation/NSRunLoop.h>
#include "gnustep/gui/config.h"
#include <AppKit/NSEvent.h>
#include <AppKit/NSSlider.h>
#include <AppKit/NSSliderCell.h>
@ -123,6 +123,11 @@ static Class cellClass;
return self;
}
- (double) altIncrementValue
{
return [_cell altIncrementValue];
}
- (NSImage *) image
{
return [_cell image];
@ -138,6 +143,11 @@ static Class cellClass;
return [_cell knobThickness];
}
- (void) setAltIncrementValue: (double)increment
{
[_cell setAltIncrementValue: increment];
}
- (void) setImage: (NSImage *)backgroundImage
{
[_cell setImage: backgroundImage];
@ -213,16 +223,58 @@ static Class cellClass;
return YES;
}
- (void) drawRect: (NSRect)rect
// ticks
- (BOOL) allowsTickMarkValuesOnly
{
/*
* Give the cell our bounds to draw in, not the rect - if we give it a rect
* that represents an exposed part of this view, it will try to draw the
* slider knob positioned in that rectangle ... which is wrong.
*/
[_cell drawWithFrame: _bounds inView: self];
return [_cell allowsTickMarkValuesOnly];
}
- (double) closestTickMarkValueToValue: (double)aValue
{
return [_cell closestTickMarkValueToValue: aValue];
}
- (int) indexOfTickMarkAtPoint: (NSPoint)point;
{
return [_cell indexOfTickMarkAtPoint: point];
}
- (int) numberOfTickMarks;
{
return [_cell numberOfTickMarks];
}
- (NSRect) rectOfTickMarkAtIndex: (int)index;
{
return [_cell rectOfTickMarkAtIndex: index];
}
- (void) setAllowsTickMarkValuesOnly: (BOOL)flag;
{
[_cell setAllowsTickMarkValuesOnly: flag];
}
- (void) setNumberOfTickMarks: (int)numberOfTickMarks;
{
[_cell setNumberOfTickMarks: numberOfTickMarks];
}
- (void) setTickMarkPosition: (NSTickMarkPosition)position;
{
[_cell setTickMarkPosition: position];
}
- (NSTickMarkPosition) tickMarkPosition;
{
return [_cell tickMarkPosition];
}
- (double) tickMarkValueAtIndex: (int)index;
{
return [_cell tickMarkValueAtIndex: index];
}
- (void) trackKnob: (NSEvent*)theEvent knobRect: (NSRect)knobRect
{
NSApplication *app = [NSApplication sharedApplication];
@ -275,7 +327,7 @@ static Class cellClass;
[_window flushWindow];
if (isContinuous)
{
[target performSelector: action withObject: self];
[self sendAction: action to: target];
}
oldFloatValue = floatValue;
}
@ -286,7 +338,7 @@ static Class cellClass;
// If the control is not continuous send the action at the end of the drag
if (!isContinuous)
{
[target performSelector: action withObject: self];
[self sendAction: action to: target];
}
[NSEvent stopPeriodicEvents];
}
@ -311,7 +363,7 @@ static Class cellClass;
[_cell setFloatValue: floatValue];
if ([_cell isContinuous])
{
[[_cell target] performSelector: [_cell action] withObject: self];
[self sendAction: [_cell action] to: [_cell target]];
}
[_cell drawWithFrame: _bounds inView: self];
[_window flushWindow];

View file

@ -25,8 +25,6 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#include "gnustep/gui/config.h"
#include <Foundation/NSString.h>
#include <AppKit/NSSliderCell.h>
@ -281,6 +279,73 @@
return aFloat;
}
// ticks
- (BOOL) allowsTickMarkValuesOnly
{
return _allowsTickMarkValuesOnly;
}
- (double) closestTickMarkValueToValue: (double)aValue
{
if (aValue < _minValue)
return _minValue;
else if (aValue > _maxValue)
return _maxValue;
if (_numberOfTickMarks == 0)
return aValue;
// FIXME
return 0.0;
}
- (int) indexOfTickMarkAtPoint: (NSPoint)point;
{
// FIXME
return 0;
}
- (int) numberOfTickMarks;
{
return _numberOfTickMarks;
}
- (NSRect) rectOfTickMarkAtIndex: (int)index;
{
// FIXME
return NSZeroRect;
}
- (void) setAllowsTickMarkValuesOnly: (BOOL)flag;
{
_allowsTickMarkValuesOnly = flag;
}
- (void) setNumberOfTickMarks: (int)numberOfTickMarks;
{
_numberOfTickMarks = numberOfTickMarks;
}
- (void) setTickMarkPosition: (NSTickMarkPosition)position;
{
_tickMarkPosition = position;
}
- (NSTickMarkPosition) tickMarkPosition;
{
return _tickMarkPosition;
}
- (double) tickMarkValueAtIndex: (int)index;
{
if (index >= _numberOfTickMarks)
return _maxValue;
if (index <= 0)
return _minValue;
return _minValue + index * (_maxValue - _minValue) / _numberOfTickMarks;
}
- (id) initWithCoder: (NSCoder*)decoder
{
self = [super initWithCoder: decoder];