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

  1. ;/* Dynamic Example
  2. sc link dynamicexample.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /* system includes
  7.  */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11.  
  12. #include <exec/types.h>
  13. #include <exec/memory.h>
  14. #include <libraries/gadtools.h>
  15. #include <intuition/intuition.h>
  16. #include <intuition/gadgetclass.h>
  17. #include <graphics/gfxbase.h>
  18. #include <graphics/text.h>
  19. #include <graphics/gfxmacros.h>
  20. #include <utility/tagitem.h>
  21. #include <workbench/startup.h>
  22. #include <workbench/workbench.h>
  23.  
  24. #include <proto/intuition.h>
  25. #include <proto/graphics.h>
  26. #include <proto/exec.h>
  27. #include <proto/dos.h>
  28. #include <proto/utility.h>
  29. #include <proto/wb.h>
  30. #include <proto/icon.h>
  31.  
  32. /* ClassAct includes
  33.  */
  34. #include <classact.h>
  35.  
  36. enum
  37. {
  38.     GID_MAIN=0,
  39.     GID_ADDBUTTON,
  40.     GID_REMBUTTON,
  41.     GID_REPLACE,
  42.     GID_ADDED,
  43.     GID_QUIT,
  44.     GID_LAST
  45. };
  46.  
  47. enum
  48. {
  49.     WID_MAIN=0,
  50.     WID_LAST
  51. };
  52.  
  53. enum
  54. {
  55.     OID_MAIN=0,
  56.     OID_LAST
  57. };
  58.  
  59. int main(void)
  60. {
  61.     struct MsgPort *AppPort;
  62.  
  63.     struct Window *windows[WID_LAST];
  64.  
  65.     struct Gadget *gadgets[GID_LAST];
  66.  
  67.     Object *objects[OID_LAST];
  68.  
  69.     /* we must initialize this pointer! */
  70.     gadgets[GID_ADDED] = NULL;
  71.  
  72.     /* make sure our classes opened... */
  73.     if (!ButtonBase || !CheckBoxBase || !WindowBase || !LayoutBase)
  74.         return(30);
  75.     else if ( AppPort = CreateMsgPort() )
  76.     {
  77.         /* Create the window object.
  78.          */
  79.         objects[OID_MAIN] = WindowObject,
  80.             WA_ScreenTitle, "ClassAct Release 2.0",
  81.             WA_Title, "ClassAct Dynamic Layout Example",
  82.             WA_Activate, TRUE,
  83.             WA_DepthGadget, TRUE,
  84.             WA_DragBar, TRUE,
  85.             WA_CloseGadget, TRUE,
  86.             WA_SizeGadget, TRUE,
  87.             WINDOW_IconifyGadget, TRUE,
  88.             WINDOW_IconTitle, "Dynamic Iconified",
  89.             WINDOW_AppPort, AppPort,
  90.             WINDOW_Position, WPOS_CENTERMOUSE,
  91.             WINDOW_ParentGroup, gadgets[GID_MAIN] = VGroupObject,
  92.                 LAYOUT_DeferLayout, TRUE,
  93.                 LAYOUT_SpaceOuter, TRUE,
  94.  
  95.                 LAYOUT_AddChild, HGroupObject,
  96.                     LAYOUT_EvenSize, TRUE,
  97.                     LAYOUT_AddChild, gadgets[GID_ADDBUTTON] = ButtonObject,
  98.                         GA_ID, GID_ADDBUTTON,
  99.                         GA_RelVerify, TRUE,
  100.                         GA_Text, "_AddChild",
  101.                     ButtonEnd,
  102.  
  103.                     LAYOUT_AddChild, gadgets[GID_REMBUTTON] = ButtonObject,
  104.                         GA_ID, GID_REMBUTTON,
  105.                         GA_RelVerify, TRUE,
  106.                         GA_Text, "_RemoveChild",
  107.                         GA_Disabled, TRUE,
  108.                     ButtonEnd,
  109.  
  110.                     LAYOUT_AddChild, gadgets[GID_REPLACE] = ButtonObject,
  111.                         GA_ID, GID_REPLACE,
  112.                         GA_RelVerify, TRUE,
  113.                         GA_Text, "Replace",
  114.                         GA_Disabled, TRUE,
  115.                     ButtonEnd,
  116.  
  117.                     LAYOUT_AddChild, gadgets[GID_QUIT] = ButtonObject,
  118.                         GA_ID, GID_QUIT,
  119.                         GA_RelVerify, TRUE,
  120.                         GA_Text,"_Quit",
  121.                     ButtonEnd,
  122.                 LayoutEnd,
  123.  
  124.             EndGroup,
  125.         EndWindow;
  126.  
  127.          /*  Object creation sucessful?
  128.           */
  129.         if (objects[OID_MAIN])
  130.         {
  131.             /*  Open the window.
  132.              */
  133.             if (windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]))
  134.             {
  135.                 ULONG wait, signal, app = (1L << AppPort->mp_SigBit);
  136.                 ULONG done = FALSE;
  137.                 ULONG result;
  138.                 UWORD code;
  139.  
  140.                  /* Obtain the window wait signal mask.
  141.                  */
  142.                 GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  143.  
  144.                 /* Input Event Loop
  145.                  */
  146.                 while (!done)
  147.                 {
  148.                     wait = Wait( signal | SIGBREAKF_CTRL_C | app );
  149.  
  150.                     if ( wait & SIGBREAKF_CTRL_C )
  151.                     {
  152.                         done = TRUE;
  153.                     }
  154.                     else
  155.                     {
  156.                         while ( (result = CA_HandleInput(objects[OID_MAIN], &code) ) != WMHI_LASTMSG )
  157.                         {
  158.                             switch (result & WMHI_CLASSMASK)
  159.                             {
  160.                                 case WMHI_CLOSEWINDOW:
  161.                                     windows[WID_MAIN] = NULL;
  162.                                     done = TRUE;
  163.                                     break;
  164.  
  165.                                 case WMHI_GADGETUP:
  166.                                     switch (result & WMHI_GADGETMASK)
  167.                                     {
  168.                                         case GID_ADDBUTTON:
  169.                                             if (gadgets[GID_ADDED] == NULL)
  170.                                             {
  171.                                                 SetGadgetAttrs(gadgets[GID_ADDBUTTON], windows[WID_MAIN], NULL,
  172.                                                     GA_Disabled, TRUE,
  173.                                                     TAG_DONE);
  174.                                                 SetGadgetAttrs(gadgets[GID_REMBUTTON], windows[WID_MAIN], NULL,
  175.                                                     GA_Disabled, FALSE,
  176.                                                     TAG_DONE);
  177.                                                 SetGadgetAttrs(gadgets[GID_REPLACE], windows[WID_MAIN], NULL,
  178.                                                     GA_Disabled, FALSE,
  179.                                                     TAG_DONE);
  180.  
  181.                                                 /* add a new child! */
  182.                                                 SetGadgetAttrs(gadgets[GID_MAIN], windows[WID_MAIN], NULL,
  183.                                                     LAYOUT_Inverted, TRUE,    // Causes AddHead vs. AddTail!
  184.                                                     LAYOUT_AddChild, gadgets[GID_ADDED] = ButtonObject,
  185.                                                         GA_ID, GID_ADDED,
  186.                                                         GA_RelVerify, TRUE,
  187.                                                         GA_Text, "Peekaboo!",
  188.                                                     ButtonEnd,
  189.                                                     TAG_DONE);
  190.  
  191.                                                 /* rethink the window layout */
  192.                                                 if (DoMethod(objects[OID_MAIN], WM_RETHINK) == 0)
  193.                                                     DoMethod(objects[OID_MAIN], WM_NEWPREFS);
  194.                                             }
  195.                                             break;
  196.  
  197.                                         case GID_REMBUTTON:
  198.                                             if (gadgets[GID_ADDED] != NULL)
  199.                                             {
  200.                                                 SetGadgetAttrs(gadgets[GID_ADDBUTTON], windows[WID_MAIN], NULL,
  201.                                                     GA_Disabled, FALSE,
  202.                                                     TAG_DONE);
  203.                                                 SetGadgetAttrs(gadgets[GID_REMBUTTON], windows[WID_MAIN], NULL,
  204.                                                     GA_Disabled, TRUE,
  205.                                                     TAG_DONE);
  206.                                                 SetGadgetAttrs(gadgets[GID_REPLACE], windows[WID_MAIN], NULL,
  207.                                                     GA_Disabled, TRUE,
  208.                                                     TAG_DONE);
  209.  
  210.                                                 /* remove the child! */
  211.                                                 SetGadgetAttrs(gadgets[GID_MAIN], windows[WID_MAIN], NULL,
  212.                                                     LAYOUT_RemoveChild, gadgets[GID_ADDED],
  213.                                                     TAG_DONE);
  214.  
  215.                                                 /* clear the pointer */
  216.                                                 gadgets[GID_ADDED] = NULL;
  217.  
  218.                                                 /* rethink the window layout */
  219.                                                 if (DoMethod(objects[OID_MAIN], WM_RETHINK) == 0)
  220.                                                     DoMethod(objects[OID_MAIN], WM_NEWPREFS);
  221.                                             }
  222.                                             break;
  223.  
  224.                                         case GID_REPLACE:
  225.                                             if (gadgets[GID_ADDED] != NULL)
  226.                                             {
  227.                                                 struct Gadget *temp = NULL;
  228.  
  229.                                                 SetGadgetAttrs(gadgets[GID_REPLACE], windows[WID_MAIN], NULL,
  230.                                                     GA_Disabled, TRUE,
  231.                                                     TAG_DONE);
  232.  
  233.                                                 /* replace the child! */
  234.                                                 SetGadgetAttrs(gadgets[GID_MAIN], windows[WID_MAIN], NULL,
  235.                                                     LAYOUT_ModifyChild, gadgets[GID_ADDED],
  236.                                                         CHILD_ReplaceObject, temp = CheckBoxObject,
  237.                                                             GA_ID, GID_ADDED,
  238.                                                             GA_RelVerify, TRUE,
  239.                                                             GA_Text, "Peekaboo!",
  240.                                                             CHECKBOX_TextPlace, PLACETEXT_RIGHT,
  241.                                                         CheckBoxEnd,
  242.                                                     TAG_DONE);
  243.  
  244.                                                 gadgets[GID_ADDED] = temp;
  245.  
  246.                                                 /* rethink the window layout */
  247.                                                 if (DoMethod(objects[OID_MAIN], WM_RETHINK) == 0)
  248.                                                     DoMethod(objects[OID_MAIN], WM_NEWPREFS);
  249.                                             }
  250.                                             break;
  251.  
  252.                                         case GID_ADDED:
  253.                                             break;
  254.  
  255.                                         case GID_QUIT:
  256.                                             done = TRUE;
  257.                                             break;
  258.                                     }
  259.                                     break;
  260.  
  261.                                 case WMHI_ICONIFY:
  262.                                     CA_Iconify(objects[OID_MAIN]);
  263.                                     windows[WID_MAIN] = NULL;
  264.                                     break;
  265.  
  266.                                 case WMHI_UNICONIFY:
  267.                                     windows[WID_MAIN] = (struct Window *) CA_OpenWindow(objects[OID_MAIN]);
  268.  
  269.                                     if (windows[WID_MAIN])
  270.                                     {
  271.                                         GetAttr(WINDOW_SigMask, objects[OID_MAIN], &signal);
  272.                                     }
  273.                                     else
  274.                                     {
  275.                                         done = TRUE;    // error re-opening window!
  276.                                     }
  277.                                      break;
  278.                             }
  279.                         }
  280.                     }
  281.                 }
  282.             }
  283.  
  284.             /* Disposing of the window object will also close the window if it is
  285.              * already opened, and it will dispose of the layout object attached to it.
  286.              */
  287.             DisposeObject(objects[OID_MAIN]);
  288.         }
  289.  
  290.         DeleteMsgPort(AppPort);
  291.     }
  292.  
  293.     return(0);
  294. }
  295.