home *** CD-ROM | disk | FTP | other *** search
- /* amiga_eventloop.c -- Eventloop for AmigaDOS
- Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
-
- This file is part of Jade.
-
- Jade is free software; you can redistribute it and/or modify it
- under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- Jade is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Jade; see the file COPYING. If not, write to
- the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
-
- #include "jade.h"
- #include "jade_protos.h"
-
- #define INTUI_V36_NAMES_ONLY
- #include <clib/intuition_protos.h>
- #include <intuition/gadgetclass.h>
- #include <string.h>
-
- _PR VALUE eventloop(void);
-
- VALUE
- handleevent(struct IntuiMessage *imsg)
- {
- VW *oldvw = CurrVW, *ev_vw;
- VALUE result = sym_nil;
- ev_vw = (VW *)imsg->IDCMPWindow->UserData;
- if(((imsg->Class != IDCMP_RAWKEY) || (!(imsg->Code & IECODE_UP_PREFIX)))
- && ((imsg->Class != IDCMP_MENUPICK) || (imsg->Code != MENUNULL)))
- {
- switch(imsg->Class)
- {
- Event ev;
- case IDCMP_NEWSIZE:
- if(ev_vw == oldvw)
- cursor(ev_vw, CURS_OFF);
- updatedimensions(ev_vw);
- ev_vw->vw_Flags |= VWFF_FORCE_REFRESH;
- refreshwindow(ev_vw);
- if(ev_vw == oldvw)
- cursor(ev_vw, CURS_ON);
- break;
- case IDCMP_ACTIVEWINDOW:
- if(ev_vw != oldvw)
- {
- cursor(oldvw, CURS_OFF);
- cursor(ev_vw, CURS_ON);
- CurrVW = ev_vw;
- }
- break;
- case IDCMP_MOUSEBUTTONS:
- case IDCMP_MOUSEMOVE:
- #ifndef NOSCRLBAR
- if(ev_vw->vw_SBar.gad
- && (ev_vw->vw_SBar.gad->Flags & GFLG_SELECTED))
- {
- long newtop;
- GetAttr(PGA_Top, ev_vw->vw_SBar.gad, &newtop);
- if(ev_vw == oldvw)
- cursor(ev_vw, CURS_OFF);
- setstartline(ev_vw, newtop);
- refreshwindow(ev_vw);
- if(ev_vw == oldvw)
- cursor(ev_vw, CURS_ON);
- ev_vw->vw_SBar.top = newtop;
- break;
- }
- #endif
- /* FALL THROUGH */
- case IDCMP_RAWKEY:
- ev.ev_EventDef.evd_Type = ev.ev_EventDef.evd_Mods = ev.ev_EventDef.evd_Code = 0;
- translateevent(&ev, imsg);
- if(ev.ev_EventDef.evd_Type)
- {
- CurrVW = ev_vw;
- if(oldvw != ev_vw)
- cursor(oldvw, CURS_OFF);
- ev.ev_Window = ev_vw;
- result = usekey(imsg, &ev, (ev_vw == oldvw));
- }
- break;
- case IDCMP_CLOSEWINDOW:
- CurrVW = ev_vw;
- cursor(oldvw, CURS_OFF);
- result = cmd_eval_hook2(MKSTR("close-gadget-hook"), sym_nil);
- if(CurrVW)
- {
- refreshworld();
- cursor(CurrVW, CURS_ON);
- }
- break;
- case IDCMP_MENUPICK:
- CurrVW = ev_vw;
- resettitle(ev_vw);
- if(ev_vw == oldvw)
- cursor(CurrVW, CURS_OFF);
- result = evalmenu(imsg->Code, imsg->Qualifier);
- break;
- #ifndef NOSCRLBAR
- case IDCMP_GADGETUP:
- case IDCMP_GADGETDOWN:
- if(imsg->IAddress == ev_vw->vw_SBar.gad)
- {
- long newtop;
- GetAttr(PGA_Top, ev_vw->vw_SBar.gad, &newtop);
- if(ev_vw == oldvw)
- cursor(ev_vw, CURS_OFF);
- setstartline(ev_vw, newtop);
- refreshwindow(ev_vw);
- if(ev_vw == oldvw)
- cursor(ev_vw, CURS_ON);
- ev_vw->vw_SBar.top = newtop;
- }
- break;
- #endif
- }
- }
- return(result);
- }
-
- VALUE
- eventloop(void)
- {
- VALUE result = sym_nil;
- int ticks = 0;
- RecurseDepth++;
- refreshworldcurs();
- while(CurrVW)
- {
- u_long signals;
- struct IntuiMessage *imsg;
- stdtitle(CurrVW);
- if(ILock && RexxSig)
- signals = Wait(RexxSig);
- else
- signals = Wait((1 << CurrVW->vw_Window->UserPort->mp_SigBit) | RexxSig);
- if(RexxSig && (signals & RexxSig))
- disp_rexx_port();
- while(CurrVW
- && (imsg = (struct IntuiMessage *)GetMsg(CurrVW->vw_Window->UserPort)))
- {
- struct IntuiMessage imsgcopy = *imsg;
- ReplyMsg((struct Message *)imsg);
- if(imsg->Class == IDCMP_INTUITICKS)
- {
- /* These needs fixing. Intuiticks are only received while one
- of our windows is active. */
- if(++ticks >= (EVENT_TIMEOUT_LENGTH * 10))
- {
- ticks = 0;
- if(!autosavebuffers())
- {
- /* nothing was saved so try a GC */
- if(DataAfterGC > IdleDataBeforeGC)
- cmd_garbage_collect(sym_t);
- }
- }
- }
- else
- {
- ticks = 0;
- if(!(result = handleevent(&imsgcopy)))
- {
- if(ThrowValue)
- {
- VALUE car = VCAR(ThrowValue);
- if(car == sym_exit)
- {
- result = VCDR(ThrowValue);
- ThrowValue = NULL;
- if(RecurseDepth > 0)
- goto end;
- }
- else if((car == sym_top_level) && (RecurseDepth == 0))
- {
- result = VCDR(ThrowValue);
- ThrowValue = NULL;
- }
- else if(car == sym_quit)
- goto end;
- else if(car == sym_error)
- {
- handleerror(VCAR(VCDR(ThrowValue)), VCDR(VCDR(ThrowValue)));
- ThrowValue = NULL;
- result = sym_nil;
- }
- else if(RecurseDepth == 0)
- {
- ThrowValue = NULL;
- result = sym_nil;
- #if 0
- /* This is no good -- we have to do the error NOW */
- cmd_signal(sym_no_catcher, LIST_1(car));
- #else
- handleerror(sym_no_catcher, LIST_1(car));
- #endif
- }
- else
- goto end;
- }
- else
- {
- result = sym_nil;
- ThrowValue = NULL;
- }
- }
- }
- }
- if(!CurrVW)
- goto end;
- #ifndef NOSCRLBAR
- if(!CurrVW->vw_Sleeping
- && ((CurrVW->vw_StartLine != CurrVW->vw_SBar.top)
- || (CurrVW->vw_Tx->tx_NumLines != CurrVW->vw_SBar.total)))
- {
- updatescroller(CurrVW);
- }
- #endif
- stdtitle(CurrVW);
- if(CurrVW->vw_Flags & VWFF_REFRESH_STATUS)
- {
- setvwtitle(CurrVW);
- CurrVW->vw_Flags &= ~VWFF_REFRESH_STATUS;
- }
- }
- end:
- RecurseDepth--;
- return(result);
- }
-