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

  1. #include <exec/types.h>
  2.  
  3. #include <string.h>
  4. #include <proto/dos.h>
  5. #include <proto/exec.h>
  6. #include <proto/gadtools.h>
  7. #include <proto/intuition.h>
  8. #include <proto/icon.h>
  9. #include <proto/graphics.h>
  10. #include <proto/wb.h>
  11. #include <proto/commodities.h>
  12. #include <proto/diskfont.h>
  13. #include <proto/graphics.h>
  14. #include <proto/utility.h>
  15.  
  16.  
  17.  
  18. char *GetStringWindow(UWORD x, UWORD y, char *windowtitle, char *buffer, WORD len)
  19. {
  20.   /* WORD x         The current X mouse position */
  21.   /* WORD y         The current Y mouse position */
  22.   /* char *windowtitle  The title of the window */
  23.   /* char *buffer   What to put in the initial string gadget, and the resulting string */
  24.   /* WORD len       The # of characters in buffer, including the added NULL */
  25.   /* RETURNS a pointer to buffer */
  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 *gad;
  35.   struct Gadget *glist=NULL;
  36.   struct NewGadget ng;
  37.   ULONG winheight,winwidth;
  38.   char  *gadgetbuffer;
  39.  
  40.   if (scr=LockPubScreen(NULL))
  41.   {
  42.     if (vi=GetVisualInfo(scr,TAG_END))
  43.     {
  44.       winheight = scr->WBorTop + (2 * scr->Font->ta_YSize) + 1 + scr->WBorBottom + 8;
  45.       winwidth  = (2 * TextLength(&scr->RastPort,windowtitle,strlen(windowtitle))) + 40; /* 40 is for the close and depth gadgets */
  46.       if (win = OpenWindowTags(NULL,
  47.           WA_Left,   x - (winwidth/2),
  48.           WA_Top,    y - (winheight/2),
  49.           WA_Width, winwidth,
  50.           WA_Height, winheight,
  51.           WA_AutoAdjust, TRUE,
  52.           WA_Gadgets, glist,
  53.           WA_IDCMP,  IDCMP_REFRESHWINDOW | IDCMP_CLOSEWINDOW | IDCMP_ACTIVEWINDOW | IDCMP_GADGETUP,
  54.           WA_Flags,  WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE,
  55.           WA_Title,  windowtitle,
  56.           WA_PubScreen, scr,
  57.           TAG_END))
  58.       {
  59.         gad = CreateContext(&glist);
  60.  
  61.         ng.ng_LeftEdge = win->BorderLeft+2;
  62.         ng.ng_TopEdge = win->BorderTop+2;
  63.         ng.ng_Width = win->Width-win->BorderRight-2-ng.ng_LeftEdge;
  64.         ng.ng_Height = scr->Font->ta_YSize + 4;
  65.         ng.ng_GadgetText = NULL;
  66.         ng.ng_TextAttr = NULL;//win->WScreen->Font;
  67.         ng.ng_VisualInfo = vi;
  68.         ng.ng_GadgetID = 0;
  69.         ng.ng_Flags = 0;
  70.  
  71.         gad = CreateGadget(STRING_KIND,gad,&ng,
  72.           GTST_String, buffer,
  73.           GTST_MaxChars, len-1,
  74.           TAG_DONE);
  75.  
  76.         if (gad)
  77.         {
  78.           winsigflag = 1L<<win->UserPort->mp_SigBit;
  79.           AddGList(win, glist, (UWORD)~0, -1, NULL);
  80.           RefreshGList(glist,win,NULL,-1);
  81.           GT_RefreshWindow(win,NULL);
  82.  
  83.           LOOP=TRUE;
  84.           while (LOOP)
  85.           {
  86.             signals=Wait(SIGBREAKF_CTRL_C | winsigflag);
  87.  
  88.             if (signals & SIGBREAKF_CTRL_C)
  89.               LOOP=FALSE;
  90.  
  91.             if (signals & winsigflag)
  92.             {
  93.               while (winmsg = (struct IntuiMessage *)GT_GetIMsg((struct MsgPort *)win->UserPort))
  94.               {
  95.                 switch(winmsg->Class)
  96.                 {
  97.                   case IDCMP_GADGETUP:
  98.                     LOOP=FALSE;
  99.                     break;
  100.                   case IDCMP_REFRESHWINDOW:
  101.                     BeginRefresh(win);
  102.                     EndRefresh(win, TRUE);
  103.                     break;
  104.                   case IDCMP_CLOSEWINDOW:
  105.                     LOOP=FALSE;
  106.                     break;
  107.                   case IDCMP_ACTIVEWINDOW:
  108.                     ActivateGadget(gad,win,NULL);
  109.                     break;
  110.                 }
  111.                 GT_ReplyIMsg(winmsg);
  112.               }
  113.             }  /* End of process window events */
  114.           }   /* End of while (LOOP) */
  115.  
  116.           GT_GetGadgetAttrs(gad, win, NULL, GTST_String, &gadgetbuffer);
  117.           strcpy(buffer, gadgetbuffer);
  118.  
  119.           RemoveGList(win,glist,-1);
  120.         }
  121.         FreeGadgets(glist);
  122.         CloseWindow(win);
  123.       }  /* End of if (OpenWindowTags()) */
  124.       FreeVisualInfo(vi);
  125.     }
  126.     UnlockPubScreen(NULL,scr);
  127.   }
  128.   return(buffer);
  129. }
  130.