home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 3 / AACD03.BIN / CDTools / ClassAct / Examples / Chooser / hiddenchooser.c < prev    next >
C/C++ Source or Header  |  1997-07-09  |  6KB  |  235 lines

  1. ;/* Hidden Chooser Example
  2. sc link hiddenchooser.c lib lib:classact.lib
  3. quit
  4.  */
  5.  
  6. /** This example demonstrates the "hidden mode" mode of the chooser gadget.
  7.  **
  8.  ** It is a NEW mode added recently to ClassAct release 2.0 - you *must*
  9.  ** have atleast V41.103 or later installed. Officially, this is a V42
  10.  ** ClassAct 2.1 feature, but made available now due to developer demand.
  11.  **
  12.  ** Hidden choosers currently need to be handled differently than visible
  13.  ** gadget objects. Since they are NOT added to the window, or layout group,
  14.  ** they do not trigger a GADGETUP. So, you must use an IDCMPUPDATE hook
  15.  ** and use the CHOOSER_Active notifications to get the selection.
  16.  **/
  17.  
  18. #define USE_BUILTIN_MATH
  19. #define USE_SYSBASE
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <math.h>
  24.  
  25. #define    INTUI_V36_NAMES_ONLY
  26.  
  27. #include <exec/types.h>
  28. #include <exec/memory.h>
  29. #include <dos/dos.h>
  30. #include <dos/dosextens.h>
  31. #include <intuition/intuition.h>
  32. #include <intuition/gadgetclass.h>
  33. #include <intuition/intuitionbase.h>
  34. #include <intuition/classusr.h>
  35. #include <intuition/imageclass.h>
  36. #include <intuition/gadgetclass.h>
  37. #include <intuition/icclass.h>
  38. #include <intuition/cghooks.h>
  39. #include <intuition/classes.h>
  40. #include <graphics/gfxbase.h>
  41. #include <graphics/text.h>
  42. #include <graphics/gfxmacros.h>
  43. #include <utility/tagitem.h>
  44. #include <utility/hooks.h>
  45.  
  46. #include <clib/macros.h>
  47.  
  48. #include <proto/intuition.h>
  49. #include <proto/graphics.h>
  50. #include <proto/dos.h>
  51. #include <proto/exec.h>
  52. #include <proto/utility.h>
  53.  
  54. #include <classact.h>
  55.  
  56. #define ID_BUTTON        1
  57. #define ID_HIDDEN        2
  58.  
  59. extern struct ClassLibrary *ChooserBase;
  60.  
  61.  
  62. /* Labels for the popup.
  63.  */
  64. UBYTE *chooser_strs[] =
  65. {
  66.     "Save Image",
  67.     "Load Image",
  68.     "Follow URL",
  69.     "Save to HotList",
  70.     NULL
  71. };
  72.  
  73. /*************************************************************************
  74.  * IDCMP hook
  75.  */
  76.  
  77. void __asm __saveds IDCMPFunc(    register __a0 struct Hook *Hook,
  78.                                 register __a2 Object *Window,
  79.                                 register __a1 struct IntuiMessage *Msg )
  80. {
  81.     ULONG active;
  82.  
  83.     if (Msg->Class == IDCMP_IDCMPUPDATE)
  84.     {
  85.         /* The notification might include one of the tags we want to look at...
  86.          */
  87.         if      (GetTagData(GA_ID, 0, Msg->IAddress) == ID_HIDDEN)
  88.         {
  89.             active = GetTagData(CHOOSER_Active, -1, Msg->IAddress);
  90.             printf("active: %ld\n", active);
  91.         }
  92.     }
  93. }
  94.  
  95.  
  96. int main( int argc, char *argv[] )
  97. {
  98.     if (ChooserBase->cl_Lib.lib_Version < 41 || (ChooserBase->cl_Lib.lib_Version == 41 && ChooserBase->cl_Lib.lib_Revision < 103))
  99.     {
  100.         PutStr("You require at least version 41.103 of chooser.gadget\nPlease install more recent classes\n");
  101.         exit(10);
  102.     }
  103.     
  104.     if (ButtonBase)
  105.     {
  106.         Object *Chooser_Object_Hidden;
  107.         Object *Window_Object;
  108.         struct Window *window;
  109.         struct List *chooserlist;
  110.         struct Hook idcmphook;
  111.  
  112.         idcmphook.h_Entry = (ULONG (* )())IDCMPFunc;
  113.         idcmphook.h_SubEntry = NULL;
  114.  
  115.         chooserlist = ChooserLabelsA(chooser_strs);
  116.  
  117.         if (chooserlist)
  118.         {
  119.             /*    Create an instance of the chooser class that will remain hidden.
  120.             */
  121.             Chooser_Object_Hidden = ChooserObject,
  122.                 GA_RelVerify, TRUE,
  123.                 GA_ID, ID_HIDDEN,
  124.                 CHOOSER_Labels, chooserlist,
  125.                 CHOOSER_DropDown, TRUE,
  126.                 CHOOSER_AutoFit, TRUE,
  127.                 CHOOSER_Hidden, TRUE,
  128.                 ICA_TARGET, ICTARGET_IDCMP,
  129.             ChooserEnd;
  130.  
  131.             /* Create the window object. */
  132.             Window_Object = WindowObject,
  133.                 WA_ScreenTitle, "ClassAct Release 2.0",
  134.                 WA_Title, "Another ClassAct chooser.gadget Example",
  135.                 WA_SizeGadget, TRUE,
  136.                 WA_Left, 40,
  137.                 WA_Top, 30,
  138.                 WA_DepthGadget, TRUE,
  139.                 WA_DragBar, TRUE,
  140.                 WA_CloseGadget, TRUE,
  141.                 WA_Activate, TRUE,
  142.                 WA_SmartRefresh, TRUE,
  143.                 WA_IDCMP, IDCMP_GADGETUP|IDCMP_GADGETDOWN|IDCMP_IDCMPUPDATE,
  144.                 WINDOW_IDCMPHook, &idcmphook,    /* For BOOPSI notification */
  145.                 WINDOW_IDCMPHookBits, IDCMP_IDCMPUPDATE,
  146.                 WINDOW_ParentGroup, VGroupObject,
  147.                     LAYOUT_SpaceOuter, TRUE,
  148.                     LAYOUT_DeferLayout, TRUE,
  149.  
  150.                     LAYOUT_AddChild, ButtonObject,
  151.                         GA_RelVerify, TRUE,
  152.                         GA_ID, ID_BUTTON,
  153.                         GA_Text, "Press me to show the hidden chooser!",
  154.                     ButtonEnd,
  155.                     CHILD_WeightedHeight, 0,
  156.  
  157.                     LAYOUT_AddChild, VGroupObject,
  158.                         CLASSACT_BackFill, NULL,
  159.                         LAYOUT_SpaceOuter, TRUE,
  160.                         LAYOUT_VertAlignment, LALIGN_CENTER,
  161.                         LAYOUT_HorizAlignment, LALIGN_CENTER,
  162.                         LAYOUT_BevelStyle, BVS_GROUP,
  163.  
  164.                         LAYOUT_AddImage, LabelObject,
  165.                             LABEL_Text, "Selecting the button above will\n",
  166.                             LABEL_Text, "reveal the hidden popup chooser!\n\n",
  167.                             LABEL_Text, "Hidden choosers are useful for\n",
  168.                             LABEL_Text, "context sensitive quick menus.\n",
  169.                         LabelEnd,
  170.  
  171.                     LayoutEnd,
  172.                 LayoutEnd,
  173.             WindowEnd;
  174.  
  175.             /*  Object creation sucessful?
  176.              */
  177.             if( Window_Object )
  178.             {
  179.                 /*  Open the window.
  180.                  */
  181.                 if( window = (struct Window *) CA_OpenWindow(Window_Object) )
  182.                 {
  183.                     ULONG wait, signal, result, done = FALSE;
  184.                     WORD Code;
  185.                     
  186.                     /* Obtain the window wait signal mask.
  187.                      */
  188.                     GetAttr( WINDOW_SigMask, Window_Object, &signal );
  189.  
  190.                     /* Input Event Loop
  191.                      */
  192.                     while( !done )
  193.                     {
  194.                         wait = Wait(signal|SIGBREAKF_CTRL_C);
  195.                         
  196.                         if (wait & SIGBREAKF_CTRL_C) done = TRUE;
  197.                         else
  198.  
  199.                         while ((result = CA_HandleInput(Window_Object,&Code)) != WMHI_LASTMSG)
  200.                         {
  201.                             switch (result & WMHI_CLASSMASK)
  202.                             {
  203.                                 case WMHI_CLOSEWINDOW:
  204.                                     done = TRUE;
  205.                                     break;
  206.  
  207.                                 case WMHI_GADGETUP:
  208.                                     switch(result & WMHI_GADGETMASK)
  209.                                     {
  210.                                         case ID_BUTTON:
  211.                                             ActivateGadget((struct Gadget *)Chooser_Object_Hidden, window, NULL);
  212.                                             break;
  213.  
  214.                                     }
  215.                                     break;
  216.                             }
  217.                         }
  218.                     }
  219.                 }
  220.  
  221.                 /* Disposing of the window object will also close the window if it is
  222.                  * already opened and it will dispose of all objects attached to it.
  223.                  */
  224.                 DisposeObject( Window_Object );
  225.  
  226.                 /* The hidden chooser isn't attached to anything, so we must dispose
  227.                  * it ourselves...
  228.                  */
  229.                 DisposeObject( Chooser_Object_Hidden );
  230.             }
  231.         }
  232.         FreeChooserLabels(chooserlist);
  233.     }
  234. }
  235.