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

  1. ;/*
  2. sc link reqtools.c lib lib:classact.lib
  3. quit
  4. */
  5.  
  6. /* ClassAct Example, "reqtools" prefs skeleton.
  7.  */
  8. #include <exec/types.h>
  9. #include <exec/memory.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <intuition/icclass.h>
  13. #include <libraries/gadtools.h>
  14.  
  15. #include <graphics/gfxbase.h>
  16. #include <graphics/text.h>
  17. #include <graphics/gfxmacros.h>
  18. #include <utility/tagitem.h>
  19.  
  20. #include <proto/intuition.h>
  21. #include <proto/graphics.h>
  22. #include <proto/exec.h>
  23. #include <proto/dos.h>
  24. #include <proto/diskfont.h>
  25. #include <proto/utility.h>
  26.  
  27. #include <classact.h>
  28. //#include <classact_lib.h>
  29. //#include <clib/classact_lib_protos.h>
  30.  
  31. struct Screen *Scr = NULL;
  32. struct DrawInfo *Dri;
  33. BOOL done = FALSE;
  34.  
  35. /**************************************************************************
  36.  * Chooser label arrays 
  37.  */
  38. static STRPTR chooserlabels1[] = 
  39. {
  40.     "File Requester", 
  41.     "Font Requester", 
  42.     "Palette Requester", 
  43.     "Screen Mode Requester", 
  44.     "Volume Requester", 
  45.     "Other Requesters", 
  46.     NULL     
  47. };
  48.  
  49. static STRPTR chooserlabels2[] = 
  50. {
  51.     "Mouse Pointer",
  52.     "Center in Window", 
  53.     "Center on Screen", 
  54.     "Top Left of Window", 
  55.     "Top Left of Screen", 
  56.     NULL
  57. };
  58.  
  59. /*************************************************************************
  60.  * Gadget list
  61.  */
  62. typedef enum { G_PopScreen = 1, G_UseSysFont, G_ImmSort, G_DrawerFirst,
  63.  G_MixFiles, G_DiskLed, G_DefPage, G_Visible, G_VisMin, G_VisMax,
  64.  G_Pos, G_PosX, G_PosY, G_Save, G_Use, G_Cancel, G_MAX } GadgetIDs;
  65.  
  66. struct Gadget *GList[G_MAX+1];
  67.  
  68. /*************************************************************************
  69.  * Main Program
  70.  */
  71. int main(argc,argv)
  72. int argc;
  73. char *argv[];
  74. {
  75.     struct Window *Win;
  76.  
  77.     Scr = LockPubScreen(NULL);
  78.     
  79.     if (!ButtonBase) /* force it open */
  80.         return (30);
  81.  
  82.     if (Scr == NULL)
  83.     {
  84.         /* Shut down, no screen lock
  85.          */ 
  86.         Printf("Failed locking public screen.\n");
  87.         return(30);
  88.     }
  89.  
  90.     Dri = GetScreenDrawInfo(Scr);
  91.     if (Dri)
  92.     {
  93.         struct List *chooser1 = ChooserLabelsA( chooserlabels1 );
  94.         struct List *chooser2 = ChooserLabelsA( chooserlabels2 );
  95.         
  96.         if (chooser1 && chooser2)
  97.         {
  98.             struct Gadget *MainLayout, *l1, *l2;
  99.             Object *Window;
  100.     
  101.             Window = WindowObject,
  102.                     WA_SizeGadget, TRUE,
  103.                     WA_DepthGadget, TRUE,
  104.                     WA_DragBar, TRUE,
  105.                     WA_CloseGadget, TRUE,
  106.                     WA_Activate, TRUE,
  107.                     WA_PubScreen, Scr,
  108.                     WA_Title, "ClassAct layout.gadget Example (ReqTools preferences mockup)",
  109.                     WA_ScreenTitle, "ClassAct Release 2.0",
  110.                     WINDOW_Position, WPOS_CENTERMOUSE,
  111.                     WINDOW_ParentGroup,    MainLayout = VGroupObject, 
  112.                         LAYOUT_SpaceOuter, TRUE,
  113.                         LAYOUT_DeferLayout, TRUE,        /* this tag instructs layout.gadget to
  114.                                                          * defer GM_LAYOUT and GM_RENDER and ask
  115.                                                          * the application to do them. This
  116.                                                          * lessens the load on input.device */
  117.                         StartHGroup,
  118.                             StartVGroup,
  119.                             
  120.                                 /* This is a basic vertical centered layout group with three gadgets */
  121.                                 StartVGroup, VCentered, LAYOUT_SpaceOuter, TRUE,
  122.                                     LAYOUT_BevelStyle, GroupFrame,
  123.                                     LAYOUT_Label, "General",
  124.                                     
  125.                                     /* SetGadgetCommKeys will set the gadget IDs automatically */
  126.                                     StartMember, GList[G_PopScreen] = CheckBoxObject,
  127.                                         GA_Text, "_Pop screen to front",
  128.                                     End,
  129.                                         
  130.                                     StartMember, GList[G_UseSysFont] = CheckBoxObject,
  131.                                         GA_Text, "Us_e system default font",
  132.                                     End,
  133.                                 End,
  134.                                 CHILD_WeightMinimum, TRUE,    /* by setting WeightMinimum you instruct
  135.                                                              * layout.gadget to weight the object according
  136.                                                              * to its minimum size. This retains group
  137.                                                              * aspects at all sizes. */
  138.                                 
  139.                                 StartVGroup, VCentered, LAYOUT_SpaceOuter, TRUE,
  140.                                     LAYOUT_BevelStyle, GroupFrame,
  141.                                     LAYOUT_Label, "File Requester",
  142.                                     
  143.                                     StartMember, GList[G_ImmSort] = CheckBoxObject,
  144.                                         GA_Text, "_Immediate sort",
  145.                                     End,
  146.                                     
  147.                                     StartMember, GList[G_DrawerFirst] = CheckBoxObject,
  148.                                         GA_Text, "_Display drawers first",
  149.                                     End,
  150.                                     
  151.                                     StartMember, GList[G_MixFiles] = CheckBoxObject,
  152.                                         GA_Text, "Mi_x files and drawers",
  153.                                     End,
  154.                                     
  155.                                     StartMember, GList[G_DiskLed] = CheckBoxObject,
  156.                                          GA_Text, "Dis_k activity LED",
  157.                                     End,
  158.                                 End,
  159.                                 CHILD_WeightMinimum, TRUE,
  160.                             End,
  161.                             CHILD_WeightMinimum, TRUE,
  162.                             
  163.                             StartVGroup, TOffset(INTERSPACING),
  164.                                 StartMember, GList[G_DefPage] = ChooserObject,
  165.                                     CHOOSER_Labels, chooser1,
  166.                                 End,
  167.                                 CHILD_Label, LabelObject, LABEL_Text, "De_faults for", End,
  168.                                 CHILD_WeightedHeight, 0,
  169.                                 
  170.                                 StartMember, l1 = VGroupObject,
  171.                                     LAYOUT_SpaceOuter, TRUE,
  172.                                     LAYOUT_BevelStyle, StandardFrame,
  173.                                     LAYOUT_BevelState, IDS_SELECTED,
  174.                                     
  175.                                     StartHGroup, TOffset(INTERSPACING),
  176.                                         LAYOUT_Label, "Size (% of visible height):",
  177.                                         
  178.                                         StartMember, GList[G_Visible] = ScrollerObject,
  179.                                             SCROLLER_Total, 100,
  180.                                             SCROLLER_Arrows, FALSE,
  181.                                             SCROLLER_Orientation, SORIENT_HORIZ,
  182.                                         End,
  183.                                         CHILD_MinHeight, Scr->Font->ta_YSize + 6,
  184.                                         
  185.                                     End,
  186.                                     CHILD_WeightedHeight, 0,
  187.             
  188.                                     StartMember, l2 = HGroupObject, TOffset(INTERSPACING),
  189.                                         LAYOUT_Label, "Number of visible entries:",
  190.                                     
  191.                                         StartMember, GList[G_VisMin] = IntegerObject, 
  192.                                             GA_TabCycle, TRUE,
  193.                                         End,
  194.                                         CHILD_Label, LabelObject, LABEL_Text, "_Minimum", End,
  195.                                     
  196.                                         StartMember, GList[G_VisMax] = IntegerObject, 
  197.                                             GA_RelVerify, TRUE,
  198.                                             GA_TabCycle, TRUE,
  199.                                         End,
  200.                                         CHILD_Label, LabelObject, LABEL_Text, "Ma_ximum", End,
  201.                                     
  202.                                     End,
  203.                                     CHILD_WeightedHeight, 0,
  204.             
  205.                                     StartMember, GList[G_Pos] = ChooserObject,
  206.                                         GA_TabCycle, TRUE,
  207.                                         CHOOSER_Labels, chooser2,
  208.                                     End,
  209.                                     CHILD_Label, LabelObject, LABEL_Text, "P_osition", End,
  210.                                     CHILD_WeightedHeight, 0,
  211.                                     
  212.                                     StartHGroup,
  213.                                     
  214.                                         StartMember, GList[G_PosX] = IntegerObject, 
  215.                                             GA_TabCycle, TRUE,
  216.                                         End,
  217.                                         
  218.                                         StartMember, GList[G_PosY] = IntegerObject, 
  219.                                             GA_TabCycle, TRUE,
  220.                                         End,
  221.                                         
  222.                                     End,
  223.                                     CHILD_Label, LabelObject, LABEL_Text, "Offse_t", End,
  224.                                     CHILD_WeightedHeight, 0,
  225.                                 End, 
  226.                             End,
  227.                             CHILD_WeightMinimum, TRUE,
  228.                         End,
  229.                         
  230.                         StartHGroup,
  231.                             LAYOUT_EvenSize, TRUE,
  232.                             
  233.                             StartMember, GList[G_Save] = ButtonObject,
  234.                                 GA_Text, "_Save",
  235.                             End,
  236.                             CHILD_NominalSize, TRUE, /* make it a bit larger than necessary */
  237.                             CHILD_WeightedWidth, 0,
  238.                             
  239.                             StartMember, GList[G_Use] = ButtonObject,
  240.                                 GA_Text, "_Use",
  241.                             End,
  242.                             CHILD_NominalSize, TRUE,
  243.                             CHILD_WeightedWidth, 0,
  244.                             
  245.                             StartMember, GList[G_Cancel] = ButtonObject,
  246.                                 GA_Text, "_Cancel",
  247.                             End,
  248.                             CHILD_NominalSize, TRUE,
  249.                             CHILD_WeightedWidth, 0,
  250.                         End,
  251.                         CHILD_WeightedHeight, 0,
  252.                     End,
  253.                 EndWindow;
  254.     
  255.             if (Window)
  256.             {
  257.                 /* set up automatic label justification */
  258.                 SetAttrs( l1, LAYOUT_AlignLabels, l2, TAG_END );
  259.                 SetAttrs( l2, LAYOUT_AlignLabels, l1, TAG_END );
  260.     
  261.                 /* Finish the gadgetarray initialisation. Set gadget IDs and release verify */
  262.                 
  263.                 {
  264.                     LONG i = 1;
  265.                     do SetAttrs(GList[i], GA_ID, i, GA_RelVerify, TRUE, TAG_END);
  266.                     while (GList[++i]);
  267.                 }
  268.                 
  269.                 if (Win = CA_OpenWindow( Window ))
  270.                 {
  271.                     ULONG wsig;
  272.                     
  273.                     GetAttr( WINDOW_SigMask, Window, &wsig );
  274.         
  275.                     while (done == FALSE)
  276.                     {
  277.                         ULONG sig = Wait(wsig | SIGBREAKF_CTRL_C);
  278.                         ULONG result;
  279.                         WORD code;
  280.     
  281.                         if (sig & wsig)
  282.                         {
  283.                             while ((result = CA_HandleInput(Window,&code)) != WMHI_LASTMSG)
  284.                             {
  285.                                 switch(result & WMHI_CLASSMASK)
  286.                                 {
  287.                                 case WMHI_GADGETUP:
  288.                                     switch(result & WMHI_GADGETMASK)
  289.                                     {
  290.                                     case G_Save:
  291.                                     case G_Use:
  292.                                     case G_Cancel:
  293.                                         done = TRUE;
  294.                                         /*FALLTHROUGH*/
  295.                                         
  296.                                     /* Gadgets here */
  297.                                     default:
  298.                                         Printf("Gadget ID %ld hit (code %ld)\n", result & WMHI_GADGETMASK, code);
  299.                                         break;
  300.                                     }
  301.                                     break;
  302.  
  303.                                 case WMHI_CLOSEWINDOW:
  304.                                     done = TRUE;
  305.                                     break;
  306.                                 }
  307.                             }
  308.                         }
  309.                         else if (sig & SIGBREAKF_CTRL_C)
  310.                         {
  311.                             done = TRUE;
  312.                         }
  313.                     }
  314.                     /* Close the window and dispose of all attached gadgets */
  315.                     DisposeObject( Window );
  316.                 }
  317.             }
  318.         }
  319.         
  320.         FreeChooserLabels( chooser1 );
  321.         FreeChooserLabels( chooser2 );
  322.         
  323.         FreeScreenDrawInfo(Win->WScreen, Dri);
  324.     }
  325.     UnlockPubScreen(0, Scr);
  326. }
  327.