home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!eagle.smec.Sony.COM!dave
- From: dave@eagle.smec.Sony.COM (David Jarrin)
- Newsgroups: comp.windows.x.motif
- Subject: RE: Key events (translations) on SUN... (Unocal Corporation)
- Message-ID: <9208271839.AA04075@eagle.smec.sony.com>
- Date: 27 Aug 92 18:39:23 GMT
- Sender: daemon@ucbvax.BERKELEY.EDU
- Distribution: inet
- Organization: The Internet
- Lines: 67
-
-
- Hello!
-
- This is in reply to your question about translations. It took me a while
- to figure out how to get it to work right.
-
- The following is an example of how I do it:
-
- /*******************************************************************/
- #include <Xm/Xm.h>
-
- void quit(); /* code defined somewhere */
- void doit(); /* code defined somewhere */
-
- void
- setup_translations()
- {
- XtTranslations trans_table;
- Arg args[5];
- int argcnt;
-
- static XtActionsRec myActions[] = {{"doit", doit},
- {"quit", quit},};
-
- static char defaultTranslations[] = "Ctrl<Key>P: doit()\n\
- Ctrl<Key>Q: quit()";
-
- /* Add the above translations to the default translation table */
- XtAppAddActions(context, myActions, XtNumber(myActions));
- trans_table = XtParseTranslationTable(defaultTranslations);
-
-
- /* Now, add all translations to your Widgets */
- /* NOTE: Make sure the wigdet names are accessible by this routine. */
-
- /* For container Widgets use something like this to enable your */
- /* translations within the specified container. */
- /********************************************************************/
- argcnt = 0;
- XtSetArg(args[argcnt], XmNtranslations, trans_table); argcnt++;
- XtSetValues(containerWidget, args, argcnt);
- /********************************************************************/
-
- /* For NON-container Widgets such as pushButtons, text fields, etc. */
- /********************************************************************/
- XtAugmentTranslations(buttonWidget1, trans_table);
- XtAugmentTranslations(buttonWidget2, trans_table);
- XtAugmentTranslations(textWidget, trans_table);
- /********************************************************************/
- }
- /*******************************************************************/
-
- You can call your "setup_translations()" routine just before you close your
- main application loop.
- Note that by pressing "Ctrl-p" the routine "doit()" is called. If, for
- example, "doit()" happens to be the "activateCallback" for a particular button,
- you will NOT "see" that button get armed, but "doit()" will still be called.
- If you want the button to give some kind of indication that its callback
- was activated, you will have to do some additional coding (probably within
- "doit()") to do so (e.g. change button colors).
-
- I hope this helps you some.
-
- Good luck!!
-
- David Jarrin
- dave@smec.sony.com
-