From d3d9f52365c583b9f27311c076d7cbf10030898c Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Mon, 14 Sep 2015 06:11:36 +0200 Subject: [PATCH] API: widget: Add gtk_widget_get_allocated_size() See docs for what this is. --- docs/reference/gtk/gtk3-sections.txt | 1 + gtk/gtkwidget.c | 41 ++++++++++++++++++++++++++++ gtk/gtkwidget.h | 4 +++ gtk/gtkwidgetprivate.h | 2 ++ 4 files changed, 48 insertions(+) diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index 453fdacbaf..b352d13aa4 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -5553,6 +5553,7 @@ gtk_widget_get_allocated_height gtk_widget_get_allocation gtk_widget_set_allocation gtk_widget_get_allocated_baseline +gtk_widget_get_allocated_size gtk_widget_get_clip gtk_widget_set_clip gtk_widget_get_app_paintable diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 5cac170aee..cb2a178364 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -5864,6 +5864,9 @@ gtk_widget_size_allocate_with_baseline (GtkWidget *widget, old_baseline = priv->allocated_baseline; real_allocation = *allocation; + priv->allocated_size = *allocation; + priv->allocated_size_baseline = baseline; + adjusted_allocation = real_allocation; if (gtk_widget_get_request_mode (widget) == GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH) { @@ -8898,6 +8901,8 @@ _gtk_widget_set_visible_flag (GtkWidget *widget, priv->allocation.width = 1; priv->allocation.height = 1; memset (&priv->clip, 0, sizeof (priv->clip)); + memset (&priv->allocated_size, 0, sizeof (priv->allocated_size)); + priv->allocated_size_baseline = 0; } } @@ -15532,6 +15537,42 @@ _gtk_widget_set_simple_clip (GtkWidget *widget, gtk_widget_set_clip (widget, &clip); } +/** + * gtk_widget_get_allocated_size: + * @widget: a #GtkWidget + * @allocation: (out) (allow-none): a pointer to a #GtkAllocation to copy to + * @baseline: (out) (allow-none): a pointer to an integer to copy to + * + * Retrieves the widget’s allocated size. + * + * This function returns the last values passed to + * gtk_widget_size_allocate_with_baseline(). The value differs from + * the size returned in gtk_widget_get_allocation() in that functions + * like gtk_widget_set_halign() can adjust the allocation, but not + * the value returned by this function. + * + * If a widget is not visible, its allocated size is 0. + * + * Since: 3.20 + */ +void +gtk_widget_get_allocated_size (GtkWidget *widget, + GtkAllocation *allocation, + int *baseline) +{ + GtkWidgetPrivate *priv; + + g_return_if_fail (GTK_IS_WIDGET (widget)); + g_return_if_fail (allocation != NULL); + + priv = widget->priv; + + if (allocation) + *allocation = priv->allocated_size; + if (baseline) + *baseline = priv->allocated_size_baseline; +} + /** * gtk_widget_get_allocation: * @widget: a #GtkWidget diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h index 67441de36f..e98c537b34 100644 --- a/gtk/gtkwidget.h +++ b/gtk/gtkwidget.h @@ -918,6 +918,10 @@ GDK_AVAILABLE_IN_ALL int gtk_widget_get_allocated_height (GtkWidget *widget); GDK_AVAILABLE_IN_3_10 int gtk_widget_get_allocated_baseline (GtkWidget *widget); +GDK_AVAILABLE_IN_3_20 +void gtk_widget_get_allocated_size (GtkWidget *widget, + GtkAllocation *allocation, + int *baseline); GDK_AVAILABLE_IN_ALL void gtk_widget_get_allocation (GtkWidget *widget, diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h index 6f49d245d7..aefa4f8699 100644 --- a/gtk/gtkwidgetprivate.h +++ b/gtk/gtkwidgetprivate.h @@ -130,6 +130,8 @@ struct _GtkWidgetPrivate GtkStyleContext *context; /* The widget's allocated size */ + GtkAllocation allocated_size; + gint allocated_size_baseline; GtkAllocation allocation; GtkAllocation clip; gint allocated_baseline;