Home > Articles > Home & Office Computing > Mac OS X

This chapter is from the book

This chapter is from the book

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, and so on. An MDEF thus determines the look and behavior of menus.

  • Menu Bar Definition Function. The Menu Manager uses the menu bar definition function (MBDF) to draw and clear the menu bar, determine whether the cursor is currently within the menu bar or any currently displayed menu, highlight menu titles, and so on. A menu bar definition function thus determines the look and behavior of the menu bar.

Standard Menu and Menu Bar Definition Functions

The system software provides a standard MDEF and a standard MBDF. The standard MDEF is the 'MDEF' resource with a resource ID of 63. The standard MBDF is the 'MBDF' resource with a resource ID of 63.

Ordinarily, your application will specify the standard definition 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.

The Menu Bar and Menus

The Menu Bar

The menu bar extends across the top of the screen and is high enough to display menu titles in the height of the large system font (Mac OS 8/9) or system font (Mac OS X).

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) 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 application's 'MBAR' resource should be defined such that the Mac OS 8/9 Apple menu or Mac OS X Application menu (see below) is the first menu in the menu bar, with the File menu being the next. For Mac OS 8/9, the Help menu and the Mac OS 8/9 Application menu do not need to be defined in the 'MBAR' resource, because 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 ordinarily provide the Mac OS 8/9 Apple menu or Mac OS X Application menu, a File menu, and a Window menu (see Chapter 16). If your application is not document-oriented, the File menu may be renamed to something more appropriate.

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 is, in effect, an 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.

Menu Items

A menu item can contain text or a divider. On Mac OS 8/9 the divider is a line extending the full width of the menu. On Mac OS X it is simply an empty space, like a menu item with no text. Each menu item, other than a divider, can have a number of characteristics as follows:

  • An icon, small icon, reduced icon, color icon, or an icon from an icon family to the left of the menu item's text.

  • NOTE

    The various icon types are described in Chapter 13.

  • A checkmark or other marking character indicating the status of the menu item or the mode it controls.

  • 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 small icon or a reduced icon.)

  • A font style (bold, italic, and so on) 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 the application will display a dialog requesting more information from the user before executing the command. (The ellipsis character should not be used in menu items that 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.)

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 that perform actions and commands that set attributes. The action commands that are logically related should be grouped, as should attribute commands that are interdependent. The attribute commands that are mutually exclusive, and those that 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. Your application can 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 a keyboard equivalent is detected, 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.

NOTE

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 Command-C is thus, by definition, also a keyboard equivalent.

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-H

Hide <appname>

Application (Mac OS X)

Command-M

Minimize Window

Window (Mac OS X)

Command-O

Open...

File

Command-P

Print...

File

Command-Q

Quit Application (Mac OS X)

File (Mac OS 8/9)

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


The Mac OS 8/9 Apple Menu and Mac OS X Application Menu

On Mac OS 8/9, the Mac OS 8/9 Apple Menu is the first menu in your application. On Mac OS X, the Mac OS X Application Menu (see Fig 1) is the first menu.

Figure 3.1 MAC OSX application menu

Typically, applications provide an About command as the first menu item in the Apple (Mac OS 8/9) and Mac OS X Application menus. On Mac OS 8/9, the remaining items are controlled by the contents of the Apple Menu Items folder in the System folder. On Mac OS X, the remaining items are the default items automatically included in the system-created Mac OS X Application menu. Mac OS X Application menu items are general to the application, that is, they are items that are not specific to a document or other window.

To create your application's Mac OS 8/9 Apple menu for Mac OS 8/9, you simply define the Apple menu title and the characteristics of your application's About command in a 'MENU' resource. When your application is run on Mac OS 8/9, the contents of the Apple Menu Items folder are automatically added to the Apple menu.

The Apple menu 'MENU' resource will also cause the About command to be inserted in the Mac OS X Application menu when the application is run on Mac OS X.

When the user chooses the About command on Mac OS 8/9, your application should display a dialog or an alert containing your application's name, version number, copyright information, any other information as required. On Mac OS X, your application should display a modeless dialog containing the application's version and copyright information, as prescribed in Aqua Human Interface Guidelines.

The File Menu

The standard File menu contains commands related to document management plus, on Mac OS 8/9, the Quit command. (On Mac OS X, the Quit command is located in the Application menu (refer to Fig 1).) The standard commands should be supported by your application where appropriate (see Fig 2). Any other commands added to the menu should pertain to the management of documents. The actions your application should take when File menu commands are chosen are detailed in Chapter 15 and Chapter 18.

Figure 3.2 The standard file and edit menus

The Edit Menu

The standard Edit menu provides commands related to the editing of a document's contents, to copying data between different applications using the Clipboard and, on Mac OS 8/9, to showing and hiding the Clipboard (refer to Fig 2). For Mac OS 8/9 only, the standard Edit menu also standardizes the location of the Preferences... command, which, when chosen, should invoke a dialog that enables the user to set application-specific preferences. (On Mac OS X, the Preferences... command is located in the Mac OS X Application menu.)

NOTE

The implementation of Preferences commands is demonstrated at the demonstration program in Chapter 19.

All Macintosh applications which support text entry, including text entry in edit text items in dialogs, should include the standard editing commands (Undo, Cut, Copy, Paste and Clear). 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 Mac OS 8/9 System-Managed Menus

On Mac OS 8/9, two menus, namely the Mac OS 8/9 Application menu and the Help menu, are added automatically by the Menu Manager and are often referred to as the system- managed menus.

The Mac OS 8/9 Application Menu

When the user chooses an item from the Mac OS 8/9 Application menu, the Menu Manager handles the event as appropriate. For example, if the user chooses another application, your application is sent to the background and receives a suspend event.

The Mac OS 8/9 Help Menu

Applications written for Mac OS 8/9 using the Classic API have the option of programmatically appending an item (or items) to the end of the Help menu, and of programmatically detecting the user's choice of that item, so as to give the user access to help texts provided by the application. This option is not available in the Carbon API.

Carbon applications may use Apple Help, which was introduced with Mac OS 8.6, to provide application 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. 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 in Fig 3 show the Help menu as it normally appears. The menus at the right at Fig 3 show the Help menu as it appears when the Apple Guide file is present.

Figure 3.3 The MAC OS help menu - effect of the Apple guide file.

Mac OS Help Menus

For Mac OS X, your application must itself create the Help menu (using the function HMGetHelpMenu), insert the required item, or items, in that menu, and respond to the user choosing items in the menu.

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 may be added to the Font menu using AppendResMenu or InsertResMenu. However, a better alternative is to use the relatively new Menu Manager function CreateStandardFontMenu to build either a hierarchical or non-hierarchical Font menu. (A hierarchical Font menu is one in which the styles available in each font family (regular, bold, italic, and so on) appear in a submenu attached to the menu item containing the font family name.)

To indicate which font is currently in use in a non-hierachical Font menu, your application should add a checkmark to the left of the font's 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.

To indicate which font is currently in use in a hierachical Font menu, your application should place a checkmark next to the font in the submenu and a dash next to the menu item to which the submenu is attached.

Font Attributes

Separate menus should be used to accommodate lists of font attributes such as styles and sizes.

WYSIWYG Font Menus

The function SetMenuItemFontID allows you to easily set up a Font menu with each item being drawn in the actual font.

  • + Share This
  • 🔖 Save To Your Account