home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / program / gempp15b / gema.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-23  |  5.0 KB  |  267 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //  This file is Copyright 1992,1993 by Warwick W. Allison.
  4. //  This file is part of the gem++ library.
  5. //  You are free to copy and modify these sources, provided you acknowledge
  6. //  the origin by retaining this notice, and adhere to the conditions
  7. //  described in the file COPYING.LIB.
  8. //
  9. /////////////////////////////////////////////////////////////////////////////
  10.  
  11.  
  12. #include <aesbind.h>
  13. #include "gema.h"
  14. #include "gemw.h"
  15. #include "gemm.h"
  16. #include "gemt.h"
  17. #include "gemda.h"
  18. #include "geme.h"
  19. #include "gemks.h"
  20. #include "grect.h"
  21. #include "contract.h"
  22. #include "scancode.h"
  23.  
  24. GEMactivity::WL::WL(GEMwindow *Wind, GEMactivity::WL *n) :
  25.     Window(Wind),
  26.     Next(n),
  27.     Prev(n ? n->Prev : 0)
  28. {
  29.     if (n) n->Prev=this;
  30. }
  31.  
  32. GEMactivity::GEMactivity() :
  33.     W(0), Menu(0), Acc(0), Timer(0), KeySink(0)
  34. { }
  35.  
  36. GEMactivity::~GEMactivity()
  37. { }
  38.  
  39. void GEMactivity::AddWindow(GEMwindow& w)
  40. {
  41.     W=new struct WL(&w,W);
  42. }
  43.  
  44. void GEMactivity::RemoveWindow(GEMwindow& w)
  45. {
  46.     for (WL* c=W; c && c->Window!=&w;  c=c->Next)
  47.         ;
  48.  
  49.     if (c) {
  50.         // Cut it out
  51.         if (c->Prev) c->Prev->Next=c->Next;
  52.         if (c->Next) c->Next->Prev=c->Prev;
  53.         if (c==W) W=c->Next;
  54.  
  55.         delete c;
  56.     }
  57. }
  58.  
  59. void GEMactivity::SetMenu(GEMmenu* m)
  60. {
  61.     Menu=m;
  62. }
  63.  
  64. void GEMactivity::SetTimer(GEMtimer* t)
  65. {
  66.     Timer=t;
  67. }
  68.  
  69. void GEMactivity::SetKeySink(GEMkeysink* k)
  70. {
  71.     KeySink=k;
  72. }
  73.  
  74. void GEMactivity::SetDeskAccessory(GEMdeskaccessory* a)
  75. {
  76.     Acc=a;
  77. }
  78.  
  79. void GEMactivity::Do()
  80. {
  81.     GEMfeedback res=ContinueInteraction;
  82.  
  83.     BeginDo();
  84.  
  85.     while (res != EndInteraction) {
  86.         res=OneDo();
  87.     }
  88.  
  89.     EndDo();
  90. }
  91.  
  92. void GEMactivity::BeginDo()
  93. {
  94.     if (Menu) Menu->Show();
  95.  
  96.     graf_mouse(ARROW,0);
  97. }
  98.  
  99. GEMfeedback GEMactivity::OneDo()
  100. {
  101.     GEMfeedback res=ContinueInteraction;
  102.  
  103.     GEMevent event;
  104.  
  105.     int get=MU_BUTTON|MU_MESAG;
  106.  
  107.     if (Timer && Timer->NextInterval()>=0) {
  108.         get|=MU_TIMER;
  109.         event.Interval(Timer->NextInterval());
  110.     }
  111.  
  112.     if (KeySink) get|=MU_KEYBD;
  113.  
  114.     event.Get(get);
  115.  
  116.     if (event.Keyboard()) {
  117.         KeySink->Consume(event);
  118.     }
  119.  
  120.     if (event.Timer()) {
  121.         Timer->ExpireNext(event);
  122.     }
  123.  
  124.     if (event.Button()) {
  125.         GEMwindow *win=0;
  126.         for (WL* c=W; c && !win; c=c->Next) {
  127.             int X,Y,W,H;
  128.             if (c->Window->IsOpen()) {
  129.                 wind_get(c->Window->Handle(),WF_WORKXYWH,&X,&Y,&W,&H);
  130.                 if (event.X()>=X && event.X()<X+W && event.Y()>=Y && event.Y()<Y+H)
  131.                     win=c->Window;
  132.             }
  133.         }
  134.         if (win) res=win->Click(event);
  135.     }
  136.  
  137.     if (event.Message()) {
  138.         res = PerformMessage(event);
  139.     }
  140.  
  141.     return res;
  142. }
  143.  
  144. void GEMactivity::EndDo()
  145. {
  146.     if (Menu) Menu->Hide();
  147. }
  148.  
  149. GEMwindow* GEMactivity::Window(int ID) const
  150. {
  151.     for (WL* c=W; c && c->Window->Handle()!=ID;  c=c->Next)
  152.         ;
  153.     return c ? c->Window : 0;
  154. }
  155.  
  156. GEMactivity::WL* GEMactivity::ListWindow(int ID) const
  157. {
  158.     for (WL* c=W; c && c->Window->Handle()!=ID;  c=c->Next)
  159.         ;
  160.     return c;
  161. }
  162.  
  163. void GEMactivity::Bottomed(const GEMwindow& w)
  164. {
  165.     for (WL* c=W; c && c->Window!=&w;  c=c->Next)
  166.         ;
  167.  
  168.     if (c && c->Next) {
  169.         // Find the end
  170.         WL* curs=c;
  171.         while (curs->Next) {
  172.             curs=curs->Next;
  173.         }
  174.  
  175.         // Cut c out
  176.         if (c->Prev) c->Prev->Next=c->Next;
  177.         if (c->Next) c->Next->Prev=c->Prev;
  178.         if (c==W) W=c->Next;
  179.  
  180.         // Put c there
  181.         curs->Next=c;
  182.         c->Prev=curs;
  183.         c->Next=0;
  184.     }
  185. }
  186.  
  187. void GEMactivity::Topped(const GEMwindow& w)
  188. {
  189.     for (WL* c=W; c && c->Window!=&w;  c=c->Next)
  190.         ;
  191.  
  192.     if (c && c!=W) {
  193.         if (c->Prev) c->Prev->Next=c->Next;
  194.         if (c->Next) c->Next->Prev=c->Prev;
  195.         c->Next=W;
  196.         c->Prev=0;
  197.         W->Prev=c;
  198.         W=c;
  199.     }
  200. }
  201.  
  202.  
  203.  
  204.  
  205.  
  206.  
  207. GEMfeedback GEMactivity::PerformMessage(const GEMevent& event)
  208. {
  209.     GEMfeedback    r = ContinueInteraction;
  210.  
  211.     if (event.Message(0)==MN_SELECTED && Menu) {
  212.         return Menu->Select(event);
  213.     } else if (event.Message(0)==AC_OPEN) {
  214.         if (Acc) Acc->Open(event);
  215.         return ContinueInteraction;
  216.     } else if (event.Message(0)==AC_CLOSE) {
  217.         if (Acc) Acc->Close(event);
  218.         return ContinueInteraction;
  219.     }
  220.  
  221.     GEMwindow* To=Window(event.Message(3));
  222.  
  223.     if (To)
  224.         switch (event.Message(0)) {
  225.          case WM_NEWTOP:        // it's a test
  226.             form_alert(1,"[1][ NewTop Message received! ][  OK  ]");
  227.  
  228.         break; case WM_REDRAW:
  229.             To->RedrawOverlaps( GRect(event.Message(4),event.Message(5),event.Message(6),event.Message(7)) );
  230.  
  231.         break; case WM_CLOSED:    r=To->UserClosed();
  232.         break; case WM_MOVED:    To->Move(event.Message(4),event.Message(5));
  233.         break; case WM_TOPPED:    To->Top(event);
  234.         break; case WM_FULLED:    To->UserFulled();
  235.         break; case WM_SIZED:    To->UserResized( event.Message(6),event.Message(7) );
  236.         break; case WM_VSLID:    r = To->VSlidered( event.Message(4) );
  237.         break; case WM_HSLID:    r = To->HSlidered( event.Message(4) );
  238.  
  239.         break; case WM_ARROWED:
  240.             switch (event.Message(4)) {
  241.              case WA_UPLINE:
  242.                 r = To->LineUp();
  243.             break; case WA_DNLINE:
  244.                 r = To->LineDown();
  245.             break; case WA_UPPAGE:
  246.                 r = To->PageUp();
  247.             break; case WA_DNPAGE:
  248.                 r = To->PageDown();
  249.             break; case WA_LFLINE:
  250.                 r = To->ColumnLeft();
  251.             break; case WA_RTLINE:
  252.                 r = To->ColumnRight();
  253.             break; case WA_LFPAGE:
  254.                 r = To->PageLeft();
  255.             break; case WA_RTPAGE:
  256.                 r = To->PageRight();
  257.             }
  258.         }
  259.     
  260.     if (r == RedrawMe) {
  261.         To->RedrawOverlaps(To->WorkRect());
  262.         r = ContinueInteraction;
  263.     }
  264.  
  265.     return r;
  266. }
  267.