2001-12-17 16:51:51 +00:00
|
|
|
/** <title>NSPopUpButton</title>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
<abstract>Popup list class</abstract>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
1996-05-30 20:03:15 +00:00
|
|
|
Date: 1996
|
1999-06-17 21:07:38 +00:00
|
|
|
Author: Michael Hanni <mhanni@sprintmail.com>
|
|
|
|
Date: June 1999
|
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
|
2007-10-29 21:16:17 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
1996-05-30 20:03:15 +00:00
|
|
|
License as published by the Free Software Foundation; either
|
2008-06-10 04:01:49 +00:00
|
|
|
version 2 of the License, or (at your option) any later version.
|
2007-10-29 21:16:17 +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
|
2007-10-29 21:16:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2007-10-29 21:16:17 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
1996-10-18 17:14:13 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
2007-10-29 21:16:17 +00:00
|
|
|
If not, see <http://www.gnu.org/licenses/> or write to the
|
|
|
|
Free Software Foundation, 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110-1301, USA.
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
2010-03-25 09:11:50 +00:00
|
|
|
#import <Foundation/NSKeyValueCoding.h>
|
|
|
|
#import <Foundation/NSKeyValueObserving.h>
|
|
|
|
#import <Foundation/NSValue.h>
|
|
|
|
#import "AppKit/NSApplication.h"
|
|
|
|
#import "AppKit/NSEvent.h"
|
2010-03-25 21:30:28 +00:00
|
|
|
#import "AppKit/NSGraphics.h"
|
2010-03-25 09:11:50 +00:00
|
|
|
#import "AppKit/NSKeyValueBinding.h"
|
|
|
|
#import "AppKit/NSPopUpButton.h"
|
|
|
|
#import "AppKit/NSPopUpButtonCell.h"
|
|
|
|
#import "AppKit/NSMenu.h"
|
|
|
|
#import "AppKit/NSMenuItem.h"
|
|
|
|
#import "AppKit/NSMenuView.h"
|
2010-03-25 21:30:28 +00:00
|
|
|
#import "AppKit/NSWindow.h"
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
/*
|
|
|
|
* class variables
|
|
|
|
*/
|
1999-12-07 05:34:07 +00:00
|
|
|
Class _nspopupbuttonCellClass = 0;
|
1999-11-22 21:48:03 +00:00
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
/*
|
|
|
|
* NSPopUpButton implementation
|
|
|
|
*/
|
1999-07-18 03:53:42 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSPopUpButton
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
/*
|
|
|
|
* Class methods
|
|
|
|
*/
|
1999-11-25 11:54:08 +00:00
|
|
|
+ (void) initialize
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
if (self == [NSPopUpButton class])
|
|
|
|
{
|
|
|
|
// Initial version
|
1999-11-25 11:54:08 +00:00
|
|
|
[self setVersion: 1];
|
1999-11-22 21:48:03 +00:00
|
|
|
[self setCellClass: [NSPopUpButtonCell class]];
|
2007-12-23 22:13:24 +00:00
|
|
|
|
|
|
|
[self exposeBinding: NSSelectedIndexBinding];
|
2011-06-11 12:01:59 +00:00
|
|
|
[self exposeBinding: NSSelectedObjectBinding];
|
2011-03-07 15:35:36 +00:00
|
|
|
[self exposeBinding: NSSelectedTagBinding];
|
2013-04-15 20:20:38 +00:00
|
|
|
[self exposeBinding: NSContentValuesBinding];
|
2011-03-07 15:35:36 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
1999-12-07 05:34:07 +00:00
|
|
|
|
|
|
|
+ (Class) cellClass
|
|
|
|
{
|
|
|
|
return _nspopupbuttonCellClass;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) setCellClass: (Class)classId
|
|
|
|
{
|
|
|
|
_nspopupbuttonCellClass = classId;
|
|
|
|
}
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
/*
|
|
|
|
* Initializing an NSPopUpButton
|
|
|
|
*/
|
1999-11-25 11:54:08 +00:00
|
|
|
- (id) init
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-25 11:54:08 +00:00
|
|
|
return [self initWithFrame: NSZeroRect pullsDown: NO];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (id) initWithFrame: (NSRect)frameRect
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-25 11:54:08 +00:00
|
|
|
return [self initWithFrame: frameRect pullsDown: NO];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Initialize and returns a new NSPopUpButton into the frame frameRect
|
|
|
|
and specified by flag if the NSPopUpButton is a pull-down list</p>
|
|
|
|
<p>See Also: -setPullsDown: [NSView-initWithFrame:]</p>
|
|
|
|
*/
|
1999-11-25 11:54:08 +00:00
|
|
|
- (id) initWithFrame: (NSRect)frameRect
|
|
|
|
pullsDown: (BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2005-11-24 10:28:06 +00:00
|
|
|
if ( ! ( self = [super initWithFrame: frameRect] ) )
|
|
|
|
return nil;
|
|
|
|
|
1999-12-11 02:57:23 +00:00
|
|
|
[self setPullsDown: flag];
|
1999-07-28 10:50:30 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2003-02-22 11:33:41 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
In NSView, -menuForEvent: returns [self menu] as the context menu of the
|
|
|
|
view. Since our -menu returns the menu for our pop-up, we need to override
|
|
|
|
this to return nil to indicate that we have no context menu.
|
|
|
|
*/
|
|
|
|
- (NSMenu *)menuForEvent:(NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
- (void) setMenu: (NSMenu*)menu
|
1999-07-28 10:50:30 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setMenu: menu];
|
1999-07-28 10:50:30 +00:00
|
|
|
}
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
- (NSMenu*) menu
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell menu];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Sets whether the NSPopUpButton's cell has a pulls-down list ( YES )
|
|
|
|
or a pop-up list (NO) </p> <p>See Also: -pullsDown
|
|
|
|
[NSPopUpButtonCell-setPullsDown:]</p>
|
|
|
|
*/
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) setPullsDown: (BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setPullsDown: flag];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Returns whether the NSPopUpButton's cell has a pulls-down list ( YES )
|
|
|
|
or a pop-up list (NO) </p>
|
|
|
|
<p>See Also: -setPullsDown: [NSPopUpButtonCell-pullsDown]</p>
|
|
|
|
*/
|
1999-11-25 11:54:08 +00:00
|
|
|
- (BOOL) pullsDown
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell pullsDown];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) setAutoenablesItems: (BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setAutoenablesItems: flag];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (BOOL) autoenablesItems
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell autoenablesItems];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Inserts a new item with title as its title at the end of the list and
|
|
|
|
synchronizes the NSPopUpButton's title with the title of the selected item.
|
|
|
|
</p><p>See Also: [NSPopUpButtonCell-addItemWithTitle:]
|
|
|
|
-synchronizeTitleAndSelectedItem</p>
|
|
|
|
*/
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) addItemWithTitle: (NSString *)title
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell addItemWithTitle: title];
|
1999-11-22 21:48:03 +00:00
|
|
|
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Inserts a new list of items with titles as titles at the end of the list
|
|
|
|
and synchronizes the NSPopUpButton's title with the title of the selected
|
|
|
|
item.</p><p>See Also: [NSPopUpButtonCell-addItemsWithTitles:]
|
|
|
|
-synchronizeTitleAndSelectedItem</p>
|
|
|
|
*/
|
2000-01-06 19:49:19 +00:00
|
|
|
- (void) addItemsWithTitles: (NSArray*)itemTitles
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell addItemsWithTitles: itemTitles];
|
1998-01-30 00:34:25 +00:00
|
|
|
|
1999-11-22 21:48:03 +00:00
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1998-01-30 00:34:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Inserts a new item with title as its title at the specified index
|
|
|
|
and synchronizes the NSPopUpButton's title with the title of the selected
|
|
|
|
item.</p><p>See Also: [NSPopUpButtonCell-insertItemWithTitle:atIndex:]
|
|
|
|
-synchronizeTitleAndSelectedItem</p>
|
|
|
|
*/
|
2000-01-06 19:49:19 +00:00
|
|
|
- (void) insertItemWithTitle: (NSString*)title
|
2013-01-30 12:43:27 +00:00
|
|
|
atIndex: (NSInteger)index
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell insertItemWithTitle: title
|
2000-01-06 19:49:19 +00:00
|
|
|
atIndex: index];
|
1999-07-18 03:53:42 +00:00
|
|
|
|
1998-01-30 00:34:25 +00:00
|
|
|
[self synchronizeTitleAndSelectedItem];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Removes all items from the item list and synchronizes the
|
|
|
|
NSPopUpButton's title with the title of the selected</p>
|
|
|
|
<p>See Also: [NSPopUpButtonCell-removeAllItems] -removeItemWithTitle:
|
|
|
|
-synchronizeTitleAndSelectedItem</p>
|
|
|
|
*/
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) removeAllItems
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell removeAllItems];
|
1999-07-30 22:10:02 +00:00
|
|
|
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1998-01-30 00:34:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Removes the item specified with title as its title from the item list
|
|
|
|
and synchronizes the NSPopUpButton's title with the title of the selected
|
|
|
|
</p><p>See Also: [NSPopUpButtonCell-removeItemWithTitle:]
|
|
|
|
-removeAllItems -removeItemAtIndex: -synchronizeTitleAndSelectedItem</p>
|
|
|
|
*/
|
2000-01-06 19:49:19 +00:00
|
|
|
- (void) removeItemWithTitle: (NSString*)title
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell removeItemWithTitle: title];
|
1998-01-30 00:34:25 +00:00
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1998-01-30 00:34:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Removes the item at the specified index index from the item list
|
|
|
|
and synchronizes the NSPopUpButton's title with the title of the selected
|
|
|
|
</p><p>See Also: [NSPopUpButtonCell-removeItemAtIndex:]
|
|
|
|
-removeAllItems -removeItemWithTitle: -synchronizeTitleAndSelectedItem</p>
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void) removeItemAtIndex: (NSInteger)index
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell removeItemAtIndex: index];
|
1999-07-30 22:10:02 +00:00
|
|
|
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1998-01-30 00:34:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Returns the selected item</p>
|
|
|
|
<p>See Also: [NSPopUpButtonCell-selectedItem]</p>
|
|
|
|
*/
|
1999-11-25 11:54:08 +00:00
|
|
|
- (id <NSMenuItem>) selectedItem
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell selectedItem];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
1998-01-30 00:34:25 +00:00
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Returns the title of the selected item</p>
|
|
|
|
<p>See Also: [NSPopUpButtonCell-titleOfSelectedItem]</p>
|
|
|
|
*/
|
2000-01-06 19:49:19 +00:00
|
|
|
- (NSString*) titleOfSelectedItem
|
1999-07-30 22:10:02 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell titleOfSelectedItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Returns the index of the selected item</p>
|
|
|
|
<p>See Also: [NSPopUpButtonCell-indexOfSelectedItem]</p>
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger) indexOfSelectedItem
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell indexOfSelectedItem];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
|
|
|
|
2009-09-06 21:38:15 +00:00
|
|
|
/**<p>Returns the tag of the selected item</p>
|
|
|
|
<p>See Also: [NSPopUpButtonCell-indexOfSelectedItem]</p>
|
|
|
|
*/
|
2010-09-16 02:51:30 +00:00
|
|
|
- (NSInteger) selectedTag
|
2009-09-06 21:38:15 +00:00
|
|
|
{
|
|
|
|
return [[_cell selectedItem] tag];
|
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) selectItem: (id <NSMenuItem>)anObject
|
1999-07-30 22:10:02 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell selectItem: anObject];
|
2000-02-19 00:40:47 +00:00
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Select the item at index <var>index</var> and synchronizes the
|
|
|
|
NSPopUpButton's title with the title of the selected</p><p>See Also:
|
|
|
|
[NSPopUpButtonCell-selectItemAtIndex:] -synchronizeTitleAndSelectedItem</p>
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (void) selectItemAtIndex: (NSInteger)index
|
1999-07-30 22:10:02 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell selectItemAtIndex: index];
|
2000-02-19 00:40:47 +00:00
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Select the item with title <var>title</var> and synchronizes the
|
|
|
|
NSPopUpButton's title with the title of the selected</p><p>See Also:
|
|
|
|
[NSPopUpButtonCell-selectItemWithTitle:]
|
|
|
|
-synchronizeTitleAndSelectedItem</p>
|
|
|
|
*/
|
2000-01-06 19:49:19 +00:00
|
|
|
- (void) selectItemWithTitle: (NSString*)title
|
1999-07-30 22:10:02 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell selectItemWithTitle: title];
|
2000-02-19 00:40:47 +00:00
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2008-07-02 22:10:53 +00:00
|
|
|
- (BOOL) selectItemWithTag: (NSInteger)tag
|
|
|
|
{
|
2013-01-30 12:43:27 +00:00
|
|
|
NSInteger index = [self indexOfItemWithTag: tag];
|
2008-07-02 22:10:53 +00:00
|
|
|
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
|
|
|
[self selectItemAtIndex: index];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Returns the number of items in the item list</p>
|
|
|
|
<p>See Also: [NSPopUpButtonCell-numberOfItems]</p>
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger) numberOfItems
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell numberOfItems];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
- (NSArray*) itemArray
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell itemArray];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Returns the NSMenuItem at index index or nil if index is out of
|
|
|
|
range</p><p>See Also: [NSPopUpButtonCell-itemAtIndex:] </p>
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (id <NSMenuItem>) itemAtIndex: (NSInteger)index
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell itemAtIndex: index];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/** <p>Returns the item's title at index <var>index</var></p>
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSString*) itemTitleAtIndex: (NSInteger)index
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell itemTitleAtIndex: index];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Returns an array containing the items's titles</p>
|
|
|
|
*/
|
2000-01-06 19:49:19 +00:00
|
|
|
- (NSArray*) itemTitles
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell itemTitles];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Returns the NSMenuItem with title as its title</p>
|
|
|
|
*/
|
2000-01-06 19:49:19 +00:00
|
|
|
- (id <NSMenuItem>) itemWithTitle: (NSString*)title
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell itemWithTitle: title];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p> Returns the last NSMenuItem of the list</p>
|
|
|
|
*/
|
1999-11-25 11:54:08 +00:00
|
|
|
- (id <NSMenuItem>) lastItem
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell lastItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger) indexOfItem: (id <NSMenuItem>)anObject
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell indexOfItem: anObject];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Returns the index of the item with tag as its tag. Returns -1
|
|
|
|
if the cell is not found</p><p>See Also:
|
|
|
|
[NSPopUpButtonCell-indexOfItemWithTag:] -indexOfItemWithTitle:
|
|
|
|
-indexOfItemWithRepresentedObject:</p>
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger) indexOfItemWithTag: (NSInteger)tag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell indexOfItemWithTag: tag];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2005-11-24 10:28:06 +00:00
|
|
|
/**<p>Returns the index of the item with title as its title. Returns -1
|
|
|
|
if the cell is not found</p><p>See Also:
|
|
|
|
[NSPopUpButtonCell-indexOfItemWithTitle:] -indexOfItemWithTag:
|
|
|
|
-indexOfItemWithRepresentedObject:</p>
|
|
|
|
*/
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger) indexOfItemWithTitle: (NSString*)title
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell indexOfItemWithTitle: title];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger) indexOfItemWithRepresentedObject: (id)anObject
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell indexOfItemWithRepresentedObject: anObject];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2013-01-30 12:43:27 +00:00
|
|
|
- (NSInteger) indexOfItemWithTarget: (id)target
|
1999-11-25 11:54:08 +00:00
|
|
|
andAction: (SEL)actionSelector
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell indexOfItemWithTarget: target andAction: actionSelector];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) setPreferredEdge: (NSRectEdge)edge
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setPreferredEdge: edge];
|
1998-01-30 00:34:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (NSRectEdge) preferredEdge
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
return [_cell preferredEdge];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
- (void) setTitle: (NSString*)aString
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell setTitle: aString];
|
2004-01-26 20:49:33 +00:00
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) synchronizeTitleAndSelectedItem
|
1999-07-30 22:10:02 +00:00
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell synchronizeTitleAndSelectedItem];
|
1999-12-03 21:38:43 +00:00
|
|
|
[self setNeedsDisplay: YES];
|
1999-08-19 23:18:25 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 00:27:37 +00:00
|
|
|
- (BOOL) resignFirstResponder
|
|
|
|
{
|
|
|
|
[_cell dismissPopUp];
|
|
|
|
|
|
|
|
return [super resignFirstResponder];
|
|
|
|
}
|
|
|
|
|
2001-09-28 23:37:37 +00:00
|
|
|
- (BOOL) performKeyEquivalent: (NSEvent*)theEvent
|
|
|
|
{
|
2003-04-10 15:05:50 +00:00
|
|
|
NSMenu *m = [self menu];
|
2008-12-31 16:49:46 +00:00
|
|
|
NSMenuItem *oldSelectedItem = (NSMenuItem *)[_cell selectedItem];
|
2001-09-28 23:37:37 +00:00
|
|
|
|
|
|
|
if (m != nil)
|
2003-01-21 01:17:26 +00:00
|
|
|
{
|
|
|
|
if ([m performKeyEquivalent: theEvent])
|
|
|
|
{
|
2003-04-10 15:05:50 +00:00
|
|
|
// pullsDown does not change selected item
|
|
|
|
if ([_cell pullsDown])
|
|
|
|
{
|
|
|
|
[self selectItem: oldSelectedItem];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* If the key equivalent was performed, redisplay ourselves
|
|
|
|
* to account for potential changes in the selected item.
|
|
|
|
*/
|
|
|
|
[self setNeedsDisplay: YES];
|
|
|
|
}
|
2003-01-21 01:17:26 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
2001-09-28 23:37:37 +00:00
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
- (void) mouseDown: (NSEvent*)theEvent
|
1999-12-11 02:57:23 +00:00
|
|
|
{
|
2005-02-14 18:33:46 +00:00
|
|
|
[_cell trackMouse: theEvent
|
|
|
|
inRect: [self bounds]
|
|
|
|
ofView: self
|
|
|
|
untilMouseUp: YES];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-03-22 00:27:37 +00:00
|
|
|
- (void) keyDown: (NSEvent*)theEvent
|
|
|
|
{
|
2005-04-17 21:25:32 +00:00
|
|
|
// FIXME: This method also handles the key events for the popup menu window,
|
|
|
|
// as menu windows cannot become key window.
|
2001-03-22 00:27:37 +00:00
|
|
|
if ([self isEnabled])
|
|
|
|
{
|
|
|
|
NSString *characters = [theEvent characters];
|
|
|
|
unichar character = 0;
|
|
|
|
|
|
|
|
if ([characters length] > 0)
|
|
|
|
{
|
|
|
|
character = [characters characterAtIndex: 0];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (character)
|
|
|
|
{
|
|
|
|
case NSNewlineCharacter:
|
|
|
|
case NSEnterCharacter:
|
|
|
|
case NSCarriageReturnCharacter:
|
2008-11-05 23:01:37 +00:00
|
|
|
/* Handle Enter and Return keys only when the menu is visible.
|
|
|
|
The button's action to pop up the menu is initiated only by
|
|
|
|
the Space key similar to other buttons. */
|
|
|
|
{
|
|
|
|
NSMenuView *menuView = [[_cell menu] menuRepresentation];
|
|
|
|
if ([[menuView window] isVisible] == NO)
|
|
|
|
break;
|
|
|
|
}
|
2001-03-22 00:27:37 +00:00
|
|
|
case ' ':
|
|
|
|
{
|
2013-01-30 12:43:27 +00:00
|
|
|
NSInteger selectedIndex;
|
2001-09-28 23:37:37 +00:00
|
|
|
NSMenuView *menuView;
|
|
|
|
|
2003-04-13 08:56:35 +00:00
|
|
|
// Beep, as on OS, and then return.
|
|
|
|
if ([[_cell menu] numberOfItems] == 0)
|
|
|
|
{
|
|
|
|
NSBeep();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-09-28 23:37:37 +00:00
|
|
|
menuView = [[_cell menu] menuRepresentation];
|
|
|
|
if ([[menuView window] isVisible] == NO)
|
2001-03-22 00:27:37 +00:00
|
|
|
{
|
|
|
|
// Attach the popUp
|
|
|
|
[_cell attachPopUpWithFrame: _bounds
|
|
|
|
inView: self];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-01-10 21:13:39 +00:00
|
|
|
selectedIndex = [menuView highlightedItemIndex];
|
2007-01-19 13:01:38 +00:00
|
|
|
if (selectedIndex >= 0)
|
2005-04-17 21:25:32 +00:00
|
|
|
{
|
|
|
|
[[_cell menu] performActionForItemAtIndex: selectedIndex];
|
|
|
|
}
|
2001-03-22 00:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case '\e':
|
|
|
|
[_cell dismissPopUp];
|
|
|
|
return;
|
|
|
|
case NSUpArrowFunctionKey:
|
|
|
|
{
|
|
|
|
NSMenuView *menuView;
|
2013-01-30 12:43:27 +00:00
|
|
|
NSInteger selectedIndex, numberOfItems;
|
2001-03-22 00:27:37 +00:00
|
|
|
|
|
|
|
menuView = [[_cell menu] menuRepresentation];
|
|
|
|
selectedIndex = [menuView highlightedItemIndex];
|
|
|
|
numberOfItems = [self numberOfItems];
|
|
|
|
|
|
|
|
switch (selectedIndex)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
selectedIndex = numberOfItems - 1;
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
return;
|
|
|
|
default:
|
|
|
|
selectedIndex--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
[menuView setHighlightedItemIndex: selectedIndex];
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case NSDownArrowFunctionKey:
|
|
|
|
{
|
|
|
|
NSMenuView *menuView;
|
2013-01-30 12:43:27 +00:00
|
|
|
NSInteger selectedIndex, numberOfItems;
|
2001-03-22 00:27:37 +00:00
|
|
|
|
|
|
|
menuView = [[_cell menu] menuRepresentation];
|
|
|
|
selectedIndex = [menuView highlightedItemIndex];
|
|
|
|
numberOfItems = [self numberOfItems];
|
|
|
|
|
|
|
|
if (selectedIndex < numberOfItems-1)
|
|
|
|
[menuView setHighlightedItemIndex: selectedIndex + 1];
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[super keyDown: theEvent];
|
|
|
|
}
|
|
|
|
|
2007-12-23 22:13:24 +00:00
|
|
|
- (void) setValue: (id)anObject forKey: (NSString*)aKey
|
|
|
|
{
|
|
|
|
if ([aKey isEqual: NSSelectedIndexBinding])
|
|
|
|
{
|
|
|
|
[self selectItemAtIndex: [anObject intValue]];
|
|
|
|
}
|
2011-03-07 15:35:36 +00:00
|
|
|
else if ([aKey isEqual: NSSelectedTagBinding])
|
|
|
|
{
|
|
|
|
[self selectItemWithTag: [anObject integerValue]];
|
|
|
|
}
|
2011-06-11 12:01:59 +00:00
|
|
|
else if ([aKey isEqual: NSSelectedObjectBinding])
|
|
|
|
{
|
|
|
|
[self selectItemWithTag: [anObject intValue]];
|
|
|
|
}
|
2013-04-15 20:20:38 +00:00
|
|
|
else if ([aKey isEqual: NSContentValuesBinding])
|
|
|
|
{
|
|
|
|
[self removeAllItems];
|
|
|
|
[self addItemsWithTitles: (NSArray*)anObject];
|
|
|
|
}
|
2007-12-23 22:13:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
[super setValue: anObject forKey: aKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) valueForKey: (NSString*)aKey
|
|
|
|
{
|
|
|
|
if ([aKey isEqual: NSSelectedIndexBinding])
|
|
|
|
{
|
|
|
|
return [NSNumber numberWithInt: [self indexOfSelectedItem]];
|
|
|
|
}
|
2011-03-07 15:35:36 +00:00
|
|
|
else if ([aKey isEqual: NSSelectedTagBinding])
|
|
|
|
{
|
|
|
|
return [NSNumber numberWithInteger: [self selectedTag]];
|
|
|
|
}
|
2011-06-11 12:01:59 +00:00
|
|
|
else if ([aKey isEqual: NSSelectedObjectBinding])
|
|
|
|
{
|
|
|
|
return [NSNumber numberWithInt: [self selectedTag]];
|
|
|
|
}
|
2013-04-15 20:20:38 +00:00
|
|
|
else if ([aKey isEqual: NSContentValuesBinding])
|
|
|
|
{
|
|
|
|
return [self itemTitles];
|
|
|
|
}
|
2007-12-23 22:13:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return [super valueForKey: aKey];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@end
|