home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 377a.lha / libraries / intuition / IO / idcmpdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-04  |  6.0 KB  |  205 lines

  1.  
  2. /* IDCMPDemo.c -- Tests the IDCMP by printing IDCMP classes */
  3. /*                to the console.                           */
  4. /* Compiled with Lattice C v5.02                                     */
  5. /* Compiler invoked with: lc -b1 -cfist -L -v -w                     */
  6.  
  7. /* Copyright (c) 1990 Commodore-Amiga, Inc.
  8.  *
  9.  * This example is provided in electronic form by Commodore-Amiga, Inc. for
  10.  * use with the 1.3 revisions of the Addison-Wesley Amiga reference manuals. 
  11.  * The 1.3 Addison-Wesley Amiga Reference Manual series contains additional
  12.  * information on the correct usage of the techniques and operating system
  13.  * functions presented in this example.  The source and executable code of
  14.  * this example may only be distributed in free electronic form, via bulletin
  15.  * board or as part of a fully non-commercial and freely redistributable
  16.  * diskette.  Both the source and executable code (including comments) must
  17.  * be included, without modification, in any copy.  This example may not be
  18.  * published in printed form or distributed with any commercial product.
  19.  * However, the programming techniques and support routines set forth in
  20.  * this example may be used in the development of original executable
  21.  * software products for Commodore Amiga computers.
  22.  * All other rights reserved.
  23.  * This example is provided "as-is" and is subject to change; no warranties
  24.  * are made.  All use is at your own risk.  No liability or responsibility
  25.  * is assumed.
  26.  */
  27.  
  28. #include <exec/types.h>
  29. #include <intuition/intuition.h>
  30. #include <libraries/dos.h>
  31. #ifdef LATTICE
  32. #include <proto/all.h>
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. int CXBRK(void) {return(0);}
  36. #endif
  37. /* Include other required vendor- or Commodore-Amiga-supplied header */
  38. /*  files here.                                                      */
  39.  
  40. /* Include user-written header files here. */
  41. #include "quartzWindow.h"
  42.  
  43. /* Use lowest non-obselete version that supplies the functions you need. */
  44. #define INTUITION_REV 33
  45.  
  46. extern VOID cleanExit( struct Window *, int );
  47. extern UBYTE handleIDCMP( struct Window * );
  48.  
  49. struct IntuitionBase *IntuitionBase = NULL;
  50.         
  51. VOID main(int argc, char *argv[])
  52. {
  53.     /* Declare variables here */
  54.     ULONG signalmask, signals, moreFlags;
  55.     UBYTE done = 0;
  56.     struct Window *window1 = NULL;
  57.  
  58.  
  59.     /* Open the Intuition Library */
  60.     IntuitionBase = (struct IntuitionBase *)
  61.                     OpenLibrary( "intuition.library",INTUITION_REV );
  62.  
  63.     if (IntuitionBase == NULL)
  64.         cleanExit(window1, RETURN_WARN);
  65.  
  66.  
  67.     /* Open any other required libraries */
  68.  
  69.  
  70.     /* Make the assignments that were postponed above */
  71.     /* We need a couple more flags in the window      */
  72.  
  73.     quartzWindow.Flags |= REPORTMOUSE | RMBTRAP;
  74.     quartzWindow.Type = WBENCHSCREEN;
  75.  
  76.  
  77.     /* Open the window */
  78.     window1 = OpenWindow(&quartzWindow);
  79.     if (window1 == NULL)
  80.         cleanExit(window1, RETURN_WARN);
  81.  
  82.  
  83.     /* QuartzWindow has only the CLOSEWINDOW IDCMP flag set. */
  84.     /* We'll set all of the following flags in quartzWindow  */
  85.     /* by using the ModifyIDCMP() function.                  */
  86.     moreFlags = CLOSEWINDOW | NEWSIZE | DISKINSERTED |
  87.                 DISKREMOVED | MOUSEBUTTONS;
  88.  
  89.     ModifyIDCMP( window1, moreFlags );
  90.  
  91.  
  92.     /* Set up the signals that you want to hear about ... */
  93.     signalmask = 1L << window1->UserPort->mp_SigBit;
  94.  
  95.  
  96.     /* Call the functions that do the main processing */
  97.     /* None to call in this example */
  98.  
  99.  
  100.     /* And wait to hear from your signals */      
  101.     while( !done ) {
  102.  
  103.         signals = Wait(signalmask);    
  104.         if (signals & signalmask)
  105.             done = handleIDCMP(window1);
  106.     };
  107.  
  108.  
  109.     /* Exit the program */
  110.     cleanExit(window1, RETURN_OK);
  111.  
  112.  
  113. }
  114.  
  115. UBYTE handleIDCMP( struct Window *win )
  116. {
  117.     UBYTE flag = 0;
  118.     struct IntuiMessage *message = NULL;
  119.     USHORT code;
  120.     SHORT mousex, mousey;
  121.     ULONG class;
  122.  
  123.     /* Examine pending messages */
  124.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort) ) {
  125.  
  126.         class = message->Class;
  127.         code = message->Code;
  128.         mousex = message->MouseX;
  129.         mousey = message->MouseY;
  130.         
  131.         /* When we're through with a message, reply */
  132.         ReplyMsg( (struct Message *)message);
  133.  
  134.         /* See what events occurred */
  135.         switch( class ) {
  136.         
  137.             case CLOSEWINDOW:            
  138.                 flag = 1;
  139.                 break;
  140.             case NEWSIZE:
  141.                 printf( "NEWSIZE\n" );
  142.                 break;
  143.             case DISKINSERTED:
  144.                 printf( "DISKINSERTED\n" );
  145.                 break;
  146.             case DISKREMOVED:
  147.                 printf( "DISKREMOVED\n" );
  148.                 break;
  149.             case MOUSEBUTTONS:
  150.                 switch( code )
  151.                 {
  152.                     case SELECTUP:
  153.                         printf( "SELECTUP at %d,%d\n",mousex,mousey );
  154.                         break;
  155.                     case SELECTDOWN:
  156.                         printf( "SELECTDOWN at %d,%d\n",mousex,mousey );
  157.                         break;
  158.                     case MENUUP:
  159.                         printf( "MENUUP\n" );
  160.                         break;
  161.                     case MENUDOWN:
  162.                         printf( "MENUDOWN\n" );
  163.                         break;
  164.                     default:
  165.                         printf( "UNKNOWN CODE\n" );
  166.                         break;
  167.                 }; /* end of switch on code */
  168.         break;
  169.             default:
  170.                 printf( "Unknown IDCMP message\n" );
  171.                 break;
  172.                 
  173.         } /* End switch */        
  174.     }   /* End while */
  175.  
  176.     /* Flush any remaining pending messages */
  177.  
  178.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort))
  179.                   ReplyMsg( (struct Message *)message );
  180.  
  181.  
  182.     return(flag);
  183. }
  184.  
  185. VOID cleanExit( wind, returnValue )
  186. struct Window *wind;
  187. int returnValue;
  188. {
  189.     /* Close things in the reverse order of opening */
  190.  
  191.     /* Close the windows */
  192.  
  193.     if (wind) CloseWindow( wind );
  194.  
  195.  
  196.     /* Close the library, and then exit */
  197.  
  198.     if (IntuitionBase) CloseLibrary( (struct Library *)IntuitionBase );
  199.  
  200.  
  201.     exit(returnValue);
  202.  
  203. }
  204.  
  205.