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>
|
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
|
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.
|
|
|
|
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
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>
|
|
|
|
|
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
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSButtonCell
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
if (self == [NSButtonCell class])
|
|
|
|
[self setVersion:1]; // Initial version
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
1998-08-30 16:06:47 +00:00
|
|
|
- _init
|
|
|
|
{
|
1998-11-25 17:16:48 +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;
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
return self;
|
1998-08-30 16:06:47 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
- init
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[self initTextCell:@"Button"];
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
return self;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initImageCell:(NSImage *)anImage
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[super initImageCell:anImage];
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
contents = nil;
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
return [self _init];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- initTextCell:(NSString *)aString
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[super initTextCell:aString];
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
return [self _init];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[altContents release];
|
|
|
|
[altImage release];
|
|
|
|
[keyEquivalent release];
|
|
|
|
[keyEquivalentFont release];
|
|
|
|
|
|
|
|
[super dealloc];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Titles
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (NSString *)title { return [self stringValue]; }
|
|
|
|
- (NSString *)alternateTitle { return altContents; }
|
|
|
|
- (void)setFont:(NSFont *)fontObject { [super setFont:fontObject]; }
|
|
|
|
|
|
|
|
- (void)setTitle:(NSString *)aString
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
[self setStringValue:aString];
|
|
|
|
[self setState:[self state]]; // update our state
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAlternateTitle:(NSString *)aString
|
|
|
|
{
|
1998-08-30 16:06:47 +00:00
|
|
|
NSString* _string = [aString copy];
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
ASSIGN(altContents, _string);
|
|
|
|
[self setState:[self state]]; // update our state
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Images
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (NSImage *)alternateImage { return altImage; }
|
|
|
|
- (NSCellImagePosition)imagePosition { return image_position; }
|
|
|
|
- (void)setAlternateImage:(NSImage *)anImage { ASSIGN(altImage, anImage); }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setImagePosition:(NSCellImagePosition)aPosition
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
image_position = aPosition;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Repeat Interval
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)getPeriodicDelay:(float *)delay interval:(float *)interval
|
1997-08-05 21:50:10 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
*delay = delayInterval;
|
|
|
|
*interval = repeatInterval;
|
1997-08-05 21:50:10 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)setPeriodicDelay:(float)delay interval:(float)interval
|
1997-08-05 21:50:10 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +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
|
|
|
|
|
|
|
//
|
|
|
|
// Setting the Key Equivalent
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (NSString *)keyEquivalent { return keyEquivalent; }
|
|
|
|
- (NSFont *)keyEquivalentFont { return keyEquivalentFont; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (unsigned int)keyEquivalentModifierMask
|
|
|
|
{
|
|
|
|
return keyEquivalentModifierMask;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1998-08-30 16:06:47 +00:00
|
|
|
- (void)setKeyEquivalent:(NSString *)key
|
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
ASSIGN(keyEquivalent, [key copy]);
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setKeyEquivalentModifierMask:(unsigned int)mask
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
keyEquivalentModifierMask = mask;
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)setKeyEquivalentFont:(NSFont *)fontObj
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
ASSIGN(keyEquivalentFont, fontObj);
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)setKeyEquivalentFont:(NSString *)fontName size:(float)fontSize
|
1997-02-18 00:29:25 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +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
|
|
|
|
|
|
|
//
|
|
|
|
// Modifying Graphic Attributes
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (BOOL)isTransparent { return transparent; }
|
|
|
|
- (void)setTransparent:(BOOL)flag { transparent = flag; }
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (BOOL)isOpaque
|
|
|
|
{
|
|
|
|
return !transparent && [self isBordered];
|
1997-02-18 00:29:25 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Modifying Graphic Attributes
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (int)highlightsBy { return highlightsByMask; }
|
|
|
|
- (void)setHighlightsBy:(int)mask { highlightsByMask = mask; }
|
|
|
|
- (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:
|
1997-02-18 18:45:16 +00:00
|
|
|
[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;
|
1997-02-18 00:29:25 +00:00
|
|
|
case NSRadioButton:
|
|
|
|
[self setHighlightsBy:NSContentsCellMask];
|
|
|
|
[self setShowsStateBy:NSContentsCellMask];
|
1997-02-18 18:45:16 +00:00
|
|
|
[self setImage:[NSImage imageNamed:@"common_RadioOff"]];
|
|
|
|
[self setAlternateImage:[NSImage imageNamed:@"common_RadioOn"]];
|
|
|
|
[self setImagePosition:NSImageLeft];
|
|
|
|
[self setAlignment:NSLeftTextAlignment];
|
1997-02-18 00:29:25 +00:00
|
|
|
break;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
// update our state
|
|
|
|
[self setState:[self state]];
|
|
|
|
}
|
|
|
|
|
1998-11-25 17:16:48 +00:00
|
|
|
- (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)]; }
|
|
|
|
- (int)intValue { return [self state]; }
|
|
|
|
- (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
|
|
|
|
//
|
1998-11-25 17:16:48 +00:00
|
|
|
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1998-11-25 17:16:48 +00:00
|
|
|
control_view = controlView; // Save last view cell was drawn to
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Simulating a Click
|
|
|
|
//
|
|
|
|
- (void)performClick:(id)sender
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1997-04-22 18:23:58 +00:00
|
|
|
- (id)copyWithZone:(NSZone*)zone
|
|
|
|
{
|
|
|
|
NSButtonCell* c = [super copyWithZone:zone];
|
|
|
|
|
1998-08-30 16:06:47 +00:00
|
|
|
c->altContents = [[altContents copy] retain];
|
|
|
|
ASSIGN(c->altImage, altImage);
|
|
|
|
c->keyEquivalent = [[keyEquivalent copy] retain];
|
|
|
|
ASSIGN(c->keyEquivalentFont, keyEquivalentFont);
|
|
|
|
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
|
|
|
|
//
|
|
|
|
- (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");
|
1998-08-30 16:06:47 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|