home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 124 / af124a.adf / af124a.lzx / WBStartup+V2.8 / Source / WBStartup+Prefs / GetPriorityWindow.c < prev    next >
C/C++ Source or Header  |  1999-03-29  |  4KB  |  128 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. #include <intuition/gadgetclass.h> /* PGA_Freedom */
  16.  
  17. #include "WBStartupPlusPrefs_Cat.h"
  18.  
  19. int GetPriority(int pri, UWORD x, UWORD y)
  20. {
  21.   ULONG signals;
  22.   ULONG winsigflag;
  23.   BOOL LOOP;
  24.   struct IntuiMessage *winmsg;
  25.   struct Window *win;
  26.   struct Screen *scr;
  27.   struct VisualInfo *vi;
  28.   struct Gadget *gad;
  29.   struct Gadget *glist=NULL;
  30.   struct NewGadget ng;
  31.   ULONG winheight,winwidth;
  32.  
  33.   if (scr=LockPubScreen(NULL))
  34.   {
  35.     if (vi=GetVisualInfo(scr,TAG_END))
  36.     {
  37.       winheight = scr->WBorTop + (2 * scr->Font->ta_YSize) + 1 + scr->WBorBottom + 8;
  38.       winwidth  = (2 * TextLength(&scr->RastPort,GetString(STRPriority),strlen(GetString(STRPriority)))) + 40; /* 40 is for the close and depth gadgets */
  39.       if (win = OpenWindowTags(NULL,
  40.           WA_Left,   x - (winwidth/2),
  41.           WA_Top,    y - (winheight/2),
  42.           WA_Width, winwidth,
  43.           WA_Height, winheight,
  44.           WA_AutoAdjust, TRUE,
  45.           WA_Gadgets, glist,
  46.           WA_IDCMP,  IDCMP_REFRESHWINDOW | IDCMP_CLOSEWINDOW | IDCMP_ACTIVEWINDOW | IDCMP_GADGETUP | SLIDERIDCMP,
  47.           WA_Flags,  WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE,
  48.           WA_Title,  GetString(STRPriority),
  49.           WA_PubScreen, scr,
  50.           TAG_END))
  51.       {
  52.         gad = CreateContext(&glist);
  53.  
  54.         ng.ng_LeftEdge = win->BorderLeft+2;
  55.         ng.ng_TopEdge = win->BorderTop+2;
  56.         ng.ng_Width = win->Width-win->BorderRight-win->BorderLeft-ng.ng_LeftEdge-2-(TextLength(&scr->RastPort," -000",5));
  57.         ng.ng_Height = scr->Font->ta_YSize + 4;
  58.         ng.ng_GadgetText = NULL;
  59.         ng.ng_TextAttr = NULL;//win->WScreen->Font;
  60.         ng.ng_VisualInfo = vi;
  61.         ng.ng_GadgetID = 0;
  62.         ng.ng_Flags = 0;
  63.  
  64.         gad = CreateGadget(SLIDER_KIND,gad,&ng,
  65.           GTSL_Min, -128,
  66.           GTSL_Max, 127,
  67.           GTSL_Level, pri,
  68.           PGA_Freedom, LORIENT_HORIZ,
  69.           GTSL_LevelFormat, "%ld",
  70.           GTSL_LevelPlace, PLACETEXT_RIGHT,
  71.           GTSL_MaxLevelLen, 4,
  72.           TAG_DONE);
  73.  
  74.         if (gad)
  75.         {
  76.           winsigflag = 1L<<win->UserPort->mp_SigBit;
  77.           AddGList(win, glist, (UWORD)~0, -1, NULL);
  78.           RefreshGList(glist,win,NULL,-1);
  79.           GT_RefreshWindow(win,NULL);
  80.  
  81.           LOOP=TRUE;
  82.           while (LOOP)
  83.           {
  84.             signals=Wait(SIGBREAKF_CTRL_C | winsigflag);
  85.  
  86.             if (signals & SIGBREAKF_CTRL_C)
  87.               LOOP=FALSE;
  88.  
  89.             if (signals & winsigflag)
  90.             {
  91.               while (winmsg = (struct IntuiMessage *)GT_GetIMsg((struct MsgPort *)win->UserPort))
  92.               {
  93.                 switch(winmsg->Class)
  94.                 {
  95. //                  case IDCMP_GADGETUP:
  96. //                    LOOP=FALSE;
  97. //                    break;
  98.                   case IDCMP_REFRESHWINDOW:
  99.                     BeginRefresh(win);
  100.                     EndRefresh(win, TRUE);
  101.                     break;
  102.                   case IDCMP_CLOSEWINDOW:
  103.                     LOOP=FALSE;
  104.                     break;
  105.                 }
  106.                 GT_ReplyIMsg(winmsg);
  107.               }
  108.             }  /* End of process window events */
  109.           }   /* End of while (LOOP) */
  110.  
  111.           GT_GetGadgetAttrs(gad,win,NULL,GTSL_Level,&pri);
  112.           if (pri > 127)
  113.             pri=127;
  114.           if (pri < -128)
  115.             pri=-128;
  116.  
  117.           RemoveGList(win,glist,-1);
  118.         }
  119.         FreeGadgets(glist);
  120.         CloseWindow(win);
  121.       }  /* End of if (OpenWindowTags()) */
  122.       FreeVisualInfo(vi);
  123.     }
  124.     UnlockPubScreen(NULL,scr);
  125.   }
  126.   return(pri);
  127. }
  128.