home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-c / macc-carbon-demos-nonbinhex.sit / macc-carbon-demos-nonbinhex / chap03-demo / Menus2 / Menus2.c < prev    next >
C/C++ Source or Header  |  2001-07-05  |  20KB  |  695 lines

  1. // *******************************************************************************************
  2. // Menus2.c                                                                CLASSIC EVENT MODEL
  3. // *******************************************************************************************
  4. // 
  5. // This program is based on Menus1.  The basic differences between this program and Menus1 are
  6. // as follows:
  7. //
  8. // •    'xmnu' resources are used to extend the 'MENU' resources for some menus.
  9. //
  10. // •    Extended modifier keys (Shift, Option, and Control) are used to extend the Command-key
  11. //        equivalents for two menu items in the Style menus.
  12. //
  13. // •    There are two Style menus (Style ('xmnu') and Style (Programmatic).  The two Style menus
  14. //        are intended to demonstrate assigning extended modifier keys to a menu item (1) via an
  15. //        'xmnu' resource and (2)    programmatically.
  16. //
  17. // •    Command IDs are assigned to all menu items except those in the system-managed menus and
  18. //        the Font menu, and the associated menu handling code branches according to the command
  19. //        ID of the chosen menu item (as opposed to menu ID and menu item).
  20. //
  21. // •    The Font menu is non-hierarchical.  It is also WYSIWYG, meaning that each item is drawn
  22. //        in that font.
  23. //
  24. // •    The delete-to-the-left, delete-to-the-right, page-up, and page-down keys are assigned as 
  25. //        Command-key equivalents in the Size menu, and the glyphs are adjusted where necessary.
  26. //
  27. // •    The submenu is attached to the second item in the Special menu programmatically rather 
  28. //        than via the 'MENU' resource.
  29. // 
  30. // •    Colour icons are included in the menu items in the submenu.
  31. //
  32. // •    Balloon help is provided, via 'hmnu' resources, for all menus.
  33. //
  34. // The extended modifier keys in the Style ('xmnu') menu are assigned via the 'xmnu' resource
  35. // for that menu.  The extended  modifier keys in the Style (Programmatic) menu are assigned 
  36. // programmatically .  
  37. //
  38. // The command IDs for items in the File, Edit, and Style ('xmnu') menus are assigned via the
  39. // 'xmnu' resources for those menus.  The command IDs for the items in the Style
  40. // (Programmatic), Size, and Special menus, and the submenu, are assigned programmatically.
  41. //
  42. // The colour icon in the first submenu item is assigned via the 'MENU' resource.  The colour
  43. // icon in the second item is assigned programmatically via a call to
  44. // SetMenuItemIconHandle.
  45. //
  46. // The program utilises the following resources:
  47. //
  48. // •    A 'plst' resource.
  49. //
  50. // •    A 'WIND' resource (purgeable) (initially not visible).
  51. //
  52. // •    An 'MBAR' resource (preload, non-purgeable).
  53. //
  54. // •    'MENU' resources for the drop-down menus and submenu (all preload, all non-purgeable).
  55. //
  56. // •    'xmnu' resources (preload, purgeable) for the drop-down menus (except the system-managed
  57. //         menus and the Font menu) and the submenu.
  58. //
  59. // •    'hmnu' resources (purgeable) providing balloon help for menus and menu items.
  60. //
  61. // •    Two 'cicn' resources (purgeable) for the items in the submenu.
  62. //
  63. // •    A 'SIZE' resource with the acceptSuspendResumeEvents, canBackground, 
  64. //        doesActivateOnFGSwitch, and isHighLevelEventAware flags set.
  65. //
  66. // *******************************************************************************************
  67.  
  68. // ………………………………………………………………………………………………………………………………………………………………………………………………………………………… includes
  69.  
  70. #include <Carbon.h>
  71.  
  72. // …………………………………………………………………………………………………………………………………………………………………………………………………………………………… defines
  73.  
  74. #define rMenubar                    128
  75. #define mAppleApplication    128
  76. #define mFile                            129
  77. #define  iQuit                        12
  78. #define mFont                            131
  79. #define mStyleXmnu                132
  80. #define mStyleProg                133
  81. #define  iPlain                        1
  82. #define  iBold                        3
  83. #define  iItalic                    4
  84. #define  iOutline                    6
  85. #define  iUnderline                5
  86. #define  iShadow                    7
  87. #define mSize                            134
  88. #define  iTen                            1
  89. #define  iTwelve                    2
  90. #define  iEighteen                3
  91. #define  iTwentyFour            4
  92. #define mSpecial                    135
  93. #define  iFirst                        1
  94. #define  iSecond                    2
  95. #define mSubmenu                    136
  96. #define  iBat                            1
  97. #define  iBowl                        2
  98. #define rWindowResource        128
  99. #define rColourIcon                258
  100.  
  101. // …………………………………………………………………………………………………………………………………………………………………………………………………… global variables
  102.  
  103. Boolean                gRunningOnX                        = false;
  104. Boolean                gDone;
  105. MenuItemIndex    gCurrentFontMenuItem    = 0;
  106. Style                    gCurrentStyle                    = 0;
  107. MenuItemIndex    gCurrentSizeMenuItem    = 2;
  108.  
  109. // …………………………………………………………………………………………………………………………………………………………………………………………… function prototypes
  110.  
  111. void    main                                    (void);
  112. void    doPreliminaries                (void);
  113. OSErr    quitAppEventHandler        (AppleEvent *,AppleEvent *,SInt32);
  114. void    doGetMenus                        (void);
  115. void    doEvents                            (EventRecord *);
  116. void    doMouseDown                        (EventRecord *);
  117. void    doAdjustMenus                    (void);
  118. void    doMenuChoice                    (SInt32);
  119. void    doCommand                            (MenuCommand);
  120. void    doFontMenu                        (MenuItemIndex);
  121. void    doCheckStyleMenuItem    (MenuID);
  122. void    doCheckSizeMenuItem        (MenuItemIndex);
  123. void    drawItemString                (Str255);
  124.  
  125. // ************************************************************************************** main
  126.  
  127. void  main(void)
  128. {
  129.     EventRecord    eventStructure;
  130.     WindowRef        windowRef;
  131.     RGBColor        foreColour = { 0xFFFF,0xFFFF,0xFFFF };
  132.     RGBColor        backColour = { 0x4444,0x4444,0x9999 };
  133.     Rect                portRect;
  134.     
  135.     // ……………………………………………………………………………………………………………………………………………………………………………………………… do preliminaries
  136.  
  137.     doPreliminaries();
  138.     
  139.     // ……………………………………………………………………………………………………………………………………………………………………………………………………… open a window
  140.         
  141.     if(!(windowRef = GetNewCWindow(rWindowResource,NULL,(WindowRef) -1)))
  142.     {
  143.         SysBeep(10);
  144.         ExitToShell();
  145.     }
  146.  
  147.     SetPortWindowPort(windowRef);
  148.     TextSize(10);
  149.     RGBBackColor(&backColour);
  150.     RGBForeColor(&foreColour);
  151.  
  152.     // ……………………………………………………………………………………………………………………… set up menu bar and menus, then show window
  153.     
  154.     doGetMenus();
  155.     ShowWindow(windowRef);
  156.     GetWindowPortBounds(windowRef,&portRect);
  157.     EraseRect(&portRect);
  158.  
  159.     // ……………………………………………………………………………………………………………………………………………………………………………………………………………… event loop
  160.  
  161.     gDone = false;
  162.  
  163.     while(!gDone)
  164.     {
  165.         if(WaitNextEvent(everyEvent,&eventStructure,180,NULL))
  166.             doEvents(&eventStructure);
  167.     }
  168. }
  169.  
  170. // *************************************************************************** doPreliminaries
  171.  
  172. void  doPreliminaries(void)
  173. {
  174.     OSErr    osError;
  175.  
  176.     MoreMasterPointers(32);
  177.     InitCursor();
  178.     FlushEvents(everyEvent,0);
  179.  
  180.     osError = AEInstallEventHandler(kCoreEventClass,kAEQuitApplication,
  181.                                                         NewAEEventHandlerUPP((AEEventHandlerProcPtr) quitAppEventHandler),
  182.                                                         0L,false);
  183.     if(osError != noErr)
  184.         ExitToShell();
  185. }
  186.  
  187. // **************************************************************************** doQuitAppEvent
  188.  
  189. OSErr  quitAppEventHandler(AppleEvent *appEvent,AppleEvent *reply,SInt32 handlerRefcon)
  190. {
  191.     OSErr            osError;
  192.     DescType    returnedType;
  193.     Size            actualSize;
  194.  
  195.     osError = AEGetAttributePtr(appEvent,keyMissedKeywordAttr,typeWildCard,&returnedType,NULL,0,
  196.                                                             &actualSize);
  197.  
  198.     if(osError == errAEDescNotFound)
  199.     {
  200.         gDone = true;
  201.         osError = noErr;
  202.     } 
  203.     else if(osError == noErr)
  204.         osError = errAEParamMissed;
  205.  
  206.     return osError;
  207. }
  208.  
  209. // ******************************************************************************** doGetMenus
  210.  
  211. void  doGetMenus(void)
  212. {
  213.     MenuBarHandle    menubarHdl;
  214.     SInt32                response;
  215.     MenuRef                menuRef;
  216.     OSStatus            osError;
  217.     ItemCount            hierMenuCount;
  218.     SInt16                a, numberOfItems, fontNumber;
  219.     Str255                fontName, smallSystemFontName;
  220.     CIconHandle        cicnHdl;
  221.  
  222.     // …………………………………………………………………………………………………………………………………………………………………………………… get and set menu bar
  223.  
  224.     menubarHdl = GetNewMBar(rMenubar);
  225.     if(menubarHdl == NULL)
  226.         ExitToShell();
  227.     SetMenuBar(menubarHdl);
  228.  
  229.     Gestalt(gestaltMenuMgrAttr,&response);
  230.     if(response & gestaltMenuMgrAquaLayoutMask)
  231.     {
  232.         menuRef = GetMenuRef(mFile);
  233.         if(menuRef != NULL)
  234.         {
  235.             DeleteMenuItem(menuRef,iQuit);
  236.             DeleteMenuItem(menuRef,iQuit - 1);
  237.             DisableMenuItem(menuRef,0);
  238.         }
  239.  
  240.         gRunningOnX = true;
  241.     }
  242.  
  243.     // ………………………………………………………………………………………………………………………………………………… set up Font menu and make WYSIWYG
  244.  
  245.     GetFontName(kThemeSmallSystemFont,smallSystemFontName);
  246.  
  247.     menuRef = GetMenuRef(mFont);
  248.     if(menuRef != NULL)
  249.     {
  250.         osError = CreateStandardFontMenu(menuRef,0,0,kNilOptions,&hierMenuCount);
  251.         if(osError == noErr)
  252.         {
  253.             numberOfItems = CountMenuItems(menuRef);
  254.             for(a=1;a<=numberOfItems;a++)
  255.             {
  256.                 GetMenuItemText(menuRef,a,fontName);
  257.                 GetFNum(fontName,&fontNumber);
  258.                 SetMenuItemFontID(menuRef,a,fontNumber);
  259.  
  260.                 if(EqualString(fontName,smallSystemFontName,false,false))
  261.                 {
  262.                     CheckMenuItem(menuRef,a,true);
  263.                     gCurrentFontMenuItem = a;
  264.                 }
  265.             }
  266.         }
  267.         else ExitToShell();
  268.     }
  269.     else
  270.         ExitToShell();
  271.  
  272.     // ………………………………………… programmatically set the extended modifiers in Style (Programmatic) menu
  273.  
  274.     menuRef = GetMenuRef(mStyleProg);
  275.     SetMenuItemModifiers(menuRef,iOutline,kMenuShiftModifier + kMenuOptionModifier
  276.                                              + kMenuControlModifier);
  277.     SetMenuItemModifiers(menuRef,iShadow,kMenuShiftModifier + kMenuOptionModifier);
  278.  
  279.     // ………… insert submenu into menu list and programmatically attach it to Special menu, item 2
  280.  
  281.     menuRef = GetMenu(mSubmenu);
  282.     if(menuRef != NULL)
  283.     {
  284.         InsertMenu(menuRef,hierMenu);
  285.         menuRef = GetMenuRef(mSpecial);
  286.         SetMenuItemHierarchicalID(menuRef,iSecond,mSubmenu);
  287.     }
  288.     else
  289.         ExitToShell();
  290.  
  291.     // ……………… programmatically set command IDs for second Style, Size, Special menus and submenu
  292.  
  293.     menuRef = GetMenuRef(mStyleProg);
  294.     SetMenuItemCommandID(menuRef,iPlain,            'plai');
  295.     SetMenuItemCommandID(menuRef,iBold,                'bold');
  296.     SetMenuItemCommandID(menuRef,iItalic,            'ital');
  297.     SetMenuItemCommandID(menuRef,iUnderline,    'unde');
  298.     SetMenuItemCommandID(menuRef,iOutline,        'outl');
  299.     SetMenuItemCommandID(menuRef,iShadow,            'shad');
  300.  
  301.     menuRef = GetMenuRef(mSize);
  302.     SetMenuItemCommandID(menuRef,iTen,                'ten ');
  303.     SetMenuItemCommandID(menuRef,iTwelve,            'twel');
  304.     SetMenuItemCommandID(menuRef,iEighteen,        'eigh');
  305.     SetMenuItemCommandID(menuRef,iTwentyFour,    'twen');
  306.  
  307.     menuRef = GetMenuRef(mSpecial);
  308.     SetMenuItemCommandID(menuRef,iFirst,            'firs');
  309.  
  310.     menuRef = GetMenuRef(mSubmenu);
  311.     SetMenuItemCommandID(menuRef,iBat,                'bat ');
  312.     SetMenuItemCommandID(menuRef,iBowl,                'bowl');
  313.     
  314.     // …………………………………………………………………… programmatically set the icon for the Bowl item in the submenu
  315.  
  316.     cicnHdl = GetCIcon(rColourIcon);
  317.     SetMenuItemIconHandle(menuRef,iBowl,kMenuColorIconType,(Handle) cicnHdl);
  318.  
  319.     // ………………… programmatically set Command-key equivalents to Size menu items and adjust glyphs
  320.  
  321.     menuRef = GetMenuRef(mSize);
  322.     SetItemCmd(menuRef,iTen,0x08);
  323.     SetMenuItemKeyGlyph(menuRef,iTen,kMenuDeleteLeftGlyph);
  324.     SetItemCmd(menuRef,iTwelve,0x7f);
  325.     SetMenuItemKeyGlyph(menuRef,iTwelve,kMenuDeleteRightGlyph);
  326.     SetItemCmd(menuRef,iEighteen,0x0b);
  327.     SetMenuItemKeyGlyph(menuRef,iEighteen,kMenuPageUpGlyph);
  328.     SetItemCmd(menuRef,iTwentyFour,0x0c);
  329.     SetMenuItemKeyGlyph(menuRef,iTwentyFour,kMenuPageDownGlyph);
  330.  
  331.     // …………………………… programmatically exclude the mark column and set the font in the Special menu
  332.  
  333.     menuRef = GetMenuRef(mSpecial);
  334.     SetMenuExcludesMarkColumn(menuRef,true);
  335.         
  336.     GetFNum("\pGadget",&fontNumber);
  337.     if(fontNumber != 0)
  338.         SetMenuFont(menuRef,fontNumber,12);
  339.         
  340.     // ………………………………………………………………………… if running on Mac OS X, create Help menu and insert one item
  341.  
  342.     if(gRunningOnX)
  343.     {
  344.         HMGetHelpMenu(&menuRef,NULL);
  345.         InsertMenuItem(menuRef,"\pMenus Help",0);
  346.         SetMenuItemCommandID(menuRef,1,'help');
  347.     }
  348.  
  349.     // …………………………………………………………………………………………… set initial font, style, and size, and checkmark them
  350.  
  351.     doCheckStyleMenuItem(mStyleXmnu);
  352.     doCheckStyleMenuItem(mStyleProg);
  353.     doCheckSizeMenuItem(iTen);
  354.  
  355.     // ……………………………………………………………………………………………………………………………………………………………………………………………………… draw menu bar
  356.  
  357.     DrawMenuBar();
  358. }
  359.  
  360. // ********************************************************************************** doEvents
  361.  
  362. void  doEvents(EventRecord *eventStrucPtr)
  363. {
  364.     switch(eventStrucPtr->what)
  365.     {
  366.         case kHighLevelEvent:
  367.             AEProcessAppleEvent(eventStrucPtr);
  368.             break;
  369.  
  370.         case mouseDown:
  371.             doMouseDown(eventStrucPtr);
  372.             break;
  373.  
  374.         case keyDown:
  375.             if((eventStrucPtr->modifiers & cmdKey) != 0)
  376.             {
  377.                 doAdjustMenus();
  378.                 doMenuChoice(MenuEvent(eventStrucPtr));
  379.             }
  380.             break;
  381.  
  382.         case updateEvt:
  383.             BeginUpdate((WindowRef) eventStrucPtr->message);
  384.             EndUpdate((WindowRef) eventStrucPtr->message);
  385.             break;
  386.     }
  387. }
  388.  
  389. // ******************************************************************************* doMouseDown
  390.  
  391. void  doMouseDown(EventRecord *eventStrucPtr)
  392. {
  393.     WindowRef                windowRef;
  394.     WindowPartCode    partCode;
  395.     SInt32                    menuChoice;
  396.  
  397.     partCode = FindWindow(eventStrucPtr->where,&windowRef);
  398.     
  399.     switch(partCode)
  400.     {
  401.         case inMenuBar:
  402.             doAdjustMenus();
  403.             menuChoice = MenuSelect(eventStrucPtr->where);
  404.             doMenuChoice(menuChoice);
  405.             break;
  406.  
  407.         case inContent:
  408.             if(windowRef != FrontWindow())
  409.                 SelectWindow(windowRef);
  410.             break;
  411.  
  412.         case inDrag:
  413.             DragWindow(windowRef,eventStrucPtr->where,NULL);
  414.             break;
  415.  
  416.         case inGoAway:
  417.             if(TrackGoAway(windowRef,eventStrucPtr->where))
  418.                 gDone = true;
  419.             break;
  420.     }
  421. }
  422.  
  423. // ***************************************************************************** doAdjustMenus
  424.  
  425. void  doAdjustMenus(void)
  426. {
  427.     // Adjust menus here.  Use EnableMenuCommand and DisableMenuCommand to enable/disable those
  428.     // menu items with command IDs.
  429. }
  430.  
  431. // ****************************************************************************** doMenuChoice
  432.  
  433. void  doMenuChoice(SInt32 menuChoice)
  434. {
  435.     MenuID                menuID;
  436.     MenuItemIndex    menuItem;
  437.     OSErr                    osErr;
  438.     MenuCommand        commandID;
  439.  
  440.     menuID     = HiWord(menuChoice);
  441.     menuItem = LoWord(menuChoice);
  442.  
  443.     if(menuID == 0)
  444.         return;
  445.     else if(menuID == mFont)
  446.         doFontMenu(menuItem);
  447.     else
  448.     {
  449.         osErr = GetMenuItemCommandID(GetMenuRef(menuID),menuItem,&commandID);
  450.         if(osErr == noErr && commandID != 0)
  451.             doCommand(commandID);
  452.     }
  453.  
  454.     HiliteMenu(0);
  455. }
  456.  
  457. // ********************************************************************************* doCommand
  458.  
  459. void  doCommand(MenuCommand commandID)
  460. {
  461.     MenuRef    menuRef;
  462.  
  463.     switch(commandID)
  464.     {
  465.         // ………………………………………………………………………………………………………………………………………………………………………… Apple/Application menu
  466.  
  467.         case 'abou':                                                                                                                                            // About
  468.             drawItemString("\pAbout Menus2");
  469.             break;
  470.  
  471.         // …………………………………………………………………………………………………………………………………………………………………………………………………………… File menu
  472.  
  473.         case 'quit':                                                                                                                                             // Quit
  474.             gDone = true;
  475.             break;
  476.             
  477.         // …………………………………………………………………………………………………………………………………………………………………………………………………………… Edit menu
  478.  
  479.         case 'undo':                                                                                                                                             // Undo
  480.             drawItemString("\pUndo");
  481.             break;
  482.  
  483.         case 'cut ':                                                                                                                                                // Cut
  484.             drawItemString("\pCut");
  485.             break;
  486.  
  487.         case 'copy':                                                                                                                                             // Copy
  488.             drawItemString("\pCopy");
  489.             break;
  490.  
  491.         case 'past':                                                                                                                                            // Paste
  492.             drawItemString("\pPaste");
  493.             break;
  494.  
  495.         case 'clea':                                                                                                                                            // Clear
  496.             drawItemString("\pClear");
  497.             break;
  498.  
  499.         // ……………………………………………………………………………………………………………… Style ('xmnu') and Style (Programmatic) menu
  500.  
  501.         case 'plai':                                                                                                                                            // Plain
  502.             gCurrentStyle = 0;
  503.             doCheckStyleMenuItem(mStyleXmnu);
  504.             doCheckStyleMenuItem(mStyleProg);
  505.             break;
  506.  
  507.         case 'bold':                                                                                                                                             // Bold
  508.             if(gCurrentStyle & bold)
  509.                 gCurrentStyle -= bold;
  510.             else
  511.                 gCurrentStyle |= bold;
  512.             doCheckStyleMenuItem(mStyleXmnu);
  513.             doCheckStyleMenuItem(mStyleProg);
  514.             break;
  515.  
  516.         case 'ital':                                                                                                                                        // Italics
  517.             if(gCurrentStyle & italic)
  518.                 gCurrentStyle -= italic;
  519.             else
  520.             gCurrentStyle |= italic;
  521.             doCheckStyleMenuItem(mStyleXmnu);
  522.             doCheckStyleMenuItem(mStyleProg);
  523.             break;
  524.  
  525.         case 'unde':                                                                                                                                    // Underline
  526.             if(gCurrentStyle & underline)
  527.                 gCurrentStyle -= underline;
  528.             else
  529.                 gCurrentStyle |= underline;
  530.             doCheckStyleMenuItem(mStyleXmnu);
  531.             doCheckStyleMenuItem(mStyleProg);
  532.             break;
  533.  
  534.         case 'outl':                                                                                                                                        // Outline
  535.             if(gCurrentStyle & outline)
  536.                 gCurrentStyle -= outline;
  537.             else
  538.                 gCurrentStyle |= outline;
  539.             doCheckStyleMenuItem(mStyleXmnu);
  540.             doCheckStyleMenuItem(mStyleProg);
  541.             break;
  542.  
  543.         case 'shad':                                                                                                                                         // Shadow
  544.             if(gCurrentStyle & shadow)
  545.                 gCurrentStyle -= shadow;
  546.             else
  547.                 gCurrentStyle |= shadow;
  548.             doCheckStyleMenuItem(mStyleXmnu);
  549.             doCheckStyleMenuItem(mStyleProg);
  550.             break;
  551.  
  552.         // …………………………………………………………………………………………………………………………………………………………………………………………………………… Size menu
  553.  
  554.         case 'ten ':                                                                                                                                                 // 10
  555.             TextSize(10);
  556.             doCheckSizeMenuItem(iTen);
  557.             break;
  558.  
  559.         case 'twel':                                                                                                                                                 // 12
  560.             TextSize(12);
  561.             doCheckSizeMenuItem(iTwelve);
  562.             break;
  563.  
  564.         case 'eigh':                                                                                                                                                 // 18
  565.             TextSize(18);
  566.             doCheckSizeMenuItem(iEighteen);
  567.             break;
  568.  
  569.         case 'twen':                                                                                                                                                 // 24
  570.             TextSize(24);
  571.             doCheckSizeMenuItem(iTwentyFour);
  572.             break;
  573.                 
  574.         // …………………………………………………………………………………………………………………………………………………………………………………………………… Special menu
  575.     
  576.         case 'firs':                                                                                                                                            // First
  577.             drawItemString("\pFirst Item");
  578.             break;
  579.  
  580.         // ………………………………………………………………………………………………………………………………………………………………………………………………………………… submenu
  581.  
  582.         case 'bat ':                                                                                                                                                // Bat
  583.             menuRef = GetMenuRef(mSubmenu);
  584.             DisableMenuItem(menuRef,iBat);
  585.             EnableMenuItem(menuRef,iBowl);
  586.             drawItemString("\pBat");
  587.             break;
  588.  
  589.         case 'bowl':                                                                                                                                             // Bowl
  590.             menuRef = GetMenuRef(mSubmenu);
  591.             DisableMenuItem(menuRef,iBowl);
  592.             EnableMenuItem(menuRef,iBat);
  593.             drawItemString("\pBowl");
  594.             break;
  595.  
  596.         case 'help':
  597.             AHGotoPage(CFSTR("Menus Help"),CFSTR("Menus.htm"),NULL);
  598.             break;
  599.     }
  600. }
  601.  
  602. // ******************************************************************************** doFontMenu
  603.  
  604. void  doFontMenu(MenuItemIndex menuItem)
  605. {
  606.     MenuRef                menuRef;
  607.     OSStatus            osError;
  608.     FMFontFamily    currentFontFamilyReference;
  609.     FMFontStyle        fontStyle;
  610.     Str255                fontName;
  611.     
  612.     menuRef = GetMenuRef(mFont);
  613.  
  614.     osError = GetFontFamilyFromMenuSelection(menuRef,menuItem,¤tFontFamilyReference,
  615.                         &fontStyle);
  616.  
  617.     if(osError == noErr || osError == menuPropertyNotFoundErr)
  618.     {
  619.         TextFont(currentFontFamilyReference);
  620.  
  621.         CheckMenuItem(menuRef,gCurrentFontMenuItem,false);
  622.         gCurrentFontMenuItem = menuItem;
  623.         CheckMenuItem(menuRef,gCurrentFontMenuItem,true);
  624.  
  625.         GetMenuItemText(menuRef,menuItem,fontName);
  626.         drawItemString(fontName);
  627.     }
  628.     else
  629.         ExitToShell();
  630. }
  631.  
  632. // ********************************************************************** doCheckStyleMenuItem
  633.  
  634. void  doCheckStyleMenuItem(MenuID menuID)
  635. {
  636.     MenuRef                    styleMenuRef;
  637.     static Boolean    stringAlreadyDrawnOnce = false;
  638.  
  639.     styleMenuRef = GetMenuRef(menuID);
  640.  
  641.     CheckMenuItem(styleMenuRef,iPlain,        gCurrentStyle == 0);
  642.     CheckMenuItem(styleMenuRef,iBold,            gCurrentStyle & bold);
  643.     CheckMenuItem(styleMenuRef,iItalic,        gCurrentStyle & italic);
  644.     CheckMenuItem(styleMenuRef,iUnderline,gCurrentStyle & underline);
  645.     CheckMenuItem(styleMenuRef,iOutline,    gCurrentStyle & outline);
  646.     CheckMenuItem(styleMenuRef,iShadow,        gCurrentStyle & shadow);
  647.     
  648.     TextFace(gCurrentStyle);
  649.  
  650.     if(!stringAlreadyDrawnOnce)
  651.         drawItemString("\pStyle change");
  652.  
  653.     stringAlreadyDrawnOnce = !stringAlreadyDrawnOnce;
  654. }
  655.  
  656. // *********************************************************************** doCheckSizeMenuItem
  657.  
  658. void  doCheckSizeMenuItem(MenuItemIndex menuItem)
  659. {    
  660.     MenuRef    sizeMenuRef;    
  661.  
  662.     sizeMenuRef = GetMenuRef(mSize);
  663.  
  664.     CheckMenuItem(sizeMenuRef,gCurrentSizeMenuItem,false);
  665.     CheckMenuItem(sizeMenuRef,menuItem,true);
  666.     
  667.     gCurrentSizeMenuItem = menuItem;
  668.     
  669.     drawItemString("\pSize change");
  670. }
  671.  
  672. // **************************************************************************** drawItemString
  673.  
  674. void  drawItemString(Str255 eventString)
  675. {
  676.     RgnHandle    tempRegion;
  677.     WindowRef    windowRef;
  678.     Rect            scrollBox;
  679.     
  680.     windowRef = FrontWindow();
  681.     tempRegion = NewRgn();
  682.  
  683.     GetWindowPortBounds(windowRef,&scrollBox);
  684.  
  685.     ScrollRect(&scrollBox,0,-30,tempRegion);
  686.     DisposeRgn(tempRegion);
  687.     
  688.     MoveTo(8,286);
  689.     DrawString(eventString);
  690. }
  691.  
  692. // *******************************************************************************************
  693.  
  694.  
  695.