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

  1. /*
  2.     winmouse.c    11/16/88
  3.  
  4.     % window mouse functions.
  5.     by Ted.
  6.  
  7.     OWL 1.1
  8.     Copyright (c) 1988, by Oakland Group, Inc.
  9.     ALL RIGHTS RESERVED.
  10.  
  11.     Revision History:
  12.     -----------------
  13.      3/25/89 ted    Made Dclick & Holddown use CheckEventWait calls.
  14.      3/31/89 ted:    Extracted wmgr_PointWin to winobsc.c
  15. */
  16.  
  17. #include "oakhead.h"
  18. #include "disppriv.h"
  19. #include "digutil.h"
  20. #include "scancode.h"    /* for mouse pseudo-scancodes */
  21.  
  22. OSTATIC boolean OWLPRIV moveout(_arg2(mev_struct *, mev_struct *));
  23. /* -------------------------------------------------------------------------- */
  24.  
  25. unsigned win_ReadEvent(win, mev)
  26.     win_type win;
  27.     mev_struct *mev;
  28. /*
  29.     Use this function inside a mouse handler when you want to keep control
  30.     and receive mouse coordinates that can range outside of your window.
  31.     NOTE: your window is not asked to accept the events.
  32. */
  33. {
  34.     moupos_struct moupos;
  35.     unsigned evcode;
  36.  
  37.     if (win == NULL) {
  38.         return(0);
  39.     }
  40.     if ((evcode = hard_ReadEvent(&moupos)) == HARD_MEV) {
  41.         evcode = MOU_EVENT;
  42.  
  43.         memmove((VOID *)wmgr_lastmoupos(),
  44.                 (VOID *)&moupos, sizeof(moupos_struct));
  45.     /* Make the mouse coords relative to the window */
  46.         mev->win = win;
  47.         mev->x = moupos.x - win_GetXmin(win);
  48.         mev->y = moupos.y - win_GetYmin(win);
  49.         mev->event = moupos.event;
  50.     }
  51.     return(evcode);
  52. }
  53. /* -------------------------------------------------------------------------- */
  54.  
  55. boolean win_MouseCurrEvent(mev)
  56.     mev_struct *mev;
  57. {
  58.     mev_struct *tmev;
  59.  
  60.     tmev = wmgr_lastmev();
  61.     if (!win_Ok(tmev->win)) {
  62.         return(FALSE);
  63.     }
  64.     memmove(mev, tmev, sizeof(mev_struct));
  65.  
  66.     return(TRUE);
  67. }
  68. /* -------------------------------------------------------------------------- */
  69.  
  70. unsigned win_MouseHoldDownTime(win, mev, duration)
  71.     win_type win;
  72.     mev_struct *mev;
  73.     unsigned duration;
  74. /*
  75.     Returns MOU_HOLDDOWN if a mouse button stays pressed for 'duration'
  76.     hundredths of a second.    If duration is 0, the default mouse timeout is used.
  77.     If a keystroke is gotten, this function returns immediately with the
  78.     scancode value.
  79.     On return, mev contains the last recorded mouse event.
  80.     If no mouse events occur while control is in this function, mev is unaltered.
  81. */
  82. {
  83.     unsigned itime, ttime, tdiff;
  84.     mev_struct firstmev;
  85.     unsigned evcode;
  86.  
  87.     if (win == NULL) {
  88.         return(0);
  89.     }
  90. /* Wait a while for any button to go up */
  91.     firstmev.event = TRUE;    /* use firstmev.event as a first-flag */
  92.     if (duration != (unsigned)-1) {
  93.         itime = hard_Timer();
  94.     }
  95.     for (;;) {
  96.         /* Check first in case no events pending */
  97.         if (win_CheckEventWait(win, duration)) {
  98.             if ((evcode = win_ReadEvent(win, mev)) == MOU_EVENT) {
  99.  
  100.                 if (moveout(&firstmev, mev)) {
  101.                     break;    /* return MOU_EVENT */
  102.                 }
  103.                 if (!mev_IsButtonDown(mev)) {
  104.                     break;    /* return MOU_EVENT */
  105.                 }
  106.             }
  107.             else break;        /* return Keystroke */
  108.         }
  109.         else return(MOU_HOLDDOWN); /* time expired with no event */
  110.  
  111.         /* Going around again - reduce wait duration by what has now elapsed */
  112.         if (duration != (unsigned)-1) {
  113.             /* Note: this block of code should be made atomic somehow */
  114.             ttime = hard_Timer();
  115.             /* Double check in case time has now expired */
  116.             if ((tdiff = dig_SubHsecs(itime, ttime)) > duration) {
  117.                 return(MOU_HOLDDOWN);    /* Hold-down */
  118.             }
  119.             duration -= tdiff;
  120.             itime = ttime;
  121.         }
  122.     }
  123.     return(evcode);
  124. }
  125. /* -------------------------------------------------------------------------- */
  126.  
  127. unsigned win_MouseDblClick(win, mev)
  128.     win_type win;
  129.     mev_struct *mev;
  130. /*
  131.     Returns MOU_DCLICK if a fresh button press event is detected within a few
  132.     fractions of a second. Returns MOU_HOLDDOWN if a button was held down during
  133.     the whole interval.
  134.     If a keystroke is gotten, this function returns immediately with the
  135.     scancode value.
  136.     On return, mev contains the last recorded mouse event.
  137.     If no mouse events occur while control is in this function, mev is
  138.     unaltered and MOU_HOLDDOWN is returned. (It is assumed that you only call
  139.     this function if a button down event has occurred).
  140. */
  141. {
  142.     unsigned itime, ttime, tdiff;
  143.     unsigned duration;
  144.     mev_struct firstmev;
  145.     unsigned oldevent;
  146.     unsigned evcode;
  147.     boolean stillheld;
  148.  
  149.     if (win == NULL) {
  150.         return(0);
  151.     }
  152. /* Start as if all buttons were pressed */
  153.     oldevent = (MEV_BUT1 | MEV_BUT2 | MEV_BUT3);
  154.     stillheld = TRUE;        /* assume function was called w/ button down */
  155.  
  156. /* Wait a while for any button to go up and then get pressed again */
  157.     duration = disp_MouseTimeout();
  158.     firstmev.event = TRUE;    /* use firstmev.event as a first-flag */
  159.     itime = hard_Timer();
  160.  
  161.     for (;;) {
  162.         /* Check first in case no events pending */
  163.         if (win_CheckEventWait(win, duration)) {
  164.             if ((evcode = win_ReadEvent(win, mev)) == MOU_EVENT) {
  165.  
  166.                 if (moveout(&firstmev, mev)) {
  167.                     return(MOU_EVENT);    /* Too much motion */
  168.                 }
  169.                 if (mev_ButtonGoneDown(oldevent, mev->event)) {
  170.                     return(MOU_DCLICK);    /* Double click */
  171.                 }
  172.                 if (!mev_IsButtonDown(mev)) {
  173.                     stillheld = FALSE;    /* clear hold-down flag */
  174.                 }
  175.                 oldevent = mev->event;
  176.             }
  177.             else return(evcode);    /* return Keystroke */
  178.         }
  179.         else return(MOU_HOLDDOWN); /* time expired with no event */
  180.  
  181.         /* Going around again - reduce wait duration by what has now elapsed */
  182.         /* Note: this block of code should be made atomic somehow */
  183.         ttime = hard_Timer();
  184.         /* Double check in case time has now expired */
  185.         if ((tdiff = dig_SubHsecs(itime, ttime)) > duration) {
  186.             if (stillheld) {
  187.                 return(MOU_HOLDDOWN);    /* Hold-down */
  188.             }
  189.             else return(MOU_EVENT);        /* Timeout w/ button up */
  190.             /* Note: if stillheld is FALSE, a mouse event must have occurred */
  191.         }
  192.         duration -= tdiff;
  193.         itime = ttime;
  194.     }
  195. }
  196. /* -------------------------------------------------------------------------- */
  197.  
  198. static boolean OWLPRIV moveout(firstmev, currmev)
  199.     mev_struct *firstmev;
  200.     mev_struct *currmev;
  201. /*
  202.     Returns TRUE if the mouse position moved too far.
  203. */
  204. {
  205.     if (firstmev->event) {
  206.         firstmev->x = currmev->x; firstmev->y = currmev->y;
  207.         firstmev->event = FALSE;
  208.         return(FALSE);
  209.     }
  210.     else return(mev_MovedOut(firstmev, currmev, disp_MouseDistout()));
  211. }
  212. /* -------------------------------------------------------------------------- */
  213.  
  214.