home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / boopsi / appiconclass / addicons.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  5KB  |  153 lines

  1. /*
  2. **
  3. **  $VER: AppIconClass Demo 1.0 (28.6.95) Doguet Emmanuel
  4. **
  5. **/
  6.  
  7. #include <libraries/bgui.h>
  8. #include <libraries/bgui_macros.h>
  9. #include <libraries/gadtools.h>
  10. #include <clib/alib_protos.h>
  11. #include <clib/exec_protos.h>
  12. #include <clib/bgui_protos.h>
  13. #include <clib/intuition_protos.h>
  14. #include <clib/icon_protos.h>
  15. #include <clib/wb_protos.h>
  16. #include <workbench/startup.h>
  17.  
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20.  
  21. #include <Boopsi/AppIconClass.h>
  22.  
  23. #ifdef _DCC
  24. #include <lib/misc.h>
  25. #endif
  26.  
  27. #define ID_ADD      0
  28. #define ID_REM      1
  29. #define ID_QUIT     2
  30.  
  31. /*
  32. **      Library base pointer.
  33. **      NOTE: The intuition.library is opened by DICE
  34. **      it's auto-init code.
  35. **/
  36. struct Library          *BGUIBase;
  37.  
  38. int main( int argc, char *argv[] )
  39. {
  40. struct Window           *window;
  41. Object                  *WO_Window, *GO_Add, *GO_Quit, *GO_Rem, *addobj[20];
  42. ULONG                    signal = 0, rc, tmp = 0;
  43. BOOL                     running = TRUE, ok = FALSE;
  44. int                      x = 0, xx;
  45.  
  46. Class                    *MasterClass;
  47.  
  48.     if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION ))
  49.     {
  50.  
  51.         // Window definition
  52.         WO_Window = WindowObject,
  53.         WINDOW_Title,             "AppIcon demo",
  54.         WINDOW_RMBTrap,           TRUE,
  55.         WINDOW_SizeGadget,      TRUE,
  56.         WINDOW_MasterGroup,
  57.             HGroupObject,
  58.                 StartMember, GO_Add  = XenKeyButton( "_Add", ID_ADD ), EndMember,
  59.                 StartMember, GO_Rem  = XenKeyButton( "_Remove all", ID_REM ), EndMember,
  60.                 StartMember, GO_Quit = XenKeyButton( "_Quit",  ID_QUIT  ), EndMember,
  61.             EndObject,
  62.         EndObject;
  63.  
  64.         // Initialise the class
  65.         if( MasterClass=InitAppIconClass() )
  66.         {
  67.             if ( WO_Window )
  68.             {
  69.                 tmp += GadgetKey( WO_Window, GO_Add, "a" );
  70.                 tmp += GadgetKey( WO_Window, GO_Quit,  "q" );
  71.                 tmp += GadgetKey( WO_Window, GO_Rem,  "r" );
  72.  
  73.                 if ( tmp == 3 )
  74.                 {
  75.                     if ( window = WindowOpen( WO_Window ))
  76.                     {
  77.                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  78.                         do
  79.                         {
  80.                             Wait( signal );
  81.                             while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE )
  82.                             {
  83.                                 switch ( rc )
  84.                                 {
  85.                                     case  WMHI_CLOSEWINDOW:
  86.                                     case  ID_QUIT:      if (x>0)
  87.                                                         {
  88.                                                             for (xx=0;xx<x;xx++)
  89.                                                                 DisposeObject( addobj[xx] );
  90.                                                             x=0;
  91.                                                         }
  92.                                                         running = FALSE;
  93.                                                         break;
  94.  
  95.                                     case  ID_ADD:       if(x<20)
  96.                                                         {
  97.                                                             addobj[x]  =
  98.                                                             NewObject( MasterClass, NULL, GA_ID, x, AIC_AppName, "Added", AIC_IconFileName, argv[0], TAG_END );
  99.                                                             if( addobj[x] )
  100.                                                                 x++;
  101.                                                             else
  102.                                                                 printf("Erreur NeWOvjec\n");
  103.                                                         }
  104.                                                        break;
  105.  
  106.                                     case  ID_REM:       if (x>0)
  107.                                                         {
  108.                                                             for (xx=0;xx<x;xx++)
  109.                                                                 DisposeObject( addobj[xx] );
  110.                                                             x=0;
  111.                                                         }
  112.                                                         else
  113.                                                             printf("There's not AppIcon!\n");
  114.                                                         break;
  115.                                 }
  116.                             }
  117.                         }
  118.                         while ( running );
  119.                     }
  120.                     else
  121.                         puts ( "Could not open the window" );
  122.                 }
  123.                 else
  124.                     puts( "Could not assign gadget keys" );
  125.  
  126.                 DisposeObject( WO_Window );
  127.  
  128.                 FreeAppIconClass( MasterClass );
  129.             }
  130.             else
  131.                 puts( "Could not create the window object" );
  132.  
  133.         }
  134.         else    puts("Could not init. the AppIcon Class");
  135.  
  136.         CloseLibrary( BGUIBase );
  137.     }
  138.     else
  139.         puts( "Unable to open the bgui.library" );
  140.  
  141.    return( 0 );
  142. }
  143.  
  144.  
  145. #ifdef _DCC
  146. int wbmain( struct WBStartup *wbs )
  147. {
  148.     OpenConsole("CON:0/400//50/AddIcons Output");
  149.     return( main( 1, &(wbs->sm_ArgList->wa_Name) ));
  150. }
  151. #endif
  152.  
  153.