[gtk+] Fixed GtkTextView & GtkIconView to consult it's true previous size request



commit 73ea777c331b3ab62d55ddd1c258835c612c34d0
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Thu Sep 9 16:27:22 2010 +0900

    Fixed GtkTextView & GtkIconView to consult it's true previous size request
    
    Fixed issues in my previous patch for bug 626939 removing GtkRequisition
    cache: these widgets monitor the previous requested size and decide whether
    to queue a resize when the content changes based on it's prior request.

 gtk/gtkiconview.c |   17 ++++++++++-------
 gtk/gtktextview.c |   20 +++++++++++++++++---
 2 files changed, 27 insertions(+), 10 deletions(-)
---
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 84ce3f8..2dc1043 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -2821,12 +2821,12 @@ static void
 gtk_icon_view_layout (GtkIconView *icon_view)
 {
   GtkAllocation allocation;
-  GtkRequisition requisition;
   GtkWidget *widget;
   GList *icons;
   gint y = 0, maximum_width = 0;
   gint row;
   gint item_width;
+  gboolean size_changed = FALSE;
 
   if (icon_view->priv->layout_idle_id != 0)
     {
@@ -2872,22 +2872,25 @@ gtk_icon_view_layout (GtkIconView *icon_view)
   while (icons != NULL);
 
   if (maximum_width != icon_view->priv->width)
-    icon_view->priv->width = maximum_width;
+    {
+      icon_view->priv->width = maximum_width;
+      size_changed = TRUE;
+    }
 
   y += icon_view->priv->margin;
   
   if (y != icon_view->priv->height)
-    icon_view->priv->height = y;
+    {
+      icon_view->priv->height = y;
+      size_changed = TRUE;
+    }
 
   gtk_icon_view_set_adjustment_upper (icon_view->priv->hadjustment, 
 				      icon_view->priv->width);
   gtk_icon_view_set_adjustment_upper (icon_view->priv->vadjustment, 
 				      icon_view->priv->height);
 
-  gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &requisition, NULL);
-
-  if (icon_view->priv->width != requisition.width ||
-      icon_view->priv->height != requisition.height)
+  if (size_changed)
     gtk_widget_queue_resize_no_redraw (widget);
 
   gtk_widget_get_allocation (widget, &allocation);
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index db1073a..e49fb01 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -134,6 +134,18 @@ struct _GtkTextViewPrivate
   gint width;           /* Width and height of the buffer */
   gint height;
 
+  /* This is used to monitor the overall size request 
+   * and decide whether we need to queue resizes when
+   * the buffer content changes. 
+   *
+   * FIXME: This could be done in a simpler way by 
+   * consulting the above width/height of the buffer + some
+   * padding values, however all of this request code needs
+   * to be changed to use GtkSizeRequestIface and deserves
+   * more attention.
+   */
+  GtkRequisition cached_size_request;
+
   /* The virtual cursor position is normally the same as the
    * actual (strong) cursor position, except in two circumstances:
    *
@@ -3319,6 +3331,10 @@ gtk_text_view_size_request (GtkWidget      *widget,
 
       tmp_list = g_slist_next (tmp_list);
     }
+
+  /* Cache the requested size of the text view so we can 
+   * compare it in the changed_handler() */
+  priv->cached_size_request = *requisition;
 }
 
 static void
@@ -3935,11 +3951,9 @@ changed_handler (GtkTextLayout     *layout,
     }
 
   {
-    GtkRequisition old_req;
+    GtkRequisition old_req = priv->cached_size_request;
     GtkRequisition new_req;
 
-    gtk_size_request_get_size (GTK_SIZE_REQUEST (widget), &old_req, NULL);
-
     /* Use this instead of gtk_widget_size_request wrapper
      * to avoid the optimization which just returns widget->requisition
      * if a resize hasn't been queued.



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