Copyright ã1994 by NeXT Computer, Inc.  All Rights Reserved.

NSMenu 

Inherits From:	NSPanel : NSWindow : NSResponder : NSObject

Conforms To:	NSCoding (NSResponder)
NSObject (NSObject)

Declared In:	AppKit/NSMenu.h 

Class Description

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

+ (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.

Initializing a New NSMenu 

- (id)initWithTitle:(NSString *)aTitle	Initializes and returns a new NSMenu using aTitle for its title.

Setting Up the Menu Commands 

- (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 NSMenuCell.

- (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.
atIndex:(unsigned int)index

- (NSMatrix *)itemMatrix	Returns the NSMatrix of NSMenuCell items.

- (void)setItemMatrix:(NSMatrix *)aMatrix	Replaces the current matrix of items with aMatrix.

Finding Menu Items 

- (id)cellWithTag:(int)aTag	Returns the NSMenuCell that has aTag as its tag.

Building Submenus 

- (NSMenuCell *)setSubmenu:(NSMenu *)aMenu	Makes aMenu a submenu controlled by aCell.
forItem:(NSMenuCell *)aCell

- (void)submenuAction:(id)sender	Activates a submenu attached to sender's NSMenu.

Managing NSMenu Windows 

- (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 items.

- (NSMenu *)supermenu	Returns the receiver's supermenu.

Displaying the Menu 

- (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 protocol.)