[gtk+/wip/otte/queue-resize: 8/31] API: widget: Add gtk_widget_get_allocated_size()



commit a28782b0ddc6f15aa3aaa472e4a4eae7596fba69
Author: Benjamin Otte <otte redhat com>
Date:   Mon Sep 14 06:11:36 2015 +0200

    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(+), 0 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 945726e..4b874ba 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -5551,6 +5551,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 3472baa..1668f6b 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -5861,6 +5861,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)
     {
@@ -8897,6 +8900,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;
     }
 }
 
@@ -15536,6 +15541,42 @@ _gtk_widget_set_simple_clip (GtkWidget     *widget,
 }
 
 /**
+ * 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
  * @allocation: (out): a pointer to a #GtkAllocation to copy to
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index c725fcb..616b565 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 3677b71..81d483c 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;


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