[gtk+] default impls of width_for_height, hfw should chain directly not use wrapper API



commit cf6eb47758085da041fa5fa126d3e22a60bb2afc
Author: Havoc Pennington <hp pobox com>
Date:   Sun Sep 5 01:42:14 2010 -0400

    default impls of width_for_height,hfw should chain directly not use wrapper API
    
    In GtkBin and GtkWidget we tried to provide handy defaults that
    call get_width if there's no get_width_for_height and
    get_height for get_height_for_width.
    
    However, they used the wrapper API on GtkSizeRequest instead of
    chaining directly to the other method implementation.
    
    This could result in all kinds of surprising behavior, for example,
    get_width_for_height() would now already include the effects of set_size_request().
    
    If nothing else it's inefficient. But it's just conceptually wrong,
    because to chain to another implementation, we should call the other
    implementation, not call a wrapper around the other implementation
    (when we're already inside a previous invocation of the wrapper,
    i.e. compute_size_for_orientation() ends up reinvoking itself
    in the same orientation on the same object which it pretty
    likely isn't intending to do)
    
    https://bugzilla.gnome.org/show_bug.cgi?id=628829

 gtk/gtkbin.c    |   11 ++++++++---
 gtk/gtkwidget.c |    6 +++---
 2 files changed, 11 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkbin.c b/gtk/gtkbin.c
index ecc2b99..b550009 100644
--- a/gtk/gtkbin.c
+++ b/gtk/gtkbin.c
@@ -214,10 +214,15 @@ get_child_padding_delta (GtkBin         *bin,
 			 gint           *delta_v)
 {
   GtkBinPrivate *priv = bin->priv;
-  gint hmin, vmin, child_hmin, child_vmin;
+  gint hmin, vmin, hnat, vnat, child_hmin, child_vmin;
 
-  gtk_size_request_get_width (GTK_SIZE_REQUEST (bin), &hmin, NULL);
-  gtk_size_request_get_height (GTK_SIZE_REQUEST (bin), &vmin, NULL);
+  /* we can't use gtk_size_request_get_width() wrapper because we want
+   * our "original" request, not any external adjustments from
+   * set_size_request() or whatever.  we have to ask for natural also
+   * because NULL isn't allowed for the direct vfuncs
+   */
+  GTK_SIZE_REQUEST_GET_IFACE (bin)->get_width(GTK_SIZE_REQUEST (bin), &hmin, &hnat);
+  GTK_SIZE_REQUEST_GET_IFACE (bin)->get_height (GTK_SIZE_REQUEST (bin), &vmin, &vnat);
 
   gtk_size_request_get_width (GTK_SIZE_REQUEST (priv->child), &child_hmin, NULL);
   gtk_size_request_get_height (GTK_SIZE_REQUEST (priv->child), &child_vmin, NULL);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index a203236..77b37ec 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -11040,7 +11040,7 @@ gtk_widget_real_get_height_for_width (GtkSizeRequest *layout,
                                       gint      *minimum_height,
                                       gint      *natural_height)
 {
-  gtk_size_request_get_height (layout, minimum_height, natural_height);
+  GTK_SIZE_REQUEST_GET_IFACE (layout)->get_height(layout, minimum_height, natural_height);
 }
 
 static void
@@ -11048,8 +11048,8 @@ gtk_widget_real_get_width_for_height (GtkSizeRequest *layout,
                                       gint       height,
                                       gint      *minimum_width,
                                       gint      *natural_width)
-{ 
-  gtk_size_request_get_width (layout, minimum_width, natural_width);
+{
+  GTK_SIZE_REQUEST_GET_IFACE (layout)->get_width(layout, minimum_width, natural_width);
 }
 
 static void



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