home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
cdity
/
yak
/
src
/
handler.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-27
|
19KB
|
581 lines
/*
* handler.c
*
* Routines to set up handler.
* Part of Yak.
*
* Martin W. Scott, 9/92.
*/
#include <exec/types.h>
#include <exec/exec.h>
#include <hardware/custom.h>
#include <hardware/dmabits.h>
#include <devices/console.h>
#include <devices/input.h>
#include <devices/inputevent.h>
#include <libraries/commodities.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
#include <graphics/displayinfo.h>
#include <intuition/intuition.h>
#include <intuition/intuitionbase.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/layers.h>
#include <proto/graphics.h>
#include <proto/intuition.h>
#include <proto/commodities.h>
#include <string.h>
#include <stdio.h>
#include "code.h"
#include "yak.h"
#include "beep.h"
void TurnMouseOn (void);
static void TurnMouseOff (void);
static __regargs void IntuiOp (void (*routine) (APTR), APTR parameter);
static __regargs void PopToFront (struct Window *win);
static struct Window *WindowUnderMouse (void);
static __regargs BOOL StrGadgetActive (struct Window *w);
extern __far struct Custom custom;
#define REBLANKCOUNT 10 /* how long to wait to reblank mouse */
void (*intui_routine) (APTR); /* for intui_op's */
APTR intui_parameter;
CxObj *clickobj;
ULONG clicksigflag, intuiopsigflag, blankscreensigflag;
static BYTE clicksigbit, blankscreensigbit, intuiopsigbit = -1;
static struct Task *thistask;
static BOOL misspop;
/* for screen click-to-back */
STACKARGS void
MyScreenToBack (struct Screen *scr)
{
RememberActiveWindow();
ScreenToBack (scr);
ActivateMouseWindow (SCREEN);
}
/* Stub for Intuition routines - passes request on to main task.
* DO NOT CALL WHILE FORBID()ING!
* Thanks to Eddy Carroll for this.
*/
#define WTB(win) IntuiOp(WindowToBack, win)
#define WTF(win) IntuiOp(WindowToFront, win)
#define WACT(win) IntuiOp((void (*)(APTR))ActivateWindow, win)
#define STB(scr) IntuiOp(MyScreenToBack, scr)
#define STF(scr) IntuiOp(ScreenToFront, scr)
static __regargs void
IntuiOp (void (*routine) (APTR), APTR parameter)
{
BYTE oldpri = SetTaskPri (thistask, 21);
intui_routine = routine;
intui_parameter = parameter;
Signal (thistask, intuiopsigflag);
SetTaskPri (thistask, oldpri);
}
/* pattern-matching on screen/window titles */
#define IsXXXScreen(scr, pat) (scr && (!scr->DefaultTitle || MatchPattern(pat, scr->DefaultTitle)))
#define IsClickScreen(scr) IsXXXScreen(scr, clickscrpat)
#define IsAutoScreen(scr) IsXXXScreen(scr, autoscrpat)
#define IsXXXWindow(win, pat) (!win->Title || MatchPattern(pat, win->Title))
#define IsPopWindow(win) IsXXXWindow(win,popwinpat)
#define IsClickWindow(win) IsXXXWindow(win,clickwinpat)
/* when is a window safe to bring to front and not already at front? */
#define OkayToPop(win) (!win->ReqCount && !(win->Flags & (WFLG_MENUSTATE|WFLG_BACKDROP)) \
&& win->WLayer->ClipRect && win->WLayer->ClipRect->Next)
/* WindowToFront only if no requester, not backdrop, not already front... */
static __regargs void
PopToFront (struct Window *win)
{
/* want to avoid popping immediately after mousebutton/keyboard */
if (misspop)
misspop = FALSE;
else if (OkayToPop (win))
{
/* Does it pass pattern? */
if (IsPopWindow (win))
WTF (win);
}
}
/* modified from DMouse */
/* expects multitasking to be Forbid()en */
static struct Screen *mousescr; /* the screen under the mouse */
struct Screen
*ScreenUnderMouse( void )
{
struct Screen *scr;
ULONG lock;
lock = LockIBase(0);
for (scr = FS;
(scr && scr->TopEdge > 0) && (scr->MouseY < 0);
scr = scr->NextScreen);
UnlockIBase(lock);
return(scr);
}
static struct Window
*WindowUnderMouse( void )
{
struct Layer *layer = NULL;
ULONG lock;
lock = LockIBase(0);
for (mousescr = FS;
mousescr && (mousescr->TopEdge > 0) && (mousescr->MouseY < 0);
mousescr = mousescr->NextScreen);
UnlockIBase(lock);
if (mousescr)
layer = WhichLayer(&mousescr->LayerInfo, mousescr->MouseX, mousescr->MouseY);
return (layer ? (struct Window *) layer->Window : NULL);
}
/* does active window have an active string gadget? */
static __regargs BOOL
StrGadgetActive (struct Window *w)
{
struct Gadget *g = w->FirstGadget;
for (; g; g = g->NextGadget)
if ((g->GadgetType & STRGADGET) && (g->Flags & GFLG_SELECTED))
return TRUE;
return FALSE;
}
/* activate window under mouse */
/* context sensitive; why tells routine how to behave */
/* can be AUTO, KEY, SCREEN, RMBACT */
__regargs void
ActivateMouseWindow (BYTE why)
{
struct Window *win = NULL, *IB_ActiveWindow;
ULONG lock;
if ((why != SCREEN) || scractivate)
{
if (why == SCREEN)
win = LastActiveWindow(ScreenUnderMouse());
if (!win)
win = WindowUnderMouse ();
if (win) /* window exists to activate */
{
/* either window is not active or auto-activating - need to pop? */
if (win->Flags & WFLG_WINDOWACTIVE) /* already active - needs popped? */
{
if (why == AUTO && autopop && IsAutoScreen (win->WScreen))
{
PopToFront (win);
}
}
else if (why != AUTO || IsAutoScreen (win->WScreen))
{
/* window is not active, should we try to activate it? */
lock = LockIBase(0);
IB_ActiveWindow = AW; /* AW is IntuitionBase->ActiveWindow */
UnlockIBase(lock);
if (!IB_ActiveWindow ||
!(IB_ActiveWindow->Flags & WFLG_MENUSTATE) && /* not showing menus */
!(why == KEY && StrGadgetActive (IB_ActiveWindow))) /* no str gad active */
{
/* do autopop? */
if (why == AUTO && autopop)
PopToFront (win);
if (why == KEY)
ActivateWindow (win); /* need this to avoid losing keys */
else
WACT (win); /* ...activate window */
}
}
}
else
{
lock = LockIBase(0);
IB_ActiveWindow = AW; /* AW is IntuitionBase->ActiveWindow */
UnlockIBase(lock);
if (scractivate && mousescr && mousescr->FirstWindow &&
((why == SCREEN) ||
(why == RMBACT && IB_ActiveWindow && IB_ActiveWindow->WScreen != mousescr)))
{
WACT (mousescr->FirstWindow); /* ...activate window */
}
}
}
}
static __chip UWORD posctldata[4];
static struct SimpleSprite simplesprite =
{posctldata, 0, 0, 0, 0};
static BOOL mouseoff; /* is mouse off? (MB_SPRITES only) */
void
TurnMouseOn () /* restore mouse-pointer */
{
if (mouseblank == MB_SPRITES) /* really dirty blanking */
{ /* but guaranteed to work... */
if (mouseoff)
{
Forbid ();
WaitTOF ();
ON_SPRITE;
Permit ();
}
}
else
{
RethinkDisplay();
}
mouseoff = FALSE;
}
static void
TurnMouseOff () /* blank mouse-pointer */
{
if (!mouseoff) /* no point in turning it off twice... */
{
Forbid ();
if (mouseblank == MB_SPRITES)
{
WaitTOF ();
OFF_SPRITE;
custom.spr[0].dataa = custom.spr[0].datab = 0; }
else
{
ChangeSprite(NULL, &simplesprite, (APTR)posctldata);
}
Permit ();
mouseoff = TRUE;
}
}
static BOOL blanked;
static struct Screen *blankscr;
/* blank display, by putting up a black screen