Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.0 and later. |
Companion guide | |
Declared in | NSMenuItemCell.h |
NSMenuItemCell
is a class that handles the measurement and display of a single menu item in its encompassing frame. Instances of NSMenuItemCell
work in conjunction with an NSMenuView
object to control the overall appearance of the menu.
Note: NSMenuItemCell
is no longer used to draw menus. Using it will not affect the appearance of your menus.
– calcSize
– needsSizing
– setNeedsSizing:
– imageWidth
– titleWidth
– keyEquivalentWidth
– stateImageWidth
– drawBorderAndBackgroundWithFrame:inView:
– drawImageWithFrame:inView:
– drawKeyEquivalentWithFrame:inView:
– drawSeparatorItemWithFrame:inView:
– drawStateImageWithFrame:inView:
– drawTitleWithFrame:inView:
– needsDisplay
– setNeedsDisplay:
Calculates the minimum required width and height of the receiver’s menu item.
- (void)calcSize
The calculated values are cached for future use. This method also calculates the sizes of individual components of the cell’s menu item and caches those values.
This method is invoked automatically when necessary. You should not need to invoke it directly.
NSMenuItemCell.h
Draws the borders and background associated with the receiver’s menu item (if any).
- (void)drawBorderAndBackgroundWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
A rectangle defining the receiver's frame area.
The view object that contains this cell (usually an NSControl
object).
This method invokes the NSCell
method imageRectForBounds:
, passing it cellFrame, to calculate the rectangle in which to draw the image. The cell invokes this method before invoking the methods to draw the other menu item components.
– drawWithFrame:inView:
(NSCell)NSMenuItemCell.h
Draws the image associated with the menu item.
- (void)drawImageWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
A rectangle defining the receiver's frame area.
The view object that contains this cell (usually an NSControl
object).
This method invokes the NSCell
method imageRectForBounds:
, passing it cellFrame, to calculate the rectangle in which to draw the image. This method is invoked by the cell’s drawWithFrame:
method. You should not need to invoke it directly. Subclasses may override this method to control the drawing of the image.
NSMenuItemCell.h
Draws the key equivalent associated with the menu item.
- (void)drawKeyEquivalentWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
A rectangle defining the receiver's frame area.
The view object that contains this cell (usually an NSControl
object).
This method invokes keyEquivalentRectForBounds:
, passing it cellFrame, to calculate the rectangle in which to draw the key equivalent. This method is invoked by the cell’s drawWithFrame:
method. You should not need to invoke it directly. Subclasses may override this method to control the drawing of the key equivalent.
NSMenuItemCell.h
Draws a menu item separator.
- (void)drawSeparatorItemWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
A rectangle defining the receiver's frame area.
The view object that contains this cell (usually an NSControl
object).
This method uses the cellFrame parameter to calculate the rectangle in which to draw the menu item separator. This method uses the controlView to determine whether the separator item should be drawn normally or flipped.
You should not need to invoke this method directly. Subclasses may override this method to control the drawing of the separator.
NSMenuItemCell.h
Draws the state image associated with the menu item.
- (void)drawStateImageWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
A rectangle defining the receiver's frame area.
The view object that contains this cell (usually an NSControl
object).
This method invokes stateImageRectForBounds:
, passing it cellFrame, to calculate the rectangle in which to draw the state image. This method is invoked by the cell’s drawWithFrame:
method. You should not need to invoke it directly. Subclasses may override this method to control the drawing of the state image.
NSMenuItemCell.h
Draws the title associated with the menu item.
- (void)drawTitleWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
A rectangle defining the receiver's frame area.
The view object that contains this cell (usually an NSControl
object).
This method invokes titleRectForBounds:
, passing it cellFrame, to calculate the rectangle in which to draw the title. The controlView parameter specifies the view that contains this cell.This method is invoked by the cell’s drawWithFrame:
method. You should not need to invoke it directly. Subclasses may override this method to control the drawing of the title.
NSMenuItemCell.h
Returns the width of the image associated with a menu item.
- (CGFloat)imageWidth
You can associate an image with a menu item using the NSMenuItem
setImage:
method.
NSMenuItemCell.h
Returns the rectangle into which the menu item’s key equivalent should be drawn.
- (NSRect)keyEquivalentRectForBounds:(NSRect)cellFrame
A rectangle that defines the bounds of the receiver.
The returned rectangle is based on cellFrame but encompasses only the area to be occupied by the key equivalent.
– keyEquivalent
(NSMenuItem)– stateImageRectForBounds:
– titleRectForBounds:
– keyEquivalentRectForBounds:
NSMenuItemCell.h
Returns the width of the key equivalent associated with the menu item.
- (CGFloat)keyEquivalentWidth
You can associate a key equivalent with a menu item using the NSMenuItem
method setKeyEquivalent:
.
NSMenuItemCell.h
Returns the NSMenuItem
object associated with the receiver.
- (NSMenuItem *)menuItem
NSMenuItemCell.h
Returns the menu view associated with the receiver.
- (NSMenuView *)menuView
NSMenuItemCell.h
Returns YES
if the menu item needs to be displayed; otherwise returns NO
.
- (BOOL)needsDisplay
NSMenuItemCell.h
Returns YES
if the size of the menu item needs to be calculated; otherwise returns NO
.
- (BOOL)needsSizing
NSMenuItemCell.h
Sets the NSMenuItem
object associated withthe receive.
- (void)setMenuItem:(NSMenuItem *)item
The NSMenuItem
object to set.
NSMenuItemCell.h
Sets the menu view for the receiver.
- (void)setMenuView:(NSMenuView *)menuView
The NSMenuView
object to associate with the receiver.
NSMenuItemCell.h
Sets whether the menu item needs to be drawn.
- (void)setNeedsDisplay:(BOOL)flag
YES
if the menu item needs to be drawn, NO
otherwise.
NSMenuItemCell.h
Sets a flag that indicates whether or not the menu item must be resized.
- (void)setNeedsSizing:(BOOL)flag
If flag is YES
, the next attempt to obtain any size-related information from this menu item cell invokes the calcSize
method to recalculate the information. If flag is NO
, the next attempt to obtain size-related information returns the currently cached values.
Subclasses that drastically change the way a menu item is drawn may need to invoke this method to recalculate the menu item information. Other parts of your application should not need to invoke this method directly. The cell invokes this method as necessary when the content of its menu item changes.
NSMenuItemCell.h
Returns the rectangle into which the menu item’s state image should be drawn.
- (NSRect)stateImageRectForBounds:(NSRect)cellFrame
A rectangle that defines the bounds of the receiver.
The returned rectangle is based on cellFrame but encompasses only the area to be occupied by the menu item’s state image.
NSMenuItemCell.h
Returns the width of the image used to indicate the state of the menu item.
- (CGFloat)stateImageWidth
If the menu item has multiple images associated with it (to indicate any of the available states: on, off, or mixed), this method returns the width of the largest image. You can set the state images for a menu item using the NSMenuItem
methods setOnStateImage:
, setOffStateImage:
, and setMixedStateImage:
.
To change the state of the cell’s menu item, use the NSMenuItem
method setState:
.
– calcSize
– needsSizing
– setState:
(NSMenuItem)NSMenuItemCell.h
Returns the integer tag of the selected menu item, or 0 if no item is selected.
- (NSInteger)tag
Setting the tag value of an NSMenuItemCell
object with setTag:
does nothing.
– setTag:
(NSActionCell)NSMenuItemCell.h
Returns the rectangle into which the menu item’s title should be drawn.
- (NSRect)titleRectForBounds:(NSRect)cellFrame
A rectangle that defines the bounds of the receiver.
The returned rectangle is based on cellFrame but encompasses only the area to be occupied by the text of the title.
NSMenuItemCell.h
Returns the width of the menu item text.
- (CGFloat)titleWidth
To set the menu item text, use NSMenuItem’s setTitle:
method.
NSMenuItemCell.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-03-07)