home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / KBIDLE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  2.7 KB  |  99 lines

  1. /*
  2.       kbidle.c    10/02/87
  3.  
  4.     % kb_Idle
  5.     Replaces normal kb_Read() function with new handler.
  6.  
  7.     OWL 1.1
  8.     Copyright (c) 1987, 1988, 1989 by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13.      9/09/88 jmd    Ported to oakland lib
  14.      9/19/88 jmd    Added messages to idle func
  15.     10/04/88 jmd    Added support for kb_Check
  16.     10/27/88 jmd    Fixed bug in ReadHandler
  17.     12/01/88 jmd    modified for new KeyReadEvent
  18.      2/07/89 Ted    added timeout wait arg to hCheckEvent function.
  19.      7/07/89 gam    changed NULL to FNULL where applicable
  20. */
  21.  
  22. #include "oakhead.h"
  23. #include "disppriv.h"
  24. #include "kbidle.h"
  25.  
  26. OSTATIC unsigned kb_ReadHandler(_arg1(moupos_struct *));
  27. OSTATIC unsigned kb_CheckHandler(_arg1(unsigned));
  28.  
  29. /* static function pointers */
  30. static idle_fptr                kIdle_fptr         = FNULL;
  31. static dig_hReadEvent_func        ((*hReadEventFptr)) = FNULL;
  32. static dig_hCheckEvent_func        ((*hCheckEventFptr)) = FNULL;
  33. /* -------------------------------------------------------------------------- */
  34.  
  35. void kb_Idle(idle)
  36.     idle_fptr idle;
  37. /*
  38.     Sets up idle key function.
  39.  
  40.     The idle function is called with an IDLE_START message.
  41.  
  42.     If idle == NULL turn off the idle function and call it with
  43.     an IDLE_STOP message.
  44. */
  45. {
  46.     if (hReadEventFptr != FNULL) {
  47.         /* reset kb functions */
  48.         (*kIdle_fptr)(IDLE_STOP);
  49.         curr_dmgr->disp.dig.hReadEvent = hReadEventFptr;
  50.         curr_dmgr->disp.dig.hCheckEvent = hCheckEventFptr;
  51.         hReadEventFptr = FNULL;
  52.         hCheckEventFptr = FNULL;
  53.         kIdle_fptr = FNULL;
  54.     }
  55.  
  56.     if (idle != FNULL) {
  57.         /* save old keyboard handlers */
  58.         hReadEventFptr = curr_dmgr->disp.dig.hReadEvent;
  59.         hCheckEventFptr = curr_dmgr->disp.dig.hCheckEvent;
  60.  
  61.         /* set new keyboard handlers */
  62.         curr_dmgr->disp.dig.hReadEvent = kb_ReadHandler;
  63.         curr_dmgr->disp.dig.hCheckEvent = kb_CheckHandler;
  64.         kIdle_fptr = idle;
  65.         (*kIdle_fptr)(IDLE_START);
  66.     }
  67. }
  68. /* -------------------------------------------------------------------------- */
  69.  
  70. static unsigned kb_CheckHandler(wait)
  71.     unsigned wait;
  72. /*
  73.     Calls user idle function then calls original kb_Check routine
  74.     idle function is called with an IDLE_RUN message.
  75. */
  76. {
  77.     oak_notused(wait);
  78.  
  79.     (*kIdle_fptr)(IDLE_RUN);
  80.     return((*hCheckEventFptr)(0));
  81. }
  82. /* -------------------------------------------------------------------------- */
  83.  
  84. static unsigned int kb_ReadHandler(mposp)
  85.     moupos_struct *mposp;
  86. /*
  87.     Calls user idle function while real kb_Check routine returns FALSE.
  88.     Calls original kb_Read when a keystroke is available
  89.     idle function is called with an IDLE_RUN message.
  90. */
  91. {
  92.     while (!(*hCheckEventFptr)(0)) {
  93.         (*kIdle_fptr)(IDLE_RUN);
  94.     }
  95.     return((*hReadEventFptr)(mposp));
  96. }
  97. /* -------------------------------------------------------------------------- */
  98.  
  99.