home *** CD-ROM | disk | FTP | other *** search
- /* GadTools layout toolkit
- **
- ** Copyright © 1993-1995 by Olaf `Olsen' Barthel
- ** Freely distributable.
- **
- ** :ts=4
- */
-
- #include "gtlayout_global.h"
-
- #ifdef DO_MENUS
-
- /* LT_FindMenuCommand(struct Menu *Menu,UWORD MsgCode,UWORD MsgQualifier,struct Gadget *MsgGadget):
- *
- * Find the menu a key command is associated with; this includes only commands
- * Intuition does not process by itself.
- */
-
- struct MenuItem * LIBENT
- LT_FindMenuCommand(REG(a0) struct Menu *Menu,REG(d0) UWORD MsgCode,REG(d1) UWORD MsgQualifier,REG(a1) struct Gadget *MsgGadget)
- {
- if(!Menu)
- return(NULL);
-
- // Only take care of downstrokes
-
- if(!(MsgCode & IECODE_UP_PREFIX))
- {
- RootMenu *Root = (RootMenu *)((ULONG)Menu - offsetof(RootMenu,Menu));
- ItemNode *Item;
- struct InputEvent Event;
- UBYTE ANSIKey[10];
- ULONG Qualifier;
-
- // Fix up the MsgQualifier
-
- if(MsgQualifier & QUALIFIER_SHIFT)
- MsgQualifier = (MsgQualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
-
- if(MsgQualifier & QUALIFIER_ALT)
- MsgQualifier = (MsgQualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
-
- // Convert the key
-
- ANSIKey[0] = 0;
-
- Event . ie_NextEvent = NULL;
- Event . ie_Class = IECLASS_RAWKEY;
- Event . ie_SubClass = 0;
- Event . ie_Code = MsgCode;
- Event . ie_Qualifier = MsgQualifier;
- Event . ie_EventAddress = (APTR)MsgGadget;
-
- if(!MapRawKey(&Event,ANSIKey,9,NULL))
- ANSIKey[0] = 0;
-
- // Run down the list...
-
- for(Item = (ItemNode *)Root -> ItemList . mlh_Head ; Item -> Node . mln_Succ ; Item = (ItemNode *)Item -> Node . mln_Succ)
- {
- // See if we can do with the char
-
- if(Item -> Char)
- {
- if(Item -> Char == ANSIKey[0])
- return(&Item -> Item);
- }
- else
- {
- // So that didn't work, what about the raw data?
-
- Qualifier = Item -> Qualifier;
-
- if(Qualifier & QUALIFIER_SHIFT)
- Qualifier = (Qualifier & ~QUALIFIER_SHIFT) | IEQUALIFIER_LSHIFT;
-
- if(Qualifier & QUALIFIER_ALT)
- Qualifier = (Qualifier & ~QUALIFIER_ALT) | IEQUALIFIER_LALT;
-
- if(Item -> Code == MsgCode && (MsgQualifier & Qualifier) == Qualifier)
- return(&Item -> Item);
- }
- }
- }
-
- return(NULL);
- }
-
- #endif /* DO_MENUS */
-