home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d911 / gadlayout.lha / GadLayout / Test.c < prev    next >
C/C++ Source or Header  |  1993-10-03  |  5KB  |  218 lines

  1.  
  2. /**
  3.  **  Test.c -- An example of using the GadLayout dynamic gadget layout system.
  4.  **
  5.  **  By Timothy Aston, public domain.
  6.  **
  7.  **    A "do nothing" example that simpy creates a bunch of gadgets in a
  8.  **    window and waits for the user to close the window.  The purpose is
  9.  **    to demonstrate many of the features available in GadLayout for laying
  10.  **    out gadgets.
  11.  **
  12.  **    I wanted to write a slightly more extensive demonstration of what
  13.  **    GadLayout can do, this doesn't show a lot of what can be done.
  14.  **
  15.  **    Compiled using DICE 2.07.54: dcc Test.c gadlayout.o -o Test -r
  16.  **
  17.  **/
  18.  
  19. #include <exec/types.h>
  20. #include <intuition/intuition.h>
  21. #include <libraries/gadtools.h>
  22. #include <libraries/locale.h>
  23. #include <utility/tagitem.h>
  24. #include <clib/intuition_protos.h>
  25. #include <clib/gadtools_protos.h>
  26. #include <clib/locale_protos.h>
  27. #include "gadlayout.h"
  28. #include "gadlayout_protos.h"
  29.  
  30. #ifndef GTCB_Scaled
  31. #define GTCB_Scaled GT_TagBase + 68
  32. #endif
  33.  
  34. #define LEFT_OFFSET 6
  35. #define TOP_OFFSET 4
  36.  
  37. struct Library *LocaleBase = NULL;    /* LocaleBase MUST be defined, even if
  38.                                      * you don't use it!!! */
  39. struct Screen *screen = NULL;
  40. struct Window *win = NULL;
  41. APTR gi = NULL;
  42.  
  43. UBYTE test_str[100];                /* Buffer for the string gadget */
  44.  
  45.  
  46. /* Here are the tag lists that define each gadget.  Note that a gadget
  47.  * consists of a GadLayout tag list as well as a GadTools tag list (except
  48.  * for the GadLayout extended gadget kinds).
  49.  */
  50.  
  51. enum { GAD_BUTTON1, GAD_BUTTON2, GAD_DRAWER, GAD_STRING, GAD_CHECKBOX };
  52.  
  53. struct TagItem button1_layout_tags[] =
  54. {
  55.     { GL_GadgetKind, BUTTON_KIND },
  56.     { GL_GadgetText, "Button _1" },
  57.     { GL_Left, LEFT_OFFSET },
  58.     { GL_Top, TOP_OFFSET },
  59.     { GL_AutoHeight, 4 },
  60.     { GL_DupeWidth, GAD_BUTTON2 },
  61.     { GL_Flags, PLACETEXT_IN },
  62.     { TAG_DONE, NULL }
  63. };
  64.  
  65. struct TagItem button1_gadtools_tags[] =
  66. {
  67.     { GT_Underscore, '_' },
  68.     { TAG_DONE, NULL }
  69. };
  70.  
  71. struct TagItem button2_layout_tags[] =
  72. {
  73.     { GL_GadgetKind, BUTTON_KIND },
  74.     { GL_GadgetText, "And Button _2" },
  75.     { GL_AutoWidth, 10 },
  76.     { GL_AutoHeight, 4 },
  77.     { GL_TopRel, GAD_BUTTON1 },
  78.     { GL_AddTop, INTERHEIGHT },
  79.     { TAG_DONE, NULL }
  80. };
  81.  
  82. struct TagItem button2_gadtools_tags[] =
  83. {
  84.     { GT_Underscore, '_' },
  85.     { TAG_DONE, NULL }
  86. };
  87.  
  88. struct TagItem drawer_layout_tags[] =
  89. {
  90.     { GL_GadgetKind, DRAWER_KIND },
  91.     { GL_GadgetText, "_Filename" },
  92.     { GL_Top, TOP_OFFSET },
  93.     { GL_LeftRel, GAD_BUTTON1 },
  94.     { GL_AdjustLeft, INTERWIDTH * 2},
  95.     { GL_Width, 20 },
  96.     { GL_AutoHeight, 4 },
  97.     { GL_Flags, PLACETEXT_LEFT },
  98.     { TAG_DONE, NULL }
  99. };
  100.  
  101. struct TagItem string_layout_tags[] =
  102. {
  103.     { GL_GadgetKind, STRING_KIND },
  104.     { GL_GadgetText, NULL },
  105.     { GL_Width, 100 },
  106.     { GL_LeftRel, GAD_DRAWER },
  107.     { TAG_DONE, NULL }
  108. };
  109.  
  110. struct TagItem string_gadtools_tags[] =
  111. {
  112.     { GTST_MaxChars, 100 },
  113.     { GTST_String, test_str },
  114.     { GT_Underscore, '_' },
  115.     { TAG_DONE, NULL }
  116. };
  117.  
  118. struct TagItem checkbox_layout_tags[] =
  119. {
  120.     { GL_GadgetKind, CHECKBOX_KIND },
  121.     { GL_GadgetText, "Checkbox" },
  122.     { GL_Width, 26 },
  123.     { GL_AutoHeight, 1 },
  124.     { GL_TopRel, GAD_DRAWER },
  125.     { GL_AddTop, INTERHEIGHT },
  126.     { GL_AlignRight, GAD_STRING },
  127.     { GL_Flags, PLACETEXT_LEFT },
  128.     { TAG_DONE, NULL }
  129. };
  130.  
  131. struct TagItem checkbox_gadtools_tags[] =
  132. {
  133.     { GTCB_Checked, TRUE },
  134.     { GTCB_Scaled, TRUE },
  135.     { GT_Underscore, '_' },
  136.     { TAG_DONE, NULL }
  137. };
  138.  
  139.  
  140. /* This structure describes all the gadgets we have just defined, so that
  141.  * they can all be passed at once to the LayoutGadgets() function.
  142.  */
  143. struct LayoutGadget gadgets[] =
  144. {
  145.     { GAD_BUTTON1,    button1_layout_tags,    button1_gadtools_tags,    NULL },
  146.     { GAD_BUTTON2,    button2_layout_tags,    button2_gadtools_tags,    NULL },
  147.     { GAD_DRAWER,    drawer_layout_tags,        NULL,                    NULL },
  148.     { GAD_STRING,    string_layout_tags,        string_gadtools_tags,    NULL },
  149.     { GAD_CHECKBOX,    checkbox_layout_tags,    checkbox_gadtools_tags,    NULL },
  150.     { -1, NULL, NULL, NULL }
  151. };
  152.  
  153.  
  154. main()
  155. {
  156.     struct Gadget *glist;
  157.     WORD farright, farbottom;
  158.  
  159.     /* We'll just open up on the Workbench screen, and use its screen font.
  160.      * Try changing the screen font in your Font prefs to all sorts of
  161.      * ridiculous sizes and see how well this simple example adjust.
  162.      */
  163.     if (screen = LockPubScreen("Workbench"))
  164.     {
  165.         if (gi = LayoutGadgets(&glist, gadgets, screen,
  166.             GL_RightExtreme, &farright,
  167.             GL_LowerExtreme, &farbottom,
  168.             GL_DefTextAttr, screen->Font,
  169.             TAG_DONE))
  170.         {
  171.             /* Open the window, note how we size the window to perfectly fit
  172.              * all the gadgets.
  173.              */
  174.             if (win = OpenWindowTags(NULL,
  175.                 WA_Left, 0,
  176.                 WA_Top, screen->Font->ta_YSize + 3,
  177.                 WA_InnerWidth, farright + LEFT_OFFSET,
  178.                 WA_InnerHeight, farbottom + TOP_OFFSET,
  179.                 WA_IDCMP, BUTTONIDCMP | STRINGIDCMP | IDCMP_REFRESHWINDOW |
  180.                             IDCMP_CLOSEWINDOW,
  181.                 WA_Flags, WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET |
  182.                             WFLG_ACTIVATE | WFLG_SMART_REFRESH |
  183.                             WFLG_GIMMEZEROZERO,
  184.                 WA_Gadgets, glist,
  185.                 WA_Title, "GadLayout Test",
  186.                 TAG_DONE))
  187.             {
  188.                 struct IntuiMessage *imsg;
  189.                 BOOL ok = TRUE;
  190.  
  191.                 /* Just wait around until the close gadget is pressed.
  192.                  */
  193.                 while (ok)
  194.                 {
  195.                     WaitPort(win->UserPort);
  196.                     while (imsg = GT_GetIMsg(win->UserPort))
  197.                     {
  198.                         if (imsg->Class == IDCMP_CLOSEWINDOW)
  199.                             ok = FALSE;
  200.                         GT_ReplyIMsg(imsg);
  201.                     }
  202.                 }
  203.                 CloseWindow(win);
  204.             }
  205.             else
  206.                 PutStr("ERROR: Couldn't open window\n");
  207.  
  208.             FreeLayoutGadgets(gi);
  209.         }
  210.         else
  211.             PutStr("ERROR: Couldn't layout gadgets\n");
  212.  
  213.         UnlockPubScreen(0, screen);
  214.     }
  215.     else
  216.         PutStr("ERROR: Couldn't lock public screen\n");
  217. }
  218.