home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_GEN / GUITLS38.ZIP / WBDEMO.C < prev    next >
C/C++ Source or Header  |  1994-02-05  |  8KB  |  221 lines

  1. /**********************************************************************
  2. :Program.    WBDemo.c
  3. :Contents.   guitools.library demonstration
  4. :Author.     Carsten Ziegeler
  5. :Address.    Augustin-Wibbelt-Str.7, 33106 Paderborn
  6. :Phone.      05254/67439
  7. :Copyright.  Freeware, refer to documentation
  8. :Language.   C
  9. :Translator. SASC 6.51
  10. :Remark.     OS 2.0 required
  11. :Remark.     requires guitools.library V38.0
  12. :History.    v1.1  Carsten Ziegeler  28-Jan-94
  13. ***********************************************************************)
  14.  
  15. /* ATTENTION: This modul is a direct translation of the modula2-demo.
  16.               It's my SECOND working C-program. It may not take in some cases
  17.               the easiest way to achive things, but it works ! */
  18.  
  19. #include <exec/types.h>
  20. #include <exec/nodes.h>
  21. #include <exec/lists.h>
  22. #include <exec/memory.h>
  23. #include <intuition/intuition.h>
  24. #include <libraries/gadtools.h>
  25. #include <proto/exec.h>
  26. #include "guitools.h"
  27.  
  28.  
  29. struct Library *GUIToolsBase;
  30.  
  31.  
  32. char *listviewALabs[] = {"Amiga 500", "Amiga 500+", "Amiga 600",
  33.                          "Amiga 1000", "Amiga 1200", "Amiga 2000",
  34.                          "Amiga 3000", "Amiga 4000/030",
  35.                          "Amiga 4000/040", "Amiga XXXX/yyy"};
  36.  
  37. char *listviewCLabs[] = {"2086", "80286", "80386", "80486",
  38.                          "Pentium", "MC 68000", "MC 68020",
  39.                          "MC 68030", "MC 68040", "MC 68060"};
  40.  
  41.  
  42. /* Libraries will be opened by the auto init code ! Except GUITools !!*/
  43.  
  44. void main(void)
  45. {
  46.   struct Window *win, *oldWin;
  47.   struct GUIInfo *gui;
  48.  
  49.   WORD innerWidth, innerHeight;
  50.   int  prg, ende;
  51.  
  52.   struct MinList alist, clist;        /* Lists for ListviewKind-Gadget */
  53.  
  54.     /* Creates two exec.lists. One contains some amiga-models and the other
  55.        some cpu-kinds ! */
  56.     struct Node *entry;
  57.     int i;
  58.  
  59.     /* Init amiga-list & cpu-list */
  60.     NewList(&alist);
  61.     NewList(&clist);
  62.  
  63.     for(i=0; i<=9; i++)    /* make the list-entries */
  64.     {
  65.       entry = AllocMem(sizeof(struct Node), MEMF_CLEAR);
  66.       if (entry)
  67.       {
  68.         entry->ln_Name = listviewALabs[i];
  69.         Insert(&alist, entry, NULL);
  70.       }
  71.       entry = AllocMem(sizeof(struct Node), MEMF_CLEAR);
  72.       if (entry)
  73.       {
  74.         entry->ln_Name = listviewCLabs[i];
  75.         Insert(&clist, entry, NULL);
  76.       }
  77.     }
  78.  
  79.   /* open GUITools.library */
  80.  
  81.   GUIToolsBase = OpenLibrary(GUIToolsName, 38);
  82.  
  83.   if (GUIToolsBase == NULL)
  84.     SimpleReq("You need at least the guitools.library V38.0 !", okReqKind);
  85.   else
  86.   {
  87.  
  88.     win = OpenIntWindowTags( 50, 50, 300, 150, "WB-Demo",
  89.                             IDCMP_GADGETUP | IDCMP_CLOSEWINDOW |
  90.                             IDCMP_NEWSIZE | IDCMP_REFRESHWINDOW |
  91.                             IDCMP_VANILLAKEY,
  92.                             WFLG_ACTIVATE | WFLG_SIZEGADGET |
  93.                             WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  94.                             WFLG_DRAGBAR, NULL,
  95.                             WA_MinWidth, 250,
  96.                             WA_MinHeight,120,
  97.                             WA_MaxWidth, 500,
  98.                             WA_MaxHeight,200, NULL);
  99.     if (win)
  100.     {
  101.       oldWin = SetProcessWindow(win);
  102.       gui = CreateGUIInfoTags(win, 5, 0, GUI_ResizableGads, 1,
  103.                    GUI_Flags, GFLG_AddBorderDims | GFLG_DoRefresh |
  104.                               GFLG_VanillaKeysNotify | GFLG_ConvertKeys,
  105.                    GUI_GadFont, TopazAttr(), NULL);
  106.       if (gui)
  107.       {
  108.         innerWidth  = win->Width - win->BorderRight - win->BorderLeft;
  109.         innerHeight = win->Height- win->BorderTop - win->BorderBottom;
  110.         CreateSpecialGadget(gui, 20, 20, innerWidth-30, innerHeight-55,
  111.                             progressIndicatorKind,
  112.                             SG_GadgetText, "Progress",
  113.                             SG_GadgetFlags, PLACETEXT_ABOVE, NULL);
  114.         gui->flags = gui->flags +  GFLG_AddStdUnderscore; /* set bit */
  115.         CreateGadgetFull(gui, 20, innerHeight-30, 70, 18, BUTTON_KIND,
  116.                          "_Plus", PLACETEXT_IN, NULL);
  117.         CreateGadgetText(gui, innerWidth-90, innerHeight-30, 70, 18,
  118.                          BUTTON_KIND, "_Minus", NULL);
  119.         gui->flags = gui->flags - GFLG_AddStdUnderscore; /* clear bit */
  120.         if (SetGUI(gui) == guiSet)
  121.         {
  122.           prg = 0;
  123.           ende = 0;
  124.           while (ende == 0)
  125.           {
  126.             WaitIntMsg(gui);
  127.  
  128.             if (gui->msgClass == IDCMP_CLOSEWINDOW) ende = 1;
  129.             if (gui->msgClass == IDCMP_GADGETUP)
  130.             {
  131.               if (gui->gadID == 1)
  132.               {
  133.                 if (prg < 10) prg++;
  134.                 ModifyGadget(gui, 0, SGPI_CurrentValue, prg * 10, NULL);
  135.               }
  136.               if (gui->gadID == 2)
  137.               {
  138.                 if (prg >  0) prg--;
  139.                 ModifyGadget(gui, 0, SGPI_CurrentValue, prg * 10, NULL);
  140.               }
  141.             }
  142.             if (gui->msgClass == IDCMP_NEWSIZE)
  143.             {
  144.               innerWidth  = win->Width - win->BorderRight - win->BorderLeft;
  145.               innerHeight = win->Height- win->BorderTop - win->BorderBottom;
  146.               ResizeGadget(gui, 0, preserve, preserve,
  147.                                    innerWidth-30, innerHeight-55);
  148.               ResizeGadget(gui, 1, preserve, innerHeight-25,
  149.                                    preserve, preserve);
  150.               ResizeGadget(gui, 2, innerWidth-90, innerHeight-25,
  151.                                    preserve, preserve);
  152.               if (RedrawGadgets(gui, TRUE) != guiSet) ende = 1;
  153.             }
  154.           }
  155.         }
  156.         RemoveGadgets(gui, 1);
  157.         ClearWindow(gui);
  158.  
  159.         innerWidth  = win->Width - win->BorderRight - win->BorderLeft;
  160.         innerHeight = win->Height- win->BorderTop - win->BorderBottom;
  161.         CreateGadget(gui, 20, 10, innerWidth-35, innerHeight-45,
  162.                      LISTVIEW_KIND, GTLV_Labels, &alist, NULL);
  163.         gui->flags = gui->flags + GFLG_AddStdUnderscore;  /* set bit */
  164.         CreateGadgetFull(gui, 20, innerHeight-30, 70, 18, BUTTON_KIND,
  165.                          "_Amigas", PLACETEXT_IN, NULL);
  166.         CreateGadgetText(gui, innerWidth-90, innerHeight-30, 70, 18,
  167.                          BUTTON_KIND, "_CPUs", NULL);
  168.         CreateSpecialGadget(gui, 10, 5, innerWidth-15, innerHeight-10,
  169.                             bevelboxKind, SGBB_Recessed, 1, NULL);
  170.         if (SetGUI(gui) == guiSet)
  171.         {
  172.           ende = 0;
  173.           while (ende == 0)
  174.           {
  175.             WaitIntMsg(gui);
  176.  
  177.             if (gui->msgClass == IDCMP_CLOSEWINDOW) ende = 1;
  178.             if (gui->msgClass == IDCMP_GADGETUP)
  179.             {
  180.               if (gui->gadID == 1)    /* Amiga-list */
  181.                 ModifyGadget(gui, 0, GTLV_Labels, &alist, NULL);
  182.               if (gui->gadID == 2)    /* CPU-list */
  183.                 ModifyGadget(gui, 0, GTLV_Labels, &clist, NULL);
  184.             }
  185.             if (gui->msgClass == IDCMP_NEWSIZE)
  186.             {
  187.               innerWidth  = win->Width - win->BorderRight - win->BorderLeft;
  188.               innerHeight = win->Height- win->BorderTop - win->BorderBottom;
  189.               ResizeGadget(gui, 0, preserve, preserve,
  190.                                    innerWidth-35, innerHeight-45);
  191.               ResizeGadget(gui, 1, preserve, innerHeight-30,
  192.                                    preserve, preserve);
  193.               ResizeGadget(gui, 2, innerWidth-90, innerHeight-30,
  194.                                    preserve, preserve);
  195.               ResizeGadget(gui, 3, preserve, preserve,
  196.                                    innerWidth-15, innerHeight-10);
  197.               if (RedrawGadgets(gui, 1) != guiSet) ende = 1;
  198.             }
  199.           }
  200.         }
  201.       }
  202.       else
  203.         SimpleReq("Unable to create gui-info-structure !", okReqKind);
  204.     }
  205.     else
  206.       SimpleReq("Unable to open window !", okReqKind);
  207.  
  208.   }
  209.   if (win != NULL)
  210.   {
  211.     SetProcessWindow(oldWin);
  212.     CloseIntWindow(win);
  213.   }
  214.   while (alist.mlh_TailPred != &alist)  /* free list */
  215.     FreeMem(RemTail(&alist), sizeof(struct Node));
  216.   while (clist.mlh_TailPred != &clist)  /* free list */
  217.     FreeMem(RemTail(&clist), sizeof(struct Node));
  218.  
  219.   if (GUIToolsBase) CloseLibrary(GUIToolsBase);
  220. }
  221.