]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtksizerequest.c
GtkEntry: Sanity check the end_pos value in _get_display_text()
[~andy/gtk] / gtk / gtksizerequest.c
index a57c0dd7eb5b6d5dd540d86e94c2e7dd635648e7..0ce86bd66fc95b849c98347619791f28898604b8 100644 (file)
@@ -38,7 +38,7 @@ static GQuark recursion_check_quark = 0;
 
 static void
 push_recursion_check (GtkWidget       *widget,
-                      GtkSizeGroupMode orientation,
+                      GtkOrientation   orientation,
                       gint             for_size)
 {
 #ifndef G_DISABLE_CHECKS
@@ -50,7 +50,7 @@ push_recursion_check (GtkWidget       *widget,
 
   previous_method = g_object_get_qdata (G_OBJECT (widget), recursion_check_quark);
 
-  if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       method = for_size < 0 ? "get_width" : "get_width_for_height";
     }
@@ -76,76 +76,18 @@ push_recursion_check (GtkWidget       *widget,
 
 static void
 pop_recursion_check (GtkWidget       *widget,
-                     GtkSizeGroupMode orientation)
+                     GtkOrientation   orientation)
 {
 #ifndef G_DISABLE_CHECKS
   g_object_set_qdata (G_OBJECT (widget), recursion_check_quark, NULL);
 #endif
 }
 
-
-/* looks for a cached size request for this for_size. If not
- * found, returns the oldest entry so it can be overwritten
- *
- * Note that this caching code was originally derived from
- * the Clutter toolkit but has evolved for other GTK+ requirements.
- */
-static gboolean
-get_cached_size (GtkWidget         *widget,
-                GtkSizeGroupMode   orientation,
-                gint               for_size,
-                CachedSize       **result)
-{
-  SizeRequestCache  *cache;
-  SizeRequest      **cached_sizes;
-  guint              i, n_sizes;
-
-  cache = _gtk_widget_peek_request_cache (widget);
-
-  if (for_size < 0)
-    {
-      if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
-       {
-         *result = &cache->cached_width;
-         return cache->cached_base_width;
-       }
-      else
-       {
-         *result = &cache->cached_height;
-         return cache->cached_base_height;
-       }
-    }
-
-  if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
-    {
-      cached_sizes = cache->widths;
-      n_sizes      = cache->cached_widths;
-    }
-  else
-    {
-      cached_sizes = cache->heights;
-      n_sizes      = cache->cached_heights;
-    }
-
-  /* Search for an already cached size */
-  for (i = 0; i < n_sizes; i++)
-    {
-      if (cached_sizes[i]->lower_for_size <= for_size &&
-         cached_sizes[i]->upper_for_size >= for_size)
-       {
-         *result = &cached_sizes[i]->cached_size;
-         return TRUE;
-       }
-    }
-
-  return FALSE;
-}
-
 static const char *
-get_vfunc_name (GtkSizeGroupMode orientation,
-                gint             for_size)
+get_vfunc_name (GtkOrientation orientation,
+                gint           for_size)
 {
-  if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
+  if (orientation == GTK_ORIENTATION_HORIZONTAL)
     return for_size < 0 ? "get_preferred_width" : "get_preferred_width_for_height";
   else
     return for_size < 0 ? "get_preferred_height" : "get_preferred_height_for_width";
@@ -153,27 +95,35 @@ get_vfunc_name (GtkSizeGroupMode orientation,
 
 static void
 gtk_widget_query_size_for_orientation (GtkWidget        *widget,
-                                       GtkSizeGroupMode  orientation,
+                                       GtkOrientation    orientation,
                                        gint              for_size,
                                        gint             *minimum_size,
                                        gint             *natural_size)
 {
-  CachedSize *cached_size;
-  gboolean    found_in_cache = FALSE;
-  gint        min_size = 0;
-  gint        nat_size = 0;
+  SizeRequestCache *cache;
+  gint min_size = 0;
+  gint nat_size = 0;
+  gboolean found_in_cache;
 
-  found_in_cache = get_cached_size (widget, orientation, for_size, &cached_size);
+  if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
+    for_size = -1;
 
+  cache = _gtk_widget_peek_request_cache (widget);
+  found_in_cache = _gtk_size_request_cache_lookup (cache,
+                                                   orientation,
+                                                   for_size,
+                                                   &min_size,
+                                                   &nat_size);
+  
   if (!found_in_cache)
     {
       gint adjusted_min, adjusted_natural, adjusted_for_size = for_size;
 
       gtk_widget_ensure_style (widget);
 
-      if (orientation == GTK_SIZE_GROUP_HORIZONTAL)
+      if (orientation == GTK_ORIENTATION_HORIZONTAL)
         {
-          if (for_size < 0 || gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
+          if (for_size < 0)
             {
              push_recursion_check (widget, orientation, for_size);
               GTK_WIDGET_GET_CLASS (widget)->get_preferred_width (widget, &min_size, &nat_size);
@@ -206,7 +156,7 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
         }
       else
         {
-          if (for_size < 0 || gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_CONSTANT_SIZE)
+          if (for_size < 0)
             {
              push_recursion_check (widget, orientation, for_size);
               GTK_WIDGET_GET_CLASS (widget)->get_preferred_height (widget, &min_size, &nat_size);
@@ -247,9 +197,7 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
       adjusted_min     = min_size;
       adjusted_natural = nat_size;
       GTK_WIDGET_GET_CLASS (widget)->adjust_size_request (widget,
-                                                          orientation == GTK_SIZE_GROUP_HORIZONTAL ?
-                                                          GTK_ORIENTATION_HORIZONTAL :
-                                                          GTK_ORIENTATION_VERTICAL,
+                                                          orientation,
                                                           &adjusted_min,
                                                           &adjusted_natural);
 
@@ -258,7 +206,7 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
         {
           g_warning ("%s %p adjusted size %s min %d natural %d must not decrease below min %d natural %d",
                      G_OBJECT_TYPE_NAME (widget), widget,
-                     orientation == GTK_SIZE_GROUP_VERTICAL ? "vertical" : "horizontal",
+                     orientation == GTK_ORIENTATION_VERTICAL ? "vertical" : "horizontal",
                      adjusted_min, adjusted_natural,
                      min_size, nat_size);
           /* don't use the adjustment */
@@ -267,7 +215,7 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
         {
           g_warning ("%s %p adjusted size %s min %d natural %d original min %d natural %d has min greater than natural",
                      G_OBJECT_TYPE_NAME (widget), widget,
-                     orientation == GTK_SIZE_GROUP_VERTICAL ? "vertical" : "horizontal",
+                     orientation == GTK_ORIENTATION_VERTICAL ? "vertical" : "horizontal",
                      adjusted_min, adjusted_natural,
                      min_size, nat_size);
           /* don't use the adjustment */
@@ -279,17 +227,12 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
           nat_size = adjusted_natural;
         }
 
-      _gtk_size_request_cache_commit (_gtk_widget_peek_request_cache (widget),
+      _gtk_size_request_cache_commit (cache,
                                       orientation,
                                       for_size,
                                       min_size,
                                       nat_size);
     }
-  else
-    {
-      min_size = cached_size->minimum_size;
-      nat_size = cached_size->natural_size;
-    }
 
   if (minimum_size)
     *minimum_size = min_size;
@@ -302,11 +245,10 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
   GTK_NOTE (SIZE_REQUEST,
             g_print ("[%p] %s\t%s: %d is minimum %d and natural: %d (hit cache: %s)\n",
                      widget, G_OBJECT_TYPE_NAME (widget),
-                     orientation == GTK_SIZE_GROUP_HORIZONTAL ?
+                     orientation == GTK_ORIENTATION_HORIZONTAL ?
                      "width for height" : "height for width" ,
                      for_size, min_size, nat_size,
                      found_in_cache ? "yes" : "no"));
-
 }
 
 /* This is the main function that checks for a cached size and
@@ -316,7 +258,7 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
  */
 void
 _gtk_widget_compute_size_for_orientation (GtkWidget        *widget,
-                                          GtkSizeGroupMode  mode,
+                                          GtkOrientation    orientation,
                                           gint              for_size,
                                           gint             *minimum,
                                           gint             *natural)
@@ -326,13 +268,22 @@ _gtk_widget_compute_size_for_orientation (GtkWidget        *widget,
   gpointer key;
   gint    min_result = 0, nat_result = 0;
 
+  if (!gtk_widget_get_visible (widget) && !gtk_widget_is_toplevel (widget))
+    {
+      if (minimum)
+        *minimum = 0;
+      if (natural)
+        *natural = 0;
+      return;
+    }
+
   if (G_LIKELY (!_gtk_widget_get_sizegroups (widget)))
     {
-      gtk_widget_query_size_for_orientation (widget, mode, for_size, minimum, natural);
+      gtk_widget_query_size_for_orientation (widget, orientation, for_size, minimum, natural);
       return;
     }
 
-  widgets = _gtk_size_group_get_widget_peers (widget, mode);
+  widgets = _gtk_size_group_get_widget_peers (widget, orientation);
 
   g_hash_table_foreach (widgets, (GHFunc) g_object_ref, NULL);
   
@@ -342,7 +293,7 @@ _gtk_widget_compute_size_for_orientation (GtkWidget        *widget,
       GtkWidget *tmp_widget = key;
       gint min_dimension, nat_dimension;
 
-      gtk_widget_query_size_for_orientation (tmp_widget, mode, for_size, &min_dimension, &nat_dimension);
+      gtk_widget_query_size_for_orientation (tmp_widget, orientation, for_size, &min_dimension, &nat_dimension);
 
       min_result = MAX (min_result, min_dimension);
       nat_result = MAX (nat_result, nat_dimension);
@@ -421,7 +372,7 @@ gtk_widget_get_preferred_width (GtkWidget *widget,
   g_return_if_fail (minimum_width != NULL || natural_width != NULL);
 
   _gtk_widget_compute_size_for_orientation (widget,
-                                            GTK_SIZE_GROUP_HORIZONTAL,
+                                            GTK_ORIENTATION_HORIZONTAL,
                                             -1,
                                             minimum_width,
                                             natural_width);
@@ -455,7 +406,7 @@ gtk_widget_get_preferred_height (GtkWidget *widget,
   g_return_if_fail (minimum_height != NULL || natural_height != NULL);
 
   _gtk_widget_compute_size_for_orientation (widget,
-                                            GTK_SIZE_GROUP_VERTICAL,
+                                            GTK_ORIENTATION_VERTICAL,
                                             -1,
                                             minimum_height,
                                             natural_height);
@@ -492,7 +443,7 @@ gtk_widget_get_preferred_width_for_height (GtkWidget *widget,
   g_return_if_fail (height >= 0);
 
   _gtk_widget_compute_size_for_orientation (widget,
-                                            GTK_SIZE_GROUP_HORIZONTAL,
+                                            GTK_ORIENTATION_HORIZONTAL,
                                             height,
                                             minimum_width,
                                             natural_width);
@@ -527,7 +478,7 @@ gtk_widget_get_preferred_height_for_width (GtkWidget *widget,
   g_return_if_fail (width >= 0);
 
   _gtk_widget_compute_size_for_orientation (widget,
-                                            GTK_SIZE_GROUP_VERTICAL,
+                                            GTK_ORIENTATION_VERTICAL,
                                             width,
                                             minimum_height,
                                             natural_height);