Re: Problems with expose_event->region patch



On 9 Mar 2001, Owen Taylor wrote:

> You should be able to switch this code over to
>
>  gdk_window_scroll (clist->clist_window, ...);
>  gdk_window_process_updates (clist->clist_window, FALSE);
>
> [ There is some argument the second call should be
>   gdk_window_process_all_updates() to make sure that the
>   scrollbar eventually does get updated ]
>
> gdk_window_scroll() keeps an queue of translations, so there
> is no need to process all graphics exposes before scrolling
> again.

This works for gtkclist, patch appended. Same way seems to be ok for
testgtk. But it seems harder to remove from gtktext.c, but on the other
hand, I'm totally lost in the gtktext code. Any ideas?

/ Alex

Index: gtkclist.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkclist.c,v
retrieving revision 1.188
diff -u -p -r1.188 gtkclist.c
--- gtkclist.c	2001/03/09 13:28:23	1.188
+++ gtkclist.c	2001/03/09 19:36:44
@@ -358,7 +358,6 @@ static void column_button_clicked     (G
 /* Adjustments */
 static void adjust_adjustments        (GtkCList       *clist,
 				       gboolean        block_resize);
-static void check_exposures           (GtkCList       *clist);
 static void vadjustment_changed       (GtkAdjustment  *adjustment,
 				       gpointer        data);
 static void vadjustment_value_changed (GtkAdjustment  *adjustment,
@@ -6101,8 +6100,7 @@ vadjustment_value_changed (GtkAdjustment
 			   gpointer       data)
 {
   GtkCList *clist;
-  GdkRectangle area;
-  gint diff, value;
+  gint dy, value;

   g_return_if_fail (adjustment != NULL);
   g_return_if_fail (data != NULL);
@@ -6112,63 +6110,14 @@ vadjustment_value_changed (GtkAdjustment

   if (!GTK_WIDGET_DRAWABLE (clist) || adjustment != clist->vadjustment)
     return;
-
-  value = adjustment->value;
-
-  if (value > -clist->voffset)
-    {
-      /* scroll down */
-      diff = value + clist->voffset;
-
-      /* we have to re-draw the whole screen here... */
-      if (diff >= clist->clist_window_height)
-	{
-	  clist->voffset = -value;
-	  draw_rows (clist, NULL);
-	  return;
-	}
-
-      if ((diff != 0) && (diff != clist->clist_window_height))
-	gdk_window_copy_area (clist->clist_window, clist->fg_gc,
-			      0, 0, clist->clist_window, 0, diff,
-			      clist->clist_window_width,
-			      clist->clist_window_height - diff);
-
-      area.x = 0;
-      area.y = clist->clist_window_height - diff;
-      area.width = clist->clist_window_width;
-      area.height = diff;
-    }
-  else
-    {
-      /* scroll up */
-      diff = -clist->voffset - value;
-
-      /* we have to re-draw the whole screen here... */
-      if (diff >= clist->clist_window_height)
-	{
-	  clist->voffset = -value;
-	  draw_rows (clist, NULL);
-	  return;
-	}
-
-      if ((diff != 0) && (diff != clist->clist_window_height))
-	gdk_window_copy_area (clist->clist_window, clist->fg_gc,
-			      0, diff, clist->clist_window, 0, 0,
-			      clist->clist_window_width,
-			      clist->clist_window_height - diff);
-
-      area.x = 0;
-      area.y = 0;
-      area.width = clist->clist_window_width;
-      area.height = diff;
-    }

-  clist->voffset = -value;
-  if ((diff != 0) && (diff != clist->clist_window_height))
-    check_exposures (clist);
-
-  draw_rows (clist, &area);
+  value = -adjustment->value;
+  dy = value - clist->voffset;
+  clist->voffset = value;
+  gdk_window_scroll (clist->clist_window, 0, dy);
+  gdk_window_process_updates (clist->clist_window, FALSE);
+
+  return;
 }

 static void
@@ -6180,8 +6129,8 @@ hadjustment_value_changed (GtkAdjustment
   GdkRectangle area;
   gint i;
   gint y = 0;
-  gint diff = 0;
   gint value;
+  gint dx;

   g_return_if_fail (adjustment != NULL);
   g_return_if_fail (data != NULL);
@@ -6195,8 +6144,10 @@ hadjustment_value_changed (GtkAdjustment

   value = adjustment->value;

+  dx = -value - clist->hoffset;
+
   /* move the column buttons and resize windows */
-  for (i = 0; i < clist->columns; i++)
+  for (i = (dx<0)? 0 : clist->columns-1; i >= 0 && i < clist->columns; i += (dx<0)? 1 : -1)
     {
       if (clist->column[i].button)
 	{
@@ -6217,82 +6168,21 @@ hadjustment_value_changed (GtkAdjustment
 	}
     }

-  if (value > -clist->hoffset)
-    {
-      /* scroll right */
-      diff = value + clist->hoffset;
-
-      clist->hoffset = -value;
-
-      /* we have to re-draw the whole screen here... */
-      if (diff >= clist->clist_window_width)
-	{
-	  draw_rows (clist, NULL);
-	  return;
-	}

-      if (GTK_WIDGET_CAN_FOCUS(clist) && GTK_WIDGET_HAS_FOCUS(clist) &&
-	  !container->focus_child && GTK_CLIST_ADD_MODE(clist))
-	{
-	  y = ROW_TOP_YPIXEL (clist, clist->focus_row);
-
-	  gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE, 0, y,
-			      clist->clist_window_width - 1,
-			      clist->row_height - 1);
-	}
-      gdk_window_copy_area (clist->clist_window,
-			    clist->fg_gc,
-			    0, 0,
-			    clist->clist_window,
-			    diff,
-			    0,
-			    clist->clist_window_width - diff,
-			    clist->clist_window_height);
+  clist->hoffset = -value;

-      area.x = clist->clist_window_width - diff;
-    }
-  else
+  if (GTK_WIDGET_CAN_FOCUS(clist) && GTK_WIDGET_HAS_FOCUS(clist) &&
+      !container->focus_child && GTK_CLIST_ADD_MODE(clist))
     {
-      /* scroll left */
-      if (!(diff = -clist->hoffset - value))
-	return;
-
-      clist->hoffset = -value;
+      y = ROW_TOP_YPIXEL (clist, clist->focus_row);

-      /* we have to re-draw the whole screen here... */
-      if (diff >= clist->clist_window_width)
-	{
-	  draw_rows (clist, NULL);
-	  return;
-	}
-
-      if (GTK_WIDGET_CAN_FOCUS(clist) && GTK_WIDGET_HAS_FOCUS(clist) &&
-	  !container->focus_child && GTK_CLIST_ADD_MODE(clist))
-	{
-	  y = ROW_TOP_YPIXEL (clist, clist->focus_row);
-
-	  gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE, 0, y,
-			      clist->clist_window_width - 1,
-			      clist->row_height - 1);
-	}
-
-      gdk_window_copy_area (clist->clist_window,
-			    clist->fg_gc,
-			    diff, 0,
-			    clist->clist_window,
-			    0,
-			    0,
-			    clist->clist_window_width - diff,
-			    clist->clist_window_height);
-
-      area.x = 0;
+      gdk_draw_rectangle (clist->clist_window, clist->xor_gc, FALSE, 0, y,
+			  clist->clist_window_width - 1,
+			  clist->row_height - 1);
     }
-
-  area.y = 0;
-  area.width = diff;
-  area.height = clist->clist_window_height;
-
-  check_exposures (clist);
+
+  gdk_window_scroll (clist->clist_window, dx, 0);
+  gdk_window_process_updates (clist->clist_window, FALSE);

   if (GTK_WIDGET_CAN_FOCUS(clist) && GTK_WIDGET_HAS_FOCUS(clist) &&
       !container->focus_child)
@@ -6311,52 +6201,28 @@ hadjustment_value_changed (GtkAdjustment
 			      clist->row_height - 1);
 	  return;
 	}
-      else
+      else if (ABS(dx) < clist->clist_window_width - 1)
 	{
 	  gint x0;
 	  gint x1;

-	  if (area.x == 0)
+	  if (dx > 0)
 	    {
 	      x0 = clist->clist_window_width - 1;
-	      x1 = diff;
+	      x1 = dx;
 	    }
 	  else
 	    {
 	      x0 = 0;
-	      x1 = area.x - 1;
+	      x1 = clist->clist_window_width - 1 + dx;
 	    }
-
+
 	  y = ROW_TOP_YPIXEL (clist, clist->focus_row);
 	  gdk_draw_line (clist->clist_window, clist->xor_gc,
 			 x0, y + 1, x0, y + clist->row_height - 2);
 	  gdk_draw_line (clist->clist_window, clist->xor_gc,
 			 x1, y + 1, x1, y + clist->row_height - 2);
-
-	}
-    }
-  draw_rows (clist, &area);
-}
-
-static void
-check_exposures (GtkCList *clist)
-{
-  GdkEvent *event;
-
-  if (!GTK_WIDGET_REALIZED (clist))
-    return;
-
-  /* Make sure graphics expose events are processed before scrolling
-   * again */
-  while ((event = gdk_event_get_graphics_expose (clist->clist_window)) != NULL)
-    {
-      gtk_widget_send_expose (GTK_WIDGET (clist), event);
-      if (event->expose.count == 0)
-	{
-	  gdk_event_free (event);
-	  break;
 	}
-      gdk_event_free (event);
     }
 }






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