Class

NSMenuView

The NSMenuView class handles the display of menus on the user’s screen. A menu view displays its menu either horizontally or vertically and allows the user to interact with the items of that menu, either to navigate through hierarchical menus or to select a particular item.

Overview

Symbols

Initializing a Menu View

- initAsTearOff

Deprecated. Tear-off menus are not supported in macOS.

- initWithFrame:

Initialized a newly allocated menu view with a specified frame rectangle.

Managing Menu View Attributes

+ menuBarHeight

Returns the height of the menu bar.

- setMenu:

Sets the menu to be displayed in the receiver

- menu

Returns the menu object associated with this menu view.

- setHorizontal:

Sets the orientation of the menu.

- isHorizontal

Returns YES if the menu is displayed horizontally; such as for a menu bar, otherwise returns NO.

- setFont:

Sets the default font to use when drawing the menu text.

- font

Returns the default font used to draw the menu text.

- setHighlightedItemIndex:

Highlights the menu item at a specific location.

- highlightedItemIndex

Returns the index of the currently highlighted menu item, or –1 if no menu item in the menu is highlighted.

- setMenuItemCell:forItemAtIndex:

Replaces the menu item cell at a specific location.

- menuItemCellForItemAtIndex:

Returns the menu item cell at the specified location.

- attachedMenuView

Returns the receiver’s attached menu view.

- attachedMenu

Returns the menu object associated with this object’s attached menu view.

- isAttached

Returns YES if this menu is currently attached to its parent menu, NO otherwise.

- isTornOff

Deprecated. Tear-off menus are not supported in macOS.

- horizontalEdgePadding

Returns the amount of horizontal space used for padding menu item components.

- setHorizontalEdgePadding:

Sets the horizontal padding for menu item components.

Responding to Notifications

- itemChanged:

Marks the menu view as needing to be resized so changes in size resulting from a change in the menu will be tracked.

- itemAdded:

Creates a new menu item cell for the newly created item and marks the menu view as needing to be resized.

- itemRemoved:

Removes the removed item’s menu item cell and marks the menu view as needing to be resized.

Working With Submenus

- detachSubmenu

Detaches the window associated with the currently visible submenu and removes any menu item highlights.

- attachSubmenuForItemAtIndex:

Attaches the submenu associated with the menu item at index.

Calculating Menu Geometry

- update

Asks the associated menu object to update itself.

- setNeedsSizing:

Sets a flag that indicates whether the layout is invalid and needs resizing.

- needsSizing

Returns YES if the menu view needs to be resized due to changes in the menu object, NO otherwise.

- sizeToFit

Used internally by the menu view to cache information about the menu item geometry.

- stateImageOffset

Returns the offset to the space reserved for state images of this menu.

- stateImageWidth

Returns the maximum width of the state images used by this menu.

- imageAndTitleOffset

Returns the offset to the starting point of a menu item’s image and title section.

- imageAndTitleWidth

Returns the maximum width of a menu item’s image and title section.

- keyEquivalentOffset

Returns the beginning position of the menu’s key equivalent text.

- keyEquivalentWidth

Returns the width of the menu’s key equivalent text.

- innerRect

Returns the drawing rectangle for the menu contents.

- rectOfItemAtIndex:

Returns the drawing rectangle of the specified menu item.

- indexOfItemAtPoint:

Returns the index of the menu item underneath the specified or –1 if no menu item is underneath that point.

- setNeedsDisplayForItemAtIndex:

Adds the region occupied by the menu item at a specific location to the menu view’s invalid region.

- locationForSubmenu:

Returns the origin of the submenu view’s window.

- setWindowFrameForAttachingToRect:onScreen:preferredEdge:popUpSelectedItem:

Causes the menu view to resize its window so its frame is the appropriate size to attach to a specified rectangle within the screen.

Handling Events

- performActionWithHighlightingForItemAtIndex:

Uses the associated menu object to perform the action associated with the specified item when a key equivalent is pressed.

- trackWithEvent:

Handles events sent to this menu view.

Relationships

Inherits From