changeset 739:2e5e2ccbeed2

[xemacs-hg @ 2002-02-02 13:42:53 by wmperry] Fix XPM transparency in GTK, mostly.
author wmperry
date Sat, 02 Feb 2002 13:42:54 +0000
parents 5039859429c5
children 68d3b87a6754
files src/ChangeLog src/glyphs-gtk.c
diffstat 2 files changed, 94 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat Feb 02 13:39:59 2002 +0000
+++ b/src/ChangeLog	Sat Feb 02 13:42:54 2002 +0000
@@ -1,3 +1,10 @@
+2002-02-02  William M. Perry  <wmperry@gnu.org>
+
+	* glyphs-gtk.c (extract_xpm_color_names): Resurrect the xpm color
+	symbols stuff because the GTK XPM libraries do very weird things
+	if you don't specify the transparency at all.  Reverting the patch
+	of 12/22/01.
+
 2002-01-26  Stephen J. Turnbull  <stephen@xemacs.org>
 
 	* ChangeLog (2001-09-19 Ben Wing): Entry dosed with Dramamine.
--- a/src/glyphs-gtk.c	Sat Feb 02 13:39:59 2002 +0000
+++ b/src/glyphs-gtk.c	Sat Feb 02 13:42:54 2002 +0000
@@ -1083,7 +1083,6 @@
 /**********************************************************************
  *                             XPM                                    *
  **********************************************************************/
-
 static void
 write_lisp_string_to_temp_file (Lisp_Object string, char *filename_out)
 {
@@ -1183,9 +1182,77 @@
     report_file_error ("Writing temp file", build_string (filename_out));
 }
 
+struct color_symbol
+{
+  char*		name;
+  GdkColor	color;
+};
+
+static struct color_symbol*
+extract_xpm_color_names (Lisp_Object device,
+			 Lisp_Object domain,
+			 Lisp_Object color_symbol_alist,
+			 int* nsymbols)
+{
+  /* This function can GC */
+  Lisp_Object rest;
+  Lisp_Object results = Qnil;
+  int i, j;
+  struct color_symbol *colortbl;
+  struct gcpro gcpro1, gcpro2;
+
+  GCPRO2 (results, device);
+
+  /* We built up results to be (("name" . #<color>) ...) so that if an
+     error happens we don't lose any malloc()ed data, or more importantly,
+     leave any pixels allocated in the server. */
+  i = 0;
+  LIST_LOOP (rest, color_symbol_alist)
+    {
+      Lisp_Object cons = XCAR (rest);
+      Lisp_Object name = XCAR (cons);
+      Lisp_Object value = XCDR (cons);
+      if (NILP (value))
+	continue;
+      if (STRINGP (value))
+	value =
+	  Fmake_color_instance
+	  (value, device, encode_error_behavior_flag (ERROR_ME_NOT));
+      else
+        {
+          assert (COLOR_SPECIFIERP (value));
+          value = Fspecifier_instance (value, domain, Qnil, Qnil);
+        }
+
+      if (NILP (value))
+        continue;
+      results = noseeum_cons (noseeum_cons (name, value), results);
+      i++;
+    }
+  UNGCPRO;			/* no more evaluation */
+
+  *nsymbols=i;
+  if (i == 0) return 0;
+
+  colortbl = xnew_array_and_zero (struct color_symbol, i);
+
+  for (j=0; j<i; j++)
+    {
+      Lisp_Object cons = XCAR (results);
+      colortbl[j].color = 
+	* COLOR_INSTANCE_GTK_COLOR (XCOLOR_INSTANCE (XCDR (cons)));
+
+      colortbl[j].name = (char *) XSTRING_DATA (XCAR (cons));
+      free_cons (XCONS (cons));
+      cons = results;
+      results = XCDR (results);
+      free_cons (XCONS (cons));
+    }
+  return colortbl;
+}
+
 static void
-gtk_xpm_instantiate (Lisp_Object image_instance,
-		     Lisp_Object instantiator,
+gtk_xpm_instantiate (Lisp_Object image_instance, Lisp_Object instantiator,
 		     Lisp_Object pointer_fg, Lisp_Object pointer_bg,
 		     int dest_mask, Lisp_Object domain)
 {
@@ -1200,7 +1267,9 @@
   GdkPixmap *pixmap;
   GdkPixmap *mask = 0;
   GdkWindow *window = 0;
-  int i = 0;
+  int nsymbols = 0, i = 0;
+  struct color_symbol *color_symbols = NULL;
+  GdkColor *transparent_color = NULL;
   Lisp_Object color_symbol_alist = find_keyword_in_vector (instantiator,
 							   Q_color_symbols);
   enum image_instance_type type;
@@ -1231,10 +1300,23 @@
 
   assert (!NILP (data));
 
+  /* Need to get the transparent color here */
+  color_symbols = extract_xpm_color_names (device, domain, color_symbol_alist, &nsymbols);
+  for (i = 0; i < nsymbols; i++)
+    {
+      if (!strcasecmp ("BgColor", color_symbols[i].name) ||
+	  !strcasecmp ("None", color_symbols[i].name))
+	{
+	  transparent_color = &color_symbols[i].color;
+	}
+    }
+
   write_lisp_string_to_temp_file (data, temp_file_name);
-  pixmap = gdk_pixmap_create_from_xpm (window, &mask, NULL, temp_file_name);
+  pixmap = gdk_pixmap_create_from_xpm (window, &mask, transparent_color, temp_file_name);
   unlink (temp_file_name);
 
+  if (color_symbols) xfree (color_symbols);
+
   if (!pixmap)
   {
     signal_image_error ("Error reading pixmap", data);
@@ -1301,7 +1383,6 @@
       abort ();
     }
 }
-
 #endif /* HAVE_XPM */