1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gtkcontainer.h"
35 #include "gtkbuildable.h"
36 #include "gtkbuilderprivate.h"
37 #include "gtkprivate.h"
39 #include "gtkmarshalers.h"
40 #include "gtksizerequest.h"
41 #include "gtkwindow.h"
43 #include "gtktoolbar.h"
44 #include <gobject/gobjectnotifyqueue.c>
45 #include <gobject/gvaluecollector.h>
47 struct _GtkContainerPrivate
49 GtkWidget *focus_child;
51 guint border_width : 16;
53 guint has_focus_chain : 1;
54 guint need_resize : 1;
55 guint reallocate_redraws : 1;
56 guint resize_mode : 2;
74 #define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
75 #define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
78 /* --- prototypes --- */
79 static void gtk_container_base_class_init (GtkContainerClass *klass);
80 static void gtk_container_base_class_finalize (GtkContainerClass *klass);
81 static void gtk_container_class_init (GtkContainerClass *klass);
82 static void gtk_container_init (GtkContainer *container);
83 static void gtk_container_destroy (GtkWidget *widget);
84 static void gtk_container_set_property (GObject *object,
88 static void gtk_container_get_property (GObject *object,
92 static void gtk_container_add_unimplemented (GtkContainer *container,
94 static void gtk_container_remove_unimplemented (GtkContainer *container,
96 static void gtk_container_real_check_resize (GtkContainer *container);
97 static gboolean gtk_container_focus (GtkWidget *widget,
98 GtkDirectionType direction);
99 static void gtk_container_real_set_focus_child (GtkContainer *container,
102 static gboolean gtk_container_focus_move (GtkContainer *container,
104 GtkDirectionType direction);
105 static void gtk_container_children_callback (GtkWidget *widget,
106 gpointer client_data);
107 static void gtk_container_show_all (GtkWidget *widget);
108 static void gtk_container_hide_all (GtkWidget *widget);
109 static gint gtk_container_draw (GtkWidget *widget,
111 static void gtk_container_map (GtkWidget *widget);
112 static void gtk_container_unmap (GtkWidget *widget);
113 static void gtk_container_adjust_size_request (GtkWidget *widget,
114 GtkOrientation orientation,
118 static void gtk_container_adjust_size_allocation (GtkWidget *widget,
119 GtkAllocation *allocation);
121 static gchar* gtk_container_child_default_composite_name (GtkContainer *container,
125 static void gtk_container_buildable_init (GtkBuildableIface *iface);
126 static void gtk_container_buildable_add_child (GtkBuildable *buildable,
130 static gboolean gtk_container_buildable_custom_tag_start (GtkBuildable *buildable,
133 const gchar *tagname,
134 GMarkupParser *parser,
136 static void gtk_container_buildable_custom_tag_end (GtkBuildable *buildable,
139 const gchar *tagname,
143 /* --- variables --- */
144 static const gchar vadjustment_key[] = "gtk-vadjustment";
145 static guint vadjustment_key_id = 0;
146 static const gchar hadjustment_key[] = "gtk-hadjustment";
147 static guint hadjustment_key_id = 0;
148 static GSList *container_resize_queue = NULL;
149 static guint container_signals[LAST_SIGNAL] = { 0 };
150 static GtkWidgetClass *parent_class = NULL;
151 extern GParamSpecPool *_gtk_widget_child_property_pool;
152 extern GObjectNotifyContext *_gtk_widget_child_property_notify_context;
153 static GtkBuildableIface *parent_buildable_iface;
156 /* --- functions --- */
158 gtk_container_get_type (void)
160 static GType container_type = 0;
164 const GTypeInfo container_info =
166 sizeof (GtkContainerClass),
167 (GBaseInitFunc) gtk_container_base_class_init,
168 (GBaseFinalizeFunc) gtk_container_base_class_finalize,
169 (GClassInitFunc) gtk_container_class_init,
170 NULL /* class_finalize */,
171 NULL /* class_data */,
172 sizeof (GtkContainer),
174 (GInstanceInitFunc) gtk_container_init,
175 NULL, /* value_table */
178 const GInterfaceInfo buildable_info =
180 (GInterfaceInitFunc) gtk_container_buildable_init,
186 g_type_register_static (GTK_TYPE_WIDGET, I_("GtkContainer"),
187 &container_info, G_TYPE_FLAG_ABSTRACT);
189 g_type_add_interface_static (container_type,
195 return container_type;
199 gtk_container_base_class_init (GtkContainerClass *class)
201 /* reset instance specifc class fields that don't get inherited */
202 class->set_child_property = NULL;
203 class->get_child_property = NULL;
207 gtk_container_base_class_finalize (GtkContainerClass *class)
211 list = g_param_spec_pool_list_owned (_gtk_widget_child_property_pool, G_OBJECT_CLASS_TYPE (class));
212 for (node = list; node; node = node->next)
214 GParamSpec *pspec = node->data;
216 g_param_spec_pool_remove (_gtk_widget_child_property_pool, pspec);
217 PARAM_SPEC_SET_PARAM_ID (pspec, 0);
218 g_param_spec_unref (pspec);
224 gtk_container_class_init (GtkContainerClass *class)
226 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
227 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
229 parent_class = g_type_class_peek_parent (class);
231 vadjustment_key_id = g_quark_from_static_string (vadjustment_key);
232 hadjustment_key_id = g_quark_from_static_string (hadjustment_key);
234 gobject_class->set_property = gtk_container_set_property;
235 gobject_class->get_property = gtk_container_get_property;
237 widget_class->destroy = gtk_container_destroy;
238 widget_class->show_all = gtk_container_show_all;
239 widget_class->hide_all = gtk_container_hide_all;
240 widget_class->draw = gtk_container_draw;
241 widget_class->map = gtk_container_map;
242 widget_class->unmap = gtk_container_unmap;
243 widget_class->focus = gtk_container_focus;
245 widget_class->adjust_size_request = gtk_container_adjust_size_request;
246 widget_class->adjust_size_allocation = gtk_container_adjust_size_allocation;
248 class->add = gtk_container_add_unimplemented;
249 class->remove = gtk_container_remove_unimplemented;
250 class->check_resize = gtk_container_real_check_resize;
251 class->forall = NULL;
252 class->set_focus_child = gtk_container_real_set_focus_child;
253 class->child_type = NULL;
254 class->composite_name = gtk_container_child_default_composite_name;
256 g_object_class_install_property (gobject_class,
258 g_param_spec_enum ("resize-mode",
260 P_("Specify how resize events are handled"),
261 GTK_TYPE_RESIZE_MODE,
263 GTK_PARAM_READWRITE));
264 g_object_class_install_property (gobject_class,
266 g_param_spec_uint ("border-width",
268 P_("The width of the empty border outside the containers children"),
272 GTK_PARAM_READWRITE));
273 g_object_class_install_property (gobject_class,
275 g_param_spec_object ("child",
277 P_("Can be used to add a new child to the container"),
279 GTK_PARAM_WRITABLE));
280 container_signals[ADD] =
281 g_signal_new (I_("add"),
282 G_OBJECT_CLASS_TYPE (gobject_class),
284 G_STRUCT_OFFSET (GtkContainerClass, add),
286 _gtk_marshal_VOID__OBJECT,
289 container_signals[REMOVE] =
290 g_signal_new (I_("remove"),
291 G_OBJECT_CLASS_TYPE (gobject_class),
293 G_STRUCT_OFFSET (GtkContainerClass, remove),
295 _gtk_marshal_VOID__OBJECT,
298 container_signals[CHECK_RESIZE] =
299 g_signal_new (I_("check-resize"),
300 G_OBJECT_CLASS_TYPE (gobject_class),
302 G_STRUCT_OFFSET (GtkContainerClass, check_resize),
304 _gtk_marshal_VOID__VOID,
306 container_signals[SET_FOCUS_CHILD] =
307 g_signal_new (I_("set-focus-child"),
308 G_OBJECT_CLASS_TYPE (gobject_class),
310 G_STRUCT_OFFSET (GtkContainerClass, set_focus_child),
312 _gtk_marshal_VOID__OBJECT,
316 g_type_class_add_private (class, sizeof (GtkContainerPrivate));
320 gtk_container_buildable_init (GtkBuildableIface *iface)
322 parent_buildable_iface = g_type_interface_peek_parent (iface);
323 iface->add_child = gtk_container_buildable_add_child;
324 iface->custom_tag_start = gtk_container_buildable_custom_tag_start;
325 iface->custom_tag_end = gtk_container_buildable_custom_tag_end;
329 gtk_container_buildable_add_child (GtkBuildable *buildable,
336 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
338 else if (GTK_IS_WIDGET (child) &&
339 gtk_widget_get_parent (GTK_WIDGET (child)) == NULL)
341 gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
344 g_warning ("Cannot add an object of type %s to a container of type %s",
345 g_type_name (G_OBJECT_TYPE (child)), g_type_name (G_OBJECT_TYPE (buildable)));
349 gtk_container_buildable_set_child_property (GtkContainer *container,
356 GValue gvalue = { 0, };
357 GError *error = NULL;
359 pspec = gtk_container_class_find_child_property
360 (G_OBJECT_GET_CLASS (container), name);
363 g_warning ("%s does not have a property called %s",
364 g_type_name (G_OBJECT_TYPE (container)), name);
368 if (!gtk_builder_value_from_string (builder, pspec, value, &gvalue, &error))
370 g_warning ("Could not read property %s:%s with value %s of type %s: %s",
371 g_type_name (G_OBJECT_TYPE (container)),
374 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
376 g_error_free (error);
380 gtk_container_child_set_property (container, child, name, &gvalue);
381 g_value_unset (&gvalue);
386 GtkContainer *container;
388 gchar *child_prop_name;
390 gboolean translatable;
391 } PackingPropertiesData;
394 attributes_start_element (GMarkupParseContext *context,
395 const gchar *element_name,
397 const gchar **values,
401 PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
404 if (strcmp (element_name, "property") == 0)
406 for (i = 0; names[i]; i++)
407 if (strcmp (names[i], "name") == 0)
408 parser_data->child_prop_name = g_strdup (values[i]);
409 else if (strcmp (names[i], "translatable") == 0)
411 if (!_gtk_builder_boolean_from_string (values[1],
412 &parser_data->translatable,
416 else if (strcmp (names[i], "comments") == 0)
417 ; /* for translators */
418 else if (strcmp (names[i], "context") == 0)
419 parser_data->context = g_strdup (values[1]);
421 g_warning ("Unsupported attribute for GtkContainer Child "
422 "property: %s\n", names[i]);
424 else if (strcmp (element_name, "packing") == 0)
427 g_warning ("Unsupported tag for GtkContainer: %s\n", element_name);
431 attributes_text_element (GMarkupParseContext *context,
437 PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
440 if (!parser_data->child_prop_name)
443 if (parser_data->translatable && text_len)
446 domain = gtk_builder_get_translation_domain (parser_data->builder);
448 value = _gtk_builder_parser_translate (domain,
449 parser_data->context,
454 value = g_strdup (text);
457 gtk_container_buildable_set_child_property (parser_data->container,
458 parser_data->builder,
460 parser_data->child_prop_name,
463 g_free (parser_data->child_prop_name);
464 g_free (parser_data->context);
466 parser_data->child_prop_name = NULL;
467 parser_data->context = NULL;
468 parser_data->translatable = FALSE;
471 static const GMarkupParser attributes_parser =
473 attributes_start_element,
475 attributes_text_element,
479 gtk_container_buildable_custom_tag_start (GtkBuildable *buildable,
482 const gchar *tagname,
483 GMarkupParser *parser,
486 PackingPropertiesData *parser_data;
488 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
489 tagname, parser, data))
492 if (child && strcmp (tagname, "packing") == 0)
494 parser_data = g_slice_new0 (PackingPropertiesData);
495 parser_data->builder = builder;
496 parser_data->container = GTK_CONTAINER (buildable);
497 parser_data->child = GTK_WIDGET (child);
498 parser_data->child_prop_name = NULL;
500 *parser = attributes_parser;
509 gtk_container_buildable_custom_tag_end (GtkBuildable *buildable,
512 const gchar *tagname,
515 if (strcmp (tagname, "packing") == 0)
517 g_slice_free (PackingPropertiesData, (gpointer)data);
522 if (parent_buildable_iface->custom_tag_end)
523 parent_buildable_iface->custom_tag_end (buildable, builder,
524 child, tagname, data);
529 * gtk_container_child_type:
530 * @container: a #GtkContainer
532 * Returns the type of the children supported by the container.
534 * Note that this may return %G_TYPE_NONE to indicate that no more
535 * children can be added, e.g. for a #GtkPaned which already has two
538 * Return value: a #GType.
541 gtk_container_child_type (GtkContainer *container)
544 GtkContainerClass *class;
546 g_return_val_if_fail (GTK_IS_CONTAINER (container), 0);
548 class = GTK_CONTAINER_GET_CLASS (container);
549 if (class->child_type)
550 slot = class->child_type (container);
557 /* --- GtkContainer child property mechanism --- */
559 container_get_child_property (GtkContainer *container,
564 GtkContainerClass *class = g_type_class_peek (pspec->owner_type);
566 class->get_child_property (container, child, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
570 container_set_child_property (GtkContainer *container,
574 GObjectNotifyQueue *nqueue)
576 GValue tmp_value = { 0, };
577 GtkContainerClass *class = g_type_class_peek (pspec->owner_type);
579 /* provide a copy to work from, convert (if necessary) and validate */
580 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
581 if (!g_value_transform (value, &tmp_value))
582 g_warning ("unable to set child property `%s' of type `%s' from value of type `%s'",
584 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
585 G_VALUE_TYPE_NAME (value));
586 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
588 gchar *contents = g_strdup_value_contents (value);
590 g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
592 G_VALUE_TYPE_NAME (value),
594 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
599 class->set_child_property (container, child, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
600 g_object_notify_queue_add (G_OBJECT (child), nqueue, pspec);
602 g_value_unset (&tmp_value);
606 * gtk_container_child_get_valist:
607 * @container: a #GtkContainer
608 * @child: a widget which is a child of @container
609 * @first_property_name: the name of the first property to get
610 * @var_args: return location for the first property, followed
611 * optionally by more name/return location pairs, followed by %NULL
613 * Gets the values of one or more child properties for @child and @container.
616 gtk_container_child_get_valist (GtkContainer *container,
618 const gchar *first_property_name,
623 g_return_if_fail (GTK_IS_CONTAINER (container));
624 g_return_if_fail (GTK_IS_WIDGET (child));
625 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
627 g_object_ref (container);
628 g_object_ref (child);
630 name = first_property_name;
633 GValue value = { 0, };
637 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
639 G_OBJECT_TYPE (container),
643 g_warning ("%s: container class `%s' has no child property named `%s'",
645 G_OBJECT_TYPE_NAME (container),
649 if (!(pspec->flags & G_PARAM_READABLE))
651 g_warning ("%s: child property `%s' of container class `%s' is not readable",
654 G_OBJECT_TYPE_NAME (container));
657 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
658 container_get_child_property (container, child, pspec, &value);
659 G_VALUE_LCOPY (&value, var_args, 0, &error);
662 g_warning ("%s: %s", G_STRLOC, error);
664 g_value_unset (&value);
667 g_value_unset (&value);
668 name = va_arg (var_args, gchar*);
671 g_object_unref (child);
672 g_object_unref (container);
676 * gtk_container_child_get_property:
677 * @container: a #GtkContainer
678 * @child: a widget which is a child of @container
679 * @property_name: the name of the property to get
680 * @value: a location to return the value
682 * Gets the value of a child property for @child and @container.
685 gtk_container_child_get_property (GtkContainer *container,
687 const gchar *property_name,
692 g_return_if_fail (GTK_IS_CONTAINER (container));
693 g_return_if_fail (GTK_IS_WIDGET (child));
694 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
695 g_return_if_fail (property_name != NULL);
696 g_return_if_fail (G_IS_VALUE (value));
698 g_object_ref (container);
699 g_object_ref (child);
700 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool, property_name,
701 G_OBJECT_TYPE (container), TRUE);
703 g_warning ("%s: container class `%s' has no child property named `%s'",
705 G_OBJECT_TYPE_NAME (container),
707 else if (!(pspec->flags & G_PARAM_READABLE))
708 g_warning ("%s: child property `%s' of container class `%s' is not readable",
711 G_OBJECT_TYPE_NAME (container));
714 GValue *prop_value, tmp_value = { 0, };
716 /* auto-conversion of the callers value type
718 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
720 g_value_reset (value);
723 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
725 g_warning ("can't retrieve child property `%s' of type `%s' as value of type `%s'",
727 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
728 G_VALUE_TYPE_NAME (value));
729 g_object_unref (child);
730 g_object_unref (container);
735 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
736 prop_value = &tmp_value;
738 container_get_child_property (container, child, pspec, prop_value);
739 if (prop_value != value)
741 g_value_transform (prop_value, value);
742 g_value_unset (&tmp_value);
745 g_object_unref (child);
746 g_object_unref (container);
750 * gtk_container_child_set_valist:
751 * @container: a #GtkContainer
752 * @child: a widget which is a child of @container
753 * @first_property_name: the name of the first property to set
754 * @var_args: a %NULL-terminated list of property names and values, starting
755 * with @first_prop_name
757 * Sets one or more child properties for @child and @container.
760 gtk_container_child_set_valist (GtkContainer *container,
762 const gchar *first_property_name,
765 GObjectNotifyQueue *nqueue;
768 g_return_if_fail (GTK_IS_CONTAINER (container));
769 g_return_if_fail (GTK_IS_WIDGET (child));
770 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
772 g_object_ref (container);
773 g_object_ref (child);
775 nqueue = g_object_notify_queue_freeze (G_OBJECT (child), _gtk_widget_child_property_notify_context);
776 name = first_property_name;
779 GValue value = { 0, };
781 GParamSpec *pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
783 G_OBJECT_TYPE (container),
787 g_warning ("%s: container class `%s' has no child property named `%s'",
789 G_OBJECT_TYPE_NAME (container),
793 if (!(pspec->flags & G_PARAM_WRITABLE))
795 g_warning ("%s: child property `%s' of container class `%s' is not writable",
798 G_OBJECT_TYPE_NAME (container));
801 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
802 G_VALUE_COLLECT (&value, var_args, 0, &error);
805 g_warning ("%s: %s", G_STRLOC, error);
808 /* we purposely leak the value here, it might not be
809 * in a sane state if an error condition occoured
813 container_set_child_property (container, child, pspec, &value, nqueue);
814 g_value_unset (&value);
815 name = va_arg (var_args, gchar*);
817 g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
819 g_object_unref (container);
820 g_object_unref (child);
824 * gtk_container_child_set_property:
825 * @container: a #GtkContainer
826 * @child: a widget which is a child of @container
827 * @property_name: the name of the property to set
828 * @value: the value to set the property to
830 * Sets a child property for @child and @container.
833 gtk_container_child_set_property (GtkContainer *container,
835 const gchar *property_name,
838 GObjectNotifyQueue *nqueue;
841 g_return_if_fail (GTK_IS_CONTAINER (container));
842 g_return_if_fail (GTK_IS_WIDGET (child));
843 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
844 g_return_if_fail (property_name != NULL);
845 g_return_if_fail (G_IS_VALUE (value));
847 g_object_ref (container);
848 g_object_ref (child);
850 nqueue = g_object_notify_queue_freeze (G_OBJECT (child), _gtk_widget_child_property_notify_context);
851 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool, property_name,
852 G_OBJECT_TYPE (container), TRUE);
854 g_warning ("%s: container class `%s' has no child property named `%s'",
856 G_OBJECT_TYPE_NAME (container),
858 else if (!(pspec->flags & G_PARAM_WRITABLE))
859 g_warning ("%s: child property `%s' of container class `%s' is not writable",
862 G_OBJECT_TYPE_NAME (container));
865 container_set_child_property (container, child, pspec, value, nqueue);
867 g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
868 g_object_unref (container);
869 g_object_unref (child);
873 * gtk_container_add_with_properties:
874 * @container: a #GtkContainer
875 * @widget: a widget to be placed inside @container
876 * @first_prop_name: the name of the first child property to set
877 * @Varargs: a %NULL-terminated list of property names and values, starting
878 * with @first_prop_name
880 * Adds @widget to @container, setting child properties at the same time.
881 * See gtk_container_add() and gtk_container_child_set() for more details.
884 gtk_container_add_with_properties (GtkContainer *container,
886 const gchar *first_prop_name,
889 g_return_if_fail (GTK_IS_CONTAINER (container));
890 g_return_if_fail (GTK_IS_WIDGET (widget));
891 g_return_if_fail (gtk_widget_get_parent (widget) == NULL);
893 g_object_ref (container);
894 g_object_ref (widget);
895 gtk_widget_freeze_child_notify (widget);
897 g_signal_emit (container, container_signals[ADD], 0, widget);
898 if (gtk_widget_get_parent (widget))
902 va_start (var_args, first_prop_name);
903 gtk_container_child_set_valist (container, widget, first_prop_name, var_args);
907 gtk_widget_thaw_child_notify (widget);
908 g_object_unref (widget);
909 g_object_unref (container);
913 * gtk_container_child_set:
914 * @container: a #GtkContainer
915 * @child: a widget which is a child of @container
916 * @first_prop_name: the name of the first property to set
917 * @Varargs: a %NULL-terminated list of property names and values, starting
918 * with @first_prop_name
920 * Sets one or more child properties for @child and @container.
923 gtk_container_child_set (GtkContainer *container,
925 const gchar *first_prop_name,
930 g_return_if_fail (GTK_IS_CONTAINER (container));
931 g_return_if_fail (GTK_IS_WIDGET (child));
932 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
934 va_start (var_args, first_prop_name);
935 gtk_container_child_set_valist (container, child, first_prop_name, var_args);
940 * gtk_container_child_get:
941 * @container: a #GtkContainer
942 * @child: a widget which is a child of @container
943 * @first_prop_name: the name of the first property to get
944 * @Varargs: return location for the first property, followed
945 * optionally by more name/return location pairs, followed by %NULL
947 * Gets the values of one or more child properties for @child and @container.
950 gtk_container_child_get (GtkContainer *container,
952 const gchar *first_prop_name,
957 g_return_if_fail (GTK_IS_CONTAINER (container));
958 g_return_if_fail (GTK_IS_WIDGET (child));
959 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
961 va_start (var_args, first_prop_name);
962 gtk_container_child_get_valist (container, child, first_prop_name, var_args);
967 * gtk_container_class_install_child_property:
968 * @cclass: a #GtkContainerClass
969 * @property_id: the id for the property
970 * @pspec: the #GParamSpec for the property
972 * Installs a child property on a container class.
975 gtk_container_class_install_child_property (GtkContainerClass *cclass,
979 g_return_if_fail (GTK_IS_CONTAINER_CLASS (cclass));
980 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
981 if (pspec->flags & G_PARAM_WRITABLE)
982 g_return_if_fail (cclass->set_child_property != NULL);
983 if (pspec->flags & G_PARAM_READABLE)
984 g_return_if_fail (cclass->get_child_property != NULL);
985 g_return_if_fail (property_id > 0);
986 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
987 if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
988 g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
990 if (g_param_spec_pool_lookup (_gtk_widget_child_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (cclass), FALSE))
992 g_warning (G_STRLOC ": class `%s' already contains a child property named `%s'",
993 G_OBJECT_CLASS_NAME (cclass),
997 g_param_spec_ref (pspec);
998 g_param_spec_sink (pspec);
999 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
1000 g_param_spec_pool_insert (_gtk_widget_child_property_pool, pspec, G_OBJECT_CLASS_TYPE (cclass));
1004 * gtk_container_class_find_child_property:
1005 * @cclass: a #GtkContainerClass
1006 * @property_name: the name of the child property to find
1007 * @returns: (allow-none): the #GParamSpec of the child property or %NULL if @class has no
1008 * child property with that name.
1010 * Finds a child property of a container class by name.
1013 gtk_container_class_find_child_property (GObjectClass *cclass,
1014 const gchar *property_name)
1016 g_return_val_if_fail (GTK_IS_CONTAINER_CLASS (cclass), NULL);
1017 g_return_val_if_fail (property_name != NULL, NULL);
1019 return g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1021 G_OBJECT_CLASS_TYPE (cclass),
1026 * gtk_container_class_list_child_properties:
1027 * @cclass: a #GtkContainerClass
1028 * @n_properties: location to return the number of child properties found
1029 * @returns: a newly allocated %NULL-terminated array of #GParamSpec*.
1030 * The array must be freed with g_free().
1032 * Returns all child properties of a container class.
1035 gtk_container_class_list_child_properties (GObjectClass *cclass,
1036 guint *n_properties)
1038 GParamSpec **pspecs;
1041 g_return_val_if_fail (GTK_IS_CONTAINER_CLASS (cclass), NULL);
1043 pspecs = g_param_spec_pool_list (_gtk_widget_child_property_pool,
1044 G_OBJECT_CLASS_TYPE (cclass),
1053 gtk_container_add_unimplemented (GtkContainer *container,
1056 g_warning ("GtkContainerClass::add not implemented for `%s'", g_type_name (G_TYPE_FROM_INSTANCE (container)));
1060 gtk_container_remove_unimplemented (GtkContainer *container,
1063 g_warning ("GtkContainerClass::remove not implemented for `%s'", g_type_name (G_TYPE_FROM_INSTANCE (container)));
1067 gtk_container_init (GtkContainer *container)
1069 GtkContainerPrivate *priv;
1071 container->priv = G_TYPE_INSTANCE_GET_PRIVATE (container,
1073 GtkContainerPrivate);
1074 priv = container->priv;
1076 priv->focus_child = NULL;
1077 priv->border_width = 0;
1078 priv->need_resize = FALSE;
1079 priv->resize_mode = GTK_RESIZE_PARENT;
1080 priv->reallocate_redraws = FALSE;
1084 gtk_container_destroy (GtkWidget *widget)
1086 GtkContainer *container = GTK_CONTAINER (widget);
1087 GtkContainerPrivate *priv = container->priv;
1089 if (GTK_CONTAINER_RESIZE_PENDING (container))
1090 _gtk_container_dequeue_resize_handler (container);
1092 if (priv->focus_child)
1094 g_object_unref (priv->focus_child);
1095 priv->focus_child = NULL;
1098 /* do this before walking child widgets, to avoid
1099 * removing children from focus chain one by one.
1101 if (priv->has_focus_chain)
1102 gtk_container_unset_focus_chain (container);
1104 gtk_container_foreach (container, (GtkCallback) gtk_widget_destroy, NULL);
1106 GTK_WIDGET_CLASS (parent_class)->destroy (widget);
1110 gtk_container_set_property (GObject *object,
1112 const GValue *value,
1115 GtkContainer *container = GTK_CONTAINER (object);
1119 case PROP_BORDER_WIDTH:
1120 gtk_container_set_border_width (container, g_value_get_uint (value));
1122 case PROP_RESIZE_MODE:
1123 gtk_container_set_resize_mode (container, g_value_get_enum (value));
1126 gtk_container_add (container, GTK_WIDGET (g_value_get_object (value)));
1129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1135 gtk_container_get_property (GObject *object,
1140 GtkContainer *container = GTK_CONTAINER (object);
1141 GtkContainerPrivate *priv = container->priv;
1145 case PROP_BORDER_WIDTH:
1146 g_value_set_uint (value, priv->border_width);
1148 case PROP_RESIZE_MODE:
1149 g_value_set_enum (value, priv->resize_mode);
1152 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1158 * gtk_container_set_border_width:
1159 * @container: a #GtkContainer
1160 * @border_width: amount of blank space to leave <emphasis>outside</emphasis>
1161 * the container. Valid values are in the range 0-65535 pixels.
1163 * Sets the border width of the container.
1165 * The border width of a container is the amount of space to leave
1166 * around the outside of the container. The only exception to this is
1167 * #GtkWindow; because toplevel windows can't leave space outside,
1168 * they leave the space inside. The border is added on all sides of
1169 * the container. To add space to only one side, one approach is to
1170 * create a #GtkAlignment widget, call gtk_widget_set_size_request()
1171 * to give it a size, and place it on the side of the container as
1175 gtk_container_set_border_width (GtkContainer *container,
1178 GtkContainerPrivate *priv;
1180 g_return_if_fail (GTK_IS_CONTAINER (container));
1182 priv = container->priv;
1184 if (priv->border_width != border_width)
1186 priv->border_width = border_width;
1187 g_object_notify (G_OBJECT (container), "border-width");
1189 if (gtk_widget_get_realized (GTK_WIDGET (container)))
1190 gtk_widget_queue_resize (GTK_WIDGET (container));
1195 * gtk_container_get_border_width:
1196 * @container: a #GtkContainer
1198 * Retrieves the border width of the container. See
1199 * gtk_container_set_border_width().
1201 * Return value: the current border width
1204 gtk_container_get_border_width (GtkContainer *container)
1206 g_return_val_if_fail (GTK_IS_CONTAINER (container), 0);
1208 return container->priv->border_width;
1212 * gtk_container_add:
1213 * @container: a #GtkContainer
1214 * @widget: a widget to be placed inside @container
1216 * Adds @widget to @container. Typically used for simple containers
1217 * such as #GtkWindow, #GtkFrame, or #GtkButton; for more complicated
1218 * layout containers such as #GtkBox or #GtkTable, this function will
1219 * pick default packing parameters that may not be correct. So
1220 * consider functions such as gtk_box_pack_start() and
1221 * gtk_table_attach() as an alternative to gtk_container_add() in
1222 * those cases. A widget may be added to only one container at a time;
1223 * you can't place the same widget inside two different containers.
1226 gtk_container_add (GtkContainer *container,
1231 g_return_if_fail (GTK_IS_CONTAINER (container));
1232 g_return_if_fail (GTK_IS_WIDGET (widget));
1234 parent = gtk_widget_get_parent (widget);
1238 g_warning ("Attempting to add a widget with type %s to a container of "
1239 "type %s, but the widget is already inside a container of type %s, "
1240 "the GTK+ FAQ at http://library.gnome.org/devel/gtk-faq/stable/ "
1241 "explains how to reparent a widget.",
1242 g_type_name (G_OBJECT_TYPE (widget)),
1243 g_type_name (G_OBJECT_TYPE (container)),
1244 g_type_name (G_OBJECT_TYPE (parent)));
1248 g_signal_emit (container, container_signals[ADD], 0, widget);
1252 * gtk_container_remove:
1253 * @container: a #GtkContainer
1254 * @widget: a current child of @container
1256 * Removes @widget from @container. @widget must be inside @container.
1257 * Note that @container will own a reference to @widget, and that this
1258 * may be the last reference held; so removing a widget from its
1259 * container can destroy that widget. If you want to use @widget
1260 * again, you need to add a reference to it while it's not inside
1261 * a container, using g_object_ref(). If you don't want to use @widget
1262 * again it's usually more efficient to simply destroy it directly
1263 * using gtk_widget_destroy() since this will remove it from the
1264 * container and help break any circular reference count cycles.
1267 gtk_container_remove (GtkContainer *container,
1270 g_return_if_fail (GTK_IS_CONTAINER (container));
1271 g_return_if_fail (GTK_IS_WIDGET (widget));
1272 g_return_if_fail (gtk_widget_get_parent (widget) == GTK_WIDGET (container));
1274 g_signal_emit (container, container_signals[REMOVE], 0, widget);
1278 _gtk_container_dequeue_resize_handler (GtkContainer *container)
1280 g_return_if_fail (GTK_IS_CONTAINER (container));
1281 g_return_if_fail (GTK_CONTAINER_RESIZE_PENDING (container));
1283 container_resize_queue = g_slist_remove (container_resize_queue, container);
1284 GTK_PRIVATE_UNSET_FLAG (container, GTK_RESIZE_PENDING);
1288 * gtk_container_set_resize_mode:
1289 * @container: a #GtkContainer
1290 * @resize_mode: the new resize mode
1292 * Sets the resize mode for the container.
1294 * The resize mode of a container determines whether a resize request
1295 * will be passed to the container's parent, queued for later execution
1296 * or executed immediately.
1299 gtk_container_set_resize_mode (GtkContainer *container,
1300 GtkResizeMode resize_mode)
1302 GtkContainerPrivate *priv;
1304 g_return_if_fail (GTK_IS_CONTAINER (container));
1305 g_return_if_fail (resize_mode <= GTK_RESIZE_IMMEDIATE);
1307 priv = container->priv;
1309 if (gtk_widget_is_toplevel (GTK_WIDGET (container)) &&
1310 resize_mode == GTK_RESIZE_PARENT)
1312 resize_mode = GTK_RESIZE_QUEUE;
1315 if (priv->resize_mode != resize_mode)
1317 priv->resize_mode = resize_mode;
1319 gtk_widget_queue_resize (GTK_WIDGET (container));
1320 g_object_notify (G_OBJECT (container), "resize-mode");
1325 * gtk_container_get_resize_mode:
1326 * @container: a #GtkContainer
1328 * Returns the resize mode for the container. See
1329 * gtk_container_set_resize_mode ().
1331 * Return value: the current resize mode
1334 gtk_container_get_resize_mode (GtkContainer *container)
1336 g_return_val_if_fail (GTK_IS_CONTAINER (container), GTK_RESIZE_PARENT);
1338 return container->priv->resize_mode;
1342 * gtk_container_set_reallocate_redraws:
1343 * @container: a #GtkContainer
1344 * @needs_redraws: the new value for the container's @reallocate_redraws flag
1346 * Sets the @reallocate_redraws flag of the container to the given value.
1348 * Containers requesting reallocation redraws get automatically
1349 * redrawn if any of their children changed allocation.
1352 gtk_container_set_reallocate_redraws (GtkContainer *container,
1353 gboolean needs_redraws)
1355 g_return_if_fail (GTK_IS_CONTAINER (container));
1357 container->priv->reallocate_redraws = needs_redraws ? TRUE : FALSE;
1360 static GtkContainer*
1361 gtk_container_get_resize_container (GtkContainer *container)
1364 GtkWidget *widget = GTK_WIDGET (container);
1366 while ((parent = gtk_widget_get_parent (widget)))
1369 if (GTK_IS_RESIZE_CONTAINER (widget))
1373 return GTK_IS_RESIZE_CONTAINER (widget) ? (GtkContainer*) widget : NULL;
1377 gtk_container_idle_sizer (gpointer data)
1379 /* we may be invoked with a container_resize_queue of NULL, because
1380 * queue_resize could have been adding an extra idle function while
1381 * the queue still got processed. we better just ignore such case
1382 * than trying to explicitely work around them with some extra flags,
1383 * since it doesn't cause any actual harm.
1385 while (container_resize_queue)
1390 slist = container_resize_queue;
1391 container_resize_queue = slist->next;
1392 widget = slist->data;
1393 g_slist_free_1 (slist);
1395 GTK_PRIVATE_UNSET_FLAG (widget, GTK_RESIZE_PENDING);
1396 gtk_container_check_resize (GTK_CONTAINER (widget));
1399 gdk_window_process_all_updates ();
1405 _gtk_container_queue_resize (GtkContainer *container)
1407 GtkContainerPrivate *priv;
1408 GtkContainer *resize_container;
1412 g_return_if_fail (GTK_IS_CONTAINER (container));
1414 priv = container->priv;
1415 widget = GTK_WIDGET (container);
1417 resize_container = gtk_container_get_resize_container (container);
1421 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1422 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
1423 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
1425 if ((resize_container && widget == GTK_WIDGET (resize_container)) ||
1426 !(parent = gtk_widget_get_parent (widget)))
1432 if (resize_container)
1434 if (gtk_widget_get_visible (GTK_WIDGET (resize_container)) &&
1435 (gtk_widget_is_toplevel (GTK_WIDGET (resize_container)) ||
1436 gtk_widget_get_realized (GTK_WIDGET (resize_container))))
1438 switch (resize_container->priv->resize_mode)
1440 case GTK_RESIZE_QUEUE:
1441 if (!GTK_CONTAINER_RESIZE_PENDING (resize_container))
1443 GTK_PRIVATE_SET_FLAG (resize_container, GTK_RESIZE_PENDING);
1444 if (container_resize_queue == NULL)
1445 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE,
1446 gtk_container_idle_sizer,
1448 container_resize_queue = g_slist_prepend (container_resize_queue, resize_container);
1452 case GTK_RESIZE_IMMEDIATE:
1453 gtk_container_check_resize (resize_container);
1456 case GTK_RESIZE_PARENT:
1457 g_assert_not_reached ();
1463 /* we need to let hidden resize containers know that something
1464 * changed while they where hidden (currently only evaluated by
1467 resize_container->priv->need_resize = TRUE;
1473 gtk_container_check_resize (GtkContainer *container)
1475 g_return_if_fail (GTK_IS_CONTAINER (container));
1477 g_signal_emit (container, container_signals[CHECK_RESIZE], 0);
1481 gtk_container_real_check_resize (GtkContainer *container)
1483 GtkWidget *widget = GTK_WIDGET (container);
1484 GtkAllocation allocation;
1485 GtkRequisition requisition;
1487 gtk_widget_get_preferred_size (widget,
1488 &requisition, NULL);
1489 gtk_widget_get_allocation (widget, &allocation);
1491 if (requisition.width > allocation.width ||
1492 requisition.height > allocation.height)
1494 if (GTK_IS_RESIZE_CONTAINER (container))
1496 gtk_widget_size_allocate (widget, &allocation);
1497 gtk_widget_set_allocation (widget, &allocation);
1500 gtk_widget_queue_resize (widget);
1504 gtk_container_resize_children (container);
1508 /* The container hasn't changed size but one of its children
1509 * queued a resize request. Which means that the allocation
1510 * is not sufficient for the requisition of some child.
1511 * We've already performed a size request at this point,
1512 * so we simply need to reallocate and let the allocation
1513 * trickle down via GTK_WIDGET_ALLOC_NEEDED flags.
1516 gtk_container_resize_children (GtkContainer *container)
1518 GtkAllocation allocation;
1521 /* resizing invariants:
1522 * toplevels have *always* resize_mode != GTK_RESIZE_PARENT set.
1523 * containers that have an idle sizer pending must be flagged with
1526 g_return_if_fail (GTK_IS_CONTAINER (container));
1528 widget = GTK_WIDGET (container);
1529 gtk_widget_get_allocation (widget, &allocation);
1531 gtk_widget_size_allocate (widget, &allocation);
1532 gtk_widget_set_allocation (widget, &allocation);
1536 gtk_container_adjust_size_request (GtkWidget *widget,
1537 GtkOrientation orientation,
1542 GtkContainer *container;
1544 container = GTK_CONTAINER (widget);
1546 if (GTK_CONTAINER_GET_CLASS (widget)->handle_border_width)
1550 border_width = container->priv->border_width;
1552 *minimum_size += border_width * 2;
1553 *natural_size += border_width * 2;
1556 /* chain up last so gtk_widget_set_size_request() values
1557 * will have a chance to overwrite our border width.
1559 parent_class->adjust_size_request (widget, orientation, for_size,
1560 minimum_size, natural_size);
1564 gtk_container_adjust_size_allocation (GtkWidget *widget,
1565 GtkAllocation *allocation)
1567 GtkContainer *container;
1570 container = GTK_CONTAINER (widget);
1572 parent_class->adjust_size_allocation (widget, allocation);
1574 if (!GTK_CONTAINER_GET_CLASS (widget)->handle_border_width)
1577 border_width = container->priv->border_width;
1579 allocation->width -= border_width * 2;
1580 allocation->height -= border_width * 2;
1582 /* If we get a pathological too-small allocation to hold
1583 * even the border width, leave all allocation to the actual
1584 * widget, and leave x,y unchanged. (GtkWidget's min size is
1585 * 1x1 if you're wondering why <1 and not <0)
1587 * As long as we have space, set x,y properly.
1590 if (allocation->width < 1)
1592 allocation->width += border_width * 2;
1596 allocation->x += border_width;
1599 if (allocation->height < 1)
1601 allocation->height += border_width * 2;
1605 allocation->y += border_width;
1610 * gtk_container_class_handle_border_width:
1611 * @klass: the class struct of a #GtkContainer subclass
1613 * Modifies a subclass of #GtkContainerClass to automatically add and
1614 * remove the border-width setting on GtkContainer. This allows the
1615 * subclass to ignore the border width in its size request and
1616 * allocate methods. The intent is for a subclass to invoke this
1617 * in its class_init function.
1619 * gtk_container_class_handle_border_width() is necessary because it
1620 * would break API too badly to make this behavior the default. So
1621 * subclasses must "opt in" to the parent class handling border_width
1625 gtk_container_class_handle_border_width (GtkContainerClass *klass)
1627 g_return_if_fail (GTK_IS_CONTAINER_CLASS (klass));
1629 klass->handle_border_width = TRUE;
1633 * gtk_container_forall:
1634 * @container: a #GtkContainer
1635 * @callback: a callback
1636 * @callback_data: callback user data
1638 * Invokes @callback on each child of @container, including children
1639 * that are considered "internal" (implementation details of the
1640 * container). "Internal" children generally weren't added by the user
1641 * of the container, but were added by the container implementation
1642 * itself. Most applications should use gtk_container_foreach(),
1643 * rather than gtk_container_forall().
1646 gtk_container_forall (GtkContainer *container,
1647 GtkCallback callback,
1648 gpointer callback_data)
1650 GtkContainerClass *class;
1652 g_return_if_fail (GTK_IS_CONTAINER (container));
1653 g_return_if_fail (callback != NULL);
1655 class = GTK_CONTAINER_GET_CLASS (container);
1658 class->forall (container, TRUE, callback, callback_data);
1662 * gtk_container_foreach:
1663 * @container: a #GtkContainer
1664 * @callback: (scope call): a callback
1665 * @callback_data: callback user data
1667 * Invokes @callback on each non-internal child of @container. See
1668 * gtk_container_forall() for details on what constitutes an
1669 * "internal" child. Most applications should use
1670 * gtk_container_foreach(), rather than gtk_container_forall().
1673 gtk_container_foreach (GtkContainer *container,
1674 GtkCallback callback,
1675 gpointer callback_data)
1677 GtkContainerClass *class;
1679 g_return_if_fail (GTK_IS_CONTAINER (container));
1680 g_return_if_fail (callback != NULL);
1682 class = GTK_CONTAINER_GET_CLASS (container);
1685 class->forall (container, FALSE, callback, callback_data);
1689 * gtk_container_set_focus_child:
1690 * @container: a #GtkContainer
1691 * @child: (allow-none): a #GtkWidget, or %NULL
1693 * Sets, or unsets if @child is %NULL, the focused child of @container.
1695 * This function emits the GtkContainer::set_focus_child signal of
1696 * @container. Implementations of #GtkContainer can override the
1697 * default behaviour by overriding the class closure of this signal.
1699 * This is function is mostly meant to be used by widgets. Applications can use
1700 * gtk_widget_grab_focus() to manualy set the focus to a specific widget.
1703 gtk_container_set_focus_child (GtkContainer *container,
1706 g_return_if_fail (GTK_IS_CONTAINER (container));
1708 g_return_if_fail (GTK_IS_WIDGET (child));
1710 g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, child);
1714 * gtk_container_get_focus_child:
1715 * @container: a #GtkContainer
1717 * Returns the current focus child widget inside @container. This is not the
1718 * currently focused widget. That can be obtained by calling
1719 * gtk_window_get_focus().
1721 * Returns: The child widget which will recieve the focus inside @container when
1722 * the @conatiner is focussed, or %NULL if none is set.
1727 gtk_container_get_focus_child (GtkContainer *container)
1729 g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
1731 return container->priv->focus_child;
1735 * gtk_container_get_children:
1736 * @container: a #GtkContainer
1738 * Returns the container's non-internal children. See
1739 * gtk_container_forall() for details on what constitutes an "internal" child.
1741 * Return value: (element-type GtkWidget) (transfer container): a newly-allocated list of the container's non-internal children.
1744 gtk_container_get_children (GtkContainer *container)
1746 GList *children = NULL;
1748 gtk_container_foreach (container,
1749 gtk_container_children_callback,
1752 return g_list_reverse (children);
1756 gtk_container_child_position_callback (GtkWidget *widget,
1757 gpointer client_data)
1763 } *data = client_data;
1766 if (data->child == widget)
1767 data->index = data->i;
1771 gtk_container_child_default_composite_name (GtkContainer *container,
1781 /* fallback implementation */
1785 gtk_container_forall (container,
1786 gtk_container_child_position_callback,
1789 name = g_strdup_printf ("%s-%u",
1790 g_type_name (G_TYPE_FROM_INSTANCE (child)),
1797 _gtk_container_child_composite_name (GtkContainer *container,
1800 gboolean composite_child;
1802 g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
1803 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
1804 g_return_val_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container), NULL);
1806 g_object_get (child, "composite-child", &composite_child, NULL);
1807 if (composite_child)
1809 static GQuark quark_composite_name = 0;
1812 if (!quark_composite_name)
1813 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
1815 name = g_object_get_qdata (G_OBJECT (child), quark_composite_name);
1818 GtkContainerClass *class;
1820 class = GTK_CONTAINER_GET_CLASS (container);
1821 if (class->composite_name)
1822 name = class->composite_name (container, child);
1825 name = g_strdup (name);
1834 gtk_container_real_set_focus_child (GtkContainer *container,
1837 GtkContainerPrivate *priv;
1839 g_return_if_fail (GTK_IS_CONTAINER (container));
1840 g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
1842 priv = container->priv;
1844 if (child != priv->focus_child)
1846 if (priv->focus_child)
1847 g_object_unref (priv->focus_child);
1848 priv->focus_child = child;
1849 if (priv->focus_child)
1850 g_object_ref (priv->focus_child);
1854 /* check for h/v adjustments
1856 if (priv->focus_child)
1858 GtkAdjustment *hadj;
1859 GtkAdjustment *vadj;
1860 GtkAllocation allocation;
1861 GtkWidget *focus_child;
1864 hadj = g_object_get_qdata (G_OBJECT (container), hadjustment_key_id);
1865 vadj = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id);
1869 focus_child = priv->focus_child;
1870 while (gtk_container_get_focus_child (GTK_CONTAINER (focus_child)))
1872 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (focus_child));
1875 gtk_widget_translate_coordinates (focus_child, priv->focus_child,
1878 gtk_widget_get_allocation (priv->focus_child, &allocation);
1882 gtk_widget_get_allocation (focus_child, &allocation);
1885 gtk_adjustment_clamp_page (vadj, y, y + allocation.height);
1888 gtk_adjustment_clamp_page (hadj, x, x + allocation.width);
1894 get_focus_chain (GtkContainer *container)
1896 return g_object_get_data (G_OBJECT (container), "gtk-container-focus-chain");
1899 /* same as gtk_container_get_children, except it includes internals
1902 gtk_container_get_all_children (GtkContainer *container)
1904 GList *children = NULL;
1906 gtk_container_forall (container,
1907 gtk_container_children_callback,
1914 gtk_container_focus (GtkWidget *widget,
1915 GtkDirectionType direction)
1918 GList *sorted_children;
1920 GtkContainer *container;
1921 GtkContainerPrivate *priv;
1923 g_return_val_if_fail (GTK_IS_CONTAINER (widget), FALSE);
1925 container = GTK_CONTAINER (widget);
1926 priv = container->priv;
1930 if (gtk_widget_get_can_focus (widget))
1932 if (!gtk_widget_has_focus (widget))
1934 gtk_widget_grab_focus (widget);
1940 /* Get a list of the containers children, allowing focus
1941 * chain to override.
1943 if (priv->has_focus_chain)
1944 children = g_list_copy (get_focus_chain (container));
1946 children = gtk_container_get_all_children (container);
1948 if (priv->has_focus_chain &&
1949 (direction == GTK_DIR_TAB_FORWARD ||
1950 direction == GTK_DIR_TAB_BACKWARD))
1952 sorted_children = g_list_copy (children);
1954 if (direction == GTK_DIR_TAB_BACKWARD)
1955 sorted_children = g_list_reverse (sorted_children);
1958 sorted_children = _gtk_container_focus_sort (container, children, direction, NULL);
1960 return_val = gtk_container_focus_move (container, sorted_children, direction);
1962 g_list_free (sorted_children);
1963 g_list_free (children);
1970 tab_compare (gconstpointer a,
1974 GtkAllocation child1_allocation, child2_allocation;
1975 const GtkWidget *child1 = a;
1976 const GtkWidget *child2 = b;
1977 GtkTextDirection text_direction = GPOINTER_TO_INT (data);
1979 gtk_widget_get_allocation ((GtkWidget *) child1, &child1_allocation);
1980 gtk_widget_get_allocation ((GtkWidget *) child2, &child2_allocation);
1982 gint y1 = child1_allocation.y + child1_allocation.height / 2;
1983 gint y2 = child2_allocation.y + child2_allocation.height / 2;
1987 gint x1 = child1_allocation.x + child1_allocation.width / 2;
1988 gint x2 = child2_allocation.x + child2_allocation.width / 2;
1990 if (text_direction == GTK_TEXT_DIR_RTL)
1991 return (x1 < x2) ? 1 : ((x1 == x2) ? 0 : -1);
1993 return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
1996 return (y1 < y2) ? -1 : 1;
2000 gtk_container_focus_sort_tab (GtkContainer *container,
2002 GtkDirectionType direction,
2003 GtkWidget *old_focus)
2005 GtkTextDirection text_direction = gtk_widget_get_direction (GTK_WIDGET (container));
2006 children = g_list_sort_with_data (children, tab_compare, GINT_TO_POINTER (text_direction));
2008 /* if we are going backwards then reverse the order
2011 if (direction == GTK_DIR_TAB_BACKWARD)
2012 children = g_list_reverse (children);
2017 /* Get coordinates of @widget's allocation with respect to
2018 * allocation of @container.
2021 get_allocation_coords (GtkContainer *container,
2023 GdkRectangle *allocation)
2025 gtk_widget_set_allocation (widget, allocation);
2027 return gtk_widget_translate_coordinates (widget, GTK_WIDGET (container),
2028 0, 0, &allocation->x, &allocation->y);
2031 /* Look for a child in @children that is intermediate between
2032 * the focus widget and container. This widget, if it exists,
2033 * acts as the starting widget for focus navigation.
2036 find_old_focus (GtkContainer *container,
2039 GList *tmp_list = children;
2042 GtkWidget *child = tmp_list->data;
2043 GtkWidget *widget = child;
2045 while (widget && widget != (GtkWidget *)container)
2049 parent = gtk_widget_get_parent (widget);
2051 if (parent && (gtk_container_get_focus_child (GTK_CONTAINER (parent)) != widget))
2060 tmp_list = tmp_list->next;
2067 old_focus_coords (GtkContainer *container,
2068 GdkRectangle *old_focus_rect)
2070 GtkWidget *widget = GTK_WIDGET (container);
2071 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
2072 GtkWidget *old_focus;
2074 if (GTK_IS_WINDOW (toplevel))
2076 old_focus = gtk_window_get_focus (GTK_WINDOW (toplevel));
2078 return get_allocation_coords (container, old_focus, old_focus_rect);
2084 typedef struct _CompareInfo CompareInfo;
2088 GtkContainer *container;
2095 up_down_compare (gconstpointer a,
2099 GdkRectangle allocation1;
2100 GdkRectangle allocation2;
2101 CompareInfo *compare = data;
2104 get_allocation_coords (compare->container, (GtkWidget *)a, &allocation1);
2105 get_allocation_coords (compare->container, (GtkWidget *)b, &allocation2);
2107 y1 = allocation1.y + allocation1.height / 2;
2108 y2 = allocation2.y + allocation2.height / 2;
2112 gint x1 = abs (allocation1.x + allocation1.width / 2 - compare->x);
2113 gint x2 = abs (allocation2.x + allocation2.width / 2 - compare->x);
2115 if (compare->reverse)
2116 return (x1 < x2) ? 1 : ((x1 == x2) ? 0 : -1);
2118 return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
2121 return (y1 < y2) ? -1 : 1;
2125 gtk_container_focus_sort_up_down (GtkContainer *container,
2127 GtkDirectionType direction,
2128 GtkWidget *old_focus)
2130 CompareInfo compare;
2132 GdkRectangle old_allocation;
2134 compare.container = container;
2135 compare.reverse = (direction == GTK_DIR_UP);
2138 old_focus = find_old_focus (container, children);
2140 if (old_focus && get_allocation_coords (container, old_focus, &old_allocation))
2146 /* Delete widgets from list that don't match minimum criteria */
2148 compare_x1 = old_allocation.x;
2149 compare_x2 = old_allocation.x + old_allocation.width;
2151 if (direction == GTK_DIR_UP)
2152 compare_y = old_allocation.y;
2154 compare_y = old_allocation.y + old_allocation.height;
2156 tmp_list = children;
2159 GtkWidget *child = tmp_list->data;
2160 GList *next = tmp_list->next;
2161 gint child_x1, child_x2;
2162 GdkRectangle child_allocation;
2164 if (child != old_focus)
2166 if (get_allocation_coords (container, child, &child_allocation))
2168 child_x1 = child_allocation.x;
2169 child_x2 = child_allocation.x + child_allocation.width;
2171 if ((child_x2 <= compare_x1 || child_x1 >= compare_x2) /* No horizontal overlap */ ||
2172 (direction == GTK_DIR_DOWN && child_allocation.y + child_allocation.height < compare_y) || /* Not below */
2173 (direction == GTK_DIR_UP && child_allocation.y > compare_y)) /* Not above */
2175 children = g_list_delete_link (children, tmp_list);
2179 children = g_list_delete_link (children, tmp_list);
2185 compare.x = (compare_x1 + compare_x2) / 2;
2186 compare.y = old_allocation.y + old_allocation.height / 2;
2190 /* No old focus widget, need to figure out starting x,y some other way
2192 GtkAllocation allocation;
2193 GtkWidget *widget = GTK_WIDGET (container);
2194 GdkRectangle old_focus_rect;
2196 gtk_widget_get_allocation (widget, &allocation);
2198 if (old_focus_coords (container, &old_focus_rect))
2200 compare.x = old_focus_rect.x + old_focus_rect.width / 2;
2204 if (!gtk_widget_get_has_window (widget))
2205 compare.x = allocation.x + allocation.width / 2;
2207 compare.x = allocation.width / 2;
2210 if (!gtk_widget_get_has_window (widget))
2211 compare.y = (direction == GTK_DIR_DOWN) ? allocation.y : allocation.y + allocation.height;
2213 compare.y = (direction == GTK_DIR_DOWN) ? 0 : + allocation.height;
2216 children = g_list_sort_with_data (children, up_down_compare, &compare);
2218 if (compare.reverse)
2219 children = g_list_reverse (children);
2225 left_right_compare (gconstpointer a,
2229 GdkRectangle allocation1;
2230 GdkRectangle allocation2;
2231 CompareInfo *compare = data;
2234 get_allocation_coords (compare->container, (GtkWidget *)a, &allocation1);
2235 get_allocation_coords (compare->container, (GtkWidget *)b, &allocation2);
2237 x1 = allocation1.x + allocation1.width / 2;
2238 x2 = allocation2.x + allocation2.width / 2;
2242 gint y1 = abs (allocation1.y + allocation1.height / 2 - compare->y);
2243 gint y2 = abs (allocation2.y + allocation2.height / 2 - compare->y);
2245 if (compare->reverse)
2246 return (y1 < y2) ? 1 : ((y1 == y2) ? 0 : -1);
2248 return (y1 < y2) ? -1 : ((y1 == y2) ? 0 : 1);
2251 return (x1 < x2) ? -1 : 1;
2255 gtk_container_focus_sort_left_right (GtkContainer *container,
2257 GtkDirectionType direction,
2258 GtkWidget *old_focus)
2260 CompareInfo compare;
2262 GdkRectangle old_allocation;
2264 compare.container = container;
2265 compare.reverse = (direction == GTK_DIR_LEFT);
2268 old_focus = find_old_focus (container, children);
2270 if (old_focus && get_allocation_coords (container, old_focus, &old_allocation))
2276 /* Delete widgets from list that don't match minimum criteria */
2278 compare_y1 = old_allocation.y;
2279 compare_y2 = old_allocation.y + old_allocation.height;
2281 if (direction == GTK_DIR_LEFT)
2282 compare_x = old_allocation.x;
2284 compare_x = old_allocation.x + old_allocation.width;
2286 tmp_list = children;
2289 GtkWidget *child = tmp_list->data;
2290 GList *next = tmp_list->next;
2291 gint child_y1, child_y2;
2292 GdkRectangle child_allocation;
2294 if (child != old_focus)
2296 if (get_allocation_coords (container, child, &child_allocation))
2298 child_y1 = child_allocation.y;
2299 child_y2 = child_allocation.y + child_allocation.height;
2301 if ((child_y2 <= compare_y1 || child_y1 >= compare_y2) /* No vertical overlap */ ||
2302 (direction == GTK_DIR_RIGHT && child_allocation.x + child_allocation.width < compare_x) || /* Not to left */
2303 (direction == GTK_DIR_LEFT && child_allocation.x > compare_x)) /* Not to right */
2305 children = g_list_delete_link (children, tmp_list);
2309 children = g_list_delete_link (children, tmp_list);
2315 compare.y = (compare_y1 + compare_y2) / 2;
2316 compare.x = old_allocation.x + old_allocation.width / 2;
2320 /* No old focus widget, need to figure out starting x,y some other way
2322 GtkAllocation allocation;
2323 GtkWidget *widget = GTK_WIDGET (container);
2324 GdkRectangle old_focus_rect;
2326 gtk_widget_get_allocation (widget, &allocation);
2328 if (old_focus_coords (container, &old_focus_rect))
2330 compare.y = old_focus_rect.y + old_focus_rect.height / 2;
2334 if (!gtk_widget_get_has_window (widget))
2335 compare.y = allocation.y + allocation.height / 2;
2337 compare.y = allocation.height / 2;
2340 if (!gtk_widget_get_has_window (widget))
2341 compare.x = (direction == GTK_DIR_RIGHT) ? allocation.x : allocation.x + allocation.width;
2343 compare.x = (direction == GTK_DIR_RIGHT) ? 0 : allocation.width;
2346 children = g_list_sort_with_data (children, left_right_compare, &compare);
2348 if (compare.reverse)
2349 children = g_list_reverse (children);
2355 * gtk_container_focus_sort:
2356 * @container: a #GtkContainer
2357 * @children: a list of descendents of @container (they don't
2358 * have to be direct children)
2359 * @direction: focus direction
2360 * @old_focus: (allow-none): widget to use for the starting position, or %NULL
2361 * to determine this automatically.
2362 * (Note, this argument isn't used for GTK_DIR_TAB_*,
2363 * which is the only @direction we use currently,
2364 * so perhaps this argument should be removed)
2366 * Sorts @children in the correct order for focusing with
2367 * direction type @direction.
2369 * Return value: a copy of @children, sorted in correct focusing order,
2370 * with children that aren't suitable for focusing in this direction
2374 _gtk_container_focus_sort (GtkContainer *container,
2376 GtkDirectionType direction,
2377 GtkWidget *old_focus)
2379 GList *visible_children = NULL;
2383 if (gtk_widget_get_realized (children->data))
2384 visible_children = g_list_prepend (visible_children, children->data);
2385 children = children->next;
2390 case GTK_DIR_TAB_FORWARD:
2391 case GTK_DIR_TAB_BACKWARD:
2392 return gtk_container_focus_sort_tab (container, visible_children, direction, old_focus);
2395 return gtk_container_focus_sort_up_down (container, visible_children, direction, old_focus);
2398 return gtk_container_focus_sort_left_right (container, visible_children, direction, old_focus);
2401 g_assert_not_reached ();
2407 gtk_container_focus_move (GtkContainer *container,
2409 GtkDirectionType direction)
2411 GtkContainerPrivate *priv = container->priv;
2412 GtkWidget *focus_child;
2415 focus_child = priv->focus_child;
2419 child = children->data;
2420 children = children->next;
2427 if (focus_child == child)
2431 if (gtk_widget_child_focus (child, direction))
2435 else if (gtk_widget_is_drawable (child) &&
2436 gtk_widget_is_ancestor (child, GTK_WIDGET (container)))
2438 if (gtk_widget_child_focus (child, direction))
2448 gtk_container_children_callback (GtkWidget *widget,
2449 gpointer client_data)
2453 children = (GList**) client_data;
2454 *children = g_list_prepend (*children, widget);
2458 chain_widget_destroyed (GtkWidget *widget,
2461 GtkContainer *container;
2464 container = GTK_CONTAINER (user_data);
2466 chain = g_object_get_data (G_OBJECT (container),
2467 "gtk-container-focus-chain");
2469 chain = g_list_remove (chain, widget);
2471 g_signal_handlers_disconnect_by_func (widget,
2472 chain_widget_destroyed,
2475 g_object_set_data (G_OBJECT (container),
2476 I_("gtk-container-focus-chain"),
2481 * gtk_container_set_focus_chain:
2482 * @container: a #GtkContainer
2483 * @focusable_widgets: (transfer none) (element-type GtkWidget):
2484 * the new focus chain
2486 * Sets a focus chain, overriding the one computed automatically by GTK+.
2488 * In principle each widget in the chain should be a descendant of the
2489 * container, but this is not enforced by this method, since it's allowed
2490 * to set the focus chain before you pack the widgets, or have a widget
2491 * in the chain that isn't always packed. The necessary checks are done
2492 * when the focus chain is actually traversed.
2495 gtk_container_set_focus_chain (GtkContainer *container,
2496 GList *focusable_widgets)
2500 GtkContainerPrivate *priv;
2502 g_return_if_fail (GTK_IS_CONTAINER (container));
2504 priv = container->priv;
2506 if (priv->has_focus_chain)
2507 gtk_container_unset_focus_chain (container);
2509 priv->has_focus_chain = TRUE;
2512 tmp_list = focusable_widgets;
2513 while (tmp_list != NULL)
2515 g_return_if_fail (GTK_IS_WIDGET (tmp_list->data));
2517 /* In principle each widget in the chain should be a descendant
2518 * of the container, but we don't want to check that here, it's
2519 * expensive and also it's allowed to set the focus chain before
2520 * you pack the widgets, or have a widget in the chain that isn't
2521 * always packed. So we check for ancestor during actual traversal.
2524 chain = g_list_prepend (chain, tmp_list->data);
2526 g_signal_connect (tmp_list->data,
2528 G_CALLBACK (chain_widget_destroyed),
2531 tmp_list = g_list_next (tmp_list);
2534 chain = g_list_reverse (chain);
2536 g_object_set_data (G_OBJECT (container),
2537 I_("gtk-container-focus-chain"),
2542 * gtk_container_get_focus_chain:
2543 * @container: a #GtkContainer
2544 * @focusable_widgets: (element-type GtkWidget) (out) (transfer container): location
2545 * to store the focus chain of the
2546 * container, or %NULL. You should free this list
2547 * using g_list_free() when you are done with it, however
2548 * no additional reference count is added to the
2549 * individual widgets in the focus chain.
2551 * Retrieves the focus chain of the container, if one has been
2552 * set explicitly. If no focus chain has been explicitly
2553 * set, GTK+ computes the focus chain based on the positions
2554 * of the children. In that case, GTK+ stores %NULL in
2555 * @focusable_widgets and returns %FALSE.
2557 * Return value: %TRUE if the focus chain of the container
2558 * has been set explicitly.
2561 gtk_container_get_focus_chain (GtkContainer *container,
2562 GList **focus_chain)
2564 GtkContainerPrivate *priv;
2566 g_return_val_if_fail (GTK_IS_CONTAINER (container), FALSE);
2568 priv = container->priv;
2572 if (priv->has_focus_chain)
2573 *focus_chain = g_list_copy (get_focus_chain (container));
2575 *focus_chain = NULL;
2578 return priv->has_focus_chain;
2582 * gtk_container_unset_focus_chain:
2583 * @container: a #GtkContainer
2585 * Removes a focus chain explicitly set with gtk_container_set_focus_chain().
2588 gtk_container_unset_focus_chain (GtkContainer *container)
2590 GtkContainerPrivate *priv;
2592 g_return_if_fail (GTK_IS_CONTAINER (container));
2594 priv = container->priv;
2596 if (priv->has_focus_chain)
2601 chain = get_focus_chain (container);
2603 priv->has_focus_chain = FALSE;
2605 g_object_set_data (G_OBJECT (container),
2606 I_("gtk-container-focus-chain"),
2610 while (tmp_list != NULL)
2612 g_signal_handlers_disconnect_by_func (tmp_list->data,
2613 chain_widget_destroyed,
2616 tmp_list = g_list_next (tmp_list);
2619 g_list_free (chain);
2624 * gtk_container_set_focus_vadjustment:
2625 * @container: a #GtkContainer
2626 * @adjustment: an adjustment which should be adjusted when the focus
2627 * is moved among the descendents of @container
2629 * Hooks up an adjustment to focus handling in a container, so when a
2630 * child of the container is focused, the adjustment is scrolled to
2631 * show that widget. This function sets the vertical alignment. See
2632 * gtk_scrolled_window_get_vadjustment() for a typical way of obtaining
2633 * the adjustment and gtk_container_set_focus_hadjustment() for setting
2634 * the horizontal adjustment.
2636 * The adjustments have to be in pixel units and in the same coordinate
2637 * system as the allocation for immediate children of the container.
2640 gtk_container_set_focus_vadjustment (GtkContainer *container,
2641 GtkAdjustment *adjustment)
2643 g_return_if_fail (GTK_IS_CONTAINER (container));
2645 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2648 g_object_ref (adjustment);
2650 g_object_set_qdata_full (G_OBJECT (container),
2657 * gtk_container_get_focus_vadjustment:
2658 * @container: a #GtkContainer
2660 * Retrieves the vertical focus adjustment for the container. See
2661 * gtk_container_set_focus_vadjustment().
2663 * Return value: (transfer none): the vertical focus adjustment, or %NULL if
2664 * none has been set.
2667 gtk_container_get_focus_vadjustment (GtkContainer *container)
2669 GtkAdjustment *vadjustment;
2671 g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
2673 vadjustment = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id);
2679 * gtk_container_set_focus_hadjustment:
2680 * @container: a #GtkContainer
2681 * @adjustment: an adjustment which should be adjusted when the focus is
2682 * moved among the descendents of @container
2684 * Hooks up an adjustment to focus handling in a container, so when a child
2685 * of the container is focused, the adjustment is scrolled to show that
2686 * widget. This function sets the horizontal alignment.
2687 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
2688 * the adjustment and gtk_container_set_focus_vadjustment() for setting
2689 * the vertical adjustment.
2691 * The adjustments have to be in pixel units and in the same coordinate
2692 * system as the allocation for immediate children of the container.
2695 gtk_container_set_focus_hadjustment (GtkContainer *container,
2696 GtkAdjustment *adjustment)
2698 g_return_if_fail (GTK_IS_CONTAINER (container));
2700 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2703 g_object_ref (adjustment);
2705 g_object_set_qdata_full (G_OBJECT (container),
2712 * gtk_container_get_focus_hadjustment:
2713 * @container: a #GtkContainer
2715 * Retrieves the horizontal focus adjustment for the container. See
2716 * gtk_container_set_focus_hadjustment ().
2718 * Return value: (transfer none): the horizontal focus adjustment, or %NULL if
2719 * none has been set.
2722 gtk_container_get_focus_hadjustment (GtkContainer *container)
2724 GtkAdjustment *hadjustment;
2726 g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
2728 hadjustment = g_object_get_qdata (G_OBJECT (container), hadjustment_key_id);
2735 gtk_container_show_all (GtkWidget *widget)
2737 g_return_if_fail (GTK_IS_CONTAINER (widget));
2739 gtk_container_foreach (GTK_CONTAINER (widget),
2740 (GtkCallback) gtk_widget_show_all,
2742 gtk_widget_show (widget);
2746 gtk_container_hide_all (GtkWidget *widget)
2748 g_return_if_fail (GTK_IS_CONTAINER (widget));
2750 gtk_widget_hide (widget);
2751 gtk_container_foreach (GTK_CONTAINER (widget),
2752 (GtkCallback) gtk_widget_hide_all,
2758 gtk_container_draw_child (GtkWidget *child,
2759 gpointer client_data)
2762 GtkWidget *container;
2764 } *data = client_data;
2766 gtk_container_propagate_draw (GTK_CONTAINER (data->container),
2772 gtk_container_draw (GtkWidget *widget,
2776 GtkWidget *container;
2780 data.container = widget;
2783 gtk_container_forall (GTK_CONTAINER (widget),
2784 gtk_container_draw_child,
2791 gtk_container_map_child (GtkWidget *child,
2792 gpointer client_data)
2794 if (gtk_widget_get_visible (child) &&
2795 gtk_widget_get_child_visible (child) &&
2796 !gtk_widget_get_mapped (child))
2797 gtk_widget_map (child);
2801 gtk_container_map (GtkWidget *widget)
2803 gtk_widget_set_mapped (widget, TRUE);
2805 gtk_container_forall (GTK_CONTAINER (widget),
2806 gtk_container_map_child,
2809 if (gtk_widget_get_has_window (widget))
2810 gdk_window_show (gtk_widget_get_window (widget));
2814 gtk_container_unmap (GtkWidget *widget)
2816 gtk_widget_set_mapped (widget, FALSE);
2818 if (gtk_widget_get_has_window (widget))
2819 gdk_window_hide (gtk_widget_get_window (widget));
2821 gtk_container_forall (GTK_CONTAINER (widget),
2822 (GtkCallback)gtk_widget_unmap,
2827 * gtk_container_propagate_draw:
2828 * @container: a #GtkContainer
2829 * @child: a child of @container
2830 * @cr: Cairo context as passed to the container. If you want to use @cr
2831 * in container's draw function, consider using cairo_save() and
2832 * cairo_restore() before calling this function.
2834 * When a container receives a call to the draw function, it must send
2835 * synthetic #GtkWidget::draw calls to all children that don't have their
2836 * own #GdkWindows. This function provides a convenient way of doing this.
2837 * A container, when it receives a call to its #GtkWidget::draw function,
2838 * calls gtk_container_propagate_draw() once for each child, passing in
2839 * the @cr the container received.
2841 * gtk_container_propagate_draw() takes care of translating the origin of @cr,
2842 * and deciding whether the draw needs to be sent to the child. It is a
2843 * convenient and optimized way of getting the same effect as calling
2844 * gtk_widget_draw() on the child directly.
2846 * In most cases, a container can simply either inherit the
2847 * #GtkWidget::draw implementation from #GtkContainer, or do some drawing
2848 * and then chain to the ::draw implementation from #GtkContainer.
2851 gtk_container_propagate_draw (GtkContainer *container,
2855 GdkEventExpose *event;
2856 GtkAllocation allocation;
2857 GdkWindow *window, *w;
2860 g_return_if_fail (GTK_IS_CONTAINER (container));
2861 g_return_if_fail (GTK_IS_WIDGET (child));
2862 g_return_if_fail (cr != NULL);
2864 g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (container));
2866 event = _gtk_cairo_get_event (cr);
2869 if (gtk_widget_get_has_window (child) ||
2870 gtk_widget_get_window (child) != event->window)
2876 /* translate coordinates. Ugly business, that. */
2877 if (!gtk_widget_get_has_window (GTK_WIDGET (container)))
2879 gtk_widget_get_allocation (GTK_WIDGET (container), &allocation);
2889 window = gtk_widget_get_window (GTK_WIDGET (container));
2891 for (w = gtk_widget_get_window (child); w && w != window; w = gdk_window_get_parent (w))
2894 gdk_window_get_position (w, &wx, &wy);
2905 if (!gtk_widget_get_has_window (child))
2907 gtk_widget_get_allocation (child, &allocation);
2912 cairo_translate (cr, x, y);
2914 _gtk_widget_draw_internal (child, cr, TRUE);
2920 _gtk_container_get_need_resize (GtkContainer *container)
2922 return container->priv->need_resize;
2926 _gtk_container_set_need_resize (GtkContainer *container,
2927 gboolean need_resize)
2929 container->priv->need_resize = need_resize;
2933 _gtk_container_get_reallocate_redraws (GtkContainer *container)
2935 return container->priv->reallocate_redraws;