]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcontainer.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / gtk / gtkcontainer.c
index afb14cde4341c0cca162cc49f049ee478f073475..2aa7ef6988575ae0da53cc73d473a164bcc460b4 100644 (file)
@@ -31,6 +31,7 @@
 
 #include "gtkcontainer.h"
 #include "gtkbuildable.h"
+#include "gtkbuilderprivate.h"
 #include "gtkprivate.h"
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
@@ -154,7 +155,7 @@ gtk_container_get_type (void)
        NULL,       /* value_table */
       };
 
-      static const GInterfaceInfo buildable_info =
+      const GInterfaceInfo buildable_info =
       {
        (GInterfaceInitFunc) gtk_container_buildable_init,
        NULL,
@@ -245,7 +246,7 @@ gtk_container_class_init (GtkContainerClass *class)
                                                       P_("Border width"),
                                                       P_("The width of the empty border outside the containers children"),
                                                      0,
-                                                     G_MAXINT,
+                                                     65535,
                                                      0,
                                                       GTK_PARAM_READWRITE));
   g_object_class_install_property (gobject_class,
@@ -274,7 +275,7 @@ gtk_container_class_init (GtkContainerClass *class)
                  G_TYPE_NONE, 1,
                  GTK_TYPE_WIDGET);
   container_signals[CHECK_RESIZE] =
-    g_signal_new (I_("check_resize"),
+    g_signal_new (I_("check-resize"),
                  G_OBJECT_CLASS_TYPE (object_class),
                  G_SIGNAL_RUN_LAST,
                  G_STRUCT_OFFSET (GtkContainerClass, check_resize),
@@ -307,9 +308,17 @@ gtk_container_buildable_add_child (GtkBuildable  *buildable,
                                   GObject       *child,
                                   const gchar   *type)
 {
-  g_return_if_fail (GTK_IS_WIDGET (child));
-
-  gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
+  if (type)
+    {
+      GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
+    }
+  else if (GTK_IS_WIDGET (child) && GTK_WIDGET (child)->parent == NULL)
+    {
+      gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
+    }
+  else
+    g_warning ("Cannot add an object of type %s to a container of type %s", 
+              g_type_name (G_OBJECT_TYPE (child)), g_type_name (G_OBJECT_TYPE (buildable)));
 }
 
 static void
@@ -353,6 +362,8 @@ typedef struct {
   GtkContainer *container;
   GtkWidget    *child;
   gchar        *child_prop_name;
+  gchar        *context;
+  gboolean     translatable;
 } PackingPropertiesData;
 
 static void
@@ -367,9 +378,25 @@ attributes_start_element (GMarkupParseContext *context,
   guint i;
 
   if (strcmp (element_name, "property") == 0)
-    for (i = 0; names[i]; i++)
-      if (strcmp (names[i], "name") == 0)
-       parser_data->child_prop_name = g_strdup (values[i]);
+    {
+      for (i = 0; names[i]; i++)
+       if (strcmp (names[i], "name") == 0)
+         parser_data->child_prop_name = g_strdup (values[i]);
+       else if (strcmp (names[i], "translatable") == 0)
+         {
+           if (!_gtk_builder_boolean_from_string (values[1],
+                                                  &parser_data->translatable,
+                                                  error))
+             return;
+         }
+       else if (strcmp (names[i], "comments") == 0)
+         ; /* for translators */
+       else if (strcmp (names[i], "context") == 0)
+         parser_data->context = g_strdup (values[1]);
+       else
+         g_warning ("Unsupported attribute for GtkContainer Child "
+                    "property: %s\n", names[i]);
+    }
   else if (strcmp (element_name, "packing") == 0)
     return;
   else
@@ -384,18 +411,37 @@ attributes_text_element (GMarkupParseContext *context,
                         GError             **error)
 {
   PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
+  gchar* value;
 
   if (!parser_data->child_prop_name)
     return;
+  
+  if (parser_data->translatable && text_len)
+    {
+      const gchar* domain;
+      domain = gtk_builder_get_translation_domain (parser_data->builder);
+      
+      value = _gtk_builder_parser_translate (domain,
+                                            parser_data->context,
+                                            text);
+    }
+  else
+    {
+      value = g_strdup (text);
+    }
 
   gtk_container_buildable_set_child_property (parser_data->container,
                                              parser_data->builder,
                                              parser_data->child,
                                              parser_data->child_prop_name,
-                                             text);
+                                             value);
 
   g_free (parser_data->child_prop_name);
+  g_free (parser_data->context);
+  g_free (value);
   parser_data->child_prop_name = NULL;
+  parser_data->context = NULL;
+  parser_data->translatable = FALSE;
 }
 
 static const GMarkupParser attributes_parser =
@@ -819,7 +865,6 @@ gtk_container_add_with_properties (GtkContainer *container,
   g_return_if_fail (GTK_IS_CONTAINER (container));
   g_return_if_fail (GTK_IS_WIDGET (widget));
   g_return_if_fail (widget->parent == NULL);
-  g_return_if_fail (widget->parent == container);
 
   g_object_ref (container);
   g_object_ref (widget);
@@ -935,7 +980,7 @@ gtk_container_class_install_child_property (GtkContainerClass *cclass,
  * gtk_container_class_find_child_property:
  * @cclass: a #GtkContainerClass
  * @property_name: the name of the child property to find
- * @returns: the #GParamSpec of the child property or %NULL if @class has no
+ * @returns: (allow-none): the #GParamSpec of the child property or %NULL if @class has no
  *   child property with that name.
  *
  * Finds a child property of a container class by name.
@@ -1008,7 +1053,7 @@ static void
 gtk_container_destroy (GtkObject *object)
 {
   GtkContainer *container = GTK_CONTAINER (object);
-  
+
   if (GTK_CONTAINER_RESIZE_PENDING (container))
     _gtk_container_dequeue_resize_handler (container);
 
@@ -1017,11 +1062,10 @@ gtk_container_destroy (GtkObject *object)
    */
   if (container->has_focus_chain)
     gtk_container_unset_focus_chain (container);
-  
+
   gtk_container_foreach (container, (GtkCallback) gtk_widget_destroy, NULL);
-  
-  if (GTK_OBJECT_CLASS (parent_class)->destroy)
-    (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
+
+  GTK_OBJECT_CLASS (parent_class)->destroy (object);
 }
 
 static void
@@ -1146,7 +1190,8 @@ gtk_container_add (GtkContainer *container,
     {
       g_warning ("Attempting to add a widget with type %s to a container of "
                  "type %s, but the widget is already inside a container of type %s, "
-                 "the GTK+ FAQ at http://www.gtk.org/faq/ explains how to reparent a widget.",
+                 "the GTK+ FAQ at http://library.gnome.org/devel/gtk-faq/stable/ "
+                 "explains how to reparent a widget.",
                  g_type_name (G_OBJECT_TYPE (widget)),
                  g_type_name (G_OBJECT_TYPE (container)),
                  g_type_name (G_OBJECT_TYPE (widget->parent)));
@@ -1216,7 +1261,7 @@ gtk_container_set_resize_mode (GtkContainer  *container,
   g_return_if_fail (GTK_IS_CONTAINER (container));
   g_return_if_fail (resize_mode <= GTK_RESIZE_IMMEDIATE);
   
-  if (GTK_WIDGET_TOPLEVEL (container) &&
+  if (gtk_widget_is_toplevel (GTK_WIDGET (container)) &&
       resize_mode == GTK_RESIZE_PARENT)
     {
       resize_mode = GTK_RESIZE_QUEUE;
@@ -1334,8 +1379,8 @@ _gtk_container_queue_resize (GtkContainer *container)
       
   if (resize_container)
     {
-      if (GTK_WIDGET_VISIBLE (resize_container) &&
-         (GTK_WIDGET_TOPLEVEL (resize_container) || GTK_WIDGET_REALIZED (resize_container)))
+      if (gtk_widget_get_visible (GTK_WIDGET (resize_container)) &&
+         (gtk_widget_is_toplevel (GTK_WIDGET (resize_container)) || GTK_WIDGET_REALIZED (resize_container)))
        {
          switch (resize_container->resize_mode)
            {
@@ -1541,9 +1586,9 @@ gtk_container_foreach_full (GtkContainer       *container,
 /**
  * gtk_container_set_focus_child:
  * @container: a #GtkContainer
- * @widget: a #GtkWidget, or %NULL
+ * @child: (allow-none): a #GtkWidget, or %NULL
  *
- * Sets, or unsets if @widget is %NULL, the focused child of @container.
+ * Sets, or unsets if @child is %NULL, the focused child of @container.
  *
  * This function emits the GtkContainer::set_focus_child signal of
  * @container. Implementations of #GtkContainer can override the
@@ -1551,13 +1596,13 @@ gtk_container_foreach_full (GtkContainer       *container,
  */
 void
 gtk_container_set_focus_child (GtkContainer *container,
-                              GtkWidget    *widget)
+                              GtkWidget    *child)
 {
   g_return_if_fail (GTK_IS_CONTAINER (container));
-  if (widget)
-    g_return_if_fail (GTK_IS_WIDGET (widget));
+  if (child)
+    g_return_if_fail (GTK_IS_WIDGET (child));
 
-  g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, widget);
+  g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, child);
 }
 
 /**
@@ -1584,9 +1629,9 @@ gtk_container_get_focus_child (GtkContainer *container)
  * @container: a #GtkContainer
  * 
  * Returns the container's non-internal children. See
- * gtk_container_forall() for details on what constitutes an "internal" child. 
+ * gtk_container_forall() for details on what constitutes an "internal" child.
  *
- * Return value: a newly-allocated list of the container's non-internal children.
+ * Return value: (element-type GtkWidget) (transfer container): a newly-allocated list of the container's non-internal children.
  **/
 GList*
 gtk_container_get_children (GtkContainer *container)
@@ -1645,11 +1690,14 @@ gchar*
 _gtk_container_child_composite_name (GtkContainer *container,
                                    GtkWidget    *child)
 {
+  gboolean composite_child;
+
   g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
   g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
   g_return_val_if_fail (child->parent == GTK_WIDGET (container), NULL);
 
-  if (GTK_WIDGET_COMPOSITE_CHILD (child))
+  g_object_get (child, "composite-child", &composite_child, NULL);
+  if (composite_child)
     {
       static GQuark quark_composite_name = 0;
       gchar *name;
@@ -1763,11 +1811,11 @@ gtk_container_focus (GtkWidget        *widget,
 
   return_val = FALSE;
 
-  if (GTK_WIDGET_CAN_FOCUS (container))
+  if (gtk_widget_get_can_focus (widget))
     {
-      if (!GTK_WIDGET_HAS_FOCUS (container))
+      if (!gtk_widget_has_focus (widget))
        {
-         gtk_widget_grab_focus (GTK_WIDGET (container));
+         gtk_widget_grab_focus (widget);
          return_val = TRUE;
        }
     }
@@ -2026,13 +2074,13 @@ gtk_container_focus_sort_up_down (GtkContainer     *container,
        }
       else
        {
-         if (GTK_WIDGET_NO_WINDOW (widget))
+         if (!gtk_widget_get_has_window (widget))
            compare.x = widget->allocation.x + widget->allocation.width / 2;
          else
            compare.x = widget->allocation.width / 2;
        }
       
-      if (GTK_WIDGET_NO_WINDOW (widget))
+      if (!gtk_widget_get_has_window (widget))
        compare.y = (direction == GTK_DIR_DOWN) ? widget->allocation.y : widget->allocation.y + widget->allocation.height;
       else
        compare.y = (direction == GTK_DIR_DOWN) ? 0 : + widget->allocation.height;
@@ -2153,13 +2201,13 @@ gtk_container_focus_sort_left_right (GtkContainer     *container,
        }
       else
        {
-         if (GTK_WIDGET_NO_WINDOW (widget))
+         if (!gtk_widget_get_has_window (widget))
            compare.y = widget->allocation.y + widget->allocation.height / 2;
          else
            compare.y = widget->allocation.height / 2;
        }
       
-      if (GTK_WIDGET_NO_WINDOW (widget))
+      if (!gtk_widget_get_has_window (widget))
        compare.x = (direction == GTK_DIR_RIGHT) ? widget->allocation.x : widget->allocation.x + widget->allocation.width;
       else
        compare.x = (direction == GTK_DIR_RIGHT) ? 0 : widget->allocation.width;
@@ -2179,7 +2227,7 @@ gtk_container_focus_sort_left_right (GtkContainer     *container,
  * @children:  a list of descendents of @container (they don't
  *             have to be direct children)
  * @direction: focus direction
- * @old_focus: widget to use for the starting position, or %NULL
+ * @old_focus: (allow-none): widget to use for the starting position, or %NULL
  *             to determine this automatically.
  *             (Note, this argument isn't used for GTK_DIR_TAB_*,
  *              which is the only @direction we use currently,
@@ -2253,7 +2301,7 @@ gtk_container_focus_move (GtkContainer     *container,
                  return TRUE;
             }
         }
-      else if (GTK_WIDGET_DRAWABLE (child) &&
+      else if (gtk_widget_is_drawable (child) &&
                gtk_widget_is_ancestor (child, GTK_WIDGET (container)))
         {
           if (gtk_widget_child_focus (child, direction))
@@ -2358,7 +2406,8 @@ gtk_container_set_focus_chain (GtkContainer *container,
 /**
  * gtk_container_get_focus_chain:
  * @container:         a #GtkContainer
- * @focusable_widgets: location to store the focus chain of the
+ * @focusable_widgets: (element-type GtkWidget) (out) (transfer container): location
+ *                     to store the focus chain of the
  *                     container, or %NULL. You should free this list
  *                     using g_list_free() when you are done with it, however
  *                     no additional reference count is added to the
@@ -2468,7 +2517,7 @@ gtk_container_set_focus_vadjustment (GtkContainer  *container,
  * Retrieves the vertical focus adjustment for the container. See
  * gtk_container_set_focus_vadjustment().
  *
- * Return value: the vertical focus adjustment, or %NULL if
+ * Return value: (transfer none): the vertical focus adjustment, or %NULL if
  *   none has been set.
  **/
 GtkAdjustment *
@@ -2523,7 +2572,7 @@ gtk_container_set_focus_hadjustment (GtkContainer  *container,
  * Retrieves the horizontal focus adjustment for the container. See
  * gtk_container_set_focus_hadjustment ().
  *
- * Return value: the horizontal focus adjustment, or %NULL if
+ * Return value: (transfer none): the horizontal focus adjustment, or %NULL if
  *   none has been set.
  **/
 GtkAdjustment *
@@ -2589,7 +2638,7 @@ gtk_container_expose (GtkWidget      *widget,
   g_return_val_if_fail (event != NULL, FALSE);
 
   
-  if (GTK_WIDGET_DRAWABLE (widget)) 
+  if (gtk_widget_is_drawable (widget))
     {
       data.container = widget;
       data.event = event;
@@ -2606,7 +2655,7 @@ static void
 gtk_container_map_child (GtkWidget *child,
                         gpointer   client_data)
 {
-  if (GTK_WIDGET_VISIBLE (child) &&
+  if (gtk_widget_get_visible (child) &&
       GTK_WIDGET_CHILD_VISIBLE (child) &&
       !GTK_WIDGET_MAPPED (child))
     gtk_widget_map (child);
@@ -2621,7 +2670,7 @@ gtk_container_map (GtkWidget *widget)
                        gtk_container_map_child,
                        NULL);
 
-  if (!GTK_WIDGET_NO_WINDOW (widget))
+  if (gtk_widget_get_has_window (widget))
     gdk_window_show (widget->window);
 }
 
@@ -2630,7 +2679,7 @@ gtk_container_unmap (GtkWidget *widget)
 {
   GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
 
-  if (!GTK_WIDGET_NO_WINDOW (widget))
+  if (gtk_widget_get_has_window (widget))
     gdk_window_hide (widget->window);
   else
     gtk_container_forall (GTK_CONTAINER (widget),
@@ -2671,8 +2720,8 @@ gtk_container_propagate_expose (GtkContainer   *container,
 
   g_assert (child->parent == GTK_WIDGET (container));
   
-  if (GTK_WIDGET_DRAWABLE (child) &&
-      GTK_WIDGET_NO_WINDOW (child) &&
+  if (gtk_widget_is_drawable (child) &&
+      !gtk_widget_get_has_window (child) &&
       (child->window == event->window))
     {
       child_event = gdk_event_new (GDK_EXPOSE);