]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcontainer.c
Move GtkSizeRequest into GtkWidget
[~andy/gtk] / gtk / gtkcontainer.c
index 78299bea7ac04a4156d419abd0263047e62d80b1..73e42486aeae1f31ad53cf7a2df6e94362f1dd43 100644 (file)
@@ -106,8 +106,8 @@ static void     gtk_container_children_callback    (GtkWidget         *widget,
                                                    gpointer           client_data);
 static void     gtk_container_show_all             (GtkWidget         *widget);
 static void     gtk_container_hide_all             (GtkWidget         *widget);
-static gint     gtk_container_expose               (GtkWidget         *widget,
-                                                   GdkEventExpose    *event);
+static gint     gtk_container_draw                 (GtkWidget         *widget,
+                                                    cairo_t           *cr);
 static void     gtk_container_map                  (GtkWidget         *widget);
 static void     gtk_container_unmap                (GtkWidget         *widget);
 static void     gtk_container_adjust_size_request  (GtkWidget         *widget,
@@ -239,7 +239,7 @@ gtk_container_class_init (GtkContainerClass *class)
 
   widget_class->show_all = gtk_container_show_all;
   widget_class->hide_all = gtk_container_hide_all;
-  widget_class->expose_event = gtk_container_expose;
+  widget_class->draw = gtk_container_draw;
   widget_class->map = gtk_container_map;
   widget_class->unmap = gtk_container_unmap;
   widget_class->focus = gtk_container_focus;
@@ -1486,8 +1486,8 @@ gtk_container_real_check_resize (GtkContainer *container)
   GtkAllocation allocation;
   GtkRequisition requisition;
 
-  gtk_size_request_get_size (GTK_SIZE_REQUEST (widget),
-                             &requisition, NULL);
+  gtk_widget_get_preferred_size (widget,
+                                 &requisition, NULL);
   gtk_widget_get_allocation (widget, &allocation);
 
   if (requisition.width > allocation.width ||
@@ -2757,41 +2757,34 @@ gtk_container_hide_all (GtkWidget *widget)
 
 
 static void
-gtk_container_expose_child (GtkWidget *child,
-                           gpointer   client_data)
+gtk_container_draw_child (GtkWidget *child,
+                         gpointer   client_data)
 {
   struct {
     GtkWidget *container;
-    GdkEventExpose *event;
+    cairo_t *cr;
   } *data = client_data;
   
-  gtk_container_propagate_expose (GTK_CONTAINER (data->container),
-                                 child,
-                                 data->event);
+  gtk_container_propagate_draw (GTK_CONTAINER (data->container),
+                               child,
+                               data->cr);
 }
 
 static gint 
-gtk_container_expose (GtkWidget      *widget,
-                     GdkEventExpose *event)
+gtk_container_draw (GtkWidget *widget,
+                    cairo_t   *cr)
 {
   struct {
     GtkWidget *container;
-    GdkEventExpose *event;
+    cairo_t *cr;
   } data;
 
-  g_return_val_if_fail (GTK_IS_CONTAINER (widget), FALSE);
-  g_return_val_if_fail (event != NULL, FALSE);
-
+  data.container = widget;
+  data.cr = cr;
   
-  if (gtk_widget_is_drawable (widget))
-    {
-      data.container = widget;
-      data.event = event;
-      
-      gtk_container_forall (GTK_CONTAINER (widget),
-                           gtk_container_expose_child,
-                           &data);
-    }   
+  gtk_container_forall (GTK_CONTAINER (widget),
+                        gtk_container_draw_child,
+                       &data);
   
   return FALSE;
 }
@@ -2833,54 +2826,96 @@ gtk_container_unmap (GtkWidget *widget)
 }
 
 /**
- * gtk_container_propagate_expose:
+ * gtk_container_propagate_draw:
  * @container: a #GtkContainer
  * @child: a child of @container
- * @event: a expose event sent to 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 an expose event, it must send synthetic
- * expose events to all children that don't have their own #GdkWindows.
- * This function provides a convenient way of doing this. A container,
- * when it receives an expose event, calls gtk_container_propagate_expose() 
- * once for each child, passing in the event the container received.
+ * 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_expose() takes care of deciding whether
- * an expose event needs to be sent to the child, intersecting
- * the event's area with the child area, and sending the event.
+ * 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 simply inherit the
- * #GtkWidget::expose implementation from #GtkContainer, or, do some drawing 
- * and then chain to the ::expose implementation from #GtkContainer.
+ * 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_expose (GtkContainer   *container,
-                               GtkWidget      *child,
-                               GdkEventExpose *event)
+gtk_container_propagate_draw (GtkContainer   *container,
+                              GtkWidget      *child,
+                              cairo_t        *cr)
 {
-  GdkEvent *child_event;
+  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));
-  g_return_if_fail (event != NULL);
+  g_return_if_fail (cr != NULL);
 
   g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (container));
 
-  if (gtk_widget_is_drawable (child) &&
-      !gtk_widget_get_has_window (child) &&
-      gtk_widget_get_window (child) == event->window)
+  event = _gtk_cairo_get_event (cr);
+  if (event)
     {
-      child_event = gdk_event_new (GDK_EXPOSE);
-      child_event->expose = *event;
-      g_object_ref (child_event->expose.window);
+      if (gtk_widget_get_has_window (child) ||
+          gtk_widget_get_window (child) != event->window)
+        return;
+    }
 
-      child_event->expose.region = gtk_widget_region_intersect (child, event->region);
-      if (!cairo_region_is_empty (child_event->expose.region))
-       {
-         cairo_region_get_extents (child_event->expose.region, &child_event->expose.area);
-         gtk_widget_send_expose (child, child_event);
-       }
-      gdk_event_free (child_event);
+  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
+    {
+      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);
 }
 
 gboolean