1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSButtonCell.m
|
|
|
|
|
|
|
|
The button cell class
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
|
|
|
|
|
|
|
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
|
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.
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <Foundation/NSLock.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
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>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// NSButtonCell implementation
|
|
|
|
//
|
|
|
|
@implementation NSButtonCell
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
if (self == [NSButtonCell class])
|
|
|
|
{
|
|
|
|
// Initial version
|
|
|
|
[self setVersion:1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
|
|
|
- init
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
[self initTextCell:@"Button"];
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- initImageCell:(NSImage *)anImage
|
|
|
|
{
|
|
|
|
[super initImageCell:anImage];
|
1997-02-18 00:29:25 +00:00
|
|
|
[self setStringValue:@"Button"];
|
|
|
|
[self setButtonType:NSMomentaryPushButton];
|
1996-05-30 20:03:15 +00:00
|
|
|
[self setEnabled:YES];
|
1997-02-18 00:29:25 +00:00
|
|
|
[self setTransparent:NO];
|
1996-05-30 20:03:15 +00:00
|
|
|
[self setBordered:YES];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- initTextCell:(NSString *)aString
|
|
|
|
{
|
|
|
|
[super initTextCell:aString];
|
1997-02-18 00:29:25 +00:00
|
|
|
altContents = @"Button";
|
|
|
|
[self setButtonType:NSMomentaryPushButton];
|
1996-05-30 20:03:15 +00:00
|
|
|
[self setEnabled:YES];
|
1997-02-18 00:29:25 +00:00
|
|
|
[self setTransparent:NO];
|
1996-05-30 20:03:15 +00:00
|
|
|
[self setBordered:YES];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
[altContents release];
|
|
|
|
[altImage release];
|
|
|
|
[keyEquivalent release];
|
|
|
|
[keyEquivalentFont release];
|
1996-05-30 20:03:15 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Titles
|
|
|
|
//
|
|
|
|
- (NSString *)alternateTitle
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return altContents;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlternateTitle:(NSString *)aString
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
altContents = [aString copy];
|
1996-05-30 20:03:15 +00:00
|
|
|
// update our state
|
|
|
|
[self setState:[self state]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setFont:(NSFont *)fontObject
|
|
|
|
{
|
|
|
|
[super setFont:fontObject];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTitle:(NSString *)aString
|
|
|
|
{
|
|
|
|
[self setStringValue:aString];
|
|
|
|
// update our state
|
|
|
|
[self setState:[self state]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)title
|
|
|
|
{
|
|
|
|
return [self stringValue];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Images
|
|
|
|
//
|
|
|
|
- (NSImage *)alternateImage
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return altImage;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSCellImagePosition)imagePosition
|
|
|
|
{
|
|
|
|
return image_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlternateImage:(NSImage *)anImage
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
altImage = [anImage retain];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setImagePosition:(NSCellImagePosition)aPosition
|
|
|
|
{
|
|
|
|
image_position = aPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Repeat Interval
|
|
|
|
//
|
|
|
|
- (void)getPeriodicDelay:(float *)delay
|
|
|
|
interval:(float *)interval
|
|
|
|
{}
|
|
|
|
|
|
|
|
- (void)setPeriodicDelay:(float)delay
|
|
|
|
interval:(float)interval
|
|
|
|
{}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Key Equivalent
|
|
|
|
//
|
|
|
|
- (NSString *)keyEquivalent
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return keyEquivalent;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSFont *)keyEquivalentFont
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return keyEquivalentFont;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (unsigned int)keyEquivalentModifierMask
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return keyEquivalentModifierMask;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (void)setKeyEquivalent:(NSString *)key
|
|
|
|
{
|
|
|
|
keyEquivalent = [key copy];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setKeyEquivalentModifierMask:(unsigned int)mask
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
|
|
|
keyEquivalentModifierMask = mask;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setKeyEquivalentFont:(NSFont *)fontObj
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
|
|
|
keyEquivalentFont = [fontObj retain];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setKeyEquivalentFont:(NSString *)fontName
|
|
|
|
size:(float)fontSize
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
|
|
|
keyEquivalentFont = [[NSFont fontWithName:fontName size:fontSize] retain];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Modifying Graphic Attributes
|
|
|
|
//
|
|
|
|
- (BOOL)isTransparent
|
|
|
|
{
|
|
|
|
return transparent;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTransparent:(BOOL)flag
|
|
|
|
{
|
|
|
|
transparent = flag;
|
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (BOOL)isOpaque
|
|
|
|
{
|
|
|
|
return !transparent && [self isBordered];
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Modifying Graphic Attributes
|
|
|
|
//
|
|
|
|
- (int)highlightsBy
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return highlightsByMask;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (void)setHighlightsBy:(int)mask
|
|
|
|
{
|
|
|
|
highlightsByMask = mask;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (void)setShowsStateBy:(int)mask
|
|
|
|
{
|
|
|
|
showAltStateMask = mask;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (void)setButtonType:(NSButtonType)buttonType
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
[super setType:buttonType];
|
|
|
|
|
|
|
|
switch (buttonType) {
|
|
|
|
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:
|
|
|
|
case NSRadioButton:
|
|
|
|
[self setHighlightsBy:NSContentsCellMask];
|
|
|
|
[self setShowsStateBy:NSContentsCellMask];
|
|
|
|
break;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
// update our state
|
|
|
|
[self setState:[self state]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)showsStateBy
|
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
return showAltStateMask;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setIntValue:(int)anInt
|
|
|
|
{
|
|
|
|
[self setState:(anInt != 0)];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (void)setFloatValue:(float)aFloat
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1997-02-18 00:29:25 +00:00
|
|
|
[self setState:(aFloat != 0)];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1997-02-18 00:29:25 +00:00
|
|
|
- (void)setDoubleValue:(double)aDouble
|
|
|
|
{
|
|
|
|
[self setState:(aDouble != 0)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)intValue { return [self state]; }
|
|
|
|
- (float)floatValue { return [self state]; }
|
|
|
|
- (double)doubleValue { return [self state]; }
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Displaying
|
|
|
|
//
|
|
|
|
- (void)drawWithFrame:(NSRect)cellFrame
|
|
|
|
inView:(NSView *)controlView
|
|
|
|
{
|
|
|
|
// Save last view drawn to
|
|
|
|
control_view = controlView;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Simulating a Click
|
|
|
|
//
|
|
|
|
- (void)performClick:(id)sender
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
|
|
|
- (void)encodeWithCoder:aCoder
|
|
|
|
{
|
|
|
|
[super encodeWithCoder:aCoder];
|
|
|
|
|
1996-07-11 00:59:30 +00:00
|
|
|
NSDebugLog(@"NSButtonCell: start encoding\n");
|
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
|
|
|
}
|
|
|
|
|
|
|
|
- initWithCoder:aDecoder
|
|
|
|
{
|
|
|
|
[super initWithCoder:aDecoder];
|
|
|
|
|
1996-07-11 00:59:30 +00:00
|
|
|
NSDebugLog(@"NSButtonCell: start decoding\n");
|
1997-02-18 00:29:25 +00:00
|
|
|
altContents = [aDecoder decodeObject];
|
|
|
|
altImage = [aDecoder decodeObject];
|
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");
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|