1999-03-02 08:58:30 +00:00
|
|
|
/*
|
1996-05-30 20:03:15 +00:00
|
|
|
NSButtonCell.m
|
|
|
|
|
|
|
|
The button cell class
|
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
Copyright (C) 1996-1999 Free Software Foundation, Inc.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
1998-11-25 17:16:48 +00:00
|
|
|
Ovidiu Predescu <ovidiu@net-community.com>
|
1996-05-30 20:03:15 +00:00
|
|
|
Date: 1996
|
1998-08-30 16:06:47 +00:00
|
|
|
Author: Felipe A. Rodriguez <far@ix.netcom.com>
|
|
|
|
Date: August 1998
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
Modified: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
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.
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
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
|
1996-10-18 17:14:13 +00:00
|
|
|
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.
|
1999-03-02 08:58:30 +00:00
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
#include <gnustep/gui/config.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
#include <Foundation/NSLock.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
1997-08-18 17:10:23 +00:00
|
|
|
#include <Foundation/NSString.h>
|
1998-12-15 16:20:22 +00:00
|
|
|
#include <Foundation/NSException.h>
|
1997-08-18 17:10:23 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSButtonCell.h>
|
|
|
|
#include <AppKit/NSButton.h>
|
|
|
|
#include <AppKit/NSWindow.h>
|
|
|
|
#include <AppKit/NSEvent.h>
|
|
|
|
#include <AppKit/NSApplication.h>
|
|
|
|
#include <AppKit/NSFont.h>
|
|
|
|
#include <AppKit/NSImage.h>
|
1999-02-15 12:50:49 +00:00
|
|
|
#include <AppKit/NSColor.h>
|
1999-02-15 19:35:02 +00:00
|
|
|
#include <AppKit/NSGraphics.h>
|
1999-02-25 15:45:22 +00:00
|
|
|
#include <AppKit/PSOperators.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSButtonCell
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
1999-03-24 09:21:06 +00:00
|
|
|
+ (void) initialize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
if (self == [NSButtonCell class])
|
|
|
|
[self setVersion: 1];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
1999-03-24 09:21:06 +00:00
|
|
|
- (id) _init
|
1998-08-30 16:06:47 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
cell_enabled = YES;
|
|
|
|
transparent = NO;
|
|
|
|
cell_bordered = YES;
|
|
|
|
showAltStateMask = NSNoCellMask; // configure as a NSMomentaryPushButton
|
|
|
|
highlightsByMask = NSPushInCellMask | NSChangeGrayCellMask;
|
|
|
|
delayInterval = 0.4;
|
|
|
|
repeatInterval = 0.075;
|
|
|
|
altContents = nil;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
return self;
|
1998-08-30 16:06:47 +00:00
|
|
|
}
|
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (id) init
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
[self initTextCell: @"Button"];
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (id) initImageCell: (NSImage *)anImage
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
[super initImageCell: anImage];
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
contents = nil;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
return [self _init];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (id) initTextCell: (NSString *)aString
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
[super initTextCell: aString];
|
1999-03-02 08:58:30 +00:00
|
|
|
|
|
|
|
return [self _init];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (void) dealloc
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[altContents release];
|
|
|
|
[altImage release];
|
|
|
|
[keyEquivalent release];
|
|
|
|
[keyEquivalentFont release];
|
|
|
|
|
|
|
|
[super dealloc];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-03-02 08:58:30 +00:00
|
|
|
// Setting the Titles
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1999-03-24 09:21:06 +00:00
|
|
|
- (NSString *) title
|
|
|
|
{
|
|
|
|
return [self stringValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *) alternateTitle
|
|
|
|
{
|
|
|
|
return altContents;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFont: (NSFont *)fontObject
|
|
|
|
{
|
|
|
|
[super setFont: fontObject];
|
|
|
|
}
|
1998-11-25 17:16:48 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (void) setTitle: (NSString *)aString
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
[self setStringValue: aString];
|
|
|
|
[self setState: [self state]];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (void) setAlternateTitle: (NSString *)aString
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-02-15 12:50:49 +00:00
|
|
|
NSString* _string = [aString copy];
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1999-02-15 12:50:49 +00:00
|
|
|
ASSIGN(altContents, _string);
|
|
|
|
[_string release];
|
1999-03-24 09:21:06 +00:00
|
|
|
[self setState: [self state]];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-03-02 08:58:30 +00:00
|
|
|
// Setting the Images
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1999-03-24 09:21:06 +00:00
|
|
|
- (NSImage *) alternateImage
|
|
|
|
{
|
|
|
|
return altImage;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCellImagePosition) imagePosition
|
|
|
|
{
|
|
|
|
return image_position;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (void) setAlternateImage: (NSImage *)anImage
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
ASSIGN(altImage, anImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setImagePosition: (NSCellImagePosition)aPosition
|
|
|
|
{
|
|
|
|
image_position = aPosition;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
1999-03-02 08:58:30 +00:00
|
|
|
// Setting the Repeat Interval
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1999-03-24 09:21:06 +00:00
|
|
|
- (void) getPeriodicDelay: (float *)delay interval: (float *)interval
|
1997-08-05 21:50:10 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
*delay = delayInterval;
|
|
|
|
*interval = repeatInterval;
|
1997-08-05 21:50:10 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (void) setPeriodicDelay: (float)delay interval: (float)interval
|
1997-08-05 21:50:10 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
delayInterval = delay;
|
|
|
|
repeatInterval = interval;
|
|
|
|
[self setContinuous: YES];
|
1997-08-05 21:50:10 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-03-02 08:58:30 +00:00
|
|
|
// Setting the Key Equivalent
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1998-12-15 16:20:22 +00:00
|
|
|
- (NSString*) keyEquivalent
|
|
|
|
{
|
|
|
|
return keyEquivalent;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-15 16:20:22 +00:00
|
|
|
- (NSFont*) keyEquivalentFont
|
|
|
|
{
|
|
|
|
return keyEquivalentFont;
|
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (unsigned int) keyEquivalentModifierMask
|
|
|
|
{
|
1998-12-15 16:20:22 +00:00
|
|
|
return keyEquivalentModifierMask;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (void) setKeyEquivalent: (NSString*)key
|
|
|
|
{
|
1998-12-15 16:20:22 +00:00
|
|
|
if (keyEquivalent != key)
|
|
|
|
{
|
|
|
|
[keyEquivalent release];
|
|
|
|
keyEquivalent = [key copy];
|
|
|
|
}
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-15 16:20:22 +00:00
|
|
|
- (void) setKeyEquivalentModifierMask: (unsigned int)mask
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
1998-12-15 16:20:22 +00:00
|
|
|
keyEquivalentModifierMask = mask;
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-15 16:20:22 +00:00
|
|
|
- (void) setKeyEquivalentFont: (NSFont*)fontObj
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
1998-12-15 16:20:22 +00:00
|
|
|
ASSIGN(keyEquivalentFont, fontObj);
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-12-15 16:20:22 +00:00
|
|
|
- (void) setKeyEquivalentFont: (NSString*)fontName size: (float)fontSize
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
1998-12-15 16:20:22 +00:00
|
|
|
ASSIGN(keyEquivalentFont, [NSFont fontWithName: fontName size: fontSize]);
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
1999-03-02 08:58:30 +00:00
|
|
|
// Modifying Graphic Attributes
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1999-03-24 09:21:06 +00:00
|
|
|
- (BOOL) isTransparent
|
|
|
|
{
|
|
|
|
return transparent;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (void) setTransparent: (BOOL)flag
|
|
|
|
{
|
|
|
|
transparent = flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isOpaque
|
1999-03-02 08:58:30 +00:00
|
|
|
{
|
|
|
|
return !transparent && [self isBordered];
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1999-03-02 08:58:30 +00:00
|
|
|
// Modifying Graphic Attributes
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
1999-03-24 09:21:06 +00:00
|
|
|
- (int) highlightsBy
|
|
|
|
{
|
|
|
|
return highlightsByMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setHighlightsBy: (int)mask
|
|
|
|
{
|
|
|
|
highlightsByMask = mask;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (void) setShowsStateBy: (int)mask
|
|
|
|
{
|
|
|
|
showAltStateMask = mask;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (void) setButtonType: (NSButtonType)buttonType
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
[super setType: buttonType];
|
1997-02-18 00:29:25 +00:00
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
switch (buttonType)
|
1999-03-24 09:21:06 +00:00
|
|
|
{
|
|
|
|
case NSMomentaryLight:
|
|
|
|
[self setHighlightsBy: NSChangeBackgroundCellMask];
|
|
|
|
[self setShowsStateBy: NSNoCellMask];
|
|
|
|
break;
|
|
|
|
case NSMomentaryPushButton:
|
|
|
|
[self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask];
|
|
|
|
[self setShowsStateBy: NSNoCellMask];
|
|
|
|
break;
|
|
|
|
case NSMomentaryChangeButton:
|
|
|
|
[self setHighlightsBy: NSContentsCellMask];
|
|
|
|
[self setShowsStateBy: NSNoCellMask];
|
|
|
|
break;
|
|
|
|
case NSPushOnPushOffButton:
|
|
|
|
[self setHighlightsBy: NSPushInCellMask | NSChangeGrayCellMask];
|
|
|
|
[self setShowsStateBy: NSChangeBackgroundCellMask];
|
|
|
|
break;
|
|
|
|
case NSOnOffButton:
|
|
|
|
[self setHighlightsBy: NSChangeBackgroundCellMask];
|
|
|
|
[self setShowsStateBy: NSChangeBackgroundCellMask];
|
|
|
|
break;
|
|
|
|
case NSToggleButton:
|
|
|
|
[self setHighlightsBy: NSPushInCellMask | NSContentsCellMask];
|
|
|
|
[self setShowsStateBy: NSContentsCellMask];
|
|
|
|
break;
|
|
|
|
case NSSwitchButton:
|
|
|
|
[self setHighlightsBy: NSContentsCellMask];
|
|
|
|
[self setShowsStateBy: NSContentsCellMask];
|
|
|
|
[self setImage: [NSImage imageNamed: @"common_SwitchOff"]];
|
|
|
|
[self setAlternateImage: [NSImage imageNamed: @"common_SwitchOn"]];
|
|
|
|
[self setImagePosition: NSImageLeft];
|
|
|
|
[self setAlignment: NSLeftTextAlignment];
|
|
|
|
break;
|
|
|
|
case NSRadioButton:
|
|
|
|
[self setHighlightsBy: NSContentsCellMask];
|
|
|
|
[self setShowsStateBy: NSContentsCellMask];
|
|
|
|
[self setImage: [NSImage imageNamed: @"common_RadioOff"]];
|
|
|
|
[self setAlternateImage: [NSImage imageNamed: @"common_RadioOn"]];
|
|
|
|
[self setImagePosition: NSImageLeft];
|
|
|
|
[self setAlignment: NSLeftTextAlignment];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setState: [self state]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int) showsStateBy
|
|
|
|
{
|
|
|
|
return showAltStateMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setIntValue: (int)anInt
|
|
|
|
{
|
|
|
|
[self setState: (anInt != 0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setFloatValue: (float)aFloat
|
|
|
|
{
|
|
|
|
[self setState: (aFloat != 0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setDoubleValue: (double)aDouble
|
|
|
|
{
|
|
|
|
[self setState: (aDouble != 0)];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (int) intValue
|
|
|
|
{
|
|
|
|
return [self state];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
- (float) floatValue
|
|
|
|
{
|
|
|
|
return [self state];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (double) doubleValue
|
|
|
|
{
|
|
|
|
return [self state];
|
|
|
|
}
|
1997-02-18 00:29:25 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Displaying
|
|
|
|
//
|
1999-03-24 09:21:06 +00:00
|
|
|
- (NSColor *) textColor
|
1999-02-15 12:50:49 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
if ([self isEnabled] == NO)
|
|
|
|
return [NSColor disabledControlTextColor];
|
1999-02-15 12:50:49 +00:00
|
|
|
if (([self state] && ([self showsStateBy] & NSChangeGrayCellMask))
|
1999-03-02 08:58:30 +00:00
|
|
|
|| ([self isHighlighted] && ([self highlightsBy] & NSChangeGrayCellMask)))
|
1999-03-24 09:21:06 +00:00
|
|
|
return [NSColor selectedControlTextColor];
|
|
|
|
return [NSColor controlTextColor];
|
1999-02-15 12:50:49 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
// Save last view drawn to
|
|
|
|
[self setControlView: controlView];
|
1999-02-15 12:50:49 +00:00
|
|
|
|
1999-05-03 17:31:11 +00:00
|
|
|
// transparent buttons never draw
|
|
|
|
if ([self isTransparent])
|
|
|
|
return;
|
|
|
|
|
1999-02-15 12:50:49 +00:00
|
|
|
// do nothing if cell's frame rect is zero
|
|
|
|
if (NSIsEmptyRect(cellFrame))
|
|
|
|
return;
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
// draw the border if needed
|
|
|
|
if ([self isBordered])
|
|
|
|
{
|
1999-09-21 05:10:54 +00:00
|
|
|
[controlView lockFocus];
|
1999-03-02 08:58:30 +00:00
|
|
|
if ([self isHighlighted] && ([self highlightsBy] & NSPushInCellMask))
|
|
|
|
{
|
1999-05-13 13:51:57 +00:00
|
|
|
NSDrawGrayBezel(cellFrame, NSZeroRect);
|
1999-03-02 08:58:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-05-13 13:51:57 +00:00
|
|
|
NSDrawButton(cellFrame, NSZeroRect);
|
1999-03-02 08:58:30 +00:00
|
|
|
}
|
1999-09-21 05:10:54 +00:00
|
|
|
[controlView unlockFocus];
|
1999-03-02 08:58:30 +00:00
|
|
|
}
|
1999-02-15 12:50:49 +00:00
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
[self drawInteriorWithFrame: cellFrame inView: controlView];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
|
|
|
|
{
|
|
|
|
BOOL showAlternate = NO;
|
|
|
|
unsigned mask;
|
|
|
|
NSImage *imageToDisplay;
|
1999-09-11 10:08:56 +00:00
|
|
|
NSRect imageRect;
|
1999-03-02 08:58:30 +00:00
|
|
|
NSString *titleToDisplay;
|
1999-09-11 10:08:56 +00:00
|
|
|
NSRect titleRect;
|
1999-03-02 08:58:30 +00:00
|
|
|
NSSize imageSize = {0, 0};
|
1999-05-03 17:31:11 +00:00
|
|
|
NSColor *backgroundColor = nil;
|
|
|
|
|
|
|
|
// transparent buttons never draw
|
|
|
|
if ([self isTransparent])
|
|
|
|
return;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-09-11 05:25:53 +00:00
|
|
|
cellFrame = [self drawingRectForBounds: cellFrame];
|
1999-09-21 05:10:54 +00:00
|
|
|
[controlView lockFocus];
|
1999-02-15 12:50:49 +00:00
|
|
|
|
1999-09-14 01:45:58 +00:00
|
|
|
// pushed in buttons contents are displaced to the bottom right 1px
|
|
|
|
if ([self isBordered] && [self isHighlighted]
|
|
|
|
&& ([self highlightsBy] & NSPushInCellMask))
|
|
|
|
cellFrame = NSOffsetRect (cellFrame,
|
|
|
|
1., [control_view isFlipped] ? 1. : -1.);
|
|
|
|
|
1999-02-15 12:50:49 +00:00
|
|
|
// determine the background color
|
|
|
|
if ([self state])
|
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
if ( [self showsStateBy]
|
1999-09-11 10:08:56 +00:00
|
|
|
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask) )
|
1999-05-02 18:27:38 +00:00
|
|
|
backgroundColor = [NSColor selectedControlColor];
|
1999-02-15 12:50:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ([self isHighlighted])
|
|
|
|
{
|
|
|
|
if ( [self highlightsBy]
|
1999-09-11 10:08:56 +00:00
|
|
|
& (NSChangeGrayCellMask | NSChangeBackgroundCellMask) )
|
1999-05-02 18:27:38 +00:00
|
|
|
backgroundColor = [NSColor selectedControlColor];
|
1999-02-15 12:50:49 +00:00
|
|
|
}
|
|
|
|
|
1999-05-03 17:31:11 +00:00
|
|
|
if (backgroundColor == nil)
|
|
|
|
backgroundColor = [NSColor controlBackgroundColor];
|
|
|
|
|
1999-02-15 12:50:49 +00:00
|
|
|
// set cell's background color
|
1999-05-02 18:27:38 +00:00
|
|
|
[backgroundColor set];
|
1999-02-15 12:50:49 +00:00
|
|
|
NSRectFill(cellFrame);
|
|
|
|
|
1999-09-11 10:08:56 +00:00
|
|
|
/*
|
|
|
|
* Determine the image and the title that will be
|
|
|
|
* displayed. If the NSContentsCellMask is set the
|
|
|
|
* image and title are swapped only if state is 1 or
|
|
|
|
* if highlighting is set (when a button is pushed it's
|
|
|
|
* content is changed to the face of reversed state).
|
|
|
|
*/
|
1999-02-15 12:50:49 +00:00
|
|
|
if ([self isHighlighted])
|
|
|
|
mask = [self highlightsBy];
|
|
|
|
else
|
|
|
|
mask = [self showsStateBy];
|
1999-03-02 08:58:30 +00:00
|
|
|
if (mask & NSContentsCellMask)
|
|
|
|
showAlternate = [self state];
|
1999-02-15 12:50:49 +00:00
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
if (showAlternate || [self isHighlighted])
|
1999-02-15 12:50:49 +00:00
|
|
|
{
|
|
|
|
imageToDisplay = [self alternateImage];
|
1999-03-02 08:58:30 +00:00
|
|
|
if (!imageToDisplay)
|
|
|
|
imageToDisplay = [self image];
|
1999-02-15 12:50:49 +00:00
|
|
|
titleToDisplay = [self alternateTitle];
|
1999-03-24 09:21:06 +00:00
|
|
|
if (titleToDisplay == nil || [titleToDisplay isEqual: @""])
|
1999-02-15 12:50:49 +00:00
|
|
|
titleToDisplay = [self title];
|
|
|
|
}
|
1999-03-02 08:58:30 +00:00
|
|
|
else
|
1999-02-15 12:50:49 +00:00
|
|
|
{
|
|
|
|
imageToDisplay = [self image];
|
|
|
|
titleToDisplay = [self title];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imageToDisplay)
|
1999-05-02 18:27:38 +00:00
|
|
|
{
|
|
|
|
imageSize = [imageToDisplay size];
|
|
|
|
[imageToDisplay setBackgroundColor: backgroundColor];
|
|
|
|
}
|
1999-03-02 08:58:30 +00:00
|
|
|
|
|
|
|
switch ([self imagePosition])
|
1999-02-15 12:50:49 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
case NSNoImage:
|
1999-09-11 10:08:56 +00:00
|
|
|
imageToDisplay = nil;
|
|
|
|
titleRect = cellFrame;
|
|
|
|
break;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
case NSImageOnly:
|
1999-09-11 10:08:56 +00:00
|
|
|
titleToDisplay = nil;
|
|
|
|
imageRect = cellFrame;
|
|
|
|
break;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
case NSImageLeft:
|
1999-09-11 10:08:56 +00:00
|
|
|
imageRect.origin = cellFrame.origin;
|
|
|
|
imageRect.size.width = imageSize.width;
|
|
|
|
imageRect.size.height = cellFrame.size.height;
|
|
|
|
|
|
|
|
titleRect = imageRect;
|
|
|
|
titleRect.origin.x += imageSize.width + xDist;
|
|
|
|
titleRect.size.width = cellFrame.size.width - imageSize.width - xDist;
|
|
|
|
break;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
case NSImageRight:
|
1999-09-11 10:08:56 +00:00
|
|
|
imageRect.origin.x = NSMaxX(cellFrame) - imageSize.width;
|
|
|
|
imageRect.origin.y = cellFrame.origin.y;
|
|
|
|
imageRect.size.width = imageSize.width;
|
|
|
|
imageRect.size.height = cellFrame.size.height;
|
|
|
|
|
|
|
|
titleRect.origin = cellFrame.origin;
|
|
|
|
titleRect.size.width = cellFrame.size.width - imageSize.width - xDist;
|
|
|
|
titleRect.size.height = cellFrame.size.height;
|
|
|
|
break;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
case NSImageBelow:
|
1999-09-11 10:08:56 +00:00
|
|
|
imageRect = cellFrame;
|
|
|
|
imageRect.size.height /= 2;
|
|
|
|
titleRect = imageRect;
|
|
|
|
titleRect.origin.y += titleRect.size.height;
|
|
|
|
break;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
case NSImageAbove:
|
1999-09-11 10:08:56 +00:00
|
|
|
titleRect = cellFrame;
|
|
|
|
titleRect.size.height /= 2;
|
|
|
|
imageRect = titleRect;
|
|
|
|
imageRect.origin.y += imageRect.size.height;
|
|
|
|
break;
|
1999-03-02 08:58:30 +00:00
|
|
|
|
1999-03-24 09:21:06 +00:00
|
|
|
case NSImageOverlaps:
|
1999-09-11 10:08:56 +00:00
|
|
|
titleRect = cellFrame;
|
|
|
|
imageRect = cellFrame;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (imageToDisplay != nil)
|
|
|
|
{
|
|
|
|
NSSize size;
|
|
|
|
NSPoint position;
|
|
|
|
|
|
|
|
size = [imageToDisplay size];
|
|
|
|
position.x = MAX(NSMidX(imageRect) - (size.width/2.),0.);
|
|
|
|
position.y = MAX(NSMidY(imageRect) - (size.height/2.),0.);
|
|
|
|
/*
|
|
|
|
* Images are always drawn with their bottom-left corner at the origin
|
|
|
|
* so we must adjust the position to take account of a flipped view.
|
|
|
|
*/
|
|
|
|
if ([control_view isFlipped])
|
|
|
|
position.y += size.height;
|
|
|
|
[imageToDisplay compositeToPoint: position operation: NSCompositeCopy];
|
|
|
|
}
|
|
|
|
if (titleToDisplay != nil)
|
|
|
|
{
|
|
|
|
[self _drawText: titleToDisplay inFrame: titleRect];
|
1999-02-15 12:50:49 +00:00
|
|
|
}
|
1999-09-21 05:10:54 +00:00
|
|
|
[controlView unlockFocus];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-09-10 05:18:32 +00:00
|
|
|
- (NSSize) cellSize
|
|
|
|
{
|
|
|
|
NSSize s;
|
|
|
|
NSSize borderSize;
|
|
|
|
BOOL showAlternate = NO;
|
|
|
|
unsigned mask;
|
|
|
|
NSImage *imageToDisplay;
|
|
|
|
NSString *titleToDisplay;
|
|
|
|
NSSize imageSize;
|
|
|
|
NSSize titleSize;
|
|
|
|
|
|
|
|
//
|
|
|
|
// The following code must be kept in sync with -drawInteriorWithFrame
|
|
|
|
//
|
|
|
|
|
|
|
|
if ([self isHighlighted])
|
|
|
|
mask = [self highlightsBy];
|
|
|
|
else
|
|
|
|
mask = [self showsStateBy];
|
|
|
|
if (mask & NSContentsCellMask)
|
|
|
|
showAlternate = [self state];
|
|
|
|
|
|
|
|
if (showAlternate || [self isHighlighted])
|
|
|
|
{
|
|
|
|
imageToDisplay = [self alternateImage];
|
|
|
|
if (!imageToDisplay)
|
|
|
|
imageToDisplay = [self image];
|
|
|
|
titleToDisplay = [self alternateTitle];
|
|
|
|
if (titleToDisplay == nil || [titleToDisplay isEqual: @""])
|
|
|
|
titleToDisplay = [self title];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
imageToDisplay = [self image];
|
|
|
|
titleToDisplay = [self title];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (imageToDisplay)
|
|
|
|
imageSize = [imageToDisplay size];
|
|
|
|
else
|
|
|
|
imageSize = NSZeroSize;
|
|
|
|
|
|
|
|
if (titleToDisplay)
|
|
|
|
titleSize = NSMakeSize ([cell_font widthOfString: titleToDisplay],
|
|
|
|
[cell_font pointSize]);
|
|
|
|
else
|
|
|
|
titleSize = NSZeroSize;
|
|
|
|
|
|
|
|
switch ([self imagePosition])
|
|
|
|
{
|
|
|
|
case NSNoImage:
|
|
|
|
s = titleSize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSImageOnly:
|
|
|
|
s = imageSize;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSImageLeft:
|
|
|
|
case NSImageRight:
|
|
|
|
s.width = imageSize.width + titleSize.width + xDist;
|
|
|
|
if (imageSize.height > titleSize.height)
|
|
|
|
s.height = imageSize.height;
|
|
|
|
else
|
|
|
|
s.height = titleSize.height;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSImageBelow:
|
|
|
|
case NSImageAbove:
|
|
|
|
if (imageSize.width > titleSize.width)
|
|
|
|
s.height = imageSize.width;
|
|
|
|
else
|
|
|
|
s.width = titleSize.width;
|
|
|
|
s.height = imageSize.height + titleSize.height; // + yDist ??
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NSImageOverlaps:
|
|
|
|
if (imageSize.width > titleSize.width)
|
|
|
|
s.width = imageSize.width;
|
|
|
|
else
|
|
|
|
s.width = titleSize.width;
|
|
|
|
|
|
|
|
if (imageSize.height > titleSize.height)
|
|
|
|
s.height = imageSize.height;
|
|
|
|
else
|
|
|
|
s.height = titleSize.height;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-09-11 05:25:53 +00:00
|
|
|
// Add some spacing between text/image and border
|
1999-09-14 01:45:58 +00:00
|
|
|
// if there is text in the button
|
|
|
|
if (titleToDisplay) {
|
|
|
|
s.width += 2 * xDist;
|
|
|
|
s.height += 2 * yDist;
|
|
|
|
}
|
1999-09-10 05:18:32 +00:00
|
|
|
|
|
|
|
// Get border size
|
|
|
|
if ([self isBordered])
|
1999-09-14 01:45:58 +00:00
|
|
|
// Buttons only have three paths for border (NeXT looks)
|
|
|
|
borderSize = NSMakeSize (1.5, 1.5);
|
1999-09-10 05:18:32 +00:00
|
|
|
else
|
|
|
|
borderSize = [NSCell sizeForBorderType: NSNoBorder];
|
|
|
|
|
|
|
|
// Add border size
|
|
|
|
s.width += 2 * borderSize.width;
|
|
|
|
s.height += 2 * borderSize.height;
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
1999-09-14 01:45:58 +00:00
|
|
|
|
1999-09-11 05:25:53 +00:00
|
|
|
- (NSRect) drawingRectForBounds: (NSRect)theRect
|
|
|
|
{
|
|
|
|
if (cell_bordered)
|
1999-09-14 01:45:58 +00:00
|
|
|
{
|
|
|
|
// Special case: Buttons have only three different paths for border.
|
|
|
|
// One white path at the top left corner, one black path at the
|
|
|
|
// bottom right and another in dark gray at the inner bottom right.
|
|
|
|
float yDelta = [control_view isFlipped] ? 1. : 2.;
|
|
|
|
return NSMakeRect (theRect.origin.x + 1.,
|
|
|
|
theRect.origin.y + yDelta,
|
|
|
|
theRect.size.width - 3.,
|
|
|
|
theRect.size.height - 3.);
|
|
|
|
}
|
1999-09-11 05:25:53 +00:00
|
|
|
else
|
1999-09-14 01:45:58 +00:00
|
|
|
{
|
|
|
|
// Get border size
|
|
|
|
NSSize borderSize = [NSCell sizeForBorderType: NSNoBorder];
|
|
|
|
return NSInsetRect (theRect, borderSize.width, borderSize.height);
|
|
|
|
}
|
1999-09-11 05:25:53 +00:00
|
|
|
}
|
1999-02-15 12:50:49 +00:00
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
1997-04-22 18:23:58 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
NSButtonCell *c = [super copyWithZone: zone];
|
|
|
|
|
|
|
|
c->altContents = [altContents copyWithZone: zone];
|
|
|
|
if (altImage)
|
|
|
|
c->altImage = [altImage retain];
|
|
|
|
c->keyEquivalent = [keyEquivalent copyWithZone: zone];
|
|
|
|
if (keyEquivalentFont)
|
|
|
|
c->keyEquivalentFont = [keyEquivalentFont retain];
|
1998-08-30 16:06:47 +00:00
|
|
|
c->keyEquivalentModifierMask = keyEquivalentModifierMask;
|
|
|
|
c->transparent = transparent;
|
1997-04-22 18:23:58 +00:00
|
|
|
c->highlightsByMask = highlightsByMask;
|
|
|
|
c->showAltStateMask = showAltStateMask;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
1999-03-02 08:58:30 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-24 09:21:06 +00:00
|
|
|
[super encodeWithCoder: aCoder];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1996-07-11 00:59:30 +00:00
|
|
|
NSDebugLog(@"NSButtonCell: start encoding\n");
|
1999-03-02 08:58:30 +00:00
|
|
|
[aCoder encodeObject: keyEquivalent];
|
|
|
|
[aCoder encodeObject: keyEquivalentFont];
|
1997-02-18 00:29:25 +00:00
|
|
|
[aCoder encodeObject: altContents];
|
|
|
|
[aCoder encodeObject: altImage];
|
1996-05-30 20:03:15 +00:00
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &transparent];
|
1996-07-11 00:59:30 +00:00
|
|
|
NSDebugLog(@"NSButtonCell: finish encoding\n");
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[super initWithCoder: aDecoder];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1996-07-11 00:59:30 +00:00
|
|
|
NSDebugLog(@"NSButtonCell: start decoding\n");
|
1999-03-02 08:58:30 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &keyEquivalent];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &keyEquivalentFont];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &altContents];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &altImage];
|
1996-05-30 20:03:15 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &transparent];
|
1996-07-11 00:59:30 +00:00
|
|
|
NSDebugLog(@"NSButtonCell: finish decoding\n");
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|