Re: [PATCH] gtkpixmap.c, bug in gtk_pixmap_set()




Ullrich Hafner <hafner@informatik.uni-wuerzburg.de> writes:

> Hi,
> 
> this week someone reported a bug in the function gtk_pixmap_set ():
> the old pixmap is not removed on screen when a new pixmap is
> drawn. I suggested a call of gtk_widget_hide/gtk_widget_show to force a
> redisplay. However, the following code snippet is more efficient:

[...]

> Alternatively, gtkpixmap.c should be patched in this way:
> 
> Patch for gtk+-1.0.4:
> 
> *** gtkpixmap.c	Thu Jun 18 09:53:50 1998
> --- gtkpixmap.c.new	Thu Jun 18 11:47:29 1998
> ***************
> *** 133,138 ****
> --- 133,144 ----
>   	}
>         if (GTK_WIDGET_VISIBLE (pixmap))
>   	{
> + 	  if (GTK_WIDGET (pixmap)->window)
> + 	    gdk_window_clear_area (GTK_WIDGET (pixmap)->window,
> + 				   GTK_WIDGET (pixmap)->allocation.x,
> + 				   GTK_WIDGET (pixmap)->allocation.y,
> + 				   GTK_WIDGET (pixmap)->allocation.width,
> + 				   GTK_WIDGET (pixmap)->allocation.height); 
>   	  if ((GTK_WIDGET (pixmap)->requisition.width != oldwidth) ||
>   	      (GTK_WIDGET (pixmap)->requisition.height != oldheight))
>   	    gtk_widget_queue_resize (GTK_WIDGET (pixmap));

Thanks for the patch. Since clearing is something we want to avoid
if at all possible, I've changed the patch to be a bit more careful
about clearing, and also to delay the actual clear until just before
the widget is redrawn. (This works because if the allocation changes,
GTK+ will clear for us)

Regards,
                                        Owen

Index: gtkpixmap.c
===================================================================
RCS file: /debian/home/gnomecvs/gtk+/gtk/gtkpixmap.c,v
retrieving revision 1.8
diff -u -r1.8 gtkpixmap.c
--- gtkpixmap.c	1998/06/17 08:48:16	1.8
+++ gtkpixmap.c	1998/06/18 21:38:22
@@ -73,6 +73,7 @@
 
   pixmap->pixmap = NULL;
   pixmap->mask = NULL;
+  pixmap->needs_clear = FALSE;
 }
 
 GtkWidget*
@@ -133,6 +134,15 @@
 	}
       if (GTK_WIDGET_VISIBLE (pixmap))
 	{
+	  /* If we aren't drawing the entire area, clear first */
+	  if (GTK_WIDGET_DRAWABLE (pixmap) && 
+	      ((mask != NULL) || 
+	       (GTK_WIDGET (pixmap)->requisition.width != oldwidth) ||
+	       (GTK_WIDGET (pixmap)->requisition.height != oldheight)))
+	    {
+	      pixmap->needs_clear = TRUE;
+	    }
+
 	  if ((GTK_WIDGET (pixmap)->requisition.width != oldwidth) ||
 	      (GTK_WIDGET (pixmap)->requisition.height != oldheight))
 	    gtk_widget_queue_resize (GTK_WIDGET (pixmap));
@@ -182,6 +192,17 @@
     {
       pixmap = GTK_PIXMAP (widget);
       misc = GTK_MISC (widget);
+
+      if (pixmap->needs_clear)
+	{
+          gdk_window_clear_area (GTK_WIDGET (pixmap)->window,
+				 GTK_WIDGET (pixmap)->allocation.x,
+				 GTK_WIDGET (pixmap)->allocation.y,
+				 GTK_WIDGET (pixmap)->allocation.width,
+				 GTK_WIDGET (pixmap)->allocation.height);
+	  
+	  pixmap->needs_clear = FALSE;
+	}
 
       x = (widget->allocation.x * (1.0 - misc->xalign) +
 	   (widget->allocation.x + widget->allocation.width
Index: gtkpixmap.h
===================================================================
RCS file: /debian/home/gnomecvs/gtk+/gtk/gtkpixmap.h,v
retrieving revision 1.3
diff -u -r1.3 gtkpixmap.h
--- gtkpixmap.h	1998/06/17 08:48:17	1.3
+++ gtkpixmap.h	1998/06/18 21:38:22
@@ -46,6 +46,8 @@
   
   GdkPixmap *pixmap;
   GdkBitmap *mask;
+
+  guint needs_clear : 1;
 };
 
 struct _GtkPixmapClass



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