home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / PART_F / VIEWMAN / GEMSKEL.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-10  |  5.3 KB  |  248 lines

  1. /* gemskel.c - GEM application skeleton
  2.  * Copyright 1990, Atari Corporation
  3.  * ================================================================
  4.  * 900125 kbad Moved wind_updates to the right place, no mo MCTRL
  5.  *                updated #include files, cleaned up comments a bit
  6.  * 890716 kbad Modified to use *event as a quit flag
  7.  * 890708 kbad Created
  8.  */
  9.  
  10. #include <sys\gemskel.h>    /* gets aesalt, aes, vdi, stddef */
  11. #include <stdlib.h>            /* for exit() */
  12. #include <tos.h>            /* Getrez() */
  13.  
  14.  
  15. /* Globals allocated herein
  16.  * ================================================================
  17.  */
  18.  
  19. /* arguments
  20.  */
  21. int        nargs;
  22. char    **args, **env;
  23.  
  24. /* VDI arrays
  25.  */
  26. int        contrl[12], intin[128], intout[128], ptsin[128], ptsout[128],
  27.         work_in[12], work_out[57];
  28. int        vhandle, xres, yres;
  29.  
  30. /* AES variables
  31.  */
  32. int        gl_apid, gl_hchar, gl_wchar, gl_hbox, gl_wbox;
  33. GRECT    desk;
  34. OBJECT    *menu;
  35.  
  36. /* null structures
  37.  */
  38. GRECT    grect0 = { 0, 0, 0, 0 };
  39. MOBLK    moblk0 = { 0, 0, 0, 0, 0 };
  40. MFDB    mfdb0 = { NULL, 0, 0, 0, 0, 0, 0, 0, 0 };
  41.  
  42.  
  43. /* Locals used for evnt_multi input, can be set via set_events()
  44.  * ================================================================
  45.  */
  46. static    int        ev_mask=0, ev_clicks=0, ev_bmask=0, ev_bstate=0;
  47. static    MOBLK    ev_m1 = { 0, 0, 0, 0, 0 };
  48. static    MOBLK    ev_m2 = { 0, 0, 0, 0, 0 };
  49. static    long    ev_time=0L;
  50.  
  51.  
  52. /* Functions
  53.  * ================================================================
  54.  */
  55.  
  56.  
  57. void
  58. main( int argc, char *argv[], char *envp[] )
  59. {
  60.     int     i;
  61. /*     -----    evnt_multi return parameters */
  62.     int        event, msg[8], key, nclicks;
  63.     MRETS    mrets;
  64.     int      rez;
  65. /*
  66.  * Initialize global arguments
  67.  */
  68.     if( (nargs = argc) != 1)
  69.         args = argv;
  70.     env = envp;
  71.  
  72. /*
  73.  * See if we were run from the AUTO folder...
  74.  */
  75.     if( (gl_apid = appl_init()) == -1 ) {
  76.         Cconws("\r\nError initializing GEM, hit a key...");
  77.         Cconin();
  78.         exit( gl_apid );
  79.     }
  80.     rez = Getrez() + 2;
  81.     if(( rez != 2 ) && ( rez != 6 ) )
  82.     {
  83.        /* Ensure that we run ONLY in ST LOW or TT MED - 640x480 16 colors */
  84.        form_alert( 1, "[3][ | This program runs in| ST LOW or TT MED Only][ OK ]" );
  85.        appl_exit();
  86.        exit( -1 );
  87.     }
  88. /*
  89.  * Set up work_in to initialize VDI functions to useful values,
  90.  * Get the physical workstation handle from the AES, then
  91.  * open a virtual workstation and get our AES work area's extent.
  92.  */
  93.     work_in[0] = Getrez()+2; /* let's not gag GDOS */
  94.     for( i = 1; i < 10; work_in[i++] = 1 )
  95.     ;
  96.     work_in[10] = 2; /* raster coordinates */
  97.     vhandle = graf_handle( &gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox );
  98.     v_opnvwk( work_in, &vhandle, work_out );
  99.     xres = work_out[0];
  100.     yres = work_out[1];
  101.  
  102. /*
  103.  * Call initialization hooks
  104.  */
  105.     Wind_get( 0, WF_WORKXYWH, ( WARGS *)&desk );
  106.     if( !rsrc_init() ) {
  107.         form_alert( 1, "[3][ RSC ERROR ][ OK ]" );
  108.         v_clsvwk( vhandle );
  109.         appl_exit();
  110.         exit( -1 );
  111.     }
  112.  
  113.     wind_init();
  114.     evnt_init();
  115.  
  116. /*
  117.  * Main event loop
  118.  */
  119.     do {
  120.  
  121.         event = Evnt_multi( ev_mask, ev_clicks, ev_bmask, ev_bstate,
  122.                             &ev_m1, &ev_m2, ( WORD *)msg, ev_time,
  123.                             &mrets, ( WORD *)&key, ( WORD *)&nclicks );
  124.         wind_update( BEG_UPDATE );
  125.     /*
  126.      * call pre-event-processing hook
  127.      */
  128.         if( evnt_hook( event, msg, &mrets, &key, &nclicks ) )
  129.             continue;
  130.  
  131.     /* Dispatch events.
  132.      * It is possible to get more than one event at a time, so if the
  133.      * order of event handling is important to you, change the order
  134.      * in which they're handled here.
  135.      */
  136.         if( event & MU_TIMER )
  137.             do_timer( &event );
  138.  
  139.         if( event & MU_KEYBD )
  140.             do_key( mrets.kstate, key, &event );
  141.  
  142.         if( event & MU_BUTTON )
  143.             do_button( &mrets, nclicks, &event );
  144.  
  145.         if( event & MU_M1 )
  146.             do_m1( &mrets, &event );
  147.  
  148.         if( event & MU_M2 )
  149.             do_m2( &mrets, &event );
  150.  
  151.         if( event & MU_MESAG )
  152.             switch( msg[0] ) {
  153.  
  154.                 case MN_SELECTED:
  155.                     do_menu( msg, &event );
  156.                 break;
  157.  
  158.                 case WM_REDRAW:
  159.                 case WM_TOPPED:
  160.                 case WM_CLOSED:
  161.                 case WM_FULLED:
  162.                 case WM_ARROWED:
  163.                 case WM_HSLID:
  164.                 case WM_VSLID:
  165.                 case WM_SIZED:
  166.                 case WM_MOVED:
  167.                 case WM_NEWTOP:
  168.                     do_windows( msg, &event );
  169.                 break;
  170.  
  171.                 case AC_OPEN:
  172.                     acc_open( msg );
  173.                 break;
  174.  
  175.                 case AC_CLOSE:
  176.                     acc_close( msg );
  177.                 break;
  178.  
  179.                 default:
  180.                     msg_hook( msg, &event );
  181.             } /* switch */
  182.         /* MU_MESAG */
  183.  
  184.         wind_update( END_UPDATE );
  185.  
  186.     /*
  187.      * Event handling routines zero out the event variable
  188.      * to exit the application.
  189.      */
  190.     } while( event );
  191.  
  192.     gem_exit( 0 );
  193. }
  194.  
  195.  
  196. /* Clean exit.
  197.  */
  198. void
  199. gem_exit( int code )
  200. {
  201.     int ignore[8];
  202.  
  203. /*
  204.  * Go into an endless loop if we're a desk accessory...
  205.  */
  206.     if( !_app ) for(;;) evnt_mesag( ignore );
  207.  
  208. /*
  209.  * Otherwise, clean up and call the exit hooks
  210.  */
  211. /*    wind_update( END_UPDATE );*/
  212.     v_clsvwk( vhandle );
  213.     wind_exit();
  214.     rsrc_exit();
  215.     appl_exit();
  216.     exit( code );
  217. }
  218.  
  219.  
  220.  
  221. void
  222. Gem_Exit( int code )
  223. {
  224.    v_clsvwk( vhandle );
  225.    wind_exit();
  226.    rsrc_exit();
  227.    appl_exit();
  228.    exit( code );
  229. }
  230.  
  231.  
  232. /* Set parameters for main evnt_multi.
  233.  */
  234. void
  235. evnt_set( int mask, int clicks, int bmask, int bstate,
  236.             MOBLK *m1, MOBLK *m2, long time )
  237. {
  238.     if( !mask ) gem_exit( -1 );
  239.  
  240.     if( mask != -1 )    ev_mask = mask;
  241.     if( clicks != -1 )    ev_clicks = clicks;
  242.     if( bmask != -1 )    ev_bmask = bmask;
  243.     if( bstate != -1 )    ev_bstate = bstate;
  244.     if( m1 != NULL )    ev_m1 = *m1;
  245.     if( m2 != NULL )    ev_m2 = *m2;
  246.     if( time != -1L )    ev_time = time;
  247. }
  248.