[gtk+] container: Implement gtk_container_propagate_draw() without fallbacks



commit 7947b3faf830f03e4c9a407708221c45cfe7bc00
Author: Benjamin Otte <otte redhat com>
Date:   Fri Sep 10 21:03:58 2010 +0200

    container: Implement gtk_container_propagate_draw() without fallbacks
    
    No more fallbacks to gtk_container_propagate_expose().

 gtk/gtkcontainer.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 46 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 8800ecb..2a6855e 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -2831,6 +2831,9 @@ gtk_container_propagate_draw (GtkContainer   *container,
                               cairo_t        *cr)
 {
   GdkEventExpose *event;
+  GtkAllocation allocation;
+  GdkWindow *window, *w;
+  int x, y;
 
   g_return_if_fail (GTK_IS_CONTAINER (container));
   g_return_if_fail (GTK_IS_WIDGET (child));
@@ -2841,15 +2844,54 @@ gtk_container_propagate_draw (GtkContainer   *container,
   event = _gtk_cairo_get_event (cr);
   if (event)
     {
-      gtk_container_propagate_expose (container, child, event);
+      if (gtk_widget_get_has_window (child) ||
+          gtk_widget_get_window (child) != event->window)
+        return;
+    }
+
+  cairo_save (cr);
+
+  /* translate coordinates. Ugly business, that. */
+  if (!gtk_widget_get_has_window (GTK_WIDGET (container)))
+    {
+      gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
+      x = -allocation.x;
+      y = -allocation.y;
     }
   else
     {
-      /* XXX: Needs gtk_widget_draw(), but can only happen once
-       * that function exists */
-      g_assert_not_reached ();
+      x = 0;
+      y = 0;
+    }
+
+  window = gtk_widget_get_window (GTK_WIDGET (container));
+  
+  for (w = gtk_widget_get_window (child); w && w != window; w = gdk_window_get_parent (w))
+    {
+      int wx, wy;
+      gdk_window_get_position (w, &wx, &wy);
+      x += wx;
+      y += wy;
     }
 
+  if (w == NULL)
+    {
+      x = 0;
+      y = 0;
+    }
+
+  if (!gtk_widget_get_has_window (child))
+    {
+      gtk_widget_get_allocation (child, &allocation);
+      x += allocation.x;
+      y += allocation.y;
+    }
+
+  cairo_translate (cr, x, y);
+
+  _gtk_widget_draw_internal (child, cr, TRUE);
+
+  cairo_restore (cr);
 }
 
 /**



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