[gtk+/wip/baedert/drawing: 18/54] Replace a few get_content_allocation calls with get_content_size



commit 8b3b82a50e58d008c29673041ca19aa3b9004c4a
Author: Timm Bäder <mail baedert org>
Date:   Sun Jun 18 15:45:42 2017 +0200

    Replace a few get_content_allocation calls with get_content_size
    
    The position of the content allocation is almost never relevant since
    it's 0/0 for measure, size_allocate and snapshot.

 gtk/gtkcellview.c    |    8 +++-----
 gtk/gtkentry.c       |   12 +++---------
 gtk/gtkflowbox.c     |    9 +++------
 gtk/gtkframe.c       |   10 +++++-----
 gtk/gtkicon.c        |    6 +++---
 gtk/gtkimage.c       |    5 +----
 gtk/gtklabel.c       |   16 ++++++++--------
 gtk/gtkmenu.c        |   10 +++-------
 gtk/gtkrange.c       |   22 +++++++++++-----------
 gtk/gtkstack.c       |   16 ++++++++--------
 gtk/gtktoolpalette.c |   11 +++--------
 gtk/gtkviewport.c    |   25 +++++++++----------------
 12 files changed, 60 insertions(+), 90 deletions(-)
---
diff --git a/gtk/gtkcellview.c b/gtk/gtkcellview.c
index 5d20e23..6c02a23 100644
--- a/gtk/gtkcellview.c
+++ b/gtk/gtkcellview.c
@@ -649,16 +649,14 @@ gtk_cell_view_snapshot (GtkWidget   *widget,
 {
   GtkCellView *cellview;
   GdkRectangle area;
-  GdkRectangle allocation;
   GtkCellRendererState state;
 
   cellview = GTK_CELL_VIEW (widget);
 
   /* render cells */
-  gtk_widget_get_content_allocation (widget, &area);
-  gtk_widget_get_allocation (widget, &allocation);
-  area.x -= allocation.x;
-  area.y -= allocation.y;
+  area.x = 0;
+  area.y = 0;
+  gtk_widget_get_content_size (widget, &area.width, &area.height);
 
   /* set cell data (if available) */
   if (cellview->priv->displayed_row)
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 1ef28b9..e1bc2ba 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3255,17 +3255,11 @@ gtk_entry_snapshot (GtkWidget   *widget,
 {
   GtkEntry *entry = GTK_ENTRY (widget);
   GtkEntryPrivate *priv = gtk_entry_get_instance_private (entry);
-  GtkAllocation allocation;
-  GtkAllocation content_allocation;
+  int width, height;
   cairo_t *cr;
   int i;
 
-  gtk_widget_get_content_allocation (widget, &content_allocation);
-  gtk_widget_get_allocation (widget, &allocation);
-
-  allocation.x = content_allocation.x - allocation.x;
-  allocation.y = content_allocation.y - allocation.y;
-  allocation.height = content_allocation.height;
+  gtk_widget_get_content_size (widget, &width, &height);
 
   /* Draw progress */
   if (priv->progress_widget && gtk_widget_get_visible (priv->progress_widget))
@@ -3276,7 +3270,7 @@ gtk_entry_snapshot (GtkWidget   *widget,
                                   &GRAPHENE_RECT_INIT (priv->text_x,
                                                        0,
                                                        priv->text_width,
-                                                       allocation.height),
+                                                       height),
                                   "Entry Text");
 
   if (priv->dnd_position != -1)
diff --git a/gtk/gtkflowbox.c b/gtk/gtkflowbox.c
index 50c3015..1132540 100644
--- a/gtk/gtkflowbox.c
+++ b/gtk/gtkflowbox.c
@@ -2348,16 +2348,13 @@ gtk_flow_box_snapshot (GtkWidget   *widget,
 {
   GtkFlowBox *box = GTK_FLOW_BOX (widget);
   GtkFlowBoxPrivate *priv = BOX_PRIV (box);
-  GtkAllocation allocation;
   int x, y, width, height;
 
   GTK_WIDGET_CLASS (gtk_flow_box_parent_class)->snapshot (widget, snapshot);
 
-  gtk_widget_get_content_allocation (widget, &allocation);
-  x = allocation.x;
-  y = allocation.y;
-  width = allocation.width;
-  height = allocation.height;
+  gtk_widget_get_content_size (widget, &width, &height);
+  x = 0;
+  y = 0;
 
   if (priv->rubberband_first && priv->rubberband_last)
     {
diff --git a/gtk/gtkframe.c b/gtk/gtkframe.c
index c2f6cd4..ff59bac 100644
--- a/gtk/gtkframe.c
+++ b/gtk/gtkframe.c
@@ -677,10 +677,10 @@ gtk_frame_real_compute_child_allocation (GtkFrame      *frame,
                                         GtkAllocation *child_allocation)
 {
   GtkFramePrivate *priv = frame->priv;
-  GtkAllocation allocation;
+  int frame_width, frame_height;
   gint height;
 
-  gtk_widget_get_content_allocation (GTK_WIDGET (frame), &allocation);
+  gtk_widget_get_content_size (GTK_WIDGET (frame), &frame_width, &frame_height);
 
   if (priv->label_widget)
     {
@@ -688,7 +688,7 @@ gtk_frame_real_compute_child_allocation (GtkFrame      *frame,
 
       gtk_widget_measure (priv->label_widget, GTK_ORIENTATION_HORIZONTAL, -1,
                           NULL, &nat_width, NULL, NULL);
-      width = MIN (allocation.width, nat_width);
+      width = MIN (frame_width, nat_width);
       gtk_widget_measure (priv->label_widget, GTK_ORIENTATION_VERTICAL, width,
                           &height, NULL, NULL, NULL);
     }
@@ -697,8 +697,8 @@ gtk_frame_real_compute_child_allocation (GtkFrame      *frame,
 
   child_allocation->x = 0;
   child_allocation->y = height;
-  child_allocation->width = MAX (1, allocation.width);
-  child_allocation->height = MAX (1, allocation.height - height);
+  child_allocation->width = MAX (1, frame_width);
+  child_allocation->height = MAX (1, frame_height - height);
 }
 
 static void
diff --git a/gtk/gtkicon.c b/gtk/gtkicon.c
index 2539b28..56b4fdd 100644
--- a/gtk/gtkicon.c
+++ b/gtk/gtkicon.c
@@ -46,13 +46,13 @@ gtk_icon_snapshot (GtkWidget   *widget,
 {
   GtkIcon *self = GTK_ICON (widget);
   GtkCssStyle *style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
-  GtkAllocation content_alloc;
+  int width, height;
 
-  gtk_widget_get_content_allocation (widget, &content_alloc);
+  gtk_widget_get_content_size (widget, &width, &height);
 
   gtk_css_style_snapshot_icon (style,
                                snapshot,
-                               content_alloc.width, content_alloc.height,
+                               width, height,
                                self->image);
 }
 
diff --git a/gtk/gtkimage.c b/gtk/gtkimage.c
index e831fb9..11fb9ea 100644
--- a/gtk/gtkimage.c
+++ b/gtk/gtkimage.c
@@ -1352,15 +1352,12 @@ gtk_image_snapshot (GtkWidget   *widget,
 {
   GtkImage *image = GTK_IMAGE (widget);
   GtkImagePrivate *priv = gtk_image_get_instance_private (image);
-  GtkAllocation content_allocation;
   int x, y, width, height;
   gint w, h, baseline;
 
-  gtk_widget_get_content_allocation (widget, &content_allocation);
+  gtk_widget_get_content_size (widget, &width, &height);
   x = 0;
   y = 0;
-  width = content_allocation.width;
-  height = content_allocation.height;
 
   _gtk_icon_helper_get_size (priv->icon_helper, &w, &h);
 
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 2f73500..aaf7edf 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -3299,11 +3299,11 @@ gtk_label_update_layout_width (GtkLabel *label)
 
   if (priv->ellipsize || priv->wrap)
     {
-      GtkAllocation allocation;
+      int width, height;
 
-      gtk_widget_get_content_allocation (GTK_WIDGET (label), &allocation);
+      gtk_widget_get_content_size (GTK_WIDGET (label), &width, &height);
 
-      pango_layout_set_width (priv->layout, allocation.width * PANGO_SCALE);
+      pango_layout_set_width (priv->layout, width * PANGO_SCALE);
     }
   else
     {
@@ -3635,7 +3635,6 @@ get_layout_location (GtkLabel  *label,
                      gint      *xp,
                      gint      *yp)
 {
-  GtkAllocation allocation;
   GtkWidget *widget;
   GtkLabelPrivate *priv;
   gint req_width, x, y;
@@ -3643,6 +3642,7 @@ get_layout_location (GtkLabel  *label,
   gfloat xalign, yalign;
   PangoRectangle logical;
   gint baseline, layout_baseline, baseline_offset;
+  int label_width, label_height;
 
   widget = GTK_WIDGET (label);
   priv   = label->priv;
@@ -3660,11 +3660,11 @@ get_layout_location (GtkLabel  *label,
   req_width  = logical.width;
   req_height = logical.height;
 
-  gtk_widget_get_content_allocation (widget, &allocation);
+  gtk_widget_get_content_size (widget, &label_width, &label_height);
 
   baseline = gtk_widget_get_allocated_baseline (widget);
 
-  x = floor ((xalign * (allocation.width - req_width)) - logical.x);
+  x = floor ((xalign * (label_width - req_width)) - logical.x);
 
   baseline_offset = 0;
   if (baseline != -1)
@@ -3688,9 +3688,9 @@ get_layout_location (GtkLabel  *label,
    *   middle".  You want to read the first line, at least, to get some context.
    */
   if (pango_layout_get_line_count (priv->layout) == 1)
-    y = floor ((allocation.height - req_height) * yalign) + baseline_offset;
+    y = floor ((label_height - req_height) * yalign) + baseline_offset;
   else
-    y = floor (MAX ((allocation.height - req_height) * yalign, 0)) + baseline_offset;
+    y = floor (MAX ((label_height - req_height) * yalign, 0)) + baseline_offset;
 
   if (xp)
     *xp = x;
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 2ab7ff0..1ac19c0 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -2809,18 +2809,14 @@ static void
 gtk_menu_snapshot (GtkWidget   *widget,
                    GtkSnapshot *snapshot)
 {
-  GtkAllocation allocation;
+  int width, height;
 
-  gtk_widget_get_content_allocation (widget, &allocation);
+  gtk_widget_get_content_size (widget, &width, &height);
 
   /* XXX The arrows *might* be missing here */
 
   gtk_snapshot_push_clip (snapshot,
-                          &GRAPHENE_RECT_INIT(
-                              0, 0,
-                              allocation.width, allocation.height
-                          ),
-                          "MenuClip");
+                          &GRAPHENE_RECT_INIT(0, 0, width, height), "MenuClip");
 
   GTK_WIDGET_CLASS (gtk_menu_parent_class)->snapshot (widget, snapshot);
 
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index e85c9cd..9e6320d 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -1721,16 +1721,16 @@ gtk_range_render_trough (GtkGizmo    *gizmo,
   GtkWidget *widget = gtk_widget_get_parent (GTK_WIDGET (gizmo));
   GtkRange *range = GTK_RANGE (widget);
   GtkRangePrivate *priv = range->priv;
-  GtkAllocation alloc;
+  int width, height;
 
-  gtk_widget_get_content_allocation (GTK_WIDGET (gizmo), &alloc);
+  gtk_widget_get_content_size (GTK_WIDGET (gizmo), &width, &height);
 
   /* HACK: GtkColorScale wants to draw its own trough
    * so we let it...
    */
   if (GTK_IS_COLOR_SCALE (widget))
     gtk_color_scale_snapshot_trough (GTK_COLOR_SCALE (widget), snapshot,
-                                     0, 0, alloc.width, alloc.height);
+                                     0, 0, width, height);
 
   if (priv->show_fill_level &&
       gtk_adjustment_get_upper (priv->adjustment) - gtk_adjustment_get_page_size (priv->adjustment) -
@@ -2758,7 +2758,7 @@ gtk_range_compute_slider_position (GtkRange     *range,
                                    GdkRectangle *slider_rect)
 {
   GtkRangePrivate *priv = range->priv;
-  GtkAllocation trough_content_alloc;
+  int trough_width, trough_height;
   int slider_width, slider_height, min_slider_size;
 
   gtk_widget_measure (priv->slider_widget,
@@ -2770,7 +2770,7 @@ gtk_range_compute_slider_position (GtkRange     *range,
                       &slider_height, NULL,
                       NULL, NULL);
 
-  gtk_widget_get_content_allocation (priv->trough_widget, &trough_content_alloc);
+  gtk_widget_get_content_size (priv->trough_widget, &trough_width, &trough_height);
 
   if (priv->orientation == GTK_ORIENTATION_VERTICAL)
     {
@@ -2779,14 +2779,14 @@ gtk_range_compute_slider_position (GtkRange     *range,
       /* Slider fits into the trough, with stepper_spacing on either side,
        * and the size/position based on the adjustment or fixed, depending.
        */
-      slider_rect->x = (int) floor ((trough_content_alloc.width - slider_width) / 2);
+      slider_rect->x = (int) floor ((trough_width - slider_width) / 2);
       slider_rect->width = slider_width;
 
       min_slider_size = slider_height;
 
       /* Compute slider position/length */
       top = 0;
-      bottom = top + trough_content_alloc.height;
+      bottom = top + trough_height;
 
       /* Scale slider half extends over the trough edge */
       if (GTK_IS_SCALE (range))
@@ -2809,7 +2809,7 @@ gtk_range_compute_slider_position (GtkRange     *range,
           priv->slider_size_fixed)
         height = min_slider_size;
 
-      height = MIN (height, trough_content_alloc.height);
+      height = MIN (height, trough_height);
       
       y = top;
 
@@ -2832,14 +2832,14 @@ gtk_range_compute_slider_position (GtkRange     *range,
       /* Slider fits into the trough, with stepper_spacing on either side,
        * and the size/position based on the adjustment or fixed, depending.
        */
-      slider_rect->y = (int) floor ((trough_content_alloc.height - slider_height) / 2);
+      slider_rect->y = (int) floor ((trough_height - slider_height) / 2);
       slider_rect->height = slider_height;
 
       min_slider_size = slider_width;
 
       /* Compute slider position/length */
       left = 0;
-      right = left + trough_content_alloc.width;
+      right = left + trough_width;
 
       /* Scale slider half extends over the trough edge */
       if (GTK_IS_SCALE (range))
@@ -2862,7 +2862,7 @@ gtk_range_compute_slider_position (GtkRange     *range,
           priv->slider_size_fixed)
         width = min_slider_size;
 
-      width = MIN (width, trough_content_alloc.width);
+      width = MIN (width, trough_width);
 
       x = left;
 
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index cb2276c..7114b54 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -719,17 +719,17 @@ static gint
 get_bin_window_x (GtkStack *stack)
 {
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
-  GtkAllocation allocation;
+  int width, height;
   int x = 0;
 
-  gtk_widget_get_content_allocation (GTK_WIDGET (stack), &allocation);
+  gtk_widget_get_content_size (GTK_WIDGET (stack), &width, &height);
 
   if (gtk_progress_tracker_get_state (&priv->tracker) != GTK_PROGRESS_STATE_AFTER)
     {
       if (is_left_transition (priv->active_transition_type))
-        x = allocation.width * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
+        x = width * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
       if (is_right_transition (priv->active_transition_type))
-        x = -allocation.width * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
+        x = -width * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
     }
 
   return x;
@@ -739,17 +739,17 @@ static gint
 get_bin_window_y (GtkStack *stack)
 {
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
-  GtkAllocation allocation;
+  int width, height;
   int y = 0;
 
-  gtk_widget_get_content_allocation (GTK_WIDGET (stack), &allocation);
+  gtk_widget_get_content_size (GTK_WIDGET (stack), &width, &height);
 
   if (gtk_progress_tracker_get_state (&priv->tracker) != GTK_PROGRESS_STATE_AFTER)
     {
       if (is_up_transition (priv->active_transition_type))
-        y = allocation.height * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
+        y = height * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
       if (is_down_transition(priv->active_transition_type))
-        y = -allocation.height * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
+        y = -height * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
     }
 
   return y;
diff --git a/gtk/gtktoolpalette.c b/gtk/gtktoolpalette.c
index fdae646..90e0699 100644
--- a/gtk/gtktoolpalette.c
+++ b/gtk/gtktoolpalette.c
@@ -847,17 +847,12 @@ static void
 gtk_tool_palette_snapshot (GtkWidget   *widget,
                            GtkSnapshot *snapshot)
 {
-  GtkAllocation content_allocation;
+  int width, height;
 
-  gtk_widget_get_content_allocation (widget, &content_allocation);
+  gtk_widget_get_content_size (widget, &width, &height);
 
   gtk_snapshot_push_clip (snapshot,
-                          &GRAPHENE_RECT_INIT(
-                            content_allocation.x,
-                            content_allocation.y,
-                            content_allocation.width,
-                            content_allocation.height),
-                          "ToolPalette Clip");
+                          &GRAPHENE_RECT_INIT(0, 0, width, height), "ToolPalette Clip");
 
   GTK_WIDGET_CLASS (gtk_tool_palette_parent_class)->snapshot (widget, snapshot);
 
diff --git a/gtk/gtkviewport.c b/gtk/gtkviewport.c
index 3bf7349..e633844 100644
--- a/gtk/gtkviewport.c
+++ b/gtk/gtkviewport.c
@@ -120,19 +120,19 @@ viewport_set_adjustment_values (GtkViewport    *viewport,
   GtkScrollablePolicy scroll_policy;
   GtkScrollablePolicy other_scroll_policy;
   GtkOrientation other_orientation;
-  GtkAllocation view_allocation;
   GtkWidget *child;
   gdouble upper, value;
   int viewport_size, other_viewport_size;
+  int view_width, view_height;
 
-  gtk_widget_get_content_allocation (GTK_WIDGET (viewport), &view_allocation);
+  gtk_widget_get_content_size (GTK_WIDGET (viewport), &view_width, &view_height);
 
   if (orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       adjustment = priv->hadjustment;
       other_orientation = GTK_ORIENTATION_VERTICAL;
-      viewport_size = view_allocation.width;
-      other_viewport_size = view_allocation.height;
+      viewport_size = view_width;
+      other_viewport_size = view_height;
       scroll_policy = priv->hscroll_policy;
       other_scroll_policy = priv->vscroll_policy;
     }
@@ -140,8 +140,8 @@ viewport_set_adjustment_values (GtkViewport    *viewport,
     {
       adjustment = priv->vadjustment;
       other_orientation = GTK_ORIENTATION_HORIZONTAL;
-      viewport_size = view_allocation.height;
-      other_viewport_size = view_allocation.width;
+      viewport_size = view_height;
+      other_viewport_size = view_width;
       scroll_policy = priv->vscroll_policy;
       other_scroll_policy = priv->hscroll_policy;
     }
@@ -490,19 +490,12 @@ static void
 gtk_viewport_snapshot (GtkWidget   *widget,
                        GtkSnapshot *snapshot)
 {
-  GtkAllocation content_allocation;
-  GtkAllocation widget_allocation;
+  int width, height;
 
-  gtk_widget_get_content_allocation (widget, &content_allocation);
-  gtk_widget_get_allocation (widget, &widget_allocation);
+  gtk_widget_get_content_size (widget, &width, &height);
 
   gtk_snapshot_push_clip (snapshot,
-                          &GRAPHENE_RECT_INIT(
-                            content_allocation.x - widget_allocation.x,
-                            content_allocation.y - widget_allocation.y,
-                            content_allocation.width,
-                            content_allocation.height),
-                          "Viewport");
+                          &GRAPHENE_RECT_INIT(0, 0, width, height), "Viewport");
 
   GTK_WIDGET_CLASS (gtk_viewport_parent_class)->snapshot (widget, snapshot);
 


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