Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.application |
Companion guide |
Note: NSMenuItemCell and NSMenuView are deprecated and are no longer used to draw menus. Using them will not affect the appearance of your menus.
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.
drawBorderAndBackgroundWithFrameInView
drawImageWithFrameInView
drawKeyEquivalentWithFrameInView
drawSeparatorItemWithFrameInView
drawStateImageWithFrameInView
drawTitleWithFrameInView
needsDisplay
setNeedsDisplay
This class is deprecated and is no longer used to draw menus.
public NSMenuItemCell
()
Do not use this constructor.
This class is deprecated and is no longer used to draw menus.
public NSMenuItemCell
(String aString)
Do not use this constructor.
This class is deprecated and is no longer used to draw menus.
public NSMenuItemCell
(NSImage anImage)
Do not use this constructor.
Calculates the minimum required width and height of the receiver’s menu item.
public 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.
Draws the borders and background associated with the receiver’s menu item (if any).
public void drawBorderAndBackgroundWithFrameInView
(NSRect cellFrame, NSView controlView)
This method invokes imageRectForBounds
, passing it cellFrame, to calculate the rectangle in which to draw the image. The controlView parameter specifies the view that contains this cell. The cell invokes this method before invoking the methods to draw the other menu item components.
drawWithFrameInView
(NSCell)Draws the image associated with the menu item.
public void drawImageWithFrameInView
(NSRect cellFrame, NSView controlView)
This method invokes imageRectForBounds
, passing it cellFrame, to calculate the rectangle in which to draw the image. 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 image.
Draws the key equivalent associated with the menu item.
public void drawKeyEquivalentWithFrameInView
(NSRect cellFrame, NSView controlView)
This method invokes keyEquivalentRectForBounds
, passing it cellFrame, to calculate the rectangle in which to draw the key equivalent. 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 key equivalent.
Draws a menu item separator.
public void drawSeparatorItemWithFrameInView
(NSRect cellFrame, NSView controlView)
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.
Draws the state image associated with the menu item.
public void drawStateImageWithFrameInView
(NSRect cellFrame, NSView controlView)
This method invokes stateImageRectForBounds
, passing it cellFrame, to calculate the rectangle in which to draw the state image. 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 state image.
Draws the title associated with the menu item.
public void drawTitleWithFrameInView
(NSRect cellFrame, NSView controlView)
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.
Returns the rectangle into which the menu item’s image should be drawn.
public NSRect imageRectForBounds
(NSRect cellFrame)
The returned rectangle is based on cellFrame but encompasses only the area to be occupied by the image.
Returns the width of the image associated with a menu item.
public float imageWidth
()
You can associate an image with a menu item using NSMenuItem’s setImage
method.
Returns true
if the receiver currently draws its menu item with a highlighted appearance
public boolean isHighlighted
()
.
Returns the rectangle into which the menu item’s key equivalent should be drawn.
public NSRect keyEquivalentRectForBounds
(NSRect cellFrame)
The returned rectangle is based on cellFrame but encompasses only the area to be occupied by the key equivalent.
keyEquivalent
(NSMenuItem)stateImageRectForBounds
imageRectForBounds
titleRectForBounds
keyEquivalentRectForBounds
Returns the width of the key equivalent associated with the menu item.
public float keyEquivalentWidth
()
You can associate a key equivalent with a menu item using NSMenuItem’s setKeyEquivalent
method.
Returns the NSMenuItem associated with the receiver.
public NSMenuItem menuItem
()
Returns the menu view associated with the receiver.
public NSMenuView menuView
()
Returns true
if the menu item needs to be displayed; otherwise returns false
.
public boolean needsDisplay
()
Returns true
if the size of the menu item needs to be calculated; otherwise returns false
.
public boolean needsSizing
()
Sets the highlight state for the receiver to flag.
public void setHighlighted
(boolean flag)
You should not need to call this method directly. It is invoked by the NSMenuView’s setHighlightedItemIndex
method to provide user feedback during menu tracking or when the user selects a menu item (either by clicking or using a key equivalent).
isHighlighted
setHighlightedItemIndex
(NSMenuView)Sets the NSMenuItem for the receiver to item.
public void setMenuItem
(NSMenuItem item)
Sets the menu view for the receiver menuView.
public void setMenuView
(NSMenuView menuView)
Sets whether the menu item needs to be drawn to flag.
public void setNeedsDisplay
(boolean flag)
Sets a flag that indicates whether or not the menu item must be resized.
public void setNeedsSizing
(boolean flag)
If flag is true
, 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 false
, 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.
Returns the rectangle into which the menu item’s state image should be drawn.
public NSRect stateImageRectForBounds
(NSRect cellFrame)
The returned rectangle is based on cellFrame but encompasses only the area to be occupied by the menu item’s state image.
Returns the width of the image used to indicate the state of the menu item.
public float 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 NSMenuItem’s setOnStateImage
, setOffStateImage
, and setMixedStateImage
methods.
To change the state of the cell’s menu item, use NSMenuItem’s setState
method.
calcSize
needsSizing
setState
(NSMenuItem)Returns the tag of the selected menu item, or 0 if no item is selected.
public int tag
()
Setting the tag value of an NSMenuItemCell with setTag
does nothing.
setTag
(NSActionCell)Returns the rectangle into which the menu item’s title should be drawn.
public NSRect titleRectForBounds
(NSRect cellFrame)
The returned rectangle is based on cellFrame but encompasses only the area to be occupied by the text of the title.
Returns the width of the menu item text.
public float titleWidth
()
To set the menu item text, use NSMenuItem’s setTitle
method.
© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)