home *** CD-ROM | disk | FTP | other *** search
- /////////////////////////////////////////////////////////////////////////////
- //
- // This file is Copyright 1992,1993 by Warwick W. Allison.
- // This file is part of the gem++ library.
- // You are free to copy and modify these sources, provided you acknowledge
- // the origin by retaining this notice, and adhere to the conditions
- // described in the file COPYING.LIB.
- //
- /////////////////////////////////////////////////////////////////////////////
-
-
- #include <aesbind.h>
- #include "gema.h"
- #include "gemw.h"
- #include "gemm.h"
- #include "gemt.h"
- #include "gemda.h"
- #include "geme.h"
- #include "gemks.h"
- #include "grect.h"
- #include "contract.h"
- #include "scancode.h"
-
- GEMactivity::WL::WL(GEMwindow *Wind, GEMactivity::WL *n) :
- Window(Wind),
- Next(n),
- Prev(n ? n->Prev : 0)
- {
- if (n) n->Prev=this;
- }
-
- GEMactivity::GEMactivity() :
- W(0), Menu(0), Acc(0), Timer(0), KeySink(0)
- { }
-
- GEMactivity::~GEMactivity()
- { }
-
- void GEMactivity::AddWindow(GEMwindow& w)
- {
- W=new struct WL(&w,W);
- }
-
- void GEMactivity::RemoveWindow(GEMwindow& w)
- {
- for (WL* c=W; c && c->Window!=&w; c=c->Next)
- ;
-
- if (c) {
- // Cut it out
- if (c->Prev) c->Prev->Next=c->Next;
- if (c->Next) c->Next->Prev=c->Prev;
- if (c==W) W=c->Next;
-
- delete c;
- }
- }
-
- void GEMactivity::SetMenu(GEMmenu* m)
- {
- Menu=m;
- }
-
- void GEMactivity::SetTimer(GEMtimer* t)
- {
- Timer=t;
- }
-
- void GEMactivity::SetKeySink(GEMkeysink* k)
- {
- KeySink=k;
- }
-
- void GEMactivity::SetDeskAccessory(GEMdeskaccessory* a)
- {
- Acc=a;
- }
-
- void GEMactivity::Do()
- {
- GEMfeedback res=ContinueInteraction;
-
- BeginDo();
-
- while (res != EndInteraction) {
- res=OneDo();
- }
-
- EndDo();
- }
-
- void GEMactivity::BeginDo()
- {
- if (Menu) Menu->Show();
-
- graf_mouse(ARROW,0);
- }
-
- GEMfeedback GEMactivity::OneDo()
- {
- GEMfeedback res=ContinueInteraction;
-
- GEMevent event;
-
- int get=MU_BUTTON|MU_MESAG;
-
- if (Timer && Timer->NextInterval()>=0) {
- get|=MU_TIMER;
- event.Interval(Timer->NextInterval());
- }
-
- if (KeySink) get|=MU_KEYBD;
-
- event.Get(get);
-
- if (event.Keyboard()) {
- KeySink->Consume(event);
- }
-
- if (event.Timer()) {
- Timer->ExpireNext(event);
- }
-
- if (event.Button()) {
- GEMwindow *win=0;
- for (WL* c=W; c && !win; c=c->Next) {
- int X,Y,W,H;
- if (c->Window->IsOpen()) {
- wind_get(c->Window->Handle(),WF_WORKXYWH,&X,&Y,&W,&H);
- if (event.X()>=X && event.X()<X+W && event.Y()>=Y && event.Y()<Y+H)
- win=c->Window;
- }
- }
- if (win) res=win->Click(event);
- }
-
- if (event.Message()) {
- res = PerformMessage(event);
- }
-
- return res;
- }
-
- void GEMactivity::EndDo()
- {
- if (Menu) Menu->Hide();
- }
-
- GEMwindow* GEMactivity::Window(int ID) const
- {
- for (WL* c=W; c && c->Window->Handle()!=ID; c=c->Next)
- ;
- return c ? c->Window : 0;
- }
-
- GEMactivity::WL* GEMactivity::ListWindow(int ID) const
- {
- for (WL* c=W; c && c->Window->Handle()!=ID; c=c->Next)
- ;
- return c;
- }
-
- void GEMactivity::Bottomed(const GEMwindow& w)
- {
- for (WL* c=W; c && c->Window!=&w; c=c->Next)
- ;
-
- if (c && c->Next) {
- // Find the end
- WL* curs=c;
- while (curs->Next) {
- curs=curs->Next;
- }
-
- // Cut c out
- if (c->Prev) c->Prev->Next=c->Next;
- if (c->Next) c->Next->Prev=c->Prev;
- if (c==W) W=c->Next;
-
- // Put c there
- curs->Next=c;
- c->Prev=curs;
- c->Next=0;
- }
- }
-
- void GEMactivity::Topped(const GEMwindow& w)
- {
- for (WL* c=W; c && c->Window!=&w; c=c->Next)
- ;
-
- if (c && c!=W) {
- if (c->Prev) c->Prev->Next=c->Next;
- if (c->Next) c->Next->Prev=c->Prev;
- c->Next=W;
- c->Prev=0;
- W->Prev=c;
- W=c;
- }
- }
-
-
-
-
-
-
- GEMfeedback GEMactivity::PerformMessage(const GEMevent& event)
- {
- GEMfeedback r = ContinueInteraction;
-
- if (event.Message(0)==MN_SELECTED && Menu) {
- return Menu->Select(event);
- } else if (event.Message(0)==AC_OPEN) {
- if (Acc) Acc->Open(event);
- return ContinueInteraction;
- } else if (event.Message(0)==AC_CLOSE) {
- if (Acc) Acc->Close(event);
- return ContinueInteraction;
- }
-
- GEMwindow* To=Window(event.Message(3));
-
- if (To)
- switch (event.Message(0)) {
- case WM_NEWTOP: // it's a test
- form_alert(1,"[1][ NewTop Message received! ][ OK ]");
-
- break; case WM_REDRAW:
- To->RedrawOverlaps( GRect(event.Message(4),event.Message(5),event.Message(6),event.Message(7)) );
-
- break; case WM_CLOSED: r=To->UserClosed();
- break; case WM_MOVED: To->Move(event.Message(4),event.Message(5));
- break; case WM_TOPPED: To->Top(event);
- break; case WM_FULLED: To->UserFulled();
- break; case WM_SIZED: To->UserResized( event.Message(6),event.Message(7) );
- break; case WM_VSLID: r = To->VSlidered( event.Message(4) );
- break; case WM_HSLID: r = To->HSlidered( event.Message(4) );
-
- break; case WM_ARROWED:
- switch (event.Message(4)) {
- case WA_UPLINE:
- r = To->LineUp();
- break; case WA_DNLINE:
- r = To->LineDown();
- break; case WA_UPPAGE:
- r = To->PageUp();
- break; case WA_DNPAGE:
- r = To->PageDown();
- break; case WA_LFLINE:
- r = To->ColumnLeft();
- break; case WA_RTLINE:
- r = To->ColumnRight();
- break; case WA_LFPAGE:
- r = To->PageLeft();
- break; case WA_RTPAGE:
- r = To->PageRight();
- }
- }
-
- if (r == RedrawMe) {
- To->RedrawOverlaps(To->WorkRect());
- r = ContinueInteraction;
- }
-
- return r;
- }
-