home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / may94 / util / edit / jade.lha / Jade / src / amiga_eventloop.c < prev    next >
C/C++ Source or Header  |  1994-04-19  |  6KB  |  238 lines

  1. /* amiga_eventloop.c -- Eventloop for AmigaDOS
  2.    Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4. This file is part of Jade.
  5.  
  6. Jade is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Jade is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Jade; see the file COPYING.    If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "jade.h"
  21. #include "jade_protos.h"
  22.  
  23. #define INTUI_V36_NAMES_ONLY
  24. #include <clib/intuition_protos.h>
  25. #include <intuition/gadgetclass.h>
  26. #include <string.h>
  27.  
  28. _PR VALUE eventloop(void);
  29.  
  30. VALUE
  31. handleevent(struct IntuiMessage *imsg)
  32. {
  33.     VW *oldvw = CurrVW, *ev_vw;
  34.     VALUE result = sym_nil;
  35.     ev_vw = (VW *)imsg->IDCMPWindow->UserData;
  36.     if(((imsg->Class != IDCMP_RAWKEY) || (!(imsg->Code & IECODE_UP_PREFIX)))
  37.        && ((imsg->Class != IDCMP_MENUPICK) || (imsg->Code != MENUNULL)))
  38.     {
  39.     switch(imsg->Class)
  40.     {
  41.         Event ev;
  42.     case IDCMP_NEWSIZE:
  43.         if(ev_vw == oldvw)
  44.         cursor(ev_vw, CURS_OFF);
  45.         updatedimensions(ev_vw);
  46.         ev_vw->vw_Flags |= VWFF_FORCE_REFRESH;
  47.         refreshwindow(ev_vw);
  48.         if(ev_vw == oldvw)
  49.         cursor(ev_vw, CURS_ON);
  50.         break;
  51.     case IDCMP_ACTIVEWINDOW:
  52.         if(ev_vw != oldvw)
  53.         {
  54.         cursor(oldvw, CURS_OFF);
  55.         cursor(ev_vw, CURS_ON);
  56.         CurrVW = ev_vw;
  57.         }
  58.         break;
  59.     case IDCMP_MOUSEBUTTONS:
  60.     case IDCMP_MOUSEMOVE:
  61. #ifndef NOSCRLBAR
  62.         if(ev_vw->vw_SBar.gad
  63.            && (ev_vw->vw_SBar.gad->Flags & GFLG_SELECTED))
  64.         {
  65.         long newtop;
  66.         GetAttr(PGA_Top, ev_vw->vw_SBar.gad, &newtop);
  67.         if(ev_vw == oldvw)
  68.             cursor(ev_vw, CURS_OFF);
  69.         setstartline(ev_vw, newtop);
  70.         refreshwindow(ev_vw);
  71.         if(ev_vw == oldvw)
  72.             cursor(ev_vw, CURS_ON);
  73.         ev_vw->vw_SBar.top = newtop;
  74.         break;
  75.         }
  76. #endif
  77.         /* FALL THROUGH */
  78.     case IDCMP_RAWKEY:
  79.         ev.ev_EventDef.evd_Type = ev.ev_EventDef.evd_Mods = ev.ev_EventDef.evd_Code = 0;
  80.         translateevent(&ev, imsg);
  81.         if(ev.ev_EventDef.evd_Type)
  82.         {
  83.         CurrVW = ev_vw;
  84.         if(oldvw != ev_vw)
  85.             cursor(oldvw, CURS_OFF);
  86.         ev.ev_Window = ev_vw;
  87.         result = usekey(imsg, &ev, (ev_vw == oldvw));
  88.         }
  89.         break;
  90.     case IDCMP_CLOSEWINDOW:
  91.         CurrVW = ev_vw;
  92.         cursor(oldvw, CURS_OFF);
  93.         result = cmd_eval_hook2(MKSTR("close-gadget-hook"), sym_nil);
  94.         if(CurrVW)
  95.         {
  96.         refreshworld();
  97.         cursor(CurrVW, CURS_ON);
  98.         }
  99.         break;
  100.     case IDCMP_MENUPICK:
  101.         CurrVW = ev_vw;
  102.         resettitle(ev_vw);
  103.         if(ev_vw == oldvw)
  104.         cursor(CurrVW, CURS_OFF);
  105.         result = evalmenu(imsg->Code, imsg->Qualifier);
  106.         break;
  107. #ifndef NOSCRLBAR
  108.     case IDCMP_GADGETUP:
  109.     case IDCMP_GADGETDOWN:
  110.         if(imsg->IAddress == ev_vw->vw_SBar.gad)
  111.         {
  112.         long newtop;
  113.         GetAttr(PGA_Top, ev_vw->vw_SBar.gad, &newtop);
  114.         if(ev_vw == oldvw)
  115.             cursor(ev_vw, CURS_OFF);
  116.         setstartline(ev_vw, newtop);
  117.         refreshwindow(ev_vw);
  118.         if(ev_vw == oldvw)
  119.             cursor(ev_vw, CURS_ON);
  120.         ev_vw->vw_SBar.top = newtop;
  121.         }
  122.         break;
  123. #endif
  124.     }
  125.     }
  126.     return(result);
  127. }
  128.  
  129. VALUE
  130. eventloop(void)
  131. {
  132.     VALUE result = sym_nil;
  133.     int ticks = 0;
  134.     RecurseDepth++;
  135.     refreshworldcurs();
  136.     while(CurrVW)
  137.     {
  138.     u_long signals;
  139.     struct IntuiMessage *imsg;
  140.     stdtitle(CurrVW);
  141.     if(ILock && RexxSig)
  142.         signals = Wait(RexxSig);
  143.     else
  144.         signals = Wait((1 << CurrVW->vw_Window->UserPort->mp_SigBit) | RexxSig);
  145.     if(RexxSig && (signals & RexxSig))
  146.         disp_rexx_port();
  147.     while(CurrVW
  148.           && (imsg = (struct IntuiMessage *)GetMsg(CurrVW->vw_Window->UserPort)))
  149.     {
  150.         struct IntuiMessage imsgcopy = *imsg;
  151.         ReplyMsg((struct Message *)imsg);
  152.         if(imsg->Class == IDCMP_INTUITICKS)
  153.         {
  154.         /* These needs fixing. Intuiticks are only received while one
  155.            of our windows is active.  */
  156.         if(++ticks >= (EVENT_TIMEOUT_LENGTH * 10))
  157.         {
  158.             ticks = 0;
  159.             if(!autosavebuffers())
  160.             {
  161.             /* nothing was saved so try a GC */
  162.             if(DataAfterGC > IdleDataBeforeGC)
  163.                 cmd_garbage_collect(sym_t);
  164.             }
  165.         }
  166.         }
  167.         else
  168.         {
  169.         ticks = 0;
  170.         if(!(result = handleevent(&imsgcopy)))
  171.         {
  172.             if(ThrowValue)
  173.             {
  174.             VALUE car = VCAR(ThrowValue);
  175.             if(car == sym_exit)
  176.             {
  177.                 result = VCDR(ThrowValue);
  178.                 ThrowValue = NULL;
  179.                 if(RecurseDepth > 0)
  180.                 goto end;
  181.             }
  182.             else if((car == sym_top_level) && (RecurseDepth == 0))
  183.             {
  184.                 result = VCDR(ThrowValue);
  185.                 ThrowValue = NULL;
  186.             }
  187.             else if(car == sym_quit)
  188.                 goto end;
  189.             else if(car == sym_error)
  190.             {
  191.                 handleerror(VCAR(VCDR(ThrowValue)), VCDR(VCDR(ThrowValue)));
  192.                 ThrowValue = NULL;
  193.                 result = sym_nil;
  194.             }
  195.             else if(RecurseDepth == 0)
  196.             {
  197.                 ThrowValue = NULL;
  198.                 result = sym_nil;
  199. #if 0
  200.                 /* This is no good -- we have to do the error NOW */
  201.                 cmd_signal(sym_no_catcher, LIST_1(car));
  202. #else
  203.                 handleerror(sym_no_catcher, LIST_1(car));
  204. #endif
  205.             }
  206.             else
  207.                 goto end;
  208.             }
  209.             else
  210.             {
  211.             result = sym_nil;
  212.             ThrowValue = NULL;
  213.             }
  214.         }
  215.         }
  216.     }
  217.     if(!CurrVW)
  218.         goto end;
  219. #ifndef NOSCRLBAR
  220.     if(!CurrVW->vw_Sleeping
  221.        && ((CurrVW->vw_StartLine != CurrVW->vw_SBar.top)
  222.            || (CurrVW->vw_Tx->tx_NumLines != CurrVW->vw_SBar.total)))
  223.     {
  224.         updatescroller(CurrVW);
  225.     }
  226. #endif
  227.     stdtitle(CurrVW);
  228.     if(CurrVW->vw_Flags & VWFF_REFRESH_STATUS)
  229.     {
  230.         setvwtitle(CurrVW);
  231.         CurrVW->vw_Flags &= ~VWFF_REFRESH_STATUS;
  232.     }
  233.     }
  234. end:
  235.     RecurseDepth--;
  236.     return(result);
  237. }
  238.