home *** CD-ROM | disk | FTP | other *** search
- #include "HEADERS.h"
- #include "srgplocal.h"
- #include <ctype.h>
-
- /*
- * if this is defined some BIOS keycodes are remapped for the SUIT
- * text and line editor widgets
- */
- #define MAP_KEYS_FOR_SUIT
-
- #define BACKSPACE_KEY 8
- #define CARRIAGE_RETURN 13
-
- static int kb_enable = 0;
- static int ms_enable = 0;
- static int in_wait_event;
- static int previous_key = FALSE;
-
- #ifdef __GNUC__
- # define clock() rawclock()
- #endif
-
- void SRGP__initInputDrivers(void)
- {
- #ifdef DEBUG
- MouseEventMode(FALSE);
- #else
- MouseEventMode(TRUE);
- #endif
- MouseInit();
- kb_enable = 0;
- ms_enable = 0;
- MouseEventEnable(kb_enable,ms_enable);
- srgpx__starttime = clock();
- }
-
- void SRGP__updateInputSelectionMask(void)
- {
- kb_enable = (srgp__cur_mode[KEYBOARD] == INACTIVE) ? 0 : 1;
- ms_enable = (srgp__cur_mode[LOCATOR] == INACTIVE) ? 0 : 1;
- MouseEventEnable(kb_enable,ms_enable);
- }
-
- /**
- ** RAW-LEVEL DEACTIVATION OF A DEVICE
- ** Responsible for erasing echo, and resetting device's measure to the
- ** hardwired default.
- ** Upon entry, the device's cur_mode is its old value (has not been
- ** changed yet)! And this procedure does not change it!
- **/
- void SRGP__deactivateDevice(int device)
- {
- switch(device) {
- case LOCATOR:
- SRGP__disableLocatorRubberEcho();
- SRGP__disableLocatorCursorEcho();
- srgp__cur_locator_measure.position = SRGP_defPoint(
- (srgp__canvasTable[0].max_xcoord >> 1),
- (srgp__canvasTable[0].max_ycoord >> 1)
- );
- ms_enable = 0;
- MouseEventEnable(kb_enable,ms_enable);
- break;
- case KEYBOARD:
- SRGP__disableKeyboardEcho();
- srgp__cur_keyboard_measure.buffer[0] = '\0';
- srgp__cur_keyboard_measure_length = 0;
- bzero(srgp__cur_keyboard_measure.modifier_chord,
- sizeof(srgp__cur_keyboard_measure.modifier_chord)
- );
- kb_enable = 0;
- MouseEventEnable(kb_enable,ms_enable);
- previous_key = FALSE;
- break;
- }
- }
-
- /**
- ** RAW-LEVEL ACTIVATION OF A DEVICE
- ** Called whenever:
- ** a device is placed into EVENT or SAMPLE mode...
- ** a) when previously inactive
- ** b) when previously active but in a different mode
- ** Upon entry, the device's echo info and mode has already
- ** been set to their new values.
- ** Responsible for initiating echo
- **/
- void SRGP__activateDevice(int device)
- {
- switch(device) {
- case LOCATOR:
- SRGP__disableLocatorCursorEcho();
- SRGP__disableLocatorRubberEcho();
- SRGP__enableLocatorCursorEcho();
- SRGP__enableLocatorRubberEcho();
- SRGP__updateInputSelectionMask();
- ms_enable = 1;
- break;
- case KEYBOARD:
- SRGP__enableKeyboardEcho();
- SRGP__updateInputSelectionMask();
- previous_key = FALSE;
- kb_enable = 1;
- break;
- }
- MouseEventEnable(kb_enable,ms_enable);
- }
-
- void SRGP__updateRawCursorPosition(void)
- {
- srgp__cur_Xcursor_x = srgp__cur_locator_measure.position.x;
- srgp__cur_Xcursor_y = SCREENFIXED(srgp__cur_locator_measure.position.y);
- MouseWarp(srgp__cur_Xcursor_x,srgp__cur_Xcursor_y);
- }
-
- void SRGP__updateLocationKnowledge(void)
- {
- srgp__dirty_location = FALSE; /* don't bother calling me!! */
- return;
- }
-
- static inputDevice HandleButtonEvent(MouseEvent *e)
- {
- int which_button = (-1);
-
- if(e->flags & (M_LEFT_UP | M_LEFT_DOWN)) {
- if(srgp__cur_locator_button_mask & LEFT_BUTTON_MASK)
- which_button = LEFT_BUTTON;
- srgp__cur_locator_measure.button_chord[LEFT_BUTTON] =
- (e->buttons & M_LEFT) ? DOWN : UP;
- }
- if(e->flags & (M_MIDDLE_UP | M_MIDDLE_DOWN)) {
- if(srgp__cur_locator_button_mask & MIDDLE_BUTTON_MASK)
- which_button = MIDDLE_BUTTON;
- srgp__cur_locator_measure.button_chord[MIDDLE_BUTTON] =
- (e->buttons & M_MIDDLE) ? DOWN : UP;
- }
- if(e->flags & (M_RIGHT_UP | M_RIGHT_DOWN)) {
- if(srgp__cur_locator_button_mask & RIGHT_BUTTON_MASK)
- which_button = RIGHT_BUTTON;
- srgp__cur_locator_measure.button_chord[RIGHT_BUTTON] =
- (e->buttons & M_RIGHT) ? DOWN : UP;
- }
- if(which_button >= 0)
- srgp__cur_locator_measure.button_of_last_transition = which_button;
- srgp__cur_locator_measure.modifier_chord[SHIFT] =
- ((e->kbstat & KB_SHIFT) ? TRUE : FALSE);
- srgp__cur_locator_measure.modifier_chord[CONTROL] =
- ((e->kbstat & KB_CTRL) ? TRUE : FALSE);
- srgp__cur_locator_measure.modifier_chord[META] =
- ((e->kbstat & KB_ALT) ? TRUE : FALSE);
- srgp__cur_Xcursor_x = e->x;
- srgp__cur_Xcursor_y = e->y;
- srgp__cur_locator_measure.position.x = e->x;
- srgp__cur_locator_measure.position.y = SCREENFIXED(e->y);
- if(srgp__cur_mode[LOCATOR] != EVENT)
- return(NO_DEVICE);
- if(which_button < 0)
- return(NO_DEVICE);
- if(!in_wait_event)
- return(NO_DEVICE);
- srgp__get_locator_measure = srgp__cur_locator_measure;
- return(LOCATOR);
- }
-
- static inputDevice HandleRawModeKeyEvent(MouseEvent *e)
- {
- #ifdef MAP_KEYS_FOR_SUIT
- switch(e->key) {
- case 0x148:
- case 0x248: /* Up */
- srgp__cur_keyboard_measure.buffer[0] = 'P' - 0x40;
- break;
- case 0x150:
- case 0x250: /* Down */
- srgp__cur_keyboard_measure.buffer[0] = 'N' - 0x40;
- break;
- case 0x14b:
- case 0x24b: /* Left */
- srgp__cur_keyboard_measure.buffer[0] = 'B' - 0x40;
- break;
- case 0x14d:
- case 0x24d: /* Right */
- srgp__cur_keyboard_measure.buffer[0] = 'F' - 0x40;
- break;
- case 0x153:
- case 0x253: /* Del */
- srgp__cur_keyboard_measure.buffer[0] = 'D' - 0x40;
- break;
- case 0x151:
- case 0x251: /* PgDown */
- srgp__cur_keyboard_measure.buffer[0] = 'V' - 0x40;
- break;
- case 0x149:
- case 0x249: /* PgUp */
- srgp__cur_keyboard_measure.buffer[0] = 'v';
- e->kbstat |= KB_ALT;
- break;
- case 0x147:
- case 0x247: /* Home */
- srgp__cur_keyboard_measure.buffer[0] = 'A' - 0x40;
- break;
- case 0x14f:
- case 0x24f: /* End */
- srgp__cur_keyboard_measure.buffer[0] = 'E' - 0x40;
- break;
- default:
- srgp__cur_keyboard_measure.buffer[0] = e->key;
- break;
- }
- #else
- srgp__cur_keyboard_measure.buffer[0] = e->key;
- #endif
- srgp__cur_keyboard_measure.buffer[1] = '\0';
- srgp__cur_keyboard_measure.modifier_chord[SHIFT] =
- ((e->kbstat & KB_SHIFT) ? TRUE : FALSE);
- srgp__cur_keyboard_measure.modifier_chord[CONTROL] =
- ((e->kbstat & KB_CTRL) ? TRUE : FALSE);
- srgp__cur_keyboard_measure.modifier_chord[META] =
- ((e->kbstat & KB_ALT) ? TRUE : FALSE);
- if(srgp__cur_mode[KEYBOARD] == EVENT) {
- strcpy(srgp__get_keyboard_measure.buffer,srgp__cur_keyboard_measure.buffer);
- srgp__get_keyboard_measure.position = srgp__cur_keyboard_measure.position;
- bcopy(srgp__cur_keyboard_measure.modifier_chord,
- srgp__get_keyboard_measure.modifier_chord,
- sizeof(srgp__get_keyboard_measure.modifier_chord)
- );
- if(in_wait_event) return(KEYBOARD);
- previous_key = TRUE;
- }
- return(NO_DEVICE);
- }
-
- static inputDevice HandleProcModeKeyEvent(MouseEvent *e)
- {
- switch(e->key) {
- case CARRIAGE_RETURN:
- if(srgp__cur_mode[KEYBOARD] == EVENT) {
- strcpy(srgp__get_keyboard_measure.buffer,srgp__cur_keyboard_measure.buffer);
- srgp__get_keyboard_measure.position = srgp__cur_keyboard_measure.position;
- }
- srgp__cur_keyboard_measure.buffer[0] = '\0';
- srgp__cur_keyboard_measure_length = 0;
- SRGP__updateKeyboardEcho();
- if(srgp__cur_mode[KEYBOARD] == EVENT) {
- if(in_wait_event) return(KEYBOARD);
- previous_key = TRUE;
- }
- break;
- case BACKSPACE_KEY:
- if(srgp__cur_keyboard_measure_length > 0) {
- srgp__cur_keyboard_measure_length = srgp__cur_keyboard_measure_length - 1;
- srgp__cur_keyboard_measure.buffer[srgp__cur_keyboard_measure_length] = '\0';
- SRGP__updateKeyboardEcho();
- }
- break;
- default:
- /* CHECK: IS THE KEY PRINTABLE ASCII? */
- if(isprint(e->key) && (srgp__cur_keyboard_measure_length < MAX_STRING_SIZE)) {
- srgp__cur_keyboard_measure.buffer[srgp__cur_keyboard_measure_length] = e->key;
- srgp__cur_keyboard_measure_length++;
- srgp__cur_keyboard_measure.buffer[srgp__cur_keyboard_measure_length] = '\0';
- SRGP__updateKeyboardEcho();
- }
- break;
- }
- return(NO_DEVICE);
- }
-
- /**
- ** SRGP__handleRawEvents
- ** "This function nevers enters a wait state, unless it has been
- ** called as a result of SRGP_waitEvent(FOREVER).
- ** It examines all the events on the "raw"
- ** queue: the queue of the underlying graphics package
- ** (e.g., X11, Mac).
- ** Exception: it may not handle all the raw events.
- ** It exits as soon as it sees a valid trigger situation.
- ** It returns a device ID IF AND ONLY IF...
- ** 1) the appl. is in a call to SRGP_waitEvent(), AND
- ** 2) a valid trigger for a device currently in Event mode
- ** has been encountered.
- ** IF it does return a device ID, THEN...
- ** It automatically sets the proper value for either
- ** srgp__get_locator_measure or
- ** srgp__get_keyboard_measure
- ** in preparation for the application's ensuing call to
- ** SRGP_get...()
- ** Another exception: it may "pass over" some raw events and
- ** just leave them in the raw queue.
- ** It will pass over a raw event IF AND ONLY IF...
- ** 1) the appl. is not in a call to SRGP_waitEvent(), AND
- ** 2) the event is a valid trigger for a device
- ** currently in Event mode.
- ** Another possibility is that it will discard a raw event
- ** without processing it at all.
- ** It will discard a raw event IF AND ONLY IF...
- ** The event is for a device that is currently inactive."
- ** FOR GRX IT WILL NOT PUSH BACK ANY EVENTS!!!
- ** IT SIMPLY DISCARDS ANYTHING FROM THE QUEUE WHICH DOES NOT
- ** MATCH
- **/
- int SRGP__handleRawEvents(boolean inwaitevent,boolean forever)
- {
- MouseEvent evt;
- inputDevice id;
- int flags = M_NOPAINT;
-
- if(inwaitevent && previous_key) {
- previous_key = FALSE;
- return(KEYBOARD);
- }
- if(kb_enable) {
- flags = (M_KEYPRESS | M_NOPAINT);
- if(srgp__cur_mode[KEYBOARD] == SAMPLE) flags |= M_POLL;
- }
- if(ms_enable) {
- flags |= (M_MOTION | M_BUTTON_CHANGE);
- if(srgp__cur_mode[LOCATOR] == SAMPLE) flags |= M_POLL;
- }
- if(!forever || !inwaitevent) flags |= M_POLL;
- in_wait_event = inwaitevent;
- for( ; ; ) {
- MouseGetEvent(flags,&evt);
- if(evt.flags & M_KEYPRESS) {
- srgpx__cur_time = evt.time;
- srgp__cur_keyboard_measure.position = srgp__cur_locator_measure.position;
- if(srgp__cur_keyboard_processing_mode == RAW) {
- if((id = HandleRawModeKeyEvent(&evt)) != NO_DEVICE) return(id);
- continue;
- }
- if((id = HandleProcModeKeyEvent(&evt)) != NO_DEVICE) return(id);
- continue;
- }
- if(evt.flags & (M_MOTION | M_BUTTON_CHANGE)) {
- srgpx__cur_time = evt.time;
- if((id = HandleButtonEvent(&evt)) != NO_DEVICE) return(id);
- continue;
- }
- if(!forever || !inwaitevent) return(NO_DEVICE);
- }
- }
-