1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSPopUpButton.m
|
|
|
|
|
|
|
|
Popup list class
|
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
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
|
|
|
*/
|
|
|
|
|
1997-09-23 22:43:24 +00:00
|
|
|
#include <gnustep/gui/config.h>
|
1999-06-30 03:10:38 +00:00
|
|
|
#import <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>
|
1999-07-18 03:53:42 +00:00
|
|
|
#include <AppKit/NSMenuView.h>
|
1999-06-20 10:13:34 +00:00
|
|
|
#include <AppKit/NSFont.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-11-22 21:48:03 +00:00
|
|
|
//
|
|
|
|
// class variables
|
|
|
|
//
|
|
|
|
id _nspopupbuttonCellClass = nil;
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// NSPopUpButton implementation
|
|
|
|
//
|
1999-07-18 03:53:42 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSPopUpButton
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
if (self == [NSPopUpButton class])
|
|
|
|
{
|
|
|
|
// Initial version
|
|
|
|
[self setVersion:1];
|
1999-11-22 21:48:03 +00:00
|
|
|
[self setCellClass: [NSPopUpButtonCell class]];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
1999-11-22 21:48:03 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Initializing an NSPopUpButton
|
|
|
|
//
|
1999-11-22 21:48:03 +00:00
|
|
|
- (id)init
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
|
|
|
return [self initWithFrame:NSZeroRect pullsDown:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithFrame:(NSRect)frameRect
|
|
|
|
{
|
|
|
|
return [self initWithFrame:frameRect pullsDown:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithFrame:(NSRect)frameRect
|
|
|
|
pullsDown:(BOOL)flag
|
|
|
|
{
|
1999-07-30 22:10:02 +00:00
|
|
|
NSNotificationCenter* defaultCenter = [NSNotificationCenter defaultCenter];
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
[super initWithFrame:frameRect];
|
1999-07-18 03:53:42 +00:00
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
[defaultCenter addObserver: self
|
|
|
|
selector: @selector(_popup:)
|
|
|
|
name: NSPopUpButtonWillPopUpNotification
|
|
|
|
object: self];
|
1999-07-28 10:50:30 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (void)setMenu:(NSMenu *)menu
|
1999-07-28 10:50:30 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell setMenu: menu];
|
1999-07-28 10:50:30 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (NSMenu *)menu
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell menu];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (void)setPullsDown:(BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell setPullsDown: flag];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (BOOL)pullsDown
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell pullsDown];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (void)setAutoenablesItems:(BOOL)flag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell setAutoenablesItems: flag];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (BOOL)autoenablesItems
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell autoenablesItems];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addItemWithTitle:(NSString *)title
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell addItemWithTitle: title];
|
|
|
|
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)addItemsWithTitles:(NSArray *)itemTitles
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell addItemWithTitles: 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
|
|
|
|
|
|
|
- (void)insertItemWithTitle:(NSString *)title
|
1999-07-30 22:10:02 +00:00
|
|
|
atIndex:(int)index
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell insertItemWithTitle: title adIndex: 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
|
|
|
|
|
|
|
- (void)removeAllItems
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +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
|
|
|
|
|
|
|
- (void)removeItemWithTitle:(NSString *)title
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell removeItemWithTitle];
|
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
|
|
|
|
|
|
|
- (void)removeItemAtIndex:(int)index
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +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-07-30 22:10:02 +00:00
|
|
|
- (id <NSMenuItem>)selectedItem
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell selectedItem];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
1998-01-30 00:34:25 +00:00
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (NSString *)titleOfSelectedItem
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell titleOfSelectedItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int)indexOfSelectedItem
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell indexOfSelectedItem];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectItem:(id <NSMenuItem>)anObject
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell selectedItem: anObject];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectItemAtIndex:(int)index
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell selectItemAtIndex: index];
|
|
|
|
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectItemWithTitle:(NSString *)title
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell selectItemWithTitle: title];
|
|
|
|
|
|
|
|
[self synchronizeTitleAndSelectedItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int)numberOfItems
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell numberOfItems];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (NSArray *)itemArray
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell itemArray];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (id <NSMenuItem>)itemAtIndex:(int)index
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell itemAtIndex: index];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)itemTitleAtIndex:(int)index
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell itemTitleAtIndex: index];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)itemTitles
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell itemTitles];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1998-01-30 00:34:25 +00:00
|
|
|
- (id <NSMenuItem>)itemWithTitle:(NSString *)title
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell itemWithTitle: title];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1998-01-30 00:34:25 +00:00
|
|
|
- (id <NSMenuItem>)lastItem
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell lastItem];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (int)indexOfItem:(id <NSMenuItem>)anObject
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell indexOfItem: anObject];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (int)indexOfItemWithTag:(int)tag
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell indexOfItemWithTag: tag];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (int)indexOfItemWithTitle:(NSString *)title
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell indexOfItemWithTitle: title];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (int)indexOfItemWithRepresentedObject:(id)anObject
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell indexOfItemWithRepresentedObject: anObject];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (int)indexOfItemWithTarget:(id)target
|
|
|
|
andAction:(SEL)actionSelector
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell indexOfItemWithTarget: target andAction: actionSelector];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (void)setPreferredEdge:(NSRectEdge)edge
|
1998-01-30 00:34:25 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell setPreferredEdge: edge];
|
1998-01-30 00:34:25 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (NSRectEdge)preferredEdge
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
return [cell preferredEdge];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-08-19 23:18:25 +00:00
|
|
|
- (void)setTitle:(NSString *)aString
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell setTitle: aString];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (void)synchronizeTitleAndSelectedItem
|
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell synchronizeTitleAndSelectedItem];
|
1999-08-19 23:18:25 +00:00
|
|
|
|
|
|
|
[self sizeToFit];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)sizeToFit
|
|
|
|
{
|
1999-11-18 15:39:44 +00:00
|
|
|
[[popb_menu menuRepresentation] sizeToFit];
|
1999-09-09 02:56:20 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
1999-07-30 22:10:02 +00:00
|
|
|
- (void)_popup:(NSNotification*)notification
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-11-22 21:48:03 +00:00
|
|
|
[cell performClickWithFrame: [[notification object] frame]
|
|
|
|
inView: self];
|
1999-07-30 22:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mouseDown:(NSEvent *)theEvent
|
|
|
|
{
|
|
|
|
NSNotificationCenter *nc;
|
|
|
|
|
|
|
|
nc = [NSNotificationCenter defaultCenter];
|
|
|
|
[nc postNotificationName: NSPopUpButtonWillPopUpNotification
|
|
|
|
object: self
|
|
|
|
userInfo: nil];
|
1996-05-30 20:03:15 +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];
|
1999-07-30 22:10:02 +00:00
|
|
|
/*
|
1996-05-30 20:03:15 +00:00
|
|
|
[aCoder encodeObject: list_items];
|
|
|
|
[aCoder encodeRect: list_rect];
|
1999-03-02 08:58:30 +00:00
|
|
|
[aCoder encodeValueOfObjCType: @encode(int) at: &selected_item];
|
|
|
|
[aCoder encodeConditionalObject: pub_target];
|
1996-05-30 20:03:15 +00:00
|
|
|
[aCoder encodeValueOfObjCType: @encode(SEL) at: &pub_action];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &is_up];
|
|
|
|
[aCoder encodeValueOfObjCType: @encode(BOOL) at: &pulls_down];
|
1999-07-30 22:10:02 +00:00
|
|
|
*/
|
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
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[super initWithCoder: aDecoder];
|
1999-07-30 22:10:02 +00:00
|
|
|
/*
|
1999-03-02 08:58:30 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(id) at: &list_items];
|
1996-05-30 20:03:15 +00:00
|
|
|
list_rect = [aDecoder decodeRect];
|
1999-03-02 08:58:30 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(int) at: &selected_item];
|
1997-02-18 00:29:25 +00:00
|
|
|
pub_target = [aDecoder decodeObject];
|
1996-05-30 20:03:15 +00:00
|
|
|
[aDecoder decodeValueOfObjCType: @encode(SEL) at: &pub_action];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &is_up];
|
|
|
|
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &pulls_down];
|
1999-07-30 22:10:02 +00:00
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
@end
|