home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 563.lha / PortList / PortList.c < prev    next >
C/C++ Source or Header  |  1991-08-10  |  5KB  |  157 lines

  1. #include <utility/tagitem.h>
  2. #include <exec/execbase.h>
  3. #include <proto/intuition.h>
  4. #include <proto/gadtools.h>
  5. #include <proto/exec.h>
  6. #include <intuition/gadgetclass.h>
  7. #include <intuition/screens.h>
  8. struct ExecBase *ExecBase;
  9. struct IntuitionBase *IntuitionBase = NULL;
  10. struct GadToolsBase *GadToolsBase = NULL;
  11. struct Window *window1 = NULL;
  12. struct Screen *WBScreen = NULL;
  13. APTR vi = NULL;
  14. BOOL activated = TRUE;
  15. struct Gadget *currgad,*g0,*g1;
  16. struct Gadget *gadlist = NULL;
  17. #define REFRESHBUTTON 2
  18. #define NODEGAD_ID 1
  19.  
  20. void Bummer(char *errmsg)
  21. {
  22.     puts(errmsg);
  23.     CleanExit(5);
  24. }
  25. int CleanExit(returnvalue)
  26. int returnvalue;
  27. {
  28.     if (gadlist)
  29.         FreeGadgets(gadlist);
  30.     if (vi)
  31.         FreeVisualInfo(vi);
  32.     if (window1) CloseWindow (window1);
  33.     if (WBScreen != NULL)
  34.         UnlockPubScreen (NULL, WBScreen);
  35.     if (GadToolsBase)
  36.         CloseLibrary ((struct Library *)GadToolsBase);
  37.     if (IntuitionBase)
  38.         CloseLibrary ((struct Library *)IntuitionBase);
  39.     if (ExecBase)
  40.         CloseLibrary ((struct Library *)ExecBase);
  41.     exit (returnvalue);
  42.     return (returnvalue);
  43. }
  44.  
  45. void handleIDCMP(struct Window *win)
  46. {
  47.     struct IntuiMessage *message = NULL;
  48.     struct Gadget *gad = NULL;
  49.     ULONG class, signals, signalmask;
  50.     WORD code;
  51.  
  52.     signalmask = 1L << win->UserPort->mp_SigBit;
  53.     while (1)
  54.     {
  55.         signals = Wait(signalmask);
  56.         if (signals & signalmask)
  57.             while (message = (struct IntuiMessage *)GT_GetIMsg(win->UserPort))
  58.             {
  59.                 class = message->Class;
  60.                 code = (WORD)message->Code;
  61.                 gad = (struct Gadget *) message->IAddress;
  62.                 GT_ReplyIMsg(message);
  63. /*                                 printf("Gadget: %d,  Code: %d\n",gad->GadgetID,code); */
  64.                 switch(class)
  65.                 {
  66.                     case CLOSEWINDOW:
  67.                        CleanExit(0);
  68.                     case GADGETUP:
  69.                       if (gad->GadgetID = REFRESHBUTTON)
  70.                           GT_SetGadgetAttrs(g0, window1, NULL,GTLV_Labels,&(ExecBase->PortList), TAG_DONE);
  71.                                     default:
  72.                        break;
  73.                 }
  74.             }
  75.     }
  76. }
  77.  
  78. struct TagItem WindowTags[] = {
  79.     {WA_Title, (ULONG)" Port List "},
  80.     {WA_Flags, (ULONG)SMART_REFRESH|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|ACTIVATE},
  81.     {WA_GimmeZeroZero, TRUE},
  82.     {WA_AutoAdjust, TRUE},
  83.     {WA_InnerHeight, 145L},
  84.     {WA_InnerWidth, 196L},
  85.     {WA_IDCMP, (ULONG)CLOSEWINDOW|SLIDERIDCMP},
  86.     {TAG_DONE, }
  87. };
  88.  
  89. struct NewGadget ng = {
  90.     13, 15,
  91.     165, 95,
  92.     "G0",
  93.     NULL,
  94.     1,
  95.     PLACETEXT_BELOW,
  96.     NULL,
  97.     NULL
  98. };
  99.  
  100.  
  101. void main(int argc, char *argv[])
  102. {
  103.  
  104.     IntuitionBase = (struct IntuitionBase *) OpenLibrary ("intuition.library", 36);
  105.     if (IntuitionBase == NULL)
  106.         CleanExit(30);
  107.  
  108.     ExecBase = (struct ExecBase *) OpenLibrary ("exec.library", 36);
  109.     if (ExecBase == NULL)
  110.         CleanExit(30);
  111.  
  112.     GadToolsBase = (struct GadToolsBase *) OpenLibrary ("gadtools.library", 36);
  113.     if (GadToolsBase == NULL)
  114.         CleanExit(30);
  115.     WBScreen = LockPubScreen(NULL);
  116.     if (WBScreen == NULL)
  117.         CleanExit(30);
  118.  
  119.     vi = GetVisualInfo (WBScreen, TAG_DONE);
  120.     if (vi == NULL)
  121.         CleanExit(30);
  122.  
  123.     ng.ng_TextAttr = WBScreen->Font;
  124.     ng.ng_VisualInfo = vi;
  125.     currgad = CreateContext (&gadlist);
  126.         ng.ng_GadgetText="";
  127.         ng.ng_Flags= PLACETEXT_IN;
  128.         ng.ng_GadgetID=NODEGAD_ID;      /* note the Bevy of ready-to-use execbase lists */
  129.     g0 = CreateGadget(LISTVIEW_KIND, currgad, &ng,
  130. /*                     GTLV_Labels,&(ExecBase->MemList), */
  131. /*                     GTLV_Labels,&(ExecBase->ResourceList), */
  132. /*                     GTLV_Labels,&(ExecBase->DeviceList), */
  133. /*                     GTLV_Labels,&(ExecBase->IntrList), */
  134. /*                     GTLV_Labels,&(ExecBase->LibList), */
  135.                     GTLV_Labels,&(ExecBase->PortList),
  136. /*                     GTLV_Labels,&(ExecBase->TaskReady), */
  137. /*                     GTLV_Labels,&(ExecBase->TaskWait), */
  138. /*                     GTLV_ShowSelected,NULL, */
  139. /*                     GTLV_Active, 1, */
  140.                                         TAG_DONE);
  141.     if (!g0)
  142.         Bummer("ListView Gad failed");
  143.         ng.ng_TopEdge= 115L;
  144.         ng.ng_Height= (WBScreen->Font->ta_YSize *4)/3;
  145.     ng.ng_Flags= PLACETEXT_IN;
  146.         ng.ng_GadgetText=" REFRESH ";
  147.         ng.ng_GadgetID=REFRESHBUTTON;
  148.     g1 = CreateGadget(BUTTON_KIND, g0, &ng, TAG_DONE);
  149.     if (!g1)
  150.         Bummer("Button Gad failed");
  151.     window1 = OpenWindowTagList (NULL, WindowTags);
  152.     AddGList (window1, gadlist, -1, -1, NULL);
  153.     RefreshGList(window1->FirstGadget, window1, NULL, (UWORD)-1);
  154.     GT_RefreshWindow (window1, NULL);
  155.     handleIDCMP (window1);
  156. }
  157.