home *** CD-ROM | disk | FTP | other *** search
- /*
- * © Pierre Dak Baillargeon 1991.
- *
- *
- * NAME
- * Windex.c -- Translate RAWKEY to CLOSEWINDOW events.
- *
- * SYNOPSIS
- * Windex
- *
- * FUNCTION
- * Scan the input event chain to translate the esc keycode from
- * RAWKEY events in CLOSEWINDOW events and WindowToFront calls.
- *
- * DESCRIPTION
- * Scan the event one by one. If its class is RAWKEY, its code
- * is ESC and its qualifier CTRL, then take the currently active
- * window and put it in the event address field and set the class
- * to CLOSEWINDOW. If the code is an arrow key, browse through
- * the list of windows and screens.
- *
- * The scanner take the active window pointer from IntuitionBase.
- * It also check for ACTIVEWINDOW class events. When it finds one,
- * it update its internal active window pointer (NOT the one found
- * in IntuitionBase. Let it do that by itself !).
- *
- * NOTE
- * I might let the user choose his own keycode and qualifier. But
- * that would requires that he knew the keycode and qualifier codes
- * unless we would create a translation table, which would increase
- * substantially the executable size.
- *
- * To stop Windex, hit ctrl-C or use the break CLI command.
- *
- */
-
-
- void main(void);
- void PopScreen (struct IntuitionBase *);
- void PushScreen (struct IntuitionBase *);
- void PopWindow (struct IntuitionBase *);
- void PushWindow (struct IntuitionBase *);
- struct InputEvent * __asm Handler (register __a0 struct InputEvent *, register __a1 struct IntuitionBase *);
-
-
- void main(void)
- {
- struct IntuitionBase * IntuitionBase;
- struct MsgPort * InputPort = NULL;
- struct Interrupt * InputHandler = NULL;
- struct IOStdReq * InputReq = NULL;
-
- if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary ("intuition.library", 0L)))
- {
- if ((InputPort = CreatePort (0L, 0L)))
- {
- if ( (InputReq = (struct IOStdReq *)CreateExtIO (InputPort, sizeof (struct IOStdReq))))
- {
- if (!OpenDevice ("input.device", NULL, InputReq, NULL))
- {
- if ( (InputHandler = AllocMem (sizeof (struct Interrupt), MEMF_PUBLIC|MEMF_CLEAR)))
- {
- InputHandler->is_Code = (void (*__far)(void))Handler;
- InputHandler->is_Data = (APTR)IntuitionBase;
- InputHandler->is_Node.ln_Pri = 100;
- InputHandler->is_Node.ln_Name = "Escape Window";
-
- InputReq->io_Command = IND_ADDHANDLER;
- InputReq->io_Data = (APTR)InputHandler;
- DoIO (InputReq);
-
- Wait (SIGBREAKF_CTRL_C);
-
- InputReq->io_Command = IND_REMHANDLER;
- InputReq->io_Data = (APTR)InputHandler;
- DoIO (InputReq);
-
- FreeMem (InputHandler, sizeof (struct Interrupt));
- }
- CloseDevice (InputReq);
- }
- DeleteExtIO (InputReq);
- }
- DeletePort (InputPort);
- }
- CloseLibrary (IntuitionBase);
- }
- }
-
- #define ESC 0x45
- #define LEFT 0x4F
- #define RIGHT 0x4E
- #define UP 0x4C
- #define DOWN 0x4D
- #define QUAL IEQUALIFIER_CONTROL
-
- struct InputEvent * __asm Handler (register __a0 struct InputEvent *chain, register __a1 struct IntuitionBase *IntuitionBase)
- {
- struct InputEvent *ie = chain;
-
- while (ie)
- {
- if (ie->ie_Class == IECLASS_RAWKEY)
- {
- if (ie->ie_Qualifier & QUAL)
- {
- switch (ie->ie_Code)
- {
- case ESC:
- if (IntuitionBase->ActiveWindow->IDCMPFlags & CLOSEWINDOW)
- {
- if ( (IntuitionBase->ActiveWindow->Flags & BACKDROP+WBENCHWINDOW) != BACKDROP+WBENCHWINDOW)
- {
- ie->ie_Class = IECLASS_CLOSEWINDOW;
- ie->ie_EventAddress = (APTR)IntuitionBase->ActiveWindow;
- }
- }
- break;
- case UP:
- PushScreen (IntuitionBase);
- ie->ie_Class = IECLASS_NULL;
- break;
- case DOWN:
- PopScreen (IntuitionBase);
- ie->ie_Class = IECLASS_NULL;
- break;
- case RIGHT:
- PushWindow (IntuitionBase);
- ie->ie_Class = IECLASS_NULL;
- break;
- case LEFT:
- PopWindow (IntuitionBase);
- ie->ie_Class = IECLASS_NULL;
- break;
- default:
- break;
- }
- }
- }
- ie = ie->ie_NextEvent;
- }
- return chain;
- }
-
-
- void PopScreen (struct IntuitionBase *IntuitionBase)
- {
- struct Screen *s = IntuitionBase->ActiveScreen;
-
- if (s != NULL)
- {
- while (s->NextScreen)
- s = s->NextScreen;
- ScreenToFront (s);
- if (s->FirstWindow)
- ActivateWindow (s->FirstWindow);
- }
- }
-
-
- void PushScreen (struct IntuitionBase *IntuitionBase)
- {
- struct Screen *s = IntuitionBase->ActiveScreen;
-
- if (s)
- {
- ScreenToBack (s);
- s = IntuitionBase->FirstScreen;
- if (s)
- {
- if (s->FirstWindow)
- {
- ActivateWindow (s->FirstWindow);
- }
- }
- }
- }
-
-
- void PopWindow (struct IntuitionBase *IntuitionBase)
- {
- struct Window *w = IntuitionBase->ActiveWindow;
- struct Window *nw;
-
- if (w)
- {
- nw = IntuitionBase->ActiveScreen->FirstWindow;
- while (nw->NextWindow != NULL && nw->NextWindow != w)
- nw = nw->NextWindow;
- if (nw != w)
- {
- WindowToFront (nw);
- ActivateWindow (nw);
- }
- }
- }
-
-
- void PushWindow (struct IntuitionBase *IntuitionBase)
- {
- struct Window *w = IntuitionBase->ActiveWindow;
- struct Window *nw;
-
- if (w)
- {
- if ((nw = w->NextWindow) == NULL)
- nw = IntuitionBase->ActiveScreen->FirstWindow;
- if (nw != w)
- {
- WindowToBack (w);
- ActivateWindow (nw);
- }
- }
- }
-