home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d570 / view.lha / View / event.c < prev    next >
C/C++ Source or Header  |  1991-11-21  |  14KB  |  430 lines

  1. /*-- AutoRev header do NOT edit!
  2. *
  3. *   Program         :   event.c
  4. *   Copyright       :   © 1991 Jaba Development
  5. *   Author          :   Jan van den Baard
  6. *   Creation Date   :   21-Apr-91
  7. *   Current version :   1.5
  8. *   Translator      :   DICE v2.6
  9. *
  10. *   REVISION HISTORY
  11. *
  12. *   Date          Version         Comment
  13. *   ---------     -------         ------------------------------------------
  14. *   18-Sep-91     1.5             Removed SteadyRepeat() routine.
  15. *   17-Sep-91     1.5             See main.c!
  16. *   16-Sep-91     1.4             See main.c!
  17. *   23-Aug-91     1.3             See main.c!
  18. *   12-Aug-91     1.2             See main.c!
  19. *   03-Jul-91     1.1             See main.c!
  20. *   21-Apr-91     1.0             View keyboard event-handler + subs.
  21. *
  22. *-- REV_END --*/
  23.  
  24. #include "view.h"
  25.  
  26. /*
  27.  * All kinds of qualifier-key combinations.
  28.  */
  29. #define MOUSE           IEQUALIFIER_RELATIVEMOUSE
  30. #define REPEAT          IEQUALIFIER_REPEAT
  31. #define LOCK            IEQUALIFIER_CAPSLOCK
  32. #define NUMPAD          IEQUALIFIER_NUMERICPAD
  33. #define LSHIFT          IEQUALIFIER_LSHIFT
  34. #define RSHIFT          IEQUALIFIER_RSHIFT
  35. #define CONTROL         IEQUALIFIER_CONTROL
  36. #define ALT             IEQUALIFIER_LALT
  37.  
  38. #define NORM1           MOUSE
  39. #define NORM2           NORM1+REPEAT
  40. #define NORM3           NORM1+LOCK
  41. #define NORM4           NORM2+LOCK
  42.  
  43. #define LALT1           MOUSE+ALT
  44. #define LALT2           LALT1+REPEAT
  45. #define LALT3           LALT1+LOCK
  46. #define LALT4           LALT2+LOCK
  47.  
  48. #define NUMP1           MOUSE+NUMPAD
  49. #define NUMP2           NUMP1+REPEAT
  50. #define NUMP3           NUMP1+LOCK
  51. #define NUMP4           NUMP2+LOCK
  52.  
  53. #define CTRL1           MOUSE+CONTROL
  54. #define CTRL2           CTRL1+REPEAT
  55. #define CTRL3           CTRL1+LOCK
  56. #define CTRL4           CTRL2+LOCK
  57.  
  58. #define PRIN1           CTRL1+LSHIFT
  59. #define PRIN2           CTRL3+LSHIFT
  60.  
  61. #define SHIF1           MOUSE+LSHIFT
  62. #define SHIF2           MOUSE+RSHIFT
  63. #define SHIF3           SHIF1+REPEAT
  64. #define SHIF4           SHIF2+REPEAT
  65. #define SHIF5           SHIF1+LOCK
  66. #define SHIF6           SHIF2+LOCK
  67. #define SHIF7           SHIF3+LOCK
  68. #define SHIF8           SHIF4+LOCK
  69.  
  70. /*
  71.  * hot-keys to be pressed together with LALT+LAMIGA
  72.  * when view is taking a nap.
  73.  */
  74. #define VIEW            0x34
  75. #define QUIT            0x10
  76. #define FLUSH           0x23
  77.  
  78. /*
  79.  * some external referenced globals.
  80.  */
  81. extern APTR           ConsoleDevice;
  82. extern ULONG          VW_class;
  83. extern UWORD          VW_qual, VW_code, VW_pmark;
  84. extern UWORD          VW_mode, VW_pmode, VW_printing, VW_err;
  85. extern UBYTE          ClearStr[];
  86. extern struct Screen *VW_scr;
  87. extern BOOL           VW_found;
  88.  
  89. /*
  90.  * some external referenced function proto-types.
  91.  */
  92. extern void Quit( long );
  93. extern void Inform( char *);
  94. extern void LineUp( void );
  95. extern void LineDown( void );
  96. extern void DisplayText( void );
  97. extern void Top( void );
  98. extern void Bottom( void );
  99. extern void PageUp( void );
  100. extern void PageDown( void );
  101. extern void LoadFile( long );
  102. extern void Help( void );
  103. extern void DoFound( void );
  104. extern void GetSomething( ULONG );
  105. extern void FindN( void );
  106. extern void FindP( void );
  107. extern void PrintFile( void );
  108. extern void InfoLine( void );
  109. extern void EditFile( void );
  110. extern void SetMark( UWORD );
  111. extern void UnSetMark( UWORD );
  112. extern void JumpMark( UWORD );
  113. extern void SaveBlock( WORD );
  114. extern void EditLine( void );
  115. extern void CloseDisplay( void );
  116.  
  117. /*
  118.  * some local proto-types.
  119.  */
  120. void ConvertKeyTab( void );
  121. void HandleKeyboard( UWORD, UWORD );
  122. long HandleMsg( struct MsgPort * );
  123. void ClearMsg( struct MsgPort * );
  124.  
  125. /*
  126.  * Vanilla key-codes normal and shifted.
  127.  */
  128. UBYTE   KeyTable[64];
  129. UBYTE   SKeyTable[64];
  130.  
  131. /*
  132.  * Setup a key-table for normal and shifted key codes so
  133.  * View will work with all kinds of foreigh key-mappings.
  134.  */
  135. void ConvertKeyTab()
  136. {
  137.     struct InputEvent ievent;
  138.     UWORD i;
  139.  
  140.     setmem(&ievent,sizeof(struct InputEvent),0);
  141.  
  142.     ievent.ie_Class = IECLASS_RAWKEY;
  143.  
  144.     for(i=0;i<64;i++) {     /* build normal key-table */
  145.         ievent.ie_Code = i;
  146.         RawKeyConvert(&ievent,&KeyTable[i],1,NULL);
  147.     }
  148.  
  149.     ievent.ie_Qualifier = LSHIFT;
  150.  
  151.     for(i=0;i<64;i++) {     /* build shifted key-table */
  152.         ievent.ie_Code = i;
  153.         RawKeyConvert(&ievent,&SKeyTable[i],1,NULL);
  154.     }
  155. }
  156.  
  157. /*
  158.  * Get and interpred a message from the port.
  159.  * return TRUE if there was a message received
  160.  * or FALSE if not.
  161.  */
  162. long HandleMsg( struct MsgPort *port )
  163. {
  164.     struct IntuiMessage *msg;
  165.  
  166.     if((msg = GT_GetIMsg(port))) { /* gotten a message! */
  167.         VW_class = msg->Class;
  168.         VW_code  = msg->Code;
  169.         VW_qual  = msg->Qualifier;
  170.         GT_ReplyIMsg(msg);         /* gadtools is open so why not... */
  171.         return TRUE;
  172.     }
  173.     return FALSE;
  174. }
  175.  
  176. /*
  177.  * Reply all pending messages on the msgport
  178.  * without doing something with them.
  179.  */
  180. void ClearMsg( struct MsgPort *port )
  181. {
  182.     struct IntuiMessage *msg;
  183.  
  184.     Forbid(); /* don't race intuition. */
  185.     while(msg = GT_GetIMsg(port)) GT_ReplyIMsg(msg);
  186.     Permit();
  187. }
  188.  
  189. extern struct AsciiText *VW_text;
  190.  
  191. /*
  192.  * Handle all incoming RAWKEY messages.
  193.  */
  194. void HandleKeyboard( code, qualifier )
  195.     UWORD           code, qualifier;
  196. {
  197.     if((code & IECODE_UP_PREFIX) != IECODE_UP_PREFIX) { /* only key-down */
  198.         if(VW_err)  InfoLine(); /* refresh info line if needed */
  199.         switch(qualifier) {
  200.  
  201.             case NORM1:
  202.             case NORM2:
  203.             case NORM3:
  204.             case NORM4:  /* normal key without qualifier keys */
  205.                 if(code < 64) {
  206.                     switch(KeyTable[code]) { /* keymap keys */
  207.  
  208.                         case 'h':
  209.                             Help();
  210.                             break;
  211.                         case 'q':
  212.                             if(!VW_printing) Quit( RETURN_OK );
  213.                             break;
  214.                         case '/':
  215.                         case 'f':
  216.                             VW_mode = TRUE;
  217.                             GetSomething(STRING_KIND);
  218.                             break;
  219.                         case '.':
  220.                         case 's':
  221.                             VW_mode = FALSE;
  222.                             GetSomething(STRING_KIND);
  223.                             break;
  224.                         case 'n':
  225.                             VW_mode = TRUE;
  226.                             FindN();
  227.                             break;
  228.                         case 'p':
  229.                             VW_mode = TRUE;
  230.                             FindP();
  231.                             break;
  232.                         case 'r':
  233.                             Inform(ClearStr);
  234.                             DisplayText();
  235.                             break;
  236.                         case 'e':
  237.                             EditFile();
  238.                             break;
  239.                         case 'l':
  240.                             if(!VW_printing) LoadFile(TRUE);
  241.                             break;
  242.                         case 'j':
  243.                             if ( VW_found )
  244.                                 DoFound();
  245.                             break;
  246.                         case 'b':
  247.                             if(!VW_printing) {
  248.                                 if(VW_text) FreeAscii(VW_text);
  249.                                 VW_text = NULL;
  250.                                 CloseDisplay();
  251.                             }
  252.                             break;
  253.                         default:
  254.                             break;
  255.                     }
  256.                 } else if(code >= 0x50 && code <= 0x59) { /* function keys */
  257.                     SetMark((UWORD)(code - 0x50));
  258.                     break;
  259.                 } else {
  260.                     switch(code) { /* RAW keys (the same on any Amiga..?) */
  261.                         case 0x40: /* Space bar  */
  262.                             PageDown();
  263.                             break;
  264.                         case 0x41: /* BackSpace  */
  265.                             PageUp();
  266.                             break;
  267.                         case 0x4d: /* Down arrow */
  268.                         case 0x44: /* Return     */
  269.                             LineDown();
  270.                             break;
  271.                         case 0x4c: /* Up arrow   */
  272.                             LineUp();
  273.                             break;
  274.                         case 0x5f: /* Help       */
  275.                             Help();
  276.                             break;
  277.                         case 0x45: /* Esc        */
  278.                             if(!VW_printing) Quit( RETURN_OK );
  279.                             break;
  280.                         default:
  281.                             break;
  282.                     }
  283.                 }
  284.                 break;
  285.             case NUMP1:
  286.             case NUMP2:
  287.             case NUMP3:
  288.             case NUMP4: /* Numeric key-pad */
  289.                 if(code < 64) { /* keymap keys */
  290.                     switch(KeyTable[code]) {
  291.  
  292.                         case '7':
  293.                         case '4':
  294.                             Top();
  295.                             break;
  296.                         case '1':
  297.                         case '6':
  298.                             Bottom();
  299.                             break;
  300.                         case '8':
  301.                             LineUp();
  302.                             break;
  303.                         case '2':
  304.                             LineDown();
  305.                             break;
  306.                         case '9':
  307.                             PageUp();
  308.                             break;
  309.                         case '3':
  310.                             PageDown();
  311.                             break;
  312.                         default:
  313.                             break;
  314.                     }
  315.                 } else if(code == 0x43) { /* Enter */
  316.                     LineUp();
  317.                     break;
  318.                 }
  319.                 break;
  320.             case CTRL1:
  321.             case CTRL2:
  322.             case CTRL3:
  323.             case CTRL4: /* key with CTRL */
  324.                 if(code < 64) { /* keymap keys */
  325.                     switch(KeyTable[code]) {
  326.  
  327.                         case 'c':
  328.                             if(!VW_printing) Quit( RETURN_OK );
  329.                             break;
  330.                         case 'n':
  331.                             VW_mode = FALSE;
  332.                             FindN();
  333.                             break;
  334.                         case 'p':
  335.                             VW_mode = FALSE;
  336.                             FindP();
  337.                             break;
  338.                         case 'l':
  339.                             Inform(ClearStr);
  340.                             DisplayText();
  341.                             break;
  342.                         case 'b':
  343.                             if(!VW_printing)
  344.                                 CloseDisplay();
  345.                             break;
  346.                         case 's':
  347.                             SaveBlock(-1);
  348.                             break;
  349.                         default:
  350.                             break;
  351.                     }
  352.                 } else if(code >= 0x50 && code <= 0x59) { /* Function keys */
  353.                     JumpMark((UWORD)(code - 0x50));
  354.                     break;
  355.                 }
  356.                 break;
  357.             case PRIN1:
  358.             case PRIN2: /* LEFT_SHIFT + CONTROL + key */
  359.                 if(code < 64) { /* keymap keys */
  360.                     switch(KeyTable[code]) {
  361.  
  362.                         case 'd':
  363.                             if(!VW_printing) {
  364.                                 VW_pmode = PRT_PAGE;
  365.                                 PrintFile();
  366.                             }
  367.                             break;
  368.                         case 'p':
  369.                             if(!VW_printing) {
  370.                                 VW_pmode = PRT_FILE;
  371.                                 PrintFile();
  372.                             }
  373.                             break;
  374.                         default:
  375.                             break;
  376.                     }
  377.                 } else if(code >= 0x50 && code <= 0x59) { /* Function keys */
  378.                     VW_pmode = PRT_BLOCK;
  379.                     VW_pmark = (UWORD)(code - 0x50);
  380.                     PrintFile();
  381.                     break;
  382.                 }
  383.                 break;
  384.             case SHIF1:
  385.             case SHIF2:
  386.             case SHIF3:
  387.             case SHIF4:
  388.             case SHIF5:
  389.             case SHIF6:
  390.             case SHIF7:
  391.             case SHIF8: /* SHIFT + key */
  392.                 if(code < 64) { /* keymap key */
  393.                     switch(SKeyTable[code]) {
  394.  
  395.                         case '<':
  396.                             Top();
  397.                             break;
  398.                         case '>':
  399.                             Bottom();
  400.                             break;
  401.                         case '%':
  402.                             GetSomething(INTEGER_KIND);
  403.                             break;
  404.                         case 'E':
  405.                             EditLine();
  406.                             break;
  407.                         default:
  408.                             break;
  409.                     }
  410.                 } else if(code >= 0x50 && code <= 0x59) { /* Function keys */
  411.                     UnSetMark((UWORD)(code - 0x50));
  412.                     break;
  413.                 }
  414.             case LALT1:
  415.             case LALT2:
  416.             case LALT3:
  417.             case LALT4:
  418.                 if(code >= 0x50 && code <= 0x59) {
  419.                     SaveBlock((UWORD)(code - 0x50));
  420.                     break;
  421.                 }
  422.                 break;
  423.  
  424.             default:
  425.                 break;
  426.             }
  427.         }
  428.     }
  429. }
  430.