[gtk+/wip/baedert/drawing: 10/142] Slightly rework clip handling



commit 56099333af13eefedfdbf3e20022f63f785623be
Author: Timm Bäder <mail baedert org>
Date:   Fri May 5 14:06:01 2017 +0200

    Slightly rework clip handling
    
    always initialize clips to the (content) allocation, don't walk up the
    widget hierarchy in gtk_widget_set_clip, implement
    gtk_widget_size_allocate in GtkSeparator. This way we don't end up using
    uninitialized clip values.
    
    The entire clip handling is up for major rework since we can't and don't
    want to force every single widget to call _set_clip in size-allocate
    implementations.

 gtk/gtkactionbar.c   |    2 +-
 gtk/gtkcenterbox.c   |    3 ---
 gtk/gtkcheckbutton.c |    2 +-
 gtk/gtkcombobox.c    |    2 +-
 gtk/gtkgrid.c        |    2 +-
 gtk/gtkicon.c        |    2 +-
 gtk/gtklevelbar.c    |    4 +---
 gtk/gtknotebook.c    |    4 +---
 gtk/gtkseparator.c   |    9 +++++++++
 gtk/gtkspinbutton.c  |    2 +-
 gtk/gtkstack.c       |    4 +---
 gtk/gtkwidget.c      |   19 +------------------
 12 files changed, 19 insertions(+), 36 deletions(-)
---
diff --git a/gtk/gtkactionbar.c b/gtk/gtkactionbar.c
index 0e50eb1..f31bdc1 100644
--- a/gtk/gtkactionbar.c
+++ b/gtk/gtkactionbar.c
@@ -272,7 +272,7 @@ gtk_action_bar_size_allocate (GtkWidget     *widget,
                               GtkAllocation *allocation)
 {
   GtkActionBarPrivate *priv = gtk_action_bar_get_instance_private (GTK_ACTION_BAR (widget));
-  GtkAllocation clip;
+  GtkAllocation clip = *allocation;
 
   gtk_widget_size_allocate (priv->revealer, (GtkAllocation *)allocation);
   gtk_widget_get_clip (priv->revealer, &clip);
diff --git a/gtk/gtkcenterbox.c b/gtk/gtkcenterbox.c
index 316126c..4fec4ee 100644
--- a/gtk/gtkcenterbox.c
+++ b/gtk/gtkcenterbox.c
@@ -74,9 +74,6 @@ gtk_center_box_size_allocate (GtkWidget     *widget,
   int start_size, end_size;
   int min, nat;
 
-  GTK_WIDGET_CLASS (gtk_center_box_parent_class)->size_allocate (widget, allocation);
-
-
   // TODO: Allocate natural sizes if possible?
 
   /* Start Box */
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index 691b740..3b3c52b 100644
--- a/gtk/gtkcheckbutton.c
+++ b/gtk/gtkcheckbutton.c
@@ -415,7 +415,7 @@ gtk_check_button_size_allocate (GtkWidget     *widget,
                                GtkAllocation *allocation)
 {
   GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
-  GdkRectangle clip;
+  GdkRectangle clip = *allocation;
 
   if (priv->draw_indicator)
     {
diff --git a/gtk/gtkcombobox.c b/gtk/gtkcombobox.c
index b367b0a..f5c7ce4 100644
--- a/gtk/gtkcombobox.c
+++ b/gtk/gtkcombobox.c
@@ -372,7 +372,7 @@ gtk_combo_box_size_allocate (GtkWidget     *widget,
 {
   GtkComboBox *combo_box = GTK_COMBO_BOX (widget);
   GtkComboBoxPrivate *priv = combo_box->priv;
-  GtkAllocation clip;
+  GtkAllocation clip = *allocation;
 
   gtk_widget_size_allocate_with_baseline (priv->box, allocation,
                                           gtk_widget_get_allocated_baseline (widget));
diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c
index f41054a..937f3bb 100644
--- a/gtk/gtkgrid.c
+++ b/gtk/gtkgrid.c
@@ -1588,7 +1588,7 @@ gtk_grid_size_allocate (GtkWidget     *widget,
                         GtkAllocation *allocation)
 {
   GtkAllocation clip = *allocation;
-  GtkAllocation children_clip;
+  GtkAllocation children_clip = *allocation;
   GtkGrid *grid = GTK_GRID (widget);
   GtkGridPrivate *priv = grid->priv;
   GtkGridRequest request;
diff --git a/gtk/gtkicon.c b/gtk/gtkicon.c
index c22c071..1ea9fd3 100644
--- a/gtk/gtkicon.c
+++ b/gtk/gtkicon.c
@@ -118,7 +118,7 @@ gtk_icon_size_allocate (GtkWidget     *widget,
 {
   GtkIcon *self = GTK_ICON (widget);
   GtkIconPrivate *priv = gtk_icon_get_instance_private (self);
-  GtkAllocation clip;
+  GtkAllocation clip = *allocation;
 
   gtk_css_gadget_allocate (priv->gadget, allocation,
                            gtk_widget_get_allocated_baseline (widget),
diff --git a/gtk/gtklevelbar.c b/gtk/gtklevelbar.c
index 6cc32e4..077ea00 100644
--- a/gtk/gtklevelbar.c
+++ b/gtk/gtklevelbar.c
@@ -534,9 +534,7 @@ gtk_level_bar_size_allocate (GtkWidget     *widget,
                              GtkAllocation *allocation)
 {
   GtkLevelBarPrivate *priv = gtk_level_bar_get_instance_private (GTK_LEVEL_BAR (widget));
-  GtkAllocation clip;
-
-  GTK_WIDGET_CLASS (gtk_level_bar_parent_class)->size_allocate (widget, allocation);
+  GtkAllocation clip = *allocation;
 
   gtk_widget_size_allocate (priv->trough_widget, allocation);
   gtk_widget_get_clip (priv->trough_widget, &clip);
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 3aba5ba..ede9add 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -2264,9 +2264,7 @@ gtk_notebook_size_allocate (GtkWidget     *widget,
 {
   GtkNotebook *notebook = GTK_NOTEBOOK (widget);
   GtkNotebookPrivate *priv = notebook->priv;
-  GtkAllocation clip;
-
-  gtk_widget_set_allocation (widget, allocation);
+  GtkAllocation clip = *allocation;
 
   gtk_css_gadget_allocate (priv->gadget,
                            allocation,
diff --git a/gtk/gtkseparator.c b/gtk/gtkseparator.c
index ebb2f50..5306b8e 100644
--- a/gtk/gtkseparator.c
+++ b/gtk/gtkseparator.c
@@ -124,11 +124,20 @@ gtk_separator_init (GtkSeparator *separator)
 }
 
 static void
+gtk_separator_size_allocate (GtkWidget     *widget,
+                             GtkAllocation *allocation)
+{
+  gtk_widget_set_clip (widget, allocation);
+}
+
+static void
 gtk_separator_class_init (GtkSeparatorClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
+  widget_class->size_allocate = gtk_separator_size_allocate;
+
   object_class->set_property = gtk_separator_set_property;
   object_class->get_property = gtk_separator_get_property;
 
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index a105a3a..f8ba5d0 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -1057,7 +1057,7 @@ gtk_spin_button_size_allocate (GtkWidget     *widget,
                                GtkAllocation *allocation)
 {
   GtkSpinButtonPrivate *priv = gtk_spin_button_get_instance_private (GTK_SPIN_BUTTON (widget));
-  GtkAllocation clip;
+  GtkAllocation clip = *allocation;
 
   gtk_widget_size_allocate_with_baseline (priv->box, allocation,
                                           gtk_widget_get_allocated_baseline (widget));
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index 4a0d6f9..8b9d160 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -2120,9 +2120,7 @@ gtk_stack_size_allocate (GtkWidget     *widget,
 {
   GtkStack *stack = GTK_STACK (widget);
   GtkStackPrivate *priv = gtk_stack_get_instance_private (stack);
-  GtkAllocation clip;
-
-  gtk_widget_set_allocation (widget, allocation);
+  GtkAllocation clip = *allocation;
 
   gtk_css_gadget_allocate (priv->gadget,
                            allocation,
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 3887f3b..2ebb922 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -3853,6 +3853,7 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
   priv->allocation.y = -1;
   priv->allocation.width = 1;
   priv->allocation.height = 1;
+  priv->clip = priv->allocation;
   priv->user_alpha = 255;
   priv->alpha = 255;
   priv->window = NULL;
@@ -13488,24 +13489,6 @@ gtk_widget_set_clip (GtkWidget           *widget,
   allocation.width += shadow.left + shadow.right;
   allocation.height += shadow.top + shadow.bottom;
   gdk_rectangle_union (&allocation, clip, &priv->clip);
-
-
-  while (priv->parent &&
-         _gtk_widget_get_window (widget) == _gtk_widget_get_window (priv->parent))
-    {
-      GtkWidgetPrivate *parent_priv = priv->parent->priv;
-      GdkRectangle union_rect;
-
-      gdk_rectangle_union (&priv->clip,
-                           &parent_priv->clip,
-                           &union_rect);
-
-      if (gdk_rectangle_equal (&parent_priv->clip, &union_rect))
-        break;
-
-      parent_priv->clip = union_rect;
-      priv = parent_priv;
-    }
 }
 
 /*


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