- Inherits from:
- NSButtonCell : NSActionCell : NSCell : NSObject
- Package:
- com.apple.yellow.application
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.
An instance of NSMenuItemCell uses the information contained in an NSMenuItem object to obtain the basic geometry of the menu item. Using this geometry, the menu-item cell calculates the minimal space required for drawing each of its 3 components: the state image, the title text or image, and the key equivalent. Once this information has been calculated, the cell's menu view gathers the information and uses it to determine the optimal size for the menu. The cell then bases its drawing calculations on this optimal size information.
Menu-item cells have two sets of methods for returning two different sets of measurements. The first set of methods return the minimal space required by the menu item's individual components. These methods include imageWidth, titleWidth, keyEquivalentWidth, and stateImageWidth.
The second set of methods return the drawing rectangle to be used by the cell when drawing a given component. The methods imageRectForBounds, keyEquivalentRectForBounds, stateImageRectForBounds, and titleRectForBounds return the rectangle for each component, taking into account the NSMenuView adjustments. These adjusted rectangles allow the menu-item components to line up within the menu, forming coherent columns.
You can subclass NSMenuItemCell to change the way menu items are drawn by your application. For example, your subclass can display extra information for each menu item or change the basic appearance (background color, borders, adornments, and so on) of the menu item. If you create a custom subclass of NSMenuItemCell, you may also need to subclass NSMenuView to handle any additional information provided by your menu-item cell. If you simply want to change the way the cell is drawn, you can do that by overriding the menu-item cell's drawWithFrameInView method.
- Constructors
- NSMenuItemCell
- Getting and setting menu item attributes
- isHighlighted
- setHighlighted
- menuItem
- setMenuItem
- Calculating menu item sizes
- calcSize
- needsSizing
- setNeedsSizing
- imageWidth
- titleWidth
- keyEquivalentWidth
- stateImageWidth
- Getting the menu item's drawing rectangle
- imageRectForBounds
- keyEquivalentRectForBounds
- stateImageRectForBounds
- titleRectForBounds
- Drawing the menu item
- drawBorderAndBackgroundWithFrameInView
- drawImageWithFrameInView
- drawKeyEquivalentWithFrameInView
- drawSeparatorItemWithFrameInView
- drawStateImageWithFrameInView
- drawTitleWithFrameInView
public NSMenuItemCell()
public NSMenuItemCell(String aString)
public NSMenuItemCell(NSImage anImage)
public void calcSize()
Typically this method is invoked automatically when necessary. You should not need to invoke it directly.
See Also: needsSizing
public void drawBorderAndBackgroundWithFrameInView(
NSRect cellFrame,
NSView controlView)
See Also: drawWithFrameInView (NSCell)
public void drawImageWithFrameInView(
NSRect cellFrame,
NSView controlView)
Typically 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.
public void drawKeyEquivalentWithFrameInView(
NSRect cellFrame,
NSView controlView)
Typically 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.
public void drawSeparatorItemWithFrameInView(
NSRect cellFrame,
NSView controlView)
You should not need to invoke this method directly. Subclasses may override this method to control the drawing of the separator.
See Also: drawKeyEquivalentWithFrameInView, drawTitleWithFrameInView, isFlipped (NSView)
public void drawStateImageWithFrameInView(
NSRect cellFrame,
NSView controlView)
Typically 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.
public void drawTitleWithFrameInView(
NSRect cellFrame,
NSView controlView)
Typically 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.
public NSRect imageRectForBounds(NSRect cellFrame)
See Also: stateImageRectForBounds, imageRectForBounds, titleRectForBounds, keyEquivalentRectForBounds
public float imageWidth()
See Also: stateImageWidth, calcSize, needsSizing
public boolean isHighlighted()
true
if
the cell currently draws its menu item with a highlighted appearance.See Also: setHighlighted
public NSRect keyEquivalentRectForBounds(NSRect cellFrame)
See Also: keyEquivalent (NSMenuItem), stateImageRectForBounds, imageRectForBounds, titleRectForBounds, keyEquivalentRectForBounds
public float keyEquivalentWidth()
See Also: calcSize, needsSizing
public NSMenuItem menuItem()
See Also: setMenuItem
public NSMenuView menuView()
public boolean needsDisplay()
public boolean needsSizing()
true
if
the size of the menu item needs to be calculated, otherwise returns false
.See Also: setNeedsSizing, calcSize
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).
See Also: isHighlighted, setHighlightedItemIndex (NSMenuView)
public void setMenuItem(NSMenuItem item)
See Also: menuItem
public void setMenuView(NSMenuView menuView)
public void setNeedsDisplay(boolean flag)
public void setNeedsSizing(boolean flag)
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 contents of its menu item changes.
See Also: needsSizing
public NSRect stateImageRectForBounds(NSRect cellFrame)
See Also: stateImageRectForBounds, imageRectForBounds, titleRectForBounds, keyEquivalentRectForBounds
public float stateImageWidth()
To change the state of the cell's menu item, use NSMenuItem's setState method.
See Also: calcSize, needsSizing, setState (NSMenuItem)
public NSRect titleRectForBounds(NSRect cellFrame)
See Also: stateImageRectForBounds, imageRectForBounds, titleRectForBounds, keyEquivalentRectForBounds
public float titleWidth()
See Also: calcSize, needsSizing