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
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
2001-09-28 23:37:37 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSPopUpButton.h>
|
1999-06-19 00:31:39 +00:00
|
|
|
#include <AppKit/NSPopUpButtonCell.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSApplication.h>
|
1998-01-30 00:34:25 +00:00
|
|
|
#include <AppKit/NSMenu.h>
|
2001-09-28 23:37:37 +00:00
|
|
|
#include <AppKit/NSMenuItem.h>
|
1999-07-18 03:53:42 +00:00
|
|
|
#include <AppKit/NSMenuView.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]];
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (id) initWithFrame: (NSRect)frameRect
|
|
|
|
pullsDown: (BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-09-28 23:37:37 +00:00
|
|
|
self = [super initWithFrame: frameRect];
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
- (void) insertItemWithTitle: (NSString*)title
|
1999-12-07 05:34:07 +00:00
|
|
|
atIndex: (int)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
|
|
|
|
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
|
|
|
|
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
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) removeItemAtIndex: (int)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
|
|
|
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (int) 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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (void) selectItemAtIndex: (int)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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (int) 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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (id <NSMenuItem>) itemAtIndex: (int)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
|
|
|
}
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
- (NSString*) itemTitleAtIndex: (int)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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (int) 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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (int) indexOfItemWithTag: (int)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
|
|
|
}
|
|
|
|
|
2000-01-06 19:49:19 +00:00
|
|
|
- (int) 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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (int) 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
|
|
|
}
|
|
|
|
|
1999-11-25 11:54:08 +00:00
|
|
|
- (int) indexOfItemWithTarget: (id)target
|
|
|
|
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];
|
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];
|
|
|
|
NSMenuItem *oldSelectedItem = [_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
|
|
|
{
|
1999-12-16 03:07:14 +00:00
|
|
|
NSMenuView *mr = [[_cell menu] menuRepresentation];
|
2001-09-28 23:37:37 +00:00
|
|
|
NSWindow *menuWindow = [mr window];
|
1999-12-11 02:57:23 +00:00
|
|
|
NSEvent *e;
|
2000-02-19 00:40:47 +00:00
|
|
|
NSPoint p;
|
2003-04-10 15:05:50 +00:00
|
|
|
int lastSelectedItem = [_cell indexOfSelectedItem];
|
2003-01-21 01:17:26 +00:00
|
|
|
int highlightedItemIndex;
|
2000-02-19 00:40:47 +00:00
|
|
|
|
1999-12-11 02:57:23 +00:00
|
|
|
if ([self isEnabled] == NO)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Attach the popUp
|
2000-01-10 02:04:25 +00:00
|
|
|
[_cell attachPopUpWithFrame: _bounds
|
2001-07-03 18:14:35 +00:00
|
|
|
inView: self];
|
|
|
|
|
2000-03-08 16:45:44 +00:00
|
|
|
p = [_window convertBaseToScreen: [theEvent locationInWindow]];
|
2001-07-03 18:14:35 +00:00
|
|
|
p = [menuWindow convertScreenToBase: p];
|
|
|
|
|
1999-12-11 02:57:23 +00:00
|
|
|
// Process events; we start menu events processing by converting
|
|
|
|
// this event to the menu window, and sending it there.
|
|
|
|
e = [NSEvent mouseEventWithType: [theEvent type]
|
2000-02-19 00:40:47 +00:00
|
|
|
location: p
|
1999-12-11 02:57:23 +00:00
|
|
|
modifierFlags: [theEvent modifierFlags]
|
|
|
|
timestamp: [theEvent timestamp]
|
2001-07-03 18:14:35 +00:00
|
|
|
windowNumber: [menuWindow windowNumber]
|
2001-09-28 23:37:37 +00:00
|
|
|
context: [theEvent context]
|
1999-12-11 02:57:23 +00:00
|
|
|
eventNumber: [theEvent eventNumber]
|
|
|
|
clickCount: [theEvent clickCount]
|
|
|
|
pressure: [theEvent pressure]];
|
2003-02-21 23:50:21 +00:00
|
|
|
[NSApp sendEvent: e];
|
1999-12-11 02:57:23 +00:00
|
|
|
|
2003-01-21 01:17:26 +00:00
|
|
|
// Selection remains unchanged if selected item is disabled
|
2003-04-10 15:05:50 +00:00
|
|
|
// or mouse left menu.
|
|
|
|
highlightedItemIndex = [_cell indexOfSelectedItem];
|
|
|
|
if ((highlightedItemIndex >= 0
|
|
|
|
&& [[self itemAtIndex: highlightedItemIndex] isEnabled] == NO)
|
|
|
|
|| highlightedItemIndex == lastSelectedItem)
|
2003-01-21 01:17:26 +00:00
|
|
|
{
|
2003-04-10 15:05:50 +00:00
|
|
|
[mr setHighlightedItemIndex: lastSelectedItem];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[mr setHighlightedItemIndex: highlightedItemIndex];
|
2003-01-21 01:17:26 +00:00
|
|
|
}
|
|
|
|
|
1999-12-11 02:57:23 +00:00
|
|
|
// Dismiss the popUp
|
1999-12-16 03:07:14 +00:00
|
|
|
[_cell dismissPopUp];
|
1999-12-11 06:05:08 +00:00
|
|
|
|
2001-09-28 23:37:37 +00:00
|
|
|
// Update our selected item
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2002-01-10 21:13:39 +00:00
|
|
|
/* Private method which covers an obscure case where the user uses the
|
|
|
|
keyboard to open a popup, but subsequently uses the mouse to select
|
|
|
|
an item. We'll never know this was done (and thus cannot dismiss
|
|
|
|
the popUp) without getting this notification */
|
|
|
|
- (void) _handleNotification: (NSNotification*)aNotification
|
|
|
|
{
|
|
|
|
NSString *name = [aNotification name];
|
|
|
|
if ([name isEqual: NSMenuDidSendActionNotification] == YES)
|
|
|
|
{
|
|
|
|
[_cell dismissPopUp];
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-22 00:27:37 +00:00
|
|
|
- (void) keyDown: (NSEvent*)theEvent
|
|
|
|
{
|
|
|
|
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:
|
|
|
|
case ' ':
|
|
|
|
{
|
2002-01-10 21:13:39 +00:00
|
|
|
int selectedIndex;
|
2001-09-28 23:37:37 +00:00
|
|
|
NSMenuView *menuView;
|
2002-01-10 21:13:39 +00:00
|
|
|
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
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];
|
|
|
|
|
|
|
|
|
2002-01-10 21:13:39 +00:00
|
|
|
selectedIndex = [self indexOfSelectedItem];
|
2001-03-22 00:27:37 +00:00
|
|
|
if (selectedIndex > -1)
|
2001-09-28 23:37:37 +00:00
|
|
|
[menuView setHighlightedItemIndex: selectedIndex];
|
2002-01-10 21:13:39 +00:00
|
|
|
|
|
|
|
/* This covers an obscure case where the user subsequently
|
|
|
|
uses the mouse to select an item. We'll never know
|
|
|
|
this was done (and thus cannot dismiss the popUp) without
|
|
|
|
getting this notification */
|
|
|
|
[nc addObserver: self
|
|
|
|
selector: @selector(_handleNotification:)
|
|
|
|
name: NSMenuDidSendActionNotification
|
|
|
|
object: [_cell menu]];
|
|
|
|
|
2001-03-22 00:27:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-01-10 21:13:39 +00:00
|
|
|
[nc removeObserver: self
|
|
|
|
name: NSMenuDidSendActionNotification
|
|
|
|
object: [_cell menu]];
|
|
|
|
selectedIndex = [menuView highlightedItemIndex];
|
|
|
|
[[_cell menu] performActionForItemAtIndex: selectedIndex];
|
2001-03-22 00:27:37 +00:00
|
|
|
|
|
|
|
// Dismiss the popUp
|
|
|
|
[_cell dismissPopUp];
|
|
|
|
|
2001-09-28 23:37:37 +00:00
|
|
|
// Update our selected item
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
2001-03-22 00:27:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case '\e':
|
|
|
|
[_cell dismissPopUp];
|
|
|
|
return;
|
|
|
|
case NSUpArrowFunctionKey:
|
|
|
|
{
|
|
|
|
NSMenuView *menuView;
|
|
|
|
int selectedIndex, numberOfItems;
|
|
|
|
|
|
|
|
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;
|
|
|
|
int selectedIndex, numberOfItems;
|
|
|
|
|
|
|
|
menuView = [[_cell menu] menuRepresentation];
|
|
|
|
selectedIndex = [menuView highlightedItemIndex];
|
|
|
|
numberOfItems = [self numberOfItems];
|
|
|
|
|
|
|
|
if (selectedIndex < numberOfItems-1)
|
|
|
|
[menuView setHighlightedItemIndex: selectedIndex + 1];
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[super keyDown: theEvent];
|
|
|
|
}
|
|
|
|
|
2000-01-06 19:49:19 +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-02 08:58:30 +00:00
|
|
|
[super encodeWithCoder: aCoder];
|
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
|
|
|
{
|
2001-09-28 23:37:37 +00:00
|
|
|
return [super initWithCoder: aDecoder];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
1999-12-11 02:57:23 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@end
|