home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / CDTools / ClassAct / Examples / Layout / WeightedDemo.c < prev    next >
C/C++ Source or Header  |  1997-07-09  |  8KB  |  306 lines

  1. ;/*
  2. sc link weighteddemo.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /* Layout Gadget Example.
  7.  * In this example we will NOT use window.class - just to show it is possible.
  8.  * Note, we do *NOT* recommend this. Window.class offers automatic prefs refresh,
  9.  * and support for window backfills, iconification and keyboard control!
  10.  */
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <intuition/intuition.h>
  15. #include <intuition/gadgetclass.h>
  16. #include <intuition/icclass.h>
  17.  
  18. #include <graphics/gfxbase.h>
  19. #include <graphics/text.h>
  20. #include <graphics/gfxmacros.h>
  21. #include <utility/tagitem.h>
  22.  
  23. #include <proto/intuition.h>
  24. #include <proto/graphics.h>
  25. #include <proto/exec.h>
  26. #include <proto/dos.h>
  27. #include <proto/diskfont.h>
  28. #include <proto/utility.h>
  29.  
  30. #include <classact.h>
  31.  
  32. /*************************************************************************
  33.  * Main Program
  34.  */
  35. int main(argc,argv)
  36.     int argc;
  37.     char *argv[];
  38. {
  39.     struct Screen *Scr = NULL;
  40.     struct Window *Win = NULL;
  41.     struct Gadget *gParent = NULL;
  42.  
  43.     if (!ButtonBase)
  44.         return(20);
  45.  
  46.     if(argc > 1)
  47.         Scr = LockPubScreen(argv[1]);
  48.     else
  49.         Scr = LockPubScreen("Workbench");
  50.  
  51.     if (Scr == NULL)
  52.     {
  53.         /* Shut down, no screen lock
  54.          */ 
  55.         Printf("Failed locking public screen.\n");
  56.         return(5);
  57.     }
  58.  
  59.     /* In this example we will create the layout group before opening
  60.      * the window, and size the window to the minimum layout size
  61.      * returned by the LayoutLimits() function, then SetGadgetAttr()
  62.      * will be used to cause the GREL layout group to resize with the window.
  63.      */
  64.  
  65.     gParent = VGroupObject,
  66.         ICA_TARGET, ICTARGET_IDCMP,
  67.  
  68.         LAYOUT_SpaceOuter, TRUE,
  69.         LAYOUT_BevelStyle, BVS_GROUP,
  70.         LAYOUT_DeferLayout, TRUE,    /* this tag instructs layout.gadget to
  71.                                      * defer GM_LAYOUT and GM_RENDER and ask
  72.                                      * the application to do them. This
  73.                                      * lessens the load on input.device
  74.                                      */
  75.         LAYOUT_AddChild, HGroupObject,
  76.                 LAYOUT_SpaceOuter, FALSE,
  77.                 LAYOUT_AddChild, HGroupObject,
  78.                         LAYOUT_SpaceOuter, TRUE,
  79.                         /* the first group is three label-less buttons
  80.                          * side by side
  81.                          */
  82.                         LAYOUT_BevelStyle, BVS_GROUP,
  83.                         LAYOUT_Label, "Horizontal",
  84.                         LAYOUT_AddChild, ButtonObject,
  85.                             End,
  86.                         LAYOUT_AddChild, ButtonObject,
  87.                             End,
  88.                         LAYOUT_AddChild, ButtonObject,
  89.                             End,
  90.                     End,
  91.  
  92.                 LAYOUT_AddChild, VGroupObject,
  93.                         LAYOUT_SpaceOuter, TRUE,
  94.                         /* the second group is three label-less buttons
  95.                          * in a vertical group
  96.                          */
  97.                         LAYOUT_BevelStyle, BVS_GROUP,
  98.                         LAYOUT_Label, "Vertical",
  99.                         LAYOUT_AddChild, ButtonObject,
  100.                             End,
  101.                         LAYOUT_AddChild, ButtonObject,
  102.                             End,
  103.                         LAYOUT_AddChild, ButtonObject,
  104.                             End,
  105.                     End,
  106.             End,
  107.  
  108.         LAYOUT_AddChild, HGroupObject,
  109.                 /* four buttons of varying widths */
  110.                 LAYOUT_BevelStyle, BVS_SBAR_VERT,
  111.                 LAYOUT_Label, "Free, Fixed and Weighted sizes.",
  112.                 LAYOUT_AddChild, ButtonObject,
  113.                         GA_Text, "25Kg",
  114.                     End,
  115.                     CHILD_WeightedWidth, 25,
  116.  
  117.                 LAYOUT_AddChild, ButtonObject,
  118.                         GA_Text, "50Kg",
  119.                     End,
  120.                     CHILD_WeightedWidth, 50,
  121.  
  122.                 LAYOUT_AddChild, ButtonObject,
  123.                         GA_Text, "75Kg",
  124.                     End,
  125.                     CHILD_WeightedWidth, 75,
  126.  
  127.                 LAYOUT_AddChild, ButtonObject,
  128.                         GA_Text, "100Kg",
  129.                     End,
  130.                     CHILD_WeightedWidth, 100,
  131.             End,
  132.             CHILD_WeightedHeight,0,
  133.  
  134.         LAYOUT_AddChild, HGroupObject,
  135.                 /* four buttons sized in another way */
  136.                 LAYOUT_AddChild, ButtonObject,
  137.                         GA_Text, "Free",
  138.                     End,
  139.  
  140.                 LAYOUT_AddChild, ButtonObject,
  141.                         GA_Text, "Fixed",
  142.                     End,
  143.                     CHILD_WeightedWidth, 0,
  144.  
  145.                 LAYOUT_AddChild, ButtonObject,
  146.                         GA_Text, "Free",
  147.                     End,
  148.  
  149.                 LAYOUT_AddChild, ButtonObject,
  150.                         GA_Text, "Fixed",
  151.                     End,
  152.                     CHILD_WeightedWidth, 0,
  153.             End,
  154.             CHILD_WeightedHeight,0,
  155.             CHILD_MinWidth, 300,
  156.  
  157.         End;
  158.  
  159.     if (gParent)
  160.     {
  161.         struct LayoutLimits Limits;
  162.         struct TextFont *font = OpenFont( Scr->Font );
  163.  
  164.         /* Query parent layout group for min/max layout limits. */
  165.         LayoutLimits( gParent, &Limits, font, Scr );
  166.  
  167.         CloseFont( font );
  168.  
  169.         if (Win = OpenWindowTags(NULL,
  170.             WA_Flags, WFLG_DEPTHGADGET | WFLG_DRAGBAR |
  171.                 WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_SIZEGADGET,
  172.             WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_IDCMPUPDATE,
  173.             WA_Top, 20,
  174.             WA_Left, 20,
  175.             WA_InnerWidth, Limits.MinWidth,        /* open the window at the minimum */
  176.             WA_InnerHeight, Limits.MinHeight,    /* size in which the layout fits */
  177.             WA_NoCareRefresh, TRUE,    /* only BOOPSI here, no need for separate refreshing */
  178.             WA_PubScreen, Scr,
  179.             WA_Title, "ClassAct layout.gadget Example",
  180.             WA_ScreenTitle, "ClassAct Copyright 1995 Phantom Development LLC.",
  181.             TAG_END))
  182.         {
  183.             ULONG wsig = 1L << Win->UserPort->mp_SigBit;
  184.             struct IntuiMessage *msg;
  185.             BOOL done = FALSE;
  186.  
  187.             WORD BorderWidth = Win->BorderLeft + Win->BorderRight;
  188.             WORD BorderHeight = Win->BorderTop + Win->BorderBottom;
  189.  
  190.             /* set the window minimum and maximum size to the limits of the layout */
  191.             WindowLimits(Win,
  192.                         Limits.MinWidth + BorderWidth,
  193.                         Limits.MinHeight + BorderHeight,
  194.                         Limits.MaxWidth + BorderWidth,
  195.                         Limits.MaxHeight + BorderHeight);
  196.  
  197.             /* make the layout group resize itself relative to window size */
  198.             SetGadgetAttrs( gParent, NULL, NULL, 
  199.                         GA_Top, Win->BorderTop,
  200.                         GA_Left, Win->BorderLeft,
  201.                         GA_RelWidth, -BorderWidth,
  202.                         GA_RelHeight, -BorderHeight,
  203.                         TAG_END);
  204.  
  205.             /* make the layout visible */
  206.             AddGadget(Win, gParent, -1);
  207.             RefreshGList(gParent, Win, NULL, 1);
  208.  
  209.             while (done == FALSE)
  210.             {
  211.                 ULONG sig = Wait(wsig | SIGBREAKF_CTRL_C);
  212.  
  213.                 if (sig & wsig)
  214.                 {
  215.                     while (msg = (struct IntuiMessage *) GetMsg(Win->UserPort))
  216.                     {
  217.                         /* If you chooser to reply to the message before processing
  218.                          * it, remember that for IDCMP_IDCMPUPDATE the IAddress
  219.                          * field points to a tag list that will get free'd on reply.
  220.                          *
  221.                          * Before replying, check if the message is IDCMPUPDATE
  222.                          * and CloneTagItems(msg->IAddress). Don't forget to
  223.                          * FreeTagItems() your cloned list after you have
  224.                          * processed it.
  225.                          */
  226.                     
  227.                         switch (msg->Class)
  228.                         {
  229.                             case IDCMP_CLOSEWINDOW:
  230.                                  done = TRUE;
  231.                                  break;
  232.                                  
  233.                             case IDCMP_IDCMPUPDATE:
  234.                                 {
  235.                                     /* These are the deferred layout specific event 
  236.                                      * handlers. This is not as sophisticated as
  237.                                      * window.class's internal logic, but it will suffice.
  238.                                      */
  239.                                     if (FindTagItem(LAYOUT_RequestRefresh,msg->IAddress))
  240.                                     {
  241.                                         /*    Intuition attempted to refresh the window,
  242.                                          *    layout.gadget sent this message to the application.
  243.                                          *    We now do the refresh. This is done here because
  244.                                          *    refreshing a very complex layout could take some
  245.                                          *    time, and doing it in input.device context makes
  246.                                          *    the pointer jumpy.
  247.                                          *    RefreshWindowFrame() will refresh not only the
  248.                                          *    window border but also all gadgets. 
  249.                                          *    RefreshGList(gParent, Win, NULL, 1);
  250.                                          */
  251.                                         RefreshWindowFrame( Win );
  252.                                         break;
  253.                                     }
  254.                                     else if (FindTagItem(LAYOUT_RequestLayout,msg->IAddress))
  255.                                     {
  256.                                         /*    GM_LAYOUT can be a slow operation, so we don't
  257.                                          *    want it to be done my input.device...
  258.                                          */
  259.                                         RethinkLayout(gParent, Win, NULL, FALSE );
  260.                                         break;
  261.                                     }
  262.                                     else if (FindTagItem(LAYOUT_RelVerify,msg->IAddress))                                            
  263.                                     {
  264.                                         /* LAYOUT_RelVerify matches an IDCMP_GADGETUP,
  265.                                          * which is somewhat restricted because of
  266.                                          * Intuition limitations....
  267.                                          */
  268.                                         
  269.                                         switch ( GetTagData(GA_ID,0,msg->IAddress) )
  270.                                         {
  271.                                             default:
  272.                                                 done = TRUE;
  273.                                                 break;
  274.                                         }
  275.                                         break;
  276.                                     }
  277.                                 }
  278.                                 break;
  279.  
  280.                             default:
  281.                                 break;
  282.                         }
  283.  
  284.                         ReplyMsg((struct Message *) msg);
  285.                     }
  286.                 }
  287.                 else if (sig & SIGBREAKF_CTRL_C)
  288.                 {
  289.                     done = TRUE;
  290.                 }
  291.             }
  292.  
  293.             RemoveGadget(Win, gParent);
  294.             CloseWindow(Win);
  295.         }
  296.  
  297.         /* Disposing a layout instance will automatically dispose
  298.          * all the child objects.
  299.          */
  300.         DisposeObject(gParent);
  301.     }
  302.  
  303.     UnlockPubScreen(0, Scr);
  304.     exit(0);
  305. }
  306.