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

This chapter is from the book

This chapter is from the book

Demonstration Program Menus2 Comments

When this program is run, the user should choose Show Balloons from the Help menu and make menu choices from all menus, including the Apple menu. Choices should be made using the mouse and, where appropriate, the keyboard equivalents. The user should note:

  • The extended modifier keys assigned to the last two items in the Style menus.

  • The Command-key equivalents assigned to the items in the Size menu. (These are, in order, delete-to-the-left key, delete-to-the-right key, page-up key, and page-down key.)

  • That the Font menu is WYSIWYG.

  • That the marking character column has been deleted from the Special menu and the menu items in this menu are drawn in the Gadget font (assuming it is available).

  • That the items in the submenu attached to the second item in the Special menu have color icons.

  • The balloon help provided for all menus and menu items.

The Menus2 demonstration program package also includes a demonstration of Apple Help, including the methodology used to create an item in the Mac OS 8/9 Help menu. The Apple Guide file titled "Menus Guide", which will cause a "Menus Help" item to be created in the Mac OS 8/9 Help menu, should be retained in the same folder as the Menus2 application. An alias of the folder titled "Menus Help" should be placed in the Help folder in the System Folder (Mac OS 8/9) and in the user's Help folder (~/Library/Documentation/Help) (Mac OS X). You will then be able to access the help content by choosing Menus Help from the Help menu.

The help content does not provide user assistance for Menus2 programs as such. Rather, it provides a brief description of how to provide user assistance for your application using Apple Help.

Because this demonstration program is based on Menus1, the following comments exclude those for the functions that remain unchanged.

main

The calls to RGBBackColor and RGBForeColor set the window background and foreground colors to, respectively, dark blue and white.

doGetMenus

doGetMenus sets up the menu bar and the various menus.

GetNewMBar reads in the 'MENU' resources for each menu specified in the 'MBAR' resource and creates a menu object for each of those menus. (Note that the error handling here and in other areas of this program is somewhat rudimentary: the program simply terminates.) SetMenuBar makes the newly created menu list the current list.

The next block utilizes the Menu Manager function CreateStandardFontMenu in the creation of a non-hierarchical Font menu. Following the call to CreateStandardFontMenu, the process of making the menu WYSIWYG begins. The call to CountMenuItems returns the number of items in the menu. Then, for each of these items, GetMenuItemText gets the font's name, GetFNum gets the font number associated with the font name, and SetMenuItemFontID sets the font for the menu item. In the following if block, the current item is checkmarked if the item name equals the name of the small system font, and the global variable which keeps track of the currently selected font is assigned the item number.

The next block programmatically assigns extended modifier keys to the Outline and Shadow items in the Style (Programmatic) menu. The SetMenuItemModifiers calls assign Shift-Option-Control to the Outline item and Shift-Option to the Shadow item. (The extended modifier keys for the same two items in the Style ('xmnu') menu are assigned in the associated 'xmnu' resources.)

The next block inserts the application's single submenu into the submenu portion of the menu list and programmatically attaches it to the Special menu's second menu item. GetNewMBar does not read in the resource descriptions of submenus, so the first step is to read in the 'MENU' resource with GetMenu. InsertMenu inserts a menu object for this menu into the menu list at the location specified in the second parameter to this call. (Using the constant hierMenu (-1) as the second parameter causes the menu to be installed in the submenu portion of the menu list.) The call to GetMenuRef gets a reference to the Special menu, which is used in the following call to SetMenuHierarchicalID to attach the submenu to the second item in the Special menu.

The following rather large block programmatically assigns command IDs to all items in the Style (Programmatic), Size, and Special menus and the submenu. (Command IDs for the File and Style ('xmnu') menus are assigned in the associated 'xmnu' resources. It is not possible to assign command IDs to the items in the Font menu.) The Command IDs are defined in the four-character-code format, which packs four one-byte characters together in a 32-bit value. For example, 'plai' expressed as hexadecimal is 0x706C6169. 70 is the ASCII code for p, 6C is the ASCII code for l, and 69 is the ASCII code for i.

The following block programmatically assigns a color icon to the second item in the submenu. The call to GetCIcon creates a CIcon data structure and initializes it from data read in from the specified 'cicn' resource. The handle to this structure is then passed as the last parameter in the SetMenuItemIconHandle, the third parameter specifying that the type of icon is a color icon. (The color icon for the first item in the submenu is assigned in the associated 'xmnu' resource.)

The next block programmatically assigns command-key equivalents to the items of the Size menu. (Because the keys assigned are the two delete keys and the page-up and page-down keys, it is not possible to make these assignments within the 'MENU' resource.) Also, a substitute glyph must be assigned, otherwise the correct glyphs will not be displayed. The calls to SetItemCmd assign the specified key to the menu item, and a substitute glyph is assigned via calls to SetMenuItemGlyph. If this is not done, the glyphs displayed will not be the correct visual representations of the keys. (These substitute glyphs could also have been specified in the keyboard glyph fields for these items in the menu's 'xmnu' resource.)

In the next block, SetMenuExcludesMarkColumn is called to delete the marking character column from the Special menu and SetMenuFont is called to set the font for the menu items in this menu to Gadget (assuming that font is present).

In the next block, and only if the program is running on Mac OS X, HMGetHelpMenu is called to create a Help menu, InsertMenuItem is called to insert a single item in that menu, and SetMenuItemCommandID assigns a command ID to that item.

The next block sets checkmarks against the appropriate font, style and size menu items according to the initialized values of the associated global variables.

The call to DrawMenuBar draws the menu bar

Note that, in Carbon, the contents of the Apple Menu Items folder are automatically added to the Apple menu.

doMenuChoice

doMenuChoice extracts the menu ID and menu item number from the long integer returned by the MenuSelect and MenuEvent calls. An immediate return is made if the high word equals 0. The function "special cases" the Font menus, calling the function for handling choices from that menu. Otherwise, GetMenuItemCommandID is called. GetMenuItemCommandID returns zero as the function result if the call is successful, and a pointer to an integer representing the value of the item's command ID will be returned in the third parameter. If the call is successful, and if a zero is not returned in the third parameter, a command ID exists for the item. Accordingly, the command ID is passed in a call to the function doCommand.

MenuSelect and MenuEvent leave the menu title highlighted if an item was actually chosen. Accordingly, the last line unhighlights the menu title when the action associated with the user's drop-down menu choice is complete.

doCommand

doCommand handles choices from those menus whose items have command IDs.

Note that the initial handling of all of the remaining menu items, regardless of which menu they belong to, is attended to within the one switch in the one function. The responses to the user choosing the various menu items is the same as in Menus1, except that the code relating to checkmarking the Style menu items has been added and the code for checkmarking the Size menu items and storing the current size has been divided between this function a further handling function (doCheckSizeMenuItem).

At the block titled Style ('xmnu') and Style (Programmatic) menu, bits in the global variable gCurrentStyle are set or unset according to the font styles selected. The code reflects the fact that Bold, Italic, Underline, Outline and Shadow style selections are additive, not mutually exclusive, and that a selection of Plain must unset all bits in gCurrentStyle. The code also reflects the requirement that, except in the case of the Plain item, the selection of a checked item must cause that item to be unchecked, and vice versa. With gCurrentStyle set, the function doCheckStyleMenuItem is called to check/uncheck the relevant menu items as appropriate.

Note that the handling of the two submenu items has been changed to make the items mutually exclusive.

The 'help' command ID case applies only when the program is run on Mac OS X. The function AHGoToPage is called to deliver a request to load the specified HTML file in the specified Help book folder to the Help Viewer application.

doCheckStyleMenuItem

doCheckStyleMenuItem is called from doMenuChoice when an item in the Style menu is chosen. With the appropriate bit settings of gCurrentStyle attended to within doMenuChoice, a reference to the Style menu object is obtained. This is required for the six CheckMenuItem calls, which check or uncheck the individual menu items according to whether the third parameter evaluates to, respectively, true or false.

The call to TextFace sets the style for subsequent text drawing. The last line draws some text to prove that the desired effect was achieved.

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.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020