]> Pileus Git - ~andy/gtk/blob - gtk/gtksizegroup.c
sizegroup: Don't keep groups around everywhere
[~andy/gtk] / gtk / gtksizegroup.c
1 /* GTK - The GIMP Toolkit
2  * gtksizegroup.c: 
3  * Copyright (C) 2001 Red Hat Software
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "config.h"
20 #include <string.h>
21
22 #include "gtkbuildable.h"
23 #include "gtkcontainer.h"
24 #include "gtkintl.h"
25 #include "gtktypebuiltins.h"
26 #include "gtkprivate.h"
27 #include "gtksizegroup-private.h"
28 #include "gtkwidgetprivate.h"
29 #include "gtkcontainerprivate.h"
30
31
32 /**
33  * SECTION:gtksizegroup
34  * @Short_description: Grouping widgets so they request the same size
35  * @Title: GtkSizeGroup
36  *
37  * #GtkSizeGroup provides a mechanism for grouping a number of widgets
38  * together so they all request the same amount of space.  This is
39  * typically useful when you want a column of widgets to have the same
40  * size, but you can't use a #GtkGrid widget.
41  *
42  * In detail, the size requested for each widget in a #GtkSizeGroup is
43  * the maximum of the sizes that would have been requested for each
44  * widget in the size group if they were not in the size group. The mode
45  * of the size group (see gtk_size_group_set_mode()) determines whether
46  * this applies to the horizontal size, the vertical size, or both sizes.
47  *
48  * Note that size groups only affect the amount of space requested, not
49  * the size that the widgets finally receive. If you want the widgets in
50  * a #GtkSizeGroup to actually be the same size, you need to pack them in
51  * such a way that they get the size they request and not more. For
52  * example, if you are packing your widgets into a table, you would not
53  * include the %GTK_FILL flag.
54  *
55  * #GtkSizeGroup objects are referenced by each widget in the size group,
56  * so once you have added all widgets to a #GtkSizeGroup, you can drop
57  * the initial reference to the size group with g_object_unref(). If the
58  * widgets in the size group are subsequently destroyed, then they will
59  * be removed from the size group and drop their references on the size
60  * group; when all widgets have been removed, the size group will be
61  * freed.
62  *
63  * Widgets can be part of multiple size groups; GTK+ will compute the
64  * horizontal size of a widget from the horizontal requisition of all
65  * widgets that can be reached from the widget by a chain of size groups
66  * of type %GTK_SIZE_GROUP_HORIZONTAL or %GTK_SIZE_GROUP_BOTH, and the
67  * vertical size from the vertical requisition of all widgets that can be
68  * reached from the widget by a chain of size groups of type
69  * %GTK_SIZE_GROUP_VERTICAL or %GTK_SIZE_GROUP_BOTH.
70  *
71  * Note that only non-contextual sizes of every widget are ever consulted
72  * by size groups (since size groups have no knowledge of what size a widget
73  * will be allocated in one dimension, it cannot derive how much height
74  * a widget will receive for a given width). When grouping widgets that
75  * trade height for width in mode %GTK_SIZE_GROUP_VERTICAL or %GTK_SIZE_GROUP_BOTH:
76  * the height for the minimum width will be the requested height for all
77  * widgets in the group. The same is of course true when horizontally grouping
78  * width for height widgets.
79  *
80  * Widgets that trade height-for-width should set a reasonably large minimum width
81  * by way of #GtkLabel:width-chars for instance. Widgets with static sizes as well
82  * as widgets that grow (such as ellipsizing text) need no such considerations.
83  *
84  * <refsect2 id="GtkSizeGroup-BUILDER-UI">
85  * <title>GtkSizeGroup as GtkBuildable</title>
86  * <para>
87  * Size groups can be specified in a UI definition by placing an
88  * &lt;object&gt; element with <literal>class="GtkSizeGroup"</literal>
89  * somewhere in the UI definition. The widgets that belong to the
90  * size group are specified by a &lt;widgets&gt; element that may
91  * contain multiple &lt;widget&gt; elements, one for each member
92  * of the size group. The name attribute gives the id of the widget.
93  *
94  * <example>
95  * <title>A UI definition fragment with GtkSizeGroup</title>
96  * <programlisting><![CDATA[
97  * <object class="GtkSizeGroup">
98  *   <property name="mode">GTK_SIZE_GROUP_HORIZONTAL</property>
99  *   <widgets>
100  *     <widget name="radio1"/>
101  *     <widget name="radio2"/>
102  *   </widgets>
103  * </object>
104  * ]]></programlisting>
105  * </example>
106  * </para>
107  * </refsect2>
108  */
109
110
111 struct _GtkSizeGroupPrivate
112 {
113   GSList         *widgets;
114
115   guint8          mode;
116
117   guint           ignore_hidden : 1;
118 };
119
120 enum {
121   PROP_0,
122   PROP_MODE,
123   PROP_IGNORE_HIDDEN
124 };
125
126 static void gtk_size_group_set_property (GObject      *object,
127                                          guint         prop_id,
128                                          const GValue *value,
129                                          GParamSpec   *pspec);
130 static void gtk_size_group_get_property (GObject      *object,
131                                          guint         prop_id,
132                                          GValue       *value,
133                                          GParamSpec   *pspec);
134
135 static void add_group_to_closure  (GtkSizeGroup      *group,
136                                    GtkSizeGroupMode   mode,
137                                    GSList           **widgets);
138 static void add_widget_to_closure (GtkWidget         *widget,
139                                    GtkSizeGroupMode   mode,
140                                    GSList           **widgets);
141
142 /* GtkBuildable */
143 static void gtk_size_group_buildable_init (GtkBuildableIface *iface);
144 static gboolean gtk_size_group_buildable_custom_tag_start (GtkBuildable  *buildable,
145                                                            GtkBuilder    *builder,
146                                                            GObject       *child,
147                                                            const gchar   *tagname,
148                                                            GMarkupParser *parser,
149                                                            gpointer      *data);
150 static void gtk_size_group_buildable_custom_finished (GtkBuildable  *buildable,
151                                                       GtkBuilder    *builder,
152                                                       GObject       *child,
153                                                       const gchar   *tagname,
154                                                       gpointer       user_data);
155
156 static void
157 mark_widget_unvisited (GtkWidget *widget)
158 {
159   _gtk_widget_set_sizegroup_visited (widget, FALSE);
160 }
161
162 static void
163 add_group_to_closure (GtkSizeGroup    *group,
164                       GtkSizeGroupMode mode,
165                       GSList         **widgets)
166 {
167   GtkSizeGroupPrivate *priv = group->priv;
168   GSList *tmp_widgets;
169   
170   for (tmp_widgets = priv->widgets; tmp_widgets; tmp_widgets = tmp_widgets->next)
171     {
172       GtkWidget *tmp_widget = tmp_widgets->data;
173       
174       add_widget_to_closure (tmp_widget, mode, widgets);
175     }
176 }
177
178 static void
179 add_widget_to_closure (GtkWidget       *widget,
180                        GtkSizeGroupMode mode,
181                        GSList         **widgets)
182 {
183   GSList *tmp_groups;
184   gboolean hidden;
185
186   if (_gtk_widget_get_sizegroup_visited (widget))
187     return;
188
189   *widgets = g_slist_prepend (*widgets, widget);
190   _gtk_widget_set_sizegroup_visited (widget, TRUE);
191   hidden = !gtk_widget_get_mapped (widget);
192
193   for (tmp_groups = _gtk_widget_get_sizegroups (widget); tmp_groups; tmp_groups = tmp_groups->next)
194     {
195       GtkSizeGroup        *tmp_group = tmp_groups->data;
196       GtkSizeGroupPrivate *tmp_priv  = tmp_group->priv;
197
198       if (tmp_priv->ignore_hidden && hidden)
199         continue;
200
201       if (tmp_priv->mode == GTK_SIZE_GROUP_BOTH || tmp_priv->mode == mode)
202         add_group_to_closure (tmp_group, mode, widgets);
203     }
204 }
205
206 static void
207 real_queue_resize (GtkWidget          *widget,
208                    GtkQueueResizeFlags flags)
209 {
210   GtkWidget *container;
211
212   _gtk_widget_set_alloc_needed (widget, TRUE);
213   _gtk_widget_set_width_request_needed (widget, TRUE);
214   _gtk_widget_set_height_request_needed (widget, TRUE);
215
216   container = gtk_widget_get_parent (widget);
217   if (!container &&
218       gtk_widget_is_toplevel (widget) && GTK_IS_CONTAINER (widget))
219     container = widget;
220
221   if (container)
222     {
223       if (flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY)
224         _gtk_container_resize_invalidate (GTK_CONTAINER (container));
225       else
226         _gtk_container_queue_resize (GTK_CONTAINER (container));
227     }
228 }
229
230 static void
231 queue_resize_on_widget (GtkWidget          *widget,
232                         gboolean            check_siblings,
233                         GtkQueueResizeFlags flags)
234 {
235   GtkWidget *parent = widget;
236   GSList *tmp_list;
237
238   while (parent)
239     {
240       GSList *widget_groups;
241       GSList *widgets;
242       
243       if (widget == parent && !check_siblings)
244         {
245           real_queue_resize (widget, flags);
246           parent = gtk_widget_get_parent (parent);
247           continue;
248         }
249       
250       widget_groups = _gtk_widget_get_sizegroups (parent);
251       if (!widget_groups)
252         {
253           if (widget == parent)
254             real_queue_resize (widget, flags);
255
256           parent = gtk_widget_get_parent (parent);
257           continue;
258         }
259
260       widgets = NULL;
261           
262       add_widget_to_closure (parent, GTK_SIZE_GROUP_HORIZONTAL, &widgets);
263       g_slist_foreach (widgets, (GFunc)mark_widget_unvisited, NULL);
264
265       for (tmp_list = widgets; tmp_list; tmp_list = tmp_list->next)
266         {
267           if (tmp_list->data == parent)
268             {
269               if (widget == parent)
270                 real_queue_resize (parent, flags);
271             }
272           else if (tmp_list->data == widget)
273             {
274               g_warning ("A container and its child are part of this SizeGroup");
275             }
276           else
277             queue_resize_on_widget (tmp_list->data, FALSE, flags);
278         }
279       
280       g_slist_free (widgets);
281               
282       widgets = NULL;
283               
284       add_widget_to_closure (parent, GTK_SIZE_GROUP_VERTICAL, &widgets);
285       g_slist_foreach (widgets, (GFunc)mark_widget_unvisited, NULL);
286
287       for (tmp_list = widgets; tmp_list; tmp_list = tmp_list->next)
288         {
289           if (tmp_list->data == parent)
290             {
291               if (widget == parent)
292                 real_queue_resize (parent, flags);
293             }
294           else if (tmp_list->data == widget)
295             {
296               g_warning ("A container and its child are part of this SizeGroup");
297             }
298           else
299             queue_resize_on_widget (tmp_list->data, FALSE, flags);
300         }
301       
302       g_slist_free (widgets);
303
304       parent = gtk_widget_get_parent (parent);
305     }
306 }
307
308 static void
309 queue_resize_on_group (GtkSizeGroup       *size_group)
310 {
311   GtkSizeGroupPrivate *priv = size_group->priv;
312
313   if (priv->widgets)
314     queue_resize_on_widget (priv->widgets->data, TRUE, 0);
315 }
316
317 static void
318 gtk_size_group_class_init (GtkSizeGroupClass *klass)
319 {
320   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
321
322   gobject_class->set_property = gtk_size_group_set_property;
323   gobject_class->get_property = gtk_size_group_get_property;
324   
325   g_object_class_install_property (gobject_class,
326                                    PROP_MODE,
327                                    g_param_spec_enum ("mode",
328                                                       P_("Mode"),
329                                                       P_("The directions in which the size group affects the requested sizes"
330                                                         " of its component widgets"),
331                                                       GTK_TYPE_SIZE_GROUP_MODE,
332                                                       GTK_SIZE_GROUP_HORIZONTAL,                                                      GTK_PARAM_READWRITE));
333
334   /**
335    * GtkSizeGroup:ignore-hidden:
336    *
337    * If %TRUE, unmapped widgets are ignored when determining 
338    * the size of the group.
339    *
340    * Since: 2.8
341    */
342   g_object_class_install_property (gobject_class,
343                                    PROP_IGNORE_HIDDEN,
344                                    g_param_spec_boolean ("ignore-hidden",
345                                                          P_("Ignore hidden"),
346                                                          P_("If TRUE, unmapped widgets are ignored "
347                                                             "when determining the size of the group"),
348                                                          FALSE,
349                                                          GTK_PARAM_READWRITE));
350
351   g_type_class_add_private (klass, sizeof (GtkSizeGroupPrivate));
352 }
353
354 static void
355 gtk_size_group_init (GtkSizeGroup *size_group)
356 {
357   GtkSizeGroupPrivate *priv;
358
359   size_group->priv = G_TYPE_INSTANCE_GET_PRIVATE (size_group,
360                                                   GTK_TYPE_SIZE_GROUP,
361                                                   GtkSizeGroupPrivate);
362   priv = size_group->priv;
363
364   priv->widgets = NULL;
365   priv->mode = GTK_SIZE_GROUP_HORIZONTAL;
366   priv->ignore_hidden = FALSE;
367 }
368
369 static void
370 gtk_size_group_buildable_init (GtkBuildableIface *iface)
371 {
372   iface->custom_tag_start = gtk_size_group_buildable_custom_tag_start;
373   iface->custom_finished = gtk_size_group_buildable_custom_finished;
374 }
375
376 G_DEFINE_TYPE_WITH_CODE (GtkSizeGroup, gtk_size_group, G_TYPE_OBJECT,
377                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
378                                                 gtk_size_group_buildable_init))
379
380 static void
381 gtk_size_group_set_property (GObject      *object,
382                              guint         prop_id,
383                              const GValue *value,
384                              GParamSpec   *pspec)
385 {
386   GtkSizeGroup *size_group = GTK_SIZE_GROUP (object);
387
388   switch (prop_id)
389     {
390     case PROP_MODE:
391       gtk_size_group_set_mode (size_group, g_value_get_enum (value));
392       break;
393     case PROP_IGNORE_HIDDEN:
394       gtk_size_group_set_ignore_hidden (size_group, g_value_get_boolean (value));
395       break;
396     default:
397       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
398       break;
399     }
400 }
401
402 static void
403 gtk_size_group_get_property (GObject      *object,
404                              guint         prop_id,
405                              GValue       *value,
406                              GParamSpec   *pspec)
407 {
408   GtkSizeGroup *size_group = GTK_SIZE_GROUP (object);
409   GtkSizeGroupPrivate *priv = size_group->priv;
410
411   switch (prop_id)
412     {
413     case PROP_MODE:
414       g_value_set_enum (value, priv->mode);
415       break;
416     case PROP_IGNORE_HIDDEN:
417       g_value_set_boolean (value, priv->ignore_hidden);
418       break;
419     default:
420       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
421       break;
422     }
423 }
424
425 /**
426  * gtk_size_group_new:
427  * @mode: the mode for the new size group.
428  * 
429  * Create a new #GtkSizeGroup.
430  
431  * Return value: a newly created #GtkSizeGroup
432  **/
433 GtkSizeGroup *
434 gtk_size_group_new (GtkSizeGroupMode mode)
435 {
436   GtkSizeGroup *size_group = g_object_new (GTK_TYPE_SIZE_GROUP, NULL);
437   GtkSizeGroupPrivate *priv = size_group->priv;
438
439   priv->mode = mode;
440
441   return size_group;
442 }
443
444 /**
445  * gtk_size_group_set_mode:
446  * @size_group: a #GtkSizeGroup
447  * @mode: the mode to set for the size group.
448  * 
449  * Sets the #GtkSizeGroupMode of the size group. The mode of the size
450  * group determines whether the widgets in the size group should
451  * all have the same horizontal requisition (%GTK_SIZE_GROUP_HORIZONTAL)
452  * all have the same vertical requisition (%GTK_SIZE_GROUP_VERTICAL),
453  * or should all have the same requisition in both directions
454  * (%GTK_SIZE_GROUP_BOTH).
455  **/
456 void
457 gtk_size_group_set_mode (GtkSizeGroup     *size_group,
458                          GtkSizeGroupMode  mode)
459 {
460   GtkSizeGroupPrivate *priv;
461
462   g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
463
464   priv = size_group->priv;
465
466   if (priv->mode != mode)
467     {
468       if (priv->mode != GTK_SIZE_GROUP_NONE)
469         queue_resize_on_group (size_group);
470       priv->mode = mode;
471       if (priv->mode != GTK_SIZE_GROUP_NONE)
472         queue_resize_on_group (size_group);
473
474       g_object_notify (G_OBJECT (size_group), "mode");
475     }
476 }
477
478 /**
479  * gtk_size_group_get_mode:
480  * @size_group: a #GtkSizeGroup
481  * 
482  * Gets the current mode of the size group. See gtk_size_group_set_mode().
483  * 
484  * Return value: the current mode of the size group.
485  **/
486 GtkSizeGroupMode
487 gtk_size_group_get_mode (GtkSizeGroup *size_group)
488 {
489   g_return_val_if_fail (GTK_IS_SIZE_GROUP (size_group), GTK_SIZE_GROUP_BOTH);
490
491   return size_group->priv->mode;
492 }
493
494 /**
495  * gtk_size_group_set_ignore_hidden:
496  * @size_group: a #GtkSizeGroup
497  * @ignore_hidden: whether unmapped widgets should be ignored
498  *   when calculating the size
499  * 
500  * Sets whether unmapped widgets should be ignored when
501  * calculating the size.
502  *
503  * Since: 2.8 
504  */
505 void
506 gtk_size_group_set_ignore_hidden (GtkSizeGroup *size_group,
507                                   gboolean      ignore_hidden)
508 {
509   GtkSizeGroupPrivate *priv;
510
511   g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
512
513   priv = size_group->priv;
514
515   ignore_hidden = ignore_hidden != FALSE;
516
517   if (priv->ignore_hidden != ignore_hidden)
518     {
519       priv->ignore_hidden = ignore_hidden;
520
521       g_object_notify (G_OBJECT (size_group), "ignore-hidden");
522     }
523 }
524
525 /**
526  * gtk_size_group_get_ignore_hidden:
527  * @size_group: a #GtkSizeGroup
528  *
529  * Returns if invisible widgets are ignored when calculating the size.
530  *
531  * Returns: %TRUE if invisible widgets are ignored.
532  *
533  * Since: 2.8
534  */
535 gboolean
536 gtk_size_group_get_ignore_hidden (GtkSizeGroup *size_group)
537 {
538   g_return_val_if_fail (GTK_IS_SIZE_GROUP (size_group), FALSE);
539
540   return size_group->priv->ignore_hidden;
541 }
542
543 static void
544 gtk_size_group_widget_destroyed (GtkWidget    *widget,
545                                  GtkSizeGroup *size_group)
546 {
547   gtk_size_group_remove_widget (size_group, widget);
548 }
549
550 /**
551  * gtk_size_group_add_widget:
552  * @size_group: a #GtkSizeGroup
553  * @widget: the #GtkWidget to add
554  * 
555  * Adds a widget to a #GtkSizeGroup. In the future, the requisition
556  * of the widget will be determined as the maximum of its requisition
557  * and the requisition of the other widgets in the size group.
558  * Whether this applies horizontally, vertically, or in both directions
559  * depends on the mode of the size group. See gtk_size_group_set_mode().
560  *
561  * When the widget is destroyed or no longer referenced elsewhere, it will 
562  * be removed from the size group.
563  */
564 void
565 gtk_size_group_add_widget (GtkSizeGroup     *size_group,
566                            GtkWidget        *widget)
567 {
568   GtkSizeGroupPrivate *priv;
569   GSList *groups;
570   
571   g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
572   g_return_if_fail (GTK_IS_WIDGET (widget));
573
574   priv = size_group->priv;
575
576   groups = _gtk_widget_get_sizegroups (widget);
577
578   if (!g_slist_find (groups, size_group))
579     {
580       _gtk_widget_add_sizegroup (widget, size_group);
581
582       priv->widgets = g_slist_prepend (priv->widgets, widget);
583
584       g_signal_connect (widget, "destroy",
585                         G_CALLBACK (gtk_size_group_widget_destroyed),
586                         size_group);
587
588       g_object_ref (size_group);
589     }
590   
591   queue_resize_on_group (size_group);
592 }
593
594 /**
595  * gtk_size_group_remove_widget:
596  * @size_group: a #GtkSizeGroup
597  * @widget: the #GtkWidget to remove
598  * 
599  * Removes a widget from a #GtkSizeGroup.
600  **/
601 void
602 gtk_size_group_remove_widget (GtkSizeGroup *size_group,
603                               GtkWidget    *widget)
604 {
605   GtkSizeGroupPrivate *priv;
606   
607   g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
608   g_return_if_fail (GTK_IS_WIDGET (widget));
609
610   priv = size_group->priv;
611
612   g_return_if_fail (g_slist_find (priv->widgets, widget));
613
614   g_signal_handlers_disconnect_by_func (widget,
615                                         gtk_size_group_widget_destroyed,
616                                         size_group);
617   
618   _gtk_widget_remove_sizegroup (widget, size_group);
619
620   priv->widgets = g_slist_remove (priv->widgets, widget);
621   queue_resize_on_group (size_group);
622   gtk_widget_queue_resize (widget);
623
624   g_object_unref (size_group);
625 }
626
627 /**
628  * gtk_size_group_get_widgets:
629  * @size_group: a #GtkSizeGroup
630  * 
631  * Returns the list of widgets associated with @size_group.
632  *
633  * Return value:  (element-type GtkWidget) (transfer none): a #GSList of
634  *   widgets. The list is owned by GTK+ and should not be modified.
635  *
636  * Since: 2.10
637  **/
638 GSList *
639 gtk_size_group_get_widgets (GtkSizeGroup *size_group)
640 {
641   return size_group->priv->widgets;
642 }
643
644 static void
645 compute_dimension (GtkWidget        *widget,
646                    GtkSizeGroupMode  mode,
647                    gint             *minimum, /* in-out */
648                    gint             *natural) /* in-out */
649 {
650   GSList *widgets = NULL;
651   GSList *tmp_list;
652   gint    min_result = 0, nat_result = 0;
653
654   add_widget_to_closure (widget, mode, &widgets);
655   g_slist_foreach (widgets, (GFunc)mark_widget_unvisited, NULL);
656
657   g_slist_foreach (widgets, (GFunc)g_object_ref, NULL);
658   
659   for (tmp_list = widgets; tmp_list; tmp_list = tmp_list->next)
660     {
661       GtkWidget *tmp_widget = tmp_list->data;
662       gint min_dimension, nat_dimension;
663
664       if (tmp_widget == widget)
665         {
666           min_dimension = *minimum;
667           nat_dimension = *natural;
668         }
669       else
670         {
671           if (mode == GTK_SIZE_GROUP_HORIZONTAL)
672             gtk_widget_get_preferred_width (tmp_widget, &min_dimension, &nat_dimension);
673           else
674             gtk_widget_get_preferred_height (tmp_widget, &min_dimension, &nat_dimension);
675         }
676
677       min_result = MAX (min_result, min_dimension);
678       nat_result = MAX (nat_result, nat_dimension);
679     }
680
681   g_slist_foreach (widgets, (GFunc)g_object_unref, NULL);
682
683   g_slist_free (widgets);
684
685   *minimum = min_result;
686   *natural = nat_result;
687 }
688
689 /**
690  * _gtk_size_group_bump_requisition:
691  * @widget: a #GtkWidget
692  * @mode: either %GTK_SIZE_GROUP_HORIZONTAL or %GTK_SIZE_GROUP_VERTICAL, depending
693  *        on the dimension in which to bump the size.
694  * @minimum: a pointer to the widget's minimum size
695  * @natural: a pointer to the widget's natural size
696  *
697  * Refreshes the sizegroup while returning the groups requested
698  * value in the dimension @mode.
699  *
700  * This function is used both to update sizegroup minimum and natural size 
701  * information and widget minimum and natural sizes in multiple passes from 
702  * the size request apis.
703  */
704 void
705 _gtk_size_group_bump_requisition (GtkWidget        *widget,
706                                   GtkSizeGroupMode  mode,
707                                   gint             *minimum,
708                                   gint             *natural)
709 {
710   if (!_gtk_widget_get_sizegroup_bumping (widget))
711     {
712       /* Avoid recursion here */
713       _gtk_widget_set_sizegroup_bumping (widget, TRUE);
714
715       if (_gtk_widget_get_sizegroups (widget))
716         compute_dimension (widget, mode, minimum, natural);
717
718       _gtk_widget_set_sizegroup_bumping (widget, FALSE);
719     }
720 }
721
722
723
724 /**
725  * _gtk_size_group_queue_resize:
726  * @widget: a #GtkWidget
727  * 
728  * Queue a resize on a widget, and on all other widgets grouped with this widget.
729  **/
730 void
731 _gtk_size_group_queue_resize (GtkWidget           *widget,
732                               GtkQueueResizeFlags  flags)
733 {
734   queue_resize_on_widget (widget, TRUE, flags);
735 }
736
737 typedef struct {
738   GObject *object;
739   GSList *items;
740 } GSListSubParserData;
741
742 static void
743 size_group_start_element (GMarkupParseContext *context,
744                           const gchar         *element_name,
745                           const gchar        **names,
746                           const gchar        **values,
747                           gpointer            user_data,
748                           GError            **error)
749 {
750   guint i;
751   GSListSubParserData *data = (GSListSubParserData*)user_data;
752
753   if (strcmp (element_name, "widget") == 0)
754     for (i = 0; names[i]; i++)
755       if (strcmp (names[i], "name") == 0)
756         data->items = g_slist_prepend (data->items, g_strdup (values[i]));
757   else if (strcmp (element_name, "widgets") == 0)
758     return;
759   else
760     g_warning ("Unsupported type tag for GtkSizeGroup: %s\n",
761                element_name);
762
763 }
764
765 static const GMarkupParser size_group_parser =
766   {
767     size_group_start_element
768   };
769
770 static gboolean
771 gtk_size_group_buildable_custom_tag_start (GtkBuildable  *buildable,
772                                            GtkBuilder    *builder,
773                                            GObject       *child,
774                                            const gchar   *tagname,
775                                            GMarkupParser *parser,
776                                            gpointer      *data)
777 {
778   GSListSubParserData *parser_data;
779
780   if (child)
781     return FALSE;
782
783   if (strcmp (tagname, "widgets") == 0)
784     {
785       parser_data = g_slice_new0 (GSListSubParserData);
786       parser_data->items = NULL;
787       parser_data->object = G_OBJECT (buildable);
788
789       *parser = size_group_parser;
790       *data = parser_data;
791       return TRUE;
792     }
793
794   return FALSE;
795 }
796
797 static void
798 gtk_size_group_buildable_custom_finished (GtkBuildable  *buildable,
799                                           GtkBuilder    *builder,
800                                           GObject       *child,
801                                           const gchar   *tagname,
802                                           gpointer       user_data)
803 {
804   GSList *l;
805   GSListSubParserData *data;
806   GObject *object;
807
808   if (strcmp (tagname, "widgets"))
809     return;
810   
811   data = (GSListSubParserData*)user_data;
812   data->items = g_slist_reverse (data->items);
813
814   for (l = data->items; l; l = l->next)
815     {
816       object = gtk_builder_get_object (builder, l->data);
817       if (!object)
818         {
819           g_warning ("Unknown object %s specified in sizegroup %s",
820                      (const gchar*)l->data,
821                      gtk_buildable_get_name (GTK_BUILDABLE (data->object)));
822           continue;
823         }
824       gtk_size_group_add_widget (GTK_SIZE_GROUP (data->object),
825                                  GTK_WIDGET (object));
826       g_free (l->data);
827     }
828   g_slist_free (data->items);
829   g_slice_free (GSListSubParserData, data);
830 }