Tidied and fixed a couple of bugs

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3969 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-03-24 09:21:06 +00:00
parent 1ffeed382e
commit b3ffbb9eb1
2 changed files with 194 additions and 125 deletions

View file

@ -3,7 +3,7 @@
The button cell class The button cell class
Copyright (C) 1996 Free Software Foundation, Inc. Copyright (C) 1996-1999 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com> Author: Scott Christley <scottc@net-community.com>
Ovidiu Predescu <ovidiu@net-community.com> Ovidiu Predescu <ovidiu@net-community.com>
@ -11,6 +11,8 @@
Author: Felipe A. Rodriguez <far@ix.netcom.com> Author: Felipe A. Rodriguez <far@ix.netcom.com>
Date: August 1998 Date: August 1998
Modified: Richard Frith-Macdonald <richard@brainstorm.co.uk>
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
@ -53,16 +55,16 @@
// //
// Class methods // Class methods
// //
+ (void)initialize + (void) initialize
{ {
if (self == [NSButtonCell class]) if (self == [NSButtonCell class])
[self setVersion:1]; // Initial version [self setVersion: 1];
} }
// //
// Instance methods // Instance methods
// //
- _init - (id) _init
{ {
cell_enabled = YES; cell_enabled = YES;
transparent = NO; transparent = NO;
@ -76,25 +78,25 @@
return self; return self;
} }
- init - (id) init
{ {
[self initTextCell:@"Button"]; [self initTextCell: @"Button"];
return self; return self;
} }
- initImageCell:(NSImage *)anImage - (id) initImageCell: (NSImage *)anImage
{ {
[super initImageCell:anImage]; [super initImageCell: anImage];
contents = nil; contents = nil;
return [self _init]; return [self _init];
} }
- initTextCell:(NSString *)aString - (id) initTextCell: (NSString *)aString
{ {
[super initTextCell:aString]; [super initTextCell: aString];
return [self _init]; return [self _init];
} }
@ -112,33 +114,55 @@
// //
// Setting the Titles // Setting the Titles
// //
- (NSString *)title { return [self stringValue]; } - (NSString *) title
- (NSString *)alternateTitle { return altContents; }
- (void)setFont:(NSFont *)fontObject { [super setFont:fontObject]; }
- (void)setTitle:(NSString *)aString
{ {
[self setStringValue:aString]; return [self stringValue];
[self setState:[self state]]; // update our state
} }
- (void)setAlternateTitle:(NSString *)aString - (NSString *) alternateTitle
{
return altContents;
}
- (void) setFont: (NSFont *)fontObject
{
[super setFont: fontObject];
}
- (void) setTitle: (NSString *)aString
{
[self setStringValue: aString];
[self setState: [self state]];
}
- (void) setAlternateTitle: (NSString *)aString
{ {
NSString* _string = [aString copy]; NSString* _string = [aString copy];
ASSIGN(altContents, _string); ASSIGN(altContents, _string);
[_string release]; [_string release];
[self setState:[self state]]; // update our state [self setState: [self state]];
} }
// //
// Setting the Images // Setting the Images
// //
- (NSImage *)alternateImage { return altImage; } - (NSImage *) alternateImage
- (NSCellImagePosition)imagePosition { return image_position; } {
- (void)setAlternateImage:(NSImage *)anImage { ASSIGN(altImage, anImage); } return altImage;
}
- (void)setImagePosition:(NSCellImagePosition)aPosition - (NSCellImagePosition) imagePosition
{
return image_position;
}
- (void) setAlternateImage: (NSImage *)anImage
{
ASSIGN(altImage, anImage);
}
- (void) setImagePosition: (NSCellImagePosition)aPosition
{ {
image_position = aPosition; image_position = aPosition;
} }
@ -146,17 +170,17 @@
// //
// Setting the Repeat Interval // Setting the Repeat Interval
// //
- (void)getPeriodicDelay:(float *)delay interval:(float *)interval - (void) getPeriodicDelay: (float *)delay interval: (float *)interval
{ {
*delay = delayInterval; *delay = delayInterval;
*interval = repeatInterval; *interval = repeatInterval;
} }
- (void)setPeriodicDelay:(float)delay interval:(float)interval - (void) setPeriodicDelay: (float)delay interval: (float)interval
{ {
delayInterval = delay; delayInterval = delay;
repeatInterval = interval; repeatInterval = interval;
[self setContinuous:YES]; [self setContinuous: YES];
} }
- (void) performClick: (id)sender - (void) performClick: (id)sender
@ -225,10 +249,17 @@
// //
// Modifying Graphic Attributes // Modifying Graphic Attributes
// //
- (BOOL)isTransparent { return transparent; } - (BOOL) isTransparent
- (void)setTransparent:(BOOL)flag { transparent = flag; } {
return transparent;
}
- (BOOL)isOpaque - (void) setTransparent: (BOOL)flag
{
transparent = flag;
}
- (BOOL) isOpaque
{ {
return !transparent && [self isBordered]; return !transparent && [self isBordered];
} }
@ -236,80 +267,118 @@
// //
// Modifying Graphic Attributes // Modifying Graphic Attributes
// //
- (int)highlightsBy { return highlightsByMask; } - (int) highlightsBy
- (void)setHighlightsBy:(int)mask { highlightsByMask = mask; }
- (void)setShowsStateBy:(int)mask { showAltStateMask = mask; }
- (void)setButtonType:(NSButtonType)buttonType
{ {
[super setType:buttonType]; return highlightsByMask;
}
- (void) setHighlightsBy: (int)mask
{
highlightsByMask = mask;
}
- (void) setShowsStateBy: (int)mask
{
showAltStateMask = mask;
}
- (void) setButtonType: (NSButtonType)buttonType
{
[super setType: buttonType];
switch (buttonType) switch (buttonType)
{ {
case NSMomentaryLight: case NSMomentaryLight:
[self setHighlightsBy:NSChangeBackgroundCellMask]; [self setHighlightsBy: NSChangeBackgroundCellMask];
[self setShowsStateBy:NSNoCellMask]; [self setShowsStateBy: NSNoCellMask];
break; break;
case NSMomentaryPushButton: case NSMomentaryPushButton:
[self setHighlightsBy:NSPushInCellMask | NSChangeGrayCellMask]; [self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask];
[self setShowsStateBy:NSNoCellMask]; [self setShowsStateBy: NSNoCellMask];
break; break;
case NSMomentaryChangeButton: case NSMomentaryChangeButton:
[self setHighlightsBy:NSContentsCellMask]; [self setHighlightsBy: NSContentsCellMask];
[self setShowsStateBy:NSNoCellMask]; [self setShowsStateBy: NSNoCellMask];
break; break;
case NSPushOnPushOffButton: case NSPushOnPushOffButton:
[self setHighlightsBy:NSPushInCellMask | NSChangeGrayCellMask]; [self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask];
[self setShowsStateBy:NSChangeBackgroundCellMask]; [self setShowsStateBy: NSChangeBackgroundCellMask];
break; break;
case NSOnOffButton: case NSOnOffButton:
[self setHighlightsBy:NSChangeBackgroundCellMask]; [self setHighlightsBy: NSChangeBackgroundCellMask];
[self setShowsStateBy:NSChangeBackgroundCellMask]; [self setShowsStateBy: NSChangeBackgroundCellMask];
break; break;
case NSToggleButton: case NSToggleButton:
[self setHighlightsBy:NSPushInCellMask | NSContentsCellMask]; [self setHighlightsBy: NSPushInCellMask | NSContentsCellMask];
[self setShowsStateBy:NSContentsCellMask]; [self setShowsStateBy: NSContentsCellMask];
break; break;
case NSSwitchButton: case NSSwitchButton:
[self setHighlightsBy:NSContentsCellMask]; [self setHighlightsBy: NSContentsCellMask];
[self setShowsStateBy:NSContentsCellMask]; [self setShowsStateBy: NSContentsCellMask];
[self setImage:[NSImage imageNamed:@"common_SwitchOff"]]; [self setImage: [NSImage imageNamed: @"common_SwitchOff"]];
[self setAlternateImage:[NSImage imageNamed:@"common_SwitchOn"]]; [self setAlternateImage: [NSImage imageNamed: @"common_SwitchOn"]];
[self setImagePosition:NSImageLeft]; [self setImagePosition: NSImageLeft];
[self setAlignment:NSLeftTextAlignment]; [self setAlignment: NSLeftTextAlignment];
break; break;
case NSRadioButton: case NSRadioButton:
[self setHighlightsBy:NSContentsCellMask]; [self setHighlightsBy: NSContentsCellMask];
[self setShowsStateBy:NSContentsCellMask]; [self setShowsStateBy: NSContentsCellMask];
[self setImage:[NSImage imageNamed:@"common_RadioOff"]]; [self setImage: [NSImage imageNamed: @"common_RadioOff"]];
[self setAlternateImage:[NSImage imageNamed:@"common_RadioOn"]]; [self setAlternateImage: [NSImage imageNamed: @"common_RadioOn"]];
[self setImagePosition:NSImageLeft]; [self setImagePosition: NSImageLeft];
[self setAlignment:NSLeftTextAlignment]; [self setAlignment: NSLeftTextAlignment];
break; break;
} }
// update our state [self setState: [self state]];
[self setState:[self state]];
} }
- (int)showsStateBy { return showAltStateMask; } - (int) showsStateBy
- (void)setIntValue:(int)anInt { [self setState:(anInt != 0)]; } {
- (void)setFloatValue:(float)aFloat { [self setState:(aFloat != 0)]; } return showAltStateMask;
- (void)setDoubleValue:(double)aDouble { [self setState:(aDouble != 0)]; } }
- (int)intValue { return [self state]; }
- (float)floatValue { return [self state]; } - (void) setIntValue: (int)anInt
- (double)doubleValue { return [self state]; } {
[self setState: (anInt != 0)];
}
- (void) setFloatValue: (float)aFloat
{
[self setState: (aFloat != 0)];
}
- (void) setDoubleValue: (double)aDouble
{
[self setState: (aDouble != 0)];
}
- (int) intValue
{
return [self state];
}
- (float) floatValue
{
return [self state];
}
- (double) doubleValue
{
return [self state];
}
// //
// Displaying // Displaying
// //
- (NSColor *)textColor - (NSColor *) textColor
{ {
if ([self isEnabled] == NO)
return [NSColor disabledControlTextColor];
if (([self state] && ([self showsStateBy] & NSChangeGrayCellMask)) if (([self state] && ([self showsStateBy] & NSChangeGrayCellMask))
|| ([self isHighlighted] && ([self highlightsBy] & NSChangeGrayCellMask))) || ([self isHighlighted] && ([self highlightsBy] & NSChangeGrayCellMask)))
return [NSColor lightGrayColor]; return [NSColor selectedControlTextColor];
return [NSColor blackColor]; return [NSColor controlTextColor];
} }
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView - (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
@ -365,7 +434,7 @@
} }
// set cell's background color // set cell's background color
[[NSColor colorWithCalibratedWhite:backgroundGray alpha:1.0] set]; [[NSColor colorWithCalibratedWhite: backgroundGray alpha: 1.0] set];
NSRectFill(cellFrame); NSRectFill(cellFrame);
// Determine the image and the title that will be // Determine the image and the title that will be
@ -386,7 +455,7 @@
if (!imageToDisplay) if (!imageToDisplay)
imageToDisplay = [self image]; imageToDisplay = [self image];
titleToDisplay = [self alternateTitle]; titleToDisplay = [self alternateTitle];
if (!titleToDisplay) if (titleToDisplay == nil || [titleToDisplay isEqual: @""])
titleToDisplay = [self title]; titleToDisplay = [self title];
} }
else else
@ -432,7 +501,7 @@
rect.origin.y = cellFrame.origin.y; rect.origin.y = cellFrame.origin.y;
rect.size.width = imageSize.width; rect.size.width = imageSize.width;
rect.size.height = cellFrame.size.height; rect.size.height = cellFrame.size.height;
[self _drawImage:imageToDisplay inFrame:rect]; [self _drawImage: imageToDisplay inFrame: rect];
// draw title // draw title
rect.origin = cellFrame.origin; rect.origin = cellFrame.origin;
@ -489,7 +558,7 @@
// //
- (void) encodeWithCoder: (NSCoder*)aCoder - (void) encodeWithCoder: (NSCoder*)aCoder
{ {
[super encodeWithCoder:aCoder]; [super encodeWithCoder: aCoder];
NSDebugLog(@"NSButtonCell: start encoding\n"); NSDebugLog(@"NSButtonCell: start encoding\n");
[aCoder encodeObject: keyEquivalent]; [aCoder encodeObject: keyEquivalent];

View file

@ -541,9 +541,9 @@
- (NSColor*) textColor - (NSColor*) textColor
{ {
if ([self isEnabled]) if ([self isEnabled])
return [NSColor blackColor]; return [NSColor controlTextColor];
else else
return [NSColor darkGrayColor]; return [NSColor disabledControlTextColor];
} }
- (void) _drawText: (NSString *) title inFrame: (NSRect) cellFrame - (void) _drawText: (NSString *) title inFrame: (NSRect) cellFrame