[gtk+/wip/baedert/children: 29/44] Move gtk_container_propagate_draw to GtkWidget



commit bfbd694cd0333301d932d6f831d021ea477ee102
Author: Timm Bäder <mail baedert org>
Date:   Tue Nov 22 19:58:55 2016 +0100

    Move gtk_container_propagate_draw to GtkWidget

 gtk/gtkboxgadget.c |    2 +-
 gtk/gtkcontainer.c |  101 +---------------------------------------------------
 gtk/gtkcontainer.h |    5 ---
 gtk/gtknotebook.c  |   14 ++++----
 gtk/gtkpaned.c     |    4 +-
 gtk/gtkstack.c     |   24 ++++++------
 gtk/gtktextview.c  |    6 ++--
 gtk/gtktoolbar.c   |    8 ++--
 gtk/gtktreeview.c  |   10 +++---
 gtk/gtkwidget.c    |   38 +++++++++++++++++++
 gtk/gtkwidget.h    |    5 +++
 11 files changed, 78 insertions(+), 139 deletions(-)
---
diff --git a/gtk/gtkboxgadget.c b/gtk/gtkboxgadget.c
index cfc67c3..4536b8f 100644
--- a/gtk/gtkboxgadget.c
+++ b/gtk/gtkboxgadget.c
@@ -508,7 +508,7 @@ gtk_box_gadget_draw (GtkCssGadget *gadget,
       GtkBoxGadgetChild *child = &g_array_index (priv->children, GtkBoxGadgetChild, draw_index);
 
       if (GTK_IS_WIDGET (child->object))
-        gtk_container_propagate_draw (GTK_CONTAINER (owner), GTK_WIDGET (child->object), cr);
+        gtk_widget_propagate_draw (owner, GTK_WIDGET (child->object), cr);
       else
         gtk_css_gadget_draw (GTK_CSS_GADGET (child->object), cr);
     }
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 6efc2a9..4f074c8 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -3055,7 +3055,7 @@ gtk_container_draw (GtkWidget *widget,
   for (i = 0; i < child_infos->len; i++)
     {
       child_info = &g_array_index (child_infos, ChildOrderInfo, i);
-      gtk_container_propagate_draw (container, child_info->child, cr);
+      gtk_widget_propagate_draw (widget, child_info->child, cr);
     }
 
   g_array_free (child_infos, TRUE);
@@ -3133,105 +3133,6 @@ gtk_container_get_children_clip (GtkContainer  *container,
   gtk_container_forall (container, union_with_clip, out_clip);
 }
 
-static void
-gtk_container_get_translation_to_child (GtkContainer *container,
-                                        GtkWidget    *child,
-                                        int          *x_out,
-                                        int          *y_out)
-{
-  GtkAllocation allocation;
-  GdkWindow *window, *w;
-  int x, y;
-
-  /* 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
-    {
-      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;
-    }
-
-  *x_out = x;
-  *y_out = y;
-}
-
-/**
- * gtk_container_propagate_draw:
- * @container: a #GtkContainer
- * @child: a child of @container
- * @cr: Cairo context as passed to the container. If you want to use @cr
- *   in container’s draw function, consider using cairo_save() and
- *   cairo_restore() before calling this function.
- *
- * When a container receives a call to the draw function, it must send
- * synthetic #GtkWidget::draw calls to all children that don’t have their
- * own #GdkWindows. This function provides a convenient way of doing this.
- * A container, when it receives a call to its #GtkWidget::draw function,
- * calls gtk_container_propagate_draw() once for each child, passing in
- * the @cr the container received.
- *
- * gtk_container_propagate_draw() takes care of translating the origin of @cr,
- * and deciding whether the draw needs to be sent to the child. It is a
- * convenient and optimized way of getting the same effect as calling
- * gtk_widget_draw() on the child directly.
- *
- * In most cases, a container can simply either inherit the
- * #GtkWidget::draw implementation from #GtkContainer, or do some drawing
- * and then chain to the ::draw implementation from #GtkContainer.
- **/
-void
-gtk_container_propagate_draw (GtkContainer *container,
-                              GtkWidget    *child,
-                              cairo_t      *cr)
-{
-  int x, y;
-
-  g_return_if_fail (GTK_IS_CONTAINER (container));
-  g_return_if_fail (GTK_IS_WIDGET (child));
-  g_return_if_fail (cr != NULL);
-  g_return_if_fail (_gtk_widget_get_parent (child) == GTK_WIDGET (container));
-
-  if (!gtk_container_should_propagate_draw (container, child, cr))
-    return;
-
-  gtk_container_get_translation_to_child (container, child, &x, &y);
-
-  cairo_save (cr);
-  cairo_translate (cr, x, y);
-
-  gtk_widget_draw_internal (child, cr, TRUE);
-
-  cairo_restore (cr);
-}
-
 /**
  * gtk_container_get_path_for_child:
  * @container: a #GtkContainer
diff --git a/gtk/gtkcontainer.h b/gtk/gtkcontainer.h
index 6725a80..42ad410 100644
--- a/gtk/gtkcontainer.h
+++ b/gtk/gtkcontainer.h
@@ -139,11 +139,6 @@ GDK_AVAILABLE_IN_ALL
 GList*   gtk_container_get_children     (GtkContainer       *container);
 
 GDK_AVAILABLE_IN_ALL
-void     gtk_container_propagate_draw   (GtkContainer   *container,
-                                        GtkWidget      *child,
-                                        cairo_t        *cr);
-
-GDK_AVAILABLE_IN_ALL
 void     gtk_container_set_focus_chain  (GtkContainer   *container,
                                          GList          *focusable_widgets);
 GDK_AVAILABLE_IN_ALL
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index 8909d18..a0a6183 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -2371,9 +2371,9 @@ gtk_notebook_draw_stack (GtkCssGadget *gadget,
   GtkNotebookPrivate *priv = notebook->priv;
 
   if (gtk_notebook_has_current_page (notebook))
-    gtk_container_propagate_draw (GTK_CONTAINER (notebook),
-                                  priv->cur_page->child,
-                                  cr);
+    gtk_widget_propagate_draw (widget,
+                               priv->cur_page->child,
+                               cr);
 
   return FALSE;
 }
@@ -3490,7 +3490,7 @@ on_drag_icon_draw (GtkWidget *widget,
                     requisition.height);
 
   if (child)
-    gtk_container_propagate_draw (GTK_CONTAINER (widget), child, cr);
+    gtk_widget_propagate_draw (widget, child, cr);
 
   gtk_style_context_restore (context);
 
@@ -4592,9 +4592,9 @@ draw_tab (GtkCssGadget *gadget,
 
   widget = gtk_css_gadget_get_owner (gadget);
 
-  gtk_container_propagate_draw (GTK_CONTAINER (widget),
-                                page->tab_label,
-                                cr);
+  gtk_widget_propagate_draw (widget,
+                             page->tab_label,
+                             cr);
 
   return gtk_widget_has_visible_focus (widget) &&
          GTK_NOTEBOOK (widget)->priv->cur_page == page;
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 1fadaf5..421a0fa 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -1679,7 +1679,7 @@ gtk_paned_render (GtkCssGadget *gadget,
                        gdk_window_get_width (priv->child1_window),
                        gdk_window_get_height (priv->child1_window));
       cairo_clip (cr);
-      gtk_container_propagate_draw (GTK_CONTAINER (widget), priv->child1, cr);
+      gtk_widget_propagate_draw (widget, priv->child1, cr);
       cairo_restore (cr);
     }
 
@@ -1693,7 +1693,7 @@ gtk_paned_render (GtkCssGadget *gadget,
                        gdk_window_get_width (priv->child2_window),
                        gdk_window_get_height (priv->child2_window));
       cairo_clip (cr);
-      gtk_container_propagate_draw (GTK_CONTAINER (widget), priv->child2, cr);
+      gtk_widget_propagate_draw (widget, priv->child2, cr);
       cairo_restore (cr);
     }
 
diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c
index 610b2f6..b3a9fc4 100644
--- a/gtk/gtkstack.c
+++ b/gtk/gtkstack.c
@@ -1933,9 +1933,9 @@ gtk_stack_draw_crossfade (GtkWidget *widget,
   gdouble progress = gtk_progress_tracker_get_progress (&priv->tracker, FALSE);
 
   cairo_push_group (cr);
-  gtk_container_propagate_draw (GTK_CONTAINER (stack),
-                                priv->visible_child->widget,
-                                cr);
+  gtk_widget_propagate_draw (widget,
+                             priv->visible_child->widget,
+                             cr);
   cairo_save (cr);
 
   /* Multiply alpha by progress */
@@ -2004,9 +2004,9 @@ gtk_stack_draw_under (GtkWidget *widget,
   cairo_rectangle (cr, x, y, width, height);
   cairo_clip (cr);
 
-  gtk_container_propagate_draw (GTK_CONTAINER (stack),
-                                priv->visible_child->widget,
-                                cr);
+  gtk_widget_propagate_draw (widget,
+                             priv->visible_child->widget,
+                             cr);
 
   cairo_restore (cr);
 
@@ -2077,9 +2077,9 @@ gtk_stack_draw_slide (GtkWidget *widget,
       cairo_restore (cr);
      }
 
-  gtk_container_propagate_draw (GTK_CONTAINER (stack),
-                                priv->visible_child->widget,
-                                cr);
+  gtk_widget_propagate_draw (widget,
+                             priv->visible_child->widget,
+                             cr);
 }
 
 static gboolean
@@ -2171,9 +2171,9 @@ gtk_stack_render (GtkCssGadget *gadget,
 
         }
       else
-        gtk_container_propagate_draw (GTK_CONTAINER (stack),
-                                      priv->visible_child->widget,
-                                      cr);
+        gtk_widget_propagate_draw (widget,
+                                   priv->visible_child->widget,
+                                   cr);
     }
 
   return FALSE;
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 7f4f79a..c76eaf9 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -5945,9 +5945,9 @@ gtk_text_view_draw (GtkWidget *widget,
       /* propagate_draw checks that event->window matches
        * child->window
        */
-      gtk_container_propagate_draw (GTK_CONTAINER (widget),
-                                    vc->widget,
-                                    cr);
+      gtk_widget_propagate_draw (widget,
+                                 vc->widget,
+                                 cr);
       
       tmp_list = tmp_list->next;
     }
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 03d887e..439e216 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -827,9 +827,9 @@ gtk_toolbar_render (GtkCssGadget *gadget,
       toolbar_content_draw (content, GTK_CONTAINER (widget), cr);
     }
   
-  gtk_container_propagate_draw (GTK_CONTAINER (widget),
-                               priv->arrow_button,
-                               cr);
+  gtk_widget_propagate_draw (widget,
+                             priv->arrow_button,
+                             cr);
 
   return FALSE;
 }
@@ -3137,7 +3137,7 @@ toolbar_content_draw (ToolbarContent *content,
   widget = GTK_WIDGET (content->item);
 
   if (widget)
-    gtk_container_propagate_draw (container, widget, cr);
+    gtk_widget_propagate_draw (GTK_WIDGET (container), widget, cr);
 }
 
 static gboolean
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c
index d1c4847..18ca77d 100644
--- a/gtk/gtktreeview.c
+++ b/gtk/gtktreeview.c
@@ -5388,7 +5388,7 @@ gtk_tree_view_draw (GtkWidget *widget,
     {
       GtkTreeViewChild *child = list->data;
 
-      gtk_container_propagate_draw (GTK_CONTAINER (tree_view), child->widget, cr);
+      gtk_widget_propagate_draw (widget, child->widget, cr);
     }
   
   if (tree_view->priv->drag_highlight_window)
@@ -5430,16 +5430,16 @@ gtk_tree_view_draw (GtkWidget *widget,
       if (gtk_tree_view_column_get_visible (column))
         {
           button = gtk_tree_view_column_get_button (column);
-          gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
-                                        button, cr);
+          gtk_widget_propagate_draw (widget,
+                                     button, cr);
         }
     }
 
   if (tree_view->priv->drag_window)
     {
       button = gtk_tree_view_column_get_button (tree_view->priv->drag_column);
-      gtk_container_propagate_draw (GTK_CONTAINER (tree_view),
-                                    button, cr);
+      gtk_widget_propagate_draw (widget,
+                                 button, cr);
     }
 
   gtk_style_context_restore (context);
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 0e054b6..dfab843 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -15905,3 +15905,41 @@ gtk_widget_snapshot_child (GtkWidget      *widget,
   gtk_widget_snapshot (child, snapshot);
   gtk_snapshot_translate_2d (snapshot, -x, -y);
 }
+
+static gboolean
+gtk_widget_should_propagate_draw (GtkWidget *widget,
+                                  GtkWidget *child,
+                                  cairo_t   *cr)
+{
+  GdkWindow *child_in_window;
+
+  if (!_gtk_widget_is_drawable (child))
+    return FALSE;
+
+  return TRUE;
+}
+
+void
+gtk_widget_propagate_draw (GtkWidget *widget,
+                           GtkWidget *child,
+                           cairo_t   *cr)
+{
+  int x, y;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (GTK_IS_WIDGET (child));
+  g_return_if_fail (cr != NULL);
+  g_return_if_fail (_gtk_widget_get_parent (child) == widget);
+
+  if (!gtk_widget_should_propagate_draw (widget, child, cr))
+    return;
+
+  gtk_widget_get_translation_to_child (widget, child, &x, &y);
+
+  cairo_save (cr);
+  cairo_translate (cr, x, y);
+
+  gtk_widget_draw_internal (child, cr, TRUE);
+
+  cairo_restore (cr);
+}
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 3f05d8d..c05d5fd 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -1318,6 +1318,11 @@ GtkWidget *             gtk_widget_get_next_sibling     (GtkWidget *widget);
 GDK_AVAILABLE_IN_3_90
 GtkWidget *             gtk_widget_get_prev_sibling     (GtkWidget *widget);
 
+GDK_AVAILABLE_IN_3_90
+void                    gtk_widget_propagate_draw       (GtkWidget *widget,
+                                                         GtkWidget *child,
+                                                         cairo_t   *cr);
+
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWidget, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRequisition, gtk_requisition_free)
 


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