mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
NSStepperCell class : first implementation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10733 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ab5209f426
commit
f17d36556d
2 changed files with 473 additions and 0 deletions
78
Headers/gnustep/gui/NSStepperCell.h
Normal file
78
Headers/gnustep/gui/NSStepperCell.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
NSStepperCell.h
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
|
||||
Date: 2001
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef _GNUstep_H_NSStepperCell
|
||||
#define _GNUstep_H_NSStepperCell
|
||||
|
||||
#include <AppKit/NSActionCell.h>
|
||||
|
||||
|
||||
@interface NSStepperCell : NSActionCell <NSCoding>
|
||||
{
|
||||
// Think of the following ones as of two BOOL ivars
|
||||
#define _autorepeat _cell.subclass_bool_one
|
||||
#define _valueWraps _cell.subclass_bool_two
|
||||
|
||||
double _maxValue;
|
||||
double _minValue;
|
||||
double _increment;
|
||||
BOOL highlightUp;
|
||||
BOOL highlightDown;
|
||||
}
|
||||
|
||||
- (double)maxValue;
|
||||
- (void)setMaxValue: (double)maxValue;
|
||||
- (double)minValue;
|
||||
- (void)setMinValue: (double)minValue;
|
||||
- (double)increment;
|
||||
- (void)setIncrement: (double)increment;
|
||||
|
||||
|
||||
- (BOOL)autorepeat;
|
||||
- (void)setAutorepeat: (BOOL)autorepeat;
|
||||
- (BOOL)valueWraps;
|
||||
- (void)setValueWraps: (BOOL)valueWraps;
|
||||
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder:aCoder;
|
||||
- initWithCoder:aDecoder;
|
||||
|
||||
@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
|
395
Source/NSStepperCell.m
Normal file
395
Source/NSStepperCell.m
Normal file
|
@ -0,0 +1,395 @@
|
|||
/*
|
||||
NSStepperCell.m
|
||||
|
||||
Copyright (C) 2001 Free Software Foundation, Inc.
|
||||
|
||||
Author: Pierre-Yves Rivaille <pyrivail@ens-lyon.fr>
|
||||
Date: 2001
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <gnustep/gui/config.h>
|
||||
#include <AppKit/NSGraphicsContext.h>
|
||||
#include <AppKit/NSColor.h>
|
||||
#include <AppKit/DPSOperators.h>
|
||||
#include <AppKit/PSOperators.h>
|
||||
#include <AppKit/NSFont.h>
|
||||
#include <AppKit/NSGraphics.h>
|
||||
#include <AppKit/NSStepperCell.h>
|
||||
#include <AppKit/NSText.h>
|
||||
|
||||
@implementation NSStepperCell
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSStepperCell class])
|
||||
{
|
||||
[self setVersion: 1];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Initialization
|
||||
//
|
||||
- (id) init
|
||||
{
|
||||
[self initTextCell: @"0"];
|
||||
[super setAlignment: NSRightTextAlignment];
|
||||
[super setWraps: NO];
|
||||
_autorepeat = YES;
|
||||
_valueWraps = YES;
|
||||
_maxValue = 59;
|
||||
_minValue = 0;
|
||||
_increment = 1;
|
||||
highlightUp = NO;
|
||||
highlightDown = NO;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) initTextCell: (NSString *)aString
|
||||
{
|
||||
[super initTextCell: aString];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (double) maxValue
|
||||
{
|
||||
return _maxValue;
|
||||
}
|
||||
|
||||
- (void) setMaxValue: (double)newMaxValue
|
||||
{
|
||||
_maxValue = newMaxValue;
|
||||
}
|
||||
|
||||
- (double) minValue
|
||||
{
|
||||
return _minValue;
|
||||
}
|
||||
|
||||
- (void) setMinValue: (double)newMinValue
|
||||
{
|
||||
_minValue = newMinValue;
|
||||
}
|
||||
|
||||
- (double) increment
|
||||
{
|
||||
return _increment;
|
||||
}
|
||||
|
||||
- (void) setIncrement: (double)newIncrement
|
||||
{
|
||||
_increment = newIncrement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (BOOL)autorepeat
|
||||
{
|
||||
return _autorepeat;
|
||||
}
|
||||
|
||||
- (void)setAutorepeat: (BOOL)newAutorepeat
|
||||
{
|
||||
_autorepeat = newAutorepeat;
|
||||
}
|
||||
|
||||
- (BOOL)valueWraps
|
||||
{
|
||||
return _valueWraps;
|
||||
}
|
||||
|
||||
- (void)setValueWraps: (BOOL)newValueWraps
|
||||
{
|
||||
_valueWraps = newValueWraps;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)zone
|
||||
{
|
||||
NSStepperCell *c = [super copyWithZone: zone];
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
inline void DrawUpButton(NSRect aRect)
|
||||
{
|
||||
NSRectEdge up_sides[] = {NSMinXEdge, NSMaxYEdge,
|
||||
NSMaxXEdge, NSMinYEdge};
|
||||
float grays[] = {NSWhite, NSWhite,
|
||||
NSDarkGray, NSDarkGray};
|
||||
NSRect rect;
|
||||
NSGraphicsContext *ctxt;
|
||||
ctxt = GSCurrentContext();
|
||||
|
||||
rect = NSDrawTiledRects(aRect, NSZeroRect,
|
||||
up_sides, grays, 4);
|
||||
DPSsetgray(ctxt, NSLightGray);
|
||||
DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
|
||||
NSWidth(rect), NSHeight(rect));
|
||||
|
||||
PSsetgray(NSDarkGray);
|
||||
PSmoveto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
||||
PSlineto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
||||
PSstroke();
|
||||
PSsetgray(NSBlack);
|
||||
PSmoveto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
||||
PSlineto(NSMaxX(aRect) - 11, NSMinY(aRect) + 4);
|
||||
PSstroke();
|
||||
PSsetgray(NSWhite);
|
||||
PSmoveto(NSMaxX(aRect) - 11, NSMinY(aRect) + 3);
|
||||
PSlineto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
||||
PSstroke();
|
||||
}
|
||||
|
||||
inline void HighlightUpButton(NSRect aRect)
|
||||
{
|
||||
NSRectEdge up_sides[] = {NSMinXEdge, NSMaxYEdge,
|
||||
NSMaxXEdge, NSMinYEdge};
|
||||
float grays[] = {NSWhite, NSWhite,
|
||||
NSDarkGray, NSDarkGray};
|
||||
NSRect rect;
|
||||
NSGraphicsContext *ctxt;
|
||||
ctxt = GSCurrentContext();
|
||||
|
||||
rect = NSDrawTiledRects(aRect, NSZeroRect,
|
||||
up_sides, grays, 4);
|
||||
DPSsetgray(ctxt, NSWhite);
|
||||
DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
|
||||
NSWidth(rect), NSHeight(rect));
|
||||
|
||||
PSsetgray(NSLightGray);
|
||||
PSmoveto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
||||
PSlineto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
||||
PSstroke();
|
||||
PSsetgray(NSBlack);
|
||||
PSmoveto(NSMaxX(aRect) - 8, NSMinY(aRect) + 9);
|
||||
PSlineto(NSMaxX(aRect) - 11, NSMinY(aRect) + 4);
|
||||
PSstroke();
|
||||
PSsetgray(NSLightGray);
|
||||
PSmoveto(NSMaxX(aRect) - 11, NSMinY(aRect) + 3);
|
||||
PSlineto(NSMaxX(aRect) - 5, NSMinY(aRect) + 3);
|
||||
PSstroke();
|
||||
}
|
||||
|
||||
inline void DrawDownButton(NSRect aRect)
|
||||
{
|
||||
NSRectEdge up_sides[] = {NSMinXEdge, NSMaxYEdge,
|
||||
NSMaxXEdge, NSMinYEdge};
|
||||
float grays[] = {NSWhite, NSWhite,
|
||||
NSDarkGray, NSDarkGray};
|
||||
NSRect rect;
|
||||
NSGraphicsContext *ctxt;
|
||||
ctxt = GSCurrentContext();
|
||||
|
||||
rect = NSDrawTiledRects(aRect, NSZeroRect,
|
||||
up_sides, grays, 4);
|
||||
DPSsetgray(ctxt, NSLightGray);
|
||||
DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
|
||||
NSWidth(rect), NSHeight(rect));
|
||||
|
||||
PSsetlinewidth(1.0);
|
||||
PSsetgray(NSDarkGray);
|
||||
PSmoveto(NSMinX(aRect) + 4, NSMaxY(aRect) - 3);
|
||||
PSlineto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
||||
PSstroke();
|
||||
PSsetgray(NSWhite);
|
||||
PSmoveto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
||||
PSlineto(NSMinX(aRect) + 10, NSMaxY(aRect) - 3);
|
||||
PSstroke();
|
||||
PSsetgray(NSBlack);
|
||||
PSmoveto(NSMinX(aRect) + 10, NSMaxY(aRect) - 2);
|
||||
PSlineto(NSMinX(aRect) + 4, NSMaxY(aRect) - 2);
|
||||
PSstroke();
|
||||
}
|
||||
|
||||
inline void HighlightDownButton(NSRect aRect)
|
||||
{
|
||||
NSRectEdge up_sides[] = {NSMinXEdge, NSMaxYEdge,
|
||||
NSMaxXEdge, NSMinYEdge};
|
||||
float grays[] = {NSWhite, NSWhite,
|
||||
NSDarkGray, NSDarkGray};
|
||||
NSRect rect;
|
||||
NSGraphicsContext *ctxt;
|
||||
ctxt = GSCurrentContext();
|
||||
|
||||
rect = NSDrawTiledRects(aRect, NSZeroRect,
|
||||
up_sides, grays, 4);
|
||||
DPSsetgray(ctxt, NSWhite);
|
||||
DPSrectfill(ctxt, NSMinX(rect), NSMinY(rect),
|
||||
NSWidth(rect), NSHeight(rect));
|
||||
|
||||
PSsetlinewidth(1.0);
|
||||
PSsetgray(NSLightGray);
|
||||
PSmoveto(NSMinX(aRect) + 4, NSMaxY(aRect) - 3);
|
||||
PSlineto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
||||
PSstroke();
|
||||
PSsetgray(NSLightGray);
|
||||
PSmoveto(NSMinX(aRect) + 7, NSMaxY(aRect) - 8);
|
||||
PSlineto(NSMinX(aRect) + 10, NSMaxY(aRect) - 3);
|
||||
PSstroke();
|
||||
PSsetgray(NSBlack);
|
||||
PSmoveto(NSMinX(aRect) + 10, NSMaxY(aRect) - 2);
|
||||
PSlineto(NSMinX(aRect) + 4, NSMaxY(aRect) - 2);
|
||||
PSstroke();
|
||||
}
|
||||
|
||||
- (void)_drawText: (NSRect)aRect
|
||||
{
|
||||
NSDrawWhiteBezel(aRect, NSZeroRect);
|
||||
aRect.size.width -= 6;
|
||||
aRect.size.height -= 4;
|
||||
aRect.origin.x += 3;
|
||||
aRect.origin.y += 2;
|
||||
[super _drawText: _contents inFrame: aRect];
|
||||
}
|
||||
|
||||
- (void) drawInteriorWithFrame: (NSRect)cellFrame
|
||||
inView: (NSView*)controlView
|
||||
{
|
||||
NSRect textFrame;
|
||||
NSRect upRect;
|
||||
NSRect downRect;
|
||||
NSRect twoButtons;
|
||||
NSGraphicsContext *ctxt;
|
||||
[controlView lockFocus];
|
||||
ctxt = GSCurrentContext();
|
||||
textFrame = cellFrame;
|
||||
textFrame.origin.y ++;
|
||||
textFrame.size.height -= 2;
|
||||
textFrame.size.width -= 18;
|
||||
|
||||
{
|
||||
upRect = [self upButtonRectWithFrame: cellFrame];
|
||||
downRect = [self downButtonRectWithFrame: cellFrame];
|
||||
|
||||
twoButtons = downRect;
|
||||
twoButtons.origin.y--;
|
||||
twoButtons.size.width++;
|
||||
twoButtons.size.height = 23;
|
||||
|
||||
if (highlightUp)
|
||||
HighlightUpButton(upRect);
|
||||
else
|
||||
DrawUpButton(upRect);
|
||||
|
||||
if (highlightDown)
|
||||
HighlightDownButton(downRect);
|
||||
else
|
||||
DrawDownButton(downRect);
|
||||
|
||||
{
|
||||
NSRectEdge up_sides[] = {NSMaxXEdge, NSMinYEdge};
|
||||
float grays[] = {NSBlack, NSBlack};
|
||||
|
||||
NSDrawTiledRects(twoButtons, NSZeroRect,
|
||||
up_sides, grays, 2);
|
||||
}
|
||||
}
|
||||
|
||||
[self _drawText: textFrame];
|
||||
[controlView unlockFocus];
|
||||
}
|
||||
|
||||
- (void) highlight: (BOOL) highlight
|
||||
upButton: (BOOL) upButton
|
||||
withFrame: (NSRect) frame
|
||||
inView: (NSView*) controlView
|
||||
{
|
||||
NSRect upRect;
|
||||
NSRect downRect;
|
||||
NSGraphicsContext *ctxt;
|
||||
[controlView lockFocus];
|
||||
ctxt = GSCurrentContext();
|
||||
{
|
||||
upRect = [self upButtonRectWithFrame: frame];
|
||||
downRect = [self downButtonRectWithFrame: frame];
|
||||
if (upButton)
|
||||
{
|
||||
highlightUp = highlight;
|
||||
if (highlightUp)
|
||||
HighlightUpButton(upRect);
|
||||
else
|
||||
DrawUpButton(upRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
highlightDown = highlight;
|
||||
if (highlightDown)
|
||||
HighlightDownButton(downRect);
|
||||
else
|
||||
DrawDownButton(downRect);
|
||||
}
|
||||
}
|
||||
[controlView unlockFocus];
|
||||
}
|
||||
|
||||
- (NSRect) upButtonRectWithFrame: (NSRect) frame
|
||||
{
|
||||
NSRect upRect;
|
||||
upRect.size.width = 15;
|
||||
upRect.size.height = 11;
|
||||
upRect.origin.x = NSMaxX(frame) - 16;
|
||||
upRect.origin.y = NSMinY(frame) + ((int) frame.size.height / 2) + 1;
|
||||
return upRect;
|
||||
}
|
||||
|
||||
- (NSRect) downButtonRectWithFrame: (NSRect) frame
|
||||
{
|
||||
NSRect downRect;
|
||||
downRect.size.width = 15;
|
||||
downRect.size.height = 11;
|
||||
downRect.origin.x = NSMaxX(frame) - 16;
|
||||
downRect.origin.y = NSMinY(frame) +
|
||||
((int) frame.size.height / 2) - 10;
|
||||
return downRect;
|
||||
}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void) encodeWithCoder: (NSCoder*)aCoder
|
||||
{
|
||||
BOOL tmp1, tmp2;
|
||||
[super encodeWithCoder: aCoder];
|
||||
tmp1 = _autorepeat;
|
||||
tmp2 = _valueWraps;
|
||||
[aCoder encodeValuesOfObjCTypes: "dddii",
|
||||
&_maxValue, &_minValue, &_increment, &tmp1, &tmp2];
|
||||
}
|
||||
|
||||
- (id) initWithCoder: (NSCoder*)aDecoder
|
||||
{
|
||||
BOOL tmp1, tmp2;
|
||||
[super initWithCoder: aDecoder];
|
||||
[aDecoder decodeValuesOfObjCTypes: "dddii",
|
||||
&_maxValue, &_minValue, &_increment, &tmp1, &tmp2];
|
||||
_autorepeat = tmp1;
|
||||
_valueWraps = tmp2;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in a new issue