home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_02 / wmspopup.c < prev    next >
C/C++ Source or Header  |  1991-04-11  |  1KB  |  48 lines

  1. /*  WMSPOPUP.C
  2.  *        install a function to be executed 
  3.  *        whenever the mouse center button is pressed
  4.  *        the function can return a new keyvalue which is inserted into the
  5.  *        keyboard stream ( ie: allow selection of a function key by mouse )
  6.  */    
  7. #include "wsys.h"
  8.  
  9.  
  10. static int installed = 0;
  11. static int reentrant = 0;
  12. static int handler ( int );
  13. static int (*old_handler) (int) = NULL;
  14. static int (*save_func) (void) = NULL;
  15.  
  16. void wmspopup ( int (*func)(void) )
  17.     {
  18.     if ( ! installed ) 
  19.         {
  20.         installed = 1;
  21.         old_handler = wkeytrap;
  22.         wkeytrap     = handler; 
  23.         }
  24.     save_func   = func;
  25.     return;    /* wmspopup () */
  26.     }    
  27.     
  28.     
  29. static int handler ( int key )
  30.     {
  31.     if ( key == MOUSE && ( wmouse.wms_used & WMS_CENTER_PRS ) 
  32.         && ! reentrant && save_func != NULL  )
  33.         {
  34.         reentrant  =1;
  35.         key = (*save_func)();
  36.         reentrant = 0;
  37.         }
  38.         
  39.     /*    chain to any other key handlers
  40.      */
  41.     if ( old_handler != NULL )
  42.         {
  43.         key = old_handler (key );
  44.         }
  45.     return ( key );            /* end of handler */
  46.     }    
  47. /*---------------- end of WMSPOPUP.C -----------------*/    
  48.