home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SDMOUDRG.C
< prev
next >
Wrap
Text File
|
1990-10-04
|
5KB
|
186 lines
/*
sdmoudrg.c 8/21/90
% sedmou_Drag
by Ted
"Dragging" mouse handler.
Highlights all fields you drag over and returns a "CLICK" code for the
field you release over. (When the mouse button is released over the field,
the kb_Stuff code is set to MOU_CLICK.)
Gets private mouse events while mouse is dragged outside window.
C-scape 3.2
Copyright (c) 1989 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
9/23/90 ted Made it greedy in EVENT instead of sucking events in ENDEVENT.
10/04/90 ted Cancelled the MOU_HERE if GotoField was not successful.
*/
#include <stdio.h>
#include <string.h>
#include "cscape.h"
#include "oakpriv.h"
#include "winpriv.h" /* For wmgr_lastmev, wmgr_currmev */
#include "scancode.h" /* for MOU codes */
/* -------------------------------------------------------------------------- */
int sedmou_Drag(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;
boolean first;
first = FALSE;
switch (msg) {
case MEV_STARTOFFER: /* we're not the current window */
win_SetDebounced(sed, mev_IsButtonDown(mev));
if (mev_IsFake()) {
mev_ClearEvent(mev); /* Don't accept it */
break;
}
/* no break, fall through */
case MEV_OFFER: /* we're not the current window */
/* If button pressed accept the offer */
if (!mev_IsButtonDown(mev)) {
win_SetDebounced(sed, FALSE);
mev_ClearEvent(mev); /* Don't accept it */
}
else { /* button pressed */
/* Accept the offer */
win_SetDebounced(sed, TRUE);
sedmev_acceptoffer(sed, mev, TRUE);
}
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:
/* If only a border/window transition, treat this event like no start */
if (!(wmgr_lastmev()->win == wmgr_currmev()->win &&
wmgr_currmev()->incurrent == wmgr_lastmev()->incurrent)) {
win_SetDebounced(sed, mev_IsButtonDown(mev));
if (!mev_IsButtonDown(mev)) {
if (!sed_IsActive(sed)) {
sed_SetActive(sed, TRUE);
sed_GotoFirstField(sed);
}
}
else disp_TrapMouse(sed); /* Trap mouse while button is down */
first = TRUE;
}
/* no break, fall through */
case MEV_EVENT: /* we're the current window */
{
ocbox mbox;
if (mev_IsButtonDown(mev)) {
if (!win_GetDebounced(sed)) {
disp_TrapMouse(sed); /* Trap mouse when button goes down */
}
if (!mev->inborder && !mev->outside) {
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);
}
else fld = -1;
if (fld >= 0) { /* In a field, and it's not protected */
if (fld != sed_GetFieldNo(sed) ||
first || !win_GetDebounced(sed)) {
win_SetDebounced(sed, TRUE);
sed_SetActive(sed, TRUE);
if (sed_GotoField(sed, fld) == SED_MOVED) {
/* Return MOU_HERE as a scancode to kb_Read. We return it even if
the button hasn't been released because we have changed fields
and we want to leave the current field immediately.
*/
return(MOU_HERE);
}
}
else if (!sed_IsActive(sed)) {
sed_SetActive(sed, TRUE);
sed_GotoField(sed, sed_GetFieldNo(sed));
}
}
else { /* In no field or a protected one */
/* Turn off any highlighted field while we're dragging */
if (sed_IsActive(sed)) { /* && !mev_IsFake() */
sed_SetActive(sed, FALSE);
sed_GotoField(sed, sed_GetFieldNo(sed));
}
}
win_SetDebounced(sed, TRUE);
}
else { /* Button is up */
if (win_GetDebounced(sed)) {
win_SetDebounced(sed, FALSE);
/* When the mouse is released, if a field is active, CLICK it */
if (sed_IsActive(sed)) { /* A field is highlighted */
/* Set our mousecode to tell us that the mouse was released
when our field function is eventually called.
*/
kb_Stuff(MOU_CLICK);
return(MOU_HERE);
}
else {
/* No field was selected when the mouse was released, so
just go back to the first field and reactivate the sed.
*/
sed_SetActive(sed, TRUE);
sed_GotoFirstField(sed);
/* Exit to restore trapwin; re-enter ourselves */
win_SetNextWin(sed, sed);
return(MOU_THERE);
}
}
}
break;
}
case MEV_ENDEVENT: /* we're the current window */
break;
}
return(MOU_IGNORE); /* Ignore this mouse event */
}
/* -------------------------------------------------------------------------- */