[gtk+/wip/clip: 6/6] widget: Add _gtk_widget_set_css_clip()



commit f2e659b11ce0403b27b0375bbe991cb88b5c2f3a
Author: Benjamin Otte <otte redhat com>
Date:   Wed May 21 23:13:52 2014 +0200

    widget: Add _gtk_widget_set_css_clip()
    
    ... and use it in GtkBox and GtkGrid.

 gtk/gtkbox.c           |    4 ++++
 gtk/gtkgrid.c          |    3 +++
 gtk/gtkwidget.c        |   43 +++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkwidgetprivate.h |    1 +
 4 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index 557d9fd..2878aa7 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -791,6 +791,8 @@ gtk_box_size_allocate_no_center (GtkWidget     *widget,
          i++;
        }
     }
+
+  _gtk_widget_set_css_clip (widget);
 }
 
 static void
@@ -1158,6 +1160,8 @@ gtk_box_size_allocate_with_center (GtkWidget     *widget,
       child_allocation.height = center_size;
     }
   gtk_widget_size_allocate_with_baseline (priv->center->widget, &child_allocation, baseline);
+
+  _gtk_widget_set_css_clip (widget);
 }
 
 static void
diff --git a/gtk/gtkgrid.c b/gtk/gtkgrid.c
index 5c93571..a404a30 100644
--- a/gtk/gtkgrid.c
+++ b/gtk/gtkgrid.c
@@ -24,6 +24,7 @@
 
 #include "gtkorientableprivate.h"
 #include "gtksizerequest.h"
+#include "gtkwidgetprivate.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
 
@@ -1677,6 +1678,8 @@ gtk_grid_size_allocate (GtkWidget     *widget,
   gtk_grid_request_position (&request, 1);
 
   gtk_grid_request_allocate_children (&request);
+
+  _gtk_widget_set_css_clip (widget);
 }
 
 static gboolean
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index b5bc1b8..2884378 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -14983,6 +14983,49 @@ _gtk_widget_is_clipped (GtkWidget *widget)
   return widget->priv->supports_clip;
 }
 
+static void
+union_with_clip (GtkWidget *widget,
+                 gpointer   clip)
+{
+  GtkAllocation widget_clip;
+
+  if (!gtk_widget_is_drawable (widget))
+    return;
+
+  _gtk_widget_get_clip (widget, &widget_clip);
+
+  gdk_rectangle_union (&widget_clip, clip, clip);
+}
+
+/**
+ * _gtk_widget_set_css_clip:
+ * @widget: 
+ *
+ * This is a convenience function for gtk_widget_set_clip(), if you
+ * just want to set the clip for @widget based on its allocation,
+ * CSS properties and - if the widget is a #GtkContainer - its
+ * children. gtk_widget_set_allocation() must have been called
+ * and all children must have been allocated with
+ * gtk_widget_size_allocate() before calling this function. It is
+ * therefor a good idea to call this function last in your
+ * implementation of GtkWidget::size_allocate().
+ *
+ * If your widget overdraws its contents, you cannot use this
+ * function and must call gtk_widget_set_clip() yourself.
+ **/
+void
+_gtk_widget_set_css_clip (GtkWidget *widget)
+{
+  GtkAllocation clip;
+
+  gtk_widget_get_allocation (widget, &clip);
+
+  if (GTK_IS_CONTAINER (widget))
+    gtk_container_forall (GTK_CONTAINER (widget), union_with_clip, &clip);
+
+  _gtk_widget_set_clip (widget, &clip);
+}
+
 /**
  * gtk_widget_get_allocation:
  * @widget: a #GtkWidget
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 21b51a4..5315c11 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -137,6 +137,7 @@ void              _gtk_widget_set_clip                     (GtkWidget
 void              _gtk_widget_get_clip                     (GtkWidget           *widget,
                                                             GtkAllocation       *allocation);  
 gboolean          _gtk_widget_supports_clip                (GtkWidget           *widget);
+void              _gtk_widget_set_css_clip                 (GtkWidget           *widget);
 
 typedef gboolean (*GtkCapturedEventHandler) (GtkWidget *widget, GdkEvent *event);
 


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