home *** CD-ROM | disk | FTP | other *** search
/ Workbench Add-On / Workbench Add-On - Volume 1.iso / BBS-Archive / Comm / term-source.lha / Extras / Source / gtlayout-Source.lha / LT_FindMenuCommand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-26  |  2.1 KB  |  87 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. **
  6. **  :ts=4
  7. */
  8.  
  9. #include "gtlayout_global.h"
  10.  
  11. #ifdef DO_MENUS
  12.  
  13.     /* LT_FindMenuCommand(struct Menu *Menu,UWORD MsgCode,UWORD MsgQualifier,struct Gadget *MsgGadget):
  14.      *
  15.      *    Find the menu a key command is associated with; this includes only commands
  16.      *    Intuition does not process by itself.
  17.      */
  18.  
  19. struct MenuItem * LIBENT
  20. LT_FindMenuCommand(REG(a0) struct Menu *Menu,REG(d0) UWORD MsgCode,REG(d1) UWORD MsgQualifier,REG(a1) struct Gadget *MsgGadget)
  21. {
  22.         // Only take care of downstrokes
  23.  
  24.     if(!(MsgCode & IECODE_UP_PREFIX))
  25.     {
  26.         RootMenu            *Root = (RootMenu *)((ULONG)Menu - offsetof(RootMenu,Menu));
  27.         ItemNode            *Item;
  28.         struct InputEvent     Event;
  29.         UBYTE                 ANSIKey[10];
  30.         ULONG                 Qualifier;
  31.  
  32.             // Fix up the MsgQualifier
  33.  
  34.         if(MsgQualifier & QUALIFIER_SHIFT)
  35.             MsgQualifier = (MsgQualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
  36.  
  37.         if(MsgQualifier & QUALIFIER_ALT)
  38.             MsgQualifier = (MsgQualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
  39.  
  40.             // Convert the key
  41.  
  42.         ANSIKey[0] = 0;
  43.  
  44.         Event . ie_NextEvent    = NULL;
  45.         Event . ie_Class        = IECLASS_RAWKEY;
  46.         Event . ie_SubClass        = 0;
  47.         Event . ie_Code            = MsgCode;
  48.         Event . ie_Qualifier    = MsgQualifier;
  49.         Event . ie_EventAddress    = (APTR)MsgGadget;
  50.  
  51.         if(!MapRawKey(&Event,ANSIKey,9,NULL))
  52.             ANSIKey[0] = 0;
  53.  
  54.             // Run down the list...
  55.  
  56.         for(Item = (ItemNode *)Root -> ItemList . mlh_Head ; Item -> Node . mln_Succ ; Item = (ItemNode *)Item -> Node . mln_Succ)
  57.         {
  58.                 // See if we can do with the char
  59.  
  60.             if(Item -> Char)
  61.             {
  62.                 if(Item -> Char == ANSIKey[0])
  63.                     return(&Item -> Item);
  64.             }
  65.             else
  66.             {
  67.                     // So that didn't work, what about the raw data
  68.  
  69.                 Qualifier = Item -> Qualifier;
  70.  
  71.                 if(Qualifier & QUALIFIER_SHIFT)
  72.                     Qualifier = (Qualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
  73.  
  74.                 if(Qualifier & QUALIFIER_ALT)
  75.                     Qualifier = (Qualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
  76.  
  77.                 if(Item -> Code == MsgCode && (MsgQualifier & Qualifier) == Qualifier)
  78.                     return(&Item -> Item);
  79.             }
  80.         }
  81.     }
  82.  
  83.     return(NULL);
  84. }
  85.  
  86. #endif    /* DO_MENUS */
  87.