1997-07-07 16:56:52 +00:00
|
|
|
/*
|
|
|
|
NSMenuItem.m
|
|
|
|
|
|
|
|
The menu cell class.
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
1999-11-16 22:25:07 +00:00
|
|
|
Author: David Lazaro Saz <khelekir@encomix.es>
|
|
|
|
Date: Sep 1999
|
|
|
|
|
1997-07-07 16:56:52 +00:00
|
|
|
Author: Ovidiu Predescu <ovidiu@net-community.com>
|
|
|
|
Date: May 1997
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
#include <gnustep/gui/config.h>
|
1997-07-07 16:56:52 +00:00
|
|
|
#include <Foundation/NSUserDefaults.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <AppKit/NSMenuItem.h>
|
|
|
|
#include <AppKit/NSMenu.h>
|
|
|
|
|
1999-11-16 22:25:07 +00:00
|
|
|
static BOOL usesUserKeyEquivalents = NO;
|
|
|
|
static Class imageClass;
|
1997-07-07 16:56:52 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
@interface GSMenuSeparator : NSMenuItem
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation GSMenuSeparator
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [super initWithTitle: @"-----------"
|
|
|
|
action: NULL
|
|
|
|
keyEquivalent: @""];
|
|
|
|
_enabled = NO;
|
|
|
|
_changesState = NO;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isSeparatorItem
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: We need a lot of methods to switch of changes for a separator
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
1997-07-07 16:56:52 +00:00
|
|
|
@implementation NSMenuItem
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
+ (void) initialize
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
|
|
|
if (self == [NSMenuItem class])
|
|
|
|
{
|
2000-01-05 16:31:38 +00:00
|
|
|
[self setVersion: 1];
|
1999-11-16 22:25:07 +00:00
|
|
|
imageClass = [NSImage class];
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
+ (void) setUsesUserKeyEquivalents: (BOOL)flag
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
|
|
|
usesUserKeyEquivalents = flag;
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
+ (BOOL) usesUserKeyEquivalents
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
|
|
|
return usesUserKeyEquivalents;
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
+ (id <NSMenuItem>) separatorItem
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return [GSMenuSeparator new];
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (id) init
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return [self initWithTitle: @""
|
|
|
|
action: NULL
|
|
|
|
keyEquivalent: @""];
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
1999-11-16 22:25:07 +00:00
|
|
|
- (void) dealloc
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
|
|
|
NSDebugLog (@"NSMenuItem '%@' dealloc", [self title]);
|
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
TEST_RELEASE(_title);
|
|
|
|
TEST_RELEASE(_keyEquivalent);
|
|
|
|
TEST_RELEASE(_image);
|
|
|
|
TEST_RELEASE(_onStateImage);
|
|
|
|
TEST_RELEASE(_offStateImage);
|
|
|
|
TEST_RELEASE(_mixedStateImage);
|
|
|
|
TEST_RELEASE(_submenu);
|
|
|
|
TEST_RELEASE(_representedObject);
|
1997-07-07 16:56:52 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (id) initWithTitle: (NSString*)aString
|
|
|
|
action: (SEL)aSelector
|
|
|
|
keyEquivalent: (NSString*)charCode
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
self = [super init];
|
|
|
|
//_menu = nil;
|
1999-11-16 22:25:07 +00:00
|
|
|
[self setTitle: aString];
|
|
|
|
[self setKeyEquivalent: charCode];
|
2001-08-27 18:48:55 +00:00
|
|
|
_keyEquivalentModifierMask = NSCommandKeyMask;
|
|
|
|
_mnemonicLocation = 255; // No mnemonic
|
|
|
|
_state = NSOffState;
|
|
|
|
_enabled = YES;
|
|
|
|
//_image = nil;
|
1999-11-16 22:25:07 +00:00
|
|
|
// Set the images according to the spec. On: check mark; off: dash.
|
2000-01-05 16:31:38 +00:00
|
|
|
[self setOnStateImage: [imageClass imageNamed: @"common_2DCheckMark"]];
|
|
|
|
[self setMixedStateImage: [imageClass imageNamed: @"common_2DDash"]];
|
2001-08-27 18:48:55 +00:00
|
|
|
//_offStateImage = nil;
|
|
|
|
//_target = nil;
|
|
|
|
_action = aSelector;
|
|
|
|
//_changesState = NO;
|
1999-11-16 22:25:07 +00:00
|
|
|
return self;
|
|
|
|
}
|
1997-07-07 16:56:52 +00:00
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setMenu: (NSMenu*)menu
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_menu = menu;
|
|
|
|
if (_submenu != nil)
|
2000-09-08 09:41:33 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
[_submenu setSupermenu: menu];
|
|
|
|
[self setTarget: _menu];
|
2000-09-08 09:41:33 +00:00
|
|
|
}
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
1997-07-07 16:56:52 +00:00
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSMenu*) menu
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _menu;
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (BOOL) hasSubmenu
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return (_submenu == nil) ? NO : YES;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setSubmenu: (NSMenu*)submenu
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
|
|
|
if ([submenu supermenu] != nil)
|
|
|
|
[NSException raise: NSInvalidArgumentException
|
|
|
|
format: @"submenu already has supermenu: "];
|
2001-08-27 18:48:55 +00:00
|
|
|
ASSIGN(_submenu, submenu);
|
|
|
|
[submenu setSupermenu: _menu];
|
|
|
|
[self setTarget: _menu];
|
2000-09-08 09:41:33 +00:00
|
|
|
[self setAction: @selector(submenuAction:)];
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSMenu*) submenu
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _submenu;
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setTitle: (NSString*)aString
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
if (nil == aString)
|
|
|
|
aString = @"";
|
1999-11-16 22:25:07 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
ASSIGNCOPY(_title, aString);
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSString*) title
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _title;
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (BOOL) isSeparatorItem
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
1999-11-16 22:25:07 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setKeyEquivalent: (NSString*)aKeyEquivalent
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
if (nil == aKeyEquivalent)
|
|
|
|
aKeyEquivalent = @"";
|
1999-11-16 22:25:07 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
ASSIGNCOPY(_keyEquivalent, aKeyEquivalent);
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSString*) keyEquivalent
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
|
|
|
if (usesUserKeyEquivalents)
|
|
|
|
return [self userKeyEquivalent];
|
|
|
|
else
|
2001-08-27 18:48:55 +00:00
|
|
|
return _keyEquivalent;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setKeyEquivalentModifierMask: (unsigned int)mask
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_keyEquivalentModifierMask = mask;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (unsigned int) keyEquivalentModifierMask
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _keyEquivalentModifierMask;
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSString*) userKeyEquivalent
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
NSString *userKeyEquivalent = [[[[NSUserDefaults standardUserDefaults]
|
|
|
|
persistentDomainForName: NSGlobalDomain]
|
|
|
|
objectForKey: @"NSCommandKeys"]
|
|
|
|
objectForKey: _title];
|
1997-07-07 16:56:52 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
if (nil == userKeyEquivalent)
|
1999-11-16 22:25:07 +00:00
|
|
|
userKeyEquivalent = @"";
|
1997-07-07 16:56:52 +00:00
|
|
|
|
|
|
|
return userKeyEquivalent;
|
|
|
|
}
|
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
- (unsigned int) userKeyEquivalentModifierMask
|
|
|
|
{
|
|
|
|
// FIXME
|
|
|
|
return NSCommandKeyMask;
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setMnemonicLocation: (unsigned)location
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_mnemonicLocation = location;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (unsigned) mnemonicLocation
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
if (_mnemonicLocation != 255)
|
|
|
|
return _mnemonicLocation;
|
1999-11-16 22:25:07 +00:00
|
|
|
else
|
|
|
|
return NSNotFound;
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSString*) mnemonic
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
if (_mnemonicLocation != 255)
|
|
|
|
return [_title substringWithRange: NSMakeRange(_mnemonicLocation, 1)];
|
1999-11-16 22:25:07 +00:00
|
|
|
else
|
|
|
|
return @"";
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setTitleWithMnemonic: (NSString*)stringWithAmpersand
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
unsigned int location = [stringWithAmpersand rangeOfString: @"&"].location;
|
1999-11-16 22:25:07 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
[self setTitle: [stringWithAmpersand stringByReplacingString: @"&"
|
|
|
|
withString: @""]];
|
|
|
|
[self setMnemonicLocation: location];
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setImage: (NSImage *)image
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
|
|
|
NSAssert(image == nil || [image isKindOfClass: imageClass],
|
2000-01-05 16:31:38 +00:00
|
|
|
NSInvalidArgumentException);
|
1999-11-16 22:25:07 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
ASSIGN(_image, image);
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSImage*) image
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _image;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setState: (int)state
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_state = state;
|
|
|
|
_changesState = YES;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (int) state
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _state;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setOnStateImage: (NSImage*)image
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
|
|
|
NSAssert(image == nil || [image isKindOfClass: imageClass],
|
2000-01-05 16:31:38 +00:00
|
|
|
NSInvalidArgumentException);
|
1999-11-16 22:25:07 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
ASSIGN(_onStateImage, image);
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSImage*) onStateImage
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _onStateImage;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setOffStateImage: (NSImage*)image
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
|
|
|
NSAssert(image == nil || [image isKindOfClass: imageClass],
|
2000-01-05 16:31:38 +00:00
|
|
|
NSInvalidArgumentException);
|
1999-11-16 22:25:07 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
ASSIGN(_offStateImage, image);
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSImage*) offStateImage
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _offStateImage;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setMixedStateImage: (NSImage*)image
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
|
|
|
NSAssert(image == nil || [image isKindOfClass: imageClass],
|
2000-01-05 16:31:38 +00:00
|
|
|
NSInvalidArgumentException);
|
1999-11-16 22:25:07 +00:00
|
|
|
|
2001-08-27 18:48:55 +00:00
|
|
|
ASSIGN(_mixedStateImage, image);
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (NSImage*) mixedStateImage
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _mixedStateImage;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setEnabled: (BOOL)flag
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_enabled = flag;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (BOOL) isEnabled
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _enabled;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setTarget: (id)anObject
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_target = anObject;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (id) target
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _target;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setAction: (SEL)aSelector
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_action = aSelector;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (SEL) action
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _action;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setTag: (int)anInt
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_tag = anInt;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (int) tag
|
1999-11-16 22:25:07 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _tag;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (void) setRepresentedObject: (id)anObject
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
ASSIGN(_representedObject, anObject);
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
- (id) representedObject
|
1997-07-07 16:56:52 +00:00
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _representedObject;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
/*
|
|
|
|
* NSCopying protocol
|
|
|
|
*/
|
1999-11-16 22:25:07 +00:00
|
|
|
- (id) copyWithZone: (NSZone*)zone
|
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
NSMenuItem *copy = (NSMenuItem*)NSCopyObject (self, 0, zone);
|
1999-11-16 22:25:07 +00:00
|
|
|
|
|
|
|
NSDebugLog (@"menu item '%@' copy", [self title]);
|
2001-08-27 18:48:55 +00:00
|
|
|
|
|
|
|
// We reset the menu to nil to allow the reuse of the copy
|
|
|
|
copy->_menu = nil;
|
|
|
|
copy->_title = [_title copyWithZone: zone];
|
|
|
|
copy->_keyEquivalent = [_keyEquivalent copyWithZone: zone];
|
|
|
|
copy->_image = [_image copyWithZone: zone];
|
|
|
|
copy->_onStateImage = [_onStateImage copyWithZone: zone];
|
|
|
|
copy->_offStateImage = [_offStateImage copyWithZone: zone];
|
|
|
|
copy->_mixedStateImage = [_mixedStateImage copyWithZone: zone];
|
|
|
|
copy->_representedObject = RETAIN(_representedObject);
|
|
|
|
copy->_submenu = [_submenu copy];
|
1999-11-16 22:25:07 +00:00
|
|
|
|
|
|
|
return copy;
|
|
|
|
}
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
/*
|
|
|
|
* NSCoding protocol
|
|
|
|
*/
|
1999-11-16 22:25:07 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
[aCoder encodeObject: _title];
|
|
|
|
[aCoder encodeObject: _keyEquivalent];
|
|
|
|
[aCoder encodeValueOfObjCType: "I" at: &_keyEquivalentModifierMask];
|
|
|
|
[aCoder encodeValueOfObjCType: "I" at: &_mnemonicLocation];
|
|
|
|
[aCoder encodeValueOfObjCType: "i" at: &_state];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_enabled];
|
|
|
|
[aCoder encodeObject: _image];
|
|
|
|
[aCoder encodeObject: _onStateImage];
|
|
|
|
[aCoder encodeObject: _offStateImage];
|
|
|
|
[aCoder encodeObject: _mixedStateImage];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &_changesState];
|
|
|
|
[aCoder encodeConditionalObject: _target];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(SEL) at: &_action];
|
|
|
|
[aCoder encodeValueOfObjCType: "i" at: &_tag];
|
|
|
|
[aCoder encodeConditionalObject: _representedObject];
|
|
|
|
[aCoder encodeObject: _submenu];
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_title];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_keyEquivalent];
|
|
|
|
[aDecoder decodeValueOfObjCType: "I" at: &_keyEquivalentModifierMask];
|
|
|
|
[aDecoder decodeValueOfObjCType: "I" at: &_mnemonicLocation];
|
|
|
|
[aDecoder decodeValueOfObjCType: "i" at: &_state];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_enabled];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_image];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_onStateImage];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_offStateImage];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_mixedStateImage];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_changesState];
|
|
|
|
_target = [aDecoder decodeObject];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &_action];
|
|
|
|
[aDecoder decodeValueOfObjCType: "i" at: &_tag];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_representedObject];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &_submenu];
|
1999-11-16 22:25:07 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation NSMenuItem (GNUstepExtra)
|
|
|
|
|
2000-01-05 16:31:38 +00:00
|
|
|
/*
|
|
|
|
* These methods support the special arranging in columns of menu
|
|
|
|
* items in GNUstep. There's no need to use them outside but if
|
|
|
|
* they are used the display is more pleasant.
|
|
|
|
*/
|
1999-11-16 22:25:07 +00:00
|
|
|
- (void) setChangesState: (BOOL)flag
|
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
_changesState = flag;
|
1999-11-16 22:25:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) changesState
|
|
|
|
{
|
2001-08-27 18:48:55 +00:00
|
|
|
return _changesState;
|
1997-07-07 16:56:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|