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

  1. #include <libraries/bgui.h>
  2. #include <libraries/bgui_macros.h>
  3. #include <workbench/workbench.h>
  4. #include <workbench/startup.h>
  5. #include <clib/alib_protos.h>
  6.  
  7. #include <proto/exec.h>
  8. #include <proto/bgui.h>
  9. #include <proto/intuition.h>
  10. #include <proto/dos.h>
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14.  
  15. #include <Boopsi/AppIconClass.h>
  16.  
  17.  
  18. struct Library *BGUIBase;
  19.  
  20. /*
  21. **  Class base
  22. **/
  23. Class       *AppIconClass;
  24.  
  25.  
  26. int main( int argc, char *argv[] )
  27. {
  28. struct Window   *window;
  29. Object          *WO_Window;
  30. ULONG           Sig, WindowMask=0, AppIconMask;
  31. BOOL            running=TRUE;
  32. int             rc, i;
  33. struct          AppMessage  *Mess;
  34. struct          WBArg       *wa;
  35.  
  36. Object          *AO_Icon, *AO_Icon2;
  37. char            *ProgName;
  38.  
  39. #ifndef _DCC
  40.     if( !argc )
  41.         ProgName=((struct WBStartup *)argv) -> sm_ArgList -> wa_Name;
  42.     else
  43. #endif
  44.         ProgName = argv[0];
  45.  
  46.     /*
  47.     **  Open the bgui.library
  48.     **/
  49.     if( !( BGUIBase = OpenLibrary( "bgui.library", 39L )) )
  50.     {
  51.         printf("Can't open bgui.library v39\n");
  52.         return(30);
  53.     }
  54.  
  55.     /*
  56.     **  Init. the AppIconClass
  57.     **/
  58.     if( !(AppIconClass=InitAppIconClass() ))
  59.     {
  60.         printf("Impossible d'initialiser la class\n");
  61.         return(1);
  62.     }
  63.  
  64.     /*
  65.     **  Creare object.
  66.     **/
  67.     AO_Icon=NewObject( AppIconClass, NULL, GA_ID, 22, /*AIC_AppName, "TOTO",*/ AIC_IconFileName, ProgName, AIC_AppIconX, 250, AIC_AppIconY, 100,TAG_END );
  68.  
  69.     AO_Icon2=NewObject( AppIconClass, NULL, GA_ID, 23, AIC_AppName, "TOTO 2", AIC_IconFileName, ProgName, AIC_AppMenuItem, TRUE, TAG_END );
  70.  
  71.     if( !AO_Icon )   printf("NewObject 1 failed!\n");
  72.     if( !AO_Icon2 )  printf("NewObject 2 failed!\n");
  73.  
  74.     /*
  75.     **  Create window.
  76.     **/
  77.     WO_Window=WindowObject,
  78.             WINDOW_Title,   "AppIcon test",
  79.             WINDOW_RMBTrap, TRUE,
  80.             WINDOW_AutoAspect,  TRUE,
  81.             WINDOW_MasterGroup,
  82.             VGroupObject,
  83.                 StartMember, Button("End of test", 0), EndMember,
  84.             EndObject,
  85.             EndObject;
  86.     if(!WO_Window)  return(20);
  87.  
  88.  
  89.     window=WindowOpen( WO_Window );
  90.  
  91.  
  92.     GetAttr( WINDOW_SigMask, WO_Window, &WindowMask );
  93.     GetAttr( AIC_AppIconMask, AO_Icon, &AppIconMask );
  94.  
  95.     /*
  96.     **
  97.     **/
  98.     do{
  99.         Sig=Wait( WindowMask | AppIconMask );
  100.  
  101.         if(Sig&AppIconMask )
  102.         {
  103.             while( (Mess=(struct AppMessage *)DoMethod( AO_Icon, GM_HANDLEINPUT )) )
  104.             {
  105.                 if( !Mess->am_NumArgs )
  106.                     printf(" ** Double Click !\n");
  107.                 else
  108.                 {
  109.                     for(i=0, wa=Mess->am_ArgList; i<Mess->am_NumArgs; i++, wa++ )
  110.                         printf(" ** Receive: '%s'\n", wa->wa_Name );
  111.                 }
  112.  
  113.                 ReplyMsg( (struct Message *)Mess );
  114.             }
  115.         }
  116.  
  117.         /*
  118.         ** Signal en provenance de la fenêtre ?
  119.         **/
  120.         if(Sig&WindowMask)
  121.             while( (rc=HandleEvent( WO_Window ) )!= WMHI_NOMORE )
  122.             {
  123.                 switch (rc ) {
  124.                     case 0:
  125.                     case WMHI_CLOSEWINDOW:  running=FALSE;
  126.                                             break;
  127.                 }
  128.             }
  129.  
  130.     }while( running );
  131.  
  132.     /*
  133.     **  Dispose object
  134.     **/
  135.     if( AO_Icon )DisposeObject( AO_Icon );
  136.     if( AO_Icon2 ) DisposeObject( AO_Icon2 );
  137.  
  138.     if( WO_Window ) DisposeObject( WO_Window );
  139.  
  140.  
  141.     /*
  142.     **  Dispose class.
  143.     **/
  144.     FreeAppIconClass(AppIconClass);
  145.  
  146.     /*
  147.     **  Close bgui.library
  148.     **/
  149.     CloseLibrary( BGUIBase );
  150.  
  151.     return( 0 );
  152. }
  153.  
  154. #ifdef _DCC
  155. int wbmain( struct WBStartup *w )
  156. {
  157.     return(main(1, &(w->sm_ArgList->wa_Name) ));
  158. }
  159. #endif
  160.