home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / bbs / ff824.lha / FF824 / GadgetTest / GadgetTest.c < prev    next >
C/C++ Source or Header  |  2001-02-25  |  23KB  |  690 lines

  1. /*
  2.  *  Source generated with GadToolsBox V1.4
  3.  *  which is (c) Copyright 1991,92 Jaba Development
  4.  */
  5.  
  6. /* This is an example source which show you the initialization and handling of
  7.    almost every kind of the new gadget types under OS 2.xx.
  8.  
  9.    Thanks to Jaba development for the GadToolsBox V 1.4 which is the GUI first
  10.    program if designing a new interface.
  11.  
  12.    All gadgets and menuhandling will be performed by using the gadtools.library.
  13.  
  14.    No lowlevel function calls to intuition.library will be needed.
  15.  
  16.    This code is freely distributable and released as public domain.
  17.  
  18.    You use this at yourown risk. No guaranty is made for the function and anything
  19.    else.
  20.  
  21.    But I think, it should properly run. I took care about all enforcer hits and
  22.    had the commodores reference manual on my desk while I wrote this.
  23.  
  24. */
  25.  
  26. // INCLUDES
  27.     #include <exec/types.h>
  28.     #include <intuition/intuition.h>
  29.     #include <intuition/classes.h>
  30.     #include <intuition/classusr.h>
  31.     #include <intuition/imageclass.h>
  32.     #include <intuition/gadgetclass.h>
  33.     #include <libraries/gadtools.h>
  34.     #include <graphics/displayinfo.h>
  35.     #include <graphics/gfxbase.h>
  36.     #include <clib/exec_protos.h>
  37.     #include <clib/intuition_protos.h>
  38.     #include <clib/gadtools_protos.h>
  39.     #include <clib/graphics_protos.h>
  40.     #include <clib/utility_protos.h>
  41.     #include <string.h>
  42.  
  43. // DEFINITIONS
  44.  
  45.     #define VERSION "$VER: GadgetTest 0.01 just a simple example"
  46.  
  47.     #define GD_Button_Gadget                       0
  48.     #define GD_CheckBox_Gadget                     1
  49.     #define GD_Integer_Gadget                      2
  50.     #define GD_ListView_Gadget                     3
  51.     #define GD_MX_Gadget                           4
  52.     #define GD_Cycle_Gadget                        5
  53.     #define GD_Palette_Gadget                      6
  54.     #define GD_Scroller_Gadget                     7
  55.     #define GD_Slider_Gadget                       8
  56.     #define GD_String_Gadget                       9
  57.     #define GD_Text_Gadget                         10
  58.  
  59.     #define Test__CNT                              11
  60.  
  61.     #define IB IntuitionBase
  62.     #define GTB GadToolsBase
  63.     #define GFX GfxBase
  64.     // These defines saves a lot of typing time
  65.  
  66. // PROTOTYPES
  67.  
  68.     static UWORD ComputeX(UWORD value);
  69.  
  70.         // this function computes the width of gadgets and offsets dependent to the
  71.         // currently used wbench font.
  72.  
  73.     static UWORD ComputeY(UWORD value);
  74.  
  75.         // this function computes the height of gadgets and offsets dependent to the
  76.         // currently used wbench font.
  77.  
  78.     static VOID  ComputeFont(UWORD width,UWORD height);
  79.  
  80.         // this function initializes some needed variables and structures for the
  81.         // font independentness
  82.  
  83.     LONG SetupScreen(VOID);
  84.  
  85.         // This function locks the wbench screen and initializes a visualinfo
  86.         // structure which is needed by creating gadgets, bevelboxes and menus
  87.  
  88.     VOID CloseDownScreen(VOID);
  89.  
  90.         // This function frees all allocated resources, closes all opened
  91.         // libraries.
  92.  
  93.     VOID Test_Render(VOID);
  94.  
  95.         // This function draws the bevelbox and call the refreshing routins for
  96.         // the window. This function will be called each time we got a refresh
  97.         // window idcmp message.
  98.  
  99.     LONG OpenTest_Window(VOID);
  100.  
  101.         // This function creates all gadgets and menus and opens the window.
  102.         // This functions must be called after the SetupScreen() function.
  103.  
  104.     VOID CloseTest_Window(VOID);
  105.  
  106.         // This function closes our window and frees all gadget and menu
  107.         // structures that had been allocated from the gadtools.library
  108.  
  109.     VOID main(int argc,char **argv);
  110.  
  111.         // The main function starts all actions. The program starts and
  112.         // exits from this function.
  113.  
  114.     VOID HandleIDCMP(VOID);
  115.  
  116.         // This function receives the idcmp messages for our window and
  117.         // does all other actions.
  118.  
  119.  
  120. // STRUCTS & VARS
  121.     struct IB              *IB                  = NULL;
  122.     struct GTB             *GTB                 = NULL;
  123.     struct GFX             *GFX                 = NULL;
  124.     struct Screen          *Scr                 = NULL;
  125.     APTR                    VisualInfo          = NULL;
  126.     struct Window          *Test_Wnd            = NULL;
  127.     struct Gadget          *Test_GList          = NULL;
  128.     struct Menu            *Test_Menus          = NULL;
  129.     struct Gadget          *Test_Gadgets[11];
  130.     struct TextAttr        *Font, Attr;
  131.     struct List             LV_List;
  132.     struct Remember        *RememberKey         = NULL;
  133.  
  134.     UWORD                   Test_Left           = 135;
  135.     UWORD                   Test_Top            = 11;
  136.     UWORD                   Test_Width          = 569;
  137.     UWORD                   Test_Height         = 159;
  138.  
  139.     UBYTE                  *Test_Wdt = (UBYTE *)"Work Window";
  140.  
  141.     UWORD                   FontX, FontY;
  142.     UWORD                   OffX, OffY;
  143.  
  144.  
  145.     UBYTE         *MX_Gadget0Labels[] =
  146.     {  // These are the labels for the MX gadget
  147.         (UBYTE *)"MX....: 1",
  148.         (UBYTE *)"2",
  149.         (UBYTE *)"3",
  150.         NULL
  151.     };
  152.  
  153.     UBYTE         *Cycle_Gadget0Labels[] =
  154.     {  // These are the labels for the Cycle gadget
  155.         (UBYTE *)"FIRST",
  156.         (UBYTE *)"SECOND",
  157.         (UBYTE *)"THIRD",
  158.         NULL
  159.     };
  160.  
  161.     UBYTE         *ListView_Gadget0Labels[]=
  162.     {  // these are the the node names for the Listview gadget
  163.         "First Node"  ,
  164.         "Second Node" ,
  165.         "Third Node"
  166.     };
  167.  
  168.     struct NewMenu Test_NewMenu[] =
  169.     {  // this is the menuitem
  170.         NM_TITLE, (STRPTR)"Project", NULL, 0, 0L, NULL,
  171.         NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, NULL,
  172.         NM_END, NULL, NULL, 0, 0L, NULL
  173.     };
  174.  
  175.     UWORD Test_GTypes[] =
  176.     { // gadget types
  177.         BUTTON_KIND,
  178.         CHECKBOX_KIND,
  179.         INTEGER_KIND,
  180.         LISTVIEW_KIND,
  181.         MX_KIND,
  182.         CYCLE_KIND,
  183.         PALETTE_KIND,
  184.         SCROLLER_KIND,
  185.         SLIDER_KIND,
  186.         STRING_KIND,
  187.         TEXT_KIND
  188.     };
  189.  
  190.     struct NewGadget Test_NGad[] =
  191.     { // structures for allocating gadgets
  192.         91, 73, 202, 13, (UBYTE *)"BUTTON", NULL, GD_Button_Gadget, PLACETEXT_IN ,NULL, NULL,
  193.         91, 108, 26, 11, (UBYTE *)"CHECKBOX:", NULL, GD_CheckBox_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  194.         379, 125, 177, 13, (UBYTE *)"INTEGER.:", NULL, GD_Integer_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  195.         91, 4, 202, 72, (UBYTE *)"LISTVIEW:", NULL, GD_ListView_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  196.         273, 111, 17, 9, NULL, NULL, GD_MX_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  197.         91, 91, 202, 13, (UBYTE *)"CYCLE...:", NULL, GD_Cycle_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  198.         379, 4, 180, 65, (UBYTE *)"PALETTE.:", NULL, GD_Palette_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  199.         379, 73, 178, 13, (UBYTE *)"SCROLLER:", NULL, GD_Scroller_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  200.         379, 91, 177, 13, (UBYTE *)"SLIDER..:", NULL, GD_Slider_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  201.         379, 108, 177, 13, (UBYTE *)"STRING..:", NULL, GD_String_Gadget, PLACETEXT_LEFT ,NULL, NULL,
  202.         93, 141, 459, 13, (UBYTE *)"TEXT....:", NULL, GD_Text_Gadget, PLACETEXT_LEFT ,NULL, NULL
  203.     };
  204.  
  205.     ULONG *Test_GTags[] =
  206.     { // the tags for the gadget creation
  207.         (ULONG *)(TAG_DONE),
  208.  
  209.         (ULONG *)(GTCB_Checked),
  210.         (ULONG *)TRUE,
  211.         (ULONG *)(TAG_DONE),
  212.  
  213.         (ULONG *)(GTIN_Number),
  214.         (ULONG *) 0,
  215.         (ULONG *)(GTIN_MaxChars),
  216.         (ULONG *)6,
  217.         (ULONG *)(TAG_DONE),
  218.  
  219.         (ULONG *)(GTLV_ShowSelected),
  220.         (ULONG *)NULL,
  221.         (ULONG *)(GTLV_ScrollWidth),
  222.         (ULONG *)20,
  223.         (ULONG *)(LAYOUTA_Spacing),
  224.         (ULONG *)2,
  225.         (ULONG *)(TAG_DONE),
  226.  
  227.         (ULONG *)(GTMX_Labels),
  228.         (ULONG *)&MX_Gadget0Labels[ 0 ],
  229.         (ULONG *)(TAG_DONE),
  230.  
  231.         (ULONG *)(GTCY_Labels),
  232.         (ULONG *)&Cycle_Gadget0Labels[ 0 ],
  233.         (ULONG *)(TAG_DONE),
  234.  
  235.         (ULONG *)(GTPA_Depth),
  236.         (ULONG *)2,
  237.         (ULONG *)(GTPA_IndicatorWidth),
  238.         (ULONG *)50,
  239.         (ULONG *)(TAG_DONE),
  240.  
  241.         (ULONG *)(GTSC_Total),
  242.         (ULONG *)10,
  243.         (ULONG *)(GTSC_Arrows),
  244.         (ULONG *)20,
  245.         (ULONG *)(PGA_Freedom),
  246.         (ULONG *)LORIENT_HORIZ,
  247.         (ULONG *)(GA_RelVerify),
  248.         (ULONG *)TRUE,
  249.         (ULONG *)(TAG_DONE),
  250.  
  251.         (ULONG *)(PGA_Freedom),
  252.         (ULONG *)LORIENT_HORIZ,
  253.         (ULONG *)(GA_RelVerify),
  254.         (ULONG *)TRUE,
  255.         (ULONG *)(TAG_DONE),
  256.  
  257.         (ULONG *)(GTST_MaxChars),
  258.         (ULONG *)256,
  259.         (ULONG *)(TAG_DONE),
  260.  
  261.         (ULONG *)(GTTX_Text),
  262.         (ULONG *)"Click a Gadget or use menu Quit to exit...",
  263.         (ULONG *)(GTTX_Border),
  264.         (ULONG *)TRUE,
  265.         (ULONG *)(TAG_DONE)
  266.     };
  267.  
  268. // FUNCTIONS
  269.  
  270.     static UWORD ComputeX( UWORD value )
  271.     { // this function computes the x value dependent to your system font
  272.         return(( UWORD )(( FontX * value ) / 8 ));
  273.     }
  274.  
  275.     static UWORD ComputeY( UWORD value )
  276.     { // this function computes the y value dependent to your system font
  277.         return(( UWORD )(( FontY * value ) / 8 ));
  278.     }
  279.  
  280.     static void ComputeFont( UWORD width, UWORD height )
  281.     { // this function computes the width and height values dependent to your
  282.       // system font and initializes the Font and Attr vars.
  283.  
  284.         Font = &Attr;
  285.         Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  286.         Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  287.         FontX = GfxBase->DefaultFont->tf_XSize;
  288.  
  289.         OffX = Scr->WBorLeft;
  290.         OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  291.  
  292.         if ( width && height )
  293.         {
  294.             if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  295.                 goto UseTopaz;
  296.             if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  297.                 goto UseTopaz;
  298.         }
  299.         return;
  300.  
  301.         UseTopaz:
  302.  
  303.         Font->ta_Name = (STRPTR)"topaz.font";
  304.         FontX = FontY = Font->ta_YSize = 8;
  305.     }
  306.  
  307.     LONG SetupScreen( VOID )
  308.     { // this alloctes a lock for the current default public screen
  309.         if ( ! ( Scr = LockPubScreen( NULL ))) return( 1L );
  310.         ComputeFont( 0, 0 );
  311.         if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE ))) return( 2L );
  312.         return( 0L );
  313.     }
  314.  
  315.     VOID CloseDownScreen( VOID )
  316.     { // this frees all allocated resources
  317.         if ( VisualInfo )
  318.         {
  319.             FreeVisualInfo( VisualInfo );
  320.             VisualInfo = NULL;
  321.         }
  322.  
  323.         if (IB) CloseLibrary((struct Library *)IB);
  324.         if (GTB) CloseLibrary((struct Library *)GTB);
  325.         if (GFX) CloseLibrary((struct Library *)GFX);
  326.     }
  327.  
  328.     void Test_Render( void )
  329.     { // this refreshes the window and the gadgets
  330.         ComputeFont( Test_Width, Test_Height );
  331.  
  332.         DrawBevelBox( Test_Wnd->RPort, OffX + ComputeX( 3 ),
  333.             OffY + ComputeY( 2 ),
  334.             ComputeX( 563 ),
  335.             ComputeY( 155 ),
  336.             GT_VisualInfo, VisualInfo, TAG_DONE );
  337.     }
  338.  
  339.     LONG OpenTest_Window( void )
  340.     { // this creates the gadgets and opens the window
  341.         struct NewGadget     ng;
  342.         struct Gadget       *g;
  343.         struct Node         *nd;
  344.         UWORD                lc, tc;
  345.         UWORD                wleft = Test_Left, wtop = Test_Top, ww, wh;
  346.  
  347.         ComputeFont( Test_Width, Test_Height );
  348.  
  349.         ww = ComputeX( Test_Width );
  350.         wh = ComputeY( Test_Height );
  351.  
  352.         if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  353.         if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  354.  
  355.         NewList(&LV_List); // ask Exec to clear out our list
  356.  
  357.         if (!(nd=(struct Node *)AllocRemember(&RememberKey,sizeof(struct Node),MEMF_CLEAR|MEMF_PUBLIC)))
  358.             return(100);
  359.  
  360.         nd->ln_Name = ListView_Gadget0Labels[0];
  361.         nd->ln_Type = NT_UNKNOWN;
  362.  
  363.         AddTail(&LV_List,nd);
  364.  
  365.         if (!(nd=(struct Node *)AllocRemember(&RememberKey,sizeof(struct Node),MEMF_CLEAR|MEMF_PUBLIC)))
  366.             return(101);
  367.  
  368.         nd->ln_Name = ListView_Gadget0Labels[1];
  369.         nd->ln_Type = NT_UNKNOWN;
  370.  
  371.         AddTail(&LV_List,nd);
  372.  
  373.         if (!(nd=(struct Node *)AllocRemember(&RememberKey,sizeof(struct Node),MEMF_CLEAR|MEMF_PUBLIC)))
  374.             return(102);
  375.  
  376.         nd->ln_Name = ListView_Gadget0Labels[2];
  377.         nd->ln_Type = NT_UNKNOWN;
  378.  
  379.         AddTail(&LV_List,nd);
  380.  
  381.         if ( ! ( g = CreateContext( &Test_GList ))) return( 20L );
  382.  
  383.         for( lc = 0, tc = 0; lc < Test__CNT; lc++ )
  384.         {
  385.  
  386.             CopyMem((char * )&Test_NGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  387.  
  388.             ng.ng_VisualInfo = VisualInfo;
  389.             ng.ng_TextAttr   = Font;
  390.             ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  391.             ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  392.             ng.ng_Width      = ComputeX( ng.ng_Width );
  393.             ng.ng_Height     = ComputeY( ng.ng_Height);
  394.  
  395.             Test_Gadgets[ lc ] = g = CreateGadgetA((ULONG)Test_GTypes[ lc ], g, &ng, ( struct TagItem * )&Test_GTags[ tc ] );
  396.  
  397.             while( Test_GTags[ tc ] ) tc += 2;
  398.             tc++;
  399.  
  400.             if ( NOT g ) return( Test_Gadgets[tc]->GadgetID + 1 );
  401.         }
  402.  
  403.         if ( ! ( Test_Menus = CreateMenus( Test_NewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
  404.             return( 30L );
  405.  
  406.         LayoutMenus( Test_Menus, VisualInfo, TAG_DONE );
  407.  
  408.         if ( ! ( Test_Wnd = OpenWindowTags( NULL,
  409.                         WA_Left,          wleft,
  410.                         WA_Top,           wtop,
  411.                         WA_Width,         ww + OffX + Scr->WBorRight,
  412.                         WA_Height,        wh + OffY + Scr->WBorBottom,
  413.  
  414.                         WA_IDCMP,
  415.                         BUTTONIDCMP|        CHECKBOXIDCMP|    INTEGERIDCMP|
  416.                         LISTVIEWIDCMP|      MXIDCMP|          CYCLEIDCMP|
  417.                         PALETTEIDCMP|       SCROLLERIDCMP|    ARROWIDCMP|
  418.                         SLIDERIDCMP|        STRINGIDCMP|      IDCMP_MENUPICK|
  419.                         IDCMP_CLOSEWINDOW|  IDCMP_REFRESHWINDOW,
  420.  
  421.                         WA_Flags,
  422.                         WFLG_DRAGBAR|       WFLG_DEPTHGADGET|   WFLG_CLOSEGADGET|
  423.                         WFLG_SMART_REFRESH,
  424.  
  425.                         WA_Gadgets,       Test_GList,
  426.                         WA_Title,         Test_Wdt,
  427.                         WA_ScreenTitle,   "GadToolsBox v1.4 © 1991,92 ",
  428.                         WA_PubScreen,     Scr,
  429.                         TAG_DONE )))
  430.             return( 40L );
  431.  
  432.         SetMenuStrip( Test_Wnd, Test_Menus );
  433.  
  434.         GT_SetGadgetAttrs(Test_Gadgets[GD_ListView_Gadget],Test_Wnd,NULL,
  435.             GTLV_Labels,&LV_List,
  436.             TAG_DONE);
  437.  
  438.         GT_RefreshWindow( Test_Wnd, NULL );
  439.         Test_Render();
  440.  
  441.         UnlockPubScreen(NULL,Scr);
  442.         // The window is opened so we doesn`t need the lock anymore
  443.  
  444.         return( 0L );
  445.     }
  446.  
  447.     void CloseTest_Window( void )
  448.     { // this closes the test window and frees some structures
  449.         struct Node *nd;
  450.  
  451.         if ( Test_Menus      )
  452.         {
  453.             ClearMenuStrip( Test_Wnd );
  454.             FreeMenus( Test_Menus );
  455.             Test_Menus = NULL;
  456.         }
  457.  
  458.         if ( Test_Wnd        )
  459.         {
  460.             CloseWindow( Test_Wnd );
  461.             Test_Wnd = NULL;
  462.         }
  463.  
  464.         if ( Test_GList      )
  465.         {
  466.             FreeGadgets( Test_GList );
  467.             Test_GList = NULL;
  468.         }
  469.  
  470.         Forbid();
  471.         while (nd=RemHead(&LV_List));
  472.         Permit();
  473.         FreeRemember(&RememberKey,TRUE);
  474.     }
  475.  
  476.     VOID main(int argc,char **argv)
  477.     {
  478.  
  479.         LONG Error=0L;   // Error indicator
  480.         BPTR wbout=0L;
  481.  
  482.         if (!(IB=(struct IB *)OpenLibrary("intuition.library",37L)))
  483.         { // first checks if we `re running on an OS 2.xx machine
  484.  
  485.             Write(Output(),"Oops you need OS 2.xx to run this program\n",42);
  486.             exit(0);
  487.  
  488.         }
  489.  
  490.         if (argc > 1)
  491.         { // we got any more argument
  492.             PutStr(VERSION);
  493.             PutStr("\nThis is just a simple demo program which should show you\n"
  494.                    "how you can create and handle the OS 2.xx gadgets and takes\n"
  495.                    "other arguments than its name\n");
  496.             CloseDownScreen();
  497.             exit(0);
  498.         }
  499.  
  500.         // now open all other libraries and check the success
  501.  
  502.         if (!(GTB=(struct GTB *)OpenLibrary("gadtools.library",37L)))
  503.         {
  504.             CloseDownScreen();
  505.             exit(20);
  506.         }
  507.  
  508.         if (!(GFX=(struct GFX *)OpenLibrary("graphics.library",37L)))
  509.         {
  510.             CloseDownScreen();
  511.             exit(15);
  512.         }
  513.  
  514.         // initialize out screen lock and visual info
  515.  
  516.         Error = SetupScreen();
  517.  
  518.         switch (Error)
  519.         {
  520.             case 1:
  521.                 //  we got no lock for the wbench screen
  522.                 PutStr("No lock !\n");
  523.                 if (Scr) UnlockPubScreen( NULL, Scr );
  524.                 CloseDownScreen();
  525.                 break;
  526.             case 2:
  527.                 // we got no visual info structure
  528.                 PutStr("No VisualInfo !\n");
  529.                 if (Scr) UnlockPubScreen( NULL, Scr );
  530.                 CloseDownScreen();
  531.                 break;
  532.             default:
  533.                 // no error !
  534.                 break;
  535.         }
  536.  
  537.         Error = OpenTest_Window();
  538.  
  539.         switch (Error)
  540.         {
  541.             case 0:
  542.                 // no error !
  543.                 break;
  544.             case 20:
  545.                 // CreateContext() failed
  546.                 PutStr("Could not create context !\n");
  547.                 CloseTest_Window();
  548.                 if (Scr) UnlockPubScreen( NULL, Scr );
  549.                 CloseDownScreen();
  550.                 exit(5);
  551.                 break;
  552.             case 30:
  553.                 // no menu
  554.                 PutStr("Could not create menu !\n");
  555.                 CloseTest_Window();
  556.                 if (Scr) UnlockPubScreen( NULL, Scr );
  557.                 CloseDownScreen();
  558.                 exit(5);
  559.                 break;
  560.             case 40:
  561.                 // no window
  562.                 PutStr("Could not open window !\n");
  563.                 CloseTest_Window();
  564.                 if (Scr) UnlockPubScreen( NULL, Scr );
  565.                 CloseDownScreen();
  566.                 exit(5);
  567.                 break;
  568.             default:
  569.                 // we got any gadget id
  570.                 Printf("Error: %ld gadget could not be created\n",Error);
  571.                 CloseTest_Window();
  572.                 if (Scr) UnlockPubScreen( NULL, Scr );
  573.                 CloseDownScreen();
  574.                 exit(5);
  575.                 break;
  576.         }
  577.  
  578.         HandleIDCMP();
  579.         CloseTest_Window();
  580.         CloseDownScreen();
  581.         exit(0);
  582.     }
  583.  
  584.     VOID HandleIDCMP(VOID)
  585.     { // this handles all inputs
  586.         struct IntuiMessage *Msg;     // the received Message
  587.         LONG Class,Code,SelGadgetID;  // vars to copy Message`s contents to
  588.         struct Gadget *SelGadget;     // the selected gadget
  589.         BOOL ENDTEST=FALSE;           // end indicator
  590.         BOOL CHECKGADGET=TRUE;        // whether the checkbox is checked or not
  591.  
  592.         // main loop
  593.  
  594.         while (!(ENDTEST))
  595.         {
  596.             WaitPort(Test_Wnd->UserPort);
  597.             while (Msg=GT_GetIMsg(Test_Wnd->UserPort))
  598.             { // as long as we got any message
  599.               // copy all informations and then reply the message
  600.  
  601.                 Class = Msg->Class;
  602.                 Code  = Msg->Code;
  603.                 if ((Class == IDCMP_GADGETUP) || (Class == IDCMP_GADGETDOWN))
  604.                 { // enforcer is watching you !
  605.  
  606.                     if (SelGadget=(struct Gadget *)Msg->IAddress)
  607.                         SelGadgetID =   SelGadget->GadgetID;
  608.                 }
  609.                 GT_ReplyIMsg(Msg);
  610.  
  611.                 // reaction
  612.  
  613.                 switch (Class)
  614.                 {
  615.                     case IDCMP_MENUPICK:
  616.                         ENDTEST=TRUE;
  617.                         break;
  618.                     case IDCMP_GADGETUP:
  619.                     case IDCMP_GADGETDOWN:
  620.                         switch (SelGadgetID)
  621.                         {
  622.                             char *res=NULL;
  623.  
  624.                             case GD_Button_Gadget  :
  625.                                 PutStr("You clicked the button gadget\n");
  626.                                 break;
  627.                             case GD_CheckBox_Gadget:
  628.                                 if (CHECKGADGET) CHECKGADGET=FALSE;
  629.                                 else CHECKGADGET=TRUE;
  630.                                 Printf("You clicked the CheckBox gadget state: %s\n",
  631.                                 CHECKGADGET ? (LONG)"Checked" : (LONG)"NOT CHECKED");
  632.                                 break;
  633.                             case GD_Integer_Gadget :
  634.                                 res=((struct StringInfo *)SelGadget->SpecialInfo)->Buffer;
  635.                                 if (res) Printf("You insert >%s< in the Integer gadget\n",(LONG)res);
  636.                                 break;
  637.                             case GD_ListView_Gadget:
  638.                                 Printf("You clicked the ListView gadget entry: %s\n",(LONG)ListView_Gadget0Labels[Code]);
  639.                                 break;
  640.                             case GD_MX_Gadget      :
  641.                                 Printf("You clicked the MX gadget active: %s\n",(LONG)MX_Gadget0Labels[Code]);
  642.                                 break;
  643.                             case GD_Cycle_Gadget   :
  644.                                 Printf("You clicked the Cycle gadget selected: %s\n",(LONG)Cycle_Gadget0Labels[Code]);
  645.                                 break;
  646.                             case GD_Palette_Gadget :
  647.                                 Printf("You clicked the Palette gadget colour: %ld\n",Code);
  648.                                 break;
  649.                             case GD_Scroller_Gadget:
  650.                                 Printf("You clicked the Scroller gadget level: %ld\n",Code);
  651.                                 break;
  652.                             case GD_Slider_Gadget  :
  653.                                 Printf("You clicked the Slider gadget state: %ld\n",Code);
  654.                                 break;
  655.                             case GD_String_Gadget  :
  656.                                 res=((struct StringInfo *)SelGadget->SpecialInfo)->Buffer;
  657.                                 if (res) Printf("You insert >%s< in the String gadget\n",(LONG)res);
  658.                                 break;
  659.                             default:
  660.                                 // never see this
  661.                                 break;
  662.                         }
  663.                         // a gadget message
  664.                         break;
  665.                     case IDCMP_CLOSEWINDOW:
  666.                         // user ask us to quit
  667.                         ENDTEST=TRUE;
  668.                         break;
  669.                     case IDCMP_REFRESHWINDOW:
  670.                         // our window needs a refresh
  671.                         Test_Render();
  672.                         break;
  673.                     default:
  674.                         // none of them about
  675.                         break;
  676.                 }
  677.             }
  678.         }
  679.  
  680.         Forbid();
  681.  
  682.         // first clear out all messages
  683.         while (Msg=GT_GetIMsg(Test_Wnd->UserPort)) GT_ReplyIMsg(Msg);
  684.  
  685.         // no more messages will be received
  686.         ModifyIDCMP(Test_Wnd,0L);
  687.  
  688.         Permit();
  689.     }
  690.