Proposed patch to fix GdkColor support in the canvas



There were several bugs, leaks, crashes, and confusions in the
Canvas when handling GdkColors.  This should patch the worst of it.

/me crosses fingers
? gdk_color.patch
Index: libgnomecanvas/ChangeLog
===================================================================
RCS file: /cvs/gnome/libgnomecanvas/libgnomecanvas/ChangeLog,v
retrieving revision 1.110
diff -u -w -r1.110 ChangeLog
--- libgnomecanvas/ChangeLog	2002/01/10 00:36:50	1.110
+++ libgnomecanvas/ChangeLog	2002/01/15 05:33:01
@@ -1,3 +1,24 @@
+2002-01-14  Jody Goldberg <jody gnome org>
+
+	* gnome-canvas-shape.c (gnome_canvas_shape_set_property) : Here we
+	  do need to use gdk_rgb_find_color.
+
+2002-01-13  Jody Goldberg <jody gnome org>
+
+	* gnome-canvas-text.c (gnome_canvas_text_get_property) : Use
+	  gdk_colormap_query_color not gdk_rgb_find_color.
+	* gnome-canvas-line.c (gnome_canvas_line_get_property) : ditto.
+	* gnome-canvas-shape.c (get_color_value) : ditto.
+
+2002-01-13  Jody Goldberg <jody gnome org>
+
+	* gnome-canvas-text.c (gnome_canvas_text_get_property) : Do not use
+	  g_new to allocate (and leak) the color.
+	* gnome-canvas-line.c (gnome_canvas_line_get_property) : ditto.
+	* gnome-canvas-shape.c (get_color_value) : ditto.
+	(gnome_canvas_shape_set_property) : PROP_FILL_COLOR_GDK, colorptr can
+	  be NULL.
+
 2002-01-09  Darin Adler  <darin bentspoon com>
 
 	* gnome-canvas.c: (emit_event): Remove some dead code.
Index: libgnomecanvas/gnome-canvas-line.c
===================================================================
RCS file: /cvs/gnome/libgnomecanvas/libgnomecanvas/gnome-canvas-line.c,v
retrieving revision 1.68
diff -u -w -r1.68 gnome-canvas-line.c
--- libgnomecanvas/gnome-canvas-line.c	2002/01/09 06:08:07	1.68
+++ libgnomecanvas/gnome-canvas-line.c	2002/01/15 05:33:01
@@ -872,7 +872,6 @@
 				GParamSpec           *pspec)
 {
 	GnomeCanvasLine *line;
-	GdkColor *color;
 
 	g_return_if_fail (object != NULL);
 	g_return_if_fail (GNOME_IS_CANVAS_LINE (object));
@@ -893,13 +892,12 @@
 		break;
 
 	case PROP_FILL_COLOR_GDK: {
-		GdkColormap *colormap;
+		GnomeCanvas *canvas = GNOME_CANVAS_ITEM (line)->canvas;
+		GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (canvas));
+		GdkColor color;
 
-		color = g_new (GdkColor, 1);
-		color->pixel = line->fill_pixel;
-		colormap = gtk_widget_get_colormap (GTK_WIDGET (line->item.canvas));
-		gdk_rgb_find_color (colormap, color);
-		g_value_set_boxed (value, color);
+		gdk_colormap_query_color (colormap, line->fill_pixel, &color);
+		g_value_set_boxed (value, &color);
 		break;
 	}
 
Index: libgnomecanvas/gnome-canvas-shape.c
===================================================================
RCS file: /cvs/gnome/libgnomecanvas/libgnomecanvas/gnome-canvas-shape.c,v
retrieving revision 1.12
diff -u -w -r1.12 gnome-canvas-shape.c
--- libgnomecanvas/gnome-canvas-shape.c	2002/01/09 06:08:07	1.12
+++ libgnomecanvas/gnome-canvas-shape.c	2002/01/15 05:33:01
@@ -360,10 +360,17 @@
 
 	case PROP_FILL_COLOR_GDK:
 		colorptr = g_value_get_boxed (value);
+		if (colorptr == NULL)
+			break;
 
 		priv->fill_set = TRUE;
 		priv->fill_rgba = get_rgba_from_color (colorptr);
-		if (gdk) gdk->fill_pixel = colorptr->pixel;
+		if (gdk) {
+			GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas));
+			GdkColor tmp = *colorptr;
+			gdk_rgb_find_color (colormap, &tmp);
+			gdk->fill_pixel = tmp.pixel;
+		}
 
 		gnome_canvas_item_request_update (item);
 		break;
@@ -393,7 +400,12 @@
 
 		priv->outline_set = TRUE;
 		priv->outline_rgba = get_rgba_from_color (colorptr);
-		if (gdk) gdk->outline_pixel = colorptr->pixel;
+		if (gdk) {
+			GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (item->canvas));
+			GdkColor tmp = *colorptr;
+			gdk_rgb_find_color (colormap, &tmp);
+			gdk->outline_pixel = tmp.pixel;
+		}
 
 		gnome_canvas_item_request_update (item);
 		break;
@@ -484,15 +496,11 @@
 get_color_value (GnomeCanvasShape *shape, gulong pixel, GValue *value)
 {
   GnomeCanvas *canvas = GNOME_CANVAS_ITEM (shape)->canvas;
-  GdkColor *color;
-  GdkColormap *colormap;
-  
-  color = g_new (GdkColor, 1);
-  color->pixel = pixel;
+	GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (canvas));
+	GdkColor color;
   
-  colormap = gtk_widget_get_colormap (GTK_WIDGET (canvas));
-  gdk_rgb_find_color (colormap, color);
-  g_value_set_boxed (value, color);
+	gdk_colormap_query_color (colormap, pixel, &color);
+	g_value_set_boxed (value, &color);
 }
 
 /**
Index: libgnomecanvas/gnome-canvas-text.c
===================================================================
RCS file: /cvs/gnome/libgnomecanvas/libgnomecanvas/gnome-canvas-text.c,v
retrieving revision 1.80
diff -u -w -r1.80 gnome-canvas-text.c
--- libgnomecanvas/gnome-canvas-text.c	2002/01/11 23:44:18	1.80
+++ libgnomecanvas/gnome-canvas-text.c	2002/01/15 05:33:02
@@ -1102,7 +1102,6 @@
 				GParamSpec         *pspec)
 {
 	GnomeCanvasText *text;
-	GdkColor *color;
 
 	g_return_if_fail (object != NULL);
 	g_return_if_fail (GNOME_IS_CANVAS_TEXT (object));
@@ -1265,13 +1264,12 @@
 		break;
 
 	case PROP_FILL_COLOR_GDK: {
-		GdkColormap *colormap;
+		GnomeCanvas *canvas = GNOME_CANVAS_ITEM (text)->canvas;
+		GdkColormap *colormap = gtk_widget_get_colormap (GTK_WIDGET (canvas));
+		GdkColor color;
 
-		color = g_new (GdkColor, 1);
-		color->pixel = text->pixel;
-		colormap = gtk_widget_get_colormap (GTK_WIDGET (text->item.canvas));
-		gdk_rgb_find_color (colormap, color);
-		g_value_set_boxed (value, color);
+		gdk_colormap_query_color (colormap, text->pixel, &color);
+		g_value_set_boxed (value, &color);
 		break;
 	}
 	case PROP_FILL_COLOR_RGBA:


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