| Framework | Carbon/Carbon.h |
| Declared in | Menus.h |
You can use the Menu Manager to create and manage the menus in your application. Menus allow the user to view or choose from a list of choices and commands that your application provides. All Mac OS applications should provide these standard menus: the Application menu, the File menu, and the Edit menu.
Carbon supports the Menu Manager, with the following changes:
Your application must use the functions defined by the Menu Manager whenever it creates and disposes of Menu Manager data structures. Some applications, for example, create menus by using the Resource Manager function GetResource (instead of the Menu Manager function GetMenu) and dispose of them by calling ReleaseResource instead of DisposeMenu. This practice is not supported in Carbon.
The MenuInfo structure is opaque in Carbon. You must revise your application so that it accesses Menu Manager data structures only through accessor functions.
Menu color information tables are not recommended in Carbon.
You are strongly encouraged to adopt the standard Mac OS menu definition functions (also known as MDEFs) in your application. Your menus will then inherit the systemwide appearance and, furthermore, take advantage of other Menu Manager enhancements planned for the future. If you decide to customize the appearance of a menu and you are deploying your application for Mac OS X v10.3 and later, you should use a custom HIView instead of a custom menu definition function.
Function descriptions are grouped by the tasks for which you use the functions. For an alphabetical list of functions, go to the API index at the end of the document.
CreateNewMenu
DuplicateMenu
DisposeMenu
CreateCustomMenu
RegisterMenuDefinition
SetMenuDefinition
GetMenuDefinition
CreateStandardFontMenu
UpdateStandardFontMenu
ReleaseMenu Deprecated in Mac OS X v10.5
RetainMenu Deprecated in Mac OS X v10.5
HideMenuBar
ShowMenuBar
IsMenuBarVisible
FlashMenuBar
SetMenuBar
GetMenuBar
DrawMenuBar
InvalMenuBar
GetMBarHeight
DuplicateMenuBar
DisposeMenuBar
InsertMenu
DeleteMenu
ClearMenuBar
GetMenuRetainCount Deprecated in Mac OS X v10.5
GetMenuRef
GetMenuHandle
SetMenuTitleWithCFString
CopyMenuTitleAsCFString
GetMenuType
SetMenuTitleIcon
GetMenuTitleIcon
SetMenuID
GetMenuID
LMGetTheMenu
SetMenuHeight
GetMenuHeight
SetMenuWidth
GetMenuWidth
CalcMenuSize
IsMenuSizeInvalid
GetMenuAttributes
ChangeMenuAttributes
IsValidMenu
SetMenuFlashCount Deprecated in Mac OS X v10.5
HiliteMenu
UpdateInvalidMenuItems
InvalidateMenuEnabling
InvalidateMenuItems
InvalidateMenuSize
IsMenuBarInvalid
IsMenuItemInvalid
EraseMenuBackground Deprecated in Mac OS X v10.5
ScrollMenuImage Deprecated in Mac OS X v10.5
SetMenuItemProperty
SetMenuCommandProperty
GetMenuItemProperty
GetMenuCommandProperty
GetMenuItemPropertySize
GetMenuCommandPropertySize
RemoveMenuItemProperty
RemoveMenuCommandProperty
GetMenuItemPropertyAttributes
ChangeMenuItemPropertyAttributes
SetMenuItemRefCon
GetMenuItemRefCon
CountMenuItems
CountMenuItemsWithCommandID
EnableMenuItem
EnableMenuCommand
DisableMenuItem
DisableMenuCommand
EnableAllMenuItems
DisableAllMenuItems
IsMenuItemEnabled
IsMenuCommandEnabled
MenuHasEnabledItems
EnableMenuItemIcon
DisableMenuItemIcon
IsMenuItemIconEnabled
SetMenuItemTextWithCFString
CopyMenuItemTextAsCFString
AppendMenuItemTextWithCFString
InsertMenuItemTextWithCFString
GetMenuFont
SetMenuFont
GetMenuItemFontID
SetMenuItemFontID
GetFontFamilyFromMenuSelection
SetItemStyle
GetItemStyle
GetMenuItemTextEncoding Deprecated in Mac OS X v10.5
SetMenuItemTextEncoding Deprecated in Mac OS X v10.5
SetMenuItemIconHandle
GetMenuItemIconHandle
SetItemMark
SetMenuCommandMark
GetItemMark
GetMenuCommandMark
CheckMenuItem
SetMenuItemIndent
GetMenuItemIndent
SetMenuItemKeyGlyph
GetMenuItemKeyGlyph
SetMenuItemModifiers
GetMenuItemModifiers
SetMenuItemCommandID
GetMenuItemCommandID
SetMenuItemHierarchicalMenu
GetMenuItemHierarchicalMenu
SetMenuItemCommandKey
GetMenuItemCommandKey
GetIndMenuItemWithCommandID
SetMenuItemData
CopyMenuItemData
GetMenuItemAttributes
ChangeMenuItemAttributes
GetItemIcon Deprecated in Mac OS X v10.5
GetMenuItemHierarchicalID Deprecated in Mac OS X v10.5
SetItemIcon Deprecated in Mac OS X v10.5
SetMenuItemHierarchicalID Deprecated in Mac OS X v10.5
IsMenuKeyEvent
GetMenuTrackingData
CancelMenuTracking
MenuSelect
MenuChoice
IsShowContextualMenuEvent
ContextualMenuSelect
PopUpMenuSelect
GetItemCmd
GetMenu
GetMenuExcludesMarkColumn
GetNewMBar
IsShowContextualMenuClick
MenuEvent
SetItemCmd
SetMenuExcludesMarkColumn
AppendMenu Deprecated in Mac OS X v10.5
AppendMenuItemText Deprecated in Mac OS X v10.5
AppendResMenu Deprecated in Mac OS X v10.5
DeleteMCEntries Deprecated in Mac OS X v10.5
DisposeMCInfo Deprecated in Mac OS X v10.5
DisposeMenuDefUPP Deprecated in Mac OS X v10.5
GetMCEntry Deprecated in Mac OS X v10.5
GetMCInfo Deprecated in Mac OS X v10.5
GetMenuItemText Deprecated in Mac OS X v10.5
GetMenuTitle Deprecated in Mac OS X v10.5
InitContextualMenus Deprecated in Mac OS X v10.5
InsertFontResMenu Deprecated in Mac OS X v10.5
InsertIntlResMenu Deprecated in Mac OS X v10.5
InsertMenuItem Deprecated in Mac OS X v10.5
InsertMenuItemText Deprecated in Mac OS X v10.5
InsertResMenu Deprecated in Mac OS X v10.5
InvokeMenuDefUPP Deprecated in Mac OS X v10.5
MenuKey Deprecated in Mac OS X v10.5
NewMenu Deprecated in Mac OS X v10.5
NewMenuDefUPP Deprecated in Mac OS X v10.5
ProcessIsContextualMenuClient Deprecated in Mac OS X v10.5
SetMCEntries Deprecated in Mac OS X v10.5
SetMCInfo Deprecated in Mac OS X v10.5
SetMenuItemText Deprecated in Mac OS X v10.5
SetMenuTitle Deprecated in Mac OS X v10.5
Get the menu whose contents are displayed in the menubar.
MenuRef AcquireRootMenu ( void );
The current root menu. See page for a description of the MenuRef data type. If no root menu currently exists, the Menu Manager creates one and returns its menu reference.
This function increments the reference count of the root menu. The caller should call ReleaseMenu when done with the menu.
Menus.h
Appends a new menu item with text from a CFString.
OSStatus AppendMenuItemTextWithCFString ( MenuRef inMenu, CFStringRef inString, MenuItemAttributes inAttributes, MenuCommand inCommandID, MenuItemIndex *outNewItem );
The menu to which to append the new item.
The text of the new item.
The attributes of the new item.
The command ID of the new item.
On exit, the index of the new item. May be NULL if the caller does not need this information.
A result code. See “Menu Manager Result Codes.”
The Menu Manager will make its own copy of the CFString before returning from this function. Modifying the string after calling AppendMenuItemTextWithCFString will have no effect on the menu item's actual text. The caller may release the string after the call.
Menus.h
Recalculates the horizontal and vertical dimensions of a menu.
void CalcMenuSize ( MenuRef theMenu );
The menu whose dimensions need recalculating.
The CalcMenuSize function uses the menu definition function of the specified menu to calculate the dimensions of the menu. In most cases, your application does not need to use the CalcMenuSize function.
Menus.hCancels menu tracking.
OSStatus CancelMenuTracking ( MenuRef inRootMenu, Boolean inImmediate, UInt32 inDismissalReason );
The root menu of the tracking session to dismiss. For menu bar tracking, pass the result from AcquireRootMenu; for popup menu tracking, pass the menu that was passed to PopUpMenuSelect.
Pass true if you want the open menus to disappear immediately, false if you want them to fade out.
Why the menu is being dismissed. This value is passed in the kEventMenuEndTracking event. You can pass the constants in “Menu Dismissal Constants.” If you pass zero here, the kEventMenuEndTracking event contains kMenuDismissedByCancelMenuTracking.
A result code. See “Menu Manager Result Codes.”
Menus.h
Changes the attributes of a menu.
OSStatus ChangeMenuAttributes ( MenuRef menu, MenuAttributes setTheseAttributes, MenuAttributes clearTheseAttributes );
The menu whose attributes you want to change.
The attributes to add to the menu. See “Menu Attribute Constants” for a list of possible values.
The attributes to remove from the menu. See “Menu Attribute Constants” for a list of possible values.
A result code. See “Menu Manager Result Codes.”
Menus.h
Changes the attributes of a menu item.
OSStatus ChangeMenuItemAttributes ( MenuRef menu, MenuItemIndex item, MenuItemAttributes setTheseAttributes, MenuItemAttributes clearTheseAttributes );
The menu.
The index of the menu item.
The attributes to add to the menu item. See “Menu Item Attribute Constants” for a list of possible values.
The attributes to remove from the menu item.
A result code. See “Menu Manager Result Codes.”
Menus.h
Changes the attributes of a menu item property.
OSStatus ChangeMenuItemPropertyAttributes ( MenuRef menu, MenuItemIndex item, OSType propertyCreator, OSType propertyTag, OptionBits attributesToSet, OptionBits attributesToClear );
The menu containing the menu item whose properties you want ot change.
The index of the menu item.
The creator code of the property.
The property tag.
The attributes to add to the menu item property.
The attributes to remove from the menu item property.
A result code. See “Menu Manager Result Codes.”
Currently you can only specify the kMenuPropertyPersistent attribute (See “Menu Item Property Attribute Constant”), which currently has no effect on Mac OS X. Therefore, SetMenuItemPropertyAttributes is not useful at this time.
Menus.h
Adds or removes a check mark from a menu item.
void CheckMenuItem ( MenuRef theMenu, short item, Boolean checked );
The menu containing the menu item to check or uncheck.
The menu index of the item to check or uncheck.
Pass true to add a check, false to remove it.
You can also add or remove a check mark using the SetItemMark function.
Menus.h
Deletes all menus from the current menu list.
void ClearMenuBar ( void );
The ClearMenuBar function deletes all menus from the current menu list. ClearMenuBar decrements the reference count of each menu in the menu list; if the reference count reaches zero, the memory associated with the menu is released. To explicitly release the memory occupied by a menu, use DisposeMenu.
Menus.h
An application-defined callback function that examines the context in a contextual menu CFPlugin.
OSStatus CMPluginExamineContext ( void *thisInstance, const AEDesc *inContext, AEDescList *outCommandPairs );
The instance of this plugin.
The Apple event descriptor describing the selection that invoked the contextual menu.
On return, outCommandPairs points to an array of Apple event descriptors, each of which contains information about a menu item to display in the contextual menu.
A result code. See “Menu Manager Result Codes.”
Your contextual menu plugin must implement this function to determine what menu items to display given the user selection. The Apple event descriptor for each menu item contains the information to display in the item (such as text) and a command ID.
Menus.h
An application-defined callback function that handles menu item selection in a contextual menu CFPlugin.
OSStatus CMPluginHandleSelection ( void *thisInstance, AEDesc *inContext, SInt32 inCommandID );
The instance of this plugin.
The Apple event descriptor describing the selection that invoked the contextual menu.
The command ID associated with the user’s menu item selection.
A result code. See “Menu Manager Result Codes.”
Your contextual menu plugin must implement this function to handle a user’s selection of an item in the contextual menu. The command ID indicates which of the choices you gave in CMPluginExamineContext the user selected, so you can use that and the user selection stored in the inContext parameter to execute the conxtexual menu selection appropriately.
Menus.h
An application-defined callback function that handles any post-selection cleanup in a contextual menu CFPlugin.
void CMPluginPostMenuCleanup ( void *thisInstance );
The instance of this plugin.
Your contextual menu plugin must implement this function to handle any necessary cleanup required after displaying the contextual menu. If no cleanup is needed, you can simply return from this function.
Menus.h
Displays a contextual menu.
OSStatus ContextualMenuSelect ( MenuRef inMenu, Point inGlobalLocation, Boolean inReserved, UInt32 inHelpType, ConstStr255Param inHelpItemString, const AEDesc *inSelection, UInt32 *outUserSelectionType, MenuID *outMenuID, MenuItemIndex *outMenuItem );
The menu containing application commands to display. The caller creates this menu based on the current context, the mouse location, and the current selection (if it was the target of the mouse). If you pass NULL, only system commands are displayed.
The location (in global coordinates) of the mouse near which the menu is to be displayed.
Reserved for future use. Pass false for this parameter.
An identifier specifying the type of help provided by the application; see “Contextual Menu Help Type Constants.”
The string containing the text to be displayed for the help menu item. This string is unused unless you also pass the constant kCMOtherHelp in the inHelpType parameter.
A pointer to an object specifier for the current selection. This allows the system to examine the selection and add special system commands accordingly. Passing a value of NULL indicates that no selection should be examined, and most likely, no special system actions will be included.
A pointer to an unsigned 32-bit value. On return, the value indicates what the user selected from the contextual menu; see “Contextual Menu Selection Type Constants” for a list of possible values.
A pointer to a signed 16-bit value. On return, if outUserSelectionType is set to kCMMenuItemSelected, the value is set to the menu ID of the chosen item.
A pointer to an unsigned 16-bit value. On return, if outUserSelectionType is set to kCMMenuItemSelected, the value is set to the index of the menu item chosen.
A result code. See “Menu Manager Result Codes.” Returns userCanceledErr and sets outUserSelectionType to kCMNothingSelected if the user selects an item that requires no additional actions on your part.
If your application uses the standard window handler, you may want to install handlers for the kEventWindowContextualMenuSelect or kEventControlContextualMenuClick events and call ContextualMenuSelect from within your handler. The standard window handler automatically detects contextual menu clicks and sends the kEventWindowContextualMenuSelect and kEventControlContextualMenuClick events.
If the IsShowContextualMenuEvent function returns true or you receive the appropriate contextual menu Carbon event, you should call the ContextualMenuSelect function after generating your own menu and preparing an Apple Event descriptor ( AEDesc) that describes the item for which your application is displaying a contextual menu. This descriptor may contain an object specifier or raw data and will be passed to all contextual menu plug-ins.
The system will add other items before displaying the contextual menu, and it will remove those items before returning, leaving the menu in its original state.
After all the system commands are added, the contextual menu is displayed and tracked. If the user selects one of the system items, it is handled by the system and the call returns as though the user didn’t select anything from the menu. If the user selects any other item (or no item at all), the Menu Manager passes back appropriate values in the parameters outUserSelectionType, outMenuID, and outMenuItem.
Your application should provide visual feedback indicating the item that was clicked upon. For example, a click on an icon should highlight the icon, while a click on editable text should not eliminate the current selection.
If the outUserSelectionType parameter contains kCMMenuItemSelected, you should look at the outMenuID and outMenuItem parameters to determine what menu item the user chose and handle it appropriately. If the outUserSelectionType parameter contains kCMShowHelpSelected, you should open the proper help sequence.
Menus.h
Obtains multiple menu item attributes at once.
OSStatus CopyMenuItemData ( MenuRef inMenu, MenuItemID inItem, Boolean inIsCommandID, MenuItemDataPtr ioData );
The menu whose attributes you want to get. Note that if you pass true for the inIsCommandID parameter, you can pass NULL here, in which case the Menu Manager searches the root menu for the first menu that matches the specified command ID.
The menu item index or the command ID of the menu item.
A Boolean value indicating whether the value passed for the inItem parameter is a command ID or a menu item index. Pass true to indicate a command ID, false to indicate that it is a menu item index. If you pass true, the Menu Manager returns the data for the first menu item that matches the specified command ID.
A pointer to a MenuItemDataRec structure. Before calling, you should set the whichData field to indicate what data you want to obtain. (Individual fields may also require initialization before calling.) On return, the structure contains the data you requested. For more details on the types of data you can obtain, see “Menu Item Data Flags.”
A result code. See “Menu Manager Result Codes.”
You can use this function to obtain multiple menu item attributes simultaneously, which is often more efficient than making several different calls. For example, a menu definition function could use CopyMenuItemData to obtain all the individual attributes necessary for drawing a menu all at once.
This function returns copies of the data in the menu, so you should release any data in the MenuItemDataRec structure that was allocated dynamically (such as the CFString item text).
Menus.h
Copies menu items from one menu to another.
OSStatus CopyMenuItems ( MenuRef inSourceMenu, MenuItemIndex inFirstItem, ItemCount inNumItems, MenuRef inDestMenu, MenuItemIndex inInsertAfter );
The menu from which to copy items.
The first item to copy.
The number of items to copy.
The menu to which to copy items.
The menu item in the destination menu after which to insert the copied items. Pass zero to insert items at the beginning of the menu. Note that you cannot specify an index value greater than the number of items in the destination menu.
A result code. See “Menu Manager Result Codes.”
Menus.h
Returns a CFString containing the text of a menu item.
OSStatus CopyMenuItemTextAsCFString ( MenuRef inMenu, MenuItemIndex inItem, CFStringRef *outString );
The menu containing the item.
The item whose text you want to copy.
On exit, a CFString containing the item's text. The caller must release this string when it is no longer needed.
A result code. See “Menu Manager Result Codes.”
Menus.h
Returns a CFString containing the title of a menu.
OSStatus CopyMenuTitleAsCFString ( MenuRef inMenu, CFStringRef *outString );
The menu whose title you want to obtain.
On exit, a CFString containing the menu's title. This string must be released by the caller.
A result code. See “Menu Manager Result Codes.”
Menus.h
Obtains the number of menu items in a menu
UInt16 CountMenuItems ( MenuRef theMenu );
The menu whose items you want to count.
The number of menu items in the menu.
Menus.h
Counts the menu items with a specified command ID.
ItemCount CountMenuItemsWithCommandID ( MenuRef inMenu, MenuCommand inCommandID );
The menu in which to begin searching for items with the specified command ID. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID for which to search.
The number of menu items that match the specified command ID.
In CarbonLib 1.0.x, this function always returns zero or one; it stops after finding the first menu item with the specified command ID. In CarbonLib 1.1 and Mac OS X v10.0, it will count all menu items with the specified command ID.
In Mac OS X v10.0 and CarbonLib 1.0 through 1.4, this function searches only top-level menus (that is, those that are visible in the menu bar) and submenus of top-level menus. It does not search hierarchical menus that are in the menu bar but are not submenus of a top-level menu. For example, it does not search menus that are inserted for use in a popup menu. In Mac OS X v10.1 and later, and CarbonLib 1.5 and later, this function also searches hierarchical menus.
Menus.h
Creates a new, untitled, empty menu using a custom menu definition function.
OSStatus CreateCustomMenu ( const MenuDefSpec *inDefSpec, MenuID inMenuID, MenuAttributes inMenuAttributes, MenuRef *outMenuRef );
A data structure that specifies a custom menu definition function.
The menu ID to use for the new menu.
The menu attributes to use for the new menu. See “Menu Attribute Constants” for a list of possible values.
On exit, contains the new menu.
A result code. See “Menu Manager Result Codes.”
Similar to CreateNewMenu, but also allows you to create a menu from a custom menu definition function This definition can be procedure pointer–based or HIView-based, which you specify in the MenuDefSpec structure. (Note that HIView–based menus are available only in Mac OS X v10.3 and later.)
Menus.h
Creates a new, untitled, empty menu.
OSStatus CreateNewMenu ( MenuID inMenuID, MenuAttributes inMenuAttributes, MenuRef *outMenuRef );
The menu ID to use for the new menu. Note that zero is a valid ID in Carbon.
The menu attributes to use for the new menu. See “Menu Attribute Constants” for a list of possible values.
On exit, contains the new menu.
A result code. See “Menu Manager Result Codes.”
Unless you need to create new menus on-the-fly, you should not use functions like CreateNewMenu that create menus programmatically. Instead, you should define menus in Interface Builder, store them as nib files, and then call the Interface Builder Services function CreateMenuFromNib to create them.
CreateNewMenu is preferred over NewMenu because it allows you to specify the menu's attributes and it does not require you to specify a Str255-based menu title. To set the menu title, you should use SetMenuTitleWithCFString.
Menus.h
Creates a standard font menu.
OSStatus CreateStandardFontMenu ( MenuRef menu, MenuItemIndex afterItem, MenuID firstHierMenuID, OptionBits options, ItemCount *outHierMenuCount );
The menu to which you want to add the font items.
The item number of the menu item after which the new menu items are to be added. If you want to insert the new items before the first menu items, specify 0. If you want to insert the items after the last item in the menu, specify a number greater than or equal to the last item in the menu. Otherwise, specify the item number for the menu item after which you want to insert new items.
The first menu ID to use if any hierarchical menus are created. This ID is incremented for each additional hierarchical menu.
An option bits structure that specifies the behavior for the Font menu. Specify the Hierarchical Font Menu Option Constant if you want to construct a hierarchical font menu.
On return, this parameter contains the number of hierarchical menus attached to the standard font menu. This value may be NULL if the hierarchical menus count is not useful. For example, if the only submenus in your application are those created by CreateStandardFontMenu, then you don’t need to worry about the hierarchical menu count, as any existing submenu must be a font menu.
A result code. See “Menu Manager Result Codes.”
You should use this function instead of the functions AppendResMenu or InsertResMenu to designate objects in the font database as menu items in the Font menu. The fonts objects will appear by name.
Menus.h
Deletes an existing menu from the current menu list.
void DeleteMenu ( MenuID menuID );
The menu ID of the menu to delete from the current menu list. If the menu list does not contain a menu with the specified menu ID, DeleteMenu does nothing.
The DeleteMenu function deletes the menu identified by the specified menu ID from the current menu list. DeleteMenu decrements the reference count of the menu, and if the reference count reaches zero, the memory occupied by the menu is released. To explicitly release the memory occupied by the menu, use DisposeMenu.
The DeleteMenu function first checks the submenu portion of the current menu list for a menu ID with the specified ID. If it finds such a menu, it deletes that menu and returns. If DeleteMenu doesn’t find the menu in the submenu portion, it checks the regular portion of the current menu list.
Menus.h
Deletes an item from a menu.
void DeleteMenuItem ( MenuRef theMenu, MenuItemIndex item );
The menu from which you want to delete the menu item.
The item number of the menu item to delete. If you specify 0 or a number greater than the last item in the menu, DeleteMenuItem does not delete any item from the menu.
The DeleteMenuItem function deletes a specified menu item from a menu. You should not delete items from an existing menu unless the user expects the menu (such as a menu that lists open documents) to change.
Menus.h
Deletes multiple menu items.
OSStatus DeleteMenuItems ( MenuRef inMenu, MenuItemIndex inFirstItem, ItemCount inNumItems );
The menu from which to delete items.
The first item to delete.
The number of items to delete.
A result code. See “Menu Manager Result Codes.”
You can call this function rather than calling DeleteMenuItem multiple times.
Menus.h
Disables all items in a menu.
void DisableAllMenuItems ( MenuRef theMenu );
The menu whose items you want to disable.
This function is equivalent to older code that masked the enableFlags field of the MenuInfo structure (now opaque in Carbon) with 0x01. It disables all items (including items past item 31) but does not affect the state of the menu title.
Menus.h
Disables the menu item with a specified command ID.
void DisableMenuCommand ( MenuRef inMenu, MenuCommand inCommandID );
The menu in which to begin searching for the item. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID of the menu item to be disabled. If more than one item has this command ID, only the first will be disabled.
If you have access to the menu item index, in most cases you should use DisableMenuItem instead, as that function is faster and requires no searching.
Menus.h
Disables a menu item or a menu.
void DisableMenuItem ( MenuRef theMenu, MenuItemIndex item );
The menu containing the item to be disabled.
The index of the menu item that you wish to disable. Pass 0 to specify the menu title (disabling the entire menu).
The DisableMenuItem function disables a menu item (and any associated icon) so that the user cannot choose the item from the menu.
Note that EnableMenuItem calls the InvalMenuBar function to update the menu bar the next time through the event loop.
See also the EnableMenuItem and IsMenuItemEnabled functions.
Note that the implementation of Carbon on Mac OS 8.1 only supports disabling menu items less than or equal to 31.
Menus.h
Disables the icon associated with a menu item.
void DisableMenuItemIcon ( MenuRef theMenu, MenuItemIndex item );
The menu containing the icon to be disabled.
The index of the menu item containing the icon.
Your application can use the DisableMenuItemIcon function to dim individual menu item icons. The menu item that contains the icon is unaffected by calling DisableMenuItemIcon. That is, if DisableMenuItemIcon disables an enabled menu item’s icon, the menu item itself will remain enabled. Calling DisableMenuItemIcon on the icon of a menu item that is currently disabled will cause the icon to be disabled once the menu item is re-enabled.
See also the functions EnableMenuItemIcon and IsMenuItemIconEnabled.
Menus.h
Decrements the retain count of a menu.
void DisposeMenu ( MenuRef theMenu );
The menu whose retain count to decrement. If the retain count falls to zero, the menu is destroyed.
The reference that you pass in the theMenu parameter is not valid after DisposeMenu returns. This function is identical to ReleaseMenu.
Menus.h
Releases a menubar handle.
OSStatus DisposeMenuBar ( MenuBarHandle inMbar );
The menubar handle to release.
A result code. See “Menu Manager Result Codes.”
Carbon applications should call this function when releasing a handle returned from GetNewMBar, GetMenuBar, or DuplicateMenuBar. Doing so ensures that the reference counts of the menus in the menubar handle can be decremented when the handle is released.
Do not call the Memory Manager function DisposeHandle to release such a handle.
Menus.h
Draws the menu bar based on the current menu list.
void DrawMenuBar ();
The DrawMenuBar function draws (or redraws) the menu bar according to the current menu list. Note that most Menu Manager calls that affect the menu bar call InvalMenuBar so that the menu bar is redrawn the next time through the event loop; however, you can call DrawMenuBar if you want the changes to appear immediately.
Menus.h
Creates a new menu that is a copy of another menu.
OSStatus DuplicateMenu ( MenuRef inSourceMenu, MenuRef *outMenu );
The menu to duplicate.
On exit, a copy of the source menu.
A result code. See “Menu Manager Result Codes.”
Unlike RetainMenu, DuplicateMenu creates an entirely new menu that is an exact copy of the original menu. The menu definition for the new menu will receive an initialization message/event after the menu has been fully created.
Menus.h
Duplicates a menubar handle.
OSStatus DuplicateMenuBar ( MenuBarHandle inMbar, MenuBarHandle *outMbar );
The menubar handle to duplicate.
On exit, contains the new menubar handle.
A result code. See “Menu Manager Result Codes.”
Carbon applications should use this function when duplicating a handle returned from GetMenuBar or GetNewMBar. Doing so ensures that the reference counts of the menus in the menubar handle can be incremented when the handle is duplicated.
Do not use Memory Manager APIs (HandToHand, NewHandle, and so on) to duplicate such a handle.
Menus.h
Enables all items in a menu.
void EnableAllMenuItems ( MenuRef theMenu );
The menu whose items to enable.
This function is equivalent to older code that OR'd the enableFlags field of the MenuInfo structure (now opaque in Carbon) with 0xFFFFFFFE. It enables all items (including items past item 31) but does not affect the state of the menu title.
Menus.h
Enables the menu item with a specified command ID.
void EnableMenuCommand ( MenuRef inMenu, MenuCommand inCommandID );
The menu in which to begin searching for the item. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID of the menu item to be enabled. If more than one item has this command ID, only the first will be enabled.
If you have access to the menu item index, in most cases you should use EnableMenuItem instead, as that function is faster and requires no searching. For example, when receiving a kEventCommandUpdateStatus event, the HICommand structure contains both the menu item’s command ID and index. If you wanted to enable the menu item, you should call EnableMenuItem.
Menus.h
Enables a menu item or a menu.
void EnableMenuItem ( MenuRef theMenu, MenuItemIndex item );
The menu containing the item to be enabled.
The item number of the menu item that you wish to enable. If you pass 0, EnableMenuItem enables the menu title and all items in the menu that were not previously individually disabled.
The EnableMenuItem function enables a menu item so that the user can choose the item from the menu. If the menu item has an associated icon, that icon is also enabled, unless the icon was previously individually disabled with the function DisableMenuItemIcon.
Note that EnableMenuItem calls the InvalMenuBar function to update the menu bar the next time through the event loop.
See also the DisableMenuItem and IsMenuItemEnabled functions.
Menus.h
Enables the icon associated with a menu item.
void EnableMenuItemIcon ( MenuRef theMenu, MenuItemIndex item );
The menu containing the icon to be enabled.
The item number of the menu item containing the icon.
Your application can use the EnableMenuItemIcon function to enable individual menu item icons that have been previously disabled by a call to the function DisableMenuItemIcon. The menu item that contains the icon is unaffected by calling EnableMenuItemIcon. Note that enabling the icon of a currently disabled menu item has no visual effect; however, once the menu item is enabled, the icon is also enabled.
See also the DisableMenuItemIcon and IsMenuItemIconEnabled functions.
Menus.h
Highlights a menu title or the entire menu bar.
void FlashMenuBar ( MenuID menuID );
The menu ID of the menu whose title you want to highlight. Pass zero in this parameter to signal a visual alert (that is, flash the entire screen) If you pass a menu ID that is not in the menubar, FlashMenuBar returns immediately without flashing the bar or any menu title.
Call this function twice if you want the menu or menu bar to blink.
Only one menu title can be highlighted at a time. If no menus are currently highlighted, calling FlashMenuBar with a specific menu ID highlights the title of that menu. If you call FlashMenuBar again specifying another menu ID that is different from that of the previously highlighted menu title, FlashMenuBar restores the previously highlighted menu to normal and then highlights the title of the specified menu.
If you pass zero for the menu ID, this function flashes the entire screen, as if an alert had occurred while the user had specified the “Flash the screen when an alert sound occurs” checkbox in the Universal Access preference pane.
Menus.h
Gets the font family reference and style from the menu identifier and menu item number returned by the function MenuSelect.
OSStatus GetFontFamilyFromMenuSelection ( MenuRef menu, MenuItemIndex item, FMFontFamily *outFontFamily, FMFontStyle *outStyle );
A menu handle.
A menu item index.
A pointer to the font family reference associated with the menu item.
A pointer to the font style associated with the menu item.
A result code. See “Menu Manager Result Codes.”
You use this function to obtain information from a font menu created using CreateStandardFontMenu, AppendResMenu, InsertFontResMenu, InsertIntlResMenu, or InsertResMenu.
Menus.h
Finds a menu item with a specified command ID.
OSStatus GetIndMenuItemWithCommandID ( MenuRef inMenu, MenuCommand inCommandID, UInt32 inItemIndex, MenuRef *outMenu, MenuItemIndex *outIndex );
The menu in which to begin searching for items with the specified command ID. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID for which to search.
The 1-based index of the menu item to retrieve. In CarbonLib 1.0.x, this parameter must be 1. In CarbonLib 1.1 and Mac OS X 1.0, this parameter may vary from 1 to the number of menu items with the specified command ID.
On exit, the menu containing the menu item with the specified command ID.
On exit, the item index of the menu item with the specified command ID.
A result code. See “Menu Manager Result Codes.”
This API searches the specified menu and its submenus for the n'th menu item with the specified command ID. You often want to use this function in conjunction with CountMenuItemsWithCommandID.
In CarbonLib 1.1 and earlier, only the first menu item will be returned. In CarbonLib 1.2 and Mac OS X v10.0 and later, this API will iterate over all menu items with the specified command ID and return the itemIndex’th one.
In Mac OS X v10.0 and CarbonLib 1.0 through 1.4, this function searches only top-level menus (that is, those that are visible in the menu bar) and submenus of top-level menus. It does not search hierarchical menus that are in the menu bar but are not submenus of a top-level menu. For example, it does not search menus that are inserted for use in a popup menu. In Mac OS X v10.1 and later, and CarbonLib 1.5 and later, this function also searches hierarchical menus.
Menus.h
Returns the value of a menu item’s keyboard equivalent field.
Not recommended
void GetItemCmd ( MenuRef theMenu, MenuItemIndex item, CharParameter *cmdChar );
The menu containing the menu item whose keyboard equivalent you want to obtain.
An integer representing the item number of the menu item whose keyboard equivalent you want to determine.
On output, an integer representing the item’s keyboard equivalent field. The Menu Manager uses this value to map keyboard equivalents to menu commands or to indicate special characteristics of the menu item.
If the value referenced through the cmdChar parameter contains 0x1B, the menu item has a submenu; a value of 0x1C indicates that the item has a text encoding; a value of 0x1D indicates that the Menu Manager reduces the item’s 'ICON' resource; and a value of 0x1E indicates that the item has an 'SICN' resource.
You should call GetMenuItemCommandKey , GetMenuItemHierarchicalID , and GetMenuItemTextEncoding instead of GetItemCmd to obtain a menu item’s keyboard equivalent and text encoding and to determine that a menu item has a submenu.
The GetItemCmd function returns the value in the keyboard equivalent field of the specified menu item in the value pointed to by the cmdChar parameter (or 0 if the item doesn’t have a keyboard equivalent, submenu, text encoding, reduced icon, or small icon).
Menus.h
Returns a menu item’s mark.
void GetItemMark ( MenuRef theMenu, MenuItemIndex item, CharParameter *markChar );
The menu containing the item.
The menu index of the item.
On output, an integer representing the mark of the menu item or its submenu (item has a submenu). See the Font Manager for a list of character marking constants that this function can obtain. This parameter is set to 0 if the menu item has neither mark nor submenu.
You should call GetMenuItemHierarchicalID instead of GetItemMark to obtain the menu ID of a menu item’s submenu. However, you can still use GetItemMark to obtain the mark of a menu item.
Menus.h
Returns a menu item’s text style.
void GetItemStyle ( MenuRef theMenu, MenuItemIndex item, Style *chStyle );
The menu containing the item.
The menu index of the item.
On output, an integer representing the menu item’s text style. The functions returns one of the following constants: normal, bold, italic, underline, outline, shadow, condense, and extend .
Menus.h
Determines the current height of the menu bar.
short GetMBarHeight ( void );
The current height, in pixels, of the menu bar.
The GetMBarHeight function determines the menu bar height based on factors such as the current script system and theme.
Menus.h
Creates a menu from the specified menu and extended menu resources.
Not recommended
MenuRef GetMenu ( short resourceID );
The resource ID of the menu and extended menu that defines the characteristics of the menu. You typically use the same number for a menu’s resource ID as the number that you specify for the menu ID in the menu resource.
The new menu. You can use the returned menu handle to refer to this menu in most Menu Manager functions. If GetMenu is unable to read the menu or menu definition function from the resource file, GetMenu returns null. See the description of the MenuRef data type.
Unless you must support legacy code, you should not use functions like GetMenu that rely on menus stored as resources. Instead, you should define menus in Interface Builder, store them as nib files, and then call the Interface Builder Services function CreateMenuFromNib to create them.
GetMenu reads the menu definition function into memory (if not already present) and stores a handle to the menu definition function in the menu structure. GetMenu does not insert the newly created menu into the current menu list.
You typically use the GetMenu function only when you create submenus; you can create all your pull-down menus at once using the function GetNewMBar, and you can create pop-up menus using the standard pop-up menu button control definition function.
After reading the 'MENU' resource, GetMenu searches for an extended menu resource and an 'mctb' resource with the same resource ID as the 'MENU' resource. If the specified 'mctb' resource exists, GetMenu uses SetMCEntries to add the entries defined by the resource to the application’s menu color information table. If the 'mctb' resource does not exist, GetMenu uses the default colors specified in the menu bar entry of the application’s menu color information. If neither a menu bar entry nor a 'mctb' resource exists, GetMenu uses the standard colors for the menu.
Storing the definitions of your menus in resources (especially menu titles and menu items) makes your application easier to localize.
After creating a menu with GetMenu or NewMenu , use InsertMenuItem , AppendMenu , or InsertResMenu to add menu items to the menu. To add a menu created by GetMenu to the current menu list, use InsertMenu. To update the menu bar with any new menu titles, use DrawMenuBar.
Menus in a resource must not be purgeable nor should the resource lock bit be set. Do not define a “circular” hierarchical menu—that is, a hierarchical menu in which a submenu has a submenu whose submenu is a hierarchical menu higher in the chain.
To release the memory associated with a menu that you created using GetMenu, first call DeleteMenu to remove the menu from the current menu list and to remove any entries for this menu in your application’s menu color information table then call DisposeMenu to dispose of the menu structure.
In Carbon, the GetMenu function always returns a newly created MenuRef. Prior to Carbon, GetMenu would first check if the menu was already in memory. If so, GetMenu would return the in-memory copy. This behavior is no longer supported.
Carbon does not support custom menu definitions stored in 'MDEF' resources. If you want to specify a custom menu definition for GetMenu, you must compile your definition function directly in your application and then register the function by calling RegisterMenuDefinition. When GetMenu gets a resourceID value that doesn't recognize, it checks a special mapping table to find the pointer that's registered for the resourceID parameter. It then calls that function to implement your menu.
Menus.h
Gets the attributes of a menu.
OSStatus GetMenuAttributes ( MenuRef menu, MenuAttributes *outAttributes );
The menu.
On exit, contains the attributes of the menu. See “Menu Attribute Constants” for a list of possible values.
A result code. See “Menu Manager Result Codes.”
Menus.h
Gets a handle to a copy of the current menu list.
MenuBarHandle GetMenuBar ( void );
A handle to a copy of the current menu list. See the description of the MenuBarHandle data type.
The GetMenuBar function creates a copy of the current menu list and returns a handle to the copy. You can save the returned menu list and then add menus to or remove menus from the current menu list using InsertMenu , DeleteMenu , or ClearMenuBar. You can later restore the saved menu list using SetMenuBar.
To release the memory occupied by a saved menu list, use the DisposeMenuBar function.
GetMenuBar doesn’t copy the menu structures, just the menu list (which contains handles to the menu structures). Do not dispose of any menus in a saved menu list if you wish to restore the menu list later.
Menus.h
Locates the menu item with a specified command ID and returns its mark character.
OSStatus GetMenuCommandMark ( MenuRef inMenu, MenuCommand inCommandID, UniChar *outMark );
The menu in which to begin searching for the item. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID of the menu item to be examined. If more than one item has this command ID, only the first will be examined.
On exit, the menu item's mark character.
A result code. See “Menu Manager Result Codes.”
If you have access to the menu item index, in most cases you should use GetItemMark instead, as that function is faster and requires no searching.
Menus.h
Retrieves property data for a menu item with the specified command ID.
OSStatus GetMenuCommandProperty ( MenuRef inMenu, MenuCommand inCommandID, OSType inPropertyCreator, OSType inPropertyTag, ByteCount inBufferSize, ByteCount *outActualSize, void *inPropertyBuffer );
The menu in which to search for the command ID. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID of the menu item containing the property. Note that if more than one item has the same command ID, only the first match is used.
The four-character creator code of the application.
The four-character tag of the property to obtain.
The size of the buffer to hold the retrieved data, in bytes.
The actual size of the property data. If you do not need this information, pass NULL.
A pointer to the buffer in which to place the data. On return, the buffer contains the property data.
A result code. See “Menu Manager Result Codes.”
If you have access to the menu item index, in most cases you should use GetMenuItemProperty instead, as that function is faster and requires no searching.
Menus.h
Retrieves the size of the property data for a menu item with the specified command ID.
OSStatus GetMenuCommandPropertySize ( MenuRef inMenu, MenuCommand inCommandID, OSType inPropertyCreator, OSType inPropertyTag, ByteCount *outSize );
The menu in which to search for the command ID. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID of the menu item containing the property. If more than one menu item has the same command ID, only the first match is used.
The four-character creator code of the application.
The four-character tag of the property data whose size you want to obtain.
On return, contains the size of the property data.
A result code. See “Menu Manager Result Codes.”
If you have access to the menu item index, in most cases you should use GetMenuItemPropertySize instead, as that function is faster and requires no searching.
Menus.h
Obtains the menu definition structure for a menu.
OSStatus GetMenuDefinition ( MenuRef menu, MenuDefSpecPtr outDefSpec );
The menu whose menu definition structure you want to obtain.
On return, a pointer to the menu’s MenuDefSpec structure.
A result code. See “Menu Manager Result Codes.”
Note that you cannot use this function to obtain the standard system menu definition. If you call GetMenuDefinition on a menu that uses the standard system MDEF or menu content HIView, the function returns menuUsesSystemDefErr.
Menus.h
Returns whether a menu contains space for mark characters.
Not recommended
Boolean GetMenuExcludesMarkColumn ( MenuRef menu );
The menu whose width is to be examined.
Returns true if the menu currently contains no space for mark characters; false if the menu is currently drawn in its full width, with space for mark characters.
See also the SetMenuExcludesMarkColumn function.
You should instead inspect the kMenuExcludesMarkColumn menu attribute using the GetMenuAttributes function.
Menus.h
Obtains the font used in a menu.
OSStatus GetMenuFont ( MenuRef menu, SInt16 *outFontID, UInt16 *outFontSize );
The menu whose font is to be obtained.
On input, a pointer to a signed 16-bit integer. On return, this value identifies the font family ID for the menu font. Note that this is the menu item font, not the menu title font.
On input, a pointer to an unsigned 16-bit integer. On return, this value identifies the size of the font, in points.
A result code. See “Menu Manager Result Codes.”
Your application may use the GetMenuFont function to retrieve the font used for an individual menu, such as a pop-up menu.
Menus.h
Obtains a menu reference corresponding to a menu ID.
MenuRef GetMenuHandle ( MenuID menuID );
The menu ID of the menu whose reference you want to obtain. (Note that this is not the resource ID, although you often assign the menu ID so that it matches the resource ID.) You assign a menu ID in a nib file or in the 'MENU' resource of a menu. If you do not define your menus in nib files or in ‘MENU’' resources, you can assign a menu ID using NewMenu or SetMenuID.
The menu corresponding to the specified ID. If the specified menu is not in the current menu list, GetMenuHandle returns NULL. See the description of the MenuRef data type.
You can also call this function as GetMenuRef (menuID);.
Use the GetMenuHandle function to obtain the menu reference for any of your application’s pull-down menus or submenus in the current menu list, other than the Help menu. You can also use the Help Manager function HMGetHelpMenuHandle to get a handle for your application’s Help menu.
To get a menu reference for a pop-up menu that you create using the pop-up control definition function, call the Control Manager functions GetControlData and GetControlDataSize, passing the tag constant kControlPopupButtonMenuRefTag in the tagName parameter to specify the menu reference.
Menus.h
Obtains the height of a menu, in pixels.
SInt16 GetMenuHeight ( MenuRef menu );
The menu whose height you want to obtain.
The height of the menu, in pixels.
Menus.h
Obtains the ID of a menu.
MenuID GetMenuID ( MenuRef menu );
The menu ID of the menu. See the description of the MenuID data type.
Menus.h
Gets the attributes of a menu item.
OSStatus GetMenuItemAttributes ( MenuRef menu, MenuItemIndex item, MenuItemAttributes *outAttributes );
The menu.
The index of the menu item.
On exit, contains the attributes of the menu item. See “Menu Item Attribute Constants” for a list of possible values.
A result code. See “Menu Manager Result Codes.”
Menus.h
Obtains a menu item’s command ID.
OSErr GetMenuItemCommandID ( MenuRef inMenu, MenuItemIndex inItem, MenuCommand *outCommandID );
The menu that contains the menu item whose command ID you want to obtain.
The menu index of the item.
Pass a pointer to an unsigned 32-bit integer value. On return, the value is set to the item’s command ID.
A result code. See “Menu Manager Result Codes.”
After a successful call to MenuSelect, MenuEvent , or MenuKey, call the GetMenuItemCommandID function to get a menu item’s command ID. You can use a menu item’s command ID as a position-independent method of signalling a specific action in an application.
See also the function SetMenuItemCommandID.
Menus.h
Gets the keyboard equivalent of a menu item.
OSStatus GetMenuItemCommandKey ( MenuRef inMenu, MenuItemIndex inItem, Boolean inGetVirtualKey, UInt16 *outKey );
The menu containing the item.
The item whose keyboard equivalent you want to retrieve.
Indicates whether to retrieve the item's character code (false) or virtual keycode equivalent (true).
On exit, the keyboard equivalent of the item.
A result code. See “Menu Manager Result Codes.”
A menu item's keyboard equivalent may be either a character code or a virtual keycode. An item's character code and virtual keycode are stored separately and may contain different values, but only one is used by the Menu Manager at any given time. When requesting a menu item's virtual keycode equivalent, you should first check that the item is using a virtual keycode by testing the kMenuItemAttrUseVirtualKey attribute for that item. If this attribute is not set, the item's virtual keycode is ignored by the Menu Manager. Note that zero is a valid virtual keycode, so you cannot test the returned keycode against zero to determine if the item is using a virtual keycode equivalent. You must test the kMenuItemAttrUseVirtualKey attribute.
Menus.h
Obtains a menu item’s font ID.
OSErr GetMenuItemFontID ( MenuRef inMenu, MenuItemIndex inItem, SInt16 *outFontID );
The menu that contains the menu item for which you wish to get a font ID.
The menu index of the item.
Pass a pointer to a signed 16-bit integer value. On return, the value is set to the font ID for the menu item.
A result code. See “Menu Manager Result Codes.”
See also the function SetMenuItemFontID.
Menus.h
Returns the submenu attached to a menu item.
OSStatus GetMenuItemHierarchicalMenu ( MenuRef inMenu, MenuItemIndex inItem, MenuRef *outHierMenu );
The parent menu.
The parent item.
On exit, the item's submenu, or NULL if it does not have one.
A result code. See “Menu Manager Result Codes.”
GetMenuItemHierarchicalMenu will return the submenu attached to a menu item regardless of how the submenu was specified. If the submenu was specified by menu ID (using SetItemCmd or SetMenuItemHierarchicalID), GetMenuItemHierarchicalMenu will return the currently installed menu with that ID, if any. The only case where GetMenuItemHierarchicalMenu will fail to return the item's submenu is when the submenu is specified by menu ID, but the submenu is not currently inserted in the menu bar.
Menus.h
Obtains a handle to a menu item’s icon.
OSErr GetMenuItemIconHandle ( MenuRef inMenu, MenuItemIndex inItem, UInt8 *outIconType, Handle *outIconHandle );
The menu that contains the menu item for which you wish to obtain the handle.
The menu index of the item.
Pass a pointer to an unsigned 8-bit value. On return, the value specifies the type of icon ('ICON', 'cicn', 'SICN', icon suite, CGImageRef, or IconRef) for which you are obtaining a handle. If the menu item has no icon attached, this parameter will contain kMenuNoIcon. See “Menu Item Icon Type Constants” for descriptions of possible values.
Pass a pointer to a handle. On return, outIconHandle contains a handle to the icon that is attached to the menu item. If the menu item has no icon attached, this parameter contains NULL.
A result code. See “Menu Manager Result Codes.”
The GetMenuItemIconHandle function gets the icon handle and type of icon of the specified menu item. If you wish to get a resource-based menu item icon, call GetItemIcon.
See also the function SetMenuItemIconHandle.
Menus.h
Gets the indent level of a menu item.
OSStatus GetMenuItemIndent ( MenuRef inMenu, MenuItemIndex inItem, UInt32 *outIndent );
The menu containing the item.
The item whose indent level you want to retrieve.
On exit, the indent level of the item.
A result code. See “Menu Manager Result Codes.”
The indent level of an item is an amount of extra space added to the left of the item's icon or checkmark. The level is simply a number, starting at zero, which the Menu Manager multiplies by a constant to get the indent in pixels. The default indent level is zero.
Menus.h
Obtains the keyboard glyph for a menu item’s keyboard equivalent.
OSErr GetMenuItemKeyGlyph ( MenuRef inMenu, MenuItemIndex inItem, SInt16 *outGlyph );
The menu that contains the menu item for which you wish to get the keyboard glyph.
The menu index of the item.
A pointer to a signed 16-bit integer value. On return the value is set to the modifier key glyph. For a description of available keyboard glyphs, see “Menu Glyph Constants.”
A result code. See “Menu Manager Result Codes.”
See also the function SetMenuItemKeyGlyph.
Menus.h
Obtains the modifier keys that must be pressed with a character key to select a particular menu item.
OSErr GetMenuItemModifiers ( MenuRef inMenu, MenuItemIndex inItem, UInt8 *outModifiers );
The menu that contains the menu item for which you wish to get the modifier key(s).
The menu index of the item.
A pointer to an unsigned 8-bit value. On return, the bits of the value are set to indicate the modifier keys that can be used in selecting the menu item; see “Modifier Key Mask Constants.”
A result code. See “Menu Manager Result Codes.”
See also the function SetMenuItemModifiers.
Menus.h
Obtains a piece of data that has been previously associated with a menu item.
OSStatus GetMenuItemProperty ( MenuRef menu, MenuItemIndex item, OSType propertyCreator, OSType propertyTag, ByteCount bufferSize, ByteCount *actualSize, void *propertyBuffer );
The menu containing the item to be examined for associated data.
The index number of the menu item or 0 if the data is associated with the menu as a whole.
A four-character code. Pass your program’s signature (also called a creator), as registered through Apple Developer Technical Support. If your program is of a type that would not normally have a signature (for example, a plug-in), you should still register and use a signature in this case, even though your program’s file may not have the same creator code as the signature that you register. The 'macs' property signature is reserved for the system and may not be used.
A four-character code. Pass the application-defined code identifying the data.
The size of the data to be obtained. If this is unknown, use the function GetMenuItemPropertySize to get the data’s size. If the size specified in the bufferSize parameter does not match the actual size of the property, GetMenuItemProperty only retrieves data up to the size specified or up to the actual size of the property, whichever is smaller, and an error is returned.
On input, a pointer to an unsigned 32-bit integer. On return, this value is set to the actual size of the associated data. You may pass NULL for the actualSize parameter if you are not interested in this information.
On input, a pointer to a buffer. On return, this buffer contains a copy of the data that is associated with the specified menu item.
A result code. See “Menu Manager Result Codes.”
You may use the function GetMenuItemProperty to obtain a copy of data previously set with the function SetMenuItemProperty.
See also the RemoveMenuItemProperty function.
Menus.h
Gets the attributes of a menu item property.
OSStatus GetMenuItemPropertyAttributes ( MenuRef menu, MenuItemIndex item, OSType propertyCreator, OSType propertyTag, OptionBits *attributes );
The menu containing the item whose properties you want to obtain.
The menu index of the item.
The creator code of the property.
The property tag.
On exit, contains the attributes of the property.
A result code. See “Menu Manager Result Codes.”
Currently the only attribute you can receive from this function is the kMenuPropertyPersistent attribute (See “Menu Item Property Attribute Constant”), which currently has no effect on Mac OS X. Therefore, GetMenuItemPropertyAttributes is not useful at this time.
Menus.h
Obtains the size of a piece of data that has been previously associated with a menu item.
OSStatus GetMenuItemPropertySize ( MenuRef menu, MenuItemIndex item, OSType propertyCreator, OSType propertyTag, ByteCount *size );
The menu containing the item to be examined for associated data.
The index number of the menu item or 0 if the data is associated with the menu as a whole.
A four-character code. Pass your program’s signature, as registered through Apple Developer Technical Support. If your program is of a type that would not normally have a signature (for example, a plug-in), you should still register and use a signature in this case, even though your program’s file may not have the same creator code as the signature that you register. The 'macs' property signature is reserved for the system and may not be used.
A four-character code. Pass the application-defined code identifying the data.
On input, a pointer to an unsigned 32-bit integer. On return, this value is set to the actual size of the data.
A result code. See “Menu Manager Result Codes.”
If you want to retrieve a piece of associated data with the function GetMenuItemProperty , you will typically need to use the GetMenuItemPropertySize function beforehand to determine the size of the associated data.
Menus.h
Obtains application-specific information for a menu item.
OSErr GetMenuItemRefCon ( MenuRef inMenu, MenuItemIndex inItem, URefCon *outRefCon );
The menu that contains the menu item for which you wish to get information.
The menu index of the item. In CarbonLib 1.6 and later and Mac OS X v10.2 and later, you may pass zero to obtain the reference constant for the menu itself.
A pointer to an unsigned 32-bit integer value. On return, the value is set to the reference constant associated with the menu item.
A result code. See “Menu Manager Result Codes.”
If you have assigned any data to a menu item using SetMenuItemRefCon function, you can read it using the GetMenuItemRefCon function.
Menus.h
Obtains a menu reference corresponding to a menu ID.
MenuRef GetMenuHandle ( MenuID menuID ); #define GetMenuRef GetMenuHandle
This is simply a redefinition of the GetMenuHandle function.
Menus.h
Retrieves the icon, if any, being used as the title of a menu.
OSStatus GetMenuTitleIcon ( MenuRef inMenu, UInt32 *outType, void **outIcon );
The menu whose icon title to retrieve.
On exit, contains the type of icon being used as the title of the menu. Contains kMenuNoIcon if the menu does not have an icon title.
On exit, contains the icon reference, icon suite reference, or Core Graphics image reference of the icon being used as the title of the menu. If the menu does not have an icon title, this parameter is set to NULL.
A result code. See “Menu Manager Result Codes.”
This function does not increment the reference count of the returned icon, so the caller should not attempt to release it.
Menus.h
Gets information about the menu currently selected by the user.
OSStatus GetMenuTrackingData ( MenuRef theMenu, MenuTrackingData *outData );
The menu about which to get tracking information. Pass NULL to get information about the most recently opened menu; for example, if the user has selected a menu that contains a submenu, and the submenu is open, then GetMenuTrackingData returns the submenu not its parent menu.
On exit, contains tracking data about the menu.
A result code. See “Menu Manager Result Codes.” If the menu is not currently open, menuNotFoundErr is returned.
You can call this function only during menu tracking. As the standard menu definition automatically handles tracking, you would probably need this function only when writing a custom menu definition.
This function replaces direct access to the pre-Carbon low-memory globals TopMenuItem, AtMenuBottom, MenuDisable, and mbSaveLoc. See the Carbon Porting Notes for MenuDefProcPtr for more information.
Menus.h
Gets the display type (pulldown, hierarchical, or popup) of a menu.
OSStatus GetMenuType ( MenuRef theMenu, UInt16 *outType );
The menu whose type to get.
On exit, the type of the menu. The returned value will be one of the Appearance Manager ThemeMenuType constants: kThemeMenuTypePullDown, kThemeMenuTypePopUp, or kThemeMenuTypeHierarchical. The kThemeMenuTypeInactive bit is never set.
A result code. See “Menu Manager Result Codes.”
You can call this function only when the menu is displayed. If the menu is not currently open, an error is returned. The display type of a menu may vary from one menu tracking session to another; for example, the same menu might be displayed as a pulldown menu and as a popup menu.
Menus.h
Obtains the width of the menu, in pixels.
SInt16 GetMenuWidth ( MenuRef menu );
The menu whose width you want to obtain.
The width of the menu, in pixels.
Menus.h
Reads in the definition of a menu bar from an 'MBAR' resource.
Not recommended
MenuBarHandle GetNewMBar ( short menuBarID );
The resource ID of an 'MBAR' resource that specifies the menus for a menu bar.
A handle to the menu list. (If the resource isn’t already in memory, GetNewMBar reads it into memory.) If GetNewMBar can’t read the resource, GetNewMBar returns NULL. See the description of the MenuBarHandle data type.
Unless you must support legacy code, you should not use functions like GetNewMBar that rely on menus and menu bars stored as resources. Instead, you should define menus in Interface Builder, store them as nib files, and then call the Interface Builder Services functions CreateMenuFromNib , CreateMenuBarFromNib, or SetMenuBarFromNibto create them.
The GetNewMBar function reads in the definition of a menu bar and its associated menus from an ' MBAR ' resource. The ' MBAR ' resource identifies the order of menus contained in its menu bar. For each menu, it also specifies the menu’s resource ID. The GetNewMBar function reads in each menu from the ' MENU ' resource with the resource ID specified in the ' MBAR ' resource.
The GetNewMBar function creates a menu list for the menu bar defined by the ' MBAR ' resource and returns a handle to the menu list. GetNewMBar uses GetMenu to read in each individual menu.
After reading in menus from an ' MBAR ' resource, use SetMenuBar to make the menu list created by GetNewMBar the current menu list. Then use DrawMenuBar to update the menu bar.
To release the memory occupied by a menu list, use the function DisposeMenuBar
The GetNewMBar function first saves the current menu list and then clears the current menu list and your application’s menu color information table. It then creates a new menu list. Before returning a handle to the new menu list, the GetNewMBar function restores the current menu list to the previously saved menu list, but GetNewMBar does not restore the previous menu color information table. To save and then restore your application’s current menu color information table, call the function GetMCInfo before GetNewMBar and call SetMCInfo afterward.
While you supply only the resource ID of an 'MBAR' resource to the GetNewMBar function, your application often needs to use the menu IDs defined in each of your menus’ 'MENU' resources. Most Menu Manager functions require either a menu ID or a handle to a menu structure to perform operations on a specific menu. For menus in the current menu list, you can use the GetMenuHandle function to get the handle to a menu structure for a menu with a given menu ID.
Menus.h
Conceals the menu bar.
void HideMenuBar ( void );
The HideMenuBar function makes the menu bar invisible and unselectable by the user. You can use this function to enable full-screen display; however, in Mac OS X v10.2 and later, you should call the SetSystemUIMode function (available in MacApplication.h) instead.
Note that calling this function causes the kEventMenuBarHidden event to be sent to the application target (if your application has registered for the event).
Also see the ShowMenuBar and IsMenuBarVisible functions.
Menus.h
Highlights or unhighlights menu titles.
void HiliteMenu ( MenuID menuID );
The menu ID of the menu whose title should be highlighted. If the menu title of the specified menu is already highlighted, HiliteMenu does nothing. If the menu ID is 0 or the specified menu ID isn’t in the current menu list, HiliteMenu unhighlights whichever menu title is currently highlighted (if any).
The IsMenuKeyEvent, MenuSelect, MenuEvent, and MenuKey functions highlight the title of the menu containing the item chosen by the user. After performing the chosen task, your application should unhighlight the menu title by calling HiliteMenu and passing 0 in the menuID parameter.
Menus.h
Inserts an existing menu into the current menu list.
void InsertMenu ( MenuRef theMenu, MenuID beforeID );
The menu to insert.
An integer that indicates where in the current menu list the menu should be inserted. InsertMenu inserts the menu into the current menu list before the menu whose menu ID is specified in the beforeID parameter. If the number in the beforeID parameter is 0 (or it isn’t the ID of any menu in the menu list), InsertMenu adds the new menu after all others (except before the Help menu). If the menu is already in the current menu list or the menu list is already full, InsertMenu does nothing.
To insert a submenu into the current menu list, specify –1 or the equivalent constant kInsertHierarchicalMenu for the beforeID parameter. The submenus in the submenu portion of the menu list do not have to be currently associated with a hierarchical menu item; you can store submenus in the menu list and later specify that a menu item has a submenu if needed. However, note that during command key matching the Menu Manager scans all menus in the menu list for modifiers, including submenus that are not associated with any menu item.
You can also specify –1 for the beforeID parameter to insert a pop-up menu into the current menu list. However, if you use the standard pop-up control definition function, the pop-up control automatically inserts the menu into the current menu list according to the needs of the pop-up control.
Menus inserted using this function are added to a menu list attached to the current root menu. To obtain or set this root menu, call AcquireRootMenu and SetRootMenu respectively.
Inserting a menu in the root menu (menu bar) increments its reference count; removing the menu decrements its reference count.
To change a menu title, call SetMenuItemTextWithCFString.
Menus.h
Inserts a new menu item with text from a CFString.
OSStatus InsertMenuItemTextWithCFString ( MenuRef inMenu, CFStringRef inString, MenuItemIndex inAfterItem, MenuItemAttributes inAttributes, MenuCommand inCommandID );
The menu in which to insert the new item.
The text of the new item.
The item after which to insert the new item. Pass zero to insert the item at the beginning of the menu. If the index value is greater than the number of items in the menu, the item is inserted at the end of the menu.
The attributes of the new item.
The command ID of the new item.
A result code. See “Menu Manager Result Codes.”
If the CFString is mutable, the Menu Manager will make its own copy of the CFString before returning from InsertMenuItemWithCFString. Modifying the string after calling InsertMenuItemTextWithCFString will have no effect on the menu item's actual text.
If the CFString is immutable, the Menu Manager increments the reference count of the string before returning.
The caller may release the string after calling InsertMenuItemTextWithCFString.
Menus.h
Requests that the menu’s enable state be recalculated.
OSStatus InvalidateMenuEnabling ( MenuRef inMenu );
The menu whose enable states should be recalculated. Pass NULL to recalculate enable states for all menus in the root menu.
A result code. See “Menu Manager Result Codes.”
State changes in an application can cause changes in enable state of a menu’s menu items. For example, selecting a block of text would usually require the Copy menu item to become enabled. Menu items are typically updated in response to a kEventCommandUpdateStatus Carbon event. However, the update event usually occurs only before an command key press or a click in the menu bar. To explicitly update the enable states for a menu, you can call InvalidateMenuEnabling.
Note that the Carbon Event Manager automatically requests recalculation of enable states for all top-level menus when
it dispatches a user event
the user focus changes
the active window changes
so in many cases you may not need to explicitly call this function.
Menus.h
Invalidates a group of menu items so that they will be redrawn when UpdateInvalidMenuItems is next called.
OSStatus InvalidateMenuItems ( MenuRef inMenu, MenuItemIndex inFirstItem, ItemCount inNumItems );
The menu whose items to invalidate.
The first item to invalidate.
The number of items to invalidate.
A result code. See “Menu Manager Result Codes.”
Menu items are automatically invalidated when their contents are changed using Menu Manager APIs while the menu is open. However, you might need to use this function if you have a custom menu definition that draws based on information not contained in the menu. For example, say you have a custom menu definition that draws a menu item using a color stored elsewhere in an application-defined data structure. If you change the color in the data structure, there is no way for the menu definition to know this has occurred. Calling InvalidateMenuItems after changing the color in the structure indicates that the menu should be redrawn.
Menus.h
Invalidates the menu size so that it will be recalculated when next displayed.
OSStatus InvalidateMenuSize ( MenuRef inMenu );
The menu whose size you want to invalidate.
A result code. See “Menu Manager Result Codes.”
Prior to Carbon, the technique for invalidating the menu size was to set the width and height to -1. Although this technique still works, for best compatibility you should call InvalidateMenuSize so that the Menu Manager has explicit notification that the menu is invalid.
Menus.h
Invalidates the menu bar.
void InvalMenuBar ( void );
The InvalMenuBar function marks the menu bar as changed and in need of updating. When the Carbon Event Manager checks incoming events for regions that require updating, the Carbon Event Manager also checks to determine whether the menu bar requires updating (because of a call to InvalMenuBar). If the menu bar needs updating, the Carbon Event Manager calls the DrawMenuBar function to draw the menu bar.
You can use InvalMenuBar instead of DrawMenuBar to minimize blinking in the menu bar. For example, if you have several application-defined functions that can change the enabled state of a menu and each calls DrawMenuBar, you can replace the calls to DrawMenuBar with calls to InvalMenuBar. In this way the menu bar is redrawn only once instead of multiple times in quick succession. If you need to make immediate changes to the menu bar, use DrawMenuBar. If you want to redraw the menu bar at most once each time through your event loop, use InvalMenuBar. Note. however, that most Menu Manager calls that affect the menu bar call InvalMenuBar before returning. so you probably won’t need to call it yourself.
Menus.h
Determines if the menubar is invalid and should be redrawn.
Boolean IsMenuBarInvalid ( MenuRef rootMenu );
The root menu for the menubar to be examined. Pass NULL to check the state of the current menubar.
Menus.h
Reports whether the menu bar is currently visible.
Boolean IsMenuBarVisible ( void );
Returns true if the menu bar is currently visible; otherwise, false.
Also see the HideMenuBar and ShowMenuBar functions.
Menus.h
Determines if the menu item with a specified command ID is enabled.
Boolean IsMenuCommandEnabled ( MenuRef inMenu, MenuCommand inCommandID );
The menu in which to begin searching for the item. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID of the menu item to examine. If more than one item has this command ID, only the first will be examined.
If you have access to the menu item index, in most cases you should use IsMenuItemEnabled instead, as that function is faster and requires no searching.
Menus.h
Reports whether a given menu or menu item is enabled.
Boolean IsMenuItemEnabled ( MenuRef menu, MenuItemIndex item );
The menu containing the item to be examined.
The item number of the menu item. Pass 0 to specify the menu title and determine whether the menu as a whole is enabled.
Returns true if the menu item is currently enabled; otherwise, false.
Your application can use the IsMenuItemEnabled function to determine whether specific menu items, even those with item numbers greater than 31, are currently enabled and can therefore be selected by the user.
Note that this function ignores the enable state of the menu when returning the enable state of a menu item. For example, if you call IsMenuItemEnabled on an enabled item while its parent menu is disabled, the function still returns true.
Menus.h
Reports whether a given menu item icon is enabled.
Boolean IsMenuItemIconEnabled ( MenuRef menu, MenuItemIndex item );
The menu containing the icon to be examined.
The item number of the menu item containing the icon.
Returns true if the menu item icon is currently enabled; otherwise, false.
Your application can use the IsMenuItemIconEnabled function to determine whether a specific menu item’s icon is currently enabled or dimmed.
See also the functions DisableMenuItemIcon and EnableMenuItemIcon.
Menus.h
Determines if a menu item is invalid and should be redrawn.
Boolean IsMenuItemInvalid ( MenuRef inMenu, MenuItemIndex inItem );
The menu whose item to examine.
The item to examine.
Returns true if the menu is invalid, false otherwise.
Menus.h
Determines if an event corresponds to a menu command key.
Boolean IsMenuKeyEvent ( MenuRef inStartMenu, EventRef inEvent, MenuEventOptions inOptions, MenuRef *outMenu, MenuItemIndex *outMenuItem );
The menu to search. IsMenuKeyEvent searches for matching menu items in this menu and all of its submenus. Pass NULL to search the current menu bar contents.
The event to match against. Non-keyboard events are ignored.
Options controlling how to search. See “Menu Event Option Constants” for possible options. Pass kNilOptions for the default behavior.
On exit, the menu containing the matching item. Set to NULL if no match was made.
On exit, the menu item that matched. Set to NULL if no match was made.
By default, IsMenuKeyEvent searches the menus in the current menu bar and highlights the menu title of the menu containing the selected item.
Menus.h
Determines if a menu's size is invalid and should be recalculated.
Boolean IsMenuSizeInvalid ( MenuRef inMenu );
The menu whose size you want to examine.
Set to true if the menu size is invalid, false otherwise.
Prior to Carbon, the technique for determining if a menu's size is invalid was to check if the width or height was -1. This technique is not always reliable in Carbon due to implementation changes in the Menu Manager, so you should use IsMenuSizeInvalid instead.
Menus.h
Determines whether a particular event could invoke a contextual menu.
Not recommended
Boolean IsShowContextualMenuClick ( const EventRecord *inEvent );
A pointer to the event structure that describes the event to examine.
If true, the contextual menu should be displayed; if false, not.
Before calling the IsShowContextualMenuClick function, you should call InitContextualMenus. If no error is returned, you can then call IsShowContextualMenuClick.
Unless you must support the legacy WaitNextEvent event model, you should use the Carbon event–based IsShowContextualMenuEvent function instead. In addition, some users may choose to use a two-button mouse with their Macintosh computers, in which case a right-click does not return true with IsShowContextualMenuClick unless the mouse manufacturer’s driver software deliberately returns Control-left-click in place of the right-click. If you want to properly recognize the right-click to invoke a contextual menu, you should use the IsShowContextualMenuEvent function.
Applications should call IsShowContextualMenuClick when they receive non-null events. If IsShowContextualMenuClick returns true, your application should generate its own menu and Apple Event descriptor ( AEDesc), and then call ContextualMenuSelect to display and track the contextual menu, and then handle the user’s choice.
If the mouse-down event did not invoke a contextual menu, then the application should check to see if the event occurred in the menu bar (using the FindWindow function) and, if so, call MenuSelect to allow the user to choose a command from the menu bar.
See also “Contextual Menu Gestalt Selector Constants.”
Menus.h
Determines whether a particular Carbon event could invoke a contextual menu.
Boolean IsShowContextualMenuEvent ( EventRef inEvent );
The event to examine.
Returns true if the application should display a contextual menu, false otherwise.
If your application supports Carbon events, you should use this function in place of the older IsShowContextualMenuClick. This function also properly supports right-click activation of contextual menus, while IsShowContextualMenuClick does not.
However, if your application uses the standard window handler, you probably don’t need to use IsShowContextualMenuEvent, because the standard window handler automatically detects contextual menu clicks and sends the kEventWindowContextualMenuSelect and kEventControlContextualMenuClick events.
Menus.h
Determines if a menu is valid.
Boolean IsValidMenu ( MenuRef inMenu );
The menu to check for validity.
Indicates whether the menu is valid.
The Menu Manager keeps a table that maps menu references to their corresponding (opaque) MenuData structures. A menu is considered valid if its menu reference appears in that table.
Menus.h
Returns the menu ID of the currently highlighted menu in the menu bar.
MenuID LMGetTheMenu ( void );
A value which contains the menu ID of the currently highlighted menu in the menu bar.
Menus.h
Returns the menu ID and index of the menu item under the cursor.
SInt32 MenuChoice ( void );
The high-order word of the function result contains the menu ID of the menu, and the low-order word contains the item number of the menu item chosen by the user. The MenuChoice function returns 0 as the low-order word of its function result if the mouse button was released while the cursor was in the menu bar or outside the menu.
You can use this function in the rare cases that you want to take action based upon the selection of a disabled menu item. For example, say the user is in contextual help mode (activated by pressing the Help key) and wants to get help information about a disabled menu item. You can use MenuChoice to determine which item the user selected and provide help for that item.
Menus.h
Maps a keyboard combination from the event structure to the keyboard equivalent of a menu item in a menu in the current menu list.
Not recommended
UInt32 MenuEvent ( const EventRecord *inEvent );
A pointer to the event structure containing the keyboard equivalent.
A value that indicates the menu ID (in the high 16 bits) and menu item (in the low 16 bits) that the user chose. If the given character does not map to an enabled menu item in the current menu list, MenuEvent returns 0 in its high-order word and the low-order word is undefined.
Note that unless your application uses the WaitNextEvent event model, you should use the Carbon event–based IsMenuKeyEvent instead.
The MenuEvent function does not distinguish between uppercase and lowercase letters. This allows a user to invoke a keyboard equivalent command, such as the Copy command, by pressing the Command key and “c” or “C”. For consistency between applications, you should define the keyboard equivalents of your commands so that they appear in uppercase in your menus.
If the given character maps to an enabled menu item in the current menu list, MenuEvent highlights the menu title of the chosen menu, returns the menu ID in the high-order word of its function result, and returns the chosen menu item in the low-order word of its function result. After performing the chosen task, your application should unhighlight the menu title using the HiliteMenu function.
You should not define menu items with identical keyboard equivalents. The MenuEvent function scans the menus from right to left and the items from top to bottom. If you have defined more than one menu item with identical keyboard equivalents, MenuEvent returns the first one it finds.
The MenuEvent function first searches the regular portion of the current menu list for a menu item with a keyboard equivalent matching the given key. If it doesn’t find one there, it searches the submenu portion of the current menu list. If the given key maps to a menu item in a submenu, MenuEvent highlights the menu title in the menu bar that the user would normally pull down to begin traversing to the submenu. Your application should perform the desired command and then unhighlight the menu title.
Note that some keyboard equivalents are reserved for use by the system, such as Command–Shift–3 annd Command-Shift-4 (for taking screen shots).
Menus.h
Determines if any items in a menu are enabled.
Boolean MenuHasEnabledItems ( MenuRef theMenu );
The menu whose items to examine.
Returns true if one or more items in the menu are enabled, false otherwise.
This function is equivalent to pre-Carbon code that compared the enableFlags field of the MenuInfo structure (now opaque in Carbon) with 0. It checks the enable state of all items to see if any are enabled, but ignores the state of the menu title. It will return true even if the menu title is disabled.
Menus.h
Allows the user to choose a menu item from a menu in the menu bar.
SInt32 MenuSelect ( Point startPt );
The location of the cursor at the time the mouse button was first pressed, in global coordinates. Your application retrieves this point from the kEventParamMouseLocation parameter of a Carbon event, or the where field of the EventRecord structure.
If the user chooses an enabled menu item (including any item from a submenu), the MenuSelect function returns a value as its function result that indicates which menu and menu item the user chose. The high-order word of the function result contains the menu ID of the menu, and the low-order word contains the item number of the menu item chosen by the user.
If your application uses Carbon events, you probably don’t need to use this function. The standard event handler installed by the Carbon Event Manager function RunApplicationEventLoop calls MenuSelect for you to begin tracking when the user clicks in a menu. If you do not call RunApplicationEventLoop, however, you will need to use this function to initiate menu tracking.
When the user presses the mouse button while the cursor is in the menu bar, your application receives a mouse-down event. To handle mouse-down events in the menu bar, pass the location of the cursor at the time of the mouse-down event as the startPt parameter to MenuSelect. The MenuSelect function displays and removes menus as the user moves the cursor over menu titles in the menu bar, and it handles all user interaction until the user dismisses the menu.
As the user drags the cursor through the menu bar, the MenuSelect function highlights the title of the menu the cursor is currently over and displays all items in that menu. If the user moves the cursor so that it is over a different menu, the MenuSelect function removes the previous menu and unhighlights its menu title.
The MenuSelect function highlights and unhighlights menu items as the user drags the cursor over the items in a menu. The MenuSelect function highlights a menu item if the item is enabled and the cursor is currently over it; it removes such highlighting when the user moves the cursor to another menu item. The MenuSelect function does not highlight disabled menu items.
If the user chooses an enabled menu item (including any item from a submenu), the MenuSelect function returns a value as its function result that indicates which menu and menu item the user chose. The high-order word of the function result contains the menu ID of the menu, and the low-order word contains the item number of the menu item chosen by the user.The MenuSelect function leaves the menu title highlighted; after performing the chosen task your application should unhighlight the menu title using the HiliteMenu function.
If the user chooses an item from a submenu, MenuSelect returns the menu ID of the submenu in the high-order word and the item chosen by the user in the low-order word of its function result. The MenuSelect function also highlights the title of the menu in the menu bar that the user originally displayed in order to begin traversing to the submenu. After performing the chosen task, your application should unhighlight the menu title.
If the user releases the mouse button while the cursor is over a disabled item, in the menu bar, or outside of any menu, the MenuSelect function returns 0 in the high-order word of its function result and the low-order word is undefined. If it is necessary for your application to find the item number of the disabled item, your application can call MenuChoice to return the menu ID and menu item.
Note that MenuSelect sends a number of Carbon events during menu tracking:
kEventMenuBeginTracking when tracking begins, before displaying any menus. An event handler for this event may return userCanceledErr to prevent menu tracking from occurring.
kEventMenuEndTracking after tracking was completed.
kEventMenuChangeTrackingMode when the user switches from the mouse to the keyboard to navigate through menus, or vice versa.
kEventMenuOpening is sent to each menu that the user opens, just before it opens. An event handler for this event may return userCanceledErr to prevent menu tracking from occurring.
kEventMenuClosed is sent to each menu that the user closes.
kEventMenuPopulate is sent to a menu just before it is opened in a menu tracking session. This event is sent only once per menu tracking session.
kEventMenuEnableItems is sent to a menu just before it is opened in a menu tracking session. This event is sent only once per menu tracking session.
kEventCommandUpdateStatus is sent to a menu just before it is opened in a menu tracking session. This event is sent only once per menu tracking session.
kEventMenuTargetItem is sent to a menu when the mouse passes over a menu item or if the keyboard is used to select a menu item. This event is sent for both enabled and disabled menu items, and is also sent when the mouse is over a menu title.
kEventCommandProcess is sent to a menu when the user chooses one of its menu items.
For more details about these Carbon events, see the Carbon Event Manager Reference.
Carbon does not support desk accessories, so MenuSelect cannot be used in Mac OS X to pass keyboard equivalents to desk accessories.
Menus.h
Displays a pop-up menu without using the standard pop-up control definition function.
SInt32 PopUpMenuSelect ( MenuRef menu, short top, short left, MenuItemIndex popUpItem );
The pop-up menu to be displayed.
The y-coordinate of the top-left corner of the selected menu item when the menu opens. This value should be in global coordinates.
The x-coordinate of the top-left corner of the selected menu item when the menu opens. This value should be in global coordinates.
The index of the menu item to display at the global point (top, left). If you pass zero, the first menu item is positioned at the indicated point.
The menu ID of the chosen menu in the high 16-bit word of the function result and the chosen menu item index value in the low 16-bit word. If no item was selected, the result is zero.
If your application uses the standard pop-up control definition function, your application does not need to use the PopUpMenuSelect function. PopUpMenuSelect uses the location specified by the top and left parameters to determine where to display the specified item of the pop-up menu. PopUpMenuSelect displays the pop-up menu so that the menu item specified in the popUpItem parameter appears highlighted at the specified location.
The PopUpMenuSelect function highlights and unhighlights menu items and handles all user interaction until the user releases the mouse button.
Note that PopUpMenuSelect sends a number of Carbon events during menu tracking (these are the same as those sent for MenuSelect):
kEventMenuBeginTracking when tracking begins, before displaying any menus. An event handler for this event may return userCanceledErr to prevent menu tracking from occurring.
kEventMenuEndTracking after tracking was completed.
kEventMenuChangeTrackingMode when the user switches from the mouse to the keyboard to navigate through menus, or vice versa.
kEventMenuOpening is sent to each menu that the user opens, just before it opens. An event handler for this event may return userCanceledErr to prevent menu tracking from occurring.
kEventMenuClosed is sent to each menu that the user closes.
kEventMenuPopulate is sent to a menu just before it is opened in a menu tracking session. This event is sent only once per menu tracking session.
kEventMenuEnableItems is sent to a menu just before it is opened in a menu tracking session. This event is sent only once per menu tracking session.
kEventCommandUpdateStatus is sent to a menu just before it is opened in a menu tracking session. This event is sent only once per menu tracking session.
kEventMenuTargetItem is sent to a menu when the mouse passes over a menu item or if the keyboard is used to select a menu item. This event is sent for both enabled and disabled menu items, and is also sent when the mouse is over a menu title.
kEventCommandProcess is sent to a menu when the user chooses one of its menu items.
For more details about these Carbon events, see the Carbon Event Manager Programming Guide.
Menus.h
Registers a binding between a resource ID and a menu definition function.
OSStatus RegisterMenuDefinition ( SInt16 inResID, MenuDefSpecPtr inDefSpec );
An MDEF resource ID, as used in a 'MENU' resource.
Specifies the MenuDefUPP that should be used for menus with the given MDEF proc ID. Pass NULL if you want to unregister the menu definition.
A result code. See “Menu Manager Result Codes.”
Mac OS X does not allow you to store custom menu definitions in resources. However, some older functions such as GetMenu expect an 'MDEF' resource ID to be in the 'MENU' resource when creating menus . To work around this, you can use RegisterMenulDefinition to register “virtual” resource IDs for your menu definition functions. When GetMenu (or a similar function) attempts to access an 'MDEF' resource, the Menu Manager uses the menu definition specified by the MenuDefSpec structure instead.
Menus.h
Removes a property from a menu item with the specified command ID.
OSStatus RemoveMenuCommandProperty ( MenuRef inMenu, MenuCommand inCommandID, OSType inPropertyCreator, OSType inPropertyTag );
The menu in which to begin searching for the item. Pass NULL to begin searching with the root menu. The search will descend into all the submenus of this menu.
The command ID of the menu item whose property you want to remove. If more than one item has the same command ID, only the first will be modified.
The four-character creator code for the application.
The four-character tag identifying the property to remove.
A result code. See “Menu Manager Result Codes.”
If you have access to the menu item index, in most cases you should use RemoveMenuItemProperty instead, as that function is faster and requires no searching.
Menus.h
Removes a piece of data that has been previously associated with a menu item.
OSStatus RemoveMenuItemProperty ( MenuRef menu, MenuItemIndex item, OSType propertyCreator, OSType propertyTag );
The menu containing the item whose associated data is to be removed.
The index number of the menu item or 0 if the data is associated with the menu as a whole.
A four-character code. Pass your program’s signature, as registered through Apple Developer Technical Support. If your program is of a type that would not normally have a signature (for example, a plug-in), you should still register and use a signature in this case, even though your program’s file may not have the same creator code as the signature that you register. The 'macs' property signature is reserved for the system and may not be used.
A four-character code. Pass the application-defined code identifying the associated data.
A result code. See “Menu Manager Result Codes.”
Your application may remove data set with the SetMenuItemProperty function by calling the RemoveMenuItemProperty function.
When a menu is destroyed, all of its properties are removed automatically.
Menus.h
Sets the value of the keyboard equivalent field of a menu item.
Not recommended
void SetItemCmd ( MenuRef theMenu, MenuItemIndex item, CharParameter cmdChar );
The menu containing the item.
The menu index of the item.
The value to set for the item’s keyboard equivalent field. The Menu Manager uses this value to map keyboard equivalents to menu s or to define special characteristics of the menu item.
To indicate that the menu item has a submenu, specify 0x1B in the cmdChar parameter; specify a value of 0x1C to indicate that the item has a special text encoding; specify a value of 0x1D to indicate that the Menu Manager should reduce the item’s 'ICON' resource to the size of a small icon; and specify a value of 0x1E to indicate that the item has an 'SICN' resource.
The values 0x01 through 0x1A, as well as 0x1F and 0x21, are reserved for use by Apple. You should not use any of these reserved values in the cmdChar parameter.
You should call SetMenuItemCommandKey , SetMenuItemHierarchicalID , and SetMenuItemTextEncoding instead of SetItemCmd to set a menu item’s keyboard equivalent and text encoding and to indicate that a menu item has a submenu.
You usually define the keyboard equivalents and other characteristics of your menu items in the 'MENU' resource rather than using the SetItemCmd function. The SetItemCmd function sets the value in the keyboard equivalent field of the specified menu item to the value specified by the cmdChar parameter (you can specify 0 if the item doesn’t have a keyboard equivalent, submenu, text encoding, reduced icon, or small icon). If you specify that the item has a submenu, you should provide the menu ID of the submenu as the item’s marking character. If you specify that the item has a special text encoding, you must provide the text encoding in the icon field of the menu item. If you specify that the item has an 'SICN' or a reduced 'ICON' resource, you must provide the icon number in the icon field of the item.
Menus.h
Sets the mark of a menu item.
void SetItemMark ( MenuRef theMenu, MenuItemIndex item, CharParameter markChar );
The menu containing the item.
The menu index of the item.
The mark of the menu item or its submenu (if the item has a submenu). To set the submenu associated with this menu item, specify the menu ID of the submenu in the markChar parameter. You can pass the character marking constants defined in the Font Manager. Pass 0 (noMark)if the menu item has neither mark nor submenu.
You should call SetMenuItemHierarchicalID instead of SetItemMark to set the menu ID of a menu item’s submenu. However, you can still use SetItemMark to set the mark of a menu item.
Menus.h
Sets a menu item’s text style.
void SetItemStyle ( MenuRef theMenu, MenuItemIndex item, StyleParameter chStyle );
The menu containing the item.
The menu index of the item.
An integer representing the menu item’s text style. You can choose from the following constants: normal, bold, italic, underline, outline, shadow, condense, and extend .
Menus.h
Sets the current menu list to a specified menu list.
void SetMenuBar ( MenuBarHandle mbar );
A handle to a menu list that specifies the menus for a menu bar. You should specify a handle returned by GetMenuBar or GetNewMBar.
The SetMenuBar function copies the given menu list to the current menu list. As with GetMenuBar , SetMenuBar doesn’t copy the menu structures, just the menu list (which contains handles to the menu structures).
You can use SetMenuBar to restore a menu list that you previously saved using GetMenuBar or to set the current menu list to a menu list created from a nib file or from GetNewMBar.
The SetMenuBar function sets the current menu list and calls InvalMenuBar so the menu bar can be updated the next time through the event loop; if you want to redraw the menu bar immediately, call the DrawMenuBar function.
Menus.h
Locates the menu item with a specified command ID and sets its mark character.
OSStatus SetMenuCommandMark ( MenuRef inMenu, MenuCommand inCommandID, UniChar inMark );
The menu in which to begin searching for the item. Pass NULL to begin searching with the root menu. The search will descend into all submenus of this menu.
The command ID of the menu item to be modified. If more than one item has this command ID, only the first will be modified.
The new mark character. While this is a Unicode character, only the low byte is currently used as the mark character, and it is interpreted using the application text encoding.
A result code. See “Menu Manager Result Codes.”
If you have access to the menu item index, in most cases you should use SetItemMark instead, as that function is faster and requires no searching.
Menus.h
Sets the property data for a menu item with the specified command ID.
OSStatus SetMenuCommandProperty ( MenuRef inMenu, MenuCommand inCommandID, OSType inPropertyCreator, OSType inPropertyTag, ByteCount inPropertySize, const void *inPropertyData );
The command ID of the menu item whose property you want to set. If more than one item has the same command ID, only the first item’s property is set.
The four-character creator code for the application.
The four-character tag for the property you want to set.
The side of the property data, in bytes.
The property data to set.
A result code. See “Menu Manager Result Codes.”
If you have access to the menu item index, in most cases you should use SetMenuItemProperty instead, as that function is faster and requires no searching.
Menus.h
Sets the menu definition structure for a menu.
OSStatus SetMenuDefinition ( MenuRef menu, const MenuDefSpec *defSpec );
The menu whose menu definition structure you want to set.
The new menu definition structure.
A result code. See “Menu Manager Result Codes.”
You can use this function to change your menu definition on-the-fly.
Menus.h
Sets whether a menu contains space for mark characters.
Not recommended
OSStatus SetMenuExcludesMarkColumn ( MenuRef menu, Boolean excludesMark );
The menu whose width is to be set.
Pass true to specify that the menu be drawn without space for mark characters; false to specify that the menu be drawn in its full width, with space for mark characters.
A result code. See “Menu Manager Result Codes.”
Your application may use the SetMenuExcludesMarkColumn function to set the width of an individual menu, so that no space is provided for mark characters such as checkmarks, dashes, or notification symbols (diamonds).
The SetMenuExcludesMarkColumn function is only recommended for use with pop-up menus, and then only in special cases. Mac OS human interface guidelines require that all standard (menu bar) menus include space for mark characters, and pop-up menus that present user-selectable attributes or commands should also contain space for marks. If a pop-up menu does not present a list of user-selectable attributes or commands, as is the case with the Mac OS 8.5 Window Manager window proxy pop-up menus that display a standard file system path, then narrowing the menu to exclude space for marks may be appropriate.
See also the GetMenuExcludesMarkColumn function.
You should instead set the kMenuExcludesMarkColumn menu attribute using the ChangeMenuAttributes function.
Menus.h
Sets the font to be used in a menu.
OSStatus SetMenuFont ( MenuRef menu, SInt16 inFontID, UInt16 inFontSize );
The menu whose font is to be set.
The font family ID for the font to be used. Pass 0 to use the current system font. Note that this is the font to be used in the menu items, not the menu title. You cannot change the menu title font.
The size, in points, of the font to be used. Valid font size values range from 9 to 24 points, inclusive. Pass 0 to use the font size of the current system font.
A result code. See “Menu Manager Result Codes.”
Your application may use the SetMenuFont function to set the font for an individual menu, such as a pop-up menu. This function sets the font used by all the menu items in the menu. If you want to set the font of only a particular menu item, use the SetMenuItemFontID function instead.
Menus.h
Set the height of a menu.
void SetMenuHeight ( MenuRef menu, SInt16 height );
The menu whose height you want to set.
The height of the menu, in pixels.
Calling CalcMenuSize on the menu overwrites the menu height you set with this function.
Menus.h
Assigns a menu ID to a menu.
void SetMenuID ( MenuRef menu, MenuID menuID );
The menu you want to assign an ID to.
The menu ID to assign.
In most cases you assign an ID to a menu when you first create it, but you can use this function to change it later.
Menus.h
Sets a menu item’s command ID.
OSErr SetMenuItemCommandID ( MenuRef inMenu, MenuItemIndex inItem, MenuCommand inCommandID );
The menu that contains the menu item whose command ID you want to set.
The menu index of the item.
An integer representing the command ID that you wish to set.
A result code. See “Menu Manager Result Codes.”
You can use a menu item’s command ID as a position-independent method of signalling a specific action in an application. See Carbon Event Manager Programming Guide for more information about command IDs.
Note that Apple reserves all command IDs that contain all lowercase letters; your application is free to use any command ID containing uppercase characters.
See also the function GetMenuItemCommandID.
Menus.h
Sets the keyboard equivalent of a menu item.
OSStatus SetMenuItemCommandKey ( MenuRef inMenu, MenuItemIndex inItem, Boolean inSetVirtualKey, UInt16 inKey );
The menu containing the item.
The item whose keyboard equivalent you want to set.
Indicates whether to set the item's character code (false) or virtual keycode equivalent. (true).
The character code or virtual keycode equivalent to set.
A result code. See “Menu Manager Result Codes.”
A menu item's keyboard equivalent may be either a character code or a virtual keycode. The character code is always used to draw the item's keyboard equivalent in the menu, but either may be used for keyboard equivalent matching by MenuEvent and IsMenuKeyEvent, depending on whether the kMenuItemAttrUseVirtualKey item attribute is set. If SetMenuItemCommandKey is used to set the virtual keycode equivalent for a menu item, it also automatically sets the kMenuItemAttrUseVirtualKey item attribute. To make the menu item stop using the virtual keycode equivalent and use the character code equivalent instead, use ChangeMenuItemAttributes to clear the kMenuItemAttrUseVirtualKey item attribute.
Prior to Mac OS X v10.3, passing a character code in the range 0x1A to 0x21 (the range of command key metacharacters such as hMenuCmd) returned an error. In Mac OS X v10.3 and later, the Menu Manager interprets codes in this range as the ASCII character for that value, and displays the appropriate command key glyph. For example, passing hMenuCmd would set the keyboard equivalent to be command-Escape, because the value of hMenuCmd (0x1B) is the character code for the Escape character.
Menus.h
Sets multiple attributes of a menu item at once.
OSStatus SetMenuItemData ( MenuRef inMenu, MenuItemID inItem, Boolean inIsCommandID, const MenuItemDataRec *inData );
The menu whose attributes you want to set. Note that if you pass true for the inIsCommandID parameter, you can pass NULL here, in which case the Menu Manager searches the root menu for the first menu that matches the specified command ID.
The menu item index or the command ID of the menu item.
A Boolean value indicating whether the value passed for the inItem parameter is a command ID or a menu item index. Pass true to indicate a command ID, false to indicate that it is a menu item index. If you pass true, the Menu Manager sets the data for the first menu item that matches the specified command ID.
A pointer to a MenuItemDataRec structure. Before calling, you should set the whichData field to indicate what data you want to set and fill out those fields appropriately. For more details on the types of data you can set, see “Menu Item Data Flags.”
A result code. See “Menu Manager Result Codes.”
This function is often more efficient than calling individual accessor functions if you want to set multiple attributes simultaneously.
Menus.h
Sets the font for a menu item.
OSErr SetMenuItemFontID ( MenuRef inMenu, MenuItemIndex inItem, SInt16 inFontID );
The menu that contains the menu item for which you wish to set the font.
The menu index of the item.
An integer representing the font ID that you wish to set.
A result code. See “Menu Manager Result Codes.”
You can use this function to set up a font menu that displays item in its appropriate font. If you want to set the font for all the items in a menu, you can use the SetMenuFont function.
See also the function GetMenuItemFontID.
Menus.h
Attaches a submenu to a menu item.
OSStatus SetMenuItemHierarchicalMenu ( MenuRef inMenu, MenuItemIndex inItem, MenuRef inHierMenu );
The parent menu.
The parent item.
The submenu to attach. Pass NULL to remove an existing submenu.
A result code. See “Menu Manager Result Codes.”
Using SetMenuItemHierarchicalMenu, it is possible to directly specify the submenu for a menu item without specifying its menu ID. It is not necessary to insert the submenu into the hierarchical portion of the menubar, and it is not necessary for the submenu to have a unique menu ID. Simply use 0 as the menu ID for the submenu, and identify selections from the menu by command ID.
The Menu Manager will increment the reference count of the submenu that you specify, and the submenu’s reference count will be decremented automatically when the parent menu item is deleted or the parent menu is disposed.
Menus.h
Sets a menu item’s icon.
OSErr SetMenuItemIconHandle ( MenuRef inMenu, MenuItemIndex inItem, UInt8 inIconType, Handle inIconHandle );
The menu that contains the menu item for which you wish to set an icon.
The menu index of the item.
Pass a value representing the type of icon ('ICON', 'cicn', 'SICN', icon suite, or IconRef) you wish to attach; see “Menu Item Icon Type Constants” for descriptions of possible values.
Pass a handle to the icon you wish to attach to a menu item.
A result code. See “Menu Manager Result Codes.”
The SetMenuItemIconHandle function sets the icon of a menu item with an icon handle instead of a resource ID. SetMenuItemIconHandle allows you to set icons of type 'ICON', 'cicn', 'SICN', IconRef, CGImageRef, as well as icon suites. To set resource-based icons for a menu item, call SetItemIcon.
With the exception of types IconRef and CGImageRef,disposing of the menu will not dispose of the icon handles set by this function. The Menu Manager retains IconRef, CGImageRef icons and releases them when the menu is disposed or the menu item is removed. For all other icon types, your application should dispose of the icons when you dispose of the menu, to prevent memory leaks.
See also the function GetMenuItemIconHandle.
Menus.h
Sets the indent level of a menu item.
OSStatus SetMenuItemIndent ( MenuRef inMenu, MenuItemIndex inItem, UInt32 inIndent );
The menu containing the item.
The item whose indent level you want to set.
The new indent level of the item.
A result code. See “Menu Manager Result Codes.”
The indent level of an item is an amount of extra space added to the left of the item's icon or checkmark. The level is simply a number, starting at zero, which the Menu Manager multiplies by a constant to get the indent in pixels. The default indent level is zero.
Menus.h
Sets the command key glyph code for a menu item.
OSErr SetMenuItemKeyGlyph ( MenuRef inMenu, MenuItemIndex inItem, SInt16 inGlyph );
The menu that contains the menu item for which you wish to substitute a keyboard glyph.
The menu index of the item.
An integer representing the substitute glyph to display. Pass 0 to remove an existing glyph code. For a description of available keyboard glyphs, see “Menu Glyph Constants.”
A result code. See “Menu Manager Result Codes.”
The SetMenuItemKeyGlyph function overrides the character that would normally be displayed in a menu item’s keyboard equivalent with a substitute keyboard glyph. This is useful if the keyboard glyph in the font doesn’t match the actual character generated. For example, you might use this function to display function keys.
In addition, the glyph code you specify is used for command key matching if the menu item does not already have a command key or virtual keycode assigned to it.
See also the function GetMenuItemKeyGlyph.
In CarbonLib 1.2 and later and Mac OS X v10.0 and later, the Menu Manager automatically draws the appropriate glyph for a menu item that has a virtual keycode assigned to it; you do not have to set both virtual keycode and the glyph.
Menus.h
Sets the modifier key(s) that must be pressed with a character key to select a particular menu item.
OSErr SetMenuItemModifiers ( MenuRef inMenu, MenuItemIndex inItem, UInt8 inModifiers );
The menu that contains the menu item for which you wish to set the modifier key(s).
The menu index of the item.
A value representing the modifier key(s) to be used in selecting the menu item; see “Modifier Key Mask Constants.”
A result code. See “Menu Manager Result Codes.”
You can call the SetMenuItemModifiers function to change the modifier key(s) you can include with a character key to create your keyboard equivalent. For example, you can change Command-x to Command-Option-Shift-x. By default, the Command key is always specified; you can remove it by calling SetMenuItemModifiers with the kMenuNoCommandModifier mask constant, or (if you are using a nib file) by unchecking the appropriate command checkbox in the Interface Builder menu item inspector.
See also the function GetMenuItemModifiers.
Menus.h
Associates data with a menu item.
OSStatus SetMenuItemProperty ( MenuRef menu, MenuItemIndex item, OSType propertyCreator, OSType propertyTag, ByteCount propertySize, const void *propertyData );
The menu containing the item with which you wish to associate data.
The index number of the menu item or 0 if the data is to be associated with the menu as a whole.
A four-character code. Pass your program’s signature, as registered through Apple Developer Technical Support. If your program is of a type that would not normally have a signature (for example, a plug-in), you should still register and use a signature in this case, even though your program’s file may not have the same creator code as the signature that you register. The 'macs' property signature is reserved for the system and may not be used.
A four-character code that identifies the property to set. You define the tag your application uses to identify the data; this code is not to be confused with the file type for the data, but may coincide if you wish.
The size of the data.
A pointer to the data.
A result code. See “Menu Manager Result Codes.”
You may use the SetMenuItemProperty function to associate arbitrary data, tagged with an identifying code, with a menu item.
See also the GetMenuItemProperty and RemoveMenuItemProperty functions.
Menus.h
Sets application-specific information for a menu item.
OSErr SetMenuItemRefCon ( MenuRef inMenu, MenuItemIndex inItem, URefCon inRefCon );
The menu that contains the menu item with which you wish to associate information.
The menu index of the item. In CarbonLib 1.6 and later and Mac OS X v10.2 and later, you may pass zero to set a reference constant for the menu itself.
An unsigned 32-bit integer value. Pass a reference constant to associate with the menu item.
A result code. See “Menu Manager Result Codes.”
If you have any data you want to associate with a menu item, you can do so using the SetMenuItemRefCon function. Note that you can also use SetMenuItemProperty, which allows more flexibility in specifying application-specific data.
See also the function GetMenuItemRefCon.
Menus.h
Sets the text of a menu item to the text contained in a CFString.
OSStatus SetMenuItemTextWithCFString ( MenuRef inMenu, MenuItemIndex inItem, CFStringRef inString );
The menu containing the item.
The item whose text you want to set.
The CFString containing the new menu item text.
A result code. See “Menu Manager Result Codes.”
If the CFString is mutable, the Menu Manager will make its own copy of the CFString before returning from SetMenuItemTextWithCFString. Modifying the string after calling SetMenuItemTextWithCFString will have no effect on the item's actual text.
If the CFString is immutable, the Menu Manager increments the reference count of the string before returning.
The caller may release the string after calling SetMenuItemTextWithCFString.
Menus.h
Sets the title of a menu to be an icon.
OSStatus SetMenuTitleIcon ( MenuRef inMenu, UInt32 inType, void *inIcon );
The menu whose title to set.
The type of icon being used to specify the icon title; use kMenuNoIcon to remove the icon from the menu title. The supported types are kMenuIconSuiteType, kMenuIconRefType, and (in Mac OS X v10.3 and later) kMenuIconCGImageRefType.
The icon; this parameter must be NULL if inType is kMenuNoIcon. The supported icon formats are IconSuiteRef, IconRef, and (in Mac OS X v10.3 and later) CGImageRef.
A result code. See “Menu Manager Result Codes.”
The Menu Manager takes ownership of the supplied icon after this call. When a menu with an title icon is disposed, the Menu Manager will dispose the icon as well. The Menu Manager will also dispose of the current title icon when a new text or icon title is supplied for a menu. If you specify an IconRef or CGImageRef, the Menu Manager will increment its reference count, so you can release your reference to the IconRef without invalidating the Menu Manager's copy. The menu bar is invalidated by this call and will be redrawn at the first opportunity.
Menus.h
Sets the title of a menu to the text contained in a CFString.
OSStatus SetMenuTitleWithCFString ( MenuRef inMenu, CFStringRef inString );
The menu whose title you want to set.
The string containing the new menu title text.
A result code. See “Menu Manager Result Codes.”
If the string is mutable, the Menu Manager will make its own copy of the CFString before returning from SetMenuTitleWithCFString. Modifying the string after calling SetMenuTitleWithCFString will then have no effect on the menu's actual title.
If the string is immutable, the Menu Manager simply increments the string’s reference count.
The caller may release the string after calling SetMenuTitleWithCFString.
Menus.h
Sets the width of a menu.
void SetMenuWidth ( MenuRef menu, SInt16 width );
The menu whose width you want to set.
The width of the menu, in pixels.
Calling CalcMenuSize on the menu overwrites the menu width you set with this function.
Menus.h
Sets the menu whose contents are displayed in the menubar.
OSStatus SetRootMenu ( MenuRef inMenu );
The new root menu.
A result code. See “Menu Manager Result Codes.”
The root menu should contain one menu item for each top-level menu to be displayed in the menu bar. Each menu item in turn should have a submenu that was specified using SetMenuItemHierarchicalMenu.
You can use the SetRootMenu function along with the AcquireRootMenu function to save and restore the contents of the menu bar. Note that calling SetRootMenu sets the contents of the hierarchical portion of the menu list as well as the top-level menus displayed in the menu bar. Before returning the root menu, AcquireRootMenu calls InsertMenu with the kInsertHierarchialMenu option to attach to the root menu a list of the menus that are currently inserted into the hierarchical portion of the menu. SetRootMenu reinserts any attached hierarchical menus into the hierarchical portion of the menu list. If you pass a newly-created menu to SetRootMenu, the hierarchical menu list is cleared and is empty.
Calling SetRootMenu also implicitly retains the new root menu, and you should release it at the appropriate time by calling ReleaseMenu.
Menus.h
Displays the menu bar.
void ShowMenuBar ( void );
The ShowMenuBar function makes the menu bar visible and selectable by the user.
Note that calling this function also causes a kEventMenuBarShown event to be sent to the application target (if your application has registered for the event).
See also the HideMenuBar and IsMenuBarVisible functions.
Menus.h
Redraws the invalid items of an open menu.
OSStatus UpdateInvalidMenuItems ( MenuRef inMenu );
The menu whose menu items you want to update.
A result code. See “Menu Manager Result Codes.”
This function redraws menu items in an open menu that has either had some visible aspect of its menu items change (such as their enable state) or has been invalidated by a call to InvalidateMenuItems.
It is not necessary to use UpdateInvalidMenuItems if you are using Carbon's built-in support for dynamic items based on modifier key state. However, if you are modifying items dynamically using your own implementation, you should call UpdateInvalidMenuItems after completing your modifications for a single menu. It will redraw any items that have been marked as invalid, and clear the invalid flag for those items.
Menus.h
Updates a standard Font menu.
OSStatus UpdateStandardFontMenu ( MenuRef menu, ItemCount *outHierMenuCount );
The menu you want to update.
The number of hierarchical menus attached to the standard Font menu. This value may be NULL if the hierarchical menus count is not useful. For example, if the only submenus in your application are those created by CreateStandardFontMenu, then you don’t need to worry about the hierarchical menu count, as any existing submenu must be a font menu.
A result code. See “Menu Manager Result Codes.”
UpdateStandardFontMenu calls the Font Manager function FMGetFontGeneration to determine if the fonts have changed and returns immediately without modifying the font menu if no changes occurred. As there is little overhead if no fonts have changed, you can call this function whenever you think it may be useful; for example, when your application is activated, or whenever you receive a kEventMenuPopulate event for the font menu.
Menus.hDefines a pointer to a custom menu definition callback function. Your menu definition callback function draws the menu items in the menu, determines which item the user chose from the menu, and calculates the menu’s dimensions.
Not recommended
typedef void (*MenuDefProcPtr) ( SInt16 message, MenuRef theMenu, Rect *menuRect, Point hitPt, SInt16 *whichItem );
If you name your function MyMenuDefProc, you would declare it like this:
void *MyMenuDefProc ( SInt16 message, MenuRef theMenu, Rect *menuRect, Point hitPt, SInt16 *whichItem );
A constant that identifies the operation the menu definition function should perform; see “Custom Menu Definition Message Constants” and “Obsolete Menu Definition Messages” for a description of the messages that your menu definition function can receive. Your menu definition function should not respond to any value other than these defined messages. Other messages are reserved for internal use by Apple Computer, Inc.
The menu that the operation should affect. This menu reference may refer to a regular menu or a popup menu.
A pointer to the rectangle (in global coordinates) in which the menu is located.
A mouse location (in global coordinates). The Menu Manager provides information in this parameter to the menu definition function when the kMenuFindItemsMsg or kMenuPopUpMsg messages are sent.
A pointer to a value that specifies the item number of the menu item to act upon, or a pointer to a data structure related to one or more menu items. The data pointed to depends on the message sent; see the discussion for specifics.
Carbon does not let you store menu definitions as resources. If you need to upgrade legacy code, see the Carbon Porting Guide for information about converting your resource-based definitions. See the Carbon Porting Notes for this callback for additional information about changes to older messages and access to low-memory global data.
On Mac OS X v10.3 and later, all standard menus are implemented as HIViews, and custom menus can be implemnented as custom HIViews. If you want to create custom menu definitions, you should subclass the HIMenuView class. See Introducing HIView in Carbon User Experience documentation for more information.
When you define your menus, you specify the menu definition function the Menu Manager should use when managing them. You’ll usually want to use the standard menu definition function for your application. However, if you need a feature not provided by the standard menu definition function (for example, if you want to include more graphics in your menus), you can choose to write your own menu definition function.
The menu definition function is responsible for drawing the contents of the menu and its menu items, determining whether the cursor is in a displayed menu, highlighting and unhighlighting menu items, and calculating a menu’s dimensions. To create an instance of your custom menu, call the CreateCustomMenu function.
The Menu Manager calls your menu definition function whenever it needs your definition function to perform a certain action on a specific menu. The action your menu definition function should perform depends on the value of the message parameter. When the Menu Manager requests your menu definition function to perform an action on a menu, it provides your function with the appropriate menu reference. This allows your function to access the data in the menu structure and to use any data in the variable data portion of the menu structure to appropriately handle the menu items.
Your menu definition function should support the following messages:
kMenuInitMsg
The Menu Manager sends this message when creating a menu to give your menu definition a chance to perform any required initialization. If an error occurs during initialization, your menu definition should return a nonzero error code in the *whichItem parameter. This error is then returned by the function used to create the menu.
kMenuDisposeMsg
Sent when a menu is destroyed. The Menu Manager sends this message to give your menu definition a chance to release or dispose of any related data.
kMenuFindItemMsg
Sent when the Menu Manager is displaying a menu and needs to know what item is under the mouse.
The whichItem parameter points to a MenuTrackingData structure. On entry, the menu, virtualMenuTop, and virtualMenuBottom fields of this structure are valid. Your menu definition should determine which item, if any, contains the point passed to you in the hitPt parameter and fill in the itemUnderMouse, itemSelected, and itemRect fields. If an item is found, the menu definition should always fill in the itemUnderMouse and itemRect fields. The menu definition should only fill in the itemSelected field if the item is available for selection; if it is unavailable (because it is disabled, or for some other reason), the menu definition should set the itemSelected field to zero.
The index values placed in the itemUnderMouse and itemSelected fields should be less than or equal to the number of items returned by CountMenuItems on this menu. These values should also be identical if both are nonzero. The itemUnderMouse field should always be nonzero if the mouse is actually over an item.
The menu definition should not highlight the found item in response to this message, as the Menu Manager will send a separate kMenuHiliteItemMsg to request highlighting of the item.
If the menu definition supports scrolling, it should scroll the menu during this message, and update the virtualMenuTop and virtualMenuBottom fields of the MenuTrackingData to indicate the menu's new scrolled position.
If the menu definition uses QuickDraw to draw while scrolling, it should draw into the current port.
If the menu definition uses CoreGraphics to draw while scrolling, it should use the CGContextRef passed in the context field of the MDEFHiliteItemData structure. Menu definitions must use the ScrollMenuImage function, if available, to scroll the menu contents. (This function is available in CarbonLib 1.5 and later, and in Mac OS X 10.1 and later.) ScrollMenuImage properly supports scrolling the alpha channel in the menu's image data. Use of the QuickDraw function ScrollRect to scroll the menu contents will result in the alpha channel being set to 0xFF (opaque) and the menu will no longer be translucent.
The menu definition should not modify the menu field of the MenuTrackingData structure.
kMenuHiliteItemMsg
Sent when the Menu Manager is displaying a menu and needs to highlight a newly selected item.
The whichItem parameter points to a MDEFHiliteItemData structure. The menu definition should unhighlight the item in the previousItem field, if non-zero, and highlight the item in the newItem field.
If the menu definition is using the Appearance Manager's menu drawing APIs, you should use the EraseMenuBackground function to erase the old menu contents before unhighlighting a menu item. This is necessary because the background of a menu is translucent in Aqua, and if the old highlight is not erased first, it will show through the new unhighlighted menu background.
If the menu definition uses QuickDraw to draw, it should draw into the current port. If it uses CoreGraphics to draw, it should use the CGContextRef passed in the context field of the MDEFHiliteItemData structure.
kMenuDrawItemsMsg
Sent when the Menu Manager is displaying a menu and needs to redraw a portion of the menu. This message is used by the dynamic menu item support code in the Menu Manager; for example, if items five and six in a menu are a dynamic group, the Menu Manager will send a kMenuDrawItemsMsg message when the group's modifier key is pressed or released to redraw the appropriate item, but no other items in the menu.
The whichItem parameter for this message points to an MDEFDrawItemsData structure. The menu definition should redraw the items starting with firstItem and ending with lastItem, inclusive.
If the menu definition uses QuickDraw to draw, it should draw into the current port. If it uses CoreGraphics to draw, it should use the CGContextRef passed in the context field of the MDEFHiliteItemData structure.
kMenuDrawMsg
Sent when the Menu Manager is displaying a menu and needs to redraw the entire menu.
The whichItem parameter is actually a pointer to a MenuTrackingData structure. On entry, the menu field of this structure is valid. The menu definition should draw the menu and, if it supports scrolling, should also fill in the virtualMenuTop and virtualMenuBottom fields of the structure to indicate the menu's initial unscrolled position; typically, virtualMenuTop would be set to the same value as the top coordinate of the menu bounds, and virtualMenuBottom would be set to virtualMenuTop plus the virtual height of the menu.
If the menu definition uses QuickDraw to draw, it should draw into the current port. If it uses CoreGraphics to draw, it should use the CGContextRef passed in the context field of the MDEFHiliteItemData structure.
kMenuSizeMsg
Sent when the Menu Manager needs to determine the size of a menu.
The menu definition should calculate the width and height of the menu and store the sizes into the menu with SetMenuWidth and SetMenuHeight. If the gestaltMenuMgrSendsMenuBoundsToDefProc bit is set in the Menu Manager's Gestalt value, then the hitPt parameter sent with this message is the maximum width (hitPt.h) and height (hitPt.v) of the menu. The menu definition should ensure that the width and height that it places in the menu do not exceed these values. If the gestalt bit is not set, the menu definition should just use the main display device’s (GDevice) width and height as constraints on the menu's width and height.
kMenuPopUpMsg
Sent when the Menu Manager is about to display a popup menu. The Menu Manager uses the menu definition function to support pop-up menus that are not implemented as controls. If your menu definition function supports pop-up menus, it should respond appropriately to the kMenuPopUpMsg message.
The menu definition should calculate the appropriate menu bounds to contain the menu based on the requested menu location and selected item. It should write the menu’s bounds into the Rect structure passed by the menuRect parameter. If the gestaltMenuMgrSendsMenuBoundsToDefProc bit is set in the Menu Manager's Gestalt value, then the menuRect parameter on entry to this message contains a constraint rectangle, in global coordinates, outside of which the popup menu should not be positioned. The menu definition should take these constraint bounds into account as it calculates the menu bounds. If the gestalt bit is not set, the menu definition should use the bounds of the display device (GDevice) containing the menu's top left corner as a constraint on the menu's position.
The hitPt parameter is the requested location for the top left corner of the menu. The coordinates of this parameter are swapped from their normal order; hitPt.h contains the vertical coordinate and hitPt.v contains the horizontal coordinate.
On entry, the whichItem parameter points at a menu item index which is requested to be the initial selection when the menu is displayed. After calculating the menu's bounds, the menu definition should write the menu's virtual top coordinate into the location pointed at by the whichItem parameter. If displaying the menu at the requested location does not require scrolling, the virtual top will be the same as the menu bounds top; if the menu must scroll to fit in the requested location, the virtual top may be different.
kMenuCalcItemMsg
Sent when the Menu Manager needs to know the bounds of a menu item.
The menu definition should calculate the size of the menu item specified by the whichItem parameter and store the bounds in the Rect structure specified by the menuRect parameter. Some sample menu definition code provided by Apple has previously shown an implementation of this message that always sets the top left corner of the item bounds to (0,0), regardless of the item's actual position in the menu. For best future compatibility, menu definitions should begin storing an item bounds that gives the item's actual position in the menu based on the menu's current virtual top. For example, if the virtual menu top starts at 20, then the menu definition would calculate an item bounds for the first item that starts at (0,20), an item bounds for the second item that starts at (0,40), and so on. The menu definition should call GetMenuTrackingDatato get the menu's current virtual position, and use zero for the menu top if GetMenuTrackingData returns an error.
kMenuThemeSavvyMsg
Sent by the Menu Manager to determine whether the menu definition uses the Appearance Manager menu-drawing functions to draw its menu. If it does, the menu definition should return kThemeSavvyMenuResponse in the location pointed to by whichItem. If the menu definition draws its own custom content without using the Appearance Manager menu-drawing functions, it should ignore this message.
The Menu Manager defines the data type MenuDefUPP to identify the universal procedure pointer for an application-defined menu definition function:
typedef UniversalProcPtr MenuDefUPP;
You typically use the NewMenuDefProc function like this:
MenuDefUPP myMenuDefProc;
myMenuDefProc = NewMenuDefProc(MyMenu);
Prior to Carbon, menu definitions needed to use several low-memory globals to communicate with the Menu Manager. These globals have all been replaced or made obsolete in Carbon, as follows:
MenuDisable
MenuDisable is now set automatically by the Menu Manager using the value returned in the itemUnderMouse field of the MenuTrackingData structure passed to kMenuFindItemMsg.
TopMenuItem, AtMenuBottom
TopMenuItem and AtMenuBottom are now set automatically by the Menu Manager using the values returned in the virtualMenuTop and virtualMenuBottom fields of the MenuTrackingData structure passed to kMenuDrawMsg and kMenuFindItemMsg.
mbSaveLoc
This undocumented low-memory global was used by older menu definitions to store the bounding rect of the currently selected item and to avoid drawing glitches while the menu definition was scrolling the contents of a menu that had submenus. The Menu Manager now automatically sets the selected item bounds using the value returned in the itemRect field of the MenuTrackingData structure passed to kMenuFindItemMsg. In order to correctly support scrolling of menus with submenus, a menu definition should verify, before scrolling the menu contents, that no submenus of the scrolling menu are currently visible. A menu definition can use GetMenuTrackingData to verify this condition, as follows:
Boolean SafeToScroll( MenuRef menuBeingScrolled ) |
{ |
MenuTrackingData lastMenuData; |
return GetMenuTrackingData( NULL, &lastMenuData ) == noErr |
&& lastMenuData.menu == menuBeingScrolled; |
} |
If SafeToScroll returns false, the menu definition should not scroll the menu.
Menus.hDefines a list of hierarchical menus that have been inserted into a menu bar.
struct HMenuBarHeader {
UInt16 lastHMenu;
PixMapHandle menuTitleBits;
};
typedef struct HMenuBarHeader HMenuBarHeader;
lastHMenuOffset from the start of the header to the last menu in the array of HMenuBar structures.
menuTitleBitsThe saved bits behind the highlighted menu title. This value is undefined in menu bar handles returned by GetNewMBar or GetMenuBar.
The hierarchical portion of the menu bar follow the nonhierarchical portion in a menu bar handle. The hierarchical section consists of the HMenuBarHeader structure followed by an array of HMenuBarMenu structures.
You insert a hierarchical menu by specifying -1 for the beforeID parameter in InsertMenu.
Menus.h
Defines a hierarchical menu.
struct HMenuBarMenu {
MenuRef menu;
SInt16 reserved;
};
typedef struct HMenuBarMenu HMenuBarMenu;
menuThe menu.
reservedCurrently unused.
Menus.h
Specifies a menu color information table
Not recommended
struct MCEntry {
MenuID mctID;
short mctItem;
RGBColor mctRGB1;
RGBColor mctRGB2;
RGBColor mctRGB3;
RGBColor mctRGB4;
short mctReserved;
};
typedef struct MCEntry MCEntry;
typedef MCEntry * MCEntryPtr;
typedef MCEntry MCTable[1];
mctIDDefines, along with the mctItem field, whether the entry is a menu bar entry, a menu title entry, or a menu item entry. The mctID field contains either a menu ID or 0 (for a menu bar).
mctItemDefines, along with the mctID field, whether the entry is a menu bar entry, a menu title entry, or a menu item entry. The mctItem field contains either a menu item number or 0 (for a menu bar or menu title).
mctRGB1Specifies color information for the entry, as follows. For a menu bar entry, this value is the default color for menu titles. For a menu title entry, this value is the title color of a specific menu. For a menu item entry, this value is the mark color for a specific item.
mctRGB2Specifies color information for the entry, as follows. For a menu bar entry, this value is the default background color of a displayed menu. For a menu title entry, this value is the default color for the menu bar. For a menu item entry, this value is the color for the text of a specific item.
mctRGB3Specifies color information for the entry, as follows. For a menu bar entry, this value is the default color of items in a displayed menu. For a menu title entry, this value is the default color for items in a specific menu. For a menu item entry, this value is the color for the modifier of a specific item.
mctRGB4Specifies color information for the entry, as follows. For a menu bar entry, this value is the default color of the menu bar. For a menu title entry, this value is the background color of a specific menu. For a menu item entry, this value is the background color of a specific menu.
mctReservedReserved.
The menu color information table defines the standard color for the menu bar, menu titles, menu items, and the background color of a displayed menu. If you do not add any menu color entries to this table, the Menu Manager draws your menus using the current default colors. Using the menu color information table to define custom colors for your menus is not recommended with Appearance Manager 1.0 and later.
When the Appearance Manager is available and you are using standard menus, if you do not include a menu bar entry in your menu color information table, only the menu title color and menu item text color values from menu color entries are used. If you do include a menu bar entry in your menu color information table, all menu colors are used, and the menus revert to a standard System 7 appearance.
If you are creating your own custom menu definition function, all entries in the table are used.
You can add custom colors to your menus by adding entries to your application’s menu color information table, using Menu Manager functions or by defining these entries in an 'mctb' resource. Note that the menu color information table uses a format different from the standard color table format.
The value of the mctID field in the last entry in a menu color information table is mctLastIDIndic, and the rest of the fields of the last entry are reserved. The Menu Manager automatically creates the last entry in a menu color information table; your application should not use the value mctLastIDIndic as the menu ID of a menu if you wish to add a menu color entry for it.
The contents of a menu color table entry structure are interpreted differently, depending upon the values of the mctID and mctItem fields. Depending upon the value of these fields, the MCEntry structure represents a menu bar entry, a menu title entry, a menu item entry, or the last entry.
A menu bar entry is defined by a menu color entry structure that contains 0 in both the mctID and mctItem fields. You can define only one menu bar entry in a menu color information table. If you don’t provide a menu bar entry for your application’s menu color information table, the Menu Manager uses the standard menu bar colors (black text on a white background), and it uses the standard colors for the other menu elements. You can provide a menu bar entry to specify default colors for the menu title, the background of a displayed menu, the items in a menu, and the menu bar. The color information fields for a menu bar entry are interpreted as follows:
mctRGB1 specifies the default color for menu titles. If a menu doesn’t have a menu title entry, the Menu Manager uses the value in this field as the color of the menu title.
mctRGB2 specifies the default color for the background of a displayed menu. If a menu doesn’t have a menu title entry, the Menu Manager uses the value in this field as the color of the menu’s background when it is displayed.
mctRGB3 specifies the default color for the items in a displayed menu. If a menu item doesn’t have a menu item entry or a default color defined in a menu title entry, the Menu Manager uses the value in this field as the color of the menu item.
mctRGB4 specifies the default color for the menu bar. If a menu doesn’t have a menu bar entry (and doesn’t have any menu title entries), the Menu Manager uses the standard colors for the menu bar.
A menu title entry is defined by a menu color entry structure that contains a menu ID in the mctID field and 0 in the mctItem field. You can define only one menu title entry for each menu. If you don’t provide a menu title entry for a menu in your application’s menu color information table, the Menu Manager uses the colors defined by the menu bar entry. If a menu bar entry doesn’t exist, the Menu Manager uses the standard colors (black on white). You can provide a menu title entry to specify a color for the title and background of a specific menu and a default color for its items. The color information fields for a menu title entry are interpreted as follows:
mctRGB1 specifies the color for the menu title of the specified menu. If a menu doesn’t have a menu title entry, the Menu Manager uses the default value defined in the menu bar entry.
mctRGB2 specifies the default color for the menu bar. If a menu color information table doesn’t have a menu bar entry, the Menu Manager uses the value in this field as the color of the menu bar. If a menu bar entry already exists, the Menu Manager replaces the value in the mctRGB2 field of the menu title entry with the value defined in the mctRGB4 field of the menu bar entry.
mctRGB3 specifies the default color for the items in the menu. If a menu item doesn’t have a menu item entry or a default color defined in a menu bar entry, the Menu Manager uses the value in this field as the color of the menu item.
mctRGB4 specifies the color for the background of the menu.
A menu item entry is defined by a menu color entry structure that contains a menu ID in the mctID field and an item number in the mctItem field. You can define only one menu item entry for each menu item. If you don’t provide a menu item entry for an item in your application’s menu color information table, the Menu Manager uses the colors defined by the menu title entry (or by the menu bar entry if the menu containing the item doesn’t have a menu title entry). If neither a menu title entry nor a menu bar entry exists, the Menu Manager draws the mark, text, and modifier in black. You can provide a menu item entry to specify a color for the mark, text, and keyboard equivalent of a specific menu item. The color information fields for a menu item entry are interpreted as follows:
mctRGB1 specifies the color for the mark of the menu item. If a menu item doesn’t have a menu item entry, the Menu Manager uses the default value defined in the menu title entry or the menu bar entry.
mctRGB2 specifies the color for the text of the menu item. If a menu item doesn’t have a menu item entry, the Menu Manager uses the default value defined in the menu title entry or the menu bar entry. The Menu Manager also draws a black-and-white icon of a menu item using the same color as defined by the mctRGB2 field. (Use a ' cicn ' resource to provide a menu item with a color icon.)
mctRGB3 specifies the color for the modifier of the menu item. If a menu item doesn’t have a menu item entry, the Menu Manager uses the default value defined in the menu title entry or the menu bar entry.
mctRGB4 specifies the color for the background of the menu. If the menu color information table doesn’t have a menu title entry for the menu this item is in, or doesn’t have a menu bar entry, the Menu Manager uses the value in this field as the background color of the menu. If a menu title entry already exists, the Menu Manager replaces the value in the mctRGB4 field of the menu item entry with the value defined in the mctRGB4 field of the menu title entry (or with the mctRGB2 field of the menu bar entry).
You can use the GetMCInfo function to get a copy of your application’s menu color information table and the SetMCEntries function to set entries of your application’s menu color information table, or you can provide ' mctb ' resources that define the color entries for your menus.
The GetMenu , GetNewMBar , and ClearMenuBar functions can also modify the entries in the menu color information table. The GetMenu function looks for an ' mctb ' resource with a resource ID equal to the value in the menuID parameter. If it finds one, it adds the entries to the application’s menu color information table.
The GetNewMBar function builds a new menu color information table when it creates the new menu list. If you want to save the current menu color information table, call GetMCInfo before calling GetNewMBar.
The ClearMenuBar function reinitializes both the current menu list and the menu color information table.
Menus.h
Contains information needed to draw a menu.
struct MDEFDrawData {
MenuTrackingData trackingData;
void * context;
};
typedef struct MDEFDrawData MDEFDrawData;
typedef MDEFDrawData * MDEFDrawDataPtr;
trackingDataA data structure containing information about the menu to be drawn. Your menu definition should fill in the virtualMenuTop and virtualMenuBottom fields of this structure while drawing the menu.
contextThe Core Graphics context that your menu definition should draw into. The Menu Manager flushes the context after returning from the menu definition.
The Menu Manager passes this structure to your custom menu definition in the whichItem parameter of the kMenuDrawMsg message.
Menus.h
Contains information about which menu items to redraw.
struct MDEFDrawItemsData {
MenuItemIndex firstItem;
MenuItemIndex lastItem;
MenuTrackingData * trackingData;
void * context;
};
typedef struct MDEFDrawItemsData MDEFDrawItemsData;
typedef MDEFDrawItemsData * MDEFDrawItemsDataPtr;
firstItemThe first item to draw.
lastItemThe last item to draw.
trackingDataInformation about the menu's tracking state. The virtualMenuTop and virtualMenuBottom fields in this structure will be the most useful in handling the DrawItems message.
contextThe Core Graphics drawing context that your menu definition should draw into. The Menu Manager flushes the context after returning from the menu definition.
The Menu Manager passes this structure to your custom menu definition in the whichItem parameter of the kMenuDrawItemsMsg message.
Menus.h
Contains information used to determine which item the user has currently selected.
struct MDEFFindItemData {
MenuTrackingData trackingData;
void * context;
};
typedef struct MDEFFindItemData MDEFFindItemData;
typedef MDEFFindItemData * MDEFFindItemDataPtr;
trackingDataA data structure containing information about the menu to be drawn. Your menu definition should fill in the itemSelected , ItemUnderMouseand itemRect fields of this structure after determining which item is under the specified point.
contextThe Core Graphics context the menu definition should draw into if it needs to scroll the menu during the kMenuFindItemMsg message. The Menu Manager flushes the context after the menu definition returns.
The Menu Manager passes this structure to your custom menu definition in the whichItem parameter of the kMenuFindItemsMsg message.
Menus.h
Contains information about which menu items should be highlighted and unhighlighted as the user moves through the menus. .
struct MDEFHiliteItemData {
MenuItemIndex previousItem;
MenuItemIndex newItem;
void * context;
};
typedef struct MDEFHiliteItemData MDEFHiliteItemData;
typedef MDEFHiliteItemData * MDEFHiliteItemDataPtr;
typedef MDEFHiliteItemData HiliteMenuItemData;
typedef MDEFHiliteItemDataPtr HiliteMenuItemDataPtr;
previousItemThe menu item that was previously selected. This item needs to be redrawn in an unhighlighted state. This parameter can be zero if no item was previously selected.
newItemThe menu item that is now selected. This item needs to be redrawn in a highlighted state. This parameter can be zero if no item is currently highlighted.
contextThe Core Graphics context the menu definition should draw into. The Menu Manager flushes the context after the menu definition returns.
This structure is used by menu definition functions, which receive a pointer to an MDEFHiliteItemData structure as the whichItem parameter during the kMenuHiliteItemMsg message.
Menus.h
A handle to a menu bar header.
typedef Handle MenuBarHandle;
Menus.h
Defines a list of nonhierarchical menus that that have been placed in the menu bar.
struct MenuBarHeader {
UInt16 lastMenu;
SInt16 lastRight;
SInt16 mbResID;
};
typedef struct MenuBarHeader MenuBarHeader;
lastMenuOffset from the start of the header to the last menu in the array of MenuBarMenu structures, in bytes.
lastRightThe x-coordinate of the right edge of the rightmost menu, in global coordinates. This value is undefined in menu bar handles returned by GetNewMBar or GetMenuBar.
mbResIDThe MBDF resource ID. This value is undefined in menu bar handles returned by GetNewMBar or GetMenuBar.
This structure is contained within a menu bar handle (MenuBarHandle).
Menus.h
Defines a nonhierarchical menu.
struct MenuBarMenu {
MenuRef menu;
SInt16 menuLeft;
};
typedef struct MenuBarMenu MenuBarMenu;
menumenuLeftThe x-coordinate of the left edge of the menu title, in global coordinates. This value is undefined in menu bar handles returned by GetNewMBar or GetMenuBar.
Menus.h
Specifies a menu item’s command ID.
typedef UInt32 MenuCommand;
Menus.h
Specifies a set of menu color table entries
Not recommended
struct MenuCRsrc {
short numEntries;
MCTable mcEntryRecs;
};
typedef struct MenuCRsrc MenuCRsrc;
typedef MenuCRsrc * MenuCRsrcPtr;
numEntriesmcEntryRecsMenus.h
Defines the type of menu definition.
struct MenuDefSpec {
MenuDefType defType
union {
MenuDefUPP defProc;
struct {
CFStringRef classID;
EventRef initEvent;
} view;
} u;
};
typedef struct MenuDefSpec MenuDefSpec;
typedef MenuDefSpec * MenuDefSpecPtr;
defTypeThe type of menu definition. See “Menu Definition Type Constants” for a list of possible values.
u.defprocIf the defType field is kMenuDefProcPtr, the menu definition is a older procedure pointer–based definition. This field then contains a UPP to the menu definition function.
u.view.classIDIf the defType field is kMenuDefClassID, the menu definition is HIView–based. This field then contains the ID of the HIView subclass that defines this menu.
u.view.initEventIf the defType field is kMenuDefClassID, the menu definition is HIView–based. This field then contains the initialization event for the HIView subclass if one exists. Otherwise, it is NULL.
HIView-based menu definitions are available in Mac OS X 10.3 and later.
Menus.h
Defines a universal procedure pointer to a menu definition function.
Not recommended
typedef MenuDefProcPtr MenuDefUPP;
For more information, see the description of the MenuDefProcPtr callback.
In Mac OS X 10.3 and later, you should use HIView-based menu definitions instead.
Menus.h
Defines a menu reference.
typedef MenuRef MenuHandle;
You should refer to menus using the MenuRef type instead.
Menus.h
Defines a menu ID.
typedef SInt16 MenuID;
Menus.h
Used with the SetMenuItemData and CopyMenuItemData functions to get or change aspects of a menu item.
struct MenuItemDataRec {
MenuItemDataFlags whichData;
StringPtr text;
UniChar mark;
UniChar cmdKey;
UInt32 cmdKeyGlyph;
UInt32 cmdKeyModifiers;
Style style;
Boolean enabled;
Boolean iconEnabled;
UInt8 filler1;
SInt32 iconID;
UInt32 iconType;
Handle iconHandle;
MenuCommand cmdID;
TextEncoding encoding;
MenuID submenuID;
MenuRef submenuHandle;
SInt32 fontID;
UInt32 refcon;
OptionBits attr;
CFStringRef cfText;
Collection properties;
UInt32 indent;
UInt16 cmdVirtualKey;
};
typedef struct MenuItemDataRec MenuItemDataRec;
typedef MenuItemDataRec * MenuItemDataPtr;
whichDataThe fields to be set or obtained. You pass a bit mask as specified by “Menu Item Data Flags” to indicate which values you want to get or set. The values themselves are set or populated in the fields that follow.
textThe menu item title, as an Str255 string.
mark The menu item’s mark.
cmdKeyThe menu item’s command key. This can be either a character code or a virtual key code.
cmdKeyGlyphThe menu item’s command key glyph.
cmdKeyModifiersThe menu item’s command key modifiers.
styleThe menu item’s QuickDraw text style.
enabledThe menu item’s enable state.
iconEnabledThe enable state of the menu item icon.
filler1 Reserved.
iconIDThe icon resource ID of the menu item.
iconHandleThe icon handle of the menu item.
cmdIDThe command ID for the menu item.
encodingThe text encoding of the menu item.
submenuIDThe menu ID of the submenu associated with this menu item.
submenuHandleThe MenuRef of the submenu associated with this menu item.
fontIDThe font ID for the menu item.
refconThe reference constant associated with this menu item.
attrThe menu item’s attributes.
cfTextThe menu item’s title, as a Core Foundation string.
propertiesA collection holding the menu item’s properties.
indentThe menu item’s indent level.
cmdVirtualKeyThe menu item’s virtual key.
When using this structure withCopyMenuItemData or SetMenuItemData, the caller must first set the whichData field to a combination of MenuItemDataFlags indicating which specific data should be retrieved or set. Some fields also require initialization before calling CopyMenuItemData; see “Menu Item Data Flags” for details.
Menus.h
Defines a menu item.
typedef UInt32 MenuItemID;
Menus.h
Specifies a particular menu item in a menu.
typedef UInt16 MenuItemIndex;
The menu item index is one-based, so item 1 is the first menu item, item 2 is the second, and so on. Some functions allow you to pass an index of zero, which specifies the menu itself.
Menus.h
Defines a menu.
typedef struct OpaqueMenuRef * MenuRef;
Menus.h
Contains information about the menu currently being displayed during menu tracking.
struct MenuTrackingData {
MenuRef menu;
MenuItemIndex itemSelected;
MenuItemIndex itemUnderMouse;
Rect itemRect;
SInt32 virtualMenuTop;
SInt32 virtualMenuBottom;
};
typedef struct MenuTrackingData MenuTrackingData;
typedef MenuTrackingData * MenuTrackingDataPtr;
menuThe menu.
itemSelectedThe index of the menu item that is currently selected. This field should either match the itemUnderMouse field, or should be zero if the item under the mouse cannot be selected (for example, if the item is disabled).
itemUnderMouseThe index of the menu item that is currently under the mouse.
itemRectThe Rect that defines the area of the menu item currently under the mouse. Note that the itemRect field is not supported in CarbonLib and is always set to be empty. It is, however, supported in Mac OS X.
virtualMenuTopThe y-coordinate of the actual top of the menu. Because the user can scroll the menu, the menu top coordinate may be above the top of the visible screen (in which case it has a negative value).
virtualMenuBottomThe y-coordinate of the actual bottom of the menu. Because the user can scroll the menu, the menu bottom coordinate may be below the bottom of the visible screen
You can call GetMenuTrackingData to obtain this structure during menu tracking.
Menus.hDetermine which contextual menu features are available.
enum {
gestaltContextualMenuAttr = 'cmnu',
gestaltContextualMenuUnusedBit = 0,
gestaltContextualMenuTrapAvailable = 1,
gestaltContextualMenuHasAttributeAndModifierKeys = 2,
gestaltContextualMenuHasUnicodeSupport = 3
};
gestaltContextualMenuAttrThe Gestalt selector passed to the Gestalt function to determine whether contextual menu functions are available. Produces a value whose bits you should test to determine whether the contextual menu functions are available.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
gestaltContextualMenuUnusedBitAvailable in Mac OS X v10.0 and later.
Declared in Menus.h.
gestaltContextualMenuTrapAvailableIf this bit is set, the contextual menu functions are available to 68K applications. If this bit is not set, these functions are not available to 68K applications.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
gestaltContextualMenuHasAttributeAndModifierKeysThe contextual menu supports attributes and modifier keys.
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
gestaltContextualMenuHasUnicodeSupportThe contextual menu supports Unicode text.
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
Mac OS X and all versions of Mac OS that shipped with CarbonLib support contextual menus, so you need to check only to see if certain features are available.
Indicates what types of contextual menu help is available.
enum {
kCMHelpItemNoHelp = 0,
kCMHelpItemAppleGuide = 1,
kCMHelpItemOtherHelp = 2,
kCMHelpItemRemoveHelp = 3
};
kCMHelpItemNoHelpThe application does not support any help. The Menu Manager will put an appropriate help string into the menu and disable it.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kCMHelpItemAppleGuideThe application supports Apple Guide help. The Menu Manager will put the name of the main Guide file into the menu and enable it.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kCMHelpItemOtherHelpThe application supports some other form of help. In this case, the application must also pass a valid string into the inHelpItemString parameter of ContextualMenuSelect. This string will be the text of the help item in the menu, and the help item will be enabled.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kCMHelpItemRemoveHelpThe application does not support any help. The Menu Manager will remove the Help item from the contextual menu.
Available in CarbonLib 1.6 and Mac OS X and later. Note however, that in CarbonLib, this constant is equivalent to kCMItemNoHelp, which only disables the Help item.
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
You can pass these constants in the inHelpType parameter of the function ContextualMenuSelect to specify the kind of help the application supports. Contextual menu help type constants are available with Appearance Manager 1.0 and later.
Indicates the type of item the user selected from a contextual menu.
enum {
kCMNothingSelected = 0,
kCMMenuItemSelected = 1,
kCMShowHelpSelected = 3
};
kCMNothingSelectedThe user did not choose an item from the contextual menu and the application should do no further processing of the event.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kCMMenuItemSelectedThe user chose one of the application’s items from the menu. The application can examine the outMenuID and outMenuItem parameters of ContextualMenuSelect to see what the menu selection was, and it should then handle the selection appropriately.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kCMShowHelpSelectedThe user chose the Help item from the menu. The application should open an Apple Help database to a section appropriate for the selection. If the application supports some other form of help, it should be presented instead.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
These constants are returned in the outUserSelectionType parameter of the function ContextualMenuSelect to specify what the user selected from the contextual menu. Contextual menu selection type constants are available with Appearance Manager 1.0 and later.
Specify contents of menu items in contextual menus.
enum {
keyContextualMenuName = 'pnam',
keyContextualMenuCommandID = 'cmcd',
keyContextualMenuSubmenu = 'cmsb',
keyContextualMenuAttributes = 'cmat',
keyContextualMenuModifiers = 'cmmd'
};
keyContextualMenuNameThe menu item text. In Mac OS X v10.1 and earlier, the data format must be either typeChar or typeIntlText. In Mac OS X v10.2 and later, you can also specify typeStyledText, typeAEText, typeUnicodeText, and typeCFStringRef. Note that if you specify typeCFStringRef, the Menu Manager releases the CFString reference after displaying the menu. If you need to hold onto the CFString reference, you should retain it before inserting it into the Apple event record (AERecord).
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
keyContextualMenuCommandIDThe menu item command ID. The data format for this parameter must be typeLongInteger.
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
keyContextualMenuSubmenuThe submenu of the menu item. You typically use this with the Apple Event Manager function AEPutDesc to add an entire AEDesc record (which contains the submenu) as the parameter data.
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
keyContextualMenuAttributesSpecifies the menu item attributes. The data format for this parameter must be typeLongInteger.
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
keyContextualMenuModifiersSpecifies the modifer keys for the menu item. The data format for this parameter must be typeLongInteger. By using this parameter along with the keyContextualMenuAttributes parameter, you can create dynamic contextual menu items that change according to the state of the modifier keys.
Declared in Menus.h.
Available in Mac OS X v10.2 and later.
You use these keyword constants to specify parameters in an Apple Event record (AERecord) that defines a contextual menu item. Typically you assign these values in your ExamineContext method of a contextual menu plugin.
Indicate messages used for non-HIView–based custom menu definitions.
enum {
kMenuDrawMsg = 0,
kMenuSizeMsg = 2,
kMenuPopUpMsg = 3,
kMenuCalcItemMsg = 5,
kMenuThemeSavvyMsg = 7,
kMenuInitMsg = 8,
kMenuDisposeMsg = 9,
kMenuFindItemMsg = 10,
kMenuHiliteItemMsg = 11,
kMenuDrawItemsMsg = 12,
mDrawMsg = kMenuDrawMsg,
mSizeMsg = kMenuSizeMsg,
mPopUpMsg = kMenuPopUpMsg,
mCalcItemMsg = kMenuCalcItemMsg
};
kMenuDrawMsgDraw the menu in the specified rectangle.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuSizeMsgCalculate the dimensions of the menu rectangle and store them in the menu structure.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuPopUpMsgCalculate the dimensions of the pop-up menu.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuCalcItemMsgCalculate the dimensions of the specified menu item.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuThemeSavvyMsgIdentify whether your menu definition function is theme-compliant. If so, your menu definition function should respond by passing back kThemeSavvyMenuResponse in the whichItem parameter. The Menu Manager then draws the menu background as appropriate for the current theme.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuInitMsgPerform any initializations required for the menu. Return an error code in *whichItem to indicate success or failure.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDisposeMsgDispose of the menu.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuFindItemMsgDetermine the item underneath the mouse.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuHiliteItemMsgHighlight the specified menu item.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDrawItemsMsgDraw the specified menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
mDrawMsgSame as kMenuDrawMsg. Obsolete.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
mSizeMsgSame as kMenuSizeMsg. Obsolete.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
mPopUpMsgSame as kMenuPopUpMsg. Obsolete.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
mCalcItemMsgSame as kMenuCalcItemMsg. Obsolete.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
For applications running on Mac OS X v10.3 and later, Apple recommends creating custom menu definitions using HIView subclasses rather than MDEF messages. See Introducing HIView for more information.
The Menu Manager passes a value defined by one of these constants in the message parameter of your menu definition function specifying what action your function must perform. Other messages are reserved for internal use by Apple Computer, Inc. For more information on how to respond to the various messages, see MenuDefProcPtr.
Older MDEF messages.
enum {
mChooseMsg = 1,
mDrawItemMsg = 4,
kMenuChooseMsg = mChooseMsg,
kMenuDrawItemMsg = mDrawItemMsg
};
mChooseMsgDetermine whether the specified mouse location is in an enabled menu item, and highlight or unhighlight the menu item appropriately. Carbon MDEFs must replace mChooseMsg with the new messages kMenuFindItemMsg and kMenuHiliteItemMsg.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
mDrawItemMsgDraw the specified menu item in the specified rectangle. mDrawItemMsg was used by the popup menu control in versions of the Mac OS prior to Mac OS 8.5, but is no longer used.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuChooseMsgSame as mChooseMsg.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDrawItemMsgSame as mDrawItemMsg.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
Indicates that the font menu should be hierarchical.
enum {
kHierarchicalFontMenuOption = 0x00000001
};
kHierarchicalFontMenuOptionThe parent menu displays the font families, with font variations (plain, bold, and so on) displayed in submenus.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
Use this option constant when calling the CreateStandardFontMenu function.
Specify menu attributes.
typedef UInt32 MenuAttributes;
enum {
kMenuAttrExcludesMarkColumn = (1 << 0),
kMenuAttrAutoDisable = (1 << 2),
kMenuAttrUsePencilGlyph = (1 << 3),
kMenuAttrHidden = (1 << 4),
kMenuAttrCondenseSeparators = (1 << 5),
kMenuAttrDoNotCacheImage = (1 << 6),
kMenuAttrDoNotUseUserCommandKeys = (1 << 7)
};
kMenuAttrExcludesMarkColumnNo column space is allocated for the mark character when this menu is drawn.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuAttrAutoDisableThe menu title is automatically disabled when all of its menu items are disabled.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuAttrUsePencilGlyphUse the pencil glyph from the Keyboard font (kMenuPencilGlyph) to draw the control modifier keys when drawing keyboard equivalents. Typically used only for Japanese input method menus.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuAttrHiddenDo not draw the menu title, even when the menu is inserted in the menu bar. This attribute is useful for specifying keyboard equivalent commands that don’t correspond with visible menu items. That is, you can add command key equivalents to to menu items and keep the menu itself from appearing in the menu.
Declared in Menus.h.
Available in Mac OS X v10.2 and later.
kMenuAttrCondenseSeparatorsHides extra separators to avoid blank spaces in a menu. That is, if separators exists at the beginning or end of a menu, or if multiple contiguous separators exist, the Menu Manager marks the extra separator items as hidden. The Menu Manager checks for extra separators whenever it recalculates the menu size.
Declared in Menus.h.
Available in Mac OS X v10.3 and later.
kMenuAttrDoNotCacheImageDisables automatic caching of the menu image. Normally, the Menu Manager caches images of all HIView–based menus. (All standard menus are drawn using HIViews in Mac OS X v10.3 and later.) If you specify this attribute, the Menu Manager draws the menu each time it is displayed.
Declared in Menus.h.
Available in Mac OS X v10.3 and later.
kMenuAttrDoNotUseUserCommandKeysDisables substitution of command key equivalents from the NSUserKeysEquivalents dictionary. By default, the Menu Manager checks for matches in the dictionary for every menu item. Note that this attribute is effective only if you set it when you create the menu; After the Menu Manager searches the dictionary and sets the user command keys (which occurs in the CalcMenuSize, GetMenuItemCommandKey, GetItemCmd and before command key matching), you cannot retrieve the original command keys. Similarly, clearing this attribute does not restore the original command keys.
Declared in Menus.h.
Available in Mac OS X v10.3 and later.
Menu attributes control behavior of the entire menu. They are used with the ChangeMenuAttributes and GetMenuAttributes.
Specify attributes for menu items.
typedef UInt32 MenuItemAttributes;
enum {
kMenuItemAttrDisabled = (1 << 0),
kMenuItemAttrIconDisabled = (1 << 1),
kMenuItemAttrSubmenuParentChoosable = (1 << 2),
kMenuItemAttrDynamic = (1 << 3),
kMenuItemAttrNotPreviousAlternate = (1 << 4),
kMenuItemAttrHidden = (1 << 5),
kMenuItemAttrSeparator = (1 << 6),
kMenuItemAttrSectionHeader = (1 << 7),
kMenuItemAttrIgnoreMeta = (1 << 8),
kMenuItemAttrAutoRepeat = (1 << 9),
kMenuItemAttrUseVirtualKey = (1 << 10),
kMenuItemAttrCustomDraw = (1 << 11),
kMenuItemAttrIncludeInCmdKeyMatching = (1 << 12),
kMenuItemAttrAutoDisable = (1 << 13),
kMenuItemAttrUpdateSingleItem = (1 << 14)
};
kMenuItemAttrDisabledThis menu item is disabled.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrIconDisabledThis menu item’s icon is disabled.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrSubmenuParentChoosableThe user can select the parent item of a submenu.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrDynamicThis menu item changes dynamically based on the state of the modifier keys. For example, holding down the command key might change the menu item from “Select widget” to “Select all widgets.”
When a menu item has alternate dynamic states, you should group them together sequentially in the menu and assign them the same command key. A collection of menu item alternates is called a dynamic group.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrNotPreviousAlternateThis item is not part of the same dynamic group as the previous item. The Menu Manager determines which menu items belong to a dynamic group by examining the command keys of each item; if a menu item has the same command key as the previous item, the Menu Manager considers it to be part of the same dynamic group.
However, in some cases you may have sequential items with the same command key (or no command key at all) that should not be considered part of the same dynamic group. To distinguish the separation, you should set this flag for the first menu item in the new group.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrHiddenThe menu item is not drawn when displaying the menu. The item is also not included in command-key matching unless the kMenuItemAttrDynamic or kMenuItemIncludeInCmdKeyMatching attribute is set.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrSeparatorThe menu item is a separator; any text in the item is ignored.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrSectionHeaderThe menu item is a menu section header; this item is disabled and not selectable.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrIgnoreMetaIgnore the dash (-) metacharacter in this menu item. Dashes at the beginning of a menu item title traditionally signify that the menu item is a separator. However, in some cases you might want to display the dash in the title (for example, if you wanted the menu item to read “-40 degrees F.”)
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrAutoRepeatThe IsMenuKeyEvent event function recognizes this menu item when it receives an autorepeat keyboard event.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrUseVirtualKeyWhen MenuEvent and IsMenuKeyEvent compare this menu item’s keyboard equivalent against a keyboard event, they use the item’s virtual keycode equivalent rather than its character code equivalent.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemAttrCustomDrawThis is a custom menu item. Setting this attribute causes custom menu item drawing Carbon events to be sent to your application. Available in CarbonLib 1.4 and Mac OS X v10.1 and later.
Available in Mac OS X v10.1 and later.
Declared in Menus.h.
kMenuItemAttrIncludeInCmdKeyMatchingIf this attribute is set, functions such as MenuKey, MenuEvent and IsMenuKeyEvent examine this menu item during command key matching. Typically, visible items are examined and hidden items (unless they have the kMenuItemAttrDynamic attribute set) are ignored during command key matching. However, by setting this attribute, you can force hidden items to be included in the matching. Available in CarbonLib 1.6 and Mac OS X v10.2 and later.
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
kMenuItemAttrAutoDisableDisables the menu item if it does not respond to the kEventCommandUpdateStatus event . That is, if no kEventCommandUpdateStatus handler is installed on this item, or if all the handlers installed for the update event return eventNotHandledErr, this item is automatically disabled. This attribute is useful if your application uses the kEventCommandUpdateStatus event to enable menu items; for example you no longer have to install an update status handler on the application target to disable menu items when there are no document windows open.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kMenuItemAttrUpdateSingleItemUpdate only the menu item that matches when searching available command keys. Normally when the Menu Manager does command key matching, it sends a kEventMenuEnableItems event to the menu containing the matching item and then sends a kEventCommandUpdateStatus to each item in the menu. Doing so can be inefficient, since in most cases only the item that matches needs to be updated. By setting this attribute, only the matching item receives the update event and kEventMenuEnableItems is not sent to the menu. If your application enables menu items solely through kEventCommandUpdateStatus event handlers, you should set this attribute for your menu items.
Declared in Menus.h.
Available in Mac OS X v10.3 and later.
Menu item attributes control behavior of individual menu items. They are used with the GetMenuItemAttributes and ChangeMenuItemAttributes APIs.
Indicate the type of menu definition being used.
enum {
kMenuDefProcPtr = 0,
kMenuDefClassID = 1
};
typedef UInt32 MenuDefType;
kMenuDefProcPtrA custom menu definition using the older MDEF messaging model.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDefClassIDA custom menu definition using an HIView subclass.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
Indicate menu definition features.
enum {
kThemeSavvyMenuResponse = 0x7473
};
kThemeSavvyMenuResponseIndicates that the menu is Appearance theme–savvy.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
The Menu Manager may pass the kMenuThemeSavvyMsg constant in the message parameter of your menu definition function to determine if your custom menu is theme-savvy (that is, whether it draws using Appearance Manager functions). In response, your menu definition function may respond with this flag in the whichItem parameter.
Specify options used in menu item functions.
enum {
textMenuProc = 0,
hMenuCmd = 27,
hierMenu = -1,
kInsertHierarchicalMenu = -1,
};
textMenuProcThe menu definition ID for menus that are not Appearance-compliant. When mapping is enabled, this constant is mapped to kMenuStdMenuProc, its Appearance-compliant equivalent. Not normally used.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
hMenuCmdDeprecated. Use SetMenuItemHierarchicalMenu or SetMenuItemHierarchicalID to specify a hierarchical menu instead.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
hierMenuDeprecated. Use kInsertHierarchicalMenu instead.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kInsertHierarchicalMenuUsed with InsertMenu to insert a submenu or pop-up menu into the submenu portion of the current menu list.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kHIMenuAppendItemPass to InsertMenuItem, InsertMenuItemText, or InsertMenuItemTextWithCFString to indicate that the new menu item should be added to the end of the menu. Note that you can simply call AppendMenu, AppendMenuItemText, or AppendMenuItemTextWithCFString instead.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
A menu definition ID is supplied to the menu resource or a menu-creation function such as NewMenu to specify which menu definition function to use in creating the menu. The menu definition ID contains the resource ID of the menu definition function.
Specify options when attempting to match a keyboard event to a menu item.
typedef UInt32 MenuEventOptions;
enum {
kMenuEventIncludeDisabledItems = 0x0001,
kMenuEventQueryOnly = 0x0002,
kMenuEventDontCheckSubmenus = 0x0004
};
kMenuEventIncludeDisabledItemsDisabled items are examined for a match.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuEventQueryOnlyDon’t highlight the menu title if a match is found.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuEventDontCheckSubmenusDon’t search the submenus of the starting menu when looking for a match.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
Menu event options control how the menus are searched for an item matching a particular keyboard event. They are used with the IsMenuKeyEvent API.
Specify menu glyphs.
enum {
kMenuNullGlyph = 0x00,
kMenuTabRightGlyph = 0x02,
kMenuTabLeftGlyph = 0x03,
kMenuEnterGlyph = 0x04,
kMenuShiftGlyph = 0x05,
kMenuControlGlyph = 0x06,
kMenuOptionGlyph = 0x07,
kMenuSpaceGlyph = 0x09,
kMenuDeleteRightGlyph = 0x0A,
kMenuReturnGlyph = 0x0B,
kMenuReturnR2LGlyph = 0x0C,
kMenuNonmarkingReturnGlyph = 0x0D,
kMenuPencilGlyph = 0x0F,
kMenuDownwardArrowDashedGlyph = 0x10,
kMenuCommandGlyph = 0x11,
kMenuCheckmarkGlyph = 0x12,
kMenuDiamondGlyph = 0x13,
kMenuAppleLogoFilledGlyph = 0x14,
kMenuParagraphKoreanGlyph = 0x15,
kMenuDeleteLeftGlyph = 0x17,
kMenuLeftArrowDashedGlyph = 0x18,
kMenuUpArrowDashedGlyph = 0x19,
kMenuRightArrowDashedGlyph = 0x1A,
kMenuEscapeGlyph = 0x1B,
kMenuClearGlyph = 0x1C,
kMenuLeftDoubleQuotesJapaneseGlyph = 0x1D,
kMenuRightDoubleQuotesJapaneseGlyph = 0x1E,
kMenuTrademarkJapaneseGlyph = 0x1F,
kMenuBlankGlyph = 0x61,
kMenuPageUpGlyph = 0x62,
kMenuCapsLockGlyph = 0x63,
kMenuLeftArrowGlyph = 0x64,
kMenuRightArrowGlyph = 0x65,
kMenuNorthwestArrowGlyph = 0x66,
kMenuHelpGlyph = 0x67,
kMenuUpArrowGlyph = 0x68,
kMenuSoutheastArrowGlyph = 0x69,
kMenuDownArrowGlyph = 0x6A,
kMenuPageDownGlyph = 0x6B,
kMenuAppleLogoOutlineGlyph = 0x6C,
kMenuContextualMenuGlyph = 0x6D,
kMenuPowerGlyph = 0x6E,
kMenuF1Glyph = 0x6F,
kMenuF2Glyph = 0x70,
kMenuF3Glyph = 0x71,
kMenuF4Glyph = 0x72,
kMenuF5Glyph = 0x73,
kMenuF6Glyph = 0x74,
kMenuF7Glyph = 0x75,
kMenuF8Glyph = 0x76,
kMenuF9Glyph = 0x77,
kMenuF10Glyph = 0x78,
kMenuF11Glyph = 0x79,
kMenuF12Glyph = 0x7A,
kMenuF13Glyph = 0x87,
kMenuF14Glyph = 0x88,
kMenuF15Glyph = 0x89,
kMenuControlISOGlyph = 0x8A,
kMenuEjectGlyph = 0x8C
};
kMenuNullGlyphThe null character. Note that this glyph has no visible representation (that is, nothing appears in the menu).
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuTabRightGlyphThe Tab-to-the-right key. Used in left to right script systems.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuTabLeftGlyphThe Tab-to-the-left key. Used in right to left script systems.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuEnterGlyphThe Enter key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuShiftGlyphThe Shift key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuControlGlyphThe Control key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuOptionGlyphThe Option key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuSpaceGlyphThe Space bar. Note that this glyph has no visible representation (that is, nothing appears in the menu).
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDeleteRightGlyphThe Delete-to-the-right key. Used in right-to-left script systems.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuReturnGlyphThe Return key for left-to-right script systems.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuReturnR2LGlyphThe Return key for right-to-left script systems.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuNonmarkingReturnGlyphThe nonmarking Return key. Note that this glyph has no visible representation (that is, nothing appears in the menu).
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuPencilGlyphThe Pencil key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDownwardArrowDashedGlyphThe downward dashed arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuCommandGlyphThe Command key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuCheckmarkGlyphThe Check mark key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDiamondGlyphThe diamond mark.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuAppleLogoFilledGlyphThe filled Apple logo.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuParagraphKoreanGlyphUnassigned. (Paragraph glyph in Korean)
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDeleteLeftGlyphThe Delete-to-the-left key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuLeftArrowDashedGlyphThe dashed left arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuUpArrowDashedGlyphThe dashed up arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuRightArrowDashedGlyphThe dashed right arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuEscapeGlyphThe Escape key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuClearGlyphThe Clear key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuLeftDoubleQuotesJapaneseGlyphUnassigned. (Left double quotation marks in Japanese)
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuRightDoubleQuotesJapaneseGlyphUnassigned (Right double quotation marks in Japanese)
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuTrademarkJapaneseGlyphUnassigned. (Trademark in Japanese)
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuBlankGlyphThe blank key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuPageUpGlyphThe Page Up key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuCapsLockGlyphThe Caps Lock key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuLeftArrowGlyphThe left arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuRightArrowGlyphThe right arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuNorthwestArrowGlyphThe northwest arrow key
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuHelpGlyphThe Help key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuUpArrowGlyphThe up arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuSoutheastArrowGlyphThe southeast arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuDownArrowGlyphThe down arrow key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuPageDownGlyphThe Page Down key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuAppleLogoOutlineGlyphThe outlined Apple logo.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuContextualMenuGlyphThe contextual menu key
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuPowerGlyphThe power key (that is, the startup key).
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF1GlyphThe F1 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF2GlyphThe F2 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF3GlyphThe F3 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF4GlyphThe F4 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF5GlyphThe F5 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF6GlyphThe F6 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF7GlyphThe F7 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF8GlyphThe F8 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF9GlyphThe F9 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF10GlyphThe F10 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF11GlyphThe F11 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF12GlyphThe F12 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF13GlyphThe F13 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF14GlyphThe F14 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuF15GlyphThe F15 key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuControlISOGlyphThe ISO standard control key.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuEjectGlyphThe Eject key (available in Mac OS X v10.2 and later).
Available in Mac OS X v10.2 and later.
Declared in Menus.h.
Use these constants with GetMenuItemKeyGlyph and SetMenuItemKeyGlyph.
Indicate which fields of a MenuItemDataRec structure are to be copied or set.
enum {
kMenuItemDataText = (1 << 0),
kMenuItemDataMark = (1 << 1),
kMenuItemDataCmdKey = (1 << 2),
kMenuItemDataCmdKeyGlyph = (1 << 3),
kMenuItemDataCmdKeyModifiers = (1 << 4),
kMenuItemDataStyle = (1 << 5),
kMenuItemDataEnabled = (1 << 6),
kMenuItemDataIconEnabled = (1 << 7),
kMenuItemDataIconID = (1 << 8),
kMenuItemDataIconHandle = (1 << 9),
kMenuItemDataCommandID = (1 << 10),
kMenuItemDataTextEncoding = (1 << 11),
kMenuItemDataSubmenuID = (1 << 12),
kMenuItemDataSubmenuHandle = (1 << 13),
kMenuItemDataFontID = (1 << 14),
kMenuItemDataRefcon = (1 << 15),
kMenuItemDataAttributes = (1 << 16),
kMenuItemDataCFString = (1 << 17),
kMenuItemDataProperties = (1 << 18),
kMenuItemDataIndent = (1 << 19),
kMenuItemDataCmdVirtualKey = (1 << 20),
kMenuItemDataAllDataVersionOne = 0x000FFFFF,
kMenuItemDataAllDataVersionTwo = kMenuItemDataAllDataVersionOne
| kMenuItemDataCmdVirtualKey
};
enum {
kMenuItemDataAllData = kMenuItemDataAllDataVersionTwo
};
typedef UInt64 MenuItemDataFlags;
kMenuItemDataTextSet or return the Str255 text of a menu using the MenuItemDataRec.text field. If getting the text, the text field must be initialized with a pointer to a Str255 variable before calling CopyMenuItemData. If both kMenuItemDataText and kMenuItemCFString are set on entry to CopyMenuItemData, the API will determine whether the menu text was most recently set using a Str255 or CFString, and return only that text format; the flags value for the other format will be cleared. Valid for both menu items and the menu title (if item number is 0).
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataMarkSet or return the mark character of a menu item using the MenuItemDataRec.mark field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataCmdKeySet or return the command key of a menu using the MenuItemDataRec.cmdKey field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataCmdKeyGlyphSet or return the command key glyph of a menu using the MenuItemDataRec.cmdKeyGlyph field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataCmdKeyModifiersSet or return the command key modifiers of a menu using the MenuItemDataRec.cmdKeyModifiers field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataStyleSet or return the QuickDraw text style of a menu item using the MenuItemDataRec.style field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataEnabledSet or return the enable state of a menu using the MenuItemDataRec.enabled field. Valid for both menu items and the menu itself (if the item number is zero).
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataIconEnabledSet or return the enable state of the menu item icon using the MenuItemDataRec.iconEnabled field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataIconIDSet or return the icon resource ID of the menu item icon using the MenuItemDataRec.iconID field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataIconHandleSet or return the icon handle of a menu item using the MenuItemDataRec.iconType and MenuItemDataRec.iconHandle field. You must initialize both fields if you are setting the handle; both fields are returned when obtaining the handle.
The iconType field can contain one of the following constants: kMenuIconType, kMenuShrinkIconType, kMenuSmallIconType, kMenuColorIcontype, kMenuIconSuiteType, or kMenuIconRefType. The icon handle may be a handle to an 'ICON' resource, a 'SICN' resource, a 'cicn' resource, an icon suite, or an icon reference. Valid only for menu items.
In Mac OS X v10.0 and later, the iconType field can also contain kMenuCGImageType, with the icon handle being of type CGImageRef.
In Mac OS X v10.1 and later, the iconType field can also contain kMenuSystemIconSelectorType or kMenuIconResource, which have icon handles of type OSType and CFStringRef respectively.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataCommandIDSet or return the command ID of a menu using the MenuItemDataRec.cmdID field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataTextEncodingSet or return the text encoding of a menu item using the MenuItemDataRec.encoding field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataSubmenuIDSet or return the menu ID of the submenu associated with this menu item using the MenuItemDataRec.submenuID field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataSubmenuHandleSet or return the menu reference (MenuRef) of the submenu associated with this menu using the MenuItemDataRec.submenuHandle field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataFontIDSet or return the font ID associated with this menu item using the MenuItemDataRec.fomtID field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataRefconSet or return the reference constant associated with this menu item using the MenuItemDataRec.refcon field. If you specified a menu item index of 0, you can set or obtain the menu reference constant.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataAttributesSet or return the attribute bits associated with this menu item using the MenuItemDataRec.attr field. If you specified a menu item index of 0, you can set or obtain a MenuAttributes bit field, not a MenuItemAttributes bit field.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataCFStringSet or return the title of the menu item (as a Core Foundation string) using the MenuItemDataRec.cFText field. If you specified a menu item index of 0, you can set or obtain the menu title.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataPropertiesSet or return the properties of a menu using the MenuItemDataRec.properties field.
If setting properties, the properties field should contain a collection with the new properties; note that this will overwrite any existing properties with the same collection creator and tag.
If getting properties, you should set the properties field to either a valid collection or NULL. A valid collection is overwritten by the new properties. If you pass NULL, the CopyMenuItemData function allocates a new collection and returns it in the properties field.
You can set this flag for both menu items and the menu itself (if the item number is zero).
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataIndentSet or return the indent level of a menu item using the MenuItemDataRec.indent field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataCmdVirtualKeySet or return the virtual key code for this menu item using the MenuItemDataRec.cmdVirtualKey field. Valid only for menu items.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataAllDataVersionOneSets all flags, except for kMenuItemDataCmdVirtualKey.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuItemDataAllDataVersionTwoSets all flags, including kMenuItemDataCmdVirtualKey.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
A MenuItemDataFlags value indicates which fields of a “MenuItemDataRec” structure should be used by the CopyMenuItemData or SetMenuItemData functions. All menu item data flags may be used when getting or setting the contents of a menu item; some may also be used when getting or setting information about the menu itself, if the item index given to CopyMenuItemData or SetMenuItemData is 0.
Specify types of icons to attach to menu items.
enum {
kMenuNoIcon = 0,
kMenuIconType = 1,
kMenuShrinkIconType = 2,
kMenuSmallIconType = 3,
kMenuColorIconType = 4,
kMenuIconSuiteType = 5,
kMenuIconRefType = 6,
kMenuCGImageRefType = 7,
kMenuSystemIconSelectorType = 8,
kMenuIconResourceType = 9
};
kMenuNoIconNo icon.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuIconTypeIdentifies an icon of type 'ICON'.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuShrinkIconTypeIdentifies a 32-by-32-pixel icon of type 'ICON', shrunk (at display time) to 16-by-16.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuSmallIconTypeIdentifies an icon of type 'SICN'.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuColorIconTypeIdentifies an icon of type 'cicn'.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuIconSuiteTypeIdentifies an icon suite.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuIconRefTypeIdentifies an icon of type IconRef. This value is supported under Mac OS 8.5 and later.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuCGImageRefTypeIdentifies an icon of type CGImageRef.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuSystemIconSelectorTypeIdentifies an OSType value that corresponds to an icon (type IconRef )registered with Icon Services under kSystemIconsCreator.
Available in Mac OS X v10.1 and later.
Declared in Menus.h.
kMenuIconResourceTypeIdentifies a CFString that names an icon resource in the main bundle of the application.
Available in Mac OS X v10.1 and later.
Declared in Menus.h.
These constants specify the type of an icon attached to a menu item. They are passed in SetMenuItemIconHandle and obtained by GetMenuItemIconHandle. Menu item icon type constants are available with Appearance Manager 1.0 and later.
Define attributes to associate with menu item properties.
enum {
kMenuPropertyPersistent = 0x00000001
};
kMenuPropertyPersistentIf this bit is set, the menu item property is saved when the menu is flattened.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
Indicates how the menu is being tracked.
typedef UInt32 MenuTrackingMode;
enum {
kMenuTrackingModeMouse = 1,
kMenuTrackingModeKeyboard = 2
};
kMenuTrackingModeMouseMenus are being tracked using the mouse.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuTrackingModeKeyboardMenus are being tracked using the keyboard.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
A menu tracking mode constant is part of the kEventMenuBeginTracking and kEventMenuChangeTrackingMode Carbon events. It indicates whether a menu is being tracked by mouse movement or by directional keyboard input.
Specify modifier keys used with menu item selections.
enum {
kMenuNoModifiers = 0,
kMenuShiftModifier = (1 << 0),
kMenuOptionModifier = (1 << 1),
kMenuControlModifier = (1 << 2),
kMenuNoCommandModifier = (1 << 3)
};
kMenuNoModifiersIf no bit is set, only the Command key is used in the keyboard equivalent.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuShiftModifierIf this bit (bit 0) is set, the Shift key is used in the keyboard equivalent.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuOptionModifierIf this bit (bit 1) is set, the Option key is used in the keyboard equivalent.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuControlModifierIf this bit (bit 2) is set, the Control key is used in the keyboard equivalent.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
kMenuNoCommandModifierIf this bit (bit 3) is set, the Command key is not used in the keyboard equivalent.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
You can use one or more of these mask constants to determine which modifier key(s) must be pressed along with a character key to create a keyboard equivalent for selecting a menu item. You set and obtain these constants by calling SetMenuItemModifiers and GetMenuItemModifiers, respectively.
Indicates that a menu item contains no marking characters.
enum {
noMark = 0
};
noMarkNo marking character to be associated with a menu or submenu item.
Available in Mac OS X v10.0 and later.
Declared in Menus.h.
You can pass this constant, as well as those character marking constants defined in the Font Manager, in the markChar parameter of the function SetItemMark and the marking character field of the menu resource (of type ‘ MENU’) and return these constants in the markChar parameter of the function GetItemMark to specify the mark of a specific menu item or the menu ID of the submenu associated with the menu item.
Specify reasons why menu tracking ended.
enum {
kHIMenuDismissedBySelection = 1,
kHIMenuDismissedByUserCancel = 2,
kHIMenuDismissedByMouseDown = 3,
kHIMenuDismissedByMouseUp = 4,
kHIMenuDismissedByKeyEvent = 5,
kHIMenuDismissedByAppSwitch = 6,
kHIMenuDismissedByTimeout = 7,
kHIMenuDismissedByCancelMenuTracking = 8,
kHIMenuDismissedByActivationChange = 9,
kHIMenuDismissedByFocusChange = 10
};
kHIMenuDismissedBySelectionThe user selected a menu item.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByUserCancelThe user cancelled menu tracking.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByMouseDownThe user pressed the mouse someplace that did not result in a menu item selection.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByMouseUpThe user released the mouse someplace that did not result in a menu item selection.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByKeyEventA keyboard event occurred.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByAppSwitchThe application with the menu is no longer frontmost.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByTimeoutThe menu tracking mode timed out.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByCancelMenuTrackingThe application called CancelMenuTracking.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByActivationChangeThe active window changed.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
kHIMenuDismissedByFocusChangeThe user focus window changed, or the keyboard focus was removed from the current process.
Available in Mac OS X v10.3 and later.
Declared in Menus.h.
The Carbon Event Manager passes these constants in the kEventMenuEndTrackingEvent to indicate why menu tracking ended.
Specify the menu definitions for standard menus and menu bars.
enum {
kMenuStdMenuProc = 63,
kMenuStdMenuBarProc = 63
};
kMenuStdMenuProcThe menu definition ID for Appearance-compliant menus.
Available with Appearance Manager 1.0 and later.
Declared in Menus.h.
kMenuStdMenuBarProcThe menu bar definition ID for Appearance-compliant menu bars.
Available with Appearance Manager 1.0 and later.
Declared in Menus.h.
This table lists result codes defined for the Menu Manager.
© 1992, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-09-15)