[Nautilus-list] eel_gdk_color_parse () compatibility function



This patch adds a compatibility function for gdk_color_parse () to eel
and makes nautilus use it in a few places.  It is needed because the
depreciated rgb: color format has been stored in xml files all over the
place...

Things I didn't fix:

I wasn't sure if nautilus_property_browser_drag_data_get () would run
into the old rgb: format so I added an if statement to check.  I will
follow up on this once the drag and drop code for colors works again.

Also, I didn't change one instance of gdk_color_parse () related to
themes.  My assumption is that by not adding compatibility code here,
maybe theme creators will update their themes sooner so that we can
evidentially get rid of this code all together.  Besides there aren't
*that* many nautilus themes at this point anyway....  If anyone objects
to this, let me know.
Index: eel/eel-gdk-extensions.c
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gdk-extensions.c,v
retrieving revision 1.11
diff -p -u -r1.11 eel-gdk-extensions.c
--- eel/eel-gdk-extensions.c	2002/01/04 16:35:58	1.11
+++ eel/eel-gdk-extensions.c	2002/02/13 17:10:35
@@ -415,11 +415,8 @@ eel_gdk_color_parse_with_white_default (
 
 	got_color = FALSE;
 	if (color_spec != NULL) {
-		if (gdk_color_parse (color_spec, color)) {
+		if (eel_gdk_color_parse (color_spec, color)) {
 			got_color = TRUE;
-		} else if (eel_str_has_prefix (color_spec, "rgb:")) {
-			/* put rgb: parsing here? */
-			g_warning ("do we need rgb: parsing?");
 		}
 	}
 
@@ -825,6 +822,41 @@ eel_gdk_parse_geometry (const char *stri
 	}
 
 	return gdk_flags;
+}
+
+/* Color specifications have changed in gdk 2.0.  Unfortunately, nautilus has
+   the old rgb:RRRR/BBBB/GGGG format scattered about in various xml files and
+   the new gdk_color_parse () is not fully backward compatible. */
+
+/* 2002-13-02 FIXME: Someday we should remove this compatibility code. */
+
+gboolean
+eel_gdk_color_parse (const gchar *spec,
+		     GdkColor *color)
+{
+	Colormap xcolormap;
+	XColor xcolor;
+
+	g_return_val_if_fail (spec != NULL, FALSE);
+	g_return_val_if_fail (color != NULL, FALSE);
+
+	/* First try to use the new gdk code. */
+	if (gdk_color_parse (spec, color)) {
+		return TRUE;
+	}
+
+	/* If that failed, fallback to the old gdk code. */
+	xcolormap = DefaultColormap (GDK_DISPLAY (),
+				     gdk_x11_get_default_screen ());
+
+	if (XParseColor (GDK_DISPLAY (), xcolormap, spec, &xcolor)) {
+		color->red = xcolor.red;
+		color->green = xcolor.green;
+		color->blue = xcolor.blue;
+		return TRUE;
+	}
+
+	return FALSE;
 }
 
 #if ! defined (EEL_OMIT_SELF_CHECK)
Index: eel/eel-gdk-extensions.h
===================================================================
RCS file: /cvs/gnome/eel/eel/eel-gdk-extensions.h,v
retrieving revision 1.7
diff -p -u -r1.7 eel-gdk-extensions.h
--- eel/eel-gdk-extensions.h	2001/12/01 00:37:55	1.7
+++ eel/eel-gdk-extensions.h	2002/02/13 17:10:35
@@ -117,6 +117,9 @@ guint32             eel_gdk_color_to_rgb
 GdkColor            eel_gdk_rgb_to_color                   (guint32              color);
 char *              eel_gdk_rgb_to_color_spec              (guint32              color);
 
+gboolean            eel_gdk_color_parse                    (const gchar         *spec,
+							    GdkColor            *color);
+
 /* Fill routines that take GdkRectangle parameters instead of four integers. */
 void                eel_fill_rectangle                     (GdkDrawable         *drawable,
 							    GdkGC               *gc,
Index: src/nautilus-property-browser.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-property-browser.c,v
retrieving revision 1.171
diff -p -u -r1.171 nautilus-property-browser.c
--- src/nautilus-property-browser.c	2002/02/12 00:56:07	1.171
+++ src/nautilus-property-browser.c	2002/02/13 17:35:06
@@ -559,12 +559,15 @@ nautilus_property_browser_drag_data_get 
 			
 			/* handle the "reset" case as an image */
 			if (eel_strcmp (property_browser->details->dragged_file, RESET_IMAGE_NAME) != 0) {
-				gdk_color_parse(property_browser->details->dragged_file, &color);
-				colorArray[0] = color.red;
-				colorArray[1] = color.green;
-				colorArray[2] = color.blue;
-				colorArray[3] = 0xffff;
-				
+				if (gdk_color_parse (property_browser->details->dragged_file, &color)) {
+					colorArray[0] = color.red;
+					colorArray[1] = color.green;
+					colorArray[2] = color.blue;
+					colorArray[3] = 0xffff;
+				} else if (eel_str_has_prefix (property_browser->details->dragged_file, "rgb:")) {
+					g_warning ("drag_data_get needs rgb: color parsing.");
+				}
+
 				gtk_selection_data_set(selection_data,
 				selection_data->target, 16, (const char *) &colorArray[0], 8);
 				return;	
@@ -690,7 +693,7 @@ make_color_drag_image (NautilusPropertyB
 
 	color_square = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, COLOR_SQUARE_SIZE, COLOR_SQUARE_SIZE);
 	
-	gdk_color_parse(color_spec, &color);
+	eel_gdk_color_parse (color_spec, &color);
 	color.red >>= 8;
 	color.green >>= 8;
 	color.blue >>= 8;
Index: src/nautilus-sidebar-tabs.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/nautilus-sidebar-tabs.c,v
retrieving revision 1.93
diff -p -u -r1.93 nautilus-sidebar-tabs.c
--- src/nautilus-sidebar-tabs.c	2002/01/25 00:52:58	1.93
+++ src/nautilus-sidebar-tabs.c	2002/02/13 17:35:11
@@ -1606,8 +1606,8 @@ nautilus_sidebar_tabs_set_color (Nautilu
 {
 	g_return_if_fail (NAUTILUS_IS_SIDEBAR_TABS (sidebar_tabs));
 	g_return_if_fail (color_spec != NULL);
-	
-	gdk_color_parse (color_spec, &sidebar_tabs->details->tab_color);
+
+	eel_gdk_color_parse (color_spec, &sidebar_tabs->details->tab_color);
 	gdk_colormap_alloc_color (gtk_widget_get_colormap (GTK_WIDGET (sidebar_tabs)), 
 				  &sidebar_tabs->details->tab_color, FALSE, TRUE);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]