home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QBasic & Borland Pascal & C
/
Delphi5.iso
/
C
/
Samples
/
CSAPE32.ARJ
/
SOURCE
/
CSSRC
/
SDMOUFRM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-12-19
|
11KB
|
362 lines
/*
sdmoufrm.c
% sedmou_Framer
12/09/89 Re-created by Ted.
A mousehandler for framer menus.
C-scape 3.2
Copyright (c) 1988, 1989 by Oakland Group, Inc.
ALL RIGHTS RESERVED.
Revision History:
-----------------
1/24/90 ted Fixed a lot of stuff to get more SAA-like.
1/28/90 ted Added fixes for when borders pass msgs through.
2/14/90 ted Added MEV_STARTCUR check when setting framer flag.
3/03/90 ted/pmcm Fixed ufunc/child popup return case.
3/03/90 ted/pmcm Added support for sed_FindField -2 return in case of protected fields.
3/28/90 jmd ansi-fied
4/08/90 ted Fixed pulldown bug pmcm and I made on 3/3/90 when we fixed the ufunc rtn case.
5/12/90 jmd mouse handlers now return ints
8/13/90 ted Changed references from sed_SetMouseCode to kb_Stuff.
8/13/90 ted Modified framer bit test to allow sub-pulldowns.
8/29/90 ted Reconstructed to have more SAA-like mouse behavior.
9/11/90 ted Fixed null-mev bug in 'inside' assignment.
9/15/90 ted Added missing break in MEV_STARTCUR case.
9/23/90 ted Overhauled to make 'demofram' still work.
10/04/90 ted Fixed ufunc popmenu vacuum click bug.
10/16/90 ted fixed framer test loop so embedded framers will work.
12/04/90 ted checked for when CurrentWin is NULL.
12/19/90 ted/jdc changed outside startevent/event case to check mev_IsFake.
*/
#include <stdio.h>
#include "cscape.h"
#include "oaktag.h" /* For ID in bob_IsUfunc */
#include "msys.h"
#include "scancode.h" /* for MOU codes */
/* -------------------------------------------------------------------------- */
int sedmou_Framer(sed_type sed, int msg, mev_struct *mev)
/*
Messages a mouse handler receives when its window is current
MEV_REQUEST current; someone else wants to be current
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
*/
{
win_type parent;
boolean inside;
/* The first time this happens we need to set the framer true */
if (msg == MEV_STARTOFFER || msg == MEV_STARTCUR) {
/* If we're the first here, we're the top framer, so we set a bit so our
kids won't think they're it. */
if (!msys_IsFramer(sed)) {
parent = sed;
for (;;) {
if ((parent = bob_GetParent(parent)) == NULL) {
msys_SetFramer(sed, TRUE);
break;
}
if (msys_IsFramer(parent)) {
break;
}
}
}
}
if (msys_IsFramer(sed)) {
if (mev != NULL) { /* not STARTCUR or STOPCUR message */
inside = (mev_GetX(mev) >= 0 && mev_GetY(mev) >= 0 &&
mev_GetX(mev) < win_GetPixWidth(sed) &&
mev_GetY(mev) < win_GetPixHeight(sed));
}
/* Use sedmou_Drag behavior for framer top menu, except special cases. */
if (inside || msg == MEV_REQUEST ||
msg == MEV_STARTCUR || msg == MEV_STOPCUR) {
switch (msg) {
case MEV_STARTCUR:
/* Trap all mouse events while we're the current window */
disp_TrapMouse(sed);
break;
case MEV_STOPCUR:
break;
case MEV_STARTOFFER: /* we're not the current window */
win_SetDebounced(sed, mev_IsButtonDown(mev));
case MEV_OFFER:
{
ocbox mbox;
int fld;
/* If current window is a child of ours, don't accept offer
but return a code to exit the child */
parent = disp_GetCurrentWin();
for (;;) {
if (parent == NULL) {
return(sedmou_Drag(sed, msg, mev));
}
parent = bob_GetParent(parent);
if (parent == sed) {
break;
}
}
if (!mev_IsFake()) {
if (mev_IsButtonDown(mev)) {
if (win_GetDebounced(sed)) {
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);
}
/* Exit dropdown for click or new field in framer menu */
if (!win_GetDebounced(sed) ||
fld != sed_GetFieldNo(sed)) {
win_SetDebounced(sed, TRUE);
mev_ClearEvent(mev); /* Don't accept it */
return(MOU_THERE); /* code to dropdown func to exit */
}
}
else { /* No button */
parent = disp_GetCurrentWin();
if (parent !=NULL && !sed_IsActive(parent)) {
sed_SetActive(parent, TRUE);
sed_GotoFirstField(parent);
}
}
}
win_SetDebounced(sed, mev_IsButtonDown(mev));
mev_ClearEvent(mev); /* Don't accept it */
}
case MEV_ENDOFFER:
break;
case MEV_REQUEST:
/* We never get requests because child never accepts offer */
break;
case MEV_STARTEVENT:
case MEV_EVENT:
{
boolean wasactive;
int ret;
/* Override the _Drag handler by just quitting in this case */
if (!mev_IsButtonDown(mev) && !sed_IsActive(sed)) {
win_SetDebounced(sed, FALSE);
return(MOU_THERE);
}
wasactive = sed_IsActive(sed);
ret = sedmou_Drag(sed, msg, mev);
/* Note: no need to un-trap because we were already trapping */
if (ret == MOU_HERE) {
kb_Stuff(MOU_IGNORE); /* Un-stuff any click code */
if (mev_IsButtonDown(mev)) {
/* Button was pressed on a field or dragged to a new field */
return(MOU_CLICK);
}
else {
/* Button was released on a field */
return(MOU_RELEASE);
}
}
else {
if (wasactive && !sed_IsActive(sed)) {
/* Left an active field */
return(MOU_NOFIELD);
}
}
}
case MEV_ENDEVENT:
break;
}
}
else { /* Event came outside of framer bar (it's greedy) */
switch(msg) {
case MEV_STARTOFFER: /* we're not the current window */
{
mev_struct mevs;
win_SetDebounced(sed, mev_IsButtonDown(mev));
/* If event is from a bob of the dropdown, suck up mouse events
until button rises so that exiting greedy popups will not
make us do anything
*/
if (mev_IsButtonDown(mev) && mev_IsFake()) {
for (;;) {
if (win_ReadEvent(sed, &mevs) == MOU_EVENT) {
/* If button released in same field */
if (!mev_IsButtonDown(&mevs)) {
win_SetDebounced(sed, FALSE);
break;
}
}
}
mev_ClearEvent(mev); /* Don't accept it */
break;
}
/* no break; fall through */
}
case MEV_OFFER:
{
win_type child;
/* Outside window: dropdown must be current because we must be
greedy to get such an event & that means only children can
be current */
/* If button is pressed or released, return a quit msg */
if (win_GetDebounced(sed) ^ mev_IsButtonDown(mev)) {
mev_ClearEvent(mev); /* Don't accept it */
return(MOU_THERE); /* code to dropdown func to exit */
}
/* Turn off any highlighted field while we're dragging */
child = disp_GetCurrentWin();
if (mev_IsButtonDown(mev) && child != NULL && sed_IsActive(child)) {
sed_SetActive(child, FALSE);
sed_GotoField(child, sed_GetFieldNo(child));
}
mev_ClearEvent(mev); /* Don't accept it */
break;
}
case MEV_STARTEVENT:
win_SetDebounced(sed, mev_IsButtonDown(mev));
case MEV_EVENT:
{
bob_type bob;
if (!kb_WasMouse() || mev_IsFake()) {
break;
}
/* Quit the framer if dropdown was aborted by an outside mev */
if (msys_IsFrameRtn(sed)) {
return(MOU_THERE);
}
else {
if (msg == MEV_STARTEVENT ||
(mev_IsButtonDown(mev) != win_GetDebounced(sed))) {
win_SetDebounced(sed, mev_IsButtonDown(mev));
/* If current field has no bob, quit the framer */
bob = sed_GetFieldBob(sed, sed_GetFieldNo(sed));
if (bob == NULL || bob_IsUfunc(bob) || !win_IsEmployed(bob)) {
return(MOU_THERE);
}
else { /* field has a bob */
/* Mouse has left the framer bar but is not in the
dropdown. This case should act just like when the
mouse is in the bob's framer field */
if (!mev_IsButtonDown(mev)) {
return(MOU_RELEASE);
}
}
}
}
break;
case MEV_ENDEVENT:
break;
}
}
}
}
/* Use the following special behavior for framer dropdown menus */
else switch (msg) {
case MEV_STARTOFFER: /* A child or parent of the dropdown must be */
case MEV_OFFER: /* current; otherwise the dropdown is never up. */
/* If parent framer is current, send it a code to enter us */
if (win_GetParent(sed) == disp_GetCurrentWin()) {
mev_ClearEvent(mev); /* Don't accept it */
return(ENTER);
}
/* no break; */
case MEV_ENDOFFER: /* present without being current */
mev_ClearEvent(mev); /* Don't accept it */
break;
case MEV_REQUEST: /* We're current; someone else wants to be current */
/* Request must be from parent framer bar, because it's greedy and its
children don't accept offers */
/* Don't grant request because we're in a nested 'go', but
return MOU_THERE as a scancode to kb_Read to tell the dropdown func
about the request so it can exit */
return(MOU_THERE);
case MEV_STARTEVENT:
{
mev_struct mevs;
if (mev_IsButtonDown(mev)) {
if (msys_IsFrameRtn(sed) && mev_IsFake()) {
/* If event is from a bob of the dropdown, suck up mouse events
until button rises so that exiting greedy popups will not
make us do anything
*/
for (;;) {
if (win_ReadEvent(sed, &mevs) == MOU_EVENT) {
/* If button released in same field */
if (!mev_IsButtonDown(&mevs)) {
win_SetDebounced(sed, FALSE);
break;
}
}
}
break;
}
else { /* not coming from a bob */
win_SetDebounced(sed, TRUE);
/* Unhighlight lit field and go on to sedmou_Drag */
sed_SetActive(sed, FALSE);
sed_GotoField(sed, sed_GetFieldNo(sed));
}
}
else { /* Button not down */
win_SetDebounced(sed, FALSE);
}
/* no break, fall through */
}
case MEV_EVENT:
{
win_type oldtrap;
int ret;
oldtrap = disp_GetMouseTrap();
ret = sedmou_Drag(sed, msg, mev);
disp_TrapMouse(oldtrap); /* Undo any trapping Drag did */
return(ret);
}
case MEV_ENDEVENT:
break;
}
return(MOU_IGNORE); /* Ignore this mouse event */
}
/* -------------------------------------------------------------------------- */