home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 124 / af124a.adf / af124a.lzx / WBStartup+V2.8 / Source / WBStartup+Prefs / CopyWindow.c < prev    next >
C/C++ Source or Header  |  1999-03-29  |  7KB  |  198 lines

  1. #include <exec/types.h>
  2. #include <string.h>
  3. #include <proto/dos.h>
  4. #include <proto/exec.h>
  5. #include <proto/gadtools.h>
  6. #include <proto/intuition.h>
  7. #include <proto/icon.h>
  8. #include <proto/graphics.h>
  9. #include <proto/wb.h>
  10. #include <proto/commodities.h>
  11. #include <proto/diskfont.h>
  12. #include <proto/graphics.h>
  13. #include <proto/utility.h>
  14.  
  15. #include "CopyWindow.h"
  16. #include "WBStartupPlusPrefs_Cat.h"
  17.  
  18. #define GADTEXTBORDERSUM 6
  19.  
  20.  
  21. int CopyWindow(UWORD x, UWORD y, int flags)
  22. {
  23.   /* WORD x         The current X mouse position */
  24.   /* WORD y         The current Y mouse position */
  25.   /* RETURNS the new flags */
  26.  
  27.   ULONG signals;
  28.   ULONG winsigflag;
  29.   BOOL LOOP;
  30.   struct IntuiMessage *winmsg;
  31.   struct Window *win;
  32.   struct Screen *scr;
  33.   struct VisualInfo *vi;
  34.   struct Gadget *gad1,*gad2,*gad3;
  35.   struct Gadget *glist=NULL;
  36.   struct NewGadget ng;
  37.   ULONG winheight,winwidth;
  38.   UBYTE *labels[3];
  39.   UBYTE *labels2[3];
  40.   STRPTR WinTitleString  = GetString(STRAddPrograms);
  41.   STRPTR GadTitleString  = GetString(STRStatusOfPrograms);
  42.   STRPTR GadTitleString2 = GetString(STROperation);
  43.   long mxgadheight, buttongadheight;
  44.   long active;
  45.  
  46.   int newflags=0;
  47.  
  48.   labels[0]=(UBYTE *)GetString(STREnabled);
  49.   labels[1]=(UBYTE *)GetString(STRDisabled);
  50.   labels[2]=NULL;
  51.  
  52.   labels2[0]=(UBYTE *)GetString(STRCopyFile);
  53.   labels2[1]=(UBYTE *)GetString(STRMoveFile);
  54.   labels2[2]=NULL;
  55.  
  56.  
  57.   if (scr=LockPubScreen(NULL))
  58.   {
  59.     if (vi=GetVisualInfo(scr,TAG_END))
  60.     {
  61.       mxgadheight = (3 * scr->Font->ta_YSize)+6;
  62.       buttongadheight = scr->Font->ta_YSize + 6;
  63.  
  64.       winheight = scr->WBorTop + scr->Font->ta_YSize + 1 + 4 + mxgadheight + 4 + 2 + 4 + mxgadheight + 4 + 2 + buttongadheight + scr->WBorBottom-2;
  65.       winwidth  = (6/5*TextLength(&scr->RastPort,WinTitleString,strlen(WinTitleString))) + 63;
  66.       if (win = OpenWindowTags(NULL,
  67.           WA_Left,   x - (winwidth/2),
  68.           WA_Top,    y - (winheight/2),
  69.           WA_Width, winwidth,
  70.           WA_Height, winheight,
  71.           WA_AutoAdjust, TRUE,
  72.           WA_Gadgets, glist,
  73.           WA_IDCMP,  MXIDCMP | IDCMP_REFRESHWINDOW | IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
  74.           WA_Flags,  WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE,
  75.           WA_Title,  WinTitleString,
  76.           WA_PubScreen, scr,
  77.           TAG_END))
  78.       {
  79.  
  80.         gad1 = CreateContext(&glist);
  81.  
  82.         ng.ng_TopEdge = win->BorderTop + 4 + scr->Font->ta_YSize + 4;  /* The last 4 here is for the space between the gadget title and the actual gadget */
  83.         ng.ng_Height = scr->Font->ta_YSize + 1;
  84.         ng.ng_Width = ng.ng_Height*4/3;
  85.         ng.ng_LeftEdge = (win->Width-(ng.ng_Width+7+TextLength(&scr->RastPort,labels[1],strlen(labels[1]))))/2;
  86.         ng.ng_GadgetText = GadTitleString;
  87.         ng.ng_TextAttr = NULL;//win->WScreen->Font;
  88.         ng.ng_VisualInfo = vi;
  89.         ng.ng_Flags = PLACETEXT_RIGHT | NG_HIGHLABEL;
  90.         ng.ng_GadgetID = COPYGAD_ENABLED;
  91.  
  92.         gad1 = CreateGadget(MX_KIND,gad1,&ng,
  93.           GTMX_Labels, (ULONG)&labels[0],
  94.           GTMX_Active, (flags & WBSP_ENABLED) ? 0: 1,
  95.           GTMX_Scaled, TRUE,
  96.           GTMX_TitlePlace, PLACETEXT_ABOVE,
  97.           TAG_DONE);
  98.  
  99.         ng.ng_LeftEdge = (win->Width-(ng.ng_Width+7+TextLength(&scr->RastPort,labels2[0],strlen(labels2[0]))))/2;
  100.         ng.ng_TopEdge = win->BorderTop + 4 + mxgadheight + 4 + 4 + scr->Font->ta_YSize + 4 + 2 - 1; /* The 2 is is to make room for the 2 lines of the bevel box */
  101.         ng.ng_GadgetText = GadTitleString2;
  102.         ng.ng_GadgetID = COPYGAD_COPY;
  103.  
  104.         gad2 = CreateGadget(MX_KIND,gad1,&ng,
  105.           GTMX_Labels, (ULONG)&labels2[0],
  106.           GTMX_Active, (flags & WBSP_MOVE) ? 1 : 0,
  107.           GTMX_Scaled, TRUE,
  108.           GTMX_TitlePlace, PLACETEXT_ABOVE,
  109.           TAG_DONE);
  110.  
  111.         ng.ng_LeftEdge   = win->BorderRight;
  112.         ng.ng_Width      = (win->Width-win->BorderRight-win->BorderLeft)/2;
  113.         ng.ng_TopEdge    = win->BorderTop + 4 + mxgadheight + 4 + 2 + 4 + mxgadheight + 4;
  114.         ng.ng_Height     = buttongadheight;
  115.         ng.ng_GadgetText = GetString(STROk);
  116.         ng.ng_Flags      = 0;
  117.         ng.ng_GadgetID   = COPYGAD_OK;
  118.  
  119.         gad3 = CreateGadget(BUTTON_KIND,gad2,&ng,
  120.           TAG_DONE);
  121.  
  122.         ng.ng_LeftEdge   = win->BorderRight + ng.ng_Width;
  123.         ng.ng_Width      = win->Width-win->BorderRight-win->BorderLeft-ng.ng_Width;
  124.         ng.ng_GadgetText = GetString(STRCancel);
  125.         ng.ng_GadgetID   = COPYGAD_CANCEL;
  126.  
  127.         CreateGadget(BUTTON_KIND,gad3,&ng,
  128.           TAG_DONE);
  129.  
  130.         if (gad2)
  131.         {
  132.           winsigflag = 1L<<win->UserPort->mp_SigBit;
  133.           AddGList(win, glist, (UWORD)~0, -1, NULL);
  134.           RefreshGList(glist,win,NULL,-1);
  135.           GT_RefreshWindow(win,NULL);
  136.  
  137.           DrawBevelBox(win->RPort, win->BorderLeft, win->BorderTop, win->Width-win->BorderLeft-win->BorderRight, 4+mxgadheight+4+1, GT_VisualInfo, vi, TAG_DONE);
  138.           DrawBevelBox(win->RPort, win->BorderLeft, win->BorderTop+4+mxgadheight+4+1, win->Width-win->BorderLeft-win->BorderRight, 4+mxgadheight+4+1, GT_VisualInfo, vi, TAG_DONE);
  139.  
  140.           LOOP=TRUE;
  141.           while (LOOP)
  142.           {
  143.             signals=Wait(SIGBREAKF_CTRL_C | winsigflag);
  144.  
  145.             if (signals & SIGBREAKF_CTRL_C)
  146.               LOOP=FALSE;
  147.  
  148.             if (signals & winsigflag)
  149.             {
  150.               while (winmsg = (struct IntuiMessage *)GT_GetIMsg((struct MsgPort *)win->UserPort))
  151.               {
  152.                 switch(winmsg->Class)
  153.                 {
  154.                   case IDCMP_GADGETUP:
  155.                     switch(((struct Gadget *)winmsg->IAddress)->GadgetID)
  156.                     {
  157.                       case COPYGAD_OK:
  158.                         LOOP=FALSE;
  159.                         break;
  160.                       case COPYGAD_CANCEL:
  161.                         newflags |= WBSP_CANCEL;
  162.                         LOOP=FALSE;
  163.                         break;
  164.                     }
  165.                     break;
  166.                   case IDCMP_REFRESHWINDOW:
  167.                     BeginRefresh(win);
  168.                     EndRefresh(win, TRUE);
  169.                     break;
  170.                   case IDCMP_CLOSEWINDOW:
  171.                     LOOP=FALSE;
  172.                     break;
  173.                 }
  174.                 GT_ReplyIMsg(winmsg);
  175.               }
  176.             }  /* End of process window events */
  177.           }   /* End of while (LOOP) */
  178.  
  179.           /* get status gadgets */
  180.           GT_GetGadgetAttrs(gad1, win, NULL, GTMX_Active, &active);
  181.           if (!active)
  182.             newflags |= WBSP_ENABLED;
  183.           GT_GetGadgetAttrs(gad2, win, NULL, GTMX_Active, &active);
  184.           if (active)
  185.             newflags |= WBSP_MOVE;
  186.  
  187.           RemoveGList(win,glist,-1);
  188.         }
  189.         FreeGadgets(glist);
  190.         CloseWindow(win);
  191.       }  /* End of if (OpenWindowTags()) */
  192.       FreeVisualInfo(vi);
  193.     }
  194.     UnlockPubScreen(NULL,scr);
  195.   }
  196.   return(newflags);
  197. }
  198.