home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / ags_000.lha / gs261gdevintui.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-15  |  31.2 KB  |  1,183 lines

  1. #include "gs.h"
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <math.h>
  6. #include <exec/memory.h>
  7. #include <graphics/gfxbase.h>
  8. #include <graphics/gfxmacros.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/intuitionbase.h>
  11. #include <intuition/gadgetclass.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/icclass.h>
  14. #include <intuition/cghooks.h>
  15. #include <intuition/classes.h>
  16. #include <clib/intuition_protos.h>
  17. #include <clib/exec_protos.h>
  18. #include <graphics/scale.h>
  19. #include <clib/graphics_protos.h>
  20. #include <clib/utility_protos.h>
  21. #include <graphics/graphint.h>
  22. #include <clib/alib_protos.h>
  23. #include "gxdevice.h"
  24. #include "gdevintui.h"
  25. #include "gsmatrix.h"
  26. #include <signal.h>
  27. #include "rkmmodel.h"
  28.  
  29. #define LR_WIDTH 16
  30. #define UD_HEIGHT 11
  31.  
  32. extern void gs_intui(void);
  33.  
  34. /* forward declarations */
  35. private int i_open_device(gx_device *);
  36. int i_close_device(gx_device *);
  37. private int i_fill_rectangle(gx_device *,int,int,int,int,gx_color_index);
  38. dev_proc_copy_mono(i_copy_mono);
  39. private int i_draw_line(gx_device *,int,int,int,int,gx_color_index);
  40. private void i_get_initial_matrix(gx_device *, gs_matrix *);
  41. /*
  42. private int i_copy_color(gx_device *, unsigned char *,int,int, \
  43.              gx_bitmap_id,int,int,int,int);
  44. */
  45. private int i_sync_output(gx_device *);
  46.  
  47. struct Window *open_my_window(gx_device *);
  48. void clean_win(struct Window **);
  49. void close_my_window(struct Window *);
  50. void disable_gadgets(struct Window *);
  51. void enable_gadgets(struct Window *);
  52. void start_render_state(struct Window *);
  53. void stop_render_state(struct Window *);
  54.  
  55.  
  56. /* Procedure records */
  57. #ifdef BLACK_AND_WHITE
  58. private gx_color_index i_bw_map_rgb_color(gx_device *, gx_color_value , \
  59.                   gx_color_value , gx_color_value );
  60. private int i_bw_map_color_rgb(gx_device *, gx_color_index , \
  61.                gx_color_value rgb[3]);
  62. #define intui_procs {\
  63.     i_open_device, gx_default_get_initial_matrix,\
  64.     i_sync_output, gx_default_output_page, i_close_device,\
  65.     i_bw_map_rgb_color, i_bw_map_color_rgb,\
  66.     i_fill_rectangle, gx_default_tile_rectangle,\
  67.     i_copy_mono, gx_default_copy_color, i_draw_line,\
  68.     gx_default_get_bits, gx_default_get_props, gx_default_put_props}
  69. #else
  70. private gx_color_index i_map_rgb_color(gx_device *, gx_color_value , \
  71.                    gx_color_value , gx_color_value );
  72. private int i_map_color_rgb(gx_device *, gx_color_index , \
  73.                 gx_color_value rgb[3]);
  74. #define intui_procs {\
  75.     i_open_device, gx_default_get_initial_matrix,\
  76.     i_sync_output, gx_default_output_page, i_close_device,\
  77.     i_map_rgb_color, i_map_color_rgb,\
  78.     i_fill_rectangle, gx_default_tile_rectangle,\
  79.     i_copy_mono, gx_default_copy_color, i_draw_line,\
  80.     gx_default_get_bits, gx_default_get_props, gx_default_put_props}
  81. #endif
  82.  
  83. private gx_device_procs gs_intui_procs=intui_procs;
  84.  
  85. /* device structure */
  86. intui_device gs_intui_device={
  87.   sizeof(intui_device),
  88.   &gs_intui_procs,         /* procedures */
  89.   "intui",                 /* name */
  90.   PRE_WIDTH,               /* width */
  91.   PRE_HEIGHT,              /* height */
  92.   XPPI,                    /* x_pixels_per_inch */
  93.   YPPI,                    /* y_pixels_per_inch */
  94.   no_margins,              /* rectangle--margins around imageable area*/  
  95. #ifdef BLACK_AND_WHITE
  96.   dci_black_and_white,
  97. #else
  98.   {1,2,3,0,4,0},
  99. #endif
  100.   0,                       /* is open */
  101.   NULL,                    /* window */
  102.   NULL,                    /* screen */
  103.   NULL,                    /* rast port */
  104.   NULL,                    /* super bitmap */
  105.   0,                       /* real depth */
  106.   0,0,                     /* black and white */
  107.   NULL                     /* screen's DrawInfo */
  108. };
  109.  
  110. UBYTE *monoplane=NULL;
  111. size_t mono_size=0;
  112. struct BitMap *color_chipmap;
  113. ULONG sbm_plane_size=0;
  114. struct Remember *remkey=NULL;
  115. struct Remember *reremkey=NULL;
  116. struct Task *task;
  117. struct Gadget *my_gad[6];
  118. Object *my_rkm_model1;
  119. Object *my_rkm_model2;
  120. struct IClass *rkm;
  121. struct Image *up_image;
  122. struct Image *down_image;
  123. struct Image *left_image;
  124. struct Image *right_image;
  125. struct Gadget *pg_h;
  126. struct Gadget *bg_h1;
  127. struct Gadget *bg_h2;
  128. struct Gadget *pg_v;
  129. struct Gadget *bg_v1;
  130. struct Gadget *bg_v2;
  131. struct TagItem *id2u_map;
  132. struct TagItem *id2d_map;
  133. struct TagItem *c2p_map;
  134. struct TagItem *p2c_map;
  135. char version_string[]="$VER: Ghostscript 2.4.1 Amiga Port 1.0b (11 Mar 1993)";
  136. boolean render_active=FALSE;
  137.  
  138. /** procedures **/
  139.  
  140. /* tests if the pixel coordinates have valid values */
  141. boolean is_valid_area(gx_device *dev,int x,\
  142.               int y, int width, int height)
  143. {
  144.   return x>=0 && y>=0 && width>=0 && height>=0 \
  145.     && x+width<=idev->width && y+height<=idev->height ;
  146. }
  147.  
  148. /* Amiga library bases */
  149. struct IntuitionBase *IntuitionBase;
  150. struct GfxBase *GfxBase;
  151. struct UtilityBase *UtilityBase;
  152. struct LayersBase *LayersBase;
  153.  
  154. #ifdef DEBUG
  155. void ctrl_hook(int sig)
  156. {
  157.   i_close_device((gx_device *)&gs_intui_device);
  158.   fprintf(stderr,"user aborted program\n");
  159.   exit(0);
  160. }
  161. #endif
  162.  
  163. /* opens the intui device; makes allocations and initialations */
  164. int i_open_device(gx_device *dev)
  165. {
  166.   int res=0;
  167.   struct Screen *display_screen;
  168.   int depth=idev->color_info.depth;
  169.   int i;
  170.   struct TagItem *win_tags;
  171.   BOOL alloc_err=FALSE;
  172.   struct BitMap *sbm;
  173.   struct Window *display_window;
  174.   
  175. #ifdef DEBUG
  176.   printf("open device\n");
  177.   signal(SIGINT,ctrl_hook);
  178. #endif
  179.   /* Open the graphics library */
  180.   if((GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",\
  181.                         LIB_REV))!=NULL)
  182.     {
  183.       /* Open the intuition library */
  184.       if((IntuitionBase=(struct IntuitionBase *) \
  185.       OpenLibrary("intuition.library",LIB_REV))!=NULL)
  186.     {
  187.       if((LayersBase=(struct LayersBase *)\
  188.           OpenLibrary("layers.library",LIB_REV))!=NULL)
  189.         {
  190.           if((UtilityBase=(struct UtilityBase *) \
  191.           OpenLibrary("utility.library",LIB_REV))!=NULL)
  192.         {
  193.           /* alloc mem for color_chipmap structure */
  194.           if((color_chipmap=\
  195.               AllocRemember(&remkey,sizeof(*color_chipmap),\
  196.                     MEMF_PUBLIC|MEMF_CLEAR|\
  197.                     MEMF_ANY))\
  198.              !=NULL)
  199.             {
  200.               /* locks the standard public screen */
  201.               if((display_screen=LockPubScreen(NULL))!=NULL)
  202.             {
  203.               idev->s=display_screen;
  204.               idev->di=GetScreenDrawInfo(display_screen);
  205.               if((sbm=(struct BitMap *)\
  206.                   AllocRemember(&remkey,\
  207.                         sizeof(*sbm),\
  208.                         MEMF_PUBLIC|\
  209.                         MEMF_CLEAR|\
  210.                         MEMF_ANY))\
  211.                  !=NULL)
  212.                 {
  213.                   idev->real_depth=idev->di->dri_Depth;
  214. #ifdef DEBUG
  215.                   fprintf(stderr,"depth: %d\n",idev->real_depth);
  216. #endif
  217.                 InitBitMap(sbm,idev->real_depth,\
  218.                      idev->width,idev->height);
  219.                   idev->supermap=sbm;
  220.                   for(i=0;i<idev->real_depth && !alloc_err;\
  221.                   i++)
  222.                 {
  223.                   sbm_plane_size=RASSIZE(idev->width,\
  224.                              idev->height);
  225.                   if((sbm->Planes[i]=\
  226.                       AllocRemember(&remkey,\
  227.                             sbm_plane_size,\
  228.                             MEMF_CHIP|\
  229.                             MEMF_CLEAR|\
  230.                             MEMF_REVERSE|\
  231.                             MEMF_PUBLIC))\
  232.                      ==NULL) alloc_err=TRUE;
  233.                 }
  234.                   if(!alloc_err)
  235.                 {
  236.                   if((display_window=
  237.                       open_my_window(dev))!=NULL)
  238.                     {
  239.                       idev->w=display_window;
  240.                       idev->rp=\
  241.                     display_window->RPort;
  242.                       idev->is_open=-1;
  243.                       
  244.                       /* information for B&w */
  245.                       /* displaying */
  246.                       idev->white=2;
  247. /*
  248.                     idev->di->\
  249.                       dri_Pens[BLOCKPEN];
  250. */
  251.                       idev->black=1;
  252. /*
  253.                     idev->di->\
  254.                       dri_Pens[DETAILPEN];
  255. */
  256.                       /* calculate scaling */
  257.                       /* due to smaller */
  258.                       /* window size */
  259.                       if((task=\
  260.                       CreateTask("ghostscript "
  261.                              "Intuition",\
  262.                              FindTask(NULL)\
  263.                              ->tc_Node\
  264.                              .ln_Pri,\
  265.                              gs_intui,\
  266.                              STACK_SIZE))\
  267.                      ==NULL)
  268.                     {
  269.                       res=-1;
  270. #ifdef DEBUG
  271.                       fprintf(stderr,\
  272.                           "gs intui: "
  273.                           "can' create "
  274.                           "ghostscript "
  275.                           "intuition "
  276.                           "task\n");
  277. #endif
  278.                     }
  279.                     }
  280.                   else 
  281.                     {
  282.                       res=-1;
  283. #ifdef DEBUG
  284.                       fprintf(stderr,"gs intui: "
  285.                           "can't open "
  286.                           "intuition "
  287.                           "window.\n");
  288. #endif
  289.                     }
  290.                 }
  291.                   else
  292.                 {
  293.                   res=-1;
  294. #ifdef DEBUG
  295.                   fprintf(stderr,"gs intui: can't alloc mem "
  296.                       "for super bitmap planes.\n");
  297. #endif
  298.                 }
  299.                 }
  300.               else 
  301.                 {
  302.                   res=-1;
  303. #ifdef DEBUG
  304.                   fprintf(stderr,"gs intui: can't alloc mem "
  305.                       "for super bitmap structure.\n");
  306. #endif
  307.                 }
  308.             }
  309.               else 
  310.             {
  311.               res=-1;
  312. #ifdef DEBUG
  313.               fprintf(stderr,"gs intui: can't lock standard "
  314.                   "public screen.\n");
  315. #endif
  316.             }
  317.             }
  318.           else
  319.             {
  320.               res=-1;
  321. #ifdef DEBUG
  322.               fprintf(stderr,"gs intui: can't allocate mem for "
  323.                   "bitmap structure.\n");
  324. #endif
  325.             }
  326.         }
  327.           else
  328.         {
  329.           res=-1;
  330. #ifdef DEBUG
  331.           fprintf(stderr,"gs intui: can't open utility library "
  332.               "V%d.\n",LIB_REV);
  333. #endif
  334.         }
  335.         }
  336.       else
  337.         {
  338.           res=-1;
  339. #ifdef DEBUG
  340.           fprintf(stderr,"gs intui: can't open layers library "
  341.               "V%d.\n",LIB_REV);
  342. #endif
  343.         }
  344.     }
  345.       else 
  346.     {
  347.       res=-1;
  348. #ifdef DEBUG
  349.       fprintf(stderr,"gs intui: can't open intuition library "
  350.           "V%d.\n",LIB_REV);
  351. #endif
  352.     }
  353.     }
  354.   else 
  355.     {
  356.       res=-1;
  357. #ifdef DEBUG
  358.       fprintf(stderr,"gs intui: can't open graphics library "
  359.           "V%d.\n",LIB_REV);
  360. #endif
  361.     }
  362.   return res;
  363. }
  364.  
  365. /* closes intui device */
  366. int i_close_device(gx_device *dev)
  367. {
  368.   int i;
  369.   struct Window *w=idev->w;
  370.   struct BitMap *sbm=idev->supermap;
  371.  
  372.   idev->is_open=0;
  373. #ifdef DEBUG
  374.   fprintf(stderr,"gs intui: close device\n");
  375. #endif
  376.   idev->is_open=FALSE;
  377.   if(task!=NULL) DeleteTask(task);
  378.   WaitBlit();
  379.   for(i=0;i<idev->color_info.depth;i++)
  380.     {
  381.       if(color_chipmap->Planes[i]!=NULL)
  382.     FreeVec(color_chipmap->Planes[i]);
  383.     }
  384.   FreeRemember(&reremkey,TRUE);
  385.   FreeRemember(&remkey,TRUE);
  386.   close_my_window(idev->w);
  387.   FreeScreenDrawInfo(idev->s,idev->di);
  388.   UnlockPubScreen(NULL,idev->s);
  389.   CloseLibrary((struct Library *)UtilityBase);
  390.   CloseLibrary((struct Library *)LayersBase);
  391.   CloseLibrary((struct Library *)IntuitionBase);
  392.   CloseLibrary((struct Library *)GfxBase);
  393.   return 0;
  394. }
  395.  
  396. int i_ctab[]={1,3,0,2};
  397.  
  398. #ifdef BLACK_AND_WHITE
  399. gx_color_index i_bw_map_rgb_color(gx_device *dev, gx_color_value red,
  400.                   gx_color_value green, \
  401.                   gx_color_value blue)
  402. {
  403.   return red==gx_max_color_value?idev->white:idev->black;
  404. }
  405.  
  406. int i_bw_map_color_rgb(gx_device *dev, gx_color_index color, \
  407.                gx_color_value rgb[3])
  408. {
  409.   rgb[0]=rgb[1]=rgb[2]=color==idev->white?gx_max_color_value:0;
  410.  
  411.   return 0;
  412. }
  413. #else
  414. gx_color_index i_map_rgb_color(gx_device *dev, gx_color_value red,
  415.                    gx_color_value green, gx_color_value blue)
  416. {
  417.   gx_color_value nred=red>>((sizeof(gx_color_value)<<3)-2);
  418.  
  419.   return i_ctab[nred];
  420. }
  421.  
  422. int i_map_color_rgb(gx_device *dev, gx_color_index color, \
  423.             gx_color_value rgb[3])
  424. {
  425.   gx_color_value v=0;
  426.   int res=0;
  427.  
  428.   while(i_ctab[v]!=color && v<4) v++;
  429.   if(v<4)
  430.     {
  431.       v=-1&(v<<((sizeof(gx_color_value)<<3)-2));
  432.       rgb[0]=rgb[1]=rgb[2]=v;
  433.     }
  434.   else res=-1;
  435.  
  436.   return res;
  437. }
  438. #endif
  439.  
  440. int i_fill_rectangle(gx_device *dev, int x, int y, \
  441.             int width, int height, gx_color_index color)
  442. {
  443.   if(!render_active) 
  444.     start_render_state(idev->w);
  445.  
  446.   if(is_valid_area(dev,x,y,width,height))
  447.     {
  448.       if(width>0 && height>0)
  449.     {
  450.       SetDrMd(idev->rp,JAM1);
  451.       SetAPen(idev->rp,color);
  452.       LockLayerInfo(idev->rp->Layer->LayerInfo);
  453.       LockLayerRom(idev->rp->Layer);
  454.       RectFill(idev->rp,x,y,x+width-1,y+height-1);
  455.       UnlockLayerRom(idev->rp->Layer);
  456.       UnlockLayerInfo(idev->rp->Layer->LayerInfo);
  457.       SetAPen(idev->rp,1);
  458.     }
  459.     }
  460.   return 0;
  461. }
  462.  
  463. int i_draw_line(gx_device *dev, int x0, int y0, int x1, int y1, \
  464.         gx_color_index color)
  465. {
  466.   if(!render_active) 
  467.     start_render_state(idev->w);
  468.  
  469.   if(x0!=x1 || y0!=y1)
  470.     {
  471.       if(y1 < y0)
  472.     {
  473.       int d;
  474.       
  475.       d=x1;
  476.       x1=x0;
  477.       x0=d;
  478.       d=y1;
  479.       y1=y0;
  480.       y0=d;
  481.     }
  482.       if(is_valid_area(dev,x0,y0,abs(x1-x0),y1-y0))
  483.     {
  484.       SetDrMd(idev->rp,JAM1);
  485.       SetAPen(idev->rp,color);
  486.       LockLayerInfo(idev->rp->Layer->LayerInfo);
  487.       LockLayerRom(idev->rp->Layer);
  488.       Move(idev->rp,x0,y0);
  489.       Draw(idev->rp,x1-1,y1-1);
  490.       UnlockLayerRom(idev->rp->Layer);
  491.       UnlockLayerInfo(idev->rp->Layer->LayerInfo);
  492.     }
  493.     }
  494.   return 0;
  495. }
  496.  
  497. int i_copy_mono(gx_device *dev, const unsigned char *data, int data_x, \
  498.         int raster, gx_bitmap_id id, int x, int y, \
  499.         int width, int height, gx_color_index color0, \
  500.         gx_color_index color1)
  501. {
  502.   boolean draw=TRUE;
  503.   unsigned long x_words=data_x>>4;
  504.   int x_bits=data_x&0xf;
  505.   int res=0;
  506.   static gx_bitmap_id old_id=gx_no_bitmap_id;
  507.   
  508.   if(!render_active) 
  509.     start_render_state(idev->w);
  510.  
  511.   /* the drawmode and the back- and forground colors depend on
  512.      combinations of color1 color0 if they equal gx_no_color_value  */
  513.   if(is_valid_area(dev,x,y,width,height))
  514.     {
  515.       if(width>0 && height>0)
  516.     {
  517.       if(color0!=gx_no_color_index)
  518.         {
  519.           if(color1!=gx_no_color_index)
  520.         {
  521.           SetDrMd(idev->rp,JAM2);
  522.           SetAPen(idev->rp,color1);
  523.           SetBPen(idev->rp,color0);
  524.         }
  525.           else
  526.         {
  527.           SetDrMd(idev->rp,JAM1|INVERSVID);
  528.           SetAPen(idev->rp,color0);
  529.         }
  530.         }
  531.       else
  532.         {
  533.           if(color1!=gx_no_color_index)
  534.         {
  535.           SetDrMd(idev->rp,JAM1);
  536.           SetAPen(idev->rp,color1);
  537.         }
  538.           else
  539.         draw=FALSE;
  540.         }
  541.       
  542.       if(draw) 
  543.         {
  544.           /* first order optimization: 
  545.          if bitmap was already copied last
  546.          time, don't copy it again */
  547.           if(id!=old_id || id==gx_no_bitmap_id)
  548.         {
  549.           WaitBlit();
  550.           if(mono_size<RASSIZE(raster<<3,height))
  551.             {
  552.               FreeRemember(&reremkey,TRUE);
  553.               mono_size=((raster*height+15)\
  554.                  /16)*16;
  555.               monoplane=
  556.             AllocRemember(&reremkey,mono_size,\
  557.                       MEMF_CHIP|MEMF_REVERSE);
  558. #ifdef DEBUG
  559.               fprintf(stderr,"alloc size: %ld\n",\
  560.                   mono_size);
  561. #endif
  562.             }
  563.           if(monoplane!=NULL)
  564.             {
  565. /*
  566. #ifdef DEBUG
  567.               fprintf(stderr,"copy size: %ld\n",\
  568.                   RASSIZE((size_t)raster<<3,height));
  569. #endif
  570. */
  571.               CopyMem(data,monoplane,\
  572.                   (ULONG)RASSIZE((size_t)raster<<3,\
  573.                       height));
  574.               old_id=id;
  575.             }
  576.         }
  577.           if(monoplane!=NULL)
  578.         {
  579.           /* do the blit */
  580.           LockLayerInfo(idev->rp->Layer->LayerInfo);
  581.           LockLayerRom(idev->rp->Layer);
  582.           BltTemplate((UBYTE *) \
  583.                   (monoplane+(x_words<<1)), \
  584.                   x_bits,raster,idev->rp,x,y,\
  585.                   width,height);
  586.           UnlockLayerRom(idev->rp->Layer);
  587.           UnlockLayerInfo(idev->rp->Layer->LayerInfo);
  588.           /* reset the saved display id */
  589.           if(id!=gx_no_bitmap_id) old_id=id;
  590.         }
  591.           else res=-1;
  592.         }
  593.     }
  594.     }
  595.   else res=-1;
  596.   return res;
  597. }
  598.  
  599.  
  600. /*
  601. void i_get_initial_matrix(gx_device *dev, gs_matrix *m)
  602. {
  603.   
  604.   m->xy=m->yx=m->tx=0;
  605.   m->xx=idev->x_pixels_per_inch*SCALE*idev->wz_scale_x/72.0;
  606.   m->yy=-idev->y_pixels_per_inch*SCALE*idev->wz_scale_y/72.0;
  607.   m->ty=idev->height;
  608. }
  609. */
  610.  
  611. /* clgorithm for composing a graphics bitmap from a ghostscript color bitmap */
  612. int copy_converted_map(char *source, PLANEPTR dplane[], \
  613.                int raster,int height,int depth)
  614. {
  615.   unsigned long doffset=0;
  616.   char *saddress=source;
  617.   int planenr;
  618.   char sbitmask;
  619.   char dbitmask=1;
  620.   unsigned long depth_bytes=(unsigned long)(depth+7>>3);
  621.   unsigned long dbyte;
  622.   PLANEPTR *plane_pp;
  623.  
  624.   /* saddress runs through the full range of source data */
  625.   while(saddress<source+raster*height*8)
  626.     {
  627.       /* we start at graphics bitmalane zero */
  628.       plane_pp=dplane;
  629.       /* count the bytes for one graphics pixel. 
  630.      This is only valid for depths 8,16,24,32 => 2,4 not supported,
  631.      1 will be done by copy_mono */
  632.       for(dbyte=0;dbyte<depth_bytes;dbyte++)
  633.     {
  634.       /* shift the input bitmask */
  635.       for(sbitmask=1;sbitmask!=0;sbitmask<<=1)
  636.         {
  637.           /* set or not set */
  638.           if(*(saddress+dbyte)&sbitmask)
  639.         *(*plane_pp+doffset)|=dbitmask;
  640.           /* next graphics bitplane */
  641.           plane_pp++;
  642.         }
  643.     }
  644.       /* next graphics pixel */
  645.       if((dbitmask<<1)==0) doffset++;
  646.       /* calculate new source address */
  647.       saddress+=(unsigned long)depth_bytes;
  648.     }
  649.   return 0;
  650. }
  651.  
  652. /*
  653. int i_copy_color(gx_device *dev, unsigned char *data, int data_x,
  654.   int raster, gx_bitmap_id id, int x, int y, int width, int height)
  655. {
  656.   int res=0;
  657.   int conv_res=0;
  658.   static gx_bitmap_id old_cid=gx_no_bitmap_id;
  659.   int depth=idev->color_info.depth;
  660.   int i;
  661.   static size_t color_size=0;
  662.   static int max_depth=0;
  663.  
  664.   if(id!=old_cid || id==gx_no_bitmap_id)
  665.     {
  666.       color_chipmap->BytesPerRow=raster;
  667.       color_chipmap->Rows=height;
  668.       color_chipmap->Flags=0;
  669.       color_chipmap->Depth=depth;
  670.       color_chipmap->pad=0;
  671.       WaitBlit();
  672.       if(color_size<(size_t)raster*(size_t)\
  673.      height||max_depth<depth)
  674.     {
  675.       i=0;
  676.       while(color_chipmap->Planes[i]!=NULL&&i<8)
  677.         {
  678.           FreeVec(color_chipmap->Planes[i]);
  679.           color_chipmap->Planes[i++]=NULL;
  680.         }
  681.       for(i=0;i<depth,conv_res==0;i++)
  682.         {
  683.           if((color_chipmap->Planes[i]=\
  684.           AllocVec((size_t)raster*\
  685.                (size_t)height,\
  686.                MEMF_CHIP|MEMF_PUBLIC))
  687.          ==NULL)
  688.         conv_res=-1;
  689.           else
  690.         {
  691.           color_size=(size_t)raster*(size_t)height;
  692.           max_depth=depth;
  693.         }
  694.         }
  695.     }
  696.       if(conv_res==0)
  697.     {
  698.       if(copy_converted_map(data,color_chipmap->Planes,\
  699.                 raster,height,depth)!=0)
  700.         conv_res=-1;
  701.     }
  702.     }
  703.   if(conv_res==0)
  704.     {
  705.       BltBitMapRastPort(color_chipmap,data_x,0,idev->rp,x,y,width, \
  706.                  height,0xc0);
  707.       if(id!=gx_no_bitmap_id) old_cid=id;
  708.     }
  709.   else 
  710.     {
  711.       res=-1;
  712. #ifdef DEBUG
  713.       fprintf(stderr,"gs intui: copy color: copy_converted() or out "
  714.           "of copy-mem error.\n");
  715. #endif
  716.     }
  717.   return res;
  718. }
  719. */
  720.  
  721. int i_sync_output(gx_device *dev)
  722. {
  723.   struct RastPort *rp=idev->w->RPort;
  724.  
  725.   WaitBlit();
  726.   SyncSBitMap(rp->Layer);
  727.   CopySBitMap(rp->Layer);
  728.   stop_render_state(idev->w);
  729.   return 0;
  730. }
  731.  
  732. struct Window *open_my_window(gx_device *dev)
  733. {
  734.   struct Window *w=NULL;
  735.   struct TagItem *win_tags;
  736.   Object *icc_c2p_h;
  737.   Object *icc_c2p_v;
  738.   int tbs;
  739.   int rbs;
  740.   int bbs;
  741.   int lbs;
  742.   struct TagItem *pg_taglist;
  743.   struct TagItem *bg_taglist;
  744.   struct TagItem *im_taglist;
  745.   struct TagItem prop_map[]=
  746.     {
  747.       {GA_RelBottom,GA_Top},
  748.       {GA_Left,GA_RelRight},
  749.       {GA_RelWidth,GA_Width},
  750.       {GA_Height,GA_RelHeight},
  751.       {GA_BottomBorder,GA_RightBorder},
  752.       {TAG_END}
  753.     };
  754.   struct TagItem button_map[]=
  755.     {
  756.       {GA_BottomBorder,GA_RightBorder},
  757.       {TAG_END}
  758.     };
  759.   struct TagItem *tag;
  760.   struct TagItem *rkm_inittags;
  761.  
  762.   /* tags for window */
  763.   if((win_tags=AllocateTagItems(19))\
  764.      !=NULL)
  765.     {
  766.       /* set tag list for window */
  767.       win_tags[0].ti_Tag=WA_PubScreen;
  768.       win_tags[0].ti_Data=(ULONG)idev->s;
  769.       win_tags[1].ti_Tag=WA_Width;
  770.       win_tags[1].ti_Data=WIN_WIDTH;
  771.       win_tags[2].ti_Tag=WA_Height;
  772.       win_tags[2].ti_Data=WIN_HEIGHT;
  773.       win_tags[3].ti_Tag=WA_Title;
  774.       win_tags[3].ti_Data=(ULONG)"Ghostscript";
  775.       win_tags[4].ti_Tag=WA_DragBar;
  776.       win_tags[4].ti_Data=TRUE;
  777.       win_tags[5].ti_Tag=WA_DepthGadget;
  778.       win_tags[5].ti_Data=TRUE;
  779.       win_tags[6].ti_Tag=WA_GimmeZeroZero;
  780.       win_tags[6].ti_Data=TRUE;
  781.       win_tags[7].ti_Tag=TAG_IGNORE;
  782.       win_tags[7].ti_Data=TRUE;
  783.       win_tags[8].ti_Tag=WA_SizeGadget;
  784.       win_tags[8].ti_Data=TRUE;
  785.       win_tags[9].ti_Tag=WA_SizeBRight;
  786.       win_tags[9].ti_Data=TRUE;
  787.       win_tags[10].ti_Tag=WA_SizeBBottom;
  788.       win_tags[10].ti_Data=TRUE;
  789.       win_tags[11].ti_Tag=WA_SuperBitMap;
  790.       win_tags[11].ti_Data=(ULONG)idev->supermap;
  791.       win_tags[12].ti_Tag=WA_MinWidth;
  792.       win_tags[12].ti_Data=86;
  793.       win_tags[13].ti_Tag=WA_MinHeight;
  794.       win_tags[13].ti_Data=81;
  795.       win_tags[14].ti_Tag=WA_MaxWidth;
  796.       win_tags[14].ti_Data=idev->width;
  797.       win_tags[15].ti_Tag=WA_MaxHeight;
  798.       win_tags[15].ti_Data=idev->height;
  799.       win_tags[16].ti_Tag=WA_IDCMP;
  800.       win_tags[16].ti_Data=NULL;
  801.       win_tags[17].ti_Tag=TAG_IGNORE;
  802.       win_tags[18].ti_Tag=TAG_DONE;
  803.       /* open window */
  804.       if((w=OpenWindowTagList(NULL,win_tags))!=NULL)
  805.     {
  806.       /* get border dimensions */
  807.       tbs=w->BorderTop; 
  808.       rbs=w->BorderRight;
  809.       bbs=w->BorderBottom;
  810.       lbs=w->BorderLeft;
  811.       /* allocate boopsi maps */
  812.       if((id2u_map=AllocateTagItems(2))!=NULL &&\
  813.          (id2d_map=AllocateTagItems(2))!=NULL &&\
  814.          (c2p_map=AllocateTagItems(2))!=NULL &&\
  815.          (p2c_map=AllocateTagItems(2))!=NULL)
  816.         {
  817.           /* set maps */
  818.           id2u_map[0].ti_Tag=GA_ID;
  819.           id2u_map[0].ti_Data=RKMMOD_Up;
  820.           id2u_map[1].ti_Tag=TAG_DONE;
  821.           id2d_map[0].ti_Tag=GA_ID;
  822.           id2d_map[0].ti_Data=RKMMOD_Down;
  823.           id2d_map[1].ti_Tag=TAG_DONE;
  824.           c2p_map[0].ti_Tag=RKMMOD_CurrVal;
  825.           c2p_map[0].ti_Data=PGA_Top;
  826.           p2c_map[0].ti_Tag=PGA_Top;
  827.           p2c_map[0].ti_Data=RKMMOD_CurrVal;
  828.  
  829.           /* allocate tag lists */
  830.           if((pg_taglist=AllocateTagItems(14))!=NULL &&\
  831.          (bg_taglist=AllocateTagItems(10))!=NULL &&\
  832.          (im_taglist=AllocateTagItems(8))!=NULL)
  833.         {
  834.           /* init taglist for prop gadgets */
  835.           pg_taglist[0].ti_Tag=GA_ID;
  836.           pg_taglist[0].ti_Data=0;
  837.           pg_taglist[1].ti_Tag=GA_RelBottom;
  838.           pg_taglist[1].ti_Data=-bbs+2;
  839.           pg_taglist[2].ti_Tag=GA_Left;
  840.           pg_taglist[2].ti_Data=lbs;
  841.           pg_taglist[3].ti_Tag=GA_RelWidth;
  842.           pg_taglist[3].ti_Data=-lbs-rbs-2*LR_WIDTH-2;
  843.           pg_taglist[4].ti_Tag=GA_Height;
  844.           pg_taglist[4].ti_Data=bbs-3;
  845.           pg_taglist[5].ti_Tag=GA_BottomBorder;
  846.           pg_taglist[5].ti_Data=TRUE;
  847.           pg_taglist[6].ti_Tag=GA_GZZGadget;
  848.           pg_taglist[6].ti_Data=TRUE;
  849.           pg_taglist[7].ti_Tag=PGA_Freedom;
  850.           pg_taglist[7].ti_Data=FREEHORIZ;
  851.           pg_taglist[8].ti_Tag=PGA_NewLook;
  852.           pg_taglist[8].ti_Data=TRUE;
  853.           pg_taglist[9].ti_Tag=PGA_Top;
  854.           pg_taglist[9].ti_Data=0;
  855.           pg_taglist[10].ti_Tag=PGA_Total;
  856.           pg_taglist[10].ti_Data=idev->width/SCROLL_UNIT;
  857.           pg_taglist[11].ti_Tag=PGA_Visible;
  858.           pg_taglist[11].ti_Data=w->GZZWidth/SCROLL_UNIT;
  859.           pg_taglist[12].ti_Tag=GA_Previous;
  860.           pg_taglist[12].ti_Data=NULL;
  861.           pg_taglist[13].ti_Tag=TAG_DONE;
  862.  
  863.           /* init image taglist */
  864.           im_taglist[0].ti_Tag=IA_Left;
  865.           im_taglist[0].ti_Data=0;
  866.           im_taglist[1].ti_Tag=IA_Top;
  867.           im_taglist[1].ti_Data=0;
  868.           im_taglist[2].ti_Tag=IA_Width;
  869.           im_taglist[2].ti_Data=16;
  870.           im_taglist[3].ti_Tag=IA_Height;
  871.           im_taglist[3].ti_Data=10;
  872.           im_taglist[4].ti_Tag=SYSIA_Which;
  873.           im_taglist[4].ti_Data=LEFTIMAGE;
  874.           im_taglist[5].ti_Tag=SYSIA_Size;
  875.           im_taglist[5].ti_Data=SYSISIZE_MEDRES;
  876.           im_taglist[6].ti_Tag=SYSIA_DrawInfo;
  877.           im_taglist[6].ti_Data=(ULONG)idev->di;
  878.           im_taglist[7].ti_Tag=TAG_END;
  879.  
  880.           /* init button gadget taglist */
  881.           bg_taglist[0].ti_Tag=GA_ID;
  882.           bg_taglist[0].ti_Data=2;
  883.           bg_taglist[1].ti_Tag=GA_RelBottom;
  884.           bg_taglist[1].ti_Data=-bbs+1;
  885.           bg_taglist[2].ti_Tag=GA_RelRight;
  886.           bg_taglist[2].ti_Data=-rbs-2*LR_WIDTH;
  887.           bg_taglist[3].ti_Tag=GA_Width;
  888.           bg_taglist[3].ti_Data=16;
  889.           bg_taglist[4].ti_Tag=GA_Height;
  890.           bg_taglist[4].ti_Data=10;
  891.           bg_taglist[5].ti_Tag=GA_Image;
  892.           bg_taglist[5].ti_Data=NULL;
  893.           bg_taglist[6].ti_Tag=GA_GZZGadget;
  894.           bg_taglist[6].ti_Data=TRUE;
  895.           bg_taglist[7].ti_Tag=GA_BottomBorder;
  896.           bg_taglist[7].ti_Data=TRUE;
  897.           bg_taglist[8].ti_Tag=GA_Previous;
  898.           bg_taglist[8].ti_Data=NULL;
  899.           bg_taglist[9].ti_Tag=TAG_END;
  900.           
  901.           /* create images */
  902.           left_image=(struct Image *)NewObjectA(NULL,"sysiclass",im_taglist);
  903.           tag=FindTagItem(SYSIA_Which,im_taglist);tag->ti_Data=RIGHTIMAGE;
  904.           right_image=(struct Image *)NewObjectA(NULL,"sysiclass",im_taglist);
  905.           tag=FindTagItem(IA_Width,im_taglist);tag->ti_Data=18;
  906.           tag=FindTagItem(IA_Height,im_taglist);tag->ti_Data=11;
  907.           tag=FindTagItem(SYSIA_Which,im_taglist);tag->ti_Data=UPIMAGE;
  908.           up_image=(struct Image *)NewObjectA(NULL,"sysiclass",im_taglist);
  909.           tag=FindTagItem(SYSIA_Which,im_taglist);tag->ti_Data=DOWNIMAGE;
  910.           down_image=(struct Image *)NewObjectA(NULL,"sysiclass",im_taglist);
  911.           if(left_image!=NULL && right_image!=NULL && \
  912.              up_image!=NULL && down_image!=NULL)
  913.             {
  914.               /* create prop gadgets */
  915.               pg_h=(struct Gadget *)NewObjectA(NULL,"propgclass",pg_taglist);
  916.               MapTags(pg_taglist,prop_map,TRUE);
  917.               tag=FindTagItem(GA_ID,pg_taglist);tag->ti_Data=1;
  918.               tag=FindTagItem(GA_Top,pg_taglist);tag->ti_Data=tbs;
  919.               tag=FindTagItem(GA_RelRight,pg_taglist);tag->ti_Data=-rbs+4;
  920.               tag=FindTagItem(GA_Width,pg_taglist);tag->ti_Data=rbs-6;
  921.               tag=FindTagItem(GA_RelHeight,pg_taglist);tag->ti_Data=\
  922.             -tbs-bbs-2*UD_HEIGHT-1;
  923.               tag=FindTagItem(PGA_Freedom,pg_taglist);tag->ti_Data=FREEVERT;
  924.               tag=FindTagItem(GA_Previous,pg_taglist);
  925.               tag->ti_Data=(ULONG)pg_h;
  926.               tag=FindTagItem(PGA_Total,pg_taglist);
  927.               tag->ti_Data=idev->height/SCROLL_UNIT;
  928.               tag=FindTagItem(PGA_Visible,pg_taglist);
  929.               tag->ti_Data=w->GZZHeight/SCROLL_UNIT;
  930.               pg_v=(struct Gadget *)NewObjectA(NULL,"propgclass",pg_taglist);
  931.  
  932.               /* create button gadgets */
  933.               tag=FindTagItem(GA_Image,bg_taglist);
  934.               tag->ti_Data=(ULONG)left_image;
  935.               tag=FindTagItem(GA_Previous,bg_taglist);
  936.               tag->ti_Data=(ULONG)pg_v;
  937.               bg_h1=(struct Gadget *)NewObjectA(NULL,"buttongclass",\
  938.                             bg_taglist);
  939.               tag=FindTagItem(GA_ID,bg_taglist);tag->ti_Data=3;
  940.               tag=FindTagItem(GA_RelRight,bg_taglist);
  941.               tag->ti_Data=-rbs-LR_WIDTH;
  942.               tag=FindTagItem(GA_Image,bg_taglist);
  943.               tag->ti_Data=(ULONG)right_image;
  944.               tag=FindTagItem(GA_Previous,bg_taglist);
  945.               tag->ti_Data=(ULONG)bg_h1;
  946.               bg_h2=(struct Gadget *)NewObjectA(NULL,"buttongclass",\
  947.                             bg_taglist);
  948.               MapTags(bg_taglist,button_map,TRUE);
  949.               tag=FindTagItem(GA_ID,bg_taglist);tag->ti_Data=4;
  950.               tag=FindTagItem(GA_RelBottom,bg_taglist);
  951.               tag->ti_Data=-bbs-2*UD_HEIGHT+1;
  952.               tag=FindTagItem(GA_RelRight,bg_taglist);tag->ti_Data=-rbs+1;
  953.               tag=FindTagItem(GA_Image,bg_taglist);
  954.               tag->ti_Data=(ULONG)up_image;
  955.               tag=FindTagItem(GA_Previous,bg_taglist);
  956.               tag->ti_Data=(ULONG)bg_h2;
  957.               bg_v1=(struct Gadget *)NewObjectA(NULL,"buttongclass",\
  958.                             bg_taglist);
  959.               tag=FindTagItem(GA_ID,bg_taglist);tag->ti_Data=5;
  960.               tag=FindTagItem(GA_RelBottom,bg_taglist);
  961.               tag->ti_Data=-bbs-UD_HEIGHT+1;
  962.               tag=FindTagItem(GA_Image,bg_taglist);
  963.               tag->ti_Data=(ULONG)down_image;
  964.               tag=FindTagItem(GA_Previous,bg_taglist);
  965.               tag->ti_Data=(ULONG)bg_v1;
  966.               bg_v2=(struct Gadget *)NewObjectA(NULL,"buttongclass",\
  967.                             bg_taglist);
  968.               if(pg_h!=NULL && pg_v!=NULL &&\
  969.              bg_h1!=NULL && bg_h2!=NULL &&\
  970.              bg_v1!=NULL && bg_v2!=NULL)
  971.             {
  972.               /* add Gadgets to Window and refresh them */
  973.               AddGList(w,pg_h,-1,6,NULL);
  974.               RefreshGadgets(pg_h,w,NULL);
  975.  
  976.               /* create rkm model class */
  977.               if((rkm_inittags=AllocateTagItems(5))!=NULL && \
  978.                  (rkm=initRKMModClass())!=NULL)
  979.                 {
  980.                   /* set rkm init tags */
  981.                   rkm_inittags[0].ti_Tag=RKMMOD_CurrVal;
  982.                   rkm_inittags[0].ti_Data=0;
  983.                   rkm_inittags[1].ti_Tag=RKMMOD_Limit;
  984.                   rkm_inittags[1].ti_Data=\
  985.                 (idev->width-w->GZZWidth)/SCROLL_UNIT;
  986.                   rkm_inittags[2].ti_Tag=RKMMOD_Id;
  987.                   rkm_inittags[2].ti_Data=0;
  988.                   rkm_inittags[3].ti_Tag=ICA_TARGET;
  989.                   rkm_inittags[3].ti_Data=ICTARGET_IDCMP;
  990.                   rkm_inittags[4].ti_Tag=TAG_END;
  991.                   /* create two rkm models and two icc objects */
  992.                   my_rkm_model1=NewObjectA(rkm,NULL,rkm_inittags);
  993.                   tag=FindTagItem(RKMMOD_Id,rkm_inittags);tag->ti_Data=1;
  994.                   tag=FindTagItem(RKMMOD_Limit,rkm_inittags);
  995.                   tag->ti_Data=(idev->height-w->GZZHeight)\
  996.                 /SCROLL_UNIT;
  997.                   my_rkm_model2=NewObjectA(rkm,NULL,rkm_inittags);
  998.                   icc_c2p_h=NewObjectA(NULL,"icclass",NULL);
  999.                   icc_c2p_v=NewObjectA(NULL,"icclass",NULL);
  1000.                   if(my_rkm_model1!=NULL && my_rkm_model2!=NULL && \
  1001.                  icc_c2p_h!=NULL && icc_c2p_v!=NULL)
  1002.                 {
  1003.                   /* do boopsi-connection */
  1004.                   /* horizontal gadgets */
  1005.                   SetGadgetAttrs(pg_h,w,NULL,\
  1006.                          ICA_TARGET,my_rkm_model1,\
  1007.                          ICA_MAP,p2c_map);
  1008.                   SetGadgetAttrs(bg_h1,w,NULL,\
  1009.                          ICA_TARGET,my_rkm_model1,\
  1010.                          ICA_MAP,id2d_map);
  1011.                   SetGadgetAttrs(bg_h2,w,NULL,\
  1012.                          ICA_TARGET,my_rkm_model1,\
  1013.                          ICA_MAP,id2u_map);
  1014.                   DoMethod(my_rkm_model1,OM_ADDMEMBER,icc_c2p_h);
  1015.                   SetAttrs(icc_c2p_h,\
  1016.                        ICA_TARGET,pg_h,\
  1017.                        ICA_MAP,c2p_map);
  1018.                   
  1019.                   /* vertical gadgets */
  1020.                   SetGadgetAttrs(pg_v,w,NULL,\
  1021.                          ICA_TARGET,my_rkm_model2,\
  1022.                          ICA_MAP,p2c_map);
  1023.                   SetGadgetAttrs(bg_v1,w,NULL,\
  1024.                          ICA_TARGET,my_rkm_model2,\
  1025.                          ICA_MAP,id2d_map);
  1026.                   SetGadgetAttrs(bg_v2,w,NULL,\
  1027.                          ICA_TARGET,my_rkm_model2,\
  1028.                          ICA_MAP,id2u_map);
  1029.                   DoMethod(my_rkm_model2,OM_ADDMEMBER,icc_c2p_v);
  1030.                   SetAttrs(icc_c2p_v,\
  1031.                        ICA_TARGET,pg_v,\
  1032.                        ICA_MAP,c2p_map);
  1033.                   
  1034.                 }
  1035.                   else 
  1036.                 {
  1037.                   clean_win(&w);
  1038. #ifdef DEBUG
  1039.                   fprintf(stderr,"gs intui-open_my_window(): "
  1040.                       "can't create rkm model or ic class\n");
  1041. #endif
  1042.                 }
  1043.                   
  1044.                   FreeTagItems(rkm_inittags);
  1045.                 }
  1046.               else 
  1047.                 {
  1048.                   clean_win(&w);
  1049. #ifdef DEBUG
  1050.                   fprintf(stderr,"gs intui-open_my_window(): "
  1051.                       "can't create rkm model class or allocate "
  1052.                       "init tags for rkm model\n");
  1053. #endif
  1054.                 }
  1055.             }
  1056.               else 
  1057.             {
  1058.               clean_win(&w);
  1059. #ifdef DEBUG
  1060.               fprintf(stderr,"gs intui-open_my_window(): "
  1061.                   "can't create gadget; pg_h: %lx; "
  1062.                   "pg_v: %lx; bg_h1: %lx; bg_h2: %lx;"
  1063.                   "bg_v1: %lx;M bg_v2: %lx\n",pg_h,\
  1064.                   pg_v,bg_h1,bg_h2,bg_v1,bg_v2);
  1065. #endif
  1066.             }
  1067.             }
  1068.           else 
  1069.             {
  1070.               clean_win(&w);
  1071. #ifdef DEBUG
  1072.               fprintf(stderr,"gs intui-open_my_window(): can't "
  1073.                   "create image\n");
  1074. #endif
  1075.             }
  1076.  
  1077.           FreeTagItems(pg_taglist);
  1078.           FreeTagItems(bg_taglist);
  1079.           FreeTagItems(im_taglist);
  1080.         }
  1081.           else 
  1082.         {
  1083.           clean_win(&w);
  1084. #ifdef DEBUG
  1085.           fprintf(stderr,"gs intui-open_my_window(): "
  1086.               "can't allocate taglist for images or gadgets\n");
  1087. #endif
  1088.         }
  1089.         }
  1090.       else 
  1091.         {
  1092.           clean_win(&w);
  1093. #ifdef DEBUG
  1094.           fprintf(stderr,"gs intui-open_my_window(): "
  1095.               "can't allocate taglist for mapping\n");
  1096. #endif
  1097.         }
  1098.     }
  1099. #ifdef DEBUG
  1100.       else
  1101.     fprintf(stderr,"gs intui-open_my_window(): can't open window\n");
  1102. #endif    
  1103.       FreeTagItems(win_tags);
  1104.     }
  1105. #ifdef DEBUG
  1106.   else
  1107.     fprintf(stderr,"gs intui-open_my_window(): can't allocate tag list"
  1108.         "for window\n");
  1109.   fprintf(stderr,"window: %lx\n",w);
  1110. #endif
  1111.   return w;
  1112. }
  1113.  
  1114. void clean_win(struct Window **wp)
  1115. {
  1116.   CloseWindow(*wp);
  1117.   *wp=NULL;
  1118. }  
  1119.  
  1120. void close_my_window(struct Window *w)
  1121. {
  1122.   /* dispose models */
  1123.   DisposeObject(my_rkm_model1);
  1124.   DisposeObject(my_rkm_model2);
  1125.   /* free private rkm model class */
  1126.   freeRKMModClass(rkm);
  1127.   /* remove Gadgets from Window */
  1128.   RemoveGList(w,pg_h,6);
  1129.   DisposeObject(pg_h);
  1130.   DisposeObject(pg_v);
  1131.   DisposeObject(bg_h1);
  1132.   DisposeObject(bg_h2);
  1133.   DisposeObject(bg_v1);
  1134.   DisposeObject(bg_v2);
  1135.   DisposeObject(left_image);
  1136.   DisposeObject(right_image);
  1137.   DisposeObject(up_image);
  1138.   DisposeObject(down_image);
  1139.   FreeTagItems(id2u_map);
  1140.   FreeTagItems(id2d_map);
  1141.   FreeTagItems(c2p_map);
  1142.   FreeTagItems(p2c_map);
  1143.   CloseWindow(w);
  1144. }
  1145.  
  1146. void disable_gadgets(struct Window *w)
  1147. {
  1148.   struct Gadget *actual_gadget=w->FirstGadget;
  1149.   struct Gadget *NextGadget_gadget=actual_gadget->NextGadget;
  1150.   while(actual_gadget!=NULL)
  1151.     {
  1152.       OffGadget(actual_gadget,w,NULL);
  1153.       actual_gadget=NextGadget_gadget;
  1154.       NextGadget_gadget=actual_gadget->NextGadget;
  1155.     }
  1156. }
  1157.  
  1158. void enable_gadgets(struct Window *w)
  1159. {
  1160.   struct Gadget *actual_gadget=w->FirstGadget;
  1161.   struct Gadget *NextGadget_gadget=actual_gadget->NextGadget;
  1162.   while(actual_gadget!=NULL)
  1163.     {
  1164.       OnGadget(actual_gadget,w,NULL);
  1165.       actual_gadget=NextGadget_gadget;
  1166.       NextGadget_gadget=actual_gadget->NextGadget;
  1167.     }
  1168. }
  1169.  
  1170. void start_render_state(struct Window *w)
  1171. {
  1172.   SetWindowTitles(w,"Ghostscript rendering bitmap, please wait ...",(UBYTE *)-1);
  1173.   disable_gadgets(w);
  1174.   render_active=TRUE;
  1175. }
  1176.  
  1177. void stop_render_state(struct Window *w)
  1178. {
  1179.   SetWindowTitles(w,"Ghostscript",(UBYTE *)-1);
  1180.   enable_gadgets(w);
  1181.   render_active=FALSE;
  1182. }
  1183.