home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / web2c / mf / MFwindow / sun-xview.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-28  |  6.5 KB  |  255 lines

  1. /* Link this to sun.c if you are running on a XView system (OpenWindows) */
  2.  
  3. /*
  4.  *  author = "Pierre MacKay (from the original by Paul Richards)"
  5.  *  version = "0.5",
  6.  *  date = "5 May 1991 - June 1992"
  7.  *  filename = "sun_xview.c",
  8.  *  contact = "Pierre MacKay",
  9.  *  email = "mackay@cs.washington.edu"
  10.  * Graphics window interface to Metafont for Suns running
  11.  *    OpenWindows Version 2
  12.  * This code is converted to XView from a SunView translation of the
  13.  * original sun.c.  Ideally it should be converted to true Xlib
  14.  * functions, but it's pretty lightweight stuff except maybe over
  15.  * a network. 
  16.  * Destroy checking is bogus, but XView cleans up the mess ok, even
  17.  * if you "quit" from the pulldown menu.  Otherwise it seems clean.
  18.  * 
  19.  * For the moment this and the SunView interface seem to be
  20.  * mutually exclusive, since they use library routines with
  21.  * the same names, which mightily confuses the loader. 
  22.  * It doesn't help much to change the name of MFTERM since
  23.  * XView wants to name its own terminal "sun" just like
  24.  * the SunView terminal
  25.  *
  26.  * WARNING: the library sequence is critical, as I know
  27.  * to my grief.  Make sure that virmf is loaded with libraries
  28.  * in the sequence: -lxview -lXt -lX11 -lsuntool -lsunwindow -lpixrect
  29.  * or you will get some rather bewildering (and fatal) errors.
  30.  */
  31.  
  32. #define    EXTERN    extern
  33. #include "../mfd.h" 
  34.  
  35. #ifdef XVIEW
  36. /* xview headers use the non-POSIX 4.3 BSD types in <sys/types.h> */
  37. #undef _POSIX_SOURCE
  38. /* two name conflicts with mfd.h; fortunately we don't need either */
  39. #undef ord
  40. #undef reset
  41.  
  42. #include <stdio.h>
  43. #include <sys/types.h>
  44. #include <X11/Xlib.h>
  45. #include <xview/xview.h>
  46. #include <xview/canvas.h>
  47. #include <xview/notice.h>
  48.  
  49. static void repaint_proc();
  50. static void resize_proc();
  51.  
  52. static Notify_value mf_destroy_func();
  53. extern Notify_error notify_dispatch();
  54.  
  55. static int destroy_ready;  /* could be used for tighter control */
  56.  
  57. /*
  58.  * global handle on the graphics subwindow 
  59.  *
  60.  */
  61.  
  62. struct    MFsubwindow {
  63.     int    mf_flags;
  64. #define    MF_RESTART    0x01
  65.     struct    pixwin *mf_pixwin;
  66.     struct    rect mf_rect;
  67.       } sun_mf_subwin; /* Make sure that names storage is allocated. */
  68.  
  69. static struct    MFsubwindow    *metafont_sw = &sun_mf_subwin;    /* window handle */
  70.  
  71. /*
  72.  * Gray background for graphics area
  73.  */
  74.  
  75. static short    mf_graybackground_image[] = {0x5555, 0xaaaa};
  76.     mpr_static(sun_xview_gray_bkgr, 2, 2, 1, mf_graybackground_image);
  77.  
  78.  
  79. Rect *rect;
  80. Frame frame;
  81. Canvas canvas;
  82. Pixwin *pw;
  83.  
  84. /*
  85.  * init_screen: boolean;  return true if window operations legal
  86.  */
  87.  
  88. #ifdef __SUNVIEW_COMPAT__
  89. mf_xview_initscreen()
  90. #else
  91. mf_sun_initscreen()
  92. #endif
  93. {
  94.     (void)xv_init(NULL); /* Worked for a while without this---sinister!! */
  95.     frame = xv_create(NULL,FRAME,
  96.               XV_LABEL, "METAFONT",
  97.               FRAME_SHOW_LABEL, TRUE,
  98.               WIN_ERROR_MSG, 
  99.                 "! Window access requires METAFONT to run under OpenWindows\n",
  100.               0);
  101.     /* interpose a destroy procedure so we can shut down cleanly */
  102.     /* if only it worked.  As it is, this interposed procedure   */
  103.     /* is needed for error-free compilation and loading, but I   */
  104.     /* can't seem to get into it from the menu "quit" button.    */
  105.     /* If you have a fix, let us know.                           */
  106.     (void) notify_interpose_destroy_func(frame, mf_destroy_func);
  107.  
  108.      canvas = xv_create(frame, CANVAS,
  109.                    CANVAS_RESIZE_PROC, resize_proc,
  110.                    WIN_ERROR_MSG, "Can't create canvas",
  111.                    0);
  112.     pw = canvas_pixwin(canvas);
  113.  
  114.     metafont_sw->mf_pixwin = canvas_pixwin(canvas);
  115.  
  116.  
  117.     /* 
  118.      * Instead of using window_main_loop, just show the frame.
  119.      * Metafont's procedures will be in control, not the notifier.
  120.      */
  121.     xv_set(frame,WIN_SHOW, TRUE, 0);
  122.  
  123.     rect = (Rect *)xv_get(canvas, WIN_RECT);  /* Get current dimensions */
  124.     pw_replrop(pw,
  125.            0, 0,
  126.            rect->r_width,
  127.            rect->r_height,
  128.            PIX_SRC,
  129.            &sun_xview_gray_bkgr, 0, 0);    /* clear subwindow */
  130.  
  131.     return(1); /* Caller expects a TRUE value */
  132. }
  133.  
  134. /*
  135.  * updatescreen; -- Flush pending output and make sure screen is ready to view
  136.  */
  137.  
  138. #ifdef __SUNVIEW_COMPAT__
  139. mf_xview_updatescreen()
  140. #else
  141. mf_sun_updatescreen()
  142. #endif
  143. {
  144.     /* Flush out the top rows */
  145.         XFlush( (Display *) XV_DISPLAY_FROM_WINDOW(frame));
  146.     (void)notify_dispatch();
  147.     rect = (Rect *)xv_get(canvas, WIN_RECT);  /* Get current dimensions */
  148.     if (metafont_sw->mf_flags & MF_RESTART) {
  149.         metafont_sw->mf_flags &= ~MF_RESTART;
  150.         pw_replrop(pw,
  151.                0, 0,
  152.                rect->r_width,
  153.                rect->r_height,
  154.                PIX_SRC,
  155.                &sun_xview_gray_bkgr, 0, 0);    /* clear subwindow */
  156.     }
  157. }
  158.  
  159. /*
  160.  * blankrectangle: reset rectangle bounded by ([left,right],[top,bottom])
  161.  *            to background color
  162.  */
  163. #ifdef __SUNVIEW_COMPAT__
  164. mf_xview_blankrectangle(left, right, top, bottom)
  165. #else
  166. mf_sun_blankrectangle(left, right, top, bottom)
  167. #endif
  168.  
  169.     screencol left, right;
  170.     screenrow top, bottom;
  171. {
  172.     pw_writebackground(pw, left, top,
  173.                 right-left+1, bottom-top+1, PIX_CLR);
  174. }
  175.  
  176. /*
  177.  * paintrow -- paint "row" starting with color "init_color",  up to next
  178.  *        transition specified by "transition_vector", switch colors,
  179.  *        and continue for "vector_size" transitions.
  180.  */
  181.  
  182. #ifdef __SUNVIEW_COMPAT__
  183. mf_xview_paintrow(row, init_color, transition_vector, vector_size)
  184. #else
  185. mf_sun_paintrow(row, init_color, transition_vector, vector_size)
  186. #endif
  187.     screenrow    row;
  188.     pixelcolor    init_color;
  189.     transspec    transition_vector;
  190.     screencol    vector_size;
  191. {
  192.     register    col;
  193.     register    color;
  194.  
  195.     color = (init_color == 0)? 0 : 1;
  196.  
  197.     do {
  198.         col = *transition_vector++;
  199.         pw_vector(pw,
  200.               col, row, (*transition_vector)-1, row,
  201.               PIX_SRC, color);
  202.         color = 1 - color;
  203.     } while (--vector_size);
  204.     (void)notify_dispatch();
  205. }
  206.  
  207. static void
  208. repaint_proc( /* Ignore args */ )
  209. {
  210.     /* if repainting is required, just restart */
  211.     metafont_sw->mf_flags |= MF_RESTART;
  212. }
  213.  
  214. static void
  215. resize_proc( /* Ignore args */ )
  216. {
  217.     metafont_sw->mf_flags |= MF_RESTART;
  218. }
  219.  
  220. static Notify_value
  221.   mf_destroy_func(client, status)
  222. Notify_client client;
  223. Destroy_status status;
  224. {
  225.   puts("entered destroy function");
  226.   if (status == DESTROY_CHECKING) {
  227.     int answer = notice_prompt(client,NULL,
  228.                    NOTICE_MESSAGE_STRINGS, "Really quit?", NULL,
  229.                    NOTICE_BUTTON_YES, "Yes",
  230.                    NOTICE_BUTTON_NO, "No",
  231.                    NULL);
  232.     if (answer == NOTICE_NO)
  233.       notify_veto_destroy(client);
  234.   } else if (status == DESTROY_CLEANUP) {
  235.     return(notify_next_destroy_func(client,status));
  236.   } else if (status == DESTROY_SAVE_YOURSELF)
  237.     return(notify_next_destroy_func(client,status));
  238.   /* Don't want to save a MF window */
  239.   else puts("Process died.");
  240.   return NOTIFY_DONE;
  241. }
  242.  
  243.  
  244. int
  245. quit()
  246. {
  247.   fprintf(stderr,"now we are in quit");
  248.   fflush(stderr);
  249.   xv_destroy_safe(frame);
  250.   return XV_OK;
  251. }
  252. #else
  253. int mf_xiew_dummy;
  254. #endif /* XVIEW */
  255.