home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / windows / x / motif / 5876 < prev    next >
Encoding:
Text File  |  1992-08-27  |  2.8 KB  |  79 lines

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!eagle.smec.Sony.COM!dave
  2. From: dave@eagle.smec.Sony.COM (David Jarrin)
  3. Newsgroups: comp.windows.x.motif
  4. Subject: RE: Key events (translations) on SUN... (Unocal Corporation)
  5. Message-ID: <9208271839.AA04075@eagle.smec.sony.com>
  6. Date: 27 Aug 92 18:39:23 GMT
  7. Sender: daemon@ucbvax.BERKELEY.EDU
  8. Distribution: inet
  9. Organization: The Internet
  10. Lines: 67
  11.  
  12.  
  13. Hello!
  14.  
  15. This is in reply to your question about translations. It took me a while
  16. to figure out how to get it to work right.
  17.  
  18. The following is an example of how I do it:
  19.  
  20. /*******************************************************************/
  21. #include <Xm/Xm.h>
  22.  
  23. void quit(); /* code defined somewhere */
  24. void doit(); /* code defined somewhere */
  25.  
  26. void
  27. setup_translations()
  28. {
  29.     XtTranslations trans_table;
  30.     Arg args[5];
  31.     int argcnt;
  32.  
  33.     static XtActionsRec myActions[] = {{"doit", doit},
  34.                                        {"quit", quit},};
  35.  
  36.     static char defaultTranslations[] = "Ctrl<Key>P: doit()\n\
  37.                                          Ctrl<Key>Q: quit()";
  38.  
  39.     /* Add the above translations to the default translation table */
  40.     XtAppAddActions(context, myActions, XtNumber(myActions));
  41.     trans_table = XtParseTranslationTable(defaultTranslations);
  42.  
  43.  
  44.     /* Now, add all translations to your Widgets */
  45.     /* NOTE: Make sure the wigdet names are accessible by this routine. */
  46.  
  47.     /* For container Widgets use something like this to enable your */
  48.     /* translations within the specified container. */
  49.     /********************************************************************/
  50.     argcnt = 0;
  51.     XtSetArg(args[argcnt], XmNtranslations, trans_table); argcnt++;
  52.     XtSetValues(containerWidget, args, argcnt);
  53.     /********************************************************************/
  54.  
  55.     /* For NON-container Widgets such as pushButtons, text fields, etc. */
  56.     /********************************************************************/
  57.     XtAugmentTranslations(buttonWidget1, trans_table);
  58.     XtAugmentTranslations(buttonWidget2, trans_table);
  59.     XtAugmentTranslations(textWidget, trans_table);
  60.     /********************************************************************/
  61. }
  62. /*******************************************************************/
  63.  
  64. You can call your "setup_translations()" routine just before you close your
  65. main application loop.
  66. Note that by pressing "Ctrl-p" the routine "doit()" is called. If, for
  67. example, "doit()" happens to be the "activateCallback" for a particular button,
  68. you will NOT "see" that button get armed, but "doit()" will still be called.
  69. If you want the button to give some kind of indication that its callback 
  70. was activated, you will have to do some additional coding (probably within
  71. "doit()") to do so (e.g. change button colors).
  72.  
  73. I hope this helps you some.
  74.  
  75. Good luck!!
  76.  
  77. David Jarrin
  78. dave@smec.sony.com
  79.