[gtk+/wip/baedert/drawing] Fix a few allocation coordinates & sizes



commit 052b2c3ea61ba893e935c5b9f6dd7a9f0f5f6ed6
Author: Timm Bäder <mail baedert org>
Date:   Wed Jun 28 08:19:35 2017 +0200

    Fix a few allocation coordinates & sizes

 gtk/gtkcolorswatch.c     |   12 ++--------
 gtk/gtkentrycompletion.c |    3 +-
 gtk/gtklistbox.c         |    4 +-
 gtk/gtkmenu.c            |    7 +-----
 gtk/gtkrange.c           |   13 ++++-------
 gtk/gtkscale.c           |    8 +++---
 gtk/gtkscrolledwindow.c  |    8 +------
 gtk/gtkstack.c           |   47 +++++++++++++++++++++++----------------------
 gtk/gtkstackswitcher.c   |   14 ++++--------
 9 files changed, 47 insertions(+), 69 deletions(-)
---
diff --git a/gtk/gtkcolorswatch.c b/gtk/gtkcolorswatch.c
index dd5c493..507039c 100644
--- a/gtk/gtkcolorswatch.c
+++ b/gtk/gtkcolorswatch.c
@@ -98,22 +98,16 @@ swatch_snapshot (GtkWidget   *widget,
     {
       cairo_pattern_t *pattern;
       cairo_matrix_t matrix;
-      GtkAllocation allocation, border_allocation;
+      GtkAllocation border_allocation;
       GskRoundedRect content_box;
 
-      gtk_widget_get_allocation (widget, &allocation);
-      /* TODO: This should be the border allocation */
-      gtk_widget_get_allocation (widget, &border_allocation);
-
-      border_allocation.x -= allocation.x;
-      border_allocation.y -= allocation.y;
+      gtk_widget_get_border_allocation (widget, &border_allocation);
 
       gtk_rounded_boxes_init_for_style (NULL,
                                         NULL,
                                         &content_box,
                                         gtk_style_context_lookup_style (context),
-                                        border_allocation.x,
-                                        border_allocation.y,
+                                        0, 0,
                                         border_allocation.width,
                                         border_allocation.height);
       gtk_snapshot_push_rounded_clip (snapshot,
diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c
index 856cf0e..6b45e67 100644
--- a/gtk/gtkentrycompletion.c
+++ b/gtk/gtkentrycompletion.c
@@ -86,6 +86,7 @@
 
 #include "gtkprivate.h"
 #include "gtkwindowprivate.h"
+#include "gtkwidgetprivate.h"
 
 #include <string.h>
 
@@ -1515,7 +1516,7 @@ _gtk_entry_completion_resize_popup (GtkEntryCompletion *completion)
   if (!completion->priv->filter_model)
     return;
 
-  gtk_widget_get_allocation (completion->priv->entry, &allocation);
+  gtk_widget_get_window_allocation (completion->priv->entry, &allocation);
   gtk_widget_get_preferred_size (completion->priv->entry,
                                  &entry_req, NULL);
 
diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c
index ee5de48..12d76fe 100644
--- a/gtk/gtklistbox.c
+++ b/gtk/gtklistbox.c
@@ -1440,7 +1440,7 @@ ensure_row_visible (GtkListBox    *box,
   if (!priv->adjustment)
     return;
 
-  gtk_widget_get_allocation (GTK_WIDGET (row), &allocation);
+  gtk_widget_get_outer_allocation (GTK_WIDGET (row), &allocation);
   y = allocation.y;
   height = allocation.height;
 
@@ -1448,7 +1448,7 @@ ensure_row_visible (GtkListBox    *box,
   header = ROW_PRIV (row)->header;
   if (GTK_IS_WIDGET (header) && gtk_widget_is_drawable (header))
     {
-      gtk_widget_get_allocation (header, &allocation);
+      gtk_widget_get_outer_allocation (header, &allocation);
       y = allocation.y;
       height += allocation.height;
     }
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 368fad7..7f6a5a0 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -2560,14 +2560,9 @@ static void
 gtk_menu_realize (GtkWidget *widget)
 {
   GtkMenu *menu = GTK_MENU (widget);
-  GtkAllocation allocation;
-  GtkBorder arrow_border;
 
   GTK_WIDGET_CLASS (gtk_menu_parent_class)->realize (widget);
 
-  gtk_widget_get_allocation (widget, &allocation);
-  get_arrows_border (menu, &arrow_border);
-
   if (GTK_MENU_SHELL (widget)->priv->active_menu_item)
     gtk_menu_scroll_item_visible (GTK_MENU_SHELL (widget),
                                   GTK_MENU_SHELL (widget)->priv->active_menu_item);
@@ -3160,7 +3155,7 @@ definitely_within_item (GtkWidget *widget,
   GtkAllocation allocation;
   int w, h;
 
-  gtk_widget_get_allocation (widget, &allocation);
+  gtk_widget_get_outer_allocation (widget, &allocation);
   w = allocation.width;
   h = allocation.height;
 
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 9e6320d..f74f1b2 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -1412,15 +1412,12 @@ gtk_range_allocate_trough (GtkGizmo            *gizmo,
   GtkWidget *widget = gtk_widget_get_parent (GTK_WIDGET (gizmo));
   GtkRange *range = GTK_RANGE (widget);
   GtkRangePrivate *priv = range->priv;
-  GtkAllocation slider_alloc, widget_alloc;
-  GtkAllocation trough_alloc;
+  GtkAllocation slider_alloc;
   double value;
 
   /* Slider */
   gtk_range_calc_marks (range);
 
-  gtk_widget_get_allocation (widget, &widget_alloc);
-  gtk_widget_get_allocation (GTK_WIDGET (gizmo), &trough_alloc);
   gtk_range_compute_slider_position (range,
                                      gtk_adjustment_get_value (priv->adjustment),
                                      &slider_alloc);
@@ -2358,19 +2355,19 @@ update_autoscroll_mode (GtkRange *range)
 
   if (range->priv->zoom)
     {
-      GtkAllocation allocation;
+      int width, height;
       gint size, pos;
 
-      gtk_widget_get_allocation (GTK_WIDGET (range), &allocation);
+      gtk_widget_get_content_size (GTK_WIDGET (range), &width, &height);
 
       if (range->priv->orientation == GTK_ORIENTATION_VERTICAL)
         {
-          size = allocation.height;
+          size = height;
           pos = range->priv->mouse_y;
         }
       else
         {
-          size = allocation.width;
+          size = width;
           pos = range->priv->mouse_x;
         }
 
diff --git a/gtk/gtkscale.c b/gtk/gtkscale.c
index 8b5442b..75fd355 100644
--- a/gtk/gtkscale.c
+++ b/gtk/gtkscale.c
@@ -485,9 +485,9 @@ find_next_pos (GtkWidget       *widget,
                gint            *marks,
                GtkPositionType  pos)
 {
-  GtkAllocation allocation;
   GSList *m;
   gint i;
+  int width, height;
 
   for (m = list->next, i = 1; m; m = m->next, i++)
     {
@@ -497,11 +497,11 @@ find_next_pos (GtkWidget       *widget,
         return marks[i];
     }
 
-  gtk_widget_get_allocation (widget, &allocation);
+  gtk_widget_get_content_size (widget, &width, &height);
   if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_HORIZONTAL)
-    return allocation.width;
+    return width;
   else
-    return allocation.height;
+    return height;
 }
 
 static void
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index a9c1303..14efd37 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -1083,7 +1083,7 @@ event_close_to_indicator (GtkScrolledWindow *sw,
 
   priv = sw->priv;
 
-  gtk_widget_get_allocation (indicator->scrollbar, &indicator_alloc);
+  gtk_widget_get_outer_allocation (indicator->scrollbar, &indicator_alloc);
   gdk_event_get_coords (event, &x, &y);
 
   if (indicator->over)
@@ -1354,14 +1354,11 @@ gtk_scrolled_window_size_allocate (GtkWidget     *widget,
   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
   GtkBin *bin;
   GtkAllocation child_allocation;
-  GtkAllocation sw_allocation;
   GtkWidget *child;
   gint sb_width;
   gint sb_height;
 
   bin = GTK_BIN (scrolled_window);
-  gtk_widget_get_allocation (GTK_WIDGET (scrolled_window), &sw_allocation);
-
 
   /* Get possible scrollbar dimensions */
   gtk_widget_measure (priv->vscrollbar, GTK_ORIENTATION_HORIZONTAL, -1,
@@ -3985,9 +3982,6 @@ gtk_scrolled_window_realize (GtkWidget *widget)
 {
   GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (widget);
   GtkScrolledWindowPrivate *priv = scrolled_window->priv;
-  GtkAllocation allocation;
-
-  gtk_widget_get_allocation (widget, &allocation);
 
   priv->hindicator.scrollbar = priv->hscrollbar;
   priv->vindicator.scrollbar = priv->vscrollbar;
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index 6855e67..baa56d4 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -1834,35 +1834,34 @@ gtk_stack_snapshot_under (GtkWidget   *widget,
 {
   GtkStack *stack = GTK_STACK (widget);
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
-  GtkAllocation allocation;
+  int widget_width, widget_height;
   gint x, y, width, height, pos_x, pos_y;
 
-  gtk_widget_get_allocation (widget, &allocation);
+
+  gtk_widget_get_content_size (widget, &widget_width, &widget_height);
   x = y = 0;
-  width = allocation.width;
-  height = allocation.height;
   pos_x = pos_y = 0;
 
   switch (priv->active_transition_type)
     {
     case GTK_STACK_TRANSITION_TYPE_UNDER_DOWN:
       y = 0;
-      height = allocation.height * (gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
+      height = widget_height * (gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
       pos_y = height;
       break;
     case GTK_STACK_TRANSITION_TYPE_UNDER_UP:
-      y = allocation.height * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
-      height = allocation.height - y;
-      pos_y = y - allocation.height;
+      y = widget_height * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
+      height = widget_height - y;
+      pos_y = y - widget_height;
       break;
     case GTK_STACK_TRANSITION_TYPE_UNDER_LEFT:
-      x = allocation.width * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
-      width = allocation.width - x;
-      pos_x = x - allocation.width;
+      x = widget_width * (1 - gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
+      width = widget_width - x;
+      pos_x = x - widget_width;
       break;
     case GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT:
       x = 0;
-      width = allocation.width * (gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
+      width = widget_width * (gtk_progress_tracker_get_ease_out_cubic (&priv->tracker, FALSE));
       pos_x = width;
       break;
     default:
@@ -1900,11 +1899,11 @@ gtk_stack_snapshot_slide (GtkWidget   *widget,
 
   if (priv->last_visible_node)
     {
-      GtkAllocation allocation;
       graphene_matrix_t matrix;
       int x, y;
+      int width, height;
 
-      gtk_widget_get_allocation (widget, &allocation);
+      gtk_widget_get_content_size (widget, &width, &height);
 
       x = get_bin_window_x (stack);
       y = get_bin_window_y (stack);
@@ -1912,16 +1911,16 @@ gtk_stack_snapshot_slide (GtkWidget   *widget,
       switch (priv->active_transition_type)
         {
         case GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT:
-          x -= allocation.width;
+          x -= width;
           break;
         case GTK_STACK_TRANSITION_TYPE_SLIDE_RIGHT:
-          x += allocation.width;
+          x += width;
           break;
         case GTK_STACK_TRANSITION_TYPE_SLIDE_UP:
-          y -= allocation.height;
+          y -= height;
           break;
         case GTK_STACK_TRANSITION_TYPE_SLIDE_DOWN:
-          y += allocation.height;
+          y += height;
           break;
         case GTK_STACK_TRANSITION_TYPE_OVER_UP:
         case GTK_STACK_TRANSITION_TYPE_OVER_DOWN:
@@ -1937,10 +1936,10 @@ gtk_stack_snapshot_slide (GtkWidget   *widget,
         }
 
       if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_END &&
-          priv->last_visible_widget_height > allocation.height)
-        y -= priv->last_visible_widget_height - allocation.height;
+          priv->last_visible_widget_height > height)
+        y -= priv->last_visible_widget_height - height;
       else if (gtk_widget_get_valign (priv->last_visible_child->widget) == GTK_ALIGN_CENTER)
-        y -= (priv->last_visible_widget_height - allocation.height) / 2;
+        y -= (priv->last_visible_widget_height - height) / 2;
 
       graphene_matrix_init_translate (&matrix, &GRAPHENE_POINT3D_INIT (x, y, 0));
       gtk_snapshot_push_transform (snapshot, &matrix, "StackSlide");
@@ -1964,6 +1963,8 @@ gtk_stack_snapshot (GtkWidget   *widget,
     {
       if (gtk_progress_tracker_get_state (&priv->tracker) != GTK_PROGRESS_STATE_AFTER)
         {
+          int width, height;
+
           if (priv->last_visible_node == NULL &&
               priv->last_visible_child != NULL)
             {
@@ -1980,11 +1981,11 @@ gtk_stack_snapshot (GtkWidget   *widget,
               priv->last_visible_node = gtk_snapshot_finish (&last_visible_snapshot);
             }
 
+          gtk_widget_get_content_size (widget, &width, &height);
           gtk_snapshot_push_clip (snapshot,
                                   &GRAPHENE_RECT_INIT(
                                       0, 0,
-                                      gtk_widget_get_allocated_width (widget),
-                                      gtk_widget_get_allocated_height (widget)
+                                      width, height
                                   ),
                                   "StackAnimationClip");
 
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index 37678fd..19c887f 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -26,6 +26,7 @@
 #include "gtkorientable.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
+#include "gtkwidgetprivate.h"
 
 /**
  * SECTION:gtkstackswitcher
@@ -294,26 +295,21 @@ gtk_stack_switcher_drag_motion (GtkWidget      *widget,
 {
   GtkStackSwitcher *self = GTK_STACK_SWITCHER (widget);
   GtkStackSwitcherPrivate *priv;
-  GtkAllocation allocation;
   GtkWidget *button;
   GHashTableIter iter;
   gpointer value;
   gboolean retval = FALSE;
 
-  gtk_widget_get_allocation (widget, &allocation);
-
   priv = gtk_stack_switcher_get_instance_private (self);
 
-  x += allocation.x;
-  y += allocation.y;
-
   button = NULL;
   g_hash_table_iter_init (&iter, priv->buttons);
   while (g_hash_table_iter_next (&iter, NULL, &value))
     {
-      gtk_widget_get_allocation (GTK_WIDGET (value), &allocation);
-      if (x >= allocation.x && x <= allocation.x + allocation.width &&
-          y >= allocation.y && y <= allocation.y + allocation.height)
+      GdkRectangle allocation;
+
+      gtk_widget_get_outer_allocation (GTK_WIDGET (value), &allocation);
+      if (gdk_rectangle_contains_point (&allocation, (int)x, (int)y))
         {
           button = GTK_WIDGET (value);
           retval = TRUE;


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