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 "gtkprivate.h"
35
#include "gtkmarshalers.h"
36
#include "gtkwindow.h"
38
#include "gtktoolbar.h"
39
#include <gobject/gobjectnotifyqueue.c>
40
#include <gobject/gvaluecollector.h>
59
#define PARAM_SPEC_PARAM_ID(pspec) ((pspec)->param_id)
60
#define PARAM_SPEC_SET_PARAM_ID(pspec, id) ((pspec)->param_id = (id))
63
/* --- prototypes --- */
64
static void gtk_container_base_class_init (GtkContainerClass *klass);
65
static void gtk_container_base_class_finalize (GtkContainerClass *klass);
66
static void gtk_container_class_init (GtkContainerClass *klass);
67
static void gtk_container_init (GtkContainer *container);
68
static void gtk_container_destroy (GtkObject *object);
69
static void gtk_container_set_property (GObject *object,
73
static void gtk_container_get_property (GObject *object,
77
static void gtk_container_add_unimplemented (GtkContainer *container,
79
static void gtk_container_remove_unimplemented (GtkContainer *container,
81
static void gtk_container_real_check_resize (GtkContainer *container);
82
static gboolean gtk_container_focus (GtkWidget *widget,
83
GtkDirectionType direction);
84
static void gtk_container_real_set_focus_child (GtkContainer *container,
87
static gboolean gtk_container_focus_move (GtkContainer *container,
89
GtkDirectionType direction);
90
static void gtk_container_children_callback (GtkWidget *widget,
91
gpointer client_data);
92
static void gtk_container_show_all (GtkWidget *widget);
93
static void gtk_container_hide_all (GtkWidget *widget);
94
static gint gtk_container_expose (GtkWidget *widget,
95
GdkEventExpose *event);
96
static void gtk_container_map (GtkWidget *widget);
97
static void gtk_container_unmap (GtkWidget *widget);
99
static gchar* gtk_container_child_default_composite_name (GtkContainer *container,
103
/* --- variables --- */
104
static const gchar vadjustment_key[] = "gtk-vadjustment";
105
static guint vadjustment_key_id = 0;
106
static const gchar hadjustment_key[] = "gtk-hadjustment";
107
static guint hadjustment_key_id = 0;
108
static GSList *container_resize_queue = NULL;
109
static guint container_signals[LAST_SIGNAL] = { 0 };
110
static GtkWidgetClass *parent_class = NULL;
111
extern GParamSpecPool *_gtk_widget_child_property_pool;
112
extern GObjectNotifyContext *_gtk_widget_child_property_notify_context;
115
/* --- functions --- */
117
gtk_container_get_type (void)
119
static GType container_type = 0;
123
const GTypeInfo container_info =
125
sizeof (GtkContainerClass),
126
(GBaseInitFunc) gtk_container_base_class_init,
127
(GBaseFinalizeFunc) gtk_container_base_class_finalize,
128
(GClassInitFunc) gtk_container_class_init,
129
NULL /* class_finalize */,
130
NULL /* class_data */,
131
sizeof (GtkContainer),
133
(GInstanceInitFunc) gtk_container_init,
134
NULL, /* value_table */
138
g_type_register_static (GTK_TYPE_WIDGET, I_("GtkContainer"),
139
&container_info, G_TYPE_FLAG_ABSTRACT);
142
return container_type;
146
gtk_container_base_class_init (GtkContainerClass *class)
148
/* reset instance specifc class fields that don't get inherited */
149
class->set_child_property = NULL;
150
class->get_child_property = NULL;
154
gtk_container_base_class_finalize (GtkContainerClass *class)
158
list = g_param_spec_pool_list_owned (_gtk_widget_child_property_pool, G_OBJECT_CLASS_TYPE (class));
159
for (node = list; node; node = node->next)
161
GParamSpec *pspec = node->data;
163
g_param_spec_pool_remove (_gtk_widget_child_property_pool, pspec);
164
PARAM_SPEC_SET_PARAM_ID (pspec, 0);
165
g_param_spec_unref (pspec);
171
gtk_container_class_init (GtkContainerClass *class)
173
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
174
GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
175
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
177
parent_class = g_type_class_peek_parent (class);
179
vadjustment_key_id = g_quark_from_static_string (vadjustment_key);
180
hadjustment_key_id = g_quark_from_static_string (hadjustment_key);
182
gobject_class->set_property = gtk_container_set_property;
183
gobject_class->get_property = gtk_container_get_property;
185
object_class->destroy = gtk_container_destroy;
187
widget_class->show_all = gtk_container_show_all;
188
widget_class->hide_all = gtk_container_hide_all;
189
widget_class->expose_event = gtk_container_expose;
190
widget_class->map = gtk_container_map;
191
widget_class->unmap = gtk_container_unmap;
192
widget_class->focus = gtk_container_focus;
194
class->add = gtk_container_add_unimplemented;
195
class->remove = gtk_container_remove_unimplemented;
196
class->check_resize = gtk_container_real_check_resize;
197
class->forall = NULL;
198
class->set_focus_child = gtk_container_real_set_focus_child;
199
class->child_type = NULL;
200
class->composite_name = gtk_container_child_default_composite_name;
202
g_object_class_install_property (gobject_class,
204
g_param_spec_enum ("resize-mode",
206
P_("Specify how resize events are handled"),
207
GTK_TYPE_RESIZE_MODE,
209
GTK_PARAM_READWRITE));
210
g_object_class_install_property (gobject_class,
212
g_param_spec_uint ("border-width",
214
P_("The width of the empty border outside the containers children"),
218
GTK_PARAM_READWRITE));
219
g_object_class_install_property (gobject_class,
221
g_param_spec_object ("child",
223
P_("Can be used to add a new child to the container"),
225
GTK_PARAM_WRITABLE));
226
container_signals[ADD] =
227
g_signal_new (I_("add"),
228
G_OBJECT_CLASS_TYPE (object_class),
230
G_STRUCT_OFFSET (GtkContainerClass, add),
232
_gtk_marshal_VOID__OBJECT,
235
container_signals[REMOVE] =
236
g_signal_new (I_("remove"),
237
G_OBJECT_CLASS_TYPE (object_class),
239
G_STRUCT_OFFSET (GtkContainerClass, remove),
241
_gtk_marshal_VOID__OBJECT,
244
container_signals[CHECK_RESIZE] =
245
g_signal_new (I_("check_resize"),
246
G_OBJECT_CLASS_TYPE (object_class),
248
G_STRUCT_OFFSET (GtkContainerClass, check_resize),
250
_gtk_marshal_VOID__VOID,
252
container_signals[SET_FOCUS_CHILD] =
253
g_signal_new (I_("set-focus-child"),
254
G_OBJECT_CLASS_TYPE (object_class),
256
G_STRUCT_OFFSET (GtkContainerClass, set_focus_child),
258
_gtk_marshal_VOID__OBJECT,
264
* gtk_container_child_type:
265
* @container: a #GtkContainer.
267
* Returns the type of the children supported by the container.
269
* Note that this may return %G_TYPE_NONE to indicate that no more
270
* children can be added, e.g. for a #GtkPaned which already has two
273
* Return value: a #GType.
276
gtk_container_child_type (GtkContainer *container)
279
GtkContainerClass *class;
281
g_return_val_if_fail (GTK_IS_CONTAINER (container), 0);
283
class = GTK_CONTAINER_GET_CLASS (container);
284
if (class->child_type)
285
slot = class->child_type (container);
292
/* --- GtkContainer child property mechanism --- */
294
container_get_child_property (GtkContainer *container,
299
GtkContainerClass *class = g_type_class_peek (pspec->owner_type);
301
class->get_child_property (container, child, PARAM_SPEC_PARAM_ID (pspec), value, pspec);
305
container_set_child_property (GtkContainer *container,
309
GObjectNotifyQueue *nqueue)
311
GValue tmp_value = { 0, };
312
GtkContainerClass *class = g_type_class_peek (pspec->owner_type);
314
/* provide a copy to work from, convert (if necessary) and validate */
315
g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
316
if (!g_value_transform (value, &tmp_value))
317
g_warning ("unable to set child property `%s' of type `%s' from value of type `%s'",
319
g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
320
G_VALUE_TYPE_NAME (value));
321
else if (g_param_value_validate (pspec, &tmp_value) && !(pspec->flags & G_PARAM_LAX_VALIDATION))
323
gchar *contents = g_strdup_value_contents (value);
325
g_warning ("value \"%s\" of type `%s' is invalid for property `%s' of type `%s'",
327
G_VALUE_TYPE_NAME (value),
329
g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)));
334
class->set_child_property (container, child, PARAM_SPEC_PARAM_ID (pspec), &tmp_value, pspec);
335
g_object_notify_queue_add (G_OBJECT (child), nqueue, pspec);
337
g_value_unset (&tmp_value);
341
* gtk_container_child_get_valist:
342
* @container: a #GtkContainer
343
* @child: a widget which is a child of @container
344
* @first_property_name: the name of the first property to get
345
* @var_args: a %NULL-terminated list of property names and #GValue*,
346
* starting with @first_prop_name.
348
* Gets the values of one or more child properties for @child and @container.
351
gtk_container_child_get_valist (GtkContainer *container,
353
const gchar *first_property_name,
358
g_return_if_fail (GTK_IS_CONTAINER (container));
359
g_return_if_fail (GTK_IS_WIDGET (child));
360
g_return_if_fail (child->parent == GTK_WIDGET (container));
362
g_object_ref (container);
363
g_object_ref (child);
365
name = first_property_name;
368
GValue value = { 0, };
372
pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
374
G_OBJECT_TYPE (container),
378
g_warning ("%s: container class `%s' has no child property named `%s'",
380
G_OBJECT_TYPE_NAME (container),
384
if (!(pspec->flags & G_PARAM_READABLE))
386
g_warning ("%s: child property `%s' of container class `%s' is not readable",
389
G_OBJECT_TYPE_NAME (container));
392
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
393
container_get_child_property (container, child, pspec, &value);
394
G_VALUE_LCOPY (&value, var_args, 0, &error);
397
g_warning ("%s: %s", G_STRLOC, error);
399
g_value_unset (&value);
402
g_value_unset (&value);
403
name = va_arg (var_args, gchar*);
406
g_object_unref (child);
407
g_object_unref (container);
411
* gtk_container_child_get_property:
412
* @container: a #GtkContainer
413
* @child: a widget which is a child of @container
414
* @property_name: the name of the property to get
415
* @value: a location to return the value
417
* Gets the value of a child property for @child and @container.
420
gtk_container_child_get_property (GtkContainer *container,
422
const gchar *property_name,
427
g_return_if_fail (GTK_IS_CONTAINER (container));
428
g_return_if_fail (GTK_IS_WIDGET (child));
429
g_return_if_fail (child->parent == GTK_WIDGET (container));
430
g_return_if_fail (property_name != NULL);
431
g_return_if_fail (G_IS_VALUE (value));
433
g_object_ref (container);
434
g_object_ref (child);
435
pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool, property_name,
436
G_OBJECT_TYPE (container), TRUE);
438
g_warning ("%s: container class `%s' has no child property named `%s'",
440
G_OBJECT_TYPE_NAME (container),
442
else if (!(pspec->flags & G_PARAM_READABLE))
443
g_warning ("%s: child property `%s' of container class `%s' is not readable",
446
G_OBJECT_TYPE_NAME (container));
449
GValue *prop_value, tmp_value = { 0, };
451
/* auto-conversion of the callers value type
453
if (G_VALUE_TYPE (value) == G_PARAM_SPEC_VALUE_TYPE (pspec))
455
g_value_reset (value);
458
else if (!g_value_type_transformable (G_PARAM_SPEC_VALUE_TYPE (pspec), G_VALUE_TYPE (value)))
460
g_warning ("can't retrieve child property `%s' of type `%s' as value of type `%s'",
462
g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec)),
463
G_VALUE_TYPE_NAME (value));
464
g_object_unref (child);
465
g_object_unref (container);
470
g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
471
prop_value = &tmp_value;
473
container_get_child_property (container, child, pspec, prop_value);
474
if (prop_value != value)
476
g_value_transform (prop_value, value);
477
g_value_unset (&tmp_value);
480
g_object_unref (child);
481
g_object_unref (container);
485
* gtk_container_child_set_valist:
486
* @container: a #GtkContainer
487
* @child: a widget which is a child of @container
488
* @first_property_name: the name of the first property to set
489
* @var_args: a %NULL-terminated list of property names and values, starting
490
* with @first_prop_name.
492
* Sets one or more child properties for @child and @container.
495
gtk_container_child_set_valist (GtkContainer *container,
497
const gchar *first_property_name,
500
GObjectNotifyQueue *nqueue;
503
g_return_if_fail (GTK_IS_CONTAINER (container));
504
g_return_if_fail (GTK_IS_WIDGET (child));
505
g_return_if_fail (child->parent == GTK_WIDGET (container));
507
g_object_ref (container);
508
g_object_ref (child);
510
nqueue = g_object_notify_queue_freeze (G_OBJECT (child), _gtk_widget_child_property_notify_context);
511
name = first_property_name;
514
GValue value = { 0, };
516
GParamSpec *pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
518
G_OBJECT_TYPE (container),
522
g_warning ("%s: container class `%s' has no child property named `%s'",
524
G_OBJECT_TYPE_NAME (container),
528
if (!(pspec->flags & G_PARAM_WRITABLE))
530
g_warning ("%s: child property `%s' of container class `%s' is not writable",
533
G_OBJECT_TYPE_NAME (container));
536
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
537
G_VALUE_COLLECT (&value, var_args, 0, &error);
540
g_warning ("%s: %s", G_STRLOC, error);
543
/* we purposely leak the value here, it might not be
544
* in a sane state if an error condition occoured
548
container_set_child_property (container, child, pspec, &value, nqueue);
549
g_value_unset (&value);
550
name = va_arg (var_args, gchar*);
552
g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
554
g_object_unref (container);
555
g_object_unref (child);
559
* gtk_container_child_set_property:
560
* @container: a #GtkContainer
561
* @child: a widget which is a child of @container
562
* @property_name: the name of the property to set
563
* @value: the value to set the property to
565
* Sets a child property for @child and @container.
568
gtk_container_child_set_property (GtkContainer *container,
570
const gchar *property_name,
573
GObjectNotifyQueue *nqueue;
576
g_return_if_fail (GTK_IS_CONTAINER (container));
577
g_return_if_fail (GTK_IS_WIDGET (child));
578
g_return_if_fail (child->parent == GTK_WIDGET (container));
579
g_return_if_fail (property_name != NULL);
580
g_return_if_fail (G_IS_VALUE (value));
582
g_object_ref (container);
583
g_object_ref (child);
585
nqueue = g_object_notify_queue_freeze (G_OBJECT (child), _gtk_widget_child_property_notify_context);
586
pspec = g_param_spec_pool_lookup (_gtk_widget_child_property_pool, property_name,
587
G_OBJECT_TYPE (container), TRUE);
589
g_warning ("%s: container class `%s' has no child property named `%s'",
591
G_OBJECT_TYPE_NAME (container),
593
else if (!(pspec->flags & G_PARAM_WRITABLE))
594
g_warning ("%s: child property `%s' of container class `%s' is not writable",
597
G_OBJECT_TYPE_NAME (container));
600
container_set_child_property (container, child, pspec, value, nqueue);
602
g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
603
g_object_unref (container);
604
g_object_unref (child);
608
* gtk_container_add_with_properties:
609
* @container: a #GtkContainer
610
* @widget: a widget to be placed inside @container
611
* @first_prop_name: the name of the first child property to set
612
* @Varargs: a %NULL-terminated list of property names and values, starting
613
* with @first_prop_name.
615
* Adds @widget to @container, setting child properties at the same time.
616
* See gtk_container_add() and gtk_container_child_set() for more details.
619
gtk_container_add_with_properties (GtkContainer *container,
621
const gchar *first_prop_name,
624
g_return_if_fail (GTK_IS_CONTAINER (container));
625
g_return_if_fail (GTK_IS_WIDGET (widget));
626
g_return_if_fail (widget->parent == NULL);
628
g_object_ref (container);
629
g_object_ref (widget);
630
gtk_widget_freeze_child_notify (widget);
632
g_signal_emit (container, container_signals[ADD], 0, widget);
637
va_start (var_args, first_prop_name);
638
gtk_container_child_set_valist (container, widget, first_prop_name, var_args);
642
gtk_widget_thaw_child_notify (widget);
643
g_object_unref (widget);
644
g_object_unref (container);
648
* gtk_container_child_set:
649
* @container: a #GtkContainer
650
* @child: a widget which is a child of @container
651
* @first_prop_name: the name of the first property to set
652
* @Varargs: a %NULL-terminated list of property names and values, starting
653
* with @first_prop_name.
655
* Sets one or more child properties for @child and @container.
658
gtk_container_child_set (GtkContainer *container,
660
const gchar *first_prop_name,
665
g_return_if_fail (GTK_IS_CONTAINER (container));
666
g_return_if_fail (GTK_IS_WIDGET (child));
667
g_return_if_fail (child->parent == GTK_WIDGET (container));
669
va_start (var_args, first_prop_name);
670
gtk_container_child_set_valist (container, child, first_prop_name, var_args);
675
* gtk_container_child_get:
676
* @container: a #GtkContainer
677
* @child: a widget which is a child of @container
678
* @first_prop_name: the name of the first property to get
679
* @Varargs: a %NULL-terminated list of property names and #GValue*,
680
* starting with @first_prop_name.
682
* Gets the values of one or more child properties for @child and @container.
685
gtk_container_child_get (GtkContainer *container,
687
const gchar *first_prop_name,
692
g_return_if_fail (GTK_IS_CONTAINER (container));
693
g_return_if_fail (GTK_IS_WIDGET (child));
694
g_return_if_fail (child->parent == GTK_WIDGET (container));
696
va_start (var_args, first_prop_name);
697
gtk_container_child_get_valist (container, child, first_prop_name, var_args);
702
* gtk_container_class_install_child_property:
703
* @cclass: a #GtkContainerClass
704
* @property_id: the id for the property
705
* @pspec: the #GParamSpec for the property
707
* Installs a child property on a container class.
710
gtk_container_class_install_child_property (GtkContainerClass *cclass,
714
g_return_if_fail (GTK_IS_CONTAINER_CLASS (cclass));
715
g_return_if_fail (G_IS_PARAM_SPEC (pspec));
716
if (pspec->flags & G_PARAM_WRITABLE)
717
g_return_if_fail (cclass->set_child_property != NULL);
718
if (pspec->flags & G_PARAM_READABLE)
719
g_return_if_fail (cclass->get_child_property != NULL);
720
g_return_if_fail (property_id > 0);
721
g_return_if_fail (PARAM_SPEC_PARAM_ID (pspec) == 0); /* paranoid */
722
if (pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY))
723
g_return_if_fail ((pspec->flags & (G_PARAM_CONSTRUCT | G_PARAM_CONSTRUCT_ONLY)) == 0);
725
if (g_param_spec_pool_lookup (_gtk_widget_child_property_pool, pspec->name, G_OBJECT_CLASS_TYPE (cclass), FALSE))
727
g_warning (G_STRLOC ": class `%s' already contains a child property named `%s'",
728
G_OBJECT_CLASS_NAME (cclass),
732
g_param_spec_ref (pspec);
733
g_param_spec_sink (pspec);
734
PARAM_SPEC_SET_PARAM_ID (pspec, property_id);
735
g_param_spec_pool_insert (_gtk_widget_child_property_pool, pspec, G_OBJECT_CLASS_TYPE (cclass));
739
* gtk_container_class_find_child_property:
740
* @cclass: a #GtkContainerClass
741
* @property_name: the name of the child property to find
742
* @returns: the #GParamSpec of the child property or %NULL if @class has no
743
* child property with that name.
745
* Finds a child property of a container class by name.
748
gtk_container_class_find_child_property (GObjectClass *cclass,
749
const gchar *property_name)
751
g_return_val_if_fail (GTK_IS_CONTAINER_CLASS (cclass), NULL);
752
g_return_val_if_fail (property_name != NULL, NULL);
754
return g_param_spec_pool_lookup (_gtk_widget_child_property_pool,
756
G_OBJECT_CLASS_TYPE (cclass),
761
* gtk_container_class_list_child_properties:
762
* @cclass: a #GtkContainerClass
763
* @n_properties: location to return the number of child properties found
764
* @returns: a newly allocated array of #GParamSpec*. The array must be
765
* freed with g_free().
767
* Returns all child properties of a container class.
770
gtk_container_class_list_child_properties (GObjectClass *cclass,
776
g_return_val_if_fail (GTK_IS_CONTAINER_CLASS (cclass), NULL);
778
pspecs = g_param_spec_pool_list (_gtk_widget_child_property_pool,
779
G_OBJECT_CLASS_TYPE (cclass),
788
gtk_container_add_unimplemented (GtkContainer *container,
791
g_warning ("GtkContainerClass::add not implemented for `%s'", g_type_name (G_TYPE_FROM_INSTANCE (container)));
795
gtk_container_remove_unimplemented (GtkContainer *container,
798
g_warning ("GtkContainerClass::remove not implemented for `%s'", g_type_name (G_TYPE_FROM_INSTANCE (container)));
802
gtk_container_init (GtkContainer *container)
804
container->focus_child = NULL;
805
container->border_width = 0;
806
container->need_resize = FALSE;
807
container->resize_mode = GTK_RESIZE_PARENT;
808
container->reallocate_redraws = FALSE;
812
gtk_container_destroy (GtkObject *object)
814
GtkContainer *container = GTK_CONTAINER (object);
816
if (GTK_CONTAINER_RESIZE_PENDING (container))
817
_gtk_container_dequeue_resize_handler (container);
819
/* do this before walking child widgets, to avoid
820
* removing children from focus chain one by one.
822
if (container->has_focus_chain)
823
gtk_container_unset_focus_chain (container);
825
gtk_container_foreach (container, (GtkCallback) gtk_widget_destroy, NULL);
827
if (GTK_OBJECT_CLASS (parent_class)->destroy)
828
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
832
gtk_container_set_property (GObject *object,
837
GtkContainer *container = GTK_CONTAINER (object);
841
case PROP_BORDER_WIDTH:
842
gtk_container_set_border_width (container, g_value_get_uint (value));
844
case PROP_RESIZE_MODE:
845
gtk_container_set_resize_mode (container, g_value_get_enum (value));
848
gtk_container_add (container, GTK_WIDGET (g_value_get_object (value)));
851
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
857
gtk_container_get_property (GObject *object,
862
GtkContainer *container = GTK_CONTAINER (object);
866
case PROP_BORDER_WIDTH:
867
g_value_set_uint (value, container->border_width);
869
case PROP_RESIZE_MODE:
870
g_value_set_enum (value, container->resize_mode);
873
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
879
* gtk_container_set_border_width:
880
* @container: a #GtkContainer
881
* @border_width: amount of blank space to leave <emphasis>outside</emphasis> the container.
882
* Valid values are in the range 0-65535 pixels.
884
* Sets the border width of the container.
886
* The border width of a container is the amount of space to leave
887
* around the outside of the container. The only exception to this is
888
* #GtkWindow; because toplevel windows can't leave space outside,
889
* they leave the space inside. The border is added on all sides of
890
* the container. To add space to only one side, one approach is to
891
* create a #GtkAlignment widget, call gtk_widget_set_usize() to give
892
* it a size, and place it on the side of the container as a spacer.
895
gtk_container_set_border_width (GtkContainer *container,
898
g_return_if_fail (GTK_IS_CONTAINER (container));
900
if (container->border_width != border_width)
902
container->border_width = border_width;
903
g_object_notify (G_OBJECT (container), "border-width");
905
if (GTK_WIDGET_REALIZED (container))
906
gtk_widget_queue_resize (GTK_WIDGET (container));
911
* gtk_container_get_border_width:
912
* @container: a #GtkContainer
914
* Retrieves the border width of the container. See
915
* gtk_container_set_border_width().
917
* Return value: the current border width
920
gtk_container_get_border_width (GtkContainer *container)
922
g_return_val_if_fail (GTK_IS_CONTAINER (container), 0);
924
return container->border_width;
929
* @container: a #GtkContainer
930
* @widget: a widget to be placed inside @container
932
* Adds @widget to @container. Typically used for simple containers
933
* such as #GtkWindow, #GtkFrame, or #GtkButton; for more complicated
934
* layout containers such as #GtkBox or #GtkTable, this function will
935
* pick default packing parameters that may not be correct. So
936
* consider functions such as gtk_box_pack_start() and
937
* gtk_table_attach() as an alternative to gtk_container_add() in
938
* those cases. A widget may be added to only one container at a time;
939
* you can't place the same widget inside two different containers.
942
gtk_container_add (GtkContainer *container,
945
g_return_if_fail (GTK_IS_CONTAINER (container));
946
g_return_if_fail (GTK_IS_WIDGET (widget));
948
if (widget->parent != NULL)
950
g_warning ("Attempting to add a widget with type %s to a container of "
951
"type %s, but the widget is already inside a container of type %s, "
952
"the GTK+ FAQ at http://www.gtk.org/faq/ explains how to reparent a widget.",
953
g_type_name (G_OBJECT_TYPE (widget)),
954
g_type_name (G_OBJECT_TYPE (container)),
955
g_type_name (G_OBJECT_TYPE (widget->parent)));
959
g_signal_emit (container, container_signals[ADD], 0, widget);
963
* gtk_container_remove:
964
* @container: a #GtkContainer
965
* @widget: a current child of @container
967
* Removes @widget from @container. @widget must be inside @container.
968
* Note that @container will own a reference to @widget, and that this
969
* may be the last reference held; so removing a widget from its
970
* container can destroy that widget. If you want to use @widget
971
* again, you need to add a reference to it while it's not inside
972
* a container, using g_object_ref(). If you don't want to use @widget
973
* again it's usually more efficient to simply destroy it directly
974
* using gtk_widget_destroy() since this will remove it from the
975
* container and help break any circular reference count cycles.
978
gtk_container_remove (GtkContainer *container,
981
g_return_if_fail (GTK_IS_CONTAINER (container));
982
g_return_if_fail (GTK_IS_WIDGET (widget));
984
/* When using the deprecated API of the toolbar, it is possible
985
* to legitimately call this function with a widget that is not
986
* a direct child of the container.
988
g_return_if_fail (GTK_IS_TOOLBAR (container) ||
989
widget->parent == GTK_WIDGET (container));
991
g_signal_emit (container, container_signals[REMOVE], 0, widget);
995
_gtk_container_dequeue_resize_handler (GtkContainer *container)
997
g_return_if_fail (GTK_IS_CONTAINER (container));
998
g_return_if_fail (GTK_CONTAINER_RESIZE_PENDING (container));
1000
container_resize_queue = g_slist_remove (container_resize_queue, container);
1001
GTK_PRIVATE_UNSET_FLAG (container, GTK_RESIZE_PENDING);
1005
* gtk_container_set_resize_mode:
1006
* @container: a #GtkContainer.
1007
* @resize_mode: the new resize mode.
1009
* Sets the resize mode for the container.
1011
* The resize mode of a container determines whether a resize request
1012
* will be passed to the container's parent, queued for later execution
1013
* or executed immediately.
1016
gtk_container_set_resize_mode (GtkContainer *container,
1017
GtkResizeMode resize_mode)
1019
g_return_if_fail (GTK_IS_CONTAINER (container));
1020
g_return_if_fail (resize_mode <= GTK_RESIZE_IMMEDIATE);
1022
if (GTK_WIDGET_TOPLEVEL (container) &&
1023
resize_mode == GTK_RESIZE_PARENT)
1025
resize_mode = GTK_RESIZE_QUEUE;
1028
if (container->resize_mode != resize_mode)
1030
container->resize_mode = resize_mode;
1032
gtk_widget_queue_resize (GTK_WIDGET (container));
1033
g_object_notify (G_OBJECT (container), "resize-mode");
1038
* gtk_container_get_resize_mode:
1039
* @container: a #GtkContainer
1041
* Returns the resize mode for the container. See
1042
* gtk_container_set_resize_mode ().
1044
* Return value: the current resize mode
1047
gtk_container_get_resize_mode (GtkContainer *container)
1049
g_return_val_if_fail (GTK_IS_CONTAINER (container), GTK_RESIZE_PARENT);
1051
return container->resize_mode;
1055
* gtk_container_set_reallocate_redraws:
1056
* @container: a #GtkContainer.
1057
* @needs_redraws: the new value for the container's @reallocate_redraws flag.
1059
* Sets the @reallocate_redraws flag of the container to the given value.
1061
* Containers requesting reallocation redraws get automatically
1062
* redrawn if any of their children changed allocation.
1065
gtk_container_set_reallocate_redraws (GtkContainer *container,
1066
gboolean needs_redraws)
1068
g_return_if_fail (GTK_IS_CONTAINER (container));
1070
container->reallocate_redraws = needs_redraws ? TRUE : FALSE;
1073
static GtkContainer*
1074
gtk_container_get_resize_container (GtkContainer *container)
1076
GtkWidget *widget = GTK_WIDGET (container);
1078
while (widget->parent)
1080
widget = widget->parent;
1081
if (GTK_IS_RESIZE_CONTAINER (widget))
1085
return GTK_IS_RESIZE_CONTAINER (widget) ? (GtkContainer*) widget : NULL;
1089
gtk_container_idle_sizer (gpointer data)
1091
GDK_THREADS_ENTER ();
1093
/* we may be invoked with a container_resize_queue of NULL, because
1094
* queue_resize could have been adding an extra idle function while
1095
* the queue still got processed. we better just ignore such case
1096
* than trying to explicitely work around them with some extra flags,
1097
* since it doesn't cause any actual harm.
1099
while (container_resize_queue)
1104
slist = container_resize_queue;
1105
container_resize_queue = slist->next;
1106
widget = slist->data;
1107
g_slist_free_1 (slist);
1109
GTK_PRIVATE_UNSET_FLAG (widget, GTK_RESIZE_PENDING);
1110
gtk_container_check_resize (GTK_CONTAINER (widget));
1113
gdk_window_process_all_updates ();
1115
GDK_THREADS_LEAVE ();
1121
_gtk_container_queue_resize (GtkContainer *container)
1123
GtkContainer *resize_container;
1126
g_return_if_fail (GTK_IS_CONTAINER (container));
1128
widget = GTK_WIDGET (container);
1129
resize_container = gtk_container_get_resize_container (container);
1133
GTK_PRIVATE_SET_FLAG (widget, GTK_ALLOC_NEEDED);
1134
GTK_PRIVATE_SET_FLAG (widget, GTK_REQUEST_NEEDED);
1135
if ((resize_container && widget == GTK_WIDGET (resize_container)) ||
1139
widget = widget->parent;
1142
if (resize_container)
1144
if (GTK_WIDGET_VISIBLE (resize_container) &&
1145
(GTK_WIDGET_TOPLEVEL (resize_container) || GTK_WIDGET_REALIZED (resize_container)))
1147
switch (resize_container->resize_mode)
1149
case GTK_RESIZE_QUEUE:
1150
if (!GTK_CONTAINER_RESIZE_PENDING (resize_container))
1152
GTK_PRIVATE_SET_FLAG (resize_container, GTK_RESIZE_PENDING);
1153
if (container_resize_queue == NULL)
1154
g_idle_add_full (GTK_PRIORITY_RESIZE,
1155
gtk_container_idle_sizer,
1157
container_resize_queue = g_slist_prepend (container_resize_queue, resize_container);
1161
case GTK_RESIZE_IMMEDIATE:
1162
gtk_container_check_resize (resize_container);
1165
case GTK_RESIZE_PARENT:
1166
g_assert_not_reached ();
1172
/* we need to let hidden resize containers know that something
1173
* changed while they where hidden (currently only evaluated by
1176
resize_container->need_resize = TRUE;
1182
gtk_container_check_resize (GtkContainer *container)
1184
g_return_if_fail (GTK_IS_CONTAINER (container));
1186
g_signal_emit (container, container_signals[CHECK_RESIZE], 0);
1190
gtk_container_real_check_resize (GtkContainer *container)
1192
GtkWidget *widget = GTK_WIDGET (container);
1193
GtkRequisition requisition;
1195
gtk_widget_size_request (widget, &requisition);
1197
if (requisition.width > widget->allocation.width ||
1198
requisition.height > widget->allocation.height)
1200
if (GTK_IS_RESIZE_CONTAINER (container))
1201
gtk_widget_size_allocate (GTK_WIDGET (container),
1202
>K_WIDGET (container)->allocation);
1204
gtk_widget_queue_resize (widget);
1208
gtk_container_resize_children (container);
1212
/* The container hasn't changed size but one of its children
1213
* queued a resize request. Which means that the allocation
1214
* is not sufficient for the requisition of some child.
1215
* We've already performed a size request at this point,
1216
* so we simply need to reallocate and let the allocation
1217
* trickle down via GTK_WIDGET_ALLOC_NEEDED flags.
1220
gtk_container_resize_children (GtkContainer *container)
1224
/* resizing invariants:
1225
* toplevels have *always* resize_mode != GTK_RESIZE_PARENT set.
1226
* containers that have an idle sizer pending must be flagged with
1229
g_return_if_fail (GTK_IS_CONTAINER (container));
1231
widget = GTK_WIDGET (container);
1232
gtk_widget_size_allocate (widget, &widget->allocation);
1236
* gtk_container_forall:
1237
* @container: a #GtkContainer
1238
* @callback: a callback
1239
* @callback_data: callback user data
1241
* Invokes @callback on each child of @container, including children
1242
* that are considered "internal" (implementation details of the
1243
* container). "Internal" children generally weren't added by the user
1244
* of the container, but were added by the container implementation
1245
* itself. Most applications should use gtk_container_foreach(),
1246
* rather than gtk_container_forall().
1249
gtk_container_forall (GtkContainer *container,
1250
GtkCallback callback,
1251
gpointer callback_data)
1253
GtkContainerClass *class;
1255
g_return_if_fail (GTK_IS_CONTAINER (container));
1256
g_return_if_fail (callback != NULL);
1258
class = GTK_CONTAINER_GET_CLASS (container);
1261
class->forall (container, TRUE, callback, callback_data);
1265
* gtk_container_foreach:
1266
* @container: a #GtkContainer
1267
* @callback: a callback
1268
* @callback_data: callback user data
1270
* Invokes @callback on each non-internal child of @container. See
1271
* gtk_container_forall() for details on what constitutes an
1272
* "internal" child. Most applications should use
1273
* gtk_container_foreach(), rather than gtk_container_forall().
1276
gtk_container_foreach (GtkContainer *container,
1277
GtkCallback callback,
1278
gpointer callback_data)
1280
GtkContainerClass *class;
1282
g_return_if_fail (GTK_IS_CONTAINER (container));
1283
g_return_if_fail (callback != NULL);
1285
class = GTK_CONTAINER_GET_CLASS (container);
1288
class->forall (container, FALSE, callback, callback_data);
1291
typedef struct _GtkForeachData GtkForeachData;
1292
struct _GtkForeachData
1294
GtkObject *container;
1295
GtkCallbackMarshal callback;
1296
gpointer callback_data;
1300
gtk_container_foreach_unmarshal (GtkWidget *child,
1303
GtkForeachData *fdata = (GtkForeachData*) data;
1306
/* first argument */
1307
args[0].name = NULL;
1308
args[0].type = G_TYPE_FROM_INSTANCE (child);
1309
GTK_VALUE_OBJECT (args[0]) = GTK_OBJECT (child);
1311
/* location for return value */
1312
args[1].name = NULL;
1313
args[1].type = G_TYPE_NONE;
1315
fdata->callback (fdata->container, fdata->callback_data, 1, args);
1319
gtk_container_foreach_full (GtkContainer *container,
1320
GtkCallback callback,
1321
GtkCallbackMarshal marshal,
1322
gpointer callback_data,
1323
GtkDestroyNotify notify)
1325
g_return_if_fail (GTK_IS_CONTAINER (container));
1329
GtkForeachData fdata;
1331
fdata.container = GTK_OBJECT (container);
1332
fdata.callback = marshal;
1333
fdata.callback_data = callback_data;
1335
gtk_container_foreach (container, gtk_container_foreach_unmarshal, &fdata);
1339
g_return_if_fail (callback != NULL);
1341
gtk_container_foreach (container, callback, &callback_data);
1345
notify (callback_data);
1349
gtk_container_set_focus_child (GtkContainer *container,
1352
g_return_if_fail (GTK_IS_CONTAINER (container));
1354
g_return_if_fail (GTK_IS_WIDGET (widget));
1356
g_signal_emit (container, container_signals[SET_FOCUS_CHILD], 0, widget);
1360
* gtk_container_get_children:
1361
* @container: a #GtkContainer.
1363
* Returns the container's non-internal children. See
1364
* gtk_container_forall() for details on what constitutes an "internal" child.
1366
* Return value: a newly-allocated list of the container's non-internal children.
1369
gtk_container_get_children (GtkContainer *container)
1371
GList *children = NULL;
1373
gtk_container_foreach (container,
1374
gtk_container_children_callback,
1377
return g_list_reverse (children);
1381
gtk_container_child_position_callback (GtkWidget *widget,
1382
gpointer client_data)
1388
} *data = client_data;
1391
if (data->child == widget)
1392
data->index = data->i;
1396
gtk_container_child_default_composite_name (GtkContainer *container,
1406
/* fallback implementation */
1410
gtk_container_forall (container,
1411
gtk_container_child_position_callback,
1414
name = g_strdup_printf ("%s-%u",
1415
g_type_name (G_TYPE_FROM_INSTANCE (child)),
1422
_gtk_container_child_composite_name (GtkContainer *container,
1425
g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
1426
g_return_val_if_fail (GTK_IS_WIDGET (child), NULL);
1427
g_return_val_if_fail (child->parent == GTK_WIDGET (container), NULL);
1429
if (GTK_WIDGET_COMPOSITE_CHILD (child))
1431
static GQuark quark_composite_name = 0;
1434
if (!quark_composite_name)
1435
quark_composite_name = g_quark_from_static_string ("gtk-composite-name");
1437
name = g_object_get_qdata (G_OBJECT (child), quark_composite_name);
1440
GtkContainerClass *class;
1442
class = GTK_CONTAINER_GET_CLASS (container);
1443
if (class->composite_name)
1444
name = class->composite_name (container, child);
1447
name = g_strdup (name);
1456
gtk_container_real_set_focus_child (GtkContainer *container,
1459
g_return_if_fail (GTK_IS_CONTAINER (container));
1460
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
1462
if (child != container->focus_child)
1464
if (container->focus_child)
1465
g_object_unref (container->focus_child);
1466
container->focus_child = child;
1467
if (container->focus_child)
1468
g_object_ref (container->focus_child);
1472
/* check for h/v adjustments
1474
if (container->focus_child)
1476
GtkAdjustment *hadj;
1477
GtkAdjustment *vadj;
1478
GtkWidget *focus_child;
1481
hadj = g_object_get_qdata (G_OBJECT (container), hadjustment_key_id);
1482
vadj = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id);
1486
focus_child = container->focus_child;
1487
while (GTK_IS_CONTAINER (focus_child) &&
1488
GTK_CONTAINER (focus_child)->focus_child)
1490
focus_child = GTK_CONTAINER (focus_child)->focus_child;
1493
gtk_widget_translate_coordinates (focus_child, container->focus_child,
1496
x += container->focus_child->allocation.x;
1497
y += container->focus_child->allocation.y;
1500
gtk_adjustment_clamp_page (vadj, y, y + focus_child->allocation.height);
1503
gtk_adjustment_clamp_page (hadj, x, x + focus_child->allocation.width);
1509
get_focus_chain (GtkContainer *container)
1511
return g_object_get_data (G_OBJECT (container), "gtk-container-focus-chain");
1514
/* same as gtk_container_get_children, except it includes internals
1517
gtk_container_get_all_children (GtkContainer *container)
1519
GList *children = NULL;
1521
gtk_container_forall (container,
1522
gtk_container_children_callback,
1529
gtk_container_focus (GtkWidget *widget,
1530
GtkDirectionType direction)
1533
GList *sorted_children;
1535
GtkContainer *container;
1537
g_return_val_if_fail (GTK_IS_CONTAINER (widget), FALSE);
1539
container = GTK_CONTAINER (widget);
1543
if (GTK_WIDGET_CAN_FOCUS (container))
1545
if (!GTK_WIDGET_HAS_FOCUS (container))
1547
gtk_widget_grab_focus (GTK_WIDGET (container));
1553
/* Get a list of the containers children, allowing focus
1554
* chain to override.
1556
if (container->has_focus_chain)
1557
children = g_list_copy (get_focus_chain (container));
1559
children = gtk_container_get_all_children (container);
1561
if (container->has_focus_chain &&
1562
(direction == GTK_DIR_TAB_FORWARD ||
1563
direction == GTK_DIR_TAB_BACKWARD))
1565
sorted_children = g_list_copy (children);
1567
if (direction == GTK_DIR_TAB_BACKWARD)
1568
sorted_children = g_list_reverse (sorted_children);
1571
sorted_children = _gtk_container_focus_sort (container, children, direction, NULL);
1573
return_val = gtk_container_focus_move (container, sorted_children, direction);
1575
g_list_free (sorted_children);
1576
g_list_free (children);
1583
tab_compare (gconstpointer a,
1587
const GtkWidget *child1 = a;
1588
const GtkWidget *child2 = b;
1589
GtkTextDirection text_direction = GPOINTER_TO_INT (data);
1591
gint y1 = child1->allocation.y + child1->allocation.height / 2;
1592
gint y2 = child2->allocation.y + child2->allocation.height / 2;
1596
gint x1 = child1->allocation.x + child1->allocation.width / 2;
1597
gint x2 = child2->allocation.x + child2->allocation.width / 2;
1599
if (text_direction == GTK_TEXT_DIR_RTL)
1600
return (x1 < x2) ? 1 : ((x1 == x2) ? 0 : -1);
1602
return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
1605
return (y1 < y2) ? -1 : 1;
1609
gtk_container_focus_sort_tab (GtkContainer *container,
1611
GtkDirectionType direction,
1612
GtkWidget *old_focus)
1614
GtkTextDirection text_direction = gtk_widget_get_direction (GTK_WIDGET (container));
1615
children = g_list_sort_with_data (children, tab_compare, GINT_TO_POINTER (text_direction));
1617
/* if we are going backwards then reverse the order
1620
if (direction == GTK_DIR_TAB_BACKWARD)
1621
children = g_list_reverse (children);
1626
/* Get coordinates of @widget's allocation with respect to
1627
* allocation of @container.
1630
get_allocation_coords (GtkContainer *container,
1632
GdkRectangle *allocation)
1634
*allocation = widget->allocation;
1636
return gtk_widget_translate_coordinates (widget, GTK_WIDGET (container),
1637
0, 0, &allocation->x, &allocation->y);
1640
/* Look for a child in @children that is intermediate between
1641
* the focus widget and container. This widget, if it exists,
1642
* acts as the starting widget for focus navigation.
1645
find_old_focus (GtkContainer *container,
1648
GList *tmp_list = children;
1651
GtkWidget *child = tmp_list->data;
1652
GtkWidget *widget = child;
1654
while (widget && widget != (GtkWidget *)container)
1656
GtkWidget *parent = widget->parent;
1657
if (parent && ((GtkContainer *)parent)->focus_child != widget)
1666
tmp_list = tmp_list->next;
1673
old_focus_coords (GtkContainer *container,
1674
GdkRectangle *old_focus_rect)
1676
GtkWidget *widget = GTK_WIDGET (container);
1677
GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
1679
if (toplevel && GTK_IS_WINDOW (toplevel) && GTK_WINDOW (toplevel)->focus_widget)
1681
GtkWidget *old_focus = GTK_WINDOW (toplevel)->focus_widget;
1683
return get_allocation_coords (container, old_focus, old_focus_rect);
1689
typedef struct _CompareInfo CompareInfo;
1693
GtkContainer *container;
1700
up_down_compare (gconstpointer a,
1704
GdkRectangle allocation1;
1705
GdkRectangle allocation2;
1706
CompareInfo *compare = data;
1709
get_allocation_coords (compare->container, (GtkWidget *)a, &allocation1);
1710
get_allocation_coords (compare->container, (GtkWidget *)b, &allocation2);
1712
y1 = allocation1.y + allocation1.height / 2;
1713
y2 = allocation2.y + allocation2.height / 2;
1717
gint x1 = abs (allocation1.x + allocation1.width / 2 - compare->x);
1718
gint x2 = abs (allocation2.x + allocation2.width / 2 - compare->x);
1720
if (compare->reverse)
1721
return (x1 < x2) ? 1 : ((x1 == x2) ? 0 : -1);
1723
return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
1726
return (y1 < y2) ? -1 : 1;
1730
gtk_container_focus_sort_up_down (GtkContainer *container,
1732
GtkDirectionType direction,
1733
GtkWidget *old_focus)
1735
CompareInfo compare;
1737
GdkRectangle old_allocation;
1739
compare.container = container;
1740
compare.reverse = (direction == GTK_DIR_UP);
1743
old_focus = find_old_focus (container, children);
1745
if (old_focus && get_allocation_coords (container, old_focus, &old_allocation))
1751
/* Delete widgets from list that don't match minimum criteria */
1753
compare_x1 = old_allocation.x;
1754
compare_x2 = old_allocation.x + old_allocation.width;
1756
if (direction == GTK_DIR_UP)
1757
compare_y = old_allocation.y;
1759
compare_y = old_allocation.y + old_allocation.height;
1761
tmp_list = children;
1764
GtkWidget *child = tmp_list->data;
1765
GList *next = tmp_list->next;
1766
gint child_x1, child_x2;
1767
GdkRectangle child_allocation;
1769
if (child != old_focus)
1771
if (get_allocation_coords (container, child, &child_allocation))
1773
child_x1 = child_allocation.x;
1774
child_x2 = child_allocation.x + child_allocation.width;
1776
if ((child_x2 <= compare_x1 || child_x1 >= compare_x2) /* No horizontal overlap */ ||
1777
(direction == GTK_DIR_DOWN && child_allocation.y + child_allocation.height < compare_y) || /* Not below */
1778
(direction == GTK_DIR_UP && child_allocation.y > compare_y)) /* Not above */
1780
children = g_list_delete_link (children, tmp_list);
1784
children = g_list_delete_link (children, tmp_list);
1790
compare.x = (compare_x1 + compare_x2) / 2;
1791
compare.y = old_allocation.y + old_allocation.height / 2;
1795
/* No old focus widget, need to figure out starting x,y some other way
1797
GtkWidget *widget = GTK_WIDGET (container);
1798
GdkRectangle old_focus_rect;
1800
if (old_focus_coords (container, &old_focus_rect))
1802
compare.x = old_focus_rect.x + old_focus_rect.width / 2;
1806
if (GTK_WIDGET_NO_WINDOW (widget))
1807
compare.x = widget->allocation.x + widget->allocation.width / 2;
1809
compare.x = widget->allocation.width / 2;
1812
if (GTK_WIDGET_NO_WINDOW (widget))
1813
compare.y = (direction == GTK_DIR_DOWN) ? widget->allocation.y : widget->allocation.y + widget->allocation.height;
1815
compare.y = (direction == GTK_DIR_DOWN) ? 0 : + widget->allocation.height;
1818
children = g_list_sort_with_data (children, up_down_compare, &compare);
1820
if (compare.reverse)
1821
children = g_list_reverse (children);
1827
left_right_compare (gconstpointer a,
1831
GdkRectangle allocation1;
1832
GdkRectangle allocation2;
1833
CompareInfo *compare = data;
1836
get_allocation_coords (compare->container, (GtkWidget *)a, &allocation1);
1837
get_allocation_coords (compare->container, (GtkWidget *)b, &allocation2);
1839
x1 = allocation1.x + allocation1.width / 2;
1840
x2 = allocation2.x + allocation2.width / 2;
1844
gint y1 = abs (allocation1.y + allocation1.height / 2 - compare->y);
1845
gint y2 = abs (allocation2.y + allocation2.height / 2 - compare->y);
1847
if (compare->reverse)
1848
return (y1 < y2) ? 1 : ((y1 == y2) ? 0 : -1);
1850
return (y1 < y2) ? -1 : ((y1 == y2) ? 0 : 1);
1853
return (x1 < x2) ? -1 : 1;
1857
gtk_container_focus_sort_left_right (GtkContainer *container,
1859
GtkDirectionType direction,
1860
GtkWidget *old_focus)
1862
CompareInfo compare;
1864
GdkRectangle old_allocation;
1866
compare.container = container;
1867
compare.reverse = (direction == GTK_DIR_LEFT);
1870
old_focus = find_old_focus (container, children);
1872
if (old_focus && get_allocation_coords (container, old_focus, &old_allocation))
1878
/* Delete widgets from list that don't match minimum criteria */
1880
compare_y1 = old_allocation.y;
1881
compare_y2 = old_allocation.y + old_allocation.height;
1883
if (direction == GTK_DIR_LEFT)
1884
compare_x = old_allocation.x;
1886
compare_x = old_allocation.x + old_allocation.width;
1888
tmp_list = children;
1891
GtkWidget *child = tmp_list->data;
1892
GList *next = tmp_list->next;
1893
gint child_y1, child_y2;
1894
GdkRectangle child_allocation;
1896
if (child != old_focus)
1898
if (get_allocation_coords (container, child, &child_allocation))
1900
child_y1 = child_allocation.y;
1901
child_y2 = child_allocation.y + child_allocation.height;
1903
if ((child_y2 <= compare_y1 || child_y1 >= compare_y2) /* No vertical overlap */ ||
1904
(direction == GTK_DIR_RIGHT && child_allocation.x + child_allocation.width < compare_x) || /* Not to left */
1905
(direction == GTK_DIR_LEFT && child_allocation.x > compare_x)) /* Not to right */
1907
children = g_list_delete_link (children, tmp_list);
1911
children = g_list_delete_link (children, tmp_list);
1917
compare.y = (compare_y1 + compare_y2) / 2;
1918
compare.x = old_allocation.x + old_allocation.width / 2;
1922
/* No old focus widget, need to figure out starting x,y some other way
1924
GtkWidget *widget = GTK_WIDGET (container);
1925
GdkRectangle old_focus_rect;
1927
if (old_focus_coords (container, &old_focus_rect))
1929
compare.y = old_focus_rect.y + old_focus_rect.height / 2;
1933
if (GTK_WIDGET_NO_WINDOW (widget))
1934
compare.y = widget->allocation.y + widget->allocation.height / 2;
1936
compare.y = widget->allocation.height / 2;
1939
if (GTK_WIDGET_NO_WINDOW (widget))
1940
compare.x = (direction == GTK_DIR_RIGHT) ? widget->allocation.x : widget->allocation.x + widget->allocation.width;
1942
compare.x = (direction == GTK_DIR_RIGHT) ? 0 : widget->allocation.width;
1945
children = g_list_sort_with_data (children, left_right_compare, &compare);
1947
if (compare.reverse)
1948
children = g_list_reverse (children);
1954
* gtk_container_focus_sort:
1955
* @container: a #GtkContainer
1956
* @children: a list of descendents of @container (they don't
1957
* have to be direct children.
1958
* @direction: focus direction
1959
* @old_focus: widget to use for the starting position, or %NULL
1960
* to determine this automatically.
1961
* [ Note, this argument isn't used for GTK_DIR_TAB_*,
1962
* which is the only @direction we use currently,
1963
* so perhaps this argument should be removed ]
1965
* Sorts @children in the correct order for focusing with
1966
* direction type @direction.
1968
* Return value: a copy of @children, sorted in correct focusing order,
1969
* with children that aren't suitable for focusing in this direction
1973
_gtk_container_focus_sort (GtkContainer *container,
1975
GtkDirectionType direction,
1976
GtkWidget *old_focus)
1978
GList *visible_children = NULL;
1982
if (GTK_WIDGET_REALIZED (children->data))
1983
visible_children = g_list_prepend (visible_children, children->data);
1984
children = children->next;
1989
case GTK_DIR_TAB_FORWARD:
1990
case GTK_DIR_TAB_BACKWARD:
1991
return gtk_container_focus_sort_tab (container, visible_children, direction, old_focus);
1994
return gtk_container_focus_sort_up_down (container, visible_children, direction, old_focus);
1997
return gtk_container_focus_sort_left_right (container, visible_children, direction, old_focus);
2000
g_assert_not_reached ();
2006
gtk_container_focus_move (GtkContainer *container,
2008
GtkDirectionType direction)
2010
GtkWidget *focus_child;
2013
focus_child = container->focus_child;
2017
child = children->data;
2018
children = children->next;
2025
if (focus_child == child)
2029
if (gtk_widget_child_focus (child, direction))
2033
else if (GTK_WIDGET_DRAWABLE (child) &&
2034
gtk_widget_is_ancestor (child, GTK_WIDGET (container)))
2036
if (gtk_widget_child_focus (child, direction))
2046
gtk_container_children_callback (GtkWidget *widget,
2047
gpointer client_data)
2051
children = (GList**) client_data;
2052
*children = g_list_prepend (*children, widget);
2056
chain_widget_destroyed (GtkWidget *widget,
2059
GtkContainer *container;
2062
container = GTK_CONTAINER (user_data);
2064
chain = g_object_get_data (G_OBJECT (container),
2065
"gtk-container-focus-chain");
2067
chain = g_list_remove (chain, widget);
2069
g_signal_handlers_disconnect_by_func (widget,
2070
chain_widget_destroyed,
2073
g_object_set_data (G_OBJECT (container),
2074
I_("gtk-container-focus-chain"),
2079
* gtk_container_set_focus_chain:
2080
* @container: a #GtkContainer.
2081
* @focusable_widgets: the new focus chain.
2083
* Sets a focus chain, overriding the one computed automatically by GTK+.
2085
* In principle each widget in the chain should be a descendant of the
2086
* container, but this is not enforced by this method, since it's allowed
2087
* to set the focus chain before you pack the widgets, or have a widget
2088
* in the chain that isn't always packed. The necessary checks are done
2089
* when the focus chain is actually traversed.
2092
gtk_container_set_focus_chain (GtkContainer *container,
2093
GList *focusable_widgets)
2098
g_return_if_fail (GTK_IS_CONTAINER (container));
2100
if (container->has_focus_chain)
2101
gtk_container_unset_focus_chain (container);
2103
container->has_focus_chain = TRUE;
2106
tmp_list = focusable_widgets;
2107
while (tmp_list != NULL)
2109
g_return_if_fail (GTK_IS_WIDGET (tmp_list->data));
2111
/* In principle each widget in the chain should be a descendant
2112
* of the container, but we don't want to check that here, it's
2113
* expensive and also it's allowed to set the focus chain before
2114
* you pack the widgets, or have a widget in the chain that isn't
2115
* always packed. So we check for ancestor during actual traversal.
2118
chain = g_list_prepend (chain, tmp_list->data);
2120
g_signal_connect (tmp_list->data,
2122
G_CALLBACK (chain_widget_destroyed),
2125
tmp_list = g_list_next (tmp_list);
2128
chain = g_list_reverse (chain);
2130
g_object_set_data (G_OBJECT (container),
2131
I_("gtk-container-focus-chain"),
2136
* gtk_container_get_focus_chain:
2137
* @container: a #GtkContainer
2138
* @focusable_widgets: location to store the focus chain of the
2139
* container, or %NULL. You should free this list
2140
* using g_list_free() when you are done with it, however
2141
* no additional reference count is added to the
2142
* individual widgets in the focus chain.
2144
* Retrieves the focus chain of the container, if one has been
2145
* set explicitly. If no focus chain has been explicitly
2146
* set, GTK+ computes the focus chain based on the positions
2147
* of the children. In that case, GTK+ stores %NULL in
2148
* @focusable_widgets and returns %FALSE.
2150
* Return value: %TRUE if the focus chain of the container
2151
* has been set explicitly.
2154
gtk_container_get_focus_chain (GtkContainer *container,
2155
GList **focus_chain)
2157
g_return_val_if_fail (GTK_IS_CONTAINER (container), FALSE);
2161
if (container->has_focus_chain)
2162
*focus_chain = g_list_copy (get_focus_chain (container));
2164
*focus_chain = NULL;
2167
return container->has_focus_chain;
2171
* gtk_container_unset_focus_chain:
2172
* @container: a #GtkContainer.
2174
* Removes a focus chain explicitly set with gtk_container_set_focus_chain().
2177
gtk_container_unset_focus_chain (GtkContainer *container)
2179
g_return_if_fail (GTK_IS_CONTAINER (container));
2181
if (container->has_focus_chain)
2186
chain = get_focus_chain (container);
2188
container->has_focus_chain = FALSE;
2190
g_object_set_data (G_OBJECT (container),
2191
I_("gtk-container-focus-chain"),
2195
while (tmp_list != NULL)
2197
g_signal_handlers_disconnect_by_func (tmp_list->data,
2198
chain_widget_destroyed,
2201
tmp_list = g_list_next (tmp_list);
2204
g_list_free (chain);
2209
* gtk_container_set_focus_vadjustment:
2210
* @container: a #GtkContainer
2211
* @adjustment: an adjustment which should be adjusted when the focus is moved among the
2212
* descendents of @container
2214
* Hooks up an adjustment to focus handling in a container, so when a child of the
2215
* container is focused, the adjustment is scrolled to show that widget. This function
2216
* sets the vertical alignment. See gtk_scrolled_window_get_vadjustment() for a typical
2217
* way of obtaining the adjustment and gtk_container_set_focus_hadjustment() for setting
2218
* the horizontal adjustment.
2220
* The adjustments have to be in pixel units and in the same coordinate system as the
2221
* allocation for immediate children of the container.
2224
gtk_container_set_focus_vadjustment (GtkContainer *container,
2225
GtkAdjustment *adjustment)
2227
g_return_if_fail (GTK_IS_CONTAINER (container));
2229
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2232
g_object_ref (adjustment);
2234
g_object_set_qdata_full (G_OBJECT (container),
2241
* gtk_container_get_focus_vadjustment:
2242
* @container: a #GtkContainer
2244
* Retrieves the vertical focus adjustment for the container. See
2245
* gtk_container_set_focus_vadjustment ().
2247
* Return value: the vertical focus adjustment, or %NULL if
2248
* none has been set.
2251
gtk_container_get_focus_vadjustment (GtkContainer *container)
2253
GtkAdjustment *vadjustment;
2255
g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
2257
vadjustment = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id);
2263
* gtk_container_set_focus_hadjustment:
2264
* @container: a #GtkContainer
2265
* @adjustment: an adjustment which should be adjusted when the focus is moved among the
2266
* descendents of @container
2268
* Hooks up an adjustment to focus handling in a container, so when a child of the
2269
* container is focused, the adjustment is scrolled to show that widget. This function
2270
* sets the horizontal alignment. See gtk_scrolled_window_get_hadjustment() for a typical
2271
* way of obtaining the adjustment and gtk_container_set_focus_vadjustment() for setting
2272
* the vertical adjustment.
2274
* The adjustments have to be in pixel units and in the same coordinate system as the
2275
* allocation for immediate children of the container.
2278
gtk_container_set_focus_hadjustment (GtkContainer *container,
2279
GtkAdjustment *adjustment)
2281
g_return_if_fail (GTK_IS_CONTAINER (container));
2283
g_return_if_fail (GTK_IS_ADJUSTMENT (adjustment));
2286
g_object_ref (adjustment);
2288
g_object_set_qdata_full (G_OBJECT (container),
2295
* gtk_container_get_focus_hadjustment:
2296
* @container: a #GtkContainer
2298
* Retrieves the horizontal focus adjustment for the container. See
2299
* gtk_container_set_focus_hadjustment ().
2301
* Return value: the horizontal focus adjustment, or %NULL if
2302
* none has been set.
2305
gtk_container_get_focus_hadjustment (GtkContainer *container)
2307
GtkAdjustment *hadjustment;
2309
g_return_val_if_fail (GTK_IS_CONTAINER (container), NULL);
2311
hadjustment = g_object_get_qdata (G_OBJECT (container), hadjustment_key_id);
2318
gtk_container_show_all (GtkWidget *widget)
2320
g_return_if_fail (GTK_IS_CONTAINER (widget));
2322
gtk_container_foreach (GTK_CONTAINER (widget),
2323
(GtkCallback) gtk_widget_show_all,
2325
gtk_widget_show (widget);
2329
gtk_container_hide_all (GtkWidget *widget)
2331
g_return_if_fail (GTK_IS_CONTAINER (widget));
2333
gtk_widget_hide (widget);
2334
gtk_container_foreach (GTK_CONTAINER (widget),
2335
(GtkCallback) gtk_widget_hide_all,
2341
gtk_container_expose_child (GtkWidget *child,
2342
gpointer client_data)
2345
GtkWidget *container;
2346
GdkEventExpose *event;
2347
} *data = client_data;
2349
gtk_container_propagate_expose (GTK_CONTAINER (data->container),
2355
gtk_container_expose (GtkWidget *widget,
2356
GdkEventExpose *event)
2359
GtkWidget *container;
2360
GdkEventExpose *event;
2363
g_return_val_if_fail (GTK_IS_CONTAINER (widget), FALSE);
2364
g_return_val_if_fail (event != NULL, FALSE);
2367
if (GTK_WIDGET_DRAWABLE (widget))
2369
data.container = widget;
2372
gtk_container_forall (GTK_CONTAINER (widget),
2373
gtk_container_expose_child,
2381
gtk_container_map_child (GtkWidget *child,
2382
gpointer client_data)
2384
if (GTK_WIDGET_VISIBLE (child) &&
2385
GTK_WIDGET_CHILD_VISIBLE (child) &&
2386
!GTK_WIDGET_MAPPED (child))
2387
gtk_widget_map (child);
2391
gtk_container_map (GtkWidget *widget)
2393
GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED);
2395
gtk_container_forall (GTK_CONTAINER (widget),
2396
gtk_container_map_child,
2399
if (!GTK_WIDGET_NO_WINDOW (widget))
2400
gdk_window_show (widget->window);
2404
gtk_container_unmap (GtkWidget *widget)
2406
GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED);
2408
if (!GTK_WIDGET_NO_WINDOW (widget))
2409
gdk_window_hide (widget->window);
2411
gtk_container_forall (GTK_CONTAINER (widget),
2412
(GtkCallback)gtk_widget_unmap,
2417
* gtk_container_propagate_expose:
2418
* @container: a #GtkContainer
2419
* @child: a child of @container
2420
* @event: a expose event sent to container
2422
* When a container receives an expose event, it must send synthetic
2423
* expose events to all children that don't have their own #GdkWindows.
2424
* This function provides a convenient way of doing this. A container,
2425
* when it receives an expose event, calls gtk_container_propagate_expose()
2426
* once for each child, passing in the event the container received.
2428
* gtk_container_propagate_expose() takes care of deciding whether
2429
* an expose event needs to be sent to the child, intersecting
2430
* the event's area with the child area, and sending the event.
2432
* In most cases, a container can simply either simply inherit the
2433
* ::expose implementation from #GtkContainer, or, do some drawing
2434
* and then chain to the ::expose implementation from #GtkContainer.
2437
gtk_container_propagate_expose (GtkContainer *container,
2439
GdkEventExpose *event)
2441
GdkEvent *child_event;
2443
g_return_if_fail (GTK_IS_CONTAINER (container));
2444
g_return_if_fail (GTK_IS_WIDGET (child));
2445
g_return_if_fail (event != NULL);
2447
g_assert (child->parent == GTK_WIDGET (container));
2449
if (GTK_WIDGET_DRAWABLE (child) &&
2450
GTK_WIDGET_NO_WINDOW (child) &&
2451
(child->window == event->window))
2453
child_event = gdk_event_new (GDK_EXPOSE);
2454
child_event->expose = *event;
2455
g_object_ref (child_event->expose.window);
2457
child_event->expose.region = gtk_widget_region_intersect (child, event->region);
2458
if (!gdk_region_empty (child_event->expose.region))
2460
gdk_region_get_clipbox (child_event->expose.region, &child_event->expose.area);
2461
gtk_widget_send_expose (child, child_event);
2463
gdk_event_free (child_event);
2467
#define __GTK_CONTAINER_C__
2468
#include "gtkaliasdef.c"