home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / GNU_C++ / LIB / CFLIB-11.LZH / src / app.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-11  |  3.8 KB  |  188 lines

  1. #include "intern.h"
  2.  
  3. char __Ident_cflib[] = "$PatchLevel: CF library: "CFLIB_PATCHLEVEL" $";
  4.  
  5. /* intern global */
  6. int    cf_vdi_handle;
  7. int    cf_font_anz;
  8. int    cf_msg_cb = FALSE;
  9. int    cf_magxPC = FALSE;
  10.  
  11. /* intern lokal */
  12. static int        hidden;
  13. static int    rsc_load = FALSE;
  14.  
  15. void    init_app(char *rsc)
  16. {
  17.     int    d;
  18.     long    l;
  19.     int    work_out[57];
  20.     char    s[128];
  21.     char    path[256];
  22.  
  23.     debug("started\n");
  24.     gl_apid = appl_init();
  25.     gl_phys_handle = graf_handle(&gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox);
  26.     wind_get_grect(0, WF_WORKXYWH, &gl_desk);
  27.     graf_mouse(ARROW, 0x0L);            
  28.     hidden = 0;
  29. #ifdef __MINT__
  30.     gl_gem = aes_global[0];
  31. #else
  32.     gl_gem = _GemParBlk.global[0];
  33. #endif
  34.  
  35.     if (getcookie("MiNT", &l))
  36.         gl_mint = (int)l;
  37.     gl_magx = get_magx_version();
  38.     cf_magxPC = getcookie("MgPC", NULL);
  39.     if (getcookie("nAES", &l))
  40.         gl_naes = *(unsigned short *)l;
  41.     if (getcookie("NVDI", &l))
  42.         gl_nvdi = *(unsigned short *)l;
  43.  
  44.     /* Systemzeichensätze bestimmen */
  45.     if (appl_xgetinfo(0, &sys_big_height, &sys_big_id, &d, &d) == 0)
  46.     {
  47.         sys_big_id = 1;
  48.         if ((Getrez() == 0) || (Getrez() == 1))    /* ST-Low/Mid */
  49.             sys_big_height = 6;
  50.         else
  51.             sys_big_height = 13;
  52.     }
  53.     if (appl_xgetinfo(1, &sys_sml_height, &sys_sml_id, &d, &d) == 0)
  54.     {
  55.         sys_sml_id = 1;
  56.         sys_sml_height = 4;
  57.     }
  58.  
  59.     cf_vdi_handle = open_vwork(work_out);
  60.     cf_font_anz = work_out[10];
  61.     vq_extnd(cf_vdi_handle, TRUE, work_out);
  62.     gl_planes = work_out[4];
  63.  
  64.     /* Aus den Pixel-Höhen Point-Höhen ermitteln */
  65.     sys_sml_pts = height2pts(cf_vdi_handle, sys_sml_id, sys_sml_height);
  66.     sys_big_pts = height2pts(cf_vdi_handle, sys_big_id, sys_big_height);
  67.  
  68.     gl_gdos    = (vq_vgdos() != -2);
  69.     if (gl_gdos)
  70.         cf_font_anz += vst_load_fonts(cf_vdi_handle, 0);
  71.  
  72.     vst_font(cf_vdi_handle, sys_big_id);
  73.     vst_point(cf_vdi_handle, sys_big_pts, &sys_wchar, &sys_hchar, &sys_wbox, &sys_hbox);
  74.  
  75.     /*
  76.      * Startverzeichnis ermitteln. 
  77.      * Unter N.AES (Minix) kann es ungültige Pfade geben, daher der extra 
  78.      * path_exitst().
  79.      */
  80.     shel_read(path, s);
  81.     split_filename(path, gl_appdir, NULL);
  82.     if (!path_exists(gl_appdir))
  83.         get_path(gl_appdir, 0);
  84.  
  85.     init_userdef();
  86.  
  87.     if (rsc && *rsc != EOS)
  88.     {
  89.         rsc_load = (rsrc_load(rsc) != 0);
  90.         if (!rsc_load)
  91.         {
  92.             form_alert(1, "[3][RSC nicht gefunden!|RSC not found!][Exit]");
  93.             exit_app(-1);
  94.         }
  95.     }
  96. }
  97.  
  98. void    exit_gem(void)
  99. {
  100.     if (gl_gdos)
  101.         vst_unload_fonts(cf_vdi_handle, 0);
  102.     v_clsvwk(cf_vdi_handle);
  103.     term_userdef();
  104.     if (rsc_load)
  105.         rsrc_free();
  106.     appl_exit();
  107. }
  108.  
  109.  
  110. void    exit_app(int ret)
  111. {
  112.     exit_gem();
  113.     debug("finish with %d\n", ret);
  114.     exit(ret);
  115. }
  116.  
  117. void    hide_mouse(void)
  118. {
  119.     if (!hidden)
  120.         graf_mouse(M_OFF, NULL);
  121.     hidden++;
  122. }
  123.  
  124.  
  125. void    show_mouse(void)
  126. {
  127.     if (hidden > 0)
  128.     {
  129.         hidden--;
  130.         if (!hidden)
  131.             graf_mouse (M_ON, NULL);
  132.     }
  133. }
  134.  
  135.  
  136. int hide_mouse_if_needed(GRECT *rect)
  137. {
  138.     if (!hidden)
  139.     {
  140.         GRECT    mouse;
  141.         
  142.         mouse.g_w = 63;
  143.         mouse.g_h = 31;
  144. #ifdef __MTAES__
  145.     {
  146.         EVNTDATA    ev;
  147.         graf_mkstate(&ev);
  148.         mouse.g_x = ev.x - (mouse.g_w / 2);
  149.         mouse.g_y = ev.y - (mouse.g_h / 2);
  150.     }    
  151. #else
  152.     {
  153.         int    mx, my, d;
  154.         graf_mkstate(&mx, &my, &d, &d);
  155.         mouse.g_x = mx - (mouse.g_w / 2);
  156.         mouse.g_y = my - (mouse.g_h / 2);
  157.     }
  158. #endif
  159.     
  160.         if (rc_intersect(rect, &mouse))
  161.         {
  162.             hide_mouse();
  163.             return TRUE;
  164.         }
  165.     }
  166.     return FALSE;
  167. }
  168.  
  169.  
  170. int appl_xgetinfo(int type, int *out1, int *out2, int *out3, int *out4)
  171. {
  172.     int    has_agi = FALSE;
  173.  
  174. #ifdef __MINT__
  175.     has_agi = (    (gl_ap_version == 0x399 && getcookie("MagX", NULL)) ||
  176.                     (gl_ap_version >= 0x400) ||
  177.                     (appl_find("?AGI\0\0\0\0") == 0));
  178. #else
  179.     has_agi = (    (_GemParBlk.global[0] == 0x399 && getcookie("MagX", NULL)) ||
  180.                     (_GemParBlk.global[0] >= 0x400) ||
  181.                     (appl_find("?AGI\0\0\0\0") == 0));
  182. #endif
  183.     if (has_agi)
  184.         return (appl_getinfo (type, out1, out2, out3, out4));
  185.     else 
  186.         return 0;
  187. }
  188.