home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / BSP Tree 1.2 / Sources / Core / source / menu.cp < prev    next >
Encoding:
Text File  |  1995-03-19  |  6.0 KB  |  99 lines  |  [TEXT/MMCC]

  1. //------------------------------------------------------------------------------
  2. //    File:                    menu.cp
  3. //    Date:                    7/18/94
  4. //    Author:                Bretton Wade
  5. //
  6. //    Description:    this file contains definitions related to menu handling
  7. //
  8. //------------------------------------------------------------------------------
  9.  
  10. #include "event.h"
  11. #include "menu.h"
  12. #include "apple event.h"
  13. #include "window.h"
  14.  
  15. //------------------------------------------------------------------------------
  16. //    Handle Apple Menu About Event
  17. //------------------------------------------------------------------------------
  18. pascal OSErr    HandleAboutItemEvent (AppleEvent*, AppleEvent*, long)                            //    handle a menu selection of the about item
  19. {                                                                                                                                                                //    begin
  20.     Handle    version = GetResource ('vers', 1);                                                                        //    get the version resource
  21.     HLock (version);                                                                                                                            //    lock the handle
  22.     ParamText (pstr (&(*version)[6]), 0, 0, 0);                                                                        //    set up the parameter strings for the about box
  23.     HUnlock (version);                                                                                                                        //    unlock the handle
  24.     ReleaseResource (version);                                                                                                        //    release the version resource
  25.     Alert (256, NULL);                                                                                                                        //    Open the alert that is the about box
  26.     ResetAlrtStage ();                                                                                                                        //    no more beeps...
  27.     return noErr;                                                                                                                                    //    return with no error
  28. }                                                                                                                                                                //    end
  29.  
  30. //------------------------------------------------------------------------------
  31. //    Handle all other apple menu events
  32. //------------------------------------------------------------------------------
  33. pascal OSErr    HandleAppleMenuEvent (AppleEvent *AE, AppleEvent*, long)                    //    generic routine for handling apple menu events
  34. {                                                                                                                                                                //    begin
  35.     AEDesc    item;                                                                                                                                    //    data description
  36.     if (AEGetAttributeDesc (AE, keyEventIDAttr, typeWildCard, &item) == noErr)        //    if the description is retrieved without an error
  37.     {                                                                                                                                                            //    begin
  38.         Str255    DAName;                                                                                                                            //    place to get the name of the selected item
  39.         short    itemNum = *(ulong *) *(item.dataHandle);                                                            //    get the item number from the event
  40.         MenuHandle myAppleMenu = GetMHandle (kAppleMenu);                                                        //    get the menu handle
  41.         GetItem (myAppleMenu, itemNum, DAName);                                                                            //    get the name of the item selected
  42.         OpenDeskAcc (DAName);                                                                                                                //    open the item
  43.         AEDisposeDesc (&item);                                                                                                            //    release the memory associated with the descriptor
  44.     }                                                                                                                                                            //    end
  45.     return noErr;                                                                                                                                    //    return with no error
  46. }                                                                                                                                                                //    end
  47.  
  48. //------------------------------------------------------------------------------
  49. //    Handle File Menu Quit Event
  50. //------------------------------------------------------------------------------
  51. pascal OSErr    HandleQuitItemEvent (AppleEvent*, AppleEvent*, long)                            //    handle a menu selection of the about item
  52. {                                                                                                                                                                //    begin
  53.     if (CloseAllWindows ())                                                                                                                //    attempt to close all of the windows
  54.         gFinished = TRUE;                                                                                                                        //    say finished true
  55.     return noErr;                                                                                                                                    //    return with no error
  56. }                                                                                                                                                                //    end
  57.  
  58. //------------------------------------------------------------------------------
  59. //    Init Menus
  60. //------------------------------------------------------------------------------
  61. void    InitAppMenus (void)                                                                                                                //    set up the menu bar
  62. {                                                                                                                                                                //    begin
  63.     Handle    menuBar = GetNewMBar (128);                                                                                        //    get the 'MBAR' resource
  64.     SetMenuBar (menuBar);                                                                                                                    //    use it
  65.     DisposeHandle (menuBar);                                                                                                            //    get rid of the handle since we are done with it
  66.     AddResMenu (GetMHandle (kAppleMenu), 'DRVR');                                                                    //    add all the desk accesories and stuff to the apple menu
  67.     DrawMenuBar ();                                                                                                                                //    draw the new menu bar
  68.     //    apple menu item handlers
  69.     AEInstallEventHandler (kAppleMenu, kAboutItemEvent, NewAEEventHandlerProc(HandleAboutItemEvent), 0, FALSE);                                        
  70.     AEInstallEventHandler (kAppleMenu, typeWildCard, NewAEEventHandlerProc(HandleAppleMenuEvent), 0, FALSE);                                        
  71.     //    file menu item handlers
  72.     AEInstallEventHandler (kFileMenu, kQuitItemEvent, NewAEEventHandlerProc(HandleQuitItemEvent), 0, FALSE);                                        
  73. }                                                                                                                                                                //    end
  74.  
  75. //------------------------------------------------------------------------------
  76. //    Handle Menu event
  77. //------------------------------------------------------------------------------
  78. bool    HandleMenu (long code)                                                                                                        //    handle a menu event
  79. {                                                                                                                                                                //    begin
  80.     bool    handled = FALSE;                                                                                                                //    flag to indicate whether or not the event was handled
  81.     ulong    menu = hiword (code);                                                                                                        //    the menu code
  82.     if (menu)                                                                                                                                            //    if it is a valid menu
  83.     {                                                                                                                                                            //    begin
  84.         SendToMyself (menu, loword (code));                                                                                    //    do the appropriately mapped menu action
  85.         handled = TRUE;                                                                                                                            //    set the handled flag to true
  86.     }                                                                                                                                                            //    end
  87.     HiliteMenu (0);                                                                                                                                //    turn off the menu hiliting
  88.     return handled;                                                                                                                                //    return whether or not the event was handled
  89. }                                                                                                                                                                //    end
  90.  
  91. //------------------------------------------------------------------------------
  92. //    Adjust Menus
  93. //------------------------------------------------------------------------------
  94. void    AdjustMenus (void)                                                                                                                //    adjust the menus for processing
  95. {                                                                                                                                                                //    begin
  96. }                                                                                                                                                                //    end
  97. //------------------------------------------------------------------------------
  98.  
  99.