home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / wp_dtp / xdme1820.lha / XDME / keycontrol.c < prev    next >
C/C++ Source or Header  |  1993-03-09  |  7KB  |  277 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     keycontrol.c
  5.  
  6.     DESCRIPTION
  7.     interface for keyboard control from main
  8.     Handle keyboard related stuff such as keyboard mappings. Every
  9.     time a key is pressed, KEYCTL() is called with the code. KEYCTL()
  10.     remembers which qualifier keys are currently held down, and when a
  11.     non-qualifier key is pressed finds the hash entry for the key.    If
  12.     no hash entry exists (e.g. you type a normal 'a') the default
  13.     keymap is used.
  14.  
  15.     NOTES
  16.     Amiga-specific & [X]DME-specific
  17.     depends on macro-language
  18.  
  19.     BUGS
  20.  
  21.     TODO
  22.     we might enable deadkeys on our own - shall we do this ?
  23.         that would be done with a command redefining a
  24.         variable that is used instead of NO_KEYS_PRESSED
  25.  
  26.     EXAMPLES
  27.  
  28.     SEE ALSO
  29.  
  30.     INDEX
  31.  
  32.     HISTORY
  33.     15-Dez-92  b_null created
  34.     16-Dez-92  b_null documented
  35.  
  36. ******************************************************************************/
  37.  
  38. /**************************************
  39.         Includes
  40. **************************************/
  41. #include "defs.h"
  42.  
  43.  
  44. /**************************************
  45.         Globale Variable
  46. **************************************/
  47. Prototype void keyctl (struct IntuiMessage *, int, ULONG);  /* PATCH_NULL [14 Feb 1993] : changed to void */
  48.  
  49.  
  50. /**************************************
  51.       Interne Defines & Strukturen
  52. **************************************/
  53. #define NO_KEYS_PRESSED 0x00000000  /* we might write 0C0? for accents */
  54.  
  55. /* some hardcoded keys on Amiga Keyboard - look also in keycodes */
  56. #define CSPC  0x40
  57. #define CB_S  0x41 /* always ? */
  58. #define CENT  0x43
  59. #define CRET  0x44
  60.  
  61.  
  62. /**************************************
  63.         Interne Variable
  64. **************************************/
  65. /* nothing */
  66.  
  67. /**************************************
  68.        Interne Prototypes
  69. **************************************/
  70.  
  71.  
  72. /*****************************************************************************
  73.  
  74.     NAME
  75.     keyctl
  76.  
  77.     PARAMETER
  78.     struct IntuiMessage *    im
  79.     int            code
  80.     ULONG            qual
  81.  
  82.     RESULT
  83.     -/-
  84.  
  85.     RETURN
  86.     void
  87.  
  88.     DESCRIPTION
  89.     reaction on a key-information
  90.  
  91.     NOTES
  92.  
  93.     BUGS
  94.  
  95.     EXAMPLES
  96.  
  97.     SEE ALSO
  98.  
  99.     INTERNALS
  100.     erzeuge die mit der msg verbundenen keycodes
  101.     und qualifiers
  102.     suche dann nach einer map dafuer
  103.     falls es keine gab, benutze wenn moeglich die
  104.     system-belegung als macro
  105.  
  106.     HISTORY
  107.     15-Dez-92  b_null moved here & modified
  108.     16.Dez.92  b_null documented
  109.     28.Dez.92  b_null added support for NO dead-keys
  110.  
  111. ******************************************************************************/
  112.  
  113. void keyctl (struct IntuiMessage * im, int code, ULONG qual)
  114. {
  115. /* PATCH_DEAD 28-Dez-92 : this is the boolean flag for disabling Deadkeys */
  116.     static  short  last_displayed = 0;
  117. /* PATCH_DEAD 28-Dez-92 */
  118.         ubyte  buf[LINE_LENGTH];
  119.         ushort c2;
  120.         short  blen = 0;
  121.         int    ext2;
  122.  
  123.     code &= 0xFF;            /* shorten code to one byte */
  124.  
  125. /* printf ("lastdisplayed %d\n", last_displayed); */
  126.  
  127.  
  128. #ifdef PATCH_FILTER
  129. /*
  130. **  --- Before executing the keystroke,
  131. **    check if a filter is active and if the key can pass the filter
  132. */
  133.     if ((key_filter != 0) && (filter_key (code) != 0)) {
  134.     return;
  135.     } /* if */
  136. #endif /* PATCH_FILTER */
  137.  
  138.  
  139. /*
  140. **  --- Before evaluating the key's Qualifiers,
  141. **    append the extended Qualifiers to the pressed ones
  142. */
  143.     ext2 =  ext_qualifiers;
  144.     qual = (qual & 0xF000FFFF) | ext2;
  145.  
  146.     if (im) {
  147.     ushort oldQual = im->Qualifier;
  148.  
  149. /* printf ("iaddr %08lx->%08lx code/qual %04x/%04x\n", im->IAddress, *((long*)im->IAddress), im->Code, im->Qualifier); */
  150.  
  151. /* PATCH_DEAD 28-Dez-92 : if necessary hide the last pressed keys */
  152.     long  dummy_prev[1];
  153.     long * inter_iaddr = im->IAddress;
  154.     if (last_displayed) {
  155.         dummy_prev[0]  = NO_KEYS_PRESSED;
  156.         im->IAddress   = dummy_prev;
  157.         if (!(code & 0x80)) {   /* PATCH_NULL [14 Feb 1993] : added to come around with additional msges for -UP keys */
  158.         last_displayed = 0;
  159.         } /* if no up-msg */
  160.      /* last_displayed = 0; */
  161.     } /* if */
  162. /* PATCH_DEAD 28-Dez-92 */
  163.  
  164.     im->Qualifier = (oldQual & ~IEQUALIFIER_REPEAT) | (0xFFFF & ext2);  /* == ... & 0xF000FFFF | ext2 -> === qual ohne extended */
  165.  
  166.     blen = DeadKeyConvert (im, buf+1, 254, NULL);
  167.     im->Qualifier = oldQual;
  168.  
  169. /* PATCH_DEAD 28-Dez-92: restore the old value */
  170.     im->IAddress = inter_iaddr;
  171. /* PATCH_DEAD 28-Dez-92 */
  172.  
  173.     if (blen < 0) {
  174.         return;
  175.     }
  176.     }
  177.     ext_qualifiers = 0;
  178.  
  179.     c2 = iqual2qual (qual, blen, buf, code);
  180.     code &= 0x7f;                /* Remove the up/down information AFTER iqual2qual */
  181.  
  182.     {
  183.     HASH * hash;
  184.  
  185. /* PATCH_NULL [13 Jan 1993] : the following construct was added for [X]DME only to allow deletion on returnoverride */
  186. #    ifdef NOT_DEF
  187.         /* that long version disables not only return but also backspace and space */
  188.         if (globalflags.Comlinemode && c2 == 0)
  189.         {
  190.         char * str = NULL;
  191.         switch (code) {
  192.         case CRET: str = "return";  break;
  193.         case CSPC: str = "( )";     break;
  194.         case CB_S: str = "bs";      break;
  195.         } /* switch */
  196.         if (str) {
  197.             last_displayed = 1;
  198.             strcpy (buf, str);
  199.             do_command (buf);   /* PATCH_NULL [14 Feb 1993] : added */
  200.             return;
  201.         } /* if */
  202.         } /* if comline without quals */
  203. #    else
  204.         /* that short version only disables return */
  205.         if (globalflags.Comlinemode && code == CRET && c2 == 0) {
  206.         last_displayed = 1;
  207.         strcpy (buf, "return");
  208.         do_command (buf);       /* PATCH_NULL [14 Feb 1993] : added */
  209.         return;
  210.         } /* if */
  211. #    endif
  212. /* PATCH_NULL [13 Jan 1993] */
  213.  
  214.     hash = findhash (currenthash(), code, c2);
  215.  
  216.     /*
  217.      *  Use hash entry only if not in command line mode, or if the
  218.      *  entry does not correspond to an alpha key.
  219.      */
  220.  
  221.     if (hash) {
  222.         /*
  223.          * found hash-entry
  224.          * only use it, if we are not in commandline-mode
  225.          * or (if in comlinemode:) if a qualifier was pressed
  226.          *                   or it is a non-alphanum
  227.          */
  228.         if (c2 || !globalflags.Comlinemode || blen > 1 || !CtoA(code)) {
  229. /* PATCH_DEAD 28-Dez-92 : enable hiding of the last pressed keys */
  230.         if (im) {
  231.             last_displayed = 1;
  232.         } /* if key from a message */
  233. /* PATCH_DEAD 28-Dez-92 */
  234.         strcpy (buf, hash->comm);
  235.         do_command (buf);   /* PATCH_NULL [14 Feb 1993] : added */
  236.         return;
  237.         } /* if  */
  238.     }
  239.     }
  240.  
  241.     /*
  242.      *    No hash entry
  243.      */
  244.  
  245.     if (blen) {
  246.     /*
  247.      *  try to create a macro if we had a result on DeadKeyConvert
  248.      */
  249.     if (blen == 1) {
  250.         buf[0] = '\'';  /* This *MUST* be ' !!!! */
  251.         buf[2] = 0;
  252.     } else {
  253.         buf[0] = '`';
  254.         buf[blen+1] = '\'';
  255.     }
  256. //      last_displayed = 1;  /* PATCH_DEAD 28-Dez-92 : it might be senseful to put it here, too ... */
  257.                    /* PATCH_DEAD 14-Jan-93 : ... but normally active keys are no deadkeys */
  258.     do_command (buf);       /* PATCH_NULL [14 Feb 1993] : added */
  259.     return;
  260. /*
  261. **  --- if there was no real reaction on that key
  262. **    restore the extended Qualifiers
  263. */
  264.     } else {
  265.     ext_qualifiers = ext2; /* keep the qualifiers */
  266. /* printf("nothing found w/ code %d,%d\n", code, c2); */
  267.     } /* if (no) string from DeadKeyConvert */
  268.  
  269. } /* keyctl */
  270.  
  271.  
  272.  
  273.  
  274. /******************************************************************************
  275. *****  ENDE keycontrol.c
  276. ******************************************************************************/
  277.