Class CPMenu

CPObject
    extended byCPMenu

@implementation CPMenu : CPObject

Menus provide the user with a list of actions and/or submenus. Submenus themselves are full fledged menus and so a heirarchical structure appears.


Method Summary
+(CPImage)menuBarIconImage
+(CPString)menuBarTitle
+(BOOL)menuBarVisible
+(void)popUpContextMenu:(CPMenu)aMenu withEvent:(CPEvent)anEvent forView:(CPView)aView
+(void)popUpContextMenu:(CPMenu)aMenu withEvent:(CPEvent)anEvent forView:(CPView)aView withFont:(CPFont)aFont
+(void)setMenuBarIconImage:(CPImage)anImage
+(void)setMenuBarTitle:(CPString)aTitle
+(void)setMenuBarVisible:(BOOL)menuBarShouldBeVisible
-(id)initWithCoder:(CPCoder)aCoder
          Initializes the menu with data from the specified coder.
-(id)initWithTitle:(CPString)aTitle
          Initializes the menu with a specified title.
-(void)addItem:(CPMenuItem)aMenuItem
          Adds a menu item at the end of the menu.
-(CPMenuItem)addItemWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent
          Creates and adds a menu item with the specified attributes at the end of the menu.
-(CPMenu)attachedMenu
          Returns the attaced menu, or nil if there isn't one.
-(BOOL)autoenablesItems
          Returns YES if the menu auto enables items.
-(void)cancelTracking
          Cancels tracking.
-(id)delegate
-(void)encodeWithCoder:(CPCoder)aCoder
          Encodes the data of the menu into a coder.
-(CPMenuItem)highlightedItem
          Returns the currently highlighted menu item.
-(int)indexOfItem:(CPMenuItem)aMenuItem
          Returns the index of the specified menu item.
-(int)indexOfItemWithRepresentedObject:(id)anObject
          Returns the index of the menu item with the specified represented object.
-(int)indexOfItemWithSubmenu:(CPMenu)aMenu
          Returns the index of the item with the specified submenu.
-(int)indexOfItemWithTag:(int)aTag
          Returns the index of the item with the specified tag.
-(int)indexOfItemWithTarget:(id)aTarget andAction:(SEL)anAction
          Returns the index of the item with the specified target and action.
-(int)indexOfItemWithTitle:(CPString)aTitle
          Returns the index of the item with the specified title.
-(CPMenuItem)insertItemWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent atIndex:(unsigned)anIndex
          Creates and inserts a new menu item with the specified attributes.
-(void)insertItem:(CPMenuItem)aMenuItem atIndex:(unsigned)anIndex
          Inserts a menu item at the specified index.
-(BOOL)isAttached
          Returns YES if the menu is attached to another menu.
-(BOOL)isTornOff
          If there are two instances of this menu visible, return NO.
-(CPArray)itemArray
          Returns the array of menu items backing this menu.
-(CPMenuItem)itemAtIndex:(int)anIndex
          Returns the menu item at the specified index.
-(void)itemChanged:(CPMenuItem)aMenuItem
          Called when a menu item has visually changed.
-(CGPoint)locationOfSubmenu:(CPMenu)aMenu
          Not yet implemented.
-(float)menuBarHeight
-(CPMenuItem)menuWithTag:(int)aTag
          Returns the menu item with the specified tag.
-(CPMenuItem)menuWithTitle:(CPString)aTitle
          Returns the menu item with the specified title.
-(unsigned)numberOfItems
          Returns the number of menu items in the menu.
-(void)performActionForItemAtIndex:(unsigned)anIndex
          Sends the action of the menu item at the specified index.
-(BOOL)performKeyEquivalent:(CPEvent)anEvent
          Initiates the action of the menu item that has a keyboard shortcut equivalent to anEvent.
-(void)removeItem:(CPMenuItem)aMenuItem
          Removes the specified item from the menu.
-(void)removeItemAtIndex:(unsigned)anIndex
          Removes the item at the specified index from the menu.
-(void)setAutoenablesItems:(BOOL)aFlag
          Sets whether the menu automatically enables menu items.
-(void)setDelegate:(id)aDelegate
-(void)setShowsStateColumn:(BOOL)shouldShowStateColumn
          Sets whether to show the state column.
-(void)setSubmenu:(CPMenu)aMenu forItem:(CPMenuItem)aMenuItem
          Sets a submenu for a menu item.
-(void)setSupermenu:(CPMenu)aMenu
          Sets the super menu.
-(void)setTitle:(CPString)aTitle
          Sets the menu title.
-(BOOL)showsStateColumn
          Returns YES if the menu shows the state column.
-(void)submenuAction:(id)aSender
          The action method of menu items that open submenus.
-(CPMenu)supermenu
          Returns the super menu or nil if there is none.
-(CPString)title
          Returns the menu title.
-(void)update
          Not implemented.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass


Method Detail

menuBarIconImage

+(CPImage)menuBarIconImage

menuBarTitle

+(CPString)menuBarTitle

menuBarVisible

+(BOOL)menuBarVisible

popUpContextMenu

+(void)popUpContextMenu:(CPMenu)aMenu withEvent:(CPEvent)anEvent forView:(CPView)aView
Parameters:
aMenu
anEvent
aView

popUpContextMenu

+(void)popUpContextMenu:(CPMenu)aMenu withEvent:(CPEvent)anEvent forView:(CPView)aView withFont:(CPFont)aFont
Parameters:
aMenu
anEvent
aView
aFont

setMenuBarIconImage

+(void)setMenuBarIconImage:(CPImage)anImage
Parameters:
anImage

setMenuBarTitle

+(void)setMenuBarTitle:(CPString)aTitle
Parameters:
aTitle

setMenuBarVisible

+(void)setMenuBarVisible:(BOOL)menuBarShouldBeVisible
Parameters:
menuBarShouldBeVisible

initWithCoder

-(id)initWithCoder:(CPCoder)aCoder
Initializes the menu with data from the specified coder.
Parameters:
aCoder - the coder from which to read the data
Returns:
the initialized menu

initWithTitle

-(id)initWithTitle:(CPString)aTitle
Initializes the menu with a specified title.
Parameters:
aTitle
Returns:
the initialized menu

addItem

-(void)addItem:(CPMenuItem)aMenuItem
Adds a menu item at the end of the menu.
Parameters:
aMenuItem - the menu item to add

addItemWithTitle

-(CPMenuItem)addItemWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent
Creates and adds a menu item with the specified attributes at the end of the menu.
Parameters:
aTitle - the title of the new menu item
anAction - the action initiated when the user selects the item
aKeyEquivalent - the keyboard shortcut for the menu item
Returns:
the new menu item

attachedMenu

-(CPMenu)attachedMenu
Returns the attaced menu, or nil if there isn't one.

autoenablesItems

-(BOOL)autoenablesItems
Returns YES if the menu auto enables items.

cancelTracking

-(void)cancelTracking
Cancels tracking.

delegate

-(id)delegate

encodeWithCoder

-(void)encodeWithCoder:(CPCoder)aCoder
Encodes the data of the menu into a coder
Parameters:
aCoder - the coder to which the data will be written

highlightedItem

-(CPMenuItem)highlightedItem
Returns the currently highlighted menu item.
Returns:
the highlighted menu item or nil if no item is currently highlighted

indexOfItem

-(int)indexOfItem:(CPMenuItem)aMenuItem
Returns the index of the specified menu item
Parameters:
aMenuItem - the item to find the index for
Returns:
the item index or CPNotFound

indexOfItemWithRepresentedObject

-(int)indexOfItemWithRepresentedObject:(id)anObject
Returns the index of the menu item with the specified represented object.
Parameters:
anObject - the represented object of the desired item
Returns:
the index of the item or CPNotFound

indexOfItemWithSubmenu

-(int)indexOfItemWithSubmenu:(CPMenu)aMenu
Returns the index of the item with the specified submenu.
Parameters:
aMenu
Returns:
the index of the item or CPNotFound

indexOfItemWithTag

-(int)indexOfItemWithTag:(int)aTag
Returns the index of the item with the specified tag
Parameters:
aTag - the desired tag to match
Returns:
the index of the item or CPNotFound

indexOfItemWithTarget

-(int)indexOfItemWithTarget:(id)aTarget andAction:(SEL)anAction
Returns the index of the item with the specified target and action.
Parameters:
aTarget - the target of the desired menu item
anAction - the action of the desired menu item
Returns:
the index of the item or CPNotFound

indexOfItemWithTitle

-(int)indexOfItemWithTitle:(CPString)aTitle
Returns the index of the item with the specified title.
Parameters:
aTitle - the desired title to match
Returns:
the index of the item or CPNotFound

insertItemWithTitle

-(CPMenuItem)insertItemWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent atIndex:(unsigned)anIndex
Creates and inserts a new menu item with the specified attributes.
Parameters:
aTitle - the title of the menu item
anAction - the action initiated when the user selects the item
aKeyEquivalent - the keyboard shortcut for the item
anIndex - the index location in the menu for the new item
Returns:
the new menu item

insertItem

-(void)insertItem:(CPMenuItem)aMenuItem atIndex:(unsigned)anIndex
Inserts a menu item at the specified index.
Parameters:
aMenuItem - the item to insert
anIndex - the index in the menu to insert the item.

isAttached

-(BOOL)isAttached
Returns YES if the menu is attached to another menu.

isTornOff

-(BOOL)isTornOff
If there are two instances of this menu visible, return NO. Otherwise, return YES if we are a detached menu and visible.

itemArray

-(CPArray)itemArray
Returns the array of menu items backing this menu

itemAtIndex

-(CPMenuItem)itemAtIndex:(int)anIndex
Returns the menu item at the specified index
Parameters:
anIndex - the index of the requested item

itemChanged

-(void)itemChanged:(CPMenuItem)aMenuItem
Called when a menu item has visually changed.
Parameters:
aMenuItem - the item that changed

locationOfSubmenu

-(CGPoint)locationOfSubmenu:(CPMenu)aMenu
Not yet implemented
Parameters:
aMenu

menuBarHeight

-(float)menuBarHeight

menuWithTag

-(CPMenuItem)menuWithTag:(int)aTag
Returns the menu item with the specified tag
Parameters:
aTag
Returns:
the menu item or nil if a match was not found

menuWithTitle

-(CPMenuItem)menuWithTitle:(CPString)aTitle
Returns the menu item with the specified title.
Parameters:
aTitle - the title of the menu item
Returns:
the menu item or nil if a match was not found

numberOfItems

-(unsigned)numberOfItems
Returns the number of menu items in the menu

performActionForItemAtIndex

-(void)performActionForItemAtIndex:(unsigned)anIndex
Sends the action of the menu item at the specified index.
Parameters:
anIndex - the index of the item

performKeyEquivalent

-(BOOL)performKeyEquivalent:(CPEvent)anEvent
Initiates the action of the menu item that has a keyboard shortcut equivalent to anEvent
Parameters:
anEvent - the keyboard event
Returns:
YES if it was handled.

removeItem

-(void)removeItem:(CPMenuItem)aMenuItem
Removes the specified item from the menu
Parameters:
aMenuItem - the item to remove

removeItemAtIndex

-(void)removeItemAtIndex:(unsigned)anIndex
Removes the item at the specified index from the menu
Parameters:
anIndex - the index of the item to remove

setAutoenablesItems

-(void)setAutoenablesItems:(BOOL)aFlag
Sets whether the menu automatically enables menu items.
Parameters:
aFlag - YES sets the menu to automatically enable items.

setDelegate

-(void)setDelegate:(id)aDelegate
Parameters:
aDelegate

setShowsStateColumn

-(void)setShowsStateColumn:(BOOL)shouldShowStateColumn
Sets whether to show the state column
Parameters:
shouldShowStateColumn - YES shows the state column

setSubmenu

-(void)setSubmenu:(CPMenu)aMenu forItem:(CPMenuItem)aMenuItem
Sets a submenu for a menu item
Parameters:
aMenu - the submenu
aMenuItem - the menu item to set the submenu on

setSupermenu

-(void)setSupermenu:(CPMenu)aMenu
Sets the super menu.
Parameters:
aMenu - the new super menu

setTitle

-(void)setTitle:(CPString)aTitle
Sets the menu title.
Parameters:
aTitle

showsStateColumn

-(BOOL)showsStateColumn
Returns YES if the menu shows the state column

submenuAction

-(void)submenuAction:(id)aSender
The action method of menu items that open submenus. The default implementation does nothing, but it may be subclassed to provide different behavior.
Parameters:
aSender - the object that sent the message

supermenu

-(CPMenu)supermenu
Returns the super menu or nil if there is none.

title

-(CPString)title
Returns the menu title

update

-(void)update
Not implemented.

Created on Sat Sep 13 14:15:43 PDT 2008