home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Misc / TRSICAT.LZX / CATS_CD2_TRSI / Reference_Library / lib_examples / easyintuition.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-21  |  7.8 KB  |  213 lines

  1. /* Here's the same example as above written for both Release 2 and
  2.  * earlier versions of the operating system.  The main difference
  3.  * here is that this example avoids using any new Release 2
  4.  * functions, but does pass extended structures to the older
  5.  * Intuition functions so that some new Release 2 features may be
  6.  * accessed in a backward-compatible manner.
  7.  */
  8.  
  9. /* easyintuition.c  Simple backward-compatible V37 Intuition example    */
  10. /*                                                                      */
  11. /* This example uses extended structures with the pre-V37 OpenScreen()  */
  12. /* and OpenWindow() functions to compatibly open an Intuition display.  */
  13. /* Enhanced V37 options specified via tags are ignored on 1.3 systems.  */
  14. /* Compiled with Lattice C v5.10: lc -L easyintuition.c                 */
  15.  
  16. /* Force use of new variable names to help prevent errors  */
  17. #define INTUI_V36_NAMES_ONLY
  18.  
  19. #include <exec/types.h>             /* The Amiga data types file.         */
  20. #include <intuition/intuition.h>    /* Intuition data strucutres, etc.    */
  21. #include <libraries/dos.h>          /* Official return codes defined here */
  22.  
  23. #include <clib/exec_protos.h>       /* Exec function prototypes           */
  24. #include <clib/intuition_protos.h>  /* Intuition function prototypes      */
  25.  
  26. #ifdef LATTICE                      /* Disable Ctrl-C handling in SAS/C   */
  27. int CXBRK(void)  {return(0);}
  28. void chkabort(void) {return;}
  29. #endif
  30.  
  31. /* Use lowest non-obsolete version that supplies the functions needed. */
  32. #define INTUITION_REV 33L
  33.  
  34. /* Declare the prototypes of our own functions. Prototypes for system  */
  35. /* functions are declared in the header files in the clib directory    */
  36. VOID cleanExit( struct Screen *, struct Window *, LONG );
  37. BOOL handleIDCMP( struct Window *);
  38.  
  39. struct Library *IntuitionBase = NULL;
  40.  
  41. /* We can specify that we want the V37-compatible 3D look when
  42.  * running under V37 by adding an SA_Pens tag.
  43.  */
  44. WORD pens[] = {~0};    /* empty pen array to get default 3D look */
  45. struct TagItem ourscreentags[] = {
  46.     { SA_Pens, (ULONG)pens },
  47.     { TAG_DONE }};
  48.  
  49. /* ExtNewScreen is an extended NewScreen structure.
  50.  * NS_EXTENDED flags that there is a tag pointer to additional
  51.  * tag information at the end of this structure.  The tags will
  52.  * be parsed by Release 2 but ignored by earlier OS versions.
  53.  */
  54. struct ExtNewScreen fullHires =
  55.     {
  56.     0,                /* LeftEdge must be zero prior to Release 2 */
  57.     0,                /* TopEdge */
  58.     640,              /* Width (high-resolution) */
  59.     STDSCREENHEIGHT,  /* Height (non-interlace)  */
  60.     2,                /* Depth (4 colors will be available) */
  61.     0,1,              /* Default DetailPen and BlockPen  */
  62.     HIRES,            /* the high-resolution display mode */
  63.     CUSTOMSCREEN | NS_EXTENDED,     /* the screen type */
  64.     NULL,             /* no special font */
  65.     "Our Screen",     /* the screen title */
  66.     NULL,             /* no custom screen gadgets (not supported) */
  67.     NULL,             /* no CustomBitMap */
  68.     ourscreentags     /* tags for additional V37 features */
  69.     };
  70.  
  71. /* Position and sizes for our window */
  72. #define WIN_LEFTEDGE   20
  73. #define WIN_TOPEDGE    20
  74. #define WIN_WIDTH     400
  75. #define WIN_MINWIDTH   80
  76. #define WIN_HEIGHT    150
  77. #define WIN_MINHEIGHT  20
  78.  
  79. /* Under V37, we'll get a special screen title when our window is active */
  80. UBYTE activetitle[] = {"Our Screen - EasyWindow is Active"};
  81.  
  82. struct TagItem ourwindowtags[] = {
  83.     { WA_ScreenTitle, (ULONG)&activetitle[0] },
  84.     { TAG_DONE }};
  85.  
  86. /* ExtNewWindow is an extended NewWindow structure.
  87.  * NW_EXTENDED indicates that there is a tag pointer to additional tag
  88.  * information at the end of this structure.  The tags will be parsed
  89.  * by Release 2 but ignored by earlier OS versions.
  90.  */
  91. struct ExtNewWindow easyWindow =
  92.     {
  93.     WIN_LEFTEDGE,
  94.     WIN_TOPEDGE,
  95.     WIN_WIDTH,
  96.     WIN_HEIGHT,
  97.     -1,-1,             /* Means use the screen's Detail and Block pens   */
  98.  
  99.     IDCMP_CLOSEWINDOW, /* This field specifies the events we want to get */
  100.  
  101.     /* These flags specify system gadgets and other window attributes    */
  102.     /* including the EXTENDED flag which flags this as an ExtNewWindow   */
  103.     WFLG_CLOSEGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_DRAGBAR |
  104.     WFLG_DEPTHGADGET | WFLG_SIZEGADGET  | WFLG_NOCAREREFRESH |
  105.     WFLG_NW_EXTENDED,
  106.  
  107.     NULL,             /* Pointer to the first gadget  */
  108.     NULL,             /* No checkmark.                */
  109.     "EasyWindow",     /* Window title.                */
  110.     NULL,             /* Attach a screen later.       */
  111.     NULL,             /* Let Intuition set up BitMap  */
  112.     WIN_MINWIDTH,     /* Minimum width.       */
  113.     WIN_MINHEIGHT,    /* Minimum height.      */
  114.     -1,               /* Maximum width (screen size)  */
  115.     -1,               /* Maximum height (screen size) */
  116.     CUSTOMSCREEN,     /* A screen of our own. */
  117.     ourwindowtags     /* tags for additional V37 features */
  118.     };
  119.  
  120.  
  121. VOID main(int argc, char *argv[])
  122. {
  123.     /* Declare variables here */
  124.     ULONG signalmask, winsignal, signals;
  125.     BOOL done = FALSE;
  126.     struct Screen *screen1 = NULL;
  127.     struct Window *window1 = NULL;
  128.  
  129.     /* Open Intuition Library.  NOTE - We are accepting version 33 (1.2)
  130.      * or higher because we are opening our display in a compatible manner.
  131.      * However - If you add to this example, do NOT use any NEW V37
  132.      * functions unless IntuitionBase->lib_Version is >= 37
  133.      */
  134.     IntuitionBase = OpenLibrary( "intuition.library",INTUITION_REV );
  135.     if (IntuitionBase == NULL)
  136.         cleanExit(screen1, window1, RETURN_WARN);
  137.  
  138.     /* Open any other required libraries and make */
  139.     /* any assignments that were postponed above  */
  140.  
  141.     /* Open the screen */
  142.     screen1 = OpenScreen(&fullHires);
  143.     if (screen1 == NULL)
  144.         cleanExit(screen1, window1, RETURN_WARN);
  145.  
  146.     /* Attach the window to the open screen ... */
  147.     easyWindow.Screen = screen1;
  148.  
  149.     /* ... and open the window */
  150.     window1 = OpenWindow(&easyWindow);
  151.     if (window1 == NULL)
  152.         cleanExit(screen1, window1, RETURN_WARN);
  153.  
  154.     /* Set up the signals for the events we want to hear about ...   */
  155.     winsignal = 1L << window1->UserPort->mp_SigBit;  /* window IDCMP */
  156.     signalmask = winsignal;     /* we will only wait on IDCMP events */
  157.  
  158.     /* Here's the main input event loop where we wait for events.    */
  159.     /* We have asked Intuition to send us CLOSEWINDOW IDCMP events   */
  160.     /* Exec will wake us if any event we are waiting for occurs.     */
  161.     while( !done )
  162.     {
  163.         signals = Wait(signalmask);
  164.  
  165.         /* An event occurred - now act on the signal(s) we received.*/
  166.         /* We were only waiting on one signal (winsignal) in our    */
  167.         /* signalmask, so we actually know we received winsignal.   */
  168.         if(signals & winsignal)
  169.             done = handleIDCMP(window1);    /* done if close gadget */
  170.     }
  171.     cleanExit(screen1, window1, RETURN_OK); /* Exit the program     */
  172. }
  173.  
  174.  
  175. BOOL handleIDCMP( struct Window *win )
  176. {
  177.     BOOL done = FALSE;
  178.     struct IntuiMessage *message;
  179.     ULONG class;
  180.  
  181.     /* Examine pending messages */
  182.     while( message = (struct IntuiMessage *)GetMsg(win->UserPort) )
  183.     {
  184.         class = message->Class;   /* get all data we need from message */
  185.  
  186.         /* When we're through with a message, reply */
  187.         ReplyMsg( (struct Message *)message);
  188.  
  189.         /* See what events occurred */
  190.         switch( class )
  191.         {
  192.             case IDCMP_CLOSEWINDOW:
  193.                 done = TRUE;
  194.                 break;
  195.             default:
  196.                 break;
  197.         }
  198.     }
  199.     return(done);
  200. }
  201.  
  202.  
  203. VOID cleanExit( struct Screen *scrn, struct Window *wind, LONG returnValue )
  204. {
  205.     /* Close things in the reverse order of opening */
  206.     if (wind) CloseWindow( wind );      /* Close window if opened */
  207.     if (scrn) CloseScreen( scrn );      /* Close screen if opened */
  208.  
  209.     /* Close the library, and then exit */
  210.     if (IntuitionBase) CloseLibrary( IntuitionBase );
  211.     exit(returnValue);
  212. }
  213.