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

  1. /**********************************************************************
  2. :Program.    GUIToolsDemo.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. :Remark.     Written without any C-Experience ! Sorry !!
  13. :History.    v1.1  Carsten Ziegeler  23-Jan-94
  14. ***********************************************************************/
  15.  
  16. /* ATTENTION: This modul is a direct translation of the modula2-demo.
  17.               It's my FIRST working C-program. It may not take in some cases
  18.               the easiest way to achive things, but it works ! */
  19.  
  20. #include <dos.h>
  21. #include <exec/types.h>
  22. #include <exec/nodes.h>
  23. #include <exec/lists.h>
  24. #include <exec/memory.h>
  25. #include <intuition/gadgetclass.h>
  26. #include <intuition/intuition.h>
  27. #include <intuition/screens.h>
  28. #include <libraries/gadtools.h>
  29. #include <proto/exec.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32.  
  33. #include "guitools.h"
  34.  
  35. /* Let's open an own hires-pal-screen with a full-sized window. All gadget-
  36.    kinds from GADTools are displayed. The results will be printed using
  37.    printf */
  38.  
  39. #define ListViewNode Node
  40.  
  41. struct Library *GUIToolsBase;
  42.  
  43. struct GUIInfo *G;  /* The most important one */
  44.  
  45. /* Labels for Cylce-, MX- and Listview-Gadget */
  46.  
  47. char *cycleLabs[] = {"ZERO", "ONE", "TWO", NULL};
  48.  
  49. char *mxLabs[]    = {"Man", "Woman", "Child", NULL};
  50.  
  51. char *listviewLabs[] = {"Amiga 500", "Amiga 500+", "Amiga 600",
  52.                         "Amiga 1000", "Amiga 1200", "Amiga 2000",
  53.                         "Amiga 3000", "Amiga 4000/030",
  54.                         "Amiga 4000/040", "Amiga XXXX/yyy"};
  55.  
  56. /*  Hook-Funktion, ,so we can use also chars which are not letters as
  57.     key-equivalents */
  58.  
  59. ULONG __saveds __asm VanKeyHookFct(register __d0 char key,
  60.                                    register __a0 WORD *nbr,
  61.                                    register __a1 WORD *shifted)
  62. {
  63.   /* We get in D0 the key. This function will put in A0 the gadget-number
  64.      that corresponds to the key and we will put in A1 if the key should
  65.      be treated as shifted (1).
  66.      If the key can be evaluated, the result is 1, otherwise 0.
  67.      We don't need geta4, because no global data is used
  68.        MXKind-gadgets do not support gadget-text, so we have to immitate
  69.        the key-equivalent.
  70.        We also use for the sliderKind-gadget a key-equivalent with the
  71.        + and - keys */
  72.   ULONG ret;
  73.   ret = 0;
  74.   switch (key) {
  75.   case 'm' : *nbr = 9;
  76.              *shifted = 0;
  77.              ret = 1;
  78.              break;
  79.   case 'M' : *nbr = 9;
  80.              *shifted = 1;
  81.              ret = 1;
  82.              break;
  83.  
  84.   case '+' : *nbr = 8;
  85.              *shifted = 0;
  86.              ret = 1;
  87.              break;
  88.   case '-' : *nbr = 8;
  89.              *shifted = 1;
  90.              ret = 1;
  91.              break;
  92.   }
  93.   return ret;
  94. }
  95.  
  96. /* Menu-Functions :
  97.    Don't forget geta4 ! If the result is 1, GUITools will stay in the
  98.    waiting-loop, otherwise it will return ! */
  99.  
  100. ULONG MenuAbout(void)
  101. {
  102.   geta4();
  103.   ShowRequester(G, "GUITools-Demo for Version 38.0\nGUITools ⌐ C.Ziegeler",
  104.                 okReqKind, NULL);
  105.   return 1;
  106. }
  107.  
  108. ULONG MenuQuit(void)
  109. {
  110.   geta4();
  111.   if (ShowRequester(G, "Really quit demo ?", doitReqKind, NULL) == reqDo)
  112.     return 0;
  113.   else
  114.     return 1;
  115. }
  116.  
  117.  
  118. /* Libraries will be opened by the auto init code ! Except GUITools !!*/
  119.  
  120. void main(void)
  121. {
  122.   struct Screen *S;
  123.   struct Window *W;
  124.  
  125.   struct MinList list;  /* List for ListviewKind-Gadget */
  126.   struct ListViewNode *entry;
  127.  
  128.   WORD i;
  129.  
  130.   /* Variables for the entry-fields */
  131.   char string[80];
  132.   LONG longI;
  133.   UWORD cycle;
  134.   UWORD mx;
  135.   SHORT check; /* boolean */
  136.   UWORD listview;
  137.   UWORD scroller;
  138.   UWORD slider;
  139.   UWORD color;
  140.  
  141.   int ende;
  142.  
  143.   /* open GUITools.library */
  144.  
  145.   GUIToolsBase = OpenLibrary(GUIToolsName, 38);
  146.  
  147.   if (GUIToolsBase == NULL)
  148.     printf("You need at least the guitools.library V38.0 !\n");
  149.   else
  150.   {
  151.     /* Init lists */
  152.  
  153.     NewList(&list);
  154.     for(i=0; i<=9; i++)
  155.     {
  156.       entry = AllocMem(sizeof(struct ListViewNode), MEMF_CLEAR);
  157.       if (entry)
  158.       {
  159.         entry->ln_Name = listviewLabs[i];
  160.         Insert(&list, entry, NULL);
  161.       }
  162.     }
  163.  
  164.     /* set values */
  165.     strcpy(string, "This is a text-line !");
  166.     longI  = 33106;
  167.     cycle  = 2;
  168.     mx     = 1;
  169.     check  = 1;
  170.     listview = 65535;
  171.     scroller = 1;
  172.     slider   = 5;
  173.     color    = 0;
  174.  
  175.     /* open screen with Topaz/8-Font! */
  176.  
  177.     S = OpenIntScreen(hiresPalID, 2, "Test_Screen", TopazAttr());
  178.     if (S)
  179.     {
  180.       /* And now a full-sized window */
  181.       W = OpenIntWindow(0, 0, asScreen, asScreen, "GUITools-Demo",
  182.                         IDCMP_CLOSEWINDOW|IDCMP_GADGETUP|IDCMP_GADGETDOWN|
  183.                         IDCMP_MENUPICK|IDCMP_REFRESHWINDOW|IDCMP_VANILLAKEY,
  184.                         WFLG_CLOSEGADGET|WFLG_ACTIVATE, S);
  185.       if (W)
  186.       {
  187.         /* create GUIInfo */
  188.         G = CreateGUIInfoTags(W, 20, 20, /* max 20 gadgets and menuitems */
  189.                               GUI_Flags, GFLG_StringNotify|
  190.                                          GFLG_IntegerNotify|
  191.                                          GFLG_MXNotify|
  192.             /* Notify for all gadgets */ GFLG_CycleNotify|
  193.                                          GFLG_CheckboxNotify|
  194.                                          GFLG_ListviewNotify|
  195.                                          GFLG_SliderNotify|
  196.                                          GFLG_ScrollerNotify|
  197.                                          GFLG_PaletteNotify|
  198.             /* conect entry-gadgets */   GFLG_CycleEntryGads|
  199.                                          GFLG_LinkEntryGads|
  200.             /* GUITools will do refresh*/GFLG_DoRefresh|
  201.             /* notify key-equivalents */ GFLG_VanillaKeysNotify|
  202.             /* internal: key-msg to gad-msg */  GFLG_ConvertKeys|
  203.             /* only interesting msgs */  GFLG_InternMsgHandling|
  204.             /* use the hook-function */  GFLG_CallVanillaKeyFct|
  205.             /* Call the function that */ GFLG_CallMenuData|
  206.             /* the userData contains */
  207.             /* Add GT_Underscore-Tag  */ GFLG_AddStdUnderscore,
  208.                           GUI_VanKeyFct, &VanKeyHookFct, NULL);
  209.         if (G)
  210.         {
  211.           CreateGadgetFull(G, 500, 200, 80, 20, BUTTON_KIND, "_Quit",
  212.                            PLACETEXT_IN, NULL);
  213.           CreateGadgetFull(G, 100, 20, 200, 13, STRING_KIND, "S_tring:",
  214.                            PLACETEXT_LEFT, GTST_String, &string,
  215.                                            GTST_MaxChars, 80, NULL);
  216.           CreateGadgetText(G, 100, 40,  80, 13, INTEGER_KIND, "_Longint:",
  217.                            GTIN_Number, &longI,         /* NOTIFY ! */
  218.                            GTIN_MaxChars, 7, NULL);
  219.           CreateGadgetText(G, 100, 60,  80,15, CYCLE_KIND, "C_ycle It:",
  220.                            GTCY_Active, &cycle,         /* NOTIFY */
  221.                            GTCY_Labels, &cycleLabs, NULL);
  222.           CreateGadgetText(G, 270, 100,  0, 0, CHECKBOX_KIND, "_Check it:",
  223.                            GTCB_Checked, &check, NULL);    /* NOTIFY */
  224.           CreateGadgetFull(G, 320, 40, 200, 80, LISTVIEW_KIND,
  225.                            "Choose List_view-Entry", PLACETEXT_ABOVE,
  226.                            GTLV_Selected, &listview,
  227.                            GTLV_Labels, &list,
  228.                            GTLV_ShowSelected, NULL, NULL);
  229.           CreateGadgetText(G, 20, 140, 600, 14, SCROLLER_KIND,
  230.                            "_Scroll Me",
  231.                            GTSC_Top, &scroller,
  232.                            GTSC_Total, 100,
  233.                            GA_Immediate, 1,
  234.                            GA_RelVerify, 1,
  235.                            PGA_Freedom, LORIENT_HORIZ, NULL);
  236.           CreateGadgetText(G, 120, 210, 250, 35, PALETTE_KIND,
  237.                            "This is a _palette !",
  238.                            GTPA_Depth, 2,
  239.                            GTPA_Color, &color,
  240.                            GTPA_IndicatorWidth, 50, NULL);
  241.           G->flags = G->flags - GFLG_AddStdUnderscore; /* clear bit  !
  242.                       Not possible for MX_KIND ! and not desired for
  243.                       SLIDER_KIND ! */
  244.           CreateGadgetText(G, 20, 180, 600, 14, SLIDER_KIND,
  245.                            "Slider me with + and -",
  246.                            GTSL_Min, 0,
  247.                            GTSL_Max, 200,
  248.                            GTSL_Level, &slider,
  249.                            GA_Immediate, 1,
  250.                            GA_RelVerify, 1,
  251.                            PGA_Freedom, LORIENT_HORIZ, NULL);
  252.           CreateGadgetFull(G, 100, 90,  80,17, MX_KIND, NULL,
  253.                            PLACETEXT_LEFT,
  254.                            GTMX_Active, &mx,   /* NOTIFY */
  255.                            GTMX_Labels, &mxLabs, NULL);
  256.           CreateGadgetText(G, 120, 78,  10,12, TEXT_KIND, "MX:",
  257.                            GTTX_Text, "Try pressing m", NULL);
  258.  
  259.           MakeMenuEntry(G, NM_TITLE, "Project", NULL);
  260.           MakeMenuEntry(G, NM_ITEM,  "About", "A");
  261.           G->menuAdr->nm_UserData = &MenuAbout;
  262.           MakeMenuEntry(G, NM_ITEM,  "Quit", "Q");
  263.           G->menuAdr->nm_UserData = &MenuQuit;
  264.  
  265.           if (SetGUI(G) == guiSet)  /* Draw all */
  266.           {
  267.             ende = 0;
  268.             while (ende == 0)  /* Input-Loop */
  269.             {
  270.               WaitIntMsg(G);
  271.               if (G->msgClass == IDCMP_CLOSEWINDOW) ende = 1;
  272.               if (G->msgClass == IDCMP_GADGETUP)
  273.               {    /* We are only interested in the button-gadget */
  274.                 if (G->gadID == 0) ende = 1;  /* ButtonGadget Quit */
  275.               }
  276.               if (G->msgClass == IDCMP_MENUPICK) ende = 1;
  277.               /* The procedures are automatically called within WaitIntMsg
  278.                  because GFLG_CallMenuData is set */
  279.             }
  280.             UpdateEntryGadgets(G); /* update entry-gadgets */
  281.  
  282.             /* And now print all values */
  283.             printf("\nYour input:\n");
  284.             printf("String   : %s\n", string);
  285.  
  286.             printf("Longint  : %ld\n", longI);
  287.  
  288.             printf("Cycle    : %s\n", cycleLabs[cycle]);
  289.  
  290.             printf("MX       : %s\n", mxLabs[mx]);
  291.  
  292.             printf("Check    : ");
  293.             if (check) printf("YES\n"); else printf("NO\n");
  294.  
  295.             printf("Listview : ");
  296.             if (listview == 65535) printf("nothing\n");
  297.             else
  298.               printf("%s\n", listviewLabs[9-listview]);
  299.               /* The list was created in reverse order ! */
  300.  
  301.             printf("Slider   : %d\n", slider);
  302.  
  303.             printf("Scroller : %d\n", scroller);
  304.  
  305.             printf("Color    : %u\n", color);
  306.  
  307.           }
  308.         }
  309.       } /* if (W) */
  310.     } /* if (S) */
  311.   } /* if (GUIToolsBase) */
  312.  
  313.   if (S) CloseIntScreen(S);
  314.       /* The closing of the window etc is done by GUITools ! */
  315.  
  316.   while (list.mlh_TailPred != &list)  /* free list */
  317.     FreeMem(RemTail(&list), sizeof(struct ListViewNode));
  318.  
  319.   if (GUIToolsBase) CloseLibrary(GUIToolsBase);
  320. }
  321.