home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / NDK / NDK_3.5 / Examples / Reaction / Connect / Connect.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-02  |  5.2 KB  |  226 lines

  1.  
  2.  
  3. /* 
  4. *
  5. * COPYRIGHT:
  6. *
  7. *   Unless otherwise noted, all files are Copyright (c) 1999 Amiga, Inc.
  8. *   All rights reserved.
  9. *
  10. * DISCLAIMER:
  11. *
  12. *   This software is provided "as is". No representations or warranties
  13. *   are made with respect to the accuracy, reliability, performance,
  14. *   currentness, or operation of this software, and all use is at your
  15. *   own risk. Neither Amiga nor the authors assume any responsibility
  16. *   or liability whatsoever with respect to your use of this software.
  17. *
  18.  
  19.     Reaction Inter-Connection Notification Example
  20.  */
  21.  
  22. #include <exec/types.h>
  23. #include <libraries/gadtools.h>
  24. #include <intuition/icclass.h>
  25. #include <intuition/classes.h>
  26. #include <dos/dos.h>
  27.  
  28. #include <clib/macros.h>
  29. #include <clib/alib_protos.h>
  30.  
  31. #include <proto/exec.h>
  32. #include <proto/intuition.h>
  33. #include <proto/layout.h>
  34. #include <proto/palette.h>
  35. #include <proto/label.h>
  36. #include <proto/window.h>
  37.  
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40. #include <string.h>
  41.  
  42. #include <classes/window.h>
  43. #include <gadgets/layout.h>
  44. #include <gadgets/button.h>
  45. #include <gadgets/palette.h>
  46. #include <images/label.h>
  47.  
  48. #include <reaction/reaction.h>
  49. #include <reaction/reaction_macros.h>
  50.  
  51. #define ID_BUTTON       1
  52. #define ID_FOREGROUND      2
  53. #define ID_BACKGROUND    3
  54.  
  55. struct Library *WindowBase = NULL;
  56. struct Library *LayoutBase = NULL;
  57. struct Library *LabelBase = NULL;
  58. struct Library *ButtonBase = NULL;
  59. struct Library *PaletteBase = NULL;
  60.  
  61. void openlibs(void) 
  62. {
  63.     /* Open the classes - typically not required to be done manually.
  64.      * SAS/C or DICE AutoInit can do this for you if linked with the
  65.      * supplied classact.lib
  66.      */
  67.     WindowBase = OpenLibrary("window.class",44);
  68.     LayoutBase = OpenLibrary("gadgets/layout.gadget",44);
  69.     ButtonBase = OpenLibrary("gadgets/button.gadget",44);
  70.     PaletteBase = OpenLibrary("gadgets/palette.gadget",44);
  71.     LabelBase = OpenLibrary("images/label.image",44);
  72. }
  73.  
  74. void closelibs(void) 
  75. {
  76.     /* Close the classes.
  77.      */
  78.     CloseLibrary( LabelBase );
  79.     CloseLibrary( PaletteBase );
  80.     CloseLibrary( ButtonBase );
  81.     CloseLibrary( LayoutBase );
  82.     CloseLibrary( WindowBase );
  83. }
  84.  
  85. int main( int argc, char *argv[] )
  86. {
  87.     struct Window *window;
  88.     Object *But_Object, *Pal_Object1, *Pal_Object2;
  89.     Object *Win_Object;
  90.  
  91.     /* Palette Color To Button ForeGround mapping.
  92.      */
  93.     struct TagItem MapFG2Button[] =
  94.     {
  95.         PALETTE_Color, BUTTON_TextPen,
  96.         TAG_END
  97.     };
  98.  
  99.     /* Palette Color To Button BackGround mapping.
  100.      */
  101.     struct TagItem MapBG2Button[] =
  102.     {
  103.         PALETTE_Color, BUTTON_BackgroundPen,
  104.         TAG_END
  105.     };
  106.  
  107.     openlibs();
  108.     if(WindowBase && LayoutBase && ButtonBase && PaletteBase && LabelBase)
  109.     {
  110.         /* Create the window object.
  111.          */
  112.         Win_Object = (Object *)WindowObject,
  113.             WA_ScreenTitle, "ReAction, Amiga Development LLC.",
  114.             WA_Title, "ReAction Example",
  115.             WA_SizeGadget, TRUE,
  116.             WA_Left, 40,
  117.             WA_Top, 30,
  118.             WA_DepthGadget, TRUE,
  119.             WA_DragBar, TRUE,
  120.             WA_CloseGadget, TRUE,
  121.             WA_Activate, TRUE,
  122.             WA_SmartRefresh, TRUE,
  123.             WINDOW_ParentGroup, VLayoutObject,
  124.                 LAYOUT_SpaceOuter, TRUE,
  125.                 LAYOUT_DeferLayout, TRUE,
  126.                 LAYOUT_BevelStyle, GroupFrame,
  127.                 LAYOUT_Label, "InterConnection",
  128.                 StartMember, But_Object = ButtonObject,
  129.                     GA_Text, "_Inter-Connection Example",
  130.                     GA_ID, ID_BUTTON,
  131.                 EndMember,
  132.                 CHILD_WeightedHeight, 0,
  133.  
  134.                 StartMember, HLayoutObject,
  135.                     LAYOUT_SpaceOuter, FALSE,
  136.                     StartMember, Pal_Object1 = PaletteObject,
  137.                         GA_ID, ID_FOREGROUND,
  138.                         PALETTE_NumColors, 8,
  139.                         PALETTE_Color, 1,
  140.                         ICA_MAP, MapFG2Button, /* tag mapping array */
  141.                     EndMember,
  142.                     CHILD_Label, LabelObject, LABEL_Text, "_ForeGround", LabelEnd,
  143.                     CHILD_MinWidth, 90,
  144.                     CHILD_MinHeight, 20,
  145.     
  146.                     StartMember, Pal_Object2 = PaletteObject,
  147.                         GA_ID, ID_BACKGROUND,
  148.                         PALETTE_NumColors, 8,
  149.                         PALETTE_Color, 0,
  150.                         ICA_MAP, MapBG2Button, /* tag mapping array */
  151.                     EndMember,
  152.                     CHILD_Label, LabelObject, LABEL_Text, "_BackGround", LabelEnd,
  153.                     CHILD_MinWidth, 90,
  154.                     CHILD_MinHeight, 20,
  155.                 EndMember,
  156.             EndMember,
  157.         EndWindow;
  158.  
  159.         /*  Object creation sucessful?
  160.          */
  161.         if( Win_Object )
  162.         {
  163.             SetAttrs(Pal_Object1,
  164.                 ICA_TARGET, But_Object, /* object to connect to */
  165.                 TAG_END);
  166.             SetAttrs(Pal_Object2,
  167.                 ICA_TARGET, But_Object, /* object to connect to */
  168.                 TAG_END);
  169.             /*  Open the window.
  170.              */
  171.             if( window = (struct Window *) RA_OpenWindow(Win_Object) )
  172.             {
  173.                 ULONG wait, signal, result, done = FALSE;
  174.                 WORD Code;
  175.                 
  176.                 /* Obtain the window wait signal mask.
  177.                  */
  178.                 GetAttr( WINDOW_SigMask, Win_Object, &signal );
  179.  
  180.                 /* Input Event Loop
  181.                  */
  182.                 while( !done )
  183.                 {
  184.                     wait = Wait(signal|SIGBREAKF_CTRL_C);
  185.                     
  186.                     if (wait & SIGBREAKF_CTRL_C) done = TRUE;
  187.                     else
  188.  
  189.                     while ((result = RA_HandleInput(Win_Object,&Code)) != WMHI_LASTMSG)
  190.                     {
  191.                         switch (result & WMHI_CLASSMASK)
  192.                         {
  193.                             case WMHI_CLOSEWINDOW:
  194.                                 done = TRUE;
  195.                                 break;
  196.  
  197.                             case WMHI_GADGETUP:
  198.                                 switch(result & WMHI_GADGETMASK)
  199.                                 {
  200.                                     case ID_BUTTON:
  201.                                         break;
  202.                                 }
  203.                                 break;
  204.                         }
  205.                     }
  206.                 }
  207.             }
  208.  
  209.             /* Disposing of the window object will
  210.              * also close the window if it is
  211.              * already opened and it will dispose of
  212.              * all objects attached to it.
  213.              */
  214.             DisposeObject( Win_Object );
  215.         }
  216.     }
  217.     closelibs();
  218. }
  219.  
  220. #ifdef __STORM__
  221. int wbmain( struct WBStartup *wbs )
  222. {
  223.         return( main( 0, NULL ));
  224. }
  225. #endif
  226.