changeset 64424:feba2f2d875e

(x_bitmap_icon, x_make_frame_visible): Remove declarations. (XSetFont): Add declaration. (mac_set_forecolor, mac_set_backcolor, mac_set_colors): Remove functions. (GC_FORE_COLOR, GC_BACK_COLOR, GC_FONT, MAC_WINDOW_NORMAL_GC): New defines. (XDrawLine, mac_draw_line_to_pixmap, XClearWindow) (mac_draw_bitmap, XCreatePixmapFromBitmapData, XFillRectangle) (mac_draw_rectangle, mac_draw_string_common, mac_scroll_area): Use them. (mac_erase_rectangle): New function. (XClearArea, x_draw_fringe_bitmap, x_clear_glyph_string_rect) (x_draw_stretch_glyph_string): Use it. (XChangeGC, XCreateGC, XGetGCValues, XSetForeground) (XSetBackground, XSetFont): Adjust for new GC implementation. (x_draw_fringe_bitmap, x_draw_box_rect): Use GC to set colors. (XTset_vertical_scroll_bar): Clear area under scroll bar.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Mon, 18 Jul 2005 05:40:30 +0000
parents 94a250aa72e0
children fd8d1b7269d6
files src/macterm.c
diffstat 1 files changed, 145 insertions(+), 173 deletions(-) [+]
line wrap: on
line diff
--- a/src/macterm.c	Mon Jul 18 05:39:27 2005 +0000
+++ b/src/macterm.c	Mon Jul 18 05:40:30 2005 +0000
@@ -259,14 +259,19 @@
 					    Lisp_Object *, Lisp_Object *,
 					    unsigned long *));
 
-static int is_emacs_window (WindowPtr);
-
-int x_bitmap_icon (struct frame *, Lisp_Object);
-void x_make_frame_visible (struct frame *);
+static int is_emacs_window P_ ((WindowPtr));
+
+static void XSetFont P_ ((Display *, GC, XFontStruct *));
 
 /* Defined in macmenu.h.  */
 extern void menubar_selection_callback (FRAME_PTR, int);
 
+#define GC_FORE_COLOR(gc)	(&(gc)->fore_color)
+#define GC_BACK_COLOR(gc)	(&(gc)->back_color)
+#define GC_FONT(gc)		((gc)->xgcv.font)
+#define MAC_WINDOW_NORMAL_GC(w)	(((mac_output *) GetWRefCon (w))->normal_gc)
+
+
 /* X display function emulation */
 
 void
@@ -278,51 +283,6 @@
 }
 
 
-/* Set foreground color for subsequent QuickDraw commands.  Assume
-   graphic port has already been set.  */
-
-static void
-mac_set_forecolor (unsigned long color)
-{
-  RGBColor fg_color;
-
-  fg_color.red = RED16_FROM_ULONG (color);
-  fg_color.green = GREEN16_FROM_ULONG (color);
-  fg_color.blue = BLUE16_FROM_ULONG (color);
-
-  RGBForeColor (&fg_color);
-}
-
-
-/* Set background color for subsequent QuickDraw commands.  Assume
-   graphic port has already been set.  */
-
-static void
-mac_set_backcolor (unsigned long color)
-{
-  RGBColor bg_color;
-
-  bg_color.red = RED16_FROM_ULONG (color);
-  bg_color.green = GREEN16_FROM_ULONG (color);
-  bg_color.blue = BLUE16_FROM_ULONG (color);
-
-  RGBBackColor (&bg_color);
-}
-
-/* Set foreground and background color for subsequent QuickDraw
-   commands.  Assume that the graphic port has already been set.  */
-
-static void
-mac_set_colors (gc, bg_save)
-     GC gc;
-     RGBColor *bg_save;
-{
-  if (bg_save)
-    GetBackColor (bg_save);
-  mac_set_forecolor (gc->foreground);
-  mac_set_backcolor (gc->background);
-}
-
 /* Mac version of XDrawLine.  */
 
 static void
@@ -332,16 +292,12 @@
      GC gc;
      int x1, y1, x2, y2;
 {
-  RGBColor old_bg;
-
   SetPortWindowPort (w);
 
-  mac_set_colors (gc, &old_bg);
+  RGBForeColor (GC_FORE_COLOR (gc));
 
   MoveTo (x1, y1);
   LineTo (x2, y2);
-
-  RGBBackColor (&old_bg);
 }
 
 void
@@ -357,7 +313,7 @@
   GetGWorld (&old_port, &old_gdh);
   SetGWorld (p, NULL);
 
-  mac_set_colors (gc, NULL);
+  RGBForeColor (GC_FORE_COLOR (gc));
 
   LockPixels (GetGWorldPixMap (p));
   MoveTo (x1, y1);
@@ -367,6 +323,27 @@
   SetGWorld (old_port, old_gdh);
 }
 
+
+static void
+mac_erase_rectangle (w, gc, x, y, width, height)
+     WindowPtr w;
+     GC gc;
+     int x, y;
+     unsigned int width, height;
+{
+  Rect r;
+
+  SetPortWindowPort (w);
+
+  RGBBackColor (GC_BACK_COLOR (gc));
+  SetRect (&r, x, y, x + width, y + height);
+
+  EraseRect (&r);
+
+  RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w)));
+}
+
+
 /* Mac version of XClearArea.  */
 
 void
@@ -377,22 +354,7 @@
      unsigned int width, height;
      int exposures;
 {
-  struct mac_output *mwp = (mac_output *) GetWRefCon (w);
-  Rect r;
-  XGCValues xgc;
-  RGBColor old_bg;
-
-  xgc.foreground = mwp->x_compatible.foreground_pixel;
-  xgc.background = mwp->x_compatible.background_pixel;
-
-  SetPortWindowPort (w);
-
-  mac_set_colors (&xgc, &old_bg);
-  SetRect (&r, x, y, x + width, y + height);
-
-  EraseRect (&r);
-
-  RGBBackColor (&old_bg);
+  mac_erase_rectangle (w, MAC_WINDOW_NORMAL_GC (w), x, y, width, height);
 }
 
 /* Mac version of XClearWindow.  */
@@ -402,15 +364,9 @@
      Display *display;
      WindowPtr w;
 {
-  struct mac_output *mwp = (mac_output *) GetWRefCon (w);
-  XGCValues xgc;
-
-  xgc.foreground = mwp->x_compatible.foreground_pixel;
-  xgc.background = mwp->x_compatible.background_pixel;
-
   SetPortWindowPort (w);
 
-  mac_set_colors (&xgc, NULL);
+  RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w)));
 
 #if TARGET_API_MAC_CARBON
   {
@@ -438,7 +394,6 @@
 {
   BitMap bitmap;
   Rect r;
-  RGBColor old_bg;
 
   bitmap.rowBytes = sizeof(unsigned short);
   bitmap.baseAddr = (char *)bits;
@@ -446,7 +401,8 @@
 
   SetPortWindowPort (w);
 
-  mac_set_colors (gc, &old_bg);
+  RGBForeColor (GC_FORE_COLOR (gc));
+  RGBBackColor (GC_BACK_COLOR (gc));
   SetRect (&r, x, y, x + width, y + height);
 
 #if TARGET_API_MAC_CARBON
@@ -459,7 +415,7 @@
 	    overlay_p ? srcOr : srcCopy, 0);
 #endif /* not TARGET_API_MAC_CARBON */
 
-  RGBBackColor (&old_bg);
+  RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w)));
 }
 
 
@@ -565,12 +521,16 @@
      char *data;
      unsigned int width, height;
      unsigned long fg, bg;
-     unsigned int depth;	/* not used */
+     unsigned int depth;
 {
   Pixmap pixmap;
   BitMap bitmap;
   CGrafPtr old_port;
   GDHandle old_gdh;
+  static GC gc = NULL;		/* not reentrant */
+
+  if (gc == NULL)
+    gc = XCreateGC (display, w, 0, NULL);
 
   pixmap = XCreatePixmap (display, w, width, height, depth);
   if (pixmap == NULL)
@@ -579,8 +539,10 @@
   GetGWorld (&old_port, &old_gdh);
   SetGWorld (pixmap, NULL);
   mac_create_bitmap_from_bitmap_data (&bitmap, data, width, height);
-  mac_set_forecolor (fg);
-  mac_set_backcolor (bg);
+  XSetForeground (display, gc, fg);
+  XSetBackground (display, gc, bg);
+  RGBForeColor (GC_FORE_COLOR (gc));
+  RGBBackColor (GC_BACK_COLOR (gc));
   LockPixels (GetGWorldPixMap (pixmap));
 #if TARGET_API_MAC_CARBON
   CopyBits (&bitmap, GetPortBitMapForCopyBits (pixmap),
@@ -608,16 +570,13 @@
      unsigned int width, height;
 {
   Rect r;
-  RGBColor old_bg;
 
   SetPortWindowPort (w);
 
-  mac_set_colors (gc, &old_bg);
+  RGBForeColor (GC_FORE_COLOR (gc));
   SetRect (&r, x, y, x + width, y + height);
 
   PaintRect (&r); /* using foreground color of gc */
-
-  RGBBackColor (&old_bg);
 }
 
 
@@ -636,7 +595,7 @@
 
   GetGWorld (&old_port, &old_gdh);
   SetGWorld (p, NULL);
-  mac_set_colors (gc, NULL);
+  RGBForeColor (GC_FORE_COLOR (gc));
   SetRect (&r, x, y, x + width, y + height);
 
   LockPixels (GetGWorldPixMap (p));
@@ -659,16 +618,13 @@
      unsigned int width, height;
 {
   Rect r;
-  RGBColor old_bg;
 
   SetPortWindowPort (w);
 
-  mac_set_colors (gc, &old_bg);
+  RGBForeColor (GC_FORE_COLOR (gc));
   SetRect (&r, x, y, x + width + 1, y + height + 1);
 
   FrameRect (&r); /* using foreground color of gc */
-
-  RGBBackColor (&old_bg);
 }
 
 
@@ -689,7 +645,7 @@
 
   GetGWorld (&old_port, &old_gdh);
   SetGWorld (p, NULL);
-  mac_set_colors (gc, NULL);
+  RGBForeColor (GC_FORE_COLOR (gc));
   SetRect (&r, x, y, x + width + 1, y + height + 1);
 
   LockPixels (GetGWorldPixMap (p));
@@ -711,9 +667,6 @@
      char *buf;
      int nchars, mode, bytes_per_char;
 {
-  RGBColor old_bg;
-
-  SetPortWindowPort (w);
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
   UInt32 textFlags, savedFlags;
   if (!NILP(Vmac_use_core_graphics)) {
@@ -722,17 +675,22 @@
   }
 #endif
 
-  mac_set_colors (gc, &old_bg);
-
-  TextFont (gc->font->mac_fontnum);
-  TextSize (gc->font->mac_fontsize);
-  TextFace (gc->font->mac_fontface);
+  SetPortWindowPort (w);
+
+  RGBForeColor (GC_FORE_COLOR (gc));
+  if (mode != srcOr)
+    RGBBackColor (GC_BACK_COLOR (gc));
+
+  TextFont (GC_FONT (gc)->mac_fontnum);
+  TextSize (GC_FONT (gc)->mac_fontsize);
+  TextFace (GC_FONT (gc)->mac_fontface);
   TextMode (mode);
 
   MoveTo (x, y);
   DrawText (buf, 0, nchars * bytes_per_char);
 
-  RGBBackColor (&old_bg);
+  if (mode != srcOr)
+    RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w)));
 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1020
   if (!NILP(Vmac_use_core_graphics))
     SwapQDTextFlags(savedFlags);
@@ -911,7 +869,7 @@
   BackColor (whiteColor);
   CopyBits (&(w->portBits), &(w->portBits), &src_r, &dest_r, srcCopy, 0);
 
-  mac_set_colors (gc, NULL);
+  RGBBackColor (GC_BACK_COLOR (MAC_WINDOW_NORMAL_GC (w)));
 #endif /* not TARGET_API_MAC_CARBON */
 }
 
@@ -1001,28 +959,37 @@
 /* Mac replacement for XChangeGC.  */
 
 static void
-XChangeGC (void * ignore, XGCValues* gc, unsigned long mask,
-                XGCValues *xgcv)
+XChangeGC (display, gc, mask, xgcv)
+     Display *display;
+     GC gc;
+     unsigned long mask;
+     XGCValues *xgcv;
 {
   if (mask & GCForeground)
-    gc->foreground = xgcv->foreground;
+    XSetForeground (display, gc, xgcv->foreground);
   if (mask & GCBackground)
-    gc->background = xgcv->background;
+    XSetBackground (display, gc, xgcv->background);
   if (mask & GCFont)
-    gc->font = xgcv->font;
+    XSetFont (display, gc, xgcv->font);
 }
 
 
 /* Mac replacement for XCreateGC.  */
 
-XGCValues *
-XCreateGC (void * ignore, Window window, unsigned long mask,
-                      XGCValues *xgcv)
-{
-  XGCValues *gc = (XGCValues *) xmalloc (sizeof (XGCValues));
-  bzero (gc, sizeof (XGCValues));
-
-  XChangeGC (ignore, gc, mask, xgcv);
+GC
+XCreateGC (display, window, mask, xgcv)
+     Display *display;
+     Window window;
+     unsigned long mask;
+     XGCValues *xgcv;
+{
+  GC gc = xmalloc (sizeof (*gc));
+
+  if (gc)
+    {
+      bzero (gc, sizeof (*gc));
+      XChangeGC (display, gc, mask, xgcv);
+    }
 
   return gc;
 }
@@ -1042,10 +1009,18 @@
 /* Mac replacement for XGetGCValues.  */
 
 static void
-XGetGCValues (void* ignore, XGCValues *gc,
-                   unsigned long mask, XGCValues *xgcv)
-{
-  XChangeGC (ignore, xgcv, mask, gc);
+XGetGCValues (display, gc, mask, xgcv)
+     Display *display;
+     GC gc;
+     unsigned long mask;
+     XGCValues *xgcv;
+{
+  if (mask & GCForeground)
+    xgcv->foreground = gc->xgcv.foreground;
+  if (mask & GCBackground)
+    xgcv->background = gc->xgcv.background;
+  if (mask & GCFont)
+    xgcv->font = gc->xgcv.font;
 }
 
 
@@ -1057,7 +1032,13 @@
      GC gc;
      unsigned long color;
 {
-  gc->foreground = color;
+  if (gc->xgcv.foreground != color)
+    {
+      gc->xgcv.foreground = color;
+      gc->fore_color.red = RED16_FROM_ULONG (color);
+      gc->fore_color.green = GREEN16_FROM_ULONG (color);
+      gc->fore_color.blue = BLUE16_FROM_ULONG (color);
+    }
 }
 
 
@@ -1069,7 +1050,25 @@
      GC gc;
      unsigned long color;
 {
-  gc->background = color;
+  if (gc->xgcv.background != color)
+    {
+      gc->xgcv.background = color;
+      gc->back_color.red = RED16_FROM_ULONG (color);
+      gc->back_color.green = GREEN16_FROM_ULONG (color);
+      gc->back_color.blue = BLUE16_FROM_ULONG (color);
+    }
+}
+
+
+/* Mac replacement for XSetFont.  */
+
+static void
+XSetFont (display, gc, font)
+     Display *display;
+     GC gc;
+     XFontStruct *font;
+{
+  gc->xgcv.font = font;
 }
 
 
@@ -1116,19 +1115,6 @@
 #endif
 }
 
-
-/* Mac replacement for XSetFont.  */
-
-static void
-XSetFont (display, gc, font)
-     Display *display;
-     GC gc;
-     XFontStruct *font;
-{
-  gc->font = font;
-}
-
-
 /* x_sync is a no-op on Mac.  */
 void
 x_sync (f)
@@ -1439,7 +1425,6 @@
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   Display *display = FRAME_MAC_DISPLAY (f);
   WindowPtr window = FRAME_MAC_WINDOW (f);
-  XGCValues gcv;
   GC gc = f->output_data.mac->normal_gc;
   struct face *face = p->face;
   int rowY;
@@ -1463,9 +1448,6 @@
 
   if (p->bx >= 0 && !p->overlay_p)
     {
-      XGCValues gcv;
-      gcv.foreground = face->background;
-
 #if 0  /* MAC_TODO: stipple */
       /* In case the same realized face is used for fringes and
 	 for something displayed in the text (e.g. face `region' on
@@ -1477,9 +1459,7 @@
 	XSetForeground (FRAME_X_DISPLAY (f), face->gc, face->background);
 #endif
 
-      XFillRectangle (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f),
-		      &gcv,
-		      p->bx, p->by, p->nx, p->ny);
+      mac_erase_rectangle (window, face->gc, p->bx, p->by, p->nx, p->ny);
 
 #if 0  /* MAC_TODO: stipple */
       if (!face->stipple)
@@ -1490,15 +1470,17 @@
   if (p->which)
     {
       unsigned short *bits = p->bits + p->dh;
-
-      gcv.foreground = (p->cursor_p
-			? (p->overlay_p ? face->background
-			   : f->output_data.mac->cursor_pixel)
-			: face->foreground);
-      gcv.background = face->background;
-
-      mac_draw_bitmap (display, window, &gcv, p->x, p->y,
+      XGCValues gcv;
+
+      XGetGCValues (display, face->gc, GCForeground, &gcv);
+      XSetForeground (display, face->gc,
+		      (p->cursor_p
+		       ? (p->overlay_p ? face->background
+			  : f->output_data.mac->cursor_pixel)
+		       : face->foreground));
+      mac_draw_bitmap (display, window, face->gc, p->x, p->y,
 		       p->wd, p->h, bits, p->overlay_p);
+      XSetForeground (display, face->gc, gcv.foreground);
     }
 
   mac_reset_clipping (display, window);
@@ -1973,10 +1955,7 @@
      struct glyph_string *s;
      int x, y, w, h;
 {
-  XGCValues xgcv;
-
-  xgcv.foreground = s->gc->background;
-  XFillRectangle (s->display, s->window, &xgcv, x, y, w, h);
+  mac_erase_rectangle (s->window, s->gc, x, y, w, h);
 }
 
 
@@ -2564,27 +2543,29 @@
 {
   XGCValues xgcv;
 
-  xgcv.foreground = s->face->box_color;
+  XGetGCValues (s->display, s->gc, GCForeground, &xgcv);
+  XSetForeground (s->display, s->gc, s->face->box_color);
   mac_set_clip_rectangle (s->display, s->window, clip_rect);
 
   /* Top.  */
-  XFillRectangle (s->display, s->window, &xgcv,
+  XFillRectangle (s->display, s->window, s->gc,
 		  left_x, top_y, right_x - left_x + 1, width);
 
   /* Left.  */
   if (left_p)
-    XFillRectangle (s->display, s->window, &xgcv,
+    XFillRectangle (s->display, s->window, s->gc,
 		    left_x, top_y, width, bottom_y - top_y + 1);
 
   /* Bottom.  */
-  XFillRectangle (s->display, s->window, &xgcv,
+  XFillRectangle (s->display, s->window, s->gc,
 		  left_x, bottom_y - width + 1, right_x - left_x + 1, width);
 
   /* Right.  */
   if (right_p)
-    XFillRectangle (s->display, s->window, &xgcv,
+    XFillRectangle (s->display, s->window, s->gc,
 		    right_x - width + 1, top_y, width, bottom_y - top_y + 1);
 
+  XSetForeground (s->display, s->gc, xgcv.foreground);
   mac_reset_clipping (s->display, s->window);
 }
 
@@ -3003,13 +2984,7 @@
 	    }
 	  else
 #endif /* MAC_TODO */
-	    {
-	      XGCValues xgcv;
-	      XGetGCValues (s->display, gc, GCForeground | GCBackground, &xgcv);
-	      XSetForeground (s->display, gc, xgcv.background);
-	      XFillRectangle (s->display, s->window, gc, x, y, w, h);
-	      XSetForeground (s->display, gc, xgcv.foreground);
-	    }
+	    mac_erase_rectangle (s->window, gc, x, y, w, h);
 
 	  mac_reset_clipping (s->display, s->window);
 	}
@@ -4560,13 +4535,10 @@
 	    && XINT (bar->width) == sb_width
 	    && XINT (bar->height) == height))
 	{
-	  /* Clear areas not covered by the scroll bar because it's not as
-	     wide as the area reserved for it .  This makes sure a
-	     previous mode line display is cleared after C-x 2 C-x 1, for
-	     example.  */
-	  int area_width = WINDOW_SCROLL_BAR_AREA_WIDTH (w);
+	  /* Since toolkit scroll bars are smaller than the space reserved
+	     for them on the frame, we have to clear "under" them.  */
 	  XClearArea (FRAME_MAC_DISPLAY (f), FRAME_MAC_WINDOW (f),
-		      left, top, area_width, height, 0);
+		      left, top, width, height, 0);
 
 #if 0
           if (sb_left + sb_width >= FRAME_PIXEL_WIDTH (f))