Class CPMenuItem

CPObject
    extended byCPMenuItem

@implementation CPMenuItem : CPObject

A CPMenuItem is added to a CPMenu. It has an action and a target for that action to be sent to whenever the item is 'activated'.


Method Summary
+(CPMenuItem)separatorItem
          Returns a new menu item separator.
-(id)initWithCoder:(CPCoder)aCoder
          Initializes the menu item from a coder.
-(id)initWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent
          Initializes the menu item with a title, action, and keyboard equivalent.
-(SEL)action
          Returns the item's action.
-(CPImage)alternateImage
          Returns the menu item's alternate image.
-(void)encodeWithCoder:(CPCoder)aCoder
          Writes the menu item out to a coder.
-(CPFont)font
          Returns the menu item's font.
-(BOOL)hasSubmenu
          Returns YES if the menu item has a submenu.
-(CPImage)image
          Returns the menu item's image.
-(unsigned)indentationLevel
          Returns the menu item's indentation level.
-(BOOL)isAlternate
          Returns YES if the menu item is an alternate for the previous item.
-(BOOL)isEnabled
          Returns YES if the item is enabled.
-(BOOL)isHidden
          Returns YES if the item is hidden.
-(BOOL)isHiddenOrHasHiddenAncestor
          Returns YES if the item is hidden or if one of it's supermenus is hidden.
-(BOOL)isHighlighted
          Returns YES if the menu item is highlighted.
-(BOOL)isSeparatorItem
          Returns YES if the menu item is a separator.
-(CPString)keyEquivalent
          Returns the keyboard shortcut for this menu item.
-(unsigned)keyEquivalentModifierMask
          Returns the item's keyboard shortcut modifier mask.
-(CPMenu)menu
          Returns the container menu of this item.
-(CPImage)mixedStateImage
          Returns the image shown when the menu item is in the 'mixed' state.
-(CPString)mnemonic
          Returns the menu items mnemonic character.
-(unsigned)mnemonicLocation
          Returns the index of the mnemonic character in the title.
-(CPImage)offStateImage
          Returns the image shown when the menu item is in the 'off' state.
-(CPImage)onStateImage
          Returns the image shown when the menu item is in the 'on' state.
-(id)representedObject
          Returns the item's represented object.
-(void)setAction:(SEL)anAction
          Sets the action that gets sent to the item's target when triggered.
-(void)setAlternate:(BOOL)isAlternate
          Sets whether this item is an alternate for the previous menu item.
-(void)setAlternateImage:(CPImage)anImage
          Sets the menu item's alternate image.
-(void)setEnabled:(BOOL)isEnabled
          Sets whether the menu item is enabled or not.
-(void)setFont:(CPFont)aFont
          Sets the font for the text of this menu item.
-(void)setHidden:(BOOL)isHidden
          Sets whether the item should be hidden.
-(void)setImage:(CPImage)anImage
          Sets the menu item's image.
-(void)setIndentationLevel:(unsigned)aLevel
          Sets the indentation level of the menu item.
-(void)setKeyEquivalent:(CPString)aString
          Sets the keyboard shortcut for this menu item.
-(void)setKeyEquivalentModifierMask:(unsigned)aMask
          Sets the modifier mask used for the item's keyboard shortcut.
-(void)setMenu:(CPMenu)aMenu
          Set the container menu of this item.
-(void)setMixedStateImage:(CPImage)anImage
          Sets the image that is shown when the menu item is in the 'mixed' state.
-(void)setMnemonicLocation:(unsigned)aLocation
          Sets the index of the mnemonic character in the title.
-(void)setOffStateImage:(CPImage)anImage
          Sets the image that is shown when the menu item is in the 'off' state.
-(void)setOnStateImage:(CPImage)anImage
          Sets the image that is shown when the menu item is in the 'on' state.
-(void)setRepresentedObject:(id)anObject
          Sets the menu item's represented object.
-(void)setState:(int)aState
          Sets the state of the menu item.
-(void)setSubmenu:(CPMenu)aMenu
          Sets the submenu for this item.
-(void)setTag:(int)aTag
          Sets the menu item's tag.
-(void)setTarget:(id)aTarget
          Sets the menu item's action target.
-(void)setTitle:(CPString)aTitle
          Sets the item's title.
-(void)setTitleWithMnemonicLocation:(CPString)aTitle
          Sets the title of the menu item and the mnemonic character.
-(void)setToolTip:(CPString)aToolTip
          Sets the tooltip for the menu item.
-(void)setView:(CPView)aView
          Sets the view for the menu item.
-(int)state
          Returns the menu item's current state.
-(CPMenu)submenu
          Returns the submenu of the item.
-(int)tag
          Returns the item's tag.
-(id)target
          Returns the item's action target.
-(CPString)title
          Returns the menu item's title.
-(CPString)toolTip
          Returns the item's tooltip.
-(CPView)view
          Returns the menu item's view.

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

separatorItem

+(CPMenuItem)separatorItem
Returns a new menu item separator.

initWithCoder

-(id)initWithCoder:(CPCoder)aCoder
Initializes the menu item from a coder.
Parameters:
aCoder - the coder from which to initialize
Returns:
the initialized menu item

initWithTitle

-(id)initWithTitle:(CPString)aTitle action:(SEL)anAction keyEquivalent:(CPString)aKeyEquivalent
Initializes the menu item with a title, action, and keyboard equivalent.
Parameters:
aTitle - the menu item's title
anAction - the action that gets triggered when the item is selected
aKeyEquivalent - the keyboard shortcut for the item
Returns:
the initialized menu item

action

-(SEL)action
Returns the item's action.

alternateImage

-(CPImage)alternateImage
Returns the menu item's alternate image

encodeWithCoder

-(void)encodeWithCoder:(CPCoder)aCoder
Writes the menu item out to a coder.
Parameters:
aCoder - the coder to write the menu item out to

font

-(CPFont)font
Returns the menu item's font

hasSubmenu

-(BOOL)hasSubmenu
Returns YES if the menu item has a submenu.

image

-(CPImage)image
Returns the menu item's image

indentationLevel

-(unsigned)indentationLevel
Returns the menu item's indentation level. This is a value between 0 and 15 (inclusive).

isAlternate

-(BOOL)isAlternate
Returns YES if the menu item is an alternate for the previous item.

isEnabled

-(BOOL)isEnabled
Returns YES if the item is enabled.

isHidden

-(BOOL)isHidden
Returns YES if the item is hidden.

isHiddenOrHasHiddenAncestor

-(BOOL)isHiddenOrHasHiddenAncestor
Returns YES if the item is hidden or if one of it's supermenus is hidden.

isHighlighted

-(BOOL)isHighlighted
Returns YES if the menu item is highlighted.

isSeparatorItem

-(BOOL)isSeparatorItem
Returns YES if the menu item is a separator.

keyEquivalent

-(CPString)keyEquivalent
Returns the keyboard shortcut for this menu item

keyEquivalentModifierMask

-(unsigned)keyEquivalentModifierMask
Returns the item's keyboard shortcut modifier mask. Can be a combination of:
CPShiftKeyMask
CPAlternateKeyMask
CPCommandKeyMask
CPControlKeyMask

menu

-(CPMenu)menu
Returns the container menu of this item

mixedStateImage

-(CPImage)mixedStateImage
Returns the image shown when the menu item is in the 'mixed' state.

mnemonic

-(CPString)mnemonic
Returns the menu items mnemonic character

mnemonicLocation

-(unsigned)mnemonicLocation
Returns the index of the mnemonic character in the title.

offStateImage

-(CPImage)offStateImage
Returns the image shown when the menu item is in the 'off' state.

onStateImage

-(CPImage)onStateImage
Returns the image shown when the menu item is in the 'on' state.

representedObject

-(id)representedObject
Returns the item's represented object.

setAction

-(void)setAction:(SEL)anAction
Sets the action that gets sent to the item's target when triggered.
Parameters:
anAction - the action to send

setAlternate

-(void)setAlternate:(BOOL)isAlternate
Sets whether this item is an alternate for the previous menu item.
Parameters:
isAlternate - YES denotes that this menu item is an alternate

setAlternateImage

-(void)setAlternateImage:(CPImage)anImage
Sets the menu item's alternate image
Parameters:
anImage - the menu item's alternate image

setEnabled

-(void)setEnabled:(BOOL)isEnabled
Sets whether the menu item is enabled or not
Parameters:
isEnabled - YES enables the item. NO disables it.

setFont

-(void)setFont:(CPFont)aFont
Sets the font for the text of this menu item
Parameters:
aFont - the font for the menu item

setHidden

-(void)setHidden:(BOOL)isHidden
Sets whether the item should be hidden. A hidden item can not be triggered by keyboard shortcuts.
Parameters:
isHidden - YES hides the item. NO reveals it.

setImage

-(void)setImage:(CPImage)anImage
Sets the menu item's image
Parameters:
anImage - the menu item's image

setIndentationLevel

-(void)setIndentationLevel:(unsigned)aLevel
Sets the indentation level of the menu item. Must be a value between 0 and 15 (inclusive).
Parameters:
aLevel - the item's new indentation level
Throws:
CPInvalidArgumentException - if aLevel is less than 0

setKeyEquivalent

-(void)setKeyEquivalent:(CPString)aString
Sets the keyboard shortcut for this menu item
Parameters:
aString - the keyboard shortcut

setKeyEquivalentModifierMask

-(void)setKeyEquivalentModifierMask:(unsigned)aMask
Sets the modifier mask used for the item's keyboard shortcut. Can be a combination of:
CPShiftKeyMask
CPAlternateKeyMask
CPCommandKeyMask
CPControlKeyMask
Parameters:
aMask

setMenu

-(void)setMenu:(CPMenu)aMenu
Set the container menu of this item.
Parameters:
aMenu - the item's container menu

setMixedStateImage

-(void)setMixedStateImage:(CPImage)anImage
Sets the image that is shown when the menu item is in the 'mixed' state.
Parameters:
anImage - the image to show

setMnemonicLocation

-(void)setMnemonicLocation:(unsigned)aLocation
Sets the index of the mnemonic character in the title. The character will be underlined and is used as a shortcut for navigation.
Parameters:
aLocation - the index of the character in the title

setOffStateImage

-(void)setOffStateImage:(CPImage)anImage
Sets the image that is shown when the menu item is in the 'off' state.
Parameters:
anImage - the image to show

setOnStateImage

-(void)setOnStateImage:(CPImage)anImage
Sets the image that is shown when the menu item is in the 'on' state.
Parameters:
anImage - the image to show

setRepresentedObject

-(void)setRepresentedObject:(id)anObject
Sets the menu item's represented object. This is a kind of tag for the developer. Not a UI feature.
Parameters:
anObject - the represented object

setState

-(void)setState:(int)aState
Sets the state of the menu item. Possible states are:
CPMixedState
CPOnState
CPOffState
Parameters:
aState

setSubmenu

-(void)setSubmenu:(CPMenu)aMenu
Sets the submenu for this item
Parameters:
aMenu - the submenu

setTag

-(void)setTag:(int)aTag
Sets the menu item's tag
Parameters:
aTag - the tag for the item

setTarget

-(void)setTarget:(id)aTarget
Sets the menu item's action target.
Parameters:
aTarget - the target for the action

setTitle

-(void)setTitle:(CPString)aTitle
Sets the item's title.
Parameters:
aTitle - the item's new title

setTitleWithMnemonicLocation

-(void)setTitleWithMnemonicLocation:(CPString)aTitle
Sets the title of the menu item and the mnemonic character. The mnemonic chracter should be preceded by an '&'.
Parameters:
aTitle - the title string with a denoted mnemonic

setToolTip

-(void)setToolTip:(CPString)aToolTip
Sets the tooltip for the menu item.
Parameters:
aToolTip - the tool tip for the item

setView

-(void)setView:(CPView)aView
Sets the view for the menu item
Parameters:
aView - the menu's item's view

state

-(int)state
Returns the menu item's current state. Possible states are:
CPMixedState
CPOnState
CPOffState

submenu

-(CPMenu)submenu
Returns the submenu of the item. nil if there is no submenu.

tag

-(int)tag
Returns the item's tag

target

-(id)target
Returns the item's action target

title

-(CPString)title
Returns the menu item's title.

toolTip

-(CPString)toolTip
Returns the item's tooltip

view

-(CPView)view
Returns the menu item's view

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