TweetFollow Us on Twitter

MACINTOSH C
MACINTOSH C: A Hobbyist's Guide To Programming the Mac OS in C
Version 2.3

© 2000 K. J. Bricknell

Go to Contents

(Chapter 3)

MENUS

A link to the associated demonstration program listings is at the bottom of this page



Introduction

Types of Menus

A menu is a user interface element which allows the user to view, or choose from, a list of choices and commands provided by your application. There are basically three types of menus:

  • Pull-Down Menus. A pull-down menu is identified by a menu title in the menu bar. Each pull-down menu comprises a menu title and one or more menu items.

  • Submenus. A submenu is a menu that is attached to another menu. A menu to which a submenu is attached is referred to as a hierarchical menu.

  • Pop-Up Menus. A pop-up menu is a menu which does not appear in the menu bar but rather appears on another part of the screen when the user presses the mouse button while the cursor is at a particular location.

Pull-Down Menus

Menu Definition Functions and Menu Bar Definition Functions

The Menu Manager uses the following to display, and to perform basic operations on, menus and the menu bar:

  • Menu Definition Function. When you define a menu, you must specify the required menu definition function (MDEF). The Menu Manager uses that MDEF to draw the menu items in a menu, determine which item the user chose, insert scrolling indicators as items in a menu, calculate the menu's dimensions, etc. An MDEF thus determines the look and behaviour of menus.

  • Menu Bar Definition Function. The Menu Manager uses the menu bar definition function to draw and clear the menu bar, determine whether the cursor is currently within the menu bar or any currently displayed menu, calculate the left edges of menu titles, highlight a menu title, invert the entire menu bar, draw the menu's shadow box, and save/restore the bits behind a menu. A menu bar definition function thus determines the look and behaviour of the menu bar.

Standard Theme-Compliant Menu and Menu Bar Definition Functions

The system software provides a standard theme-compliant MDEF and a standard theme-compliant menu bar definition function, which are stored as code resources in the System file. The standard MDEF is the 'MDEF' resource with a resource ID of 63. The standard menu bar definition function is the 'MBDF' resource with a resource ID of 63.

Historical Note

These are the resource IDs of revised definition functions first issued with Mac OS 8 and the Appearance Manager. The old pre-Appearance definition functions have resource IDs of 0, and remain in the System file. In Mac OS 8.0 and 8.1, the new definition functions are located in the Appearance extension. As of Mac OS 8.5, they are located in the System file.

When you define your menus and menu bar, you specify the definition functions that the Menu Manager should use when managing them. Ordinarily, you will use the standard functions; however, as with most other elements of the Macintosh user interface, the option is available to write your own custom definition function if you need to provide features not available in the standard definition functions. Given the new features added by the latest standard definition functions, however, it is all but impossible to conceive of circumstances that would require the writing of a custom definition function.

Chapter 20 - Lists and Custom List Definition Functions includes an example of custom definition functions for another element of the user interface known as a list.

The Menu Bar and Menus

The Menu Bar

The menu bar extends across the top of the screen. As defined by the standard menu bar definition function, the menu bar is white and high enough to display menu titles in the height of the system font (Chicago 12 point or Charcoal 12 point for Roman Scripts) plus a single pixel bottom border.

Generally, the menu bar should always be visible. If you want to hide the menu bar for some reason, you should provide a method (for example, a keyboard equivalent for a menu command) to allow the user to make the menu bar reappear.

The 'MBAR' Resource. Each application has its own menu bar, which is defined by an 'MBAR' resource. This resource lists the order and resource ID of each menu appearing in your menu bar. Your menu's 'MBAR' resource should be defined such that the Apple menu is the first menu in the menu bar, with the File and Edit menus being the next two. The Help and Application menus do not need to be defined in the 'MBAR' resource, since the Menu Manager automatically adds them to the menu bar when the application calls GetNewMBar provided that your menu bar includes the Apple menu.

Menus

All Macintosh applications should provide, as a minimum, the standard menus. The standard menus are the Apple menu, the File menu and the Edit menu.

Your application can disable any menu, which causes the Menu Manager to dim that menu's title and all associated menu items. The menu items can also be disabled individually. Your application should specify whether menu items are enabled or disabled when it first defines and creates a menu and can enable or disable items at any time thereafter.

The 'MENU' Resource. For each menu, you define the menu title and the individual characteristics of its menu items in a 'MENU' resource.

The 'xmnu' Resource. For each menu, you may also define an 'xmnu' (extended menu) resource. The 'xmnu' resource was introduced with Mac OS 8 and the Appearance Manager and is, in effect, the extension of the 'MENU' resource required to provide for additional menu features. . Note that you do not need to provide this resource if you do not require these additional features. An 'xmnu' resource must have the same ID as the 'MENU' resource it extends

Historical Note - The 'mctb' Resource.

The use of the old standard MDEF (resource ID 0) was sometimes accompanied by the use of a menu colour table ('mctb') resource with the same ID as the associated 'MENU' resource. This allowed the default colours of the title, item text, and background to be changed. The use of 'mctb' resources is inconsistent with the concept of themes and Appearance-compliance; accordingly, under the Appearance Manager, the use of this resource is not recommended.

Menu Items

A menu item can contain text or a dividing line (that is, a divider). A divider is always dimmed. Each menu item, other than dividers, can have a number of characteristics as follows:

  • An icon, small icon, reduced icon, colour icon, or an icon from an icon family to the left of the menu item's text. (Note that items with small or reduced icons cannot have submenus.)
    The various icon types are described at Chapter 13- Offsreeen Graphics Worlds, Pictures, Cursors, and Icons.

    Historical Note

    Support for icon families was introduced with Mac OS 8 and the Appearance Manager.

  • A checkmark or other marking character to the left of the menu item's text, indicating the status of the menu item or the mode it controls. (A menu item can have a mark or a submenu, but not both.)

  • The symbols for the item's keyboard equivalent. (An item that has a keyboard equivalent cannot have a submenu, a small icon or a reduced icon.)

  • A triangular indicator to the right of a menu item's text to indicate that the item has a submenu. (An item that has a submenu cannot have a keyboard equivalent, a marking character, a small icon or a reduced icon.)

  • A font style (bold, italic, etc.) for the menu item's text.

  • The text of the menu item.

  • The ellipsis character (...) as the last character in the text of the menu item, indicating that, before executing the command, the application will display a dialog box requesting more information from the user. (The ellipsis character should not be used in menu items which display informational dialogs or a confirmational alert.)

  • A dimmed appearance when the application disables the item. (When the menu title is dimmed, all menu items in that menu are also dimmed.)
A menu can contain any number of menu items; however, in versions of the system software earlier than Mac OS 8.5, only the first 31 can be disabled.

Groups of Menu Items

Where appropriate, menu items should be grouped, with each group separated by a divider. For example, a menu can contain commands which perform actions and commands which set attributes. The action commands which are logically related should be grouped, as should attribute commands which are interdependent. The attribute commands which are mutually exclusive, and those which form accumulating attributes (for example, Bold, Italic and Underline), should also be grouped.

Keyboard Equivalents for Menu Commands

The Menu Manager provides support for keyboard equivalents. You detect a keyboard equivalent by examining the modifiers field of the event structure, first determining whether the Command key was pressed at the time of the event. If so, your application typically calls MenuEvent, which maps the keyboard equivalent character contained in the specified event structure to its corresponding menu and menu item and returns the menu ID and the chosen menu item.
A keyboard equivalent is any combination of the Command key, optionally one or more modifier keys (Shift, Option, Control), and another key. A Command-key equivalent such as _-C is thus, by definition, also a keyboard equivalent.
You should not assign a Command-Shift-number key sequence to a menu item as its keyboard equivalent; Command-Shift-number key sequences are reserved for use as 'FKEY' resources. Command-Shift-number key sequences are not returned to your application, but instead are processed by the Event Manager. The Event Manager invokes the 'FKEY' resource with a resource ID that corresponds to the number that activates it.

Historical Note

Prior to Mac OS 8 and the Appearance Manager, only Command-key equivalents for menu items were supported. Support for keyboard equivalents was introduced with Mac OS 8 and the Appearance Manager. This new capability is generally referred to as "support for extended modifier keys" (Shift, Option, and Control).

Reserved Command-Key Equivalents. Apple reserves the following Command-key equivalents, which should be used in the File and Edit menus of your application:

Keys Command Menu
Command-A Select All Edit
Command-C Copy Edit
Command-N New File
Command-O Open... File
Command-P Print... File
Command-Q Quit File
Command-S Save File
Command-V Paste Edit
Command-W Close File
Command-X Cut Edit
Command-Z Undo Edit

Other common keyboard equivalents are:

Keys Command Menu
Command-B Bold Style
Command-F Find File
Command-G Find Again File
Command-I Italic Style
Command-T Plain Text Style
Command-U Underline Style

Menus Added Automatically By the Menu Manager

The menus added automatically by the Menu Manager (the Help and Application menus) are sometimes referred to as the system-managed menus. The Application menu has an icon as a title. The Help menu is displayed only if space is available; however, the application menu is invariably displayed, overlapping the main part of a long menu if this becomes necessary.

Historical Note

Prior to Mac OS 8 and the Appearance Manager, the Help menu had an icon as a title and was located immediately to the left of the Application menu. The new menu bar definition function uses Help as the menu title and displays the menu immediately to the right of your application's last menu.

Your application does not need to take any action if the user chooses an item from the Application menu. However, if the user chooses an item added by your application to the Help menu, your application is responsible for taking the appropriate action.

The Apple Menu

The Apple menu should be defined as the first in your application. Typically, applications provide an About command as the first menu item, followed by a divider. The remaining items are, of course, controlled by the contents of the Apple Menu Items folder in the System folder.

To create your application's Apple menu, firstly define the Apple menu title, the characteristics of your application's About command and the divider following it in a 'MENU' resource. Then insert the contents of the Apple Menu Items folder into your application's Apple menu by calling AppendResMenu, with 'DRVR' specified as the resource type in the parameter theType.

When the user chooses the About command, your application should display a dialog box or an alert box containing your application's name, version number, copyright information, any other information as required, and an OK button.

When the user chooses an item other than the About command, your application should call the OpenDeskAcc function, which schedules the chosen item for execution and then returns to your application. At the next call to WaitNextEvent, your application receives a suspend event and the chosen item becomes the foreground process.

The File Menu

The standard File menu (see Fig 1) contains commands related to the management of documents, plus the Quit command. The standard commands should be supported by your application. Any other commands added to the standard section of the menu should pertain to the management of documents. The actions your application should take when File menu commands are chosen are detailed at Chapter 15 - Printing and Chapter 16 - Files.

The Edit Menu

The standard Edit menu (see Fig 2) provides commands which allow the user to edit the contents of their documents and to copy data between different applications using the Clipboard.

(Standard File and Edit menus)

All Macintosh applications should include the standard editing commands (Undo, Cut, Copy, Paste and Clear) so as to support those operations in dialog boxes.

An additional word or phrase should be added to Undo to clarify exactly what action your application will reverse. Other commands may be added if they are related to editing or changing the contents of your application's documents.

The Help Menu

You can add items to the end of the Help menu to give the user access to any online help that your application provides in addition to help balloons. Items are added to the Help menu using HMGetHelpMenuHandle and AppendMenu. When adding items, include the name of your application in the command so as to indicate to the user just which application the help relates to.

You should, however, not add an item to the Help menu in this way if you are providing online help using Apple Help (see below).

Help Balloons

In the Help menu, the effect of selecting Show Balloons and Hide Balloons is global and affects all applications. The Help Manager provides balloons for the Apple, Help and Application menu titles, for items in the Application menu, and for the standard items in the Help menu. Your application should provide the content of help balloons for all other menu items and menus in your application.

Apple Help and the Help Menu

Applications may use Apple Help, which was introduced with Mac OS 8.6, to provide online help. Apple Help documentation and tools are included in an Apple Help Software Development Kit (SDK), which is available at http:/developer.apple.com/sdk . Amongst other things, the documentation describes how to create an Apple Guide file which, when located in the same folder as your application, will cause the system to install a help menu item (or items) in the Help menu. The menu at the left at Fig 2 is the Help menu as it normally appears. The menu at the right at Fig 2 shows the Help menu as it appears when the Apple Guide file is present.

(Help Menu - Effect of Apple Guide File)

The Application Menu

When the user chooses an item from the Application menu, the Menu Manager handles the event as appropriate. For example, if the user chooses another application, the Menu Manager sends your application a suspend event.

Font Menus

If your application has a Font menu, you should list in that menu the names of all currently available fonts (that is, all those residing in the Fonts folder in the System folder). Fonts are added to the Font menu using AppendResMenu or InsertResMenu, which add items to the specified menu in alphabetical order.

Your application should indicate which font is in use by adding a checkmark to the left of the name in the Font menu. If the current selection contains more than one font, a dash should be placed next to the name of each font the selection contains. When the user starts entering text at the insertion point, your application should display text in the current font.

Font Attributes

Separate menus should be used to accommodate lists of font attributes such as styles and sizes. Since the system software supports both bitmapped and TrueType fonts, your application should not provide an upper limit for font sizes.

WYSIWYG Font Menus

Mac OS 8 and the Appearance Manager introduced the new function SetMenuItemFontID, which enables you to easily set up a Font menu with each item being drawn in the actual font.

Hierarchical Menus

A hierarchical menu is a menu which has a submenu attached to it. Hierarchical menus should be used to provide the user with additional choices in the nature of attributes. They should not be used to provide additional commands. There should only ever be one hierarchical level, that is, there should be only one level of submenus.

Pop-Up Menus

Pop-up menus are used to present the user with a list of choices in a dialog box or window. Pop-up menus work well when your application needs to present several choices to the user and it is acceptable to hide these choices until the menu is opened. (Other methods of displaying choices are checkboxes and radio buttons.) Pop-up menus should not be used for multiple choice lists or as a way to provide more commands. They should contain attributes rather than actions; accordingly, Command-key equivalents should not be used in pop-up menus.

The standard pop-up menu is actually implemented as a control, specifically, the pop-up menu button control. Its appearance (see Fig 3) and behaviour is thus determined by a pop-up menu button control definition function.

(Pop-up menu button)

Because pop-up menus are implemented as controls, they are addressed at Chapter 7 - Introduction to Controls. Further information in this chapter will be limited to the provision of the 'MENU' resource required by the pop-up menu button control.

Menu Structures, Menu IDs and Item Numbers, Command IDs, and Menu Lists

The Menu Structure

The Menu Manager maintains information about menus in menu structures, a data structure of type MenuInfo:

     struct MenuInfo 
     {
       short   menuID;       // Menu ID of the menu.
       short   menuWidth;    // Horizontal dimensions of the menu in pixels.
       short   menuHeight;   // Vertical dimensions of the menu in pixels.
       Handle  menuProc;     // Handle to the menu definition procedure.
       long    enableFlags;  // Enabled/disabled flags.
       Str255  menuData;     // Menu title
     };
     typedef struct MenuInfo MenuInfo;
     typedef MenuInfo *MenuPtr;
     typedef MenuPtr *MenuHandle;

You typically specify most of this information in a 'MENU' resource. When you create a menu, the Menu Manager creates a menu structure for the menu and returns a handle to that structure. The Menu Manager automatically updates the menu structure when you make any changes to the menu programmatically.

Menu IDs and Item Numbers

To refer to a menu, you usually use either the menu's ID or the handle to the menu's menu structure. Accordingly, you must assign a menu ID to each menu in your application as follows:

  • Pull-down menus must use a menu ID greater than 0.

  • Submenus of an application must use a menu ID of from 1 to 235.
To refer to a menu item, you use the item's item number. Item numbers in a menu start at 1.

Command IDs

Mac OS 8 and the Appearance Manager introduced the command ID, which is an alternative way of referring to a specific menu item in an application's menus.

The Menu List

The menu list, a structure private to the Menu Manager, contains handles to the menu structures of one or more menus (although a menu list can, in fact, be empty). The end of a menu list contains handles to the menu structures of submenus and pop-up menus, if any, the phrase "submenu portion of the menu list" referring to this portion of the list.

When your application initialises the Menu Manager, the Menu Manager creates the menu list. The menu list is initially empty but changes as your application adds menus to it or removes menus from it programmatically.

Creating Your Application's Menus

'MBAR', 'MENU', and 'xmnu' Resources

As stated at Chapter 1 - System Software, Memory, And Resources, you can provide a textual, formal description of resources in a file and then use a resource compiler such as Rez to compile the description into a resource, or you can create resource descriptions using a resource editor such as Resorcerer. Macintosh C assumes the use of Resorcerer.

When creating resources using Resorcerer, it is advisable that you refer to a diagram and description of the structure of the resource and relate that to the various items in the Resorcerer editing windows. Accordingly, the following describes the structure of those resources associated with the creation of menus.

Structure of a Compiled 'MBAR' Resource

Fig 4 shows the structure of a compiled 'MBAR' resource. The number of menu resource IDs should match the number of menus declared in the first two bytes.

(MBAR resource)

Structure of a Compiled 'MENU' Resource

Fig 5 shows the structure of a compiled 'MENU' resource (and its variable length data) and how it "feeds" the menu structure.

(MENU resource)

The following describes the main fields of the 'MENU' resource:

Field Description
MENU ID Each menu in your application should have a unique menu ID. Note that the menu ID does not have to match the resource ID, although by convention most applications assign the same number for a menu's resource ID and menu ID.

A menu ID from 1 to 235 indicates a menu (or submenu) of an application. A negative menu ID indicates a menu belonging to a driver. A menu ID from 236 to 255 indicates a submenu of a driver. Apple reserves the menu ID of 0.

PLACEHOLDER FOR MENU WIDTH
PLACEHOLDER FOR MENU HEIGHT
After reading in the resource data, the Menu Manager requests the menu's MDEF to calculate the width and height of the menu and store these values in the menuWidth and menuHeight fields of the menu structure.
RESOURCE ID OF MENU DEFINITION FUNCTION If the integer 63 appears here, the Menu Manager uses the standard MDEF to manage the menu. If you provide your own MDEF, its resource ID should appear in this field.

After reading in the menu's resource data, the Menu Manager reads in the MDEF, if necessary. The Menu Manager stores a handle to the MDEF in the menuProc field of the menu structure.

INITIAL ENABLED STATE OF THE MENU AND MENU ITEMS This is a 32-bit value where bits 1-31 indicate if the corresponding menu item is enabled or disabled, and bit 0 indicates whether the menu as a whole is enabled or disabled. The Menu Manager automatically enables menu items greater than 31 when a menu is created.
VARIABLE LENGTH DATA THAT DEFINES THE MENU ITEMS The Menu Manager simply reads in this variable length data for each menu item and stores it as variable data at the end of the menu structure. The MDEF is responsible for interpreting the contents of the data (see Fig 5).

The following describes the main fields of the variable length data for each menu item. Note that various alternatives apply to the icon number, keyboard equivalent, and marking character fields. For example, a menu item can have a keyboard equivalent or a submenu, but not both.

Field Description
ICON NUMBER, SCRIPTCODE, OR 0 ICON NUMBER

The icon number is a number from 1 to 255 (or from 1 to 254 for small or reduced icons).

The Menu Manager adds 256 to the icon number to generate the resource ID of the menu item's icon. If the menu item specifies an icon, you should also provide a 'cicn' (colour icon) or 'ICON' resource with a resource ID equal to the icon number plus 256. If you want the Menu Manager to reduce an 'ICON' resource to the size of a small icon ('SICN'), or reduce the size of a 'cicn' resource by half, also provide the value 0x1D in the keyboard equivalent field (see below). If you want a 'SICN' resource, also provide the value 0x1E in the keyboard equivalent field.

The Menu Manager looks first for a 'cicn' resource with the calculated resource ID. In the era of the Appearance Manager, colour icons are much to be preferred.

SCRIPTCODE (Not to be used when the 'MENU' resource is extended with an 'xmnu' resource)

If you want the Menu Manager to draw the item's text in a script other than the system script, specify the script code here and also provide 0x1C in the keyboard equivalent field (see below).

When the 'MENU' resource is extended by an 'xmnu' resource, the script code should be set in the text encoding field of the 'xmnu' resource.

0

Indicates that the menu item does not contain an icon and uses the system script.

KEYBOARD EQUIVALENT, 0X1B, 0X1C, 0X1D, OX1E, OR 0 KEYBOARD EQUIVALENT

Specified as a one-byte character and, actually, a Command-key equivalent only.

The Command-key equivalent can be extended with modifier key (Shift, Option, Control) constants in the modifier keys field of the extended menu ('xmnu') resource (see below).

0x1B

Indicates that the menu item has a submenu. (The menu ID of the submenu should be assigned to the marking character field (see below).)

0x1C (Not to be used when the 'MENU' resource is extended with an 'xmnu' resource)

Indicates that the item uses a script other than the system script. (The script code should be assigned to the icon number field (see above).)

When the 'MENU' resource is extended by an 'xmnu' resource, the script code should be set in the text encoding field of the 'xmnu' resource.

0x1D

For menu items containing icons, causes the Menu Manager to reduce an 'ICON' resource to the size of a small icon, or reduce the size of a 'cicn' resource by half.

0x1E

Indicates that you want the Menu Manager to use a small icon ('SICN') resource for the item's icon. (The small icon's resource ID should be assigned to the icon number field (see above).)

0

Indicates that the menu item has neither a keyboard equivalent nor a submenu and uses the system script.

MARKING CHARACTER, MENU ID OF SUBMENU, OR 0 MARKING CHARACTER

Special characters, such as the checkmark and diamond charcaters, are available to indicate the marks associated with a menu item.

MENU ID OF SUBMENU

Submenus of an application must have menu IDs from 1 to 235. Submenus of a driver must have menu IDs from 236 to 255..

0

Indicates that the item has neither a mark nor a submenu.

FONT STYLE OF THE MENU ITEM Indicates whether the font style of the menu item should be plain, or any combination of bold, italic, outline, and shadow.

Structure of a Compiled 'xmnu' Resource

The 'xmnu' resource provides for the additional features introduced with Mac OS 8 and the Appearance Manager, for example, support for extended modifier keys, command IDs, etc. Fig 6 shows the structure of a compiled 'xmnu' resource and an individual menu item entry in that resource.

(xmnu resource)

The following describes the fields of a compiled 'xmnu' resource:

Field Description
VERSION NUMBER An integer specifying the version of the resource.
NUMBER OF ENTRIES An integer that specifies the number of entries in the resource. Each entry is an extended menu item structure.
FIRST EXTENDED MENU ENTRY
...
LAST EXTENDED MENU ENTRY
A series of extended menu item structures, each of which consists of a type, command ID, modifier keys, text encoding, reference constants, menu ID of submenu, font ID, and keyboard glyph. (A glyph is the visual representation of a character (see Chapter 19 - Text and TextEdit).

Each entry in a 'xmnu' resource corresponds to a menu item. The following describes the main fields of an extended menu item entry.

Field Description
TYPE Specifies whether there is extended information for the item. 1 indicates that there is extended information for the item, causing the Menu Manager to read the rest of the structure. 0 indicates that there is no information for the item, causing the Menu Manager to skip the rest of the structure.
COMMAND ID A unique value which you set to identify the menu item (instead of referring to it using the menu ID and item number). This value may be ascertained via a call to GetMenuItemCommandID.

A command ID may be assigned to a menu item programmatically via a call to SetMenuItemCommandID.

MODIFIER KEYS A mask that determines which modifier keys are used in a keyboard equivalent to select a menu item. The current modifier keys may be ascertained via a call to GetMenuItemModifiers.

Modifier keys may be assigned to a menu item programmatically via a call to SetMenuItemModifiers.

ICON TYPE PLACEHOLDER
ICON HANDLE PLACEHOLDER
Initially 0.

Calls to SetMenuItemHandle assign the icon type and icon handle to these two fields.

TEXT ENCODING A long integer which indicates the text encoding that the menu item text will use.

This field of the 'xmnu' resource should be used instead of setting the keyboard equivalent field in the 'MENU' resource to 0x1C and the icon number field to the script code.

If you want the text of the item to use the system script, this value should be -1. (This should be used as the default.) If you want the text of the menu item to use the current script, this value should be -2.. The current text encoding may be ascertained via a call to GetMenuItemTextEncoding.

Text encoding may be assigned to a menu item programmatically via a call to SetMenuItemTextEncoding.

REFERENCE CONSTANT Any value that an application wishes to store. The current value may be ascertained via a call to GetMenuItemRefCon.

Reference constants may be assigned to a menu item programmatically via a call to SetMenuItemRefCon.

REFERENCE CONSTANT Any additional value that an application wishes to store. The current value may be ascertained via a call to GetMenuItemRefCon.

Reference constants may be assigned to a menu item programmatically via a call to SetMenuItemRefCon.

MENU ID OF SUBMENU A value between 1 and 235, identifying the submenu. The current submenu ID may be acertained via a call to GetMenuItemHierarchicalID.

The menu ID of a submenu may be assigned to a menu item programmatically via a call to SetMenuItemHierarchicalID. This, in effect, attaches a submenu to the menu item.

FONT ID An integer representing the ID of the font family. If this value is 0, then the system font ID is used. The current font ID may be acertained via a call to GetMenuItemFontID. The font ID of a menu item may be set programmatically via a call to SetMenuItemFontID.
KEYBOARD GLYPH A symbol representing a menu item's modifier key. The current keyboard glyph may be ascertained via a call to GetMenuItemGlyph.

If the value in this field is zero, the keyboard glyph uses the keyboard font. Use of the keyboard font (rather than the system font) provides a consistent user interface across applications, since a modifier key's symbol will not change regardless of what system font is running. If the value in this field is nonzero, you can override the character code to be displayed with a substitute glyph.

The keyboard glyph of a menu item may be set programmatically via a call to SetMenuItemKeyGlyph.

The information in an 'xmnu' resource is set for specified menu items; it is not necessary to create an extended menu entry for all menu items in a menu.

It is not necessary to provide 'xmnu' resources if your application's menus do not require the additional features introduced with Mac OS 8 and the Appearance Manager.

Creating 'MBAR', 'MENU', and 'xmnu' Resources Using Resorcerer

As previously stated, when creating resources using Resorcerer, it is advisable that you refer to a diagram and description of the structure of the resource and relate that to the various items in the Resorcerer editing windows. The following assumes that approach.

Creating 'MBAR' Resources

Fig 7 shows an 'MBAR' resource containing seven menus being created with Resorcerer. The first three entries would be, respectively, the Apple, File, and Edit menus.

(Creating MBAR resource)

Creating 'MENU' Resources

Fig 8 shows an imaginary View menu with the Full Screen menu item being edited. This menu item has been assigned a keyboard equivalent (more specifically, a Command-key equivalent); accordingly, the Key Equiv: radio button has been clicked and the character F has been entered as the Command-key equivalent. The menu item has also been assigned a marking character (a checkmark).

(Editing MENU resource)

Fig 9 shows the same View menu with the Floating Palettes menu item being edited. This item has a submenu; accordingly, the Sub-menu ID radio button has been clicked and the resource ID of the submenu's 'MENU' resource has been entered. The item also has an icon provided by a 'CICN' or 'cicn' resource with a resource ID of 257.

(Further editing MENU resource)

Creating 'MENU' Resources for Submenus

Fig 10 shows the Line and Fill submenu item in the submenu attached to the Floating Palettes menu item being edited. This item has a marking character (a checkmark), an icon provided by an 'ICON' or 'cicn' resource with resource ID 258, and a Command-key equivalent.

(Editing submenu)

Creating 'xmnu' Resources

Fig 11 shows an 'xmnu' resource being created using Resorcerer. This 'xmnu' resource extends the 'MENU' resource with resource ID 133 (the View menu, above). Menu item 4 has been assigned a command ID, and the Command-key equivalent assigned to this item in the 'MENU' resource (Command-F) has been extended to the keyboard equivalent Command-Shift-F by specifying the Shift key as an extended modifier.

(Creating xmnu resource)

Creating the Menu Bar and Pull-Down Menus

The function GetNewMBar, which itself calls GetMenu, should be used to read in the 'MBAR' resource and its associated 'MENU' resources. After reading in a 'MENU' resource, GetMenu looks for an an 'xmnu' resource with the same resource ID and reads it in if found. GetNewMBar creates a menu structure for each menu and inserts each menu into the menu list.

SetMenuBar should then be used to set the current menu list as the menu list created by your application. A call to DrawMenuBar completes the process by drawing the menu bar, displaying all the menu titles in the current menu list.

Creating an Hierarchical Menu

GetNewMBar does not read in the resource descriptions of submenus but simply records the menu ID of any submenu in the menu structure. Submenu descriptions are read in with GetMenu and the submenu is inserted in the current menu list using InsertMenu, with the constant hierMenu passed as the second parameter to that call.
As the user traverses menu items, if an item has a submenu, the MenuSelect function looks in the submenu portion of the menu list for the submenu. It then searches for a menu with a defined menu ID that matches the menu ID specified by the hierarchical menu item. If it finds a match, it attaches the submenu to the menu item.

Adding Menus to the Menu List

A menu may be added to the current menu list using one of the following procedures:

  • Read the relevant 'MENU' resource in with GetMenu, add it to the current menu list with InsertMenu, and update the menu bar with DrawMenuBar.

  • Use NewMenu to create a new empty menu, use AppendMenu, InsertMenuItem, InsertResMenu, or AppendResMenu to fill the menu with menu items, add the menu to the current menu list using InsertMenu, and update the menu bar using DrawMenuBar.
Note that GetMenuHandle may be used to obtain a handle to the menu structure of any menu in the current menu list.

Providing Help Balloons

'hmmu' Resources

You should define Help balloons for each of your application's menu items and each menu title. Help balloons for menus are defined in 'hmmu' resources. The resource ID of an 'hmnu' resource should be the same as the resource ID of the 'MENU' resource to which it pertains. In the case of the 'hmnu' resource for your Help menu item, the resource ID should be -16490.

Creating 'hmnu' Resources

Fig 12 shows an 'hmnu' (help menu) resource being created using Resorcerer.

(Creating hmnu resource)

Specifying the Format of Help Messages. The example at Fig 12 specifies the format of the help messages as (Pascal) text strings stored within the 'hmnu' resource itself. Clicking on the pop-up button adjacent to Message record type opens a pop-up menu which facilitates the choice of other formats (and also provides an option which enables you to instruct the Help Manager to skip the item). The items in the pop-up menu and their meanings are as follows:

Pop-up Menu Item Meaning to Help Manager
Use these strings Use the strings specified within this component of this 'hmnu' resource.
Use 'PICT' resources Use the picture stored in the specified 'PICT' resource.
Use 'STR#' resources Use the specified text string stored in the specified 'STR#' resource. (Storing the text strings in 'STR#' resources or 'STR ' resources (see below) simplifies the task of providing foreign language versions of your application.)
Used styled text resources Use the styled text stored in the specified 'TEXT' and 'styl' resources.
Use 'STR ' resources Use the text string stored in the specified 'STR ' resource.
Use named resource type Use the resource ('STR ', 'PICT' or 'TEXT') whose name matches the name and state of the current menu item.
Skip missing item No help message. Skip this item
Compare item Compare the specified comparison string against the current menu item in that position. If the specified string matches the name of the current menu item, display the help messages specified in the next four elements. (This is useful in the case of menu items that change names, for example Show Hidden Text and Hide Hidden Text.)

Text for Help Balloons. The text of your help balloons for menus should answer at least one of the following questions:

  • What is this? For example, when the user moves the cursor over the title of the File menu in the title bar, the beginning of the balloon text should be "File menu".

  • What does this do? For example, when the user moves the cursor over the Find item in a File menu, the balloon text should be "Finds and selects items with the characteristics you specify" or similar.

Changing the Appearance of Items in a Menu

Menu Manager functions may be used to change the appearance of items in a menu, for example, the font style, text or other characteristics. Most of the functions which get or set menu characteristics require three parameters:

  • A handle to the menu structure of the menu containing the desired item.

  • The number of the menu item.

  • A variable which either specifies the data to set or identifies where to return information about that item.

Enabling and Disabling Menu Items

Specific menu items or entire menus are disabled and enabled using:

  • DisableItem and EnableItem, which both take a handle to the menu structure that identifies the desired menu and either the item number of the menu to be enabled/disabled or a value of 0 to indicate that the entire menu is to be enabled/disabled. DisableItem and EnableItem can only disable and enable menu items with item numbers up to 31.

  • In Mac OS 8.5 and later, DisableMenuItem and EnableMenuItem. Unlike DisableItem and EnableItem, DisableMenuItem and EnableMenuItem can enable and disable menu items with item numbers greater than 31.
When an entire menu is disabled or enabled, DrawMenuBar should be called to update the appearance of the menu bar. If you do not need to update the menu bar immediately, you can use InvalMenuBar instead of DrawMenuBar, causing the Event Manager to redraw the menu bar the next time it scans for update events. This will reduce the menu bar flicker which will occur if DrawMenuBar is called more than once in rapid succession.

If you disable an entire menu, the Menu Manager dims that menu's title at the next call to DrawMenuBar and dims all menu items when it displays the menu. If you enable an entire menu, the Menu Manager enables only the menu title and any items that you did not previously disable individually.

Other Appearance Changes

The following lists other functions related to changing the appearance of menu items. Those appearing on a light blue background were introduced with Mac OS 8 and the Appearance Manager. . Those appearing on a dark blue background were introduced with Mac OS 8.5.

Function Description
SetMenuItemText
GetMenuItemText
Set and get the text.
SetItemStyle
GetItemStyle
Set and get the font style.
SetItemMark
GetItemMark
Set and get the marking character.
SetItemIcon
GetItemIcon
Set and get the icon ('ICON' or 'cicn') using a resource ID.
CheckMenuItem Places and removes a checkmark at the left of the item text.
SetMenuItemFontID
GetMenuItemFontID
Set and get the font. SetMenuItemFontID allows you to set up a font menu with each item being drawn in the actual font.
SetMenuItemIconHandle
GetMenuItemIconHandle
Set and get the icon (icon suite, 'ICON' or 'cicn') using an icon handle. Provides, in conjuction with the 'xmnu' resource, the support for icon suites introduced with Mac OS 8 and the Appearance Manager.
SetMenuItemKeyGlyph
GetMenuItemKeyGlyph
SetMenuItemKeyGlyph substitutes a keyboard glyph for that normally displayed for a menu item's keyboard equivalent. GetMenuItemKeyGlyph gets the keyboard glyph for the keyboard equivalent.
SetMenuFont
GetMenuFont
Set and get the font used in an individual menu
SetMenuExcludesMarkColumn
SetMenuExcludesMarkColumn
Set and determine whether an individual menu contains space for marking characters

Adding Items to a Menu

Adding Items Other Than the Names of Resources

AppendMenu, InsertMenuItem, AppendMenuItemText, and InsertMenuItemText (the latter two were introduced with Mac OS 8.5) are used to add items other than the names of resources (such as font resources) to a previously created menu. They require:

  • A handle to the menu structure of the menu involved.

  • A string describing the items to add.

Strings With Metacharacters

AppendMenu and InsertMenuItem allow you to specify the same characteristics for menu items as are available when defining a 'MENU' resource. The string consists of the text of the menu item and any required characteristics. You can specify a hyphen as the menu item text to create a divider line. You can also use various metacharacters in the text string to separate menu items and to specify the required characteristics. The following metacharacters may be used:

MetaCharacter Description
; or Return Separates menu items.
^ When followed by an icon number, defines the icon for the item.
! When followed by a character, defines the mark for the item. If the keyboard equivalent field contains 0x1B, this value is interpreted as the menu ID of a submenu of this menu item.1
< When followed by one or more of the characters B, I, U, O, and S, defines the character style of the item to, respectively, bold, italic, underline, outline or shadow.
/ When followed by a character, defines the Command-key equivalent for the item.2

When followed by 0x1B, specifies that this menu item has a submenu.1

(Note: To specify that a menu item has a script code, reduced icon or small icon, use SetItemCmd to set the keyboard equivalent field to, respectively, 0x1C, 0x1D or 0x1E.)3

( Defines the menu item as disabled.
1 Applicable only to menus without 'xmnu' resources. When 'xmnu' resources are used, use SetMenuItemHierarchicalID to attach a submenu to a menu item.

2 When 'xmnu' resources are used, use SetMenuItemModifiers to set the extended modifier keys (Shift, Option, Control).

3 Applicable only to menus without 'xmnu' resources. When 'xmnu' resources are used, do not use SetItemCmd to specify a script code. Use SetMenuItemTextEncoding.

As an example of the use of metacharacters, assume that the following two strings are stored in a string list ('STR#') resource:

     Pick a Colour...
     (^2!=Everything<B/E

The second string in this resource uses metacharacters to specify that the menu item is to be disabled, that it has an icon with a resource ID 258 (2+256), that it has the "=" character as a marking character, that the text style is bold, and that the item has a Command-key equivalent of Command-E.
The Menu Manager adds 256 to the number you specify, and uses the result as the icon's resource ID.

Examples

The following code uses AppendMenu to append a menu item with no specific characteristics other than its text to the menu identified by the menu handle. The text for the menu item is "Pick a Colour..." as stored in the preceding 'STR#' resource.

     MenuHandle myMenu;
     Str255     itemString;
     ...
     myMenu = GetMenuHandle(mLibrary);
     GetIndString(itemString,300,1);
     AppendMenu(myMenu,itemString);

To insert an item after a given menu item, use InsertMenuItem. The following code inserts the menu item "Everything" after the menu item with the item number specified in the iRed constant:

     MenuHandle myMenu;
     Str255     ItemString;
     ...
     myMenu = GetMenuHandle(mColours);
     GetIndString(itemString,300,2);
     InsertMenuItem(myMenu,itemString,iRed);

The following code appends multiple items to the Edit menu using AppendMenu:

     MenuHandle	myMenu;
     ...
     myMenu = GetMenuHandle(mEdit);
     AppendMenu(myMenu,"\pUndo/Z;-;Cut/X;Copy/C;Paste/V");

InsertMenuItem differs from AppendMenu in the way it handles the given text string when that string contains multiple items, inserting them in reverse order. This code is equivalent to the last line of the preceding code:

     InsertMenuItem(myMenu,"\pPaste/V;Copy/C;Cut/X-;-;Undo/Z",0);

The following code adds a divider to the Edit menu:

     AppendMenu(myMenu,"\p(-");

Strings Without Metacharacters

The two functions introduced with Mac OS 8.5 (AppendMenuItemText, and InsertMenuItemText) append and insert the specified string without evaluating the string for metacharacters. These two functions may be used if you have a need to present non-alphanumeric characters in a menu item.

Adding Items Comprising Resource Names to a Menu

AppendResMenu or InsertResMenu may be used to add items that consist of resource names to a menu.

For example, you can use AppendResMenu to add the names of all font resources in the Fonts folder as menu items in your application's Font menu. Similarly, AppendResMenu can be used to add all of the items from the Apple Menu Items folder to your application's Apple menu (with 'DRVR' specified as the resource type in the call). These are common instances of when you will need to add items not already defined in a 'MENU' resource.

Adding Items to the Help Menu

Items are added to your application's Help menu using AppendMenu or InsertMenuItem.

Handling Menu Choices

Determining the Menu ID and Menu Item - MenuSelect and MenuEvent

When the user presses the mouse button while the cursor is in the menu bar, your application should first adjust its menus (that is, enable or disable menu items and add or remove marks as required) and then call MenuSelect. MenuSelect tracks the mouse, displays menus, highlights menu titles, displays and highlights enabled menu items, handles all user activity until the user releases the mouse button, and returns a long integer as its function result. The long integer contains the menu ID in the high word and the item number in the low word.

If some of your menu items have keyboard equivalents, your application should detect such key-down events. If an examination of the modifiers field of the event structure reveals that the Command key was down, your application should first adjust its menus and then call MenuEvent. MenuEvent scans the current menu list for a menu item that has a matching keyboard equivalent. Like MenuSelect, MenuEvent returns a long integer containing the menu ID and the item number.

If the user did not actually choose a menu command with the mouse, or if the user pressed a keyboard combination which did not map to a keyboard equivalent, MenuSelect and MenuEvent return 0 in the high word, the value in the low word being undefined.

Historical Note

The function MenuEvent was introduced with Mac OS 8 and the Appearance Manager as part of the new support for extended modifier keys. Previously, when only Command-key equivalents were supported, the function MenuKey was used. Technically, either MenuEvent or MenuKey could be used if your menus do not require support for extended modifier keys, though MenuEvent is recommended.

Further Handling - Command IDs Not Used

The long integer returned by MenuSelect and MenuEvent should be passed as a parameter to an application-defined function which switches according to the menu ID in the high word and passes the low word to other application-defined functions which respond appropriately to that menu command.

Further Handling - Command IDs Used

Mac OS 8 and the Appearance Manager introduced an alternative method of identifying, for the purposes of further handling, the menu item chosen by the user. This method assumes that you have previously assigned a unique value to your individual menu items via the command ID field of the 'xmnu' resource (or, programmatically, via calls to SetMenuItemCommandID).

Using this method, the menu ID and item number should be extracted from the long integer returned by MenuSelect and MenuEvent in the usual way. The menu ID should then be used in a call to GetMenuHandle to get the handle to the menu's menu structure. This handle and the menu item should then be used in a call to GetMenuItemCommandID, which returns the unique value that you previously assigned to the item (that is, the item's command ID). Your application should then switch according to that command ID, calling the other application-defined functions which respond appropriately to that menu command.

Unhighlighting the Menu Title

Recall that one of the actions of MenuSelect and MenuEvent is to highlight the menu title. Ordinarily, your application should not unhighlight the menu title (using HiliteMenu) until it performs the action associated with the menu command chosen by the user. However, if, in response to a menu command, your application displays a modal dialog box containing an editable text item, you should unhighlight the menu title immediately so that the user can access the Edit menu.

Adjusting Menus

Menu adjustment should be on the basis of the type of window that is currently the frontmost window, for example, a text window, a modeless dialog box, etc.. Accordingly, the application-defined menu adjustment function should first determine which window is the front window. The following are examples of menu adjustment functions:

     void  doAdjustMenus(void)
     {
       WindowPtr windowPtr;
       SInt16    windowType;

       windowPtr = FrontWindow();
       windowType = doGetWindowType(windowPtr);

       switch windowType 
       {
         case kMyDocWindow:
           doAdjustFileMenuForDocWindow();
           doAdjustEditMenuForDocWindow();
           // Adjust others.
           break;

         case kMyModelessDialogWindow:
           doAdjustMenusForModelessDialogs();
           break;

         case kNil:
           doAdjustMenusNoWindows();
           break;
       };

       DrawMenuBar;
     }

     void doAdjustFileMenuForDocWindow(void)
     {
       MenuHandle menuHdl;

       menuHdl = GetMenuHandle(mFile);
       EnableItem (menuHdl,iNew);
       EnableItem (menuHdl,iOpen);
       DisableItem(menuHdl,iClose);
       DisableItem(menuHdl,iSave);
       DisableItem(menuHdl,iSaveAs);
       DisableItem(menuHdl,iPageSetup);
       DisableItem(menuHdl,iPrint);
       EnableItem (menuHdl,iQuit);
     }

Handling Apple Menu Choices

When the user chooses an item in the Apple menu, MenuSelect returns the menu ID of your application's Apple menu in the high word and the item number in the low word.

If your application provides an About command as the first menu item in the Apple menu, and the user chooses this item, you should display the About box. Otherwise, your application should use the GetMenuItemText function to get the menu item text and then call the OpenDeskAcc function, passing the text of the chosen menu item as a parameter.

The OpenDeskAcc function prepares to open the desktop object chosen by the user. For example, if the user chose a document created by the SimpleText application, OpenDeskAcc schedules SimpleText for execution (or prepares to open it if it was not already open) and returns to your application. On your application's next call to WaitNextEvent, your application receives a suspend event and the Process Manager makes SimpleText the foreground process, instructing it to open the chosen document.

Handling Help Menu Choices

Both the MenuSelect and MenuEvent functions return the kHMHelpMenuID constant (-16490) in the high word if the user chooses an appended item from the Help menu. The item number of the appended item is returned in the low word. When the kHMHelpMenuID constant is detected, an application-defined function should be called to respond to the user's choice of a Help menu command. That function must accommodate the fact that Apple reserves the right to change the number of standard items in the Help menu.

Handling a Size Menu

Preamble

Font sizes in Size menus should be outlined to indicate which sizes are directly provided by the current font. For bitmapped fonts, you should outline only those sizes that exist in the Fonts folder. For TrueType fonts, all sizes supported by that font should be outlined. The current font size should be indicated with a checkmark. If the current selection contains more than one font size, a dash should be placed next to each font size in the selection.

Size menus should, in addition to displaying available font sizes, provide an Other command to enable the user to specify a size not currently listed in the menu. When the user chooses the Other command, the current font size should be displayed in a dialog box which allows the user to enter the desired font size. If the user chooses a size not already in the menu, a checkmark should be added to the Other menu item and the chosen size should be added in parenthesis to the text of the Other command.

Handling the Menu Choice

The following is an example application-defined function which handles a user's choice of an item in the Size menu:

     void  doHandleSizeCommand(SInt16 menuItem)
     {
       SInt16   numItems;
       Boolean  addItem;
       SInt32   sizeChosen;

       numItems = CountMenuItems(GetMenuHandle(mSize));

       if(menuItem == numItems)   // If user chose Other, display dialog box. If the
       {                          // user-specified size is not in the menu, add a
         doDisplayOtherBox(sizeChosen); // checkmark to the Other command and add
       }                          // new font size to the text of the Other command.
       else                       // Return sizeChosen.
       {                                // User chose a size.  Remove marks from
         doRemoveMarksFromSizeMenu();   // item/s showing previous size.  Add mark
         CheckMenuItem(GetMenuHandle(mSize),menuItem,true); // to chosen item.
         sizeChosen = doItemToSize(menuItem);  // Convert item number to font size.
       }
       doResizeSelection(sizeChosen);     // Update document state or user selection.
     }

Hiding and Showing the Menu Bar

Mac OS 8.5 introduced the functions HideMenuBar and ShowMenuBar, which may be used to make the menu bar invisible and unselectable and visible and selectable.

Accessing Menus From Alert and Dialog Boxes

When alert boxes and dialog boxes are displayed, the Dialog Manager and the Menu Manager interact to provide varying degrees of access to menus in your menu bar. In some circumstances, you can rely on the system software to disable the appropriate menus and menu items. In other circumstances, you application must contribute to, or control, the matter of menu access.

The subject of menu access when alert boxes, movable alert boxes, modal dialog boxes, moveable modal dialog boxes, and modeless dialog boxes are displayed is somewhat involved, and is addressed in detail at Chapter 8 - Dialogs and Alerts.



Main Menu Manager Constants, Data Types, and Functions

In the following:

  • The constants, data types, and functions introduced with Mac OS 8 and the Appearance Manager are shown in light blue.

  • The functions introduced with Mac OS 8.5 are shown in a dark blue.

  • Those older constants, data types and functions affected by the introduction of Mac OS 8 and the Appearance Manager, but which may still be used in certain circumstances, are shown in red.

Constants

For markChar Parameter of SetItemMark Calls

noMark       = 0
commandMark  = 17
checkMark    = 18
diamondMark  = 19
appleMark    = 20

For beforeID Parameter of InsertMenu to Insert a Submenu Into the Submenu Portion of the Menu List

hierMenu  = -1

Modifier Key Masks for GetMenuItemModifiers and SetMenuItemModifiers Calls

kMenuCommandModifiers  = 0         // If no bit is set, only the Command key is used.
kMenuShiftModifier     = (1 << 0)  // If this bit is set, Shift key is used.
kMenuOptionModifier    = (1 << 1)  // If this bit is set, Option key is used.
kMenuControlModifier   = (1 << 2)  // If this bit is set, Control key is used.
kMenuNoCommandModifier = (1 << 3)  // If this bit is set, Command key is not used.

Menu Icon Handle Constants for GetMenuItemIconHandle and SetMenuItemIconHandle Calls

kMenuNoIcon          = 0  // No icon.
kMenuIconType        = 1  // 'ICON' handle.
kMenuShrinkIconType  = 2  // 32-by-32 'ICON' handle shrunk (at display time) to 16-by-16.
kMenuSmallIconType   = 3  // 'SICN' handle.
kMenuColorIconType   = 4  // 'cicn' handle.
kMenuIconSuiteType   = 5  // Icon suite handle.

Data Types

Menu Structure

struct MenuInfo
{
  short  menuID;       // Number that identifies the menu.
  short  menuWidth;    // Width (in pixels) of menu.
  short  menuHeight;   // Height (in pixels) of menu.
  Handle menuProc;     // Menu definition procedure.
  long   enableFlags;  // Indicates whether menu and menu items are enabled.
  Str255 menuData;     // Title of menu.
};
typedef struct MenuInfo MenuInfo;
typedef MenuInfo *MenuPtr;
typedef MenuPtr *MenuHandle;

Functions

Initialising the Menu Manager

void   InitMenus();

Creating Menus

MenuHandle  NewMenu(short menuID, ConstStr255Param menuTitle);
MenuHandle  GetMenu(short resourceID);

Adding Menus to and Removing Menus From the Current Menu List

void   InsertMenu(MenuHandle theMenu,short beforeID);
void   DeleteMenu(short menuID);
void   ClearMenuBar(void);

Getting a MenuBar Description From an 'MBAR' resource

Handle   GetNewMBar(short menuBarID);

Getting and Setting the Menu Bar

Handle  GetMenuBar(void);
void    SetMenuBar(Handle menuList);
short   GetMBarHeight(void);

Drawing the Menu Bar

void   DrawMenuBar(void);
void   InvalMenuBar(void);

Controlling Menu Bar Visibility

void     HideMenuBar(void);
void     ShowMenuBar(void);
Boolean  IsMenuBarVisible(void);

Modifying the Menu Width

Boolean  GetMenuExcludesMarkColumn(MenuHandle menu);
OSStatus SetMenuExcludesMarkColumn(MenuHandle menu,Boolean excludesMark);

Responding to User Choice of a Menu Command

long   MenuKey(short ch);
Uint32 MenuEvent (EventRecord* inEvent);
long   MenuSelect(Point startPt);
long   MenuChoice(void);
void   HiliteMenu(short menuID);
long   PopUpMenuSelect(MenuHandle menu,short top,short left,short popUpItem);

Getting a Handle to a Menu Structure

MenuHandle  GetMenuHandle(short menuID);
OSErr       HMGetHelpMenuHandle(MenuHandle *mh);

Adding and Deleting Menu Items

void   AppendMenu(MenuHandle menu,ConstStr255Param data);
void   InsertMenuItem(MenuHandle theMenu,ConstStr255Param itemString,short afterItem);
OSStatus AppendMenuItemText(MenuHandle menu,ConstStr255Param inString);
OSStatus InsertMenuItemText(MenuHandle menu,ConstStr255Param inString,UInt16 afterItem);
void   DeleteMenuItem(MenuHandle theMenu,short item);
void   AppendResMenu(MenuHandle theMenu,ResType theType);
void   InsertResMenu(MenuHandle theMenu,ResType theType,short afterItem);

Manipulating and Accessing Menu Item Characteristics

void   EnableItem(MenuHandle theMenu,short item);
void   DisableItem(MenuHandle theMenu,short item);
void   EnableMenuItem(MenuHandle theMenu,UInt16 item);
void   DisableMenuItem(MenuHandle theMenu,UInt16 item);
Boolean IsMenuItemEnabled(MenuHandle menu,UInt16 item);
void   EnableMenuItemIcon(MenuHandle theMenu,UInt16 item);
void   DisableMenuItemIcon(MenuHandle theMenu,UInt16 item);
Boolean IsMenuItemIconEnabled(MenuHandle menu,UInt16 item);
void   GetMenuItemText(MenuHandle menu,short item,Str255 itemString); 
void   SetMenuItemText(MenuHandle theMenu, short item, ConstStr255Param itemString);
void   GetItemStyle(MenuHandle theMenu,short item,Style *chStyle); 
void   SetItemStyle(MenuHandle theMenu,short item,short chStyle);
void   GetItemMark(MenuHandle theMenu,short item,short *markChar);
void   SetItemMark(MenuHandle theMenu,short item,short markChar);
void   CheckMenuItem(MenuHandle theMenu,short item,Boolean checked);
OSStatus GetMenuFont(MenuHandle menu,SInt16 *outFontID,UInt16 *outFontSize);
OSStatus SetMenuFont(MenuHandle menu,SInt16 inFontID,UInt16 inFontSize);
void   GetItemIcon(MenuHandle theMenu,short item,short *iconIndex);
void   SetItemIcon(MenuHandle theMenu,short item,short iconIndex);
void   GetItemCmd(MenuHandle theMenu,short item,short *cmdChar);
void   SetItemCmd(MenuHandle theMenu,short item,short cmdChar);
OSErr  SetMenuItemCommandID(MenuHandle inMenu,SInt16 inItem,UInt32 inCommandID);
OSErr  GetMenuItemCommandID(MenuHandle inMenu,SInt16 inItem,UInt32* outCommandID);
OSErr  SetMenuItemFontID(MenuHandle inMenu,SInt16 inItem,SInt16 inFontID);
OSErr  GetMenuItemFontID(MenuHandle inMenu,SInt16 inItem,SInt16* outFontID);
OSErr  SetMenuItemHierarchicalID(MenuHandle inMenu,SInt16 inItem,SInt16 inHierID);
OSErr  GetMenuItemHierarchicalID(MenuHandle inMenu,SInt16 inItem,SInt16 *outHierID);
OSErr  SetMenuItemIconHandle(MenuHandle inMenu,SInt16 inItem,MenuIconType inIconType,
       Handle inIconHandle);
OSErr  GetMenuItemIconHandle(MenuHandle inMenu,SInt16 inItem,MenuIconType outIconType,
       Handle* outIconHandle);
OSErr  SetMenuItemKeyGlyph(MenuHandle inMenu,SInt16 inItem,SInt16 inGlyph);
OSErr  GetMenuItemKeyGlyph(MenuHandle inMenu,SInt16 inItem,SInt16 *outGlyph);
OSErr  SetMenuItemModifiers(MenuHandle inMenu,SInt16 inItem,SInt16 inModifiers);
OSErr  GetMenuItemModifiers(MenuHandle inMenu,SInt16 inItem,SInt16* outModifiers);
OSErr  SetMenuItemRefCon(MenuHandle inMenu,SInt16 inItem,SInt32 inRefCon);
OSErr  GetMenuItemRefCon(MenuHandle inMenu,SInt16 inItem,SInt32* outRefCon);
OSErr  SetMenuItemRefCon2(MenuHandle inMenu,SInt16 inItem,SInt32 inRefCon);
OSErr  GetMenuItemRefCon2(MenuHandle inMenu,SInt16 inItem,SInt32* outRefCon);
OSErr  SetMenuItemTextEncoding(MenuHandle inMenu,SInt16 inItem,TextEncoding inScriptID);
OSErr  GetMenuItemTextEncoding(MenuHandle inMenu,SInt16 inItem,TextEncoding* outScriptID);

Disposing of Menus

void   DisposeMenu(MenuHandle theMenu);

Counting Items in a Menu

short   CountMenuItems(MenuHandle theMenu);

Highlighting the Menu Bar

void   FlashMenuBar(short menuID);
void   SetMenuFlash(short count);

Recalculating Menu Dimensions

void   CalcMenuSize(MenuHandle theMenu);

Go to Demo

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »

Price Scanner via MacPrices.net

Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more
Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&T’s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more

Jobs Board

Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
IT Systems Engineer ( *Apple* Platforms) - S...
IT Systems Engineer ( Apple Platforms) at SpaceX Hawthorne, CA SpaceX was founded under the belief that a future where humanity is out exploring the stars is Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.