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/.
32 #include "gtkcontainer.h"
33 #include "gtkbuildable.h"
34 #include "gtkbuilderprivate.h"
35 #include "gtkprivate.h"
37 #include "gtkmarshalers.h"
38 #include "gtkwindow.h"
40 #include "gtktoolbar.h"
41 #include <gobject/gobjectnotifyqueue.c>
42 #include <gobject/gvaluecollector.h>
44 struct _GtkContainerPriv
46 GtkWidget *focus_child;
48 guint border_width : 16;
50 guint has_focus_chain : 1;
51 guint need_resize : 1;
52 guint reallocate_redraws : 1;
53 guint resize_mode : 2;
71 #define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
72 #define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
75 /* --- prototypes --- */
76 static void gtk_container_base_class_init (GtkContainerClass *klass);
77 static void gtk_container_base_class_finalize (GtkContainerClass *klass);
78 static void gtk_container_class_init (GtkContainerClass *klass);
79 static void gtk_container_init (GtkContainer *container);
80 static void gtk_container_destroy (GtkObject *object);
81 static void gtk_container_set_property (GObject *object,
85 static void gtk_container_get_property (GObject *object,
89 static void gtk_container_add_unimplemented (GtkContainer *container,
91 static void gtk_container_remove_unimplemented (GtkContainer *container,
93 static void gtk_container_real_check_resize (GtkContainer *container);
94 static gboolean gtk_container_focus (GtkWidget *widget,
95 GtkDirectionType direction);
96 static void gtk_container_real_set_focus_child (GtkContainer *container,
99 static gboolean gtk_container_focus_move (GtkContainer *container,
101 GtkDirectionType direction);
102 static void gtk_container_children_callback (GtkWidget *widget,
103 gpointer client_data);
104 static void gtk_container_show_all (GtkWidget *widget);
105 static void gtk_container_hide_all (GtkWidget *widget);
106 static gint gtk_container_expose (GtkWidget *widget,
107 GdkEventExpose *event);
108 static void gtk_container_map (GtkWidget *widget);
109 static void gtk_container_unmap (GtkWidget *widget);
111 static gchar* gtk_container_child_default_composite_name (GtkContainer *container,
115 static void gtk_container_buildable_init (GtkBuildableIface *iface);
116 static void gtk_container_buildable_add_child (GtkBuildable *buildable,
120 static gboolean gtk_container_buildable_custom_tag_start (GtkBuildable *buildable,
123 const gchar *tagname,
124 GMarkupParser *parser,
126 static void gtk_container_buildable_custom_tag_end (GtkBuildable *buildable,
129 const gchar *tagname,
133 /* --- variables --- */
134 static const gchar vadjustment_key[] = "gtk-vadjustment";
135 static guint vadjustment_key_id = 0;
136 static const gchar hadjustment_key[] = "gtk-hadjustment";
137 static guint hadjustment_key_id = 0;
138 static GSList *container_resize_queue = NULL;
139 static guint container_signals[LAST_SIGNAL] = { 0 };
140 static GtkWidgetClass *parent_class = NULL;
141 extern GParamSpecPool *_gtk_widget_child_property_pool;
142 extern GObjectNotifyContext *_gtk_widget_child_property_notify_context;
143 static GtkBuildableIface *parent_buildable_iface;
146 /* --- functions --- */
148 gtk_container_get_type (void)
150 static GType container_type = 0;
154 const GTypeInfo container_info =
156 sizeof (GtkContainerClass),
157 (GBaseInitFunc) gtk_container_base_class_init,
158 (GBaseFinalizeFunc) gtk_container_base_class_finalize,
159 (GClassInitFunc) gtk_container_class_init,
160 NULL /* class_finalize */,
161 NULL /* class_data */,
162 sizeof (GtkContainer),
164 (GInstanceInitFunc) gtk_container_init,
165 NULL, /* value_table */
168 const GInterfaceInfo buildable_info =
170 (GInterfaceInitFunc) gtk_container_buildable_init,
176 g_type_register_static (GTK_TYPE_WIDGET, I_("GtkContainer"),
177 &container_info, G_TYPE_FLAG_ABSTRACT);
179 g_type_add_interface_static (container_type,
185 return container_type;
189 gtk_container_base_class_init (GtkContainerClass *class)
191 /* reset instance specifc class fields that don't get inherited */
192 class->set_child_property = NULL;
193 class->get_child_property = NULL;
197 gtk_container_base_class_finalize (GtkContainerClass *class)
201 list = g_param_spec_pool_list_owned (_gtk_widget_child_property_pool, G_OBJECT_CLASS_TYPE (class));
202 for (node = list; node; node = node->next)
204 GParamSpec *pspec = node->data;
206 g_param_spec_pool_remove (_gtk_widget_child_property_pool, pspec);
207 PARAM_SPEC_SET_PARAM_ID (pspec, 0);
208 g_param_spec_unref (pspec);
214 gtk_container_class_init (GtkContainerClass *class)
216 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
217 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
218 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
220 parent_class = g_type_class_peek_parent (class);
222 vadjustment_key_id = g_quark_from_static_string (vadjustment_key);
223 hadjustment_key_id = g_quark_from_static_string (hadjustment_key);
225 gobject_class->set_property = gtk_container_set_property;
226 gobject_class->get_property = gtk_container_get_property;
228 object_class->destroy = gtk_container_destroy;
230 widget_class->show_all = gtk_container_show_all;
231 widget_class->hide_all = gtk_container_hide_all;
232 widget_class->expose_event = gtk_container_expose;
233 widget_class->map = gtk_container_map;
234 widget_class->unmap = gtk_container_unmap;
235 widget_class->focus = gtk_container_focus;
237 class->add = gtk_container_add_unimplemented;
238 class->remove = gtk_container_remove_unimplemented;
239 class->check_resize = gtk_container_real_check_resize;
240 class->forall = NULL;
241 class->set_focus_child = gtk_container_real_set_focus_child;
242 class->child_type = NULL;
243 class->composite_name = gtk_container_child_default_composite_name;
245 g_object_class_install_property (gobject_class,
247 g_param_spec_enum ("resize-mode",
249 P_("Specify how resize events are handled"),
250 GTK_TYPE_RESIZE_MODE,
252 GTK_PARAM_READWRITE));
253 g_object_class_install_property (gobject_class,
255 g_param_spec_uint ("border-width",
257 P_("The width of the empty border outside the containers children"),
261 GTK_PARAM_READWRITE));
262 g_object_class_install_property (gobject_class,
264 g_param_spec_object ("child",
266 P_("Can be used to add a new child to the container"),
268 GTK_PARAM_WRITABLE));
269 container_signals[ADD] =
270 g_signal_new (I_("add"),
271 G_OBJECT_CLASS_TYPE (object_class),
273 G_STRUCT_OFFSET (GtkContainerClass, add),
275 _gtk_marshal_VOID__OBJECT,
278 container_signals[REMOVE] =
279 g_signal_new (I_("remove"),
280 G_OBJECT_CLASS_TYPE (object_class),
282 G_STRUCT_OFFSET (GtkContainerClass, remove),
284 _gtk_marshal_VOID__OBJECT,
287 container_signals[CHECK_RESIZE] =
288 g_signal_new (I_("check-resize"),
289 G_OBJECT_CLASS_TYPE (object_class),
291 G_STRUCT_OFFSET (GtkContainerClass, check_resize),
293 _gtk_marshal_VOID__VOID,
295 container_signals[SET_FOCUS_CHILD] =
296 g_signal_new (I_("set-focus-child"),
297 G_OBJECT_CLASS_TYPE (object_class),
299 G_STRUCT_OFFSET (GtkContainerClass, set_focus_child),
301 _gtk_marshal_VOID__OBJECT,
305 g_type_class_add_private (class, sizeof (GtkContainerPriv));
309 gtk_container_buildable_init (GtkBuildableIface *iface)
311 parent_buildable_iface = g_type_interface_peek_parent (iface);
312 iface->add_child = gtk_container_buildable_add_child;
313 iface->custom_tag_start = gtk_container_buildable_custom_tag_start;
314 iface->custom_tag_end = gtk_container_buildable_custom_tag_end;
318 gtk_container_buildable_add_child (GtkBuildable *buildable,
325 GTK_BUILDER_WARN_INVALID_CHILD_TYPE (buildable, type);
327 else if (GTK_IS_WIDGET (child) &&
328 gtk_widget_get_parent (GTK_WIDGET (child)) == NULL)
330 gtk_container_add (GTK_CONTAINER (buildable), GTK_WIDGET (child));
333 g_warning ("Cannot add an object of type %s to a container of type %s",
334 g_type_name (G_OBJECT_TYPE (child)), g_type_name (G_OBJECT_TYPE (buildable)));
338 gtk_container_buildable_set_child_property (GtkContainer *container,
345 GValue gvalue = { 0, };
346 GError *error = NULL;
348 pspec = gtk_container_class_find_child_property
349 (G_OBJECT_GET_CLASS (container), name);
352 g_warning ("%s does not have a property called %s",
353 g_type_name (G_OBJECT_TYPE (container)), name);
357 if (!gtk_builder_value_from_string (builder, pspec, value, &gvalue, &error))
359 g_warning ("Could not read property %s:%s with value %s of type %s: %s",
360 g_type_name (G_OBJECT_TYPE (container)),
363 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
365 g_error_free (error);
369 gtk_container_child_set_property (container, child, name, &gvalue);
370 g_value_unset (&gvalue);
375 GtkContainer *container;
377 gchar *child_prop_name;
379 gboolean translatable;
380 } PackingPropertiesData;
383 attributes_start_element (GMarkupParseContext *context,
384 const gchar *element_name,
386 const gchar **values,
390 PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
393 if (strcmp (element_name, "property") == 0)
395 for (i = 0; names[i]; i++)
396 if (strcmp (names[i], "name") == 0)
397 parser_data->child_prop_name = g_strdup (values[i]);
398 else if (strcmp (names[i], "translatable") == 0)
400 if (!_gtk_builder_boolean_from_string (values[1],
401 &parser_data->translatable,
405 else if (strcmp (names[i], "comments") == 0)
406 ; /* for translators */
407 else if (strcmp (names[i], "context") == 0)
408 parser_data->context = g_strdup (values[1]);
410 g_warning ("Unsupported attribute for GtkContainer Child "
411 "property: %s\n", names[i]);
413 else if (strcmp (element_name, "packing") == 0)
416 g_warning ("Unsupported tag for GtkContainer: %s\n", element_name);
420 attributes_text_element (GMarkupParseContext *context,
426 PackingPropertiesData *parser_data = (PackingPropertiesData*)user_data;
429 if (!parser_data->child_prop_name)
432 if (parser_data->translatable && text_len)
435 domain = gtk_builder_get_translation_domain (parser_data->builder);
437 value = _gtk_builder_parser_translate (domain,
438 parser_data->context,
443 value = g_strdup (text);
446 gtk_container_buildable_set_child_property (parser_data->container,
447 parser_data->builder,
449 parser_data->child_prop_name,
452 g_free (parser_data->child_prop_name);
453 g_free (parser_data->context);
455 parser_data->child_prop_name = NULL;
456 parser_data->context = NULL;
457 parser_data->translatable = FALSE;
460 static const GMarkupParser attributes_parser =
462 attributes_start_element,
464 attributes_text_element,
468 gtk_container_buildable_custom_tag_start (GtkBuildable *buildable,
471 const gchar *tagname,
472 GMarkupParser *parser,
475 PackingPropertiesData *parser_data;
477 if (parent_buildable_iface->custom_tag_start (buildable, builder, child,
478 tagname, parser, data))
481 if (child && strcmp (tagname, "packing") == 0)
483 parser_data = g_slice_new0 (PackingPropertiesData);
484 parser_data->builder = builder;
485 parser_data->container = GTK_CONTAINER (buildable);
486 parser_data->child = GTK_WIDGET (child);
487 parser_data->child_prop_name = NULL;
489 *parser = attributes_parser;
498 gtk_container_buildable_custom_tag_end (GtkBuildable *buildable,
501 const gchar *tagname,
504 if (strcmp (tagname, "packing") == 0)
506 g_slice_free (PackingPropertiesData, (gpointer)data);
511 if (parent_buildable_iface->custom_tag_end)
512 parent_buildable_iface->custom_tag_end (buildable, builder,
513 child, tagname, data);
518 * gtk_container_child_type:
519 * @container: a #GtkContainer
521 * Returns the type of the children supported by the container.
523 * Note that this may return %G_TYPE_NONE to indicate that no more
524 * children can be added, e.g. for a #GtkPaned which already has two
527 * Return value: a #GType.
530 gtk_container_child_type (GtkContainer *container)
533 GtkContainerClass *class;
535 g_return_val_if_fail (GTK_IS_CONTAINER (container), 0);
537 class = GTK_CONTAINER_GET_CLASS (container);
538 if (class->child_type)
539 slot = class->child_type (container);
546 /* --- GtkContainer child property mechanism --- */
548 container_get_child_property (GtkContainer *container,
553 GtkContainerClass *class = g_type_class_peek (pspec->owner_type);
555 class->get_child_property (container, child, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
559 container_set_child_property (GtkContainer *container,
563 GObjectNotifyQueue *nqueue)
565 GValue tmp_value = { 0, };
566 GtkContainerClass *class = g_type_class_peek (pspec->owner_type);
568 /* provide a copy to work from, convert (if necessary) and validate */
569 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
570 if (!g_value_transform (value, &tmp_value))
571 g_warning ("unable to set child property `%s' of type `%s' from value of type `%s'",
573 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
574 G_VALUE_TYPE_NAME (value));
575 else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
577 gchar *contents = g_strdup_value_contents (value);
579 g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
581 G_VALUE_TYPE_NAME (value),
583 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
588 class->set_child_property (container, child, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
589 g_object_notify_queue_add (G_OBJECT (child), nqueue, pspec);
591 g_value_unset (&tmp_value);
595 * gtk_container_child_get_valist:
596 * @container: a #GtkContainer
597 * @child: a widget which is a child of @container
598 * @first_property_name: the name of the first property to get
599 * @var_args: return location for the first property, followed
600 * optionally by more name/return location pairs, followed by %NULL
602 * Gets the values of one or more child properties for @child and @container.
605 gtk_container_child_get_valist (GtkContainer *container,
607 const gchar *first_property_name,
612 g_return_if_fail (GTK_IS_CONTAINER (container));
613 g_return_if_fail (GTK_IS_WIDGET (child));
614 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
616 g_object_ref (container);
617 g_object_ref (child);
619 name = first_property_name;
622 GValue value = { 0, };
626 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
628 G_OBJECT_TYPE (container),
632 g_warning ("%s: container class `%s' has no child property named `%s'",
634 G_OBJECT_TYPE_NAME (container),
638 if (!(pspec->flags & G_PARAM_READABLE))
640 g_warning ("%s: child property `%s' of container class `%s' is not readable",
643 G_OBJECT_TYPE_NAME (container));
646 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
647 container_get_child_property (container, child, pspec, &value);
648 G_VALUE_LCOPY (&value, var_args, 0, &error);
651 g_warning ("%s: %s", G_STRLOC, error);
653 g_value_unset (&value);
656 g_value_unset (&value);
657 name = va_arg (var_args, gchar*);
660 g_object_unref (child);
661 g_object_unref (container);
665 * gtk_container_child_get_property:
666 * @container: a #GtkContainer
667 * @child: a widget which is a child of @container
668 * @property_name: the name of the property to get
669 * @value: a location to return the value
671 * Gets the value of a child property for @child and @container.
674 gtk_container_child_get_property (GtkContainer *container,
676 const gchar *property_name,
681 g_return_if_fail (GTK_IS_CONTAINER (container));
682 g_return_if_fail (GTK_IS_WIDGET (child));
683 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
684 g_return_if_fail (property_name != NULL);
685 g_return_if_fail (G_IS_VALUE (value));
687 g_object_ref (container);
688 g_object_ref (child);
689 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool, property_name,
690 G_OBJECT_TYPE (container), TRUE);
692 g_warning ("%s: container class `%s' has no child property named `%s'",
694 G_OBJECT_TYPE_NAME (container),
696 else if (!(pspec->flags & G_PARAM_READABLE))
697 g_warning ("%s: child property `%s' of container class `%s' is not readable",
700 G_OBJECT_TYPE_NAME (container));
703 GValue *prop_value, tmp_value = { 0, };
705 /* auto-conversion of the callers value type
707 if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
709 g_value_reset (value);
712 else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
714 g_warning ("can't retrieve child property `%s' of type `%s' as value of type `%s'",
716 g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
717 G_VALUE_TYPE_NAME (value));
718 g_object_unref (child);
719 g_object_unref (container);
724 g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
725 prop_value = &tmp_value;
727 container_get_child_property (container, child, pspec, prop_value);
728 if (prop_value != value)
730 g_value_transform (prop_value, value);
731 g_value_unset (&tmp_value);
734 g_object_unref (child);
735 g_object_unref (container);
739 * gtk_container_child_set_valist:
740 * @container: a #GtkContainer
741 * @child: a widget which is a child of @container
742 * @first_property_name: the name of the first property to set
743 * @var_args: a %NULL-terminated list of property names and values, starting
744 * with @first_prop_name
746 * Sets one or more child properties for @child and @container.
749 gtk_container_child_set_valist (GtkContainer *container,
751 const gchar *first_property_name,
754 GObjectNotifyQueue *nqueue;
757 g_return_if_fail (GTK_IS_CONTAINER (container));
758 g_return_if_fail (GTK_IS_WIDGET (child));
759 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
761 g_object_ref (container);
762 g_object_ref (child);
764 nqueue = g_object_notify_queue_freeze (G_OBJECT (child), _gtk_widget_child_property_notify_context);
765 name = first_property_name;
768 GValue value = { 0, };
770 GParamSpec *pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
772 G_OBJECT_TYPE (container),
776 g_warning ("%s: container class `%s' has no child property named `%s'",
778 G_OBJECT_TYPE_NAME (container),
782 if (!(pspec->flags & G_PARAM_WRITABLE))
784 g_warning ("%s: child property `%s' of container class `%s' is not writable",
787 G_OBJECT_TYPE_NAME (container));
790 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
791 G_VALUE_COLLECT (&value, var_args, 0, &error);
794 g_warning ("%s: %s", G_STRLOC, error);
797 /* we purposely leak the value here, it might not be
798 * in a sane state if an error condition occoured
802 container_set_child_property (container, child, pspec, &value, nqueue);
803 g_value_unset (&value);
804 name = va_arg (var_args, gchar*);
806 g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
808 g_object_unref (container);
809 g_object_unref (child);
813 * gtk_container_child_set_property:
814 * @container: a #GtkContainer
815 * @child: a widget which is a child of @container
816 * @property_name: the name of the property to set
817 * @value: the value to set the property to
819 * Sets a child property for @child and @container.
822 gtk_container_child_set_property (GtkContainer *container,
824 const gchar *property_name,
827 GObjectNotifyQueue *nqueue;
830 g_return_if_fail (GTK_IS_CONTAINER (container));
831 g_return_if_fail (GTK_IS_WIDGET (child));
832 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
833 g_return_if_fail (property_name != NULL);
834 g_return_if_fail (G_IS_VALUE (value));
836 g_object_ref (container);
837 g_object_ref (child);
839 nqueue = g_object_notify_queue_freeze (G_OBJECT (child), _gtk_widget_child_property_notify_context);
840 pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool, property_name,
841 G_OBJECT_TYPE (container), TRUE);
843 g_warning ("%s: container class `%s' has no child property named `%s'",
845 G_OBJECT_TYPE_NAME (container),
847 else if (!(pspec->flags & G_PARAM_WRITABLE))
848 g_warning ("%s: child property `%s' of container class `%s' is not writable",
851 G_OBJECT_TYPE_NAME (container));
854 container_set_child_property (container, child, pspec, value, nqueue);
856 g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
857 g_object_unref (container);
858 g_object_unref (child);
862 * gtk_container_add_with_properties:
863 * @container: a #GtkContainer
864 * @widget: a widget to be placed inside @container
865 * @first_prop_name: the name of the first child property to set
866 * @Varargs: a %NULL-terminated list of property names and values, starting
867 * with @first_prop_name
869 * Adds @widget to @container, setting child properties at the same time.
870 * See gtk_container_add() and gtk_container_child_set() for more details.
873 gtk_container_add_with_properties (GtkContainer *container,
875 const gchar *first_prop_name,
878 g_return_if_fail (GTK_IS_CONTAINER (container));
879 g_return_if_fail (GTK_IS_WIDGET (widget));
880 g_return_if_fail (gtk_widget_get_parent (widget) == NULL);
882 g_object_ref (container);
883 g_object_ref (widget);
884 gtk_widget_freeze_child_notify (widget);
886 g_signal_emit (container, container_signals[ADD], 0, widget);
887 if (gtk_widget_get_parent (widget))
891 va_start (var_args, first_prop_name);
892 gtk_container_child_set_valist (container, widget, first_prop_name, var_args);
896 gtk_widget_thaw_child_notify (widget);
897 g_object_unref (widget);
898 g_object_unref (container);
902 * gtk_container_child_set:
903 * @container: a #GtkContainer
904 * @child: a widget which is a child of @container
905 * @first_prop_name: the name of the first property to set
906 * @Varargs: a %NULL-terminated list of property names and values, starting
907 * with @first_prop_name
909 * Sets one or more child properties for @child and @container.
912 gtk_container_child_set (GtkContainer *container,
914 const gchar *first_prop_name,
919 g_return_if_fail (GTK_IS_CONTAINER (container));
920 g_return_if_fail (GTK_IS_WIDGET (child));
921 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
923 va_start (var_args, first_prop_name);
924 gtk_container_child_set_valist (container, child, first_prop_name, var_args);
929 * gtk_container_child_get:
930 * @container: a #GtkContainer
931 * @child: a widget which is a child of @container
932 * @first_prop_name: the name of the first property to get
933 * @Varargs: return location for the first property, followed
934 * optionally by more name/return location pairs, followed by %NULL
936 * Gets the values of one or more child properties for @child and @container.
939 gtk_container_child_get (GtkContainer *container,
941 const gchar *first_prop_name,
946 g_return_if_fail (GTK_IS_CONTAINER (container));
947 g_return_if_fail (GTK_IS_WIDGET (child));
948 g_return_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container));
950 va_start (var_args, first_prop_name);
951 gtk_container_child_get_valist (container, child, first_prop_name, var_args);
956 * gtk_container_class_install_child_property:
957 * @cclass: a #GtkContainerClass
958 * @property_id: the id for the property
959 * @pspec: the #GParamSpec for the property
961 * Installs a child property on a container class.
964 gtk_container_class_install_child_property (GtkContainerClass *cclass,
968 g_return_if_fail (GTK_IS_CONTAINER_CLASS (cclass));
969 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
970 if (pspec->flags & G_PARAM_WRITABLE)
971 g_return_if_fail (cclass->set_child_property != NULL);
972 if (pspec->flags & G_PARAM_READABLE)
973 g_return_if_fail (cclass->get_child_property != NULL);
974 g_return_if_fail (property_id > 0);
975 g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
976 if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
977 g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
979 if (g_param_spec_pool_lookup (_gtk_widget_child_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (cclass), FALSE))
981 g_warning (G_STRLOC ": class `%s' already contains a child property named `%s'",
982 G_OBJECT_CLASS_NAME (cclass),
986 g_param_spec_ref (pspec);
987 g_param_spec_sink (pspec);
988 PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
989 g_param_spec_pool_insert (_gtk_widget_child_property_pool, pspec, G_OBJECT_CLASS_TYPE (cclass));
993 * gtk_container_class_find_child_property:
994 * @cclass: a #GtkContainerClass
995 * @property_name: the name of the child property to find
996 * @returns: (allow-none): the #GParamSpec of the child property or %NULL if @class has no
997 * child property with that name.
999 * Finds a child property of a container class by name.
1002 gtk_container_class_find_child_property (GObjectClass *cclass,
1003 const gchar *property_name)
1005 g_return_val_if_fail (GTK_IS_CONTAINER_CLASS (cclass), NULL);
1006 g_return_val_if_fail (property_name != NULL, NULL);
1008 return g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
1010 G_OBJECT_CLASS_TYPE (cclass),
1015 * gtk_container_class_list_child_properties:
1016 * @cclass: a #GtkContainerClass
1017 * @n_properties: location to return the number of child properties found
1018 * @returns: a newly allocated %NULL-terminated array of #GParamSpec*.
1019 * The array must be freed with g_free().
1021 * Returns all child properties of a container class.
1024 gtk_container_class_list_child_properties (GObjectClass *cclass,
1025 guint *n_properties)
1027 GParamSpec **pspecs;
1030 g_return_val_if_fail (GTK_IS_CONTAINER_CLASS (cclass), NULL);
1032 pspecs = g_param_spec_pool_list (_gtk_widget_child_property_pool,
1033 G_OBJECT_CLASS_TYPE (cclass),
1042 gtk_container_add_unimplemented (GtkContainer *container,
1045 g_warning ("GtkContainerClass::add not implemented for `%s'", g_type_name (G_TYPE_FROM_INSTANCE (container)));
1049 gtk_container_remove_unimplemented (GtkContainer *container,
1052 g_warning ("GtkContainerClass::remove not implemented for `%s'", g_type_name (G_TYPE_FROM_INSTANCE (container)));
1056 gtk_container_init (GtkContainer *container)
1058 GtkContainerPriv *priv;
1060 container->priv = G_TYPE_INSTANCE_GET_PRIVATE (container,
1063 priv = container->priv;
1065 priv->focus_child = NULL;
1066 priv->border_width = 0;
1067 priv->need_resize = FALSE;
1068 priv->resize_mode = GTK_RESIZE_PARENT;
1069 priv->reallocate_redraws = FALSE;
1073 gtk_container_destroy (GtkObject *object)
1075 GtkContainer *container = GTK_CONTAINER (object);
1076 GtkContainerPriv *priv = container->priv;
1078 if (GTK_CONTAINER_RESIZE_PENDING (container))
1079 _gtk_container_dequeue_resize_handler (container);
1081 /* do this before walking child widgets, to avoid
1082 * removing children from focus chain one by one.
1084 if (priv->has_focus_chain)
1085 gtk_container_unset_focus_chain (container);
1087 gtk_container_foreach (container, (GtkCallback) gtk_widget_destroy, NULL);
1089 GTK_OBJECT_CLASS (parent_class)->destroy (object);
1093 gtk_container_set_property (GObject *object,
1095 const GValue *value,
1098 GtkContainer *container = GTK_CONTAINER (object);
1102 case PROP_BORDER_WIDTH:
1103 gtk_container_set_border_width (container, g_value_get_uint (value));
1105 case PROP_RESIZE_MODE:
1106 gtk_container_set_resize_mode (container, g_value_get_enum (value));
1109 gtk_container_add (container, GTK_WIDGET (g_value_get_object (value)));
1112 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1118 gtk_container_get_property (GObject *object,
1123 GtkContainer *container = GTK_CONTAINER (object);
1124 GtkContainerPriv *priv = container->priv;
1128 case PROP_BORDER_WIDTH:
1129 g_value_set_uint (value, priv->border_width);
1131 case PROP_RESIZE_MODE:
1132 g_value_set_enum (value, priv->resize_mode);
1135 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1141 * gtk_container_set_border_width:
1142 * @container: a #GtkContainer
1143 * @border_width: amount of blank space to leave <emphasis>outside</emphasis>
1144 * the container. Valid values are in the range 0-65535 pixels.
1146 * Sets the border width of the container.
1148 * The border width of a container is the amount of space to leave
1149 * around the outside of the container. The only exception to this is
1150 * #GtkWindow; because toplevel windows can't leave space outside,
1151 * they leave the space inside. The border is added on all sides of
1152 * the container. To add space to only one side, one approach is to
1153 * create a #GtkAlignment widget, call gtk_widget_set_size_request()
1154 * to give it a size, and place it on the side of the container as
1158 gtk_container_set_border_width (GtkContainer *container,
1161 GtkContainerPriv *priv;
1163 g_return_if_fail (GTK_IS_CONTAINER (container));
1165 priv = container->priv;
1167 if (priv->border_width != border_width)
1169 priv->border_width = border_width;
1170 g_object_notify (G_OBJECT (container), "border-width");
1172 if (gtk_widget_get_realized (GTK_WIDGET (container)))
1173 gtk_widget_queue_resize (GTK_WIDGET (container));
1178 * gtk_container_get_border_width:
1179 * @container: a #GtkContainer
1181 * Retrieves the border width of the container. See
1182 * gtk_container_set_border_width().
1184 * Return value: the current border width
1187 gtk_container_get_border_width (GtkContainer *container)
1189 g_return_val_if_fail (GTK_IS_CONTAINER (container), 0);
1191 return container->priv->border_width;
1195 * gtk_container_add:
1196 * @container: a #GtkContainer
1197 * @widget: a widget to be placed inside @container
1199 * Adds @widget to @container. Typically used for simple containers
1200 * such as #GtkWindow, #GtkFrame, or #GtkButton; for more complicated
1201 * layout containers such as #GtkBox or #GtkTable, this function will
1202 * pick default packing parameters that may not be correct. So
1203 * consider functions such as gtk_box_pack_start() and
1204 * gtk_table_attach() as an alternative to gtk_container_add() in
1205 * those cases. A widget may be added to only one container at a time;
1206 * you can't place the same widget inside two different containers.
1209 gtk_container_add (GtkContainer *container,
1214 g_return_if_fail (GTK_IS_CONTAINER (container));
1215 g_return_if_fail (GTK_IS_WIDGET (widget));
1217 parent = gtk_widget_get_parent (widget);
1221 g_warning ("Attempting to add a widget with type %s to a container of "
1222 "type %s, but the widget is already inside a container of type %s, "
1223 "the GTK+ FAQ at http://library.gnome.org/devel/gtk-faq/stable/ "
1224 "explains how to reparent a widget.",
1225 g_type_name (G_OBJECT_TYPE (widget)),
1226 g_type_name (G_OBJECT_TYPE (container)),
1227 g_type_name (G_OBJECT_TYPE (parent)));
1231 g_signal_emit (container, container_signals[ADD], 0, widget);
1235 * gtk_container_remove:
1236 * @container: a #GtkContainer
1237 * @widget: a current child of @container
1239 * Removes @widget from @container. @widget must be inside @container.
1240 * Note that @container will own a reference to @widget, and that this
1241 * may be the last reference held; so removing a widget from its
1242 * container can destroy that widget. If you want to use @widget
1243 * again, you need to add a reference to it while it's not inside
1244 * a container, using g_object_ref(). If you don't want to use @widget
1245 * again it's usually more efficient to simply destroy it directly
1246 * using gtk_widget_destroy() since this will remove it from the
1247 * container and help break any circular reference count cycles.
1250 gtk_container_remove (GtkContainer *container,
1253 g_return_if_fail (GTK_IS_CONTAINER (container));
1254 g_return_if_fail (GTK_IS_WIDGET (widget));
1256 /* When using the deprecated API of the toolbar, it is possible
1257 * to legitimately call this function with a widget that is not
1258 * a direct child of the container.
1260 g_return_if_fail (GTK_IS_TOOLBAR (container) ||
1261 gtk_widget_get_parent (widget) == GTK_WIDGET (container));
1263 g_signal_emit (container, container_signals[REMOVE], 0, widget);
1267 _gtk_container_dequeue_resize_handler (GtkContainer *container)
1269 g_return_if_fail (GTK_IS_CONTAINER (container));
1270 g_return_if_fail (GTK_CONTAINER_RESIZE_PENDING (container));
1272 container_resize_queue = g_slist_remove (container_resize_queue, container);
1273 GTK_PRIVATE_UNSET_FLAG (container, GTK_RESIZE_PENDING);
1277 * gtk_container_set_resize_mode:
1278 * @container: a #GtkContainer
1279 * @resize_mode: the new resize mode
1281 * Sets the resize mode for the container.
1283 * The resize mode of a container determines whether a resize request
1284 * will be passed to the container's parent, queued for later execution
1285 * or executed immediately.
1288 gtk_container_set_resize_mode (GtkContainer *container,
1289 GtkResizeMode resize_mode)
1291 GtkContainerPriv *priv;
1293 g_return_if_fail (GTK_IS_CONTAINER (container));
1294 g_return_if_fail (resize_mode <= GTK_RESIZE_IMMEDIATE);
1296 priv = container->priv;
1298 if (gtk_widget_is_toplevel (GTK_WIDGET (container)) &&
1299 resize_mode == GTK_RESIZE_PARENT)
1301 resize_mode = GTK_RESIZE_QUEUE;
1304 if (priv->resize_mode != resize_mode)
1306 priv->resize_mode = resize_mode;
1308 gtk_widget_queue_resize (GTK_WIDGET (container));
1309 g_object_notify (G_OBJECT (container), "resize-mode");
1314 * gtk_container_get_resize_mode:
1315 * @container: a #GtkContainer
1317 * Returns the resize mode for the container. See
1318 * gtk_container_set_resize_mode ().
1320 * Return value: the current resize mode
1323 gtk_container_get_resize_mode (GtkContainer *container)
1325 g_return_val_if_fail (GTK_IS_CONTAINER (container), GTK_RESIZE_PARENT);
1327 return container->priv->resize_mode;
1331 * gtk_container_set_reallocate_redraws:
1332 * @container: a #GtkContainer
1333 * @needs_redraws: the new value for the container's @reallocate_redraws flag
1335 * Sets the @reallocate_redraws flag of the container to the given value.
1337 * Containers requesting reallocation redraws get automatically
1338 * redrawn if any of their children changed allocation.
1341 gtk_container_set_reallocate_redraws (GtkContainer *container,
1342 gboolean needs_redraws)
1344 g_return_if_fail (GTK_IS_CONTAINER (container));
1346 container->priv->reallocate_redraws = needs_redraws ? TRUE : FALSE;
1349 static GtkContainer*
1350 gtk_container_get_resize_container (GtkContainer *container)
1353 GtkWidget *widget = GTK_WIDGET (container);
1355 while (parent = gtk_widget_get_parent (widget))
1358 if (GTK_IS_RESIZE_CONTAINER (widget))
1362 return GTK_IS_RESIZE_CONTAINER (widget) ? (GtkContainer*) widget : NULL;
1366 gtk_container_idle_sizer (gpointer data)
1368 /* we may be invoked with a container_resize_queue of NULL, because
1369 * queue_resize could have been adding an extra idle function while
1370 * the queue still got processed. we better just ignore such case
1371 * than trying to explicitely work around them with some extra flags,
1372 * since it doesn't cause any actual harm.
1374 while (container_resize_queue)
1379 slist = container_resize_queue;
1380 container_resize_queue = slist->next;
1381 widget = slist->data;
1382 g_slist_free_1 (slist);
1384 GTK_PRIVATE_UNSET_FLAG (widget, GTK_RESIZE_PENDING);
1385 gtk_container_check_resize (GTK_CONTAINER (widget));
1388 gdk_window_process_all_updates ();
1394 _gtk_container_queue_resize (GtkContainer *container)
1396 GtkContainerPriv *priv;
1397 GtkContainer *resize_container;
1401 g_return_if_fail (GTK_IS_CONTAINER (container));
1403 priv = container->priv;
1404 widget = GTK_WIDGET (container);
1406 resize_container = gtk_container_get_resize_container (container);
1410 GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1411 GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1412 GTK_PRIVATE_SET_FLAG (widget, GTK_WIDTH_REQUEST_NEEDED);
1413 GTK_PRIVATE_SET_FLAG (widget, GTK_HEIGHT_REQUEST_NEEDED);
1415 if ((resize_container && widget == GTK_WIDGET (resize_container)) ||
1416 !(parent = gtk_widget_get_parent (widget)))
1422 if (resize_container)
1424 if (gtk_widget_get_visible (GTK_WIDGET (resize_container)) &&
1425 (gtk_widget_is_toplevel (GTK_WIDGET (resize_container)) ||
1426 gtk_widget_get_realized (GTK_WIDGET (resize_container))))
1428 switch (resize_container->priv->resize_mode)
1430 case GTK_RESIZE_QUEUE:
1431 if (!GTK_CONTAINER_RESIZE_PENDING (resize_container))
1433 GTK_PRIVATE_SET_FLAG (resize_container, GTK_RESIZE_PENDING);
1434 if (container_resize_queue == NULL)
1435 gdk_threads_add_idle_full (GTK_PRIORITY_RESIZE,
1436 gtk_container_idle_sizer,
1438 container_resize_queue = g_slist_prepend (container_resize_queue, resize_container);
1442 case GTK_RESIZE_IMMEDIATE:
1443 gtk_container_check_resize (resize_container);
1446 case GTK_RESIZE_PARENT:
1447 g_assert_not_reached ();
1453 /* we need to let hidden resize containers know that something
1454 * changed while they where hidden (currently only evaluated by
1457 resize_container->priv->need_resize = TRUE;
1463 gtk_container_check_resize (GtkContainer *container)
1465 g_return_if_fail (GTK_IS_CONTAINER (container));
1467 g_signal_emit (container, container_signals[CHECK_RESIZE], 0);
1471 gtk_container_real_check_resize (GtkContainer *container)
1473 GtkWidget *widget = GTK_WIDGET (container);
1474 GtkAllocation allocation;
1475 GtkRequisition requisition;
1477 gtk_widget_size_request (widget, &requisition);
1478 gtk_widget_get_allocation (widget, &allocation);
1480 if (requisition.width > allocation.width ||
1481 requisition.height > allocation.height)
1483 if (GTK_IS_RESIZE_CONTAINER (container))
1485 gtk_widget_size_allocate (widget, &allocation);
1486 gtk_widget_set_allocation (widget, &allocation);
1489 gtk_widget_queue_resize (widget);
1493 gtk_container_resize_children (container);
1497 /* The container hasn't changed size but one of its children
1498 * queued a resize request. Which means that the allocation
1499 * is not sufficient for the requisition of some child.
1500 * We've already performed a size request at this point,
1501 * so we simply need to reallocate and let the allocation
1502 * trickle down via GTK_WIDGET_ALLOC_NEEDED flags.
1505 gtk_container_resize_children (GtkContainer *container)
1507 GtkAllocation allocation;
1510 /* resizing invariants:
1511 * toplevels have *always* resize_mode != GTK_RESIZE_PARENT set.
1512 * containers that have an idle sizer pending must be flagged with
1515 g_return_if_fail (GTK_IS_CONTAINER (container));
1517 widget = GTK_WIDGET (container);
1518 gtk_widget_get_allocation (widget, &allocation);
1520 gtk_widget_size_allocate (widget, &allocation);
1521 gtk_widget_set_allocation (widget, &allocation);
1525 * gtk_container_forall:
1526 * @container: a #GtkContainer
1527 * @callback: a callback
1528 * @callback_data: callback user data
1530 * Invokes @callback on each child of @container, including children
1531 * that are considered "internal" (implementation details of the
1532 * container). "Internal" children generally weren't added by the user
1533 * of the container, but were added by the container implementation
1534 * itself. Most applications should use gtk_container_foreach(),
1535 * rather than gtk_container_forall().
1538 gtk_container_forall (GtkContainer *container,
1539 GtkCallback callback,
1540 gpointer callback_data)
1542 GtkContainerClass *class;
1544 g_return_if_fail (GTK_IS_CONTAINER (container));
1545 g_return_if_fail (callback != NULL);
1547 class = GTK_CONTAINER_GET_CLASS (container);
1550 class->forall (container, TRUE, callback, callback_data);
1554 * gtk_container_foreach:
1555 * @container: a #GtkContainer
1556 * @callback: a callback
1557 * @callback_data: callback user data
1559 * Invokes @callback on each non-internal child of @container. See
1560 * gtk_container_forall() for details on what constitutes an
1561 * "internal" child. Most applications should use
1562 * gtk_container_foreach(), rather than gtk_container_forall().
1565 gtk_container_foreach (GtkContainer *container,
1566 GtkCallback callback,
1567 gpointer callback_data)
1569 GtkContainerClass *class;
1571 g_return_if_fail (GTK_IS_CONTAINER (container));
1572 g_return_if_fail (callback != NULL);
1574 class = GTK_CONTAINER_GET_CLASS (container);
1577 class->forall (container, FALSE, callback, callback_data);
1581 * gtk_container_set_focus_child:
1582 * @container: a #GtkContainer
1583 * @child: (allow-none): a #GtkWidget, or %NULL
1585 * Sets, or unsets if @child is %NULL, the focused child of @container.
1587 * This function emits the GtkContainer::set_focus_child signal of
1588 * @container. Implementations of #GtkContainer can override the
1589 * default behaviour by overriding the class closure of this signal.
1592 gtk_container_set_focus_child (GtkContainer *container,
1595 g_return_if_fail (GTK_IS_CONTAINER (container));
1597 g_return_if_fail (GTK_IS_WIDGET (child));
1599 g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, child);
1603 * gtk_container_get_focus_child:
1604 * @container: a #GtkContainer
1606 * Returns the current focus child widget inside @container.
1608 * Returns: The child widget which has the focus
1609 * inside @container, or %NULL if none is set.
1614 gtk_container_get_focus_child (GtkContainer *container)
1616 g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
1618 return container->priv->focus_child;
1622 * gtk_container_get_children:
1623 * @container: a #GtkContainer
1625 * Returns the container's non-internal children. See
1626 * gtk_container_forall() for details on what constitutes an "internal" child.
1628 * Return value: (element-type GtkWidget) (transfer container): a newly-allocated list of the container's non-internal children.
1631 gtk_container_get_children (GtkContainer *container)
1633 GList *children = NULL;
1635 gtk_container_foreach (container,
1636 gtk_container_children_callback,
1639 return g_list_reverse (children);
1643 gtk_container_child_position_callback (GtkWidget *widget,
1644 gpointer client_data)
1650 } *data = client_data;
1653 if (data->child == widget)
1654 data->index = data->i;
1658 gtk_container_child_default_composite_name (GtkContainer *container,
1668 /* fallback implementation */
1672 gtk_container_forall (container,
1673 gtk_container_child_position_callback,
1676 name = g_strdup_printf ("%s-%u",
1677 g_type_name (G_TYPE_FROM_INSTANCE (child)),
1684 _gtk_container_child_composite_name (GtkContainer *container,
1687 gboolean composite_child;
1689 g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
1690 g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
1691 g_return_val_if_fail (gtk_widget_get_parent (child) == GTK_WIDGET (container), NULL);
1693 g_object_get (child, "composite-child", &composite_child, NULL);
1694 if (composite_child)
1696 static GQuark quark_composite_name = 0;
1699 if (!quark_composite_name)
1700 quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
1702 name = g_object_get_qdata (G_OBJECT (child), quark_composite_name);
1705 GtkContainerClass *class;
1707 class = GTK_CONTAINER_GET_CLASS (container);
1708 if (class->composite_name)
1709 name = class->composite_name (container, child);
1712 name = g_strdup (name);
1721 gtk_container_real_set_focus_child (GtkContainer *container,
1724 GtkContainerPriv *priv;
1726 g_return_if_fail (GTK_IS_CONTAINER (container));
1727 g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
1729 priv = container->priv;
1731 if (child != priv->focus_child)
1733 if (priv->focus_child)
1734 g_object_unref (priv->focus_child);
1735 priv->focus_child = child;
1736 if (priv->focus_child)
1737 g_object_ref (priv->focus_child);
1741 /* check for h/v adjustments
1743 if (priv->focus_child)
1745 GtkAdjustment *hadj;
1746 GtkAdjustment *vadj;
1747 GtkAllocation allocation;
1748 GtkWidget *focus_child;
1751 hadj = g_object_get_qdata (G_OBJECT (container), hadjustment_key_id);
1752 vadj = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id);
1756 focus_child = priv->focus_child;
1757 while (gtk_container_get_focus_child (GTK_CONTAINER (focus_child)))
1759 focus_child = gtk_container_get_focus_child (GTK_CONTAINER (focus_child));
1762 gtk_widget_translate_coordinates (focus_child, priv->focus_child,
1765 gtk_widget_get_allocation (priv->focus_child, &allocation);
1769 gtk_widget_get_allocation (focus_child, &allocation);
1772 gtk_adjustment_clamp_page (vadj, y, y + allocation.height);
1775 gtk_adjustment_clamp_page (hadj, x, x + allocation.width);
1781 get_focus_chain (GtkContainer *container)
1783 return g_object_get_data (G_OBJECT (container), "gtk-container-focus-chain");
1786 /* same as gtk_container_get_children, except it includes internals
1789 gtk_container_get_all_children (GtkContainer *container)
1791 GList *children = NULL;
1793 gtk_container_forall (container,
1794 gtk_container_children_callback,
1801 gtk_container_focus (GtkWidget *widget,
1802 GtkDirectionType direction)
1805 GList *sorted_children;
1807 GtkContainer *container;
1808 GtkContainerPriv *priv;
1810 g_return_val_if_fail (GTK_IS_CONTAINER (widget), FALSE);
1812 container = GTK_CONTAINER (widget);
1813 priv = container->priv;
1817 if (gtk_widget_get_can_focus (widget))
1819 if (!gtk_widget_has_focus (widget))
1821 gtk_widget_grab_focus (widget);
1827 /* Get a list of the containers children, allowing focus
1828 * chain to override.
1830 if (priv->has_focus_chain)
1831 children = g_list_copy (get_focus_chain (container));
1833 children = gtk_container_get_all_children (container);
1835 if (priv->has_focus_chain &&
1836 (direction == GTK_DIR_TAB_FORWARD ||
1837 direction == GTK_DIR_TAB_BACKWARD))
1839 sorted_children = g_list_copy (children);
1841 if (direction == GTK_DIR_TAB_BACKWARD)
1842 sorted_children = g_list_reverse (sorted_children);
1845 sorted_children = _gtk_container_focus_sort (container, children, direction, NULL);
1847 return_val = gtk_container_focus_move (container, sorted_children, direction);
1849 g_list_free (sorted_children);
1850 g_list_free (children);
1857 tab_compare (gconstpointer a,
1861 GtkAllocation child1_allocation, child2_allocation;
1862 const GtkWidget *child1 = a;
1863 const GtkWidget *child2 = b;
1864 GtkTextDirection text_direction = GPOINTER_TO_INT (data);
1866 gtk_widget_get_allocation ((GtkWidget *) child1, &child1_allocation);
1867 gtk_widget_get_allocation ((GtkWidget *) child2, &child2_allocation);
1869 gint y1 = child1_allocation.y + child1_allocation.height / 2;
1870 gint y2 = child2_allocation.y + child2_allocation.height / 2;
1874 gint x1 = child1_allocation.x + child1_allocation.width / 2;
1875 gint x2 = child2_allocation.x + child2_allocation.width / 2;
1877 if (text_direction == GTK_TEXT_DIR_RTL)
1878 return (x1 < x2) ? 1 : ((x1 == x2) ? 0 : -1);
1880 return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
1883 return (y1 < y2) ? -1 : 1;
1887 gtk_container_focus_sort_tab (GtkContainer *container,
1889 GtkDirectionType direction,
1890 GtkWidget *old_focus)
1892 GtkTextDirection text_direction = gtk_widget_get_direction (GTK_WIDGET (container));
1893 children = g_list_sort_with_data (children, tab_compare, GINT_TO_POINTER (text_direction));
1895 /* if we are going backwards then reverse the order
1898 if (direction == GTK_DIR_TAB_BACKWARD)
1899 children = g_list_reverse (children);
1904 /* Get coordinates of @widget's allocation with respect to
1905 * allocation of @container.
1908 get_allocation_coords (GtkContainer *container,
1910 GdkRectangle *allocation)
1912 gtk_widget_set_allocation (widget, allocation);
1914 return gtk_widget_translate_coordinates (widget, GTK_WIDGET (container),
1915 0, 0, &allocation->x, &allocation->y);
1918 /* Look for a child in @children that is intermediate between
1919 * the focus widget and container. This widget, if it exists,
1920 * acts as the starting widget for focus navigation.
1923 find_old_focus (GtkContainer *container,
1926 GList *tmp_list = children;
1929 GtkWidget *child = tmp_list->data;
1930 GtkWidget *widget = child;
1932 while (widget && widget != (GtkWidget *)container)
1936 parent = gtk_widget_get_parent (widget);
1938 if (parent && (gtk_container_get_focus_child (GTK_CONTAINER (parent)) != widget))
1947 tmp_list = tmp_list->next;
1954 old_focus_coords (GtkContainer *container,
1955 GdkRectangle *old_focus_rect)
1957 GtkWidget *widget = GTK_WIDGET (container);
1958 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
1960 if (GTK_IS_WINDOW (toplevel) && GTK_WINDOW (toplevel)->focus_widget)
1962 GtkWidget *old_focus = GTK_WINDOW (toplevel)->focus_widget;
1964 return get_allocation_coords (container, old_focus, old_focus_rect);
1970 typedef struct _CompareInfo CompareInfo;
1974 GtkContainer *container;
1981 up_down_compare (gconstpointer a,
1985 GdkRectangle allocation1;
1986 GdkRectangle allocation2;
1987 CompareInfo *compare = data;
1990 get_allocation_coords (compare->container, (GtkWidget *)a, &allocation1);
1991 get_allocation_coords (compare->container, (GtkWidget *)b, &allocation2);
1993 y1 = allocation1.y + allocation1.height / 2;
1994 y2 = allocation2.y + allocation2.height / 2;
1998 gint x1 = abs (allocation1.x + allocation1.width / 2 - compare->x);
1999 gint x2 = abs (allocation2.x + allocation2.width / 2 - compare->x);
2001 if (compare->reverse)
2002 return (x1 < x2) ? 1 : ((x1 == x2) ? 0 : -1);
2004 return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
2007 return (y1 < y2) ? -1 : 1;
2011 gtk_container_focus_sort_up_down (GtkContainer *container,
2013 GtkDirectionType direction,
2014 GtkWidget *old_focus)
2016 CompareInfo compare;
2018 GdkRectangle old_allocation;
2020 compare.container = container;
2021 compare.reverse = (direction == GTK_DIR_UP);
2024 old_focus = find_old_focus (container, children);
2026 if (old_focus && get_allocation_coords (container, old_focus, &old_allocation))
2032 /* Delete widgets from list that don't match minimum criteria */
2034 compare_x1 = old_allocation.x;
2035 compare_x2 = old_allocation.x + old_allocation.width;
2037 if (direction == GTK_DIR_UP)
2038 compare_y = old_allocation.y;
2040 compare_y = old_allocation.y + old_allocation.height;
2042 tmp_list = children;
2045 GtkWidget *child = tmp_list->data;
2046 GList *next = tmp_list->next;
2047 gint child_x1, child_x2;
2048 GdkRectangle child_allocation;
2050 if (child != old_focus)
2052 if (get_allocation_coords (container, child, &child_allocation))
2054 child_x1 = child_allocation.x;
2055 child_x2 = child_allocation.x + child_allocation.width;
2057 if ((child_x2 <= compare_x1 || child_x1 >= compare_x2) /* No horizontal overlap */ ||
2058 (direction == GTK_DIR_DOWN && child_allocation.y + child_allocation.height < compare_y) || /* Not below */
2059 (direction == GTK_DIR_UP && child_allocation.y > compare_y)) /* Not above */
2061 children = g_list_delete_link (children, tmp_list);
2065 children = g_list_delete_link (children, tmp_list);
2071 compare.x = (compare_x1 + compare_x2) / 2;
2072 compare.y = old_allocation.y + old_allocation.height / 2;
2076 /* No old focus widget, need to figure out starting x,y some other way
2078 GtkAllocation allocation;
2079 GtkWidget *widget = GTK_WIDGET (container);
2080 GdkRectangle old_focus_rect;
2082 gtk_widget_get_allocation (widget, &allocation);
2084 if (old_focus_coords (container, &old_focus_rect))
2086 compare.x = old_focus_rect.x + old_focus_rect.width / 2;
2090 if (!gtk_widget_get_has_window (widget))
2091 compare.x = allocation.x + allocation.width / 2;
2093 compare.x = allocation.width / 2;
2096 if (!gtk_widget_get_has_window (widget))
2097 compare.y = (direction == GTK_DIR_DOWN) ? allocation.y : allocation.y + allocation.height;
2099 compare.y = (direction == GTK_DIR_DOWN) ? 0 : + allocation.height;
2102 children = g_list_sort_with_data (children, up_down_compare, &compare);
2104 if (compare.reverse)
2105 children = g_list_reverse (children);
2111 left_right_compare (gconstpointer a,
2115 GdkRectangle allocation1;
2116 GdkRectangle allocation2;
2117 CompareInfo *compare = data;
2120 get_allocation_coords (compare->container, (GtkWidget *)a, &allocation1);
2121 get_allocation_coords (compare->container, (GtkWidget *)b, &allocation2);
2123 x1 = allocation1.x + allocation1.width / 2;
2124 x2 = allocation2.x + allocation2.width / 2;
2128 gint y1 = abs (allocation1.y + allocation1.height / 2 - compare->y);
2129 gint y2 = abs (allocation2.y + allocation2.height / 2 - compare->y);
2131 if (compare->reverse)
2132 return (y1 < y2) ? 1 : ((y1 == y2) ? 0 : -1);
2134 return (y1 < y2) ? -1 : ((y1 == y2) ? 0 : 1);
2137 return (x1 < x2) ? -1 : 1;
2141 gtk_container_focus_sort_left_right (GtkContainer *container,
2143 GtkDirectionType direction,
2144 GtkWidget *old_focus)
2146 CompareInfo compare;
2148 GdkRectangle old_allocation;
2150 compare.container = container;
2151 compare.reverse = (direction == GTK_DIR_LEFT);
2154 old_focus = find_old_focus (container, children);
2156 if (old_focus && get_allocation_coords (container, old_focus, &old_allocation))
2162 /* Delete widgets from list that don't match minimum criteria */
2164 compare_y1 = old_allocation.y;
2165 compare_y2 = old_allocation.y + old_allocation.height;
2167 if (direction == GTK_DIR_LEFT)
2168 compare_x = old_allocation.x;
2170 compare_x = old_allocation.x + old_allocation.width;
2172 tmp_list = children;
2175 GtkWidget *child = tmp_list->data;
2176 GList *next = tmp_list->next;
2177 gint child_y1, child_y2;
2178 GdkRectangle child_allocation;
2180 if (child != old_focus)
2182 if (get_allocation_coords (container, child, &child_allocation))
2184 child_y1 = child_allocation.y;
2185 child_y2 = child_allocation.y + child_allocation.height;
2187 if ((child_y2 <= compare_y1 || child_y1 >= compare_y2) /* No vertical overlap */ ||
2188 (direction == GTK_DIR_RIGHT && child_allocation.x + child_allocation.width < compare_x) || /* Not to left */
2189 (direction == GTK_DIR_LEFT && child_allocation.x > compare_x)) /* Not to right */
2191 children = g_list_delete_link (children, tmp_list);
2195 children = g_list_delete_link (children, tmp_list);
2201 compare.y = (compare_y1 + compare_y2) / 2;
2202 compare.x = old_allocation.x + old_allocation.width / 2;
2206 /* No old focus widget, need to figure out starting x,y some other way
2208 GtkAllocation allocation;
2209 GtkWidget *widget = GTK_WIDGET (container);
2210 GdkRectangle old_focus_rect;
2212 gtk_widget_get_allocation (widget, &allocation);
2214 if (old_focus_coords (container, &old_focus_rect))
2216 compare.y = old_focus_rect.y + old_focus_rect.height / 2;
2220 if (!gtk_widget_get_has_window (widget))
2221 compare.y = allocation.y + allocation.height / 2;
2223 compare.y = allocation.height / 2;
2226 if (!gtk_widget_get_has_window (widget))
2227 compare.x = (direction == GTK_DIR_RIGHT) ? allocation.x : allocation.x + allocation.width;
2229 compare.x = (direction == GTK_DIR_RIGHT) ? 0 : allocation.width;
2232 children = g_list_sort_with_data (children, left_right_compare, &compare);
2234 if (compare.reverse)
2235 children = g_list_reverse (children);
2241 * gtk_container_focus_sort:
2242 * @container: a #GtkContainer
2243 * @children: a list of descendents of @container (they don't
2244 * have to be direct children)
2245 * @direction: focus direction
2246 * @old_focus: (allow-none): widget to use for the starting position, or %NULL
2247 * to determine this automatically.
2248 * (Note, this argument isn't used for GTK_DIR_TAB_*,
2249 * which is the only @direction we use currently,
2250 * so perhaps this argument should be removed)
2252 * Sorts @children in the correct order for focusing with
2253 * direction type @direction.
2255 * Return value: a copy of @children, sorted in correct focusing order,
2256 * with children that aren't suitable for focusing in this direction
2260 _gtk_container_focus_sort (GtkContainer *container,
2262 GtkDirectionType direction,
2263 GtkWidget *old_focus)
2265 GList *visible_children = NULL;
2269 if (gtk_widget_get_realized (children->data))
2270 visible_children = g_list_prepend (visible_children, children->data);
2271 children = children->next;
2276 case GTK_DIR_TAB_FORWARD:
2277 case GTK_DIR_TAB_BACKWARD:
2278 return gtk_container_focus_sort_tab (container, visible_children, direction, old_focus);
2281 return gtk_container_focus_sort_up_down (container, visible_children, direction, old_focus);
2284 return gtk_container_focus_sort_left_right (container, visible_children, direction, old_focus);
2287 g_assert_not_reached ();
2293 gtk_container_focus_move (GtkContainer *container,
2295 GtkDirectionType direction)
2297 GtkContainerPriv *priv = container->priv;
2298 GtkWidget *focus_child;
2301 focus_child = priv->focus_child;
2305 child = children->data;
2306 children = children->next;
2313 if (focus_child == child)
2317 if (gtk_widget_child_focus (child, direction))
2321 else if (gtk_widget_is_drawable (child) &&
2322 gtk_widget_is_ancestor (child, GTK_WIDGET (container)))
2324 if (gtk_widget_child_focus (child, direction))
2334 gtk_container_children_callback (GtkWidget *widget,
2335 gpointer client_data)
2339 children = (GList**) client_data;
2340 *children = g_list_prepend (*children, widget);
2344 chain_widget_destroyed (GtkWidget *widget,
2347 GtkContainer *container;
2350 container = GTK_CONTAINER (user_data);
2352 chain = g_object_get_data (G_OBJECT (container),
2353 "gtk-container-focus-chain");
2355 chain = g_list_remove (chain, widget);
2357 g_signal_handlers_disconnect_by_func (widget,
2358 chain_widget_destroyed,
2361 g_object_set_data (G_OBJECT (container),
2362 I_("gtk-container-focus-chain"),
2367 * gtk_container_set_focus_chain:
2368 * @container: a #GtkContainer
2369 * @focusable_widgets: the new focus chain
2371 * Sets a focus chain, overriding the one computed automatically by GTK+.
2373 * In principle each widget in the chain should be a descendant of the
2374 * container, but this is not enforced by this method, since it's allowed
2375 * to set the focus chain before you pack the widgets, or have a widget
2376 * in the chain that isn't always packed. The necessary checks are done
2377 * when the focus chain is actually traversed.
2380 gtk_container_set_focus_chain (GtkContainer *container,
2381 GList *focusable_widgets)
2385 GtkContainerPriv *priv;
2387 g_return_if_fail (GTK_IS_CONTAINER (container));
2389 priv = container->priv;
2391 if (priv->has_focus_chain)
2392 gtk_container_unset_focus_chain (container);
2394 priv->has_focus_chain = TRUE;
2397 tmp_list = focusable_widgets;
2398 while (tmp_list != NULL)
2400 g_return_if_fail (GTK_IS_WIDGET (tmp_list->data));
2402 /* In principle each widget in the chain should be a descendant
2403 * of the container, but we don't want to check that here, it's
2404 * expensive and also it's allowed to set the focus chain before
2405 * you pack the widgets, or have a widget in the chain that isn't
2406 * always packed. So we check for ancestor during actual traversal.
2409 chain = g_list_prepend (chain, tmp_list->data);
2411 g_signal_connect (tmp_list->data,
2413 G_CALLBACK (chain_widget_destroyed),
2416 tmp_list = g_list_next (tmp_list);
2419 chain = g_list_reverse (chain);
2421 g_object_set_data (G_OBJECT (container),
2422 I_("gtk-container-focus-chain"),
2427 * gtk_container_get_focus_chain:
2428 * @container: a #GtkContainer
2429 * @focusable_widgets: (element-type GtkWidget) (out) (transfer container): location
2430 * to store the focus chain of the
2431 * container, or %NULL. You should free this list
2432 * using g_list_free() when you are done with it, however
2433 * no additional reference count is added to the
2434 * individual widgets in the focus chain.
2436 * Retrieves the focus chain of the container, if one has been
2437 * set explicitly. If no focus chain has been explicitly
2438 * set, GTK+ computes the focus chain based on the positions
2439 * of the children. In that case, GTK+ stores %NULL in
2440 * @focusable_widgets and returns %FALSE.
2442 * Return value: %TRUE if the focus chain of the container
2443 * has been set explicitly.
2446 gtk_container_get_focus_chain (GtkContainer *container,
2447 GList **focus_chain)
2449 GtkContainerPriv *priv;
2451 g_return_val_if_fail (GTK_IS_CONTAINER (container), FALSE);
2453 priv = container->priv;
2457 if (priv->has_focus_chain)
2458 *focus_chain = g_list_copy (get_focus_chain (container));
2460 *focus_chain = NULL;
2463 return priv->has_focus_chain;
2467 * gtk_container_unset_focus_chain:
2468 * @container: a #GtkContainer
2470 * Removes a focus chain explicitly set with gtk_container_set_focus_chain().
2473 gtk_container_unset_focus_chain (GtkContainer *container)
2475 GtkContainerPriv *priv;
2477 g_return_if_fail (GTK_IS_CONTAINER (container));
2479 priv = container->priv;
2481 if (priv->has_focus_chain)
2486 chain = get_focus_chain (container);
2488 priv->has_focus_chain = FALSE;
2490 g_object_set_data (G_OBJECT (container),
2491 I_("gtk-container-focus-chain"),
2495 while (tmp_list != NULL)
2497 g_signal_handlers_disconnect_by_func (tmp_list->data,
2498 chain_widget_destroyed,
2501 tmp_list = g_list_next (tmp_list);
2504 g_list_free (chain);
2509 * gtk_container_set_focus_vadjustment:
2510 * @container: a #GtkContainer
2511 * @adjustment: an adjustment which should be adjusted when the focus
2512 * is moved among the descendents of @container
2514 * Hooks up an adjustment to focus handling in a container, so when a
2515 * child of the container is focused, the adjustment is scrolled to
2516 * show that widget. This function sets the vertical alignment. See
2517 * gtk_scrolled_window_get_vadjustment() for a typical way of obtaining
2518 * the adjustment and gtk_container_set_focus_hadjustment() for setting
2519 * the horizontal adjustment.
2521 * The adjustments have to be in pixel units and in the same coordinate
2522 * system as the allocation for immediate children of the container.
2525 gtk_container_set_focus_vadjustment (GtkContainer *container,
2526 GtkAdjustment *adjustment)
2528 g_return_if_fail (GTK_IS_CONTAINER (container));
2530 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2533 g_object_ref (adjustment);
2535 g_object_set_qdata_full (G_OBJECT (container),
2542 * gtk_container_get_focus_vadjustment:
2543 * @container: a #GtkContainer
2545 * Retrieves the vertical focus adjustment for the container. See
2546 * gtk_container_set_focus_vadjustment().
2548 * Return value: (transfer none): the vertical focus adjustment, or %NULL if
2549 * none has been set.
2552 gtk_container_get_focus_vadjustment (GtkContainer *container)
2554 GtkAdjustment *vadjustment;
2556 g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
2558 vadjustment = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id);
2564 * gtk_container_set_focus_hadjustment:
2565 * @container: a #GtkContainer
2566 * @adjustment: an adjustment which should be adjusted when the focus is
2567 * moved among the descendents of @container
2569 * Hooks up an adjustment to focus handling in a container, so when a child
2570 * of the container is focused, the adjustment is scrolled to show that
2571 * widget. This function sets the horizontal alignment.
2572 * See gtk_scrolled_window_get_hadjustment() for a typical way of obtaining
2573 * the adjustment and gtk_container_set_focus_vadjustment() for setting
2574 * the vertical adjustment.
2576 * The adjustments have to be in pixel units and in the same coordinate
2577 * system as the allocation for immediate children of the container.
2580 gtk_container_set_focus_hadjustment (GtkContainer *container,
2581 GtkAdjustment *adjustment)
2583 g_return_if_fail (GTK_IS_CONTAINER (container));
2585 g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2588 g_object_ref (adjustment);
2590 g_object_set_qdata_full (G_OBJECT (container),
2597 * gtk_container_get_focus_hadjustment:
2598 * @container: a #GtkContainer
2600 * Retrieves the horizontal focus adjustment for the container. See
2601 * gtk_container_set_focus_hadjustment ().
2603 * Return value: (transfer none): the horizontal focus adjustment, or %NULL if
2604 * none has been set.
2607 gtk_container_get_focus_hadjustment (GtkContainer *container)
2609 GtkAdjustment *hadjustment;
2611 g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
2613 hadjustment = g_object_get_qdata (G_OBJECT (container), hadjustment_key_id);
2620 gtk_container_show_all (GtkWidget *widget)
2622 g_return_if_fail (GTK_IS_CONTAINER (widget));
2624 gtk_container_foreach (GTK_CONTAINER (widget),
2625 (GtkCallback) gtk_widget_show_all,
2627 gtk_widget_show (widget);
2631 gtk_container_hide_all (GtkWidget *widget)
2633 g_return_if_fail (GTK_IS_CONTAINER (widget));
2635 gtk_widget_hide (widget);
2636 gtk_container_foreach (GTK_CONTAINER (widget),
2637 (GtkCallback) gtk_widget_hide_all,
2643 gtk_container_expose_child (GtkWidget *child,
2644 gpointer client_data)
2647 GtkWidget *container;
2648 GdkEventExpose *event;
2649 } *data = client_data;
2651 gtk_container_propagate_expose (GTK_CONTAINER (data->container),
2657 gtk_container_expose (GtkWidget *widget,
2658 GdkEventExpose *event)
2661 GtkWidget *container;
2662 GdkEventExpose *event;
2665 g_return_val_if_fail (GTK_IS_CONTAINER (widget), FALSE);
2666 g_return_val_if_fail (event != NULL, FALSE);
2669 if (gtk_widget_is_drawable (widget))
2671 data.container = widget;
2674 gtk_container_forall (GTK_CONTAINER (widget),
2675 gtk_container_expose_child,
2683 gtk_container_map_child (GtkWidget *child,
2684 gpointer client_data)
2686 if (gtk_widget_get_visible (child) &&
2687 gtk_widget_get_child_visible (child) &&
2688 !gtk_widget_get_mapped (child))
2689 gtk_widget_map (child);
2693 gtk_container_map (GtkWidget *widget)
2695 gtk_widget_set_mapped (widget, TRUE);
2697 gtk_container_forall (GTK_CONTAINER (widget),
2698 gtk_container_map_child,
2701 if (gtk_widget_get_has_window (widget))
2702 gdk_window_show (gtk_widget_get_window (widget));
2706 gtk_container_unmap (GtkWidget *widget)
2708 gtk_widget_set_mapped (widget, FALSE);
2710 if (gtk_widget_get_has_window (widget))
2711 gdk_window_hide (gtk_widget_get_window (widget));
2713 gtk_container_forall (GTK_CONTAINER (widget),
2714 (GtkCallback)gtk_widget_unmap,
2719 * gtk_container_propagate_expose:
2720 * @container: a #GtkContainer
2721 * @child: a child of @container
2722 * @event: a expose event sent to container
2724 * When a container receives an expose event, it must send synthetic
2725 * expose events to all children that don't have their own #GdkWindows.
2726 * This function provides a convenient way of doing this. A container,
2727 * when it receives an expose event, calls gtk_container_propagate_expose()
2728 * once for each child, passing in the event the container received.
2730 * gtk_container_propagate_expose() takes care of deciding whether
2731 * an expose event needs to be sent to the child, intersecting
2732 * the event's area with the child area, and sending the event.
2734 * In most cases, a container can simply either simply inherit the
2735 * #GtkWidget::expose implementation from #GtkContainer, or, do some drawing
2736 * and then chain to the ::expose implementation from #GtkContainer.
2739 gtk_container_propagate_expose (GtkContainer *container,
2741 GdkEventExpose *event)
2743 GdkEvent *child_event;
2745 g_return_if_fail (GTK_IS_CONTAINER (container));
2746 g_return_if_fail (GTK_IS_WIDGET (child));
2747 g_return_if_fail (event != NULL);
2749 g_assert (gtk_widget_get_parent (child) == GTK_WIDGET (container));
2751 if (gtk_widget_is_drawable (child) &&
2752 !gtk_widget_get_has_window (child) &&
2753 gtk_widget_get_window (child) == event->window)
2755 child_event = gdk_event_new (GDK_EXPOSE);
2756 child_event->expose = *event;
2757 g_object_ref (child_event->expose.window);
2759 child_event->expose.region = gtk_widget_region_intersect (child, event->region);
2760 if (!cairo_region_is_empty (child_event->expose.region))
2762 cairo_region_get_extents (child_event->expose.region, &child_event->expose.area);
2763 gtk_widget_send_expose (child, child_event);
2765 gdk_event_free (child_event);
2770 _gtk_container_get_need_resize (GtkContainer *container)
2772 return container->priv->need_resize;
2776 _gtk_container_set_need_resize (GtkContainer *container,
2777 gboolean need_resize)
2779 container->priv->need_resize = need_resize;
2783 _gtk_container_get_reallocate_redraws (GtkContainer *container)
2785 return container->priv->reallocate_redraws;