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 >
Wrap
C/C++ Source or Header
|
1991-11-21
|
14KB
|
430 lines
/*-- AutoRev header do NOT edit!
*
* Program : event.c
* Copyright : © 1991 Jaba Development
* Author : Jan van den Baard
* Creation Date : 21-Apr-91
* Current version : 1.5
* Translator : DICE v2.6
*
* REVISION HISTORY
*
* Date Version Comment
* --------- ------- ------------------------------------------
* 18-Sep-91 1.5 Removed SteadyRepeat() routine.
* 17-Sep-91 1.5 See main.c!
* 16-Sep-91 1.4 See main.c!
* 23-Aug-91 1.3 See main.c!
* 12-Aug-91 1.2 See main.c!
* 03-Jul-91 1.1 See main.c!
* 21-Apr-91 1.0 View keyboard event-handler + subs.
*
*-- REV_END --*/
#include "view.h"
/*
* All kinds of qualifier-key combinations.
*/
#define MOUSE IEQUALIFIER_RELATIVEMOUSE
#define REPEAT IEQUALIFIER_REPEAT
#define LOCK IEQUALIFIER_CAPSLOCK
#define NUMPAD IEQUALIFIER_NUMERICPAD
#define LSHIFT IEQUALIFIER_LSHIFT
#define RSHIFT IEQUALIFIER_RSHIFT
#define CONTROL IEQUALIFIER_CONTROL
#define ALT IEQUALIFIER_LALT
#define NORM1 MOUSE
#define NORM2 NORM1+REPEAT
#define NORM3 NORM1+LOCK
#define NORM4 NORM2+LOCK
#define LALT1 MOUSE+ALT
#define LALT2 LALT1+REPEAT
#define LALT3 LALT1+LOCK
#define LALT4 LALT2+LOCK
#define NUMP1 MOUSE+NUMPAD
#define NUMP2 NUMP1+REPEAT
#define NUMP3 NUMP1+LOCK
#define NUMP4 NUMP2+LOCK
#define CTRL1 MOUSE+CONTROL
#define CTRL2 CTRL1+REPEAT
#define CTRL3 CTRL1+LOCK
#define CTRL4 CTRL2+LOCK
#define PRIN1 CTRL1+LSHIFT
#define PRIN2 CTRL3+LSHIFT
#define SHIF1 MOUSE+LSHIFT
#define SHIF2 MOUSE+RSHIFT
#define SHIF3 SHIF1+REPEAT
#define SHIF4 SHIF2+REPEAT
#define SHIF5 SHIF1+LOCK
#define SHIF6 SHIF2+LOCK
#define SHIF7 SHIF3+LOCK
#define SHIF8 SHIF4+LOCK
/*
* hot-keys to be pressed together with LALT+LAMIGA
* when view is taking a nap.
*/
#define VIEW 0x34
#define QUIT 0x10
#define FLUSH 0x23
/*
* some external referenced globals.
*/
extern APTR ConsoleDevice;
extern ULONG VW_class;
extern UWORD VW_qual, VW_code, VW_pmark;
extern UWORD VW_mode, VW_pmode, VW_printing, VW_err;
extern UBYTE ClearStr[];
extern struct Screen *VW_scr;
extern BOOL VW_found;
/*
* some external referenced function proto-types.
*/
extern void Quit( long );
extern void Inform( char *);
extern void LineUp( void );
extern void LineDown( void );
extern void DisplayText( void );
extern void Top( void );
extern void Bottom( void );
extern void PageUp( void );
extern void PageDown( void );
extern void LoadFile( long );
extern void Help( void );
extern void DoFound( void );
extern void GetSomething( ULONG );
extern void FindN( void );
extern void FindP( void );
extern void PrintFile( void );
extern void InfoLine( void );
extern void EditFile( void );
extern void SetMark( UWORD );
extern void UnSetMark( UWORD );
extern void JumpMark( UWORD );
extern void SaveBlock( WORD );
extern void EditLine( void );
extern void CloseDisplay( void );
/*
* some local proto-types.
*/
void ConvertKeyTab( void );
void HandleKeyboard( UWORD, UWORD );
long HandleMsg( struct MsgPort * );
void ClearMsg( struct MsgPort * );
/*
* Vanilla key-codes normal and shifted.
*/
UBYTE KeyTable[64];
UBYTE SKeyTable[64];
/*
* Setup a key-table for normal and shifted key codes so
* View will work with all kinds of foreigh key-mappings.
*/
void ConvertKeyTab()
{
struct InputEvent ievent;
UWORD i;
setmem(&ievent,sizeof(struct InputEvent),0);
ievent.ie_Class = IECLASS_RAWKEY;
for(i=0;i<64;i++) { /* build normal key-table */
ievent.ie_Code = i;
RawKeyConvert(&ievent,&KeyTable[i],1,NULL);
}
ievent.ie_Qualifier = LSHIFT;
for(i=0;i<64;i++) { /* build shifted key-table */
ievent.ie_Code = i;
RawKeyConvert(&ievent,&SKeyTable[i],1,NULL);
}
}
/*
* Get and interpred a message from the port.
* return TRUE if there was a message received
* or FALSE if not.
*/
long HandleMsg( struct MsgPort *port )
{
struct IntuiMessage *msg;
if((msg = GT_GetIMsg(port))) { /* gotten a message! */
VW_class = msg->Class;
VW_code = msg->Code;
VW_qual = msg->Qualifier;
GT_ReplyIMsg(msg); /* gadtools is open so why not... */
return TRUE;
}
return FALSE;
}
/*
* Reply all pending messages on the msgport
* without doing something with them.
*/
void ClearMsg( struct MsgPort *port )
{
struct IntuiMessage *msg;
Forbid(); /* don't race intuition. */
while(msg = GT_GetIMsg(port)) GT_ReplyIMsg(msg);
Permit();
}
extern struct AsciiText *VW_text;
/*
* Handle all incoming RAWKEY messages.
*/
void HandleKeyboard( code, qualifier )
UWORD code, qualifier;
{
if((code & IECODE_UP_PREFIX) != IECODE_UP_PREFIX) { /* only key-down */
if(VW_err) InfoLine(); /* refresh info line if needed */
switch(qualifier) {
case NORM1:
case NORM2:
case NORM3:
case NORM4: /* normal key without qualifier keys */
if(code < 64) {
switch(KeyTable[code]) { /* keymap keys */
case 'h':
Help();
break;
case 'q':
if(!VW_printing) Quit( RETURN_OK );
break;
case '/':
case 'f':
VW_mode = TRUE;
GetSomething(STRING_KIND);
break;
case '.':
case 's':
VW_mode = FALSE;
GetSomething(STRING_KIND);
break;
case 'n':
VW_mode = TRUE;
FindN();
break;
case 'p':
VW_mode = TRUE;
FindP();
break;
case 'r':
Inform(ClearStr);
DisplayText();
break;
case 'e':
EditFile();
break;
case 'l':
if(!VW_printing) LoadFile(TRUE);
break;
case 'j':
if ( VW_found )
DoFound();
break;
case 'b':
if(!VW_printing) {
if(VW_text) FreeAscii(VW_text);
VW_text = NULL;
CloseDisplay();
}
break;
default:
break;
}
} else if(code >= 0x50 && code <= 0x59) { /* function keys */
SetMark((UWORD)(code - 0x50));
break;
} else {
switch(code) { /* RAW keys (the same on any Amiga..?) */
case 0x40: /* Space bar */
PageDown();
break;
case 0x41: /* BackSpace */
PageUp();
break;
case 0x4d: /* Down arrow */
case 0x44: /* Return */
LineDown();
break;
case 0x4c: /* Up arrow */
LineUp();
break;
case 0x5f: /* Help */
Help();
break;
case 0x45: /* Esc */
if(!VW_printing) Quit( RETURN_OK );
break;
default:
break;
}
}
break;
case NUMP1:
case NUMP2:
case NUMP3:
case NUMP4: /* Numeric key-pad */
if(code < 64) { /* keymap keys */
switch(KeyTable[code]) {
case '7':
case '4':
Top();
break;
case '1':
case '6':
Bottom();
break;
case '8':
LineUp();
break;
case '2':
LineDown();
break;
case '9':
PageUp();
break;
case '3':
PageDown();
break;
default:
break;
}
} else if(code == 0x43) { /* Enter */
LineUp();
break;
}
break;
case CTRL1:
case CTRL2:
case CTRL3:
case CTRL4: /* key with CTRL */
if(code < 64) { /* keymap keys */
switch(KeyTable[code]) {
case 'c':
if(!VW_printing) Quit( RETURN_OK );
break;
case 'n':
VW_mode = FALSE;
FindN();
break;
case 'p':
VW_mode = FALSE;
FindP();
break;
case 'l':
Inform(ClearStr);
DisplayText();
break;
case 'b':
if(!VW_printing)
CloseDisplay();
break;
case 's':
SaveBlock(-1);
break;
default:
break;
}
} else if(code >= 0x50 && code <= 0x59) { /* Function keys */
JumpMark((UWORD)(code - 0x50));
break;
}
break;
case PRIN1:
case PRIN2: /* LEFT_SHIFT + CONTROL + key */
if(code < 64) { /* keymap keys */
switch(KeyTable[code]) {
case 'd':
if(!VW_printing) {
VW_pmode = PRT_PAGE;
PrintFile();
}
break;
case 'p':
if(!VW_printing) {
VW_pmode = PRT_FILE;
PrintFile();
}
break;
default:
break;
}
} else if(code >= 0x50 && code <= 0x59) { /* Function keys */
VW_pmode = PRT_BLOCK;
VW_pmark = (UWORD)(code - 0x50);
PrintFile();
break;
}
break;
case SHIF1:
case SHIF2:
case SHIF3:
case SHIF4:
case SHIF5:
case SHIF6:
case SHIF7:
case SHIF8: /* SHIFT + key */
if(code < 64) { /* keymap key */
switch(SKeyTable[code]) {
case '<':
Top();
break;
case '>':
Bottom();
break;
case '%':
GetSomething(INTEGER_KIND);
break;
case 'E':
EditLine();
break;
default:
break;
}
} else if(code >= 0x50 && code <= 0x59) { /* Function keys */
UnSetMark((UWORD)(code - 0x50));
break;
}
case LALT1:
case LALT2:
case LALT3:
case LALT4:
if(code >= 0x50 && code <= 0x59) {
SaveBlock((UWORD)(code - 0x50));
break;
}
break;
default:
break;
}
}
}
}