From b8e4adfff9ba62330a71ea7498595227979bb4f0 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 22 Apr 2013 08:23:08 -0400 Subject: [PATCH] Revert "Revert "gtkbin: Remove the silliest code on earth"" This reverts commit b164df74506505ac0f4559744ad9b59b5ea57ebf. --- gtk/gtkbin.c | 78 ++++++++++++++-------------------------------------- 1 file changed, 20 insertions(+), 58 deletions(-) diff --git a/gtk/gtkbin.c b/gtk/gtkbin.c index 3764938f2d..b64f54156d 100644 --- a/gtk/gtkbin.c +++ b/gtk/gtkbin.c @@ -189,44 +189,6 @@ gtk_bin_get_effective_border_width (GtkBin *bin) return gtk_container_get_border_width (GTK_CONTAINER (bin)); } -/* GtkBin widgets define the padding and borders independantly so - * we cannot provide a generic get_size() for the same reason - * we never implemented size_request() here. - * - * But for cases where the GtkBin class's padding is constant and - * does not vary based on allocation (most cases), we can at least - * deduce a common code path for the get_width_for_height()/get_height_for_width() - * cases by using the delta of the base size requsts. - */ -static void -get_child_padding_delta (GtkBin *bin, - gint *delta_h, - gint *delta_v) -{ - GtkBinPrivate *priv = bin->priv; - gint hmin, vmin, hnat, vnat, child_hmin, child_vmin; - - /* we can't use gtk_widget_get_preferred_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_WIDGET_GET_CLASS (bin)->get_preferred_width (GTK_WIDGET (bin), &hmin, &hnat); - GTK_WIDGET_GET_CLASS (bin)->adjust_size_request (GTK_WIDGET (bin), - GTK_ORIENTATION_HORIZONTAL, &hmin, &hnat); - - GTK_WIDGET_GET_CLASS (bin)->get_preferred_height (GTK_WIDGET (bin), &vmin, &vnat); - GTK_WIDGET_GET_CLASS (bin)->adjust_size_request (GTK_WIDGET (bin), - GTK_ORIENTATION_VERTICAL, &vmin, &vnat); - - gtk_widget_get_preferred_width (priv->child, &child_hmin, NULL); - gtk_widget_get_preferred_height (priv->child, &child_vmin, NULL); - - *delta_h = hmin - child_hmin; - *delta_v = vmin - child_vmin; -} - static void gtk_bin_get_preferred_width (GtkWidget *widget, gint *minimum_width, @@ -287,25 +249,25 @@ gtk_bin_get_preferred_width_for_height (GtkWidget *widget, { GtkBin *bin = GTK_BIN (widget); GtkBinPrivate *priv = bin->priv; - gint hdelta, vdelta, child_min, child_nat; + gint border_width; *minimum_width = 0; *natural_width = 0; + border_width = gtk_bin_get_effective_border_width (bin); + if (priv->child && gtk_widget_get_visible (priv->child)) { - get_child_padding_delta (bin, &hdelta, &vdelta); - - gtk_widget_get_preferred_width_for_height (priv->child, - height - vdelta, + gint child_min, child_nat; + gtk_widget_get_preferred_width_for_height (priv->child, height - 2 * border_width, &child_min, &child_nat); - if (minimum_width) - *minimum_width = child_min + hdelta; - - if (natural_width) - *natural_width = child_nat + hdelta; + *minimum_width = child_min; + *natural_width = child_nat; } + + *minimum_width += 2 * border_width; + *natural_width += 2 * border_width; } static void @@ -316,25 +278,25 @@ gtk_bin_get_preferred_height_for_width (GtkWidget *widget, { GtkBin *bin = GTK_BIN (widget); GtkBinPrivate *priv = bin->priv; - gint hdelta, vdelta, child_min, child_nat; + gint border_width; *minimum_height = 0; *natural_height = 0; + border_width = gtk_bin_get_effective_border_width (bin); + if (priv->child && gtk_widget_get_visible (priv->child)) { - get_child_padding_delta (bin, &hdelta, &vdelta); - - gtk_widget_get_preferred_height_for_width (priv->child, - width - hdelta, + gint child_min, child_nat; + gtk_widget_get_preferred_height_for_width (priv->child, width - 2 * border_width, &child_min, &child_nat); - if (minimum_height) - *minimum_height = child_min + vdelta; - - if (natural_height) - *natural_height = child_nat + vdelta; + *minimum_height = child_min; + *natural_height = child_nat; } + + *minimum_height += 2 * border_width; + *natural_height += 2 * border_width; } static void