Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 1994 by NeXT Computer, Inc. All Rights
Inherits From: NSPanel : NSWindow : NSResponder : NSObject
Conforms To: NSCoding (NSResponder)
Declared In: AppKit/NSMenu.h
This class defines an object that manages an application's menus. An NSMenu
object displays a list of items that a user can choose from. When an item is
clicked, it may either issue a command directly or bring up another menu (a
submenu) that offers further choices. An NSMenu object's choices are
implemented as a column of NSMenuCells in an NSMatrix.
Each NSMenuCell can be configured to send its action message to a target, or to
bring up a submenu. When the user clicks a submenu item, the submenu is
displayed on the screen, attached to its supermenu so that if the user drags
the supermenu, the submenu follows it. A submenu may also be torn away from its
supermenu, in which case it displays a close button.
Exactly one NSMenu created by the application is designated as the main menu
for the application (with NSApplication's setMainMenu: method). This
menu is displayed on top of all other windows whenever the application is
active, and should never display a close button (because the main menu doesn't
have a supermenu).
See the NSMenuCell and NSMatrix class specificiations for more details.
Controlling Allocation Zones
Initializing a New NSMenu
- + (NSZone *)menuZone Returns the zone from which NSMenus should be
allocated, creating one if necessary.
- + (void)setMenuZone:(NSZone *)zone Sets the zone from which
NSMenus should be allocated.
Setting Up the Menu Commands
- - (id)initWithTitle:(NSString *)aTitle Initializes and returns a
new NSMenu using aTitle for its title.
Finding Menu Items
- - (id)addItemWithTitle:(NSString *)aString Adds a new item with
title aString, action aSelector, and
action:(SEL)aSelector key equivalent charCode to the end
of the NSMenu.
keyEquivalent:(NSString *)charCode Returns the new
- - (id)insertItemWithTitle:(NSString *)aString Adds a new item at
index having the title aString, action
action:(SEL)aSelector aSelector, and key equivalent
charCode. Returns the
keyEquivalent:(NSString *)charCode new NSMenuCell.
- - (NSMatrix *)itemMatrix Returns the NSMatrix of NSMenuCell items.
- - (void)setItemMatrix:(NSMatrix *)aMatrix Replaces the current
matrix of items with aMatrix.
- - (id)cellWithTag:(int)aTag Returns the NSMenuCell that has
aTag as its tag.
Managing NSMenu Windows
- - (NSMenuCell *)setSubmenu:(NSMenu *)aMenu Makes aMenu a
submenu controlled by aCell.
- - (void)submenuAction:(id)sender Activates a submenu attached to
Displaying the Menu
- - (NSMenu *)attachedMenu Returns the NSMenu attached to the receiver or
nil if there's no such object.
- - (BOOL)isAttached Returns YES if the receiver is attached to another
menu and NO otherwise.
- - (BOOL)isTornOff Returns NO if the receiver is attached to another menu
(or if it's the main menu) and YES otherwise.
- - (NSPoint)locationForSubmenu:(NSMenu *)aSubmenu
Determines where to display an attached submenu when it's brought up.
- - (void)sizeToFit Resizes the receiver to exactly fit the command
- - (NSMenu *)supermenu Returns the receiver's supermenu.
- - (BOOL)autoenablesItems Returns whether the receiver enables and
disables its NSMenuCells. (See the NSMenuActionResponder informal protocol.)
- - (void)setAutoenablesItems:(BOOL)flag Sets whether the receiver
enables and disables its NSMenuCells. (See the NSMenuActionResponder informal