home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / bbs / libdisks / d700t799 / disk711.lha / WindowTool / source / functions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-19  |  3.6 KB  |  196 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3. #include <devices/input.h>
  4. #include <devices/inputevent.h>
  5. #include <intuition/intuitionbase.h>
  6. #include <intuition/intuition.h>
  7. #include <intuition/screens.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. extern struct IntuitionBase *IntuitionBase;
  11.  
  12. void bigwindow(void)
  13. {
  14.     struct Window *w;
  15.     struct Screen *s;
  16.     int hoch,breit,x,y;
  17.  
  18.     Forbid();
  19.     
  20.     s=IntuitionBase->ActiveScreen;
  21.  
  22.     breit=s->Width;
  23.     hoch=s->Height;
  24.  
  25.     w=IntuitionBase->ActiveWindow;
  26.     if(!w){Permit();return;}
  27.  
  28.     x=w->MaxWidth == -1 ? breit : w->MaxWidth;
  29.     y=w->MaxHeight == -1 ? hoch : w->MaxHeight;
  30.  
  31.     ChangeWindowBox(w,w->LeftEdge,w->TopEdge,x,y);
  32.  
  33.     Permit();
  34. }
  35.  
  36. void smallwindow(void)
  37. {
  38.     struct Window *w;
  39.  
  40.     Forbid();
  41.     
  42.     w=IntuitionBase->ActiveWindow;
  43.  
  44.     if(w)    ChangeWindowBox(w,w->LeftEdge,w->TopEdge,w->MinWidth,w->MinHeight);
  45.  
  46.     Permit();
  47. }
  48.  
  49. void zipwindow(void)
  50. {
  51.     struct Window *w;
  52.  
  53.     Forbid();
  54.     
  55.     w=IntuitionBase->ActiveWindow;
  56.     if(w)    ZipWindow(w);
  57.  
  58.     Permit();
  59. }
  60.  
  61. void activatefront(void)
  62. {
  63.     struct Window *w,*aw;
  64.     struct Screen *s;
  65.     struct Layer *l;
  66.  
  67.     Forbid();
  68.     s=IntuitionBase->FirstScreen;
  69.     
  70.     if(!s){Permit();return;}        /* Kein Screen da --> */
  71.     
  72.     aw=w=s->FirstWindow;
  73.  
  74.     if(!w){Permit();return;}        /* Kein Window da --> */
  75.  
  76.     l=w->WLayer;
  77.  
  78.     while(l->front)l=l->front;                        /* Vordersten Layer suchen */
  79.     while((w->WLayer!=l) && w)w=w->NextWindow;    /* Window dazu suchen */
  80.     
  81.     Permit();
  82.  
  83.     if(w)ActivateWindow(w);    /* Bei Backdrop Window ist ScreenTitleLayer */
  84.     else    if(aw)ActivateWindow(aw);        /* vor dem WindowLayer */
  85. }
  86.  
  87. void worktofront(void)
  88. {
  89.     struct Window *w;
  90.     struct Screen *s;
  91.     WBenchToFront();
  92.  
  93.     Forbid();
  94.     s=IntuitionBase->FirstScreen;
  95.     
  96.     while(s)
  97.     {
  98.         if(strcmp(s->Title,"Workbench Screen")==0)break;
  99.         s=s->NextScreen;
  100.     }
  101.     
  102.     if(s==0){Permit();return;}
  103.     
  104.     w=s->FirstWindow;
  105.  
  106.     while(w)
  107.     {
  108.     if(w->Flags&WFLG_WBENCHWINDOW)break;
  109.         w=w->NextWindow;
  110.     };
  111.  
  112.     Permit();
  113.  
  114.     ActivateWindow(w);
  115.     WindowToFront(w);
  116.  
  117. }
  118.  
  119. void cycle(void)
  120. {
  121.     struct Window *w,*nw;
  122.     struct Layer *l,*nl;
  123.  
  124.     Forbid();
  125.     nw=w=IntuitionBase->ActiveScreen->FirstWindow;
  126.     l=w->WLayer;
  127.     
  128.     if(!w){Permit();return;}
  129.     
  130.     while(l->front)l=l->front;                        /* Vordersten Layer suchen */
  131.     while((w->WLayer!=l) && w)w=w->NextWindow;    /* Window dazu suchen */
  132.     
  133.     if(nl=l->back)
  134.     {
  135.         while((nw->WLayer!=nl) && nw)nw=nw->NextWindow;
  136.     }
  137.     
  138.     Permit();
  139.     if(!w)    return;
  140.     WindowToBack(w);
  141.  
  142.     if((!nl) || (!nw)) ActivateWindow(w);
  143.     else     
  144.     {
  145.         if    (    (nw->TopEdge==11)    &&    (nw->LeftEdge==0)    &&
  146.             (nw->Width==640)    &&    (nw->Height==245)    )
  147.             ActivateWindow(w);
  148.         else
  149.             ActivateWindow(nw);
  150.     }
  151. }
  152.  
  153. void activetofront(void)
  154. {
  155.     struct Window *w;
  156.     
  157.     Forbid();
  158.     if(w=IntuitionBase->ActiveWindow)WindowToFront(w);
  159.     Permit();
  160. }
  161.  
  162. void closewindow(void)
  163. {
  164.     struct IOStdReq *InputIO;
  165.     struct MsgPort *InputMP;
  166.     struct InputEvent *FakeEvent;
  167.     
  168.     if(InputMP=CreateMsgPort())
  169.     {
  170.         if(FakeEvent=AllocMem(sizeof(struct InputEvent),MEMF_PUBLIC))
  171.         {
  172.             if(InputIO=CreateIORequest(InputMP,sizeof(struct IOStdReq)))
  173.             {
  174.                 if(!OpenDevice("input.device",NULL,(struct IORequest *)InputIO,NULL))
  175.                 {
  176.                     FakeEvent->ie_NextEvent=0;
  177.                     FakeEvent->ie_Class=IECLASS_CLOSEWINDOW;
  178.                     
  179.                     InputIO->io_Data=(APTR)FakeEvent;
  180.                     InputIO->io_Length=sizeof(struct InputEvent);
  181.                     InputIO->io_Command=IND_WRITEEVENT;
  182.                     DoIO((struct IORequest *)InputIO);
  183.                 }
  184.                 else     rtEZRequest("Unable to open input.device !", "Continue", NULL, NULL);
  185.                 DeleteIORequest(InputIO);
  186.             }
  187.             else     rtEZRequest("CreateIORequest failed !", "Continue", NULL, NULL);
  188.             FreeMem(FakeEvent,sizeof(struct InputEvent));
  189.         }
  190.         else     rtEZRequest ("No memory for InputEvent !", "Continue", NULL, NULL);
  191.         DeleteMsgPort(InputMP);
  192.     }
  193.     else     rtEZRequest ("Unable to create MsgPort for InputEvent !", "Continue", NULL, NULL);
  194.  
  195. }
  196.