home *** CD-ROM | disk | FTP | other *** search
- /*
- sdmoutrk.c 10/27/89
-
- % sedmou_Track
-
- The "tracking" mouse handler.
- Jumps to whatever field the mouse is pointing to.
- When a mouse button is clicked over the field, the sed Mouse Code
- is set to MOU_CLICK.
-
- If the field is in a different sed, and both seds have mouse handlers,
- then the first sed is exited and control is passed to the new sed.
-
- C-scape 3.2
- Copyright (c) 1986, 1987, 1988 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 5/15/89 jmd added debouncing
- 6/07/89 jmd renamed mouse codes
- 6/15/89 jmd added additional debouncing
- 8/12/89 jmd removed call to sed_GetBob
- 8/16/89 jdc fixed in bob REQUEST nextwin = (jumpwin == NULL) bug
- 8/29/89 jmd added test for 'fake' events
- 9/10/89 jmd added mev_ClearEvent to fake event test
-
- 1/04/90 jmd restructured
- 1/24/90 ted Revamped for new nested MEV_START/STOPCUR msg scheme.
- 3/03/90 ted/pmcm Added support for sed_FindField -2 return in case of protected fields.
- 3/28/90 jmd ansi-fied
- 4/13/90 jmd added MOU_NOFIELD support
- 5/12/90 jmd mouse handlers now return ints
- 8/17/90 ted Changed references from sed_SetMouseCode to kb_Stuff.
- 9/24/90 ted Cancelled the MOU_HERE if GotoField was not successful.
- */
-
- #include <stdio.h>
- #include "cscape.h"
-
- #include "scancode.h" /* for MOU codes */
-
- int sedmou_Track(sed_type sed, int msg, mev_struct *mev)
- /*
- Messages a mouse handler receives when its window is current
- MEV_REQUEST someone else wants to be it
- MEV_STARTEVENT current, mouse entered
- MEV_EVENT current, event in win
- MEV_ENDEVENT current, mouse left
- Messages a mouse handler receives when its window is not current
- MEV_STARTOFFER not current, mouse entered
- MEV_OFFER not current, event in win
- MEV_ENDOFFER not current, mouse left
- */
- {
- int fld;
-
- switch (msg) {
- case MEV_STARTOFFER: /* we're not the current window */
- win_SetDebounced(sed, mev_IsButtonDown(mev));
-
- if (mev_IsFake()) { /* ignore 'fake' events */
- mev_ClearEvent(mev);
- break;
- }
- /* no break, fall through */
-
- case MEV_OFFER: /* we're not the current window */
- /* Accept the offer */
- if ((fld = sedmev_acceptoffer(sed, mev, msg == MEV_STARTOFFER)) == -2) {
- break;
- }
- if (!mev_IsButtonDown(mev)) {
- win_SetDebounced(sed, FALSE);
- }
- else {
- if (!win_GetDebounced(sed)) {
- win_SetDebounced(sed, TRUE);
-
- /* Set the mouse code to tell us that the mouse was clicked
- when our field function is eventually called
- */
- if (fld != -1 && !mev_IsFake()) { /* ignore 'fake' clicks */
- kb_Stuff(MOU_CLICK);
- }
- else if (fld == -1 && !mev_IsFake()) {
- /* clicked, but not over a field */
- kb_Stuff(MOU_NOFIELD);
- }
- }
- }
- /* We don't care what code we return because we accepted the
- offer, which means the REQUEST message gets to decide what
- to return from this particular kb_Read call */
- break;
-
- case MEV_ENDOFFER: /* we're not the current window */
- break;
-
- case MEV_REQUEST: /* we're the current window;
- another window was selected by the mouse. */
- winmev_grantrequest(sed, mev);
-
- /* Return MOU_THERE as a scancode to kb_Read to tell the sed
- about the request so it can exit */
- return(MOU_THERE);
-
- case MEV_STARTEVENT:
- win_SetDebounced(sed, mev_IsButtonDown(mev));
- if (mev_IsFake() && !kb_WasMouse()) {
- break; /* ignore 'fake' events */
- }
-
- /* no break, fall through */
-
- case MEV_EVENT: /* we're the current window */
- {
- ocbox mbox;
- boolean ret = FALSE;
-
- mbox.toprow = mbox.botrow = mev_GetRow(mev) + sed_GetYoffset(sed);
- mbox.leftcol = mbox.rightcol = mev_GetCol(mev) + sed_GetXoffset(sed);
-
- /* sed_FindField finds the best field in the given box */
- fld = sed_FindField(sed, &mbox, OAK_DOWN);
-
- if (!mev_IsButtonDown(mev)) {
- win_SetDebounced(sed, FALSE);
- }
- else {
- if (!win_GetDebounced(sed)) {
- win_SetDebounced(sed, TRUE);
- ret = TRUE;
-
- /* Set our mousecode to tell us that the mouse was clicked
- when our field function is eventually called. */
- if (fld >= 0) {
- kb_Stuff(MOU_CLICK);
- }
- else {
- /* clicked, but not over a field */
- kb_Stuff(MOU_NOFIELD);
- }
- }
- }
-
- /* go to the new field */
- if (fld >= 0 && fld != sed_GetFieldNo(sed)) {
- if (sed_GotoField(sed, fld) == SED_MOVED) {
- ret = TRUE;
- }
- }
- if (ret) {
- /* Return MOU_HERE as a scancode to kb_Read. We return it even if
- the button hasn't been pressed because we have changed fields
- and we want to leave the current field immediately.
- */
- return(MOU_HERE);
- }
- }
- case MEV_ENDEVENT: /* we're the current window */
- break;
- }
- return(MOU_IGNORE); /* Ignore this mouse event */
- }
-