home *** CD-ROM | disk | FTP | other *** search
- /*
- winmouse.c 11/16/88
-
- % window mouse functions.
- by Ted.
-
- OWL 1.1
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 3/25/89 ted Made Dclick & Holddown use CheckEventWait calls.
- 3/31/89 ted: Extracted wmgr_PointWin to winobsc.c
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
- #include "digutil.h"
- #include "scancode.h" /* for mouse pseudo-scancodes */
-
- OSTATIC boolean OWLPRIV moveout(_arg2(mev_struct *, mev_struct *));
- /* -------------------------------------------------------------------------- */
-
- unsigned win_ReadEvent(win, mev)
- win_type win;
- mev_struct *mev;
- /*
- Use this function inside a mouse handler when you want to keep control
- and receive mouse coordinates that can range outside of your window.
- NOTE: your window is not asked to accept the events.
- */
- {
- moupos_struct moupos;
- unsigned evcode;
-
- if (win == NULL) {
- return(0);
- }
- if ((evcode = hard_ReadEvent(&moupos)) == HARD_MEV) {
- evcode = MOU_EVENT;
-
- memmove((VOID *)wmgr_lastmoupos(),
- (VOID *)&moupos, sizeof(moupos_struct));
- /* Make the mouse coords relative to the window */
- mev->win = win;
- mev->x = moupos.x - win_GetXmin(win);
- mev->y = moupos.y - win_GetYmin(win);
- mev->event = moupos.event;
- }
- return(evcode);
- }
- /* -------------------------------------------------------------------------- */
-
- boolean win_MouseCurrEvent(mev)
- mev_struct *mev;
- {
- mev_struct *tmev;
-
- tmev = wmgr_lastmev();
- if (!win_Ok(tmev->win)) {
- return(FALSE);
- }
- memmove(mev, tmev, sizeof(mev_struct));
-
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
- unsigned win_MouseHoldDownTime(win, mev, duration)
- win_type win;
- mev_struct *mev;
- unsigned duration;
- /*
- Returns MOU_HOLDDOWN if a mouse button stays pressed for 'duration'
- hundredths of a second. If duration is 0, the default mouse timeout is used.
- If a keystroke is gotten, this function returns immediately with the
- scancode value.
- On return, mev contains the last recorded mouse event.
- If no mouse events occur while control is in this function, mev is unaltered.
- */
- {
- unsigned itime, ttime, tdiff;
- mev_struct firstmev;
- unsigned evcode;
-
- if (win == NULL) {
- return(0);
- }
- /* Wait a while for any button to go up */
- firstmev.event = TRUE; /* use firstmev.event as a first-flag */
- if (duration != (unsigned)-1) {
- itime = hard_Timer();
- }
- for (;;) {
- /* Check first in case no events pending */
- if (win_CheckEventWait(win, duration)) {
- if ((evcode = win_ReadEvent(win, mev)) == MOU_EVENT) {
-
- if (moveout(&firstmev, mev)) {
- break; /* return MOU_EVENT */
- }
- if (!mev_IsButtonDown(mev)) {
- break; /* return MOU_EVENT */
- }
- }
- else break; /* return Keystroke */
- }
- else return(MOU_HOLDDOWN); /* time expired with no event */
-
- /* Going around again - reduce wait duration by what has now elapsed */
- if (duration != (unsigned)-1) {
- /* Note: this block of code should be made atomic somehow */
- ttime = hard_Timer();
- /* Double check in case time has now expired */
- if ((tdiff = dig_SubHsecs(itime, ttime)) > duration) {
- return(MOU_HOLDDOWN); /* Hold-down */
- }
- duration -= tdiff;
- itime = ttime;
- }
- }
- return(evcode);
- }
- /* -------------------------------------------------------------------------- */
-
- unsigned win_MouseDblClick(win, mev)
- win_type win;
- mev_struct *mev;
- /*
- Returns MOU_DCLICK if a fresh button press event is detected within a few
- fractions of a second. Returns MOU_HOLDDOWN if a button was held down during
- the whole interval.
- If a keystroke is gotten, this function returns immediately with the
- scancode value.
- On return, mev contains the last recorded mouse event.
- If no mouse events occur while control is in this function, mev is
- unaltered and MOU_HOLDDOWN is returned. (It is assumed that you only call
- this function if a button down event has occurred).
- */
- {
- unsigned itime, ttime, tdiff;
- unsigned duration;
- mev_struct firstmev;
- unsigned oldevent;
- unsigned evcode;
- boolean stillheld;
-
- if (win == NULL) {
- return(0);
- }
- /* Start as if all buttons were pressed */
- oldevent = (MEV_BUT1 | MEV_BUT2 | MEV_BUT3);
- stillheld = TRUE; /* assume function was called w/ button down */
-
- /* Wait a while for any button to go up and then get pressed again */
- duration = disp_MouseTimeout();
- firstmev.event = TRUE; /* use firstmev.event as a first-flag */
- itime = hard_Timer();
-
- for (;;) {
- /* Check first in case no events pending */
- if (win_CheckEventWait(win, duration)) {
- if ((evcode = win_ReadEvent(win, mev)) == MOU_EVENT) {
-
- if (moveout(&firstmev, mev)) {
- return(MOU_EVENT); /* Too much motion */
- }
- if (mev_ButtonGoneDown(oldevent, mev->event)) {
- return(MOU_DCLICK); /* Double click */
- }
- if (!mev_IsButtonDown(mev)) {
- stillheld = FALSE; /* clear hold-down flag */
- }
- oldevent = mev->event;
- }
- else return(evcode); /* return Keystroke */
- }
- else return(MOU_HOLDDOWN); /* time expired with no event */
-
- /* Going around again - reduce wait duration by what has now elapsed */
- /* Note: this block of code should be made atomic somehow */
- ttime = hard_Timer();
- /* Double check in case time has now expired */
- if ((tdiff = dig_SubHsecs(itime, ttime)) > duration) {
- if (stillheld) {
- return(MOU_HOLDDOWN); /* Hold-down */
- }
- else return(MOU_EVENT); /* Timeout w/ button up */
- /* Note: if stillheld is FALSE, a mouse event must have occurred */
- }
- duration -= tdiff;
- itime = ttime;
- }
- }
- /* -------------------------------------------------------------------------- */
-
- static boolean OWLPRIV moveout(firstmev, currmev)
- mev_struct *firstmev;
- mev_struct *currmev;
- /*
- Returns TRUE if the mouse position moved too far.
- */
- {
- if (firstmev->event) {
- firstmev->x = currmev->x; firstmev->y = currmev->y;
- firstmev->event = FALSE;
- return(FALSE);
- }
- else return(mev_MovedOut(firstmev, currmev, disp_MouseDistout()));
- }
- /* -------------------------------------------------------------------------- */
-
-