]> Pileus Git - ~andy/gtk/blob - gtk/gtksizegroup.c
d1295d0727b2d58f0437663b2124c6f69bb5c344
[~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 /* GtkBuildable */
136 static void gtk_size_group_buildable_init (GtkBuildableIface *iface);
137 static gboolean gtk_size_group_buildable_custom_tag_start (GtkBuildable  *buildable,
138                                                            GtkBuilder    *builder,
139                                                            GObject       *child,
140                                                            const gchar   *tagname,
141                                                            GMarkupParser *parser,
142                                                            gpointer      *data);
143 static void gtk_size_group_buildable_custom_finished (GtkBuildable  *buildable,
144                                                       GtkBuilder    *builder,
145                                                       GObject       *child,
146                                                       const gchar   *tagname,
147                                                       gpointer       user_data);
148
149 static void
150 mark_widget_unvisited (GtkWidget *widget)
151 {
152   _gtk_widget_set_sizegroup_visited (widget, FALSE);
153 }
154
155 static void
156 add_widget_to_closure (GtkWidget       *widget,
157                        GtkSizeGroupMode mode,
158                        GSList         **widgets)
159 {
160   GSList *tmp_groups, *tmp_widgets;
161   gboolean hidden;
162
163   if (_gtk_widget_get_sizegroup_visited (widget))
164     return;
165
166   *widgets = g_slist_prepend (*widgets, widget);
167   _gtk_widget_set_sizegroup_visited (widget, TRUE);
168   hidden = !gtk_widget_is_visible (widget);
169
170   for (tmp_groups = _gtk_widget_get_sizegroups (widget); tmp_groups; tmp_groups = tmp_groups->next)
171     {
172       GtkSizeGroup        *tmp_group = tmp_groups->data;
173       GtkSizeGroupPrivate *tmp_priv  = tmp_group->priv;
174
175       if (tmp_priv->ignore_hidden && hidden)
176         continue;
177
178       if (tmp_priv->mode != GTK_SIZE_GROUP_BOTH && tmp_priv->mode != mode)
179         continue;
180
181       for (tmp_widgets = tmp_priv->widgets; tmp_widgets; tmp_widgets = tmp_widgets->next)
182         add_widget_to_closure (tmp_widgets->data, mode, widgets);
183     }
184 }
185
186 static GSList *
187 widget_get_size_group_peers (GtkWidget        *widget,
188                              GtkSizeGroupMode  mode)
189 {
190   GSList *result = NULL;
191
192   add_widget_to_closure (widget, mode, &result);
193   g_slist_foreach (result, (GFunc) mark_widget_unvisited, NULL);
194
195   return result;
196 }
197                                      
198 static void
199 real_queue_resize (GtkWidget          *widget,
200                    GtkQueueResizeFlags flags)
201 {
202   GtkWidget *container;
203
204   _gtk_widget_set_alloc_needed (widget, TRUE);
205   _gtk_widget_set_width_request_needed (widget, TRUE);
206   _gtk_widget_set_height_request_needed (widget, TRUE);
207
208   container = gtk_widget_get_parent (widget);
209   if (!container &&
210       gtk_widget_is_toplevel (widget) && GTK_IS_CONTAINER (widget))
211     container = widget;
212
213   if (container)
214     {
215       if (flags & GTK_QUEUE_RESIZE_INVALIDATE_ONLY)
216         _gtk_container_resize_invalidate (GTK_CONTAINER (container));
217       else
218         _gtk_container_queue_resize (GTK_CONTAINER (container));
219     }
220 }
221
222 static void
223 queue_resize_on_widget (GtkWidget          *widget,
224                         gboolean            check_siblings,
225                         GtkQueueResizeFlags flags)
226 {
227   GtkWidget *parent = widget;
228   GSList *tmp_list;
229
230   while (parent)
231     {
232       GSList *widget_groups;
233       GSList *widgets;
234       
235       if (widget == parent && !check_siblings)
236         {
237           real_queue_resize (widget, flags);
238           parent = gtk_widget_get_parent (parent);
239           continue;
240         }
241       
242       widget_groups = _gtk_widget_get_sizegroups (parent);
243       if (!widget_groups)
244         {
245           if (widget == parent)
246             real_queue_resize (widget, flags);
247
248           parent = gtk_widget_get_parent (parent);
249           continue;
250         }
251
252       widgets = widget_get_size_group_peers (parent, GTK_SIZE_GROUP_HORIZONTAL);
253
254       for (tmp_list = widgets; tmp_list; tmp_list = tmp_list->next)
255         {
256           if (tmp_list->data == parent)
257             {
258               if (widget == parent)
259                 real_queue_resize (parent, flags);
260             }
261           else if (tmp_list->data == widget)
262             {
263               g_warning ("A container and its child are part of this SizeGroup");
264             }
265           else
266             queue_resize_on_widget (tmp_list->data, FALSE, flags);
267         }
268       
269       g_slist_free (widgets);
270               
271       widgets = widget_get_size_group_peers (parent, GTK_SIZE_GROUP_VERTICAL);
272
273       for (tmp_list = widgets; tmp_list; tmp_list = tmp_list->next)
274         {
275           if (tmp_list->data == parent)
276             {
277               if (widget == parent)
278                 real_queue_resize (parent, flags);
279             }
280           else if (tmp_list->data == widget)
281             {
282               g_warning ("A container and its child are part of this SizeGroup");
283             }
284           else
285             queue_resize_on_widget (tmp_list->data, FALSE, flags);
286         }
287       
288       g_slist_free (widgets);
289
290       parent = gtk_widget_get_parent (parent);
291     }
292 }
293
294 static void
295 queue_resize_on_group (GtkSizeGroup       *size_group)
296 {
297   GtkSizeGroupPrivate *priv = size_group->priv;
298
299   if (priv->widgets)
300     queue_resize_on_widget (priv->widgets->data, TRUE, 0);
301 }
302
303 static void
304 gtk_size_group_class_init (GtkSizeGroupClass *klass)
305 {
306   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
307
308   gobject_class->set_property = gtk_size_group_set_property;
309   gobject_class->get_property = gtk_size_group_get_property;
310   
311   g_object_class_install_property (gobject_class,
312                                    PROP_MODE,
313                                    g_param_spec_enum ("mode",
314                                                       P_("Mode"),
315                                                       P_("The directions in which the size group affects the requested sizes"
316                                                         " of its component widgets"),
317                                                       GTK_TYPE_SIZE_GROUP_MODE,
318                                                       GTK_SIZE_GROUP_HORIZONTAL,                                                      GTK_PARAM_READWRITE));
319
320   /**
321    * GtkSizeGroup:ignore-hidden:
322    *
323    * If %TRUE, unmapped widgets are ignored when determining 
324    * the size of the group.
325    *
326    * Since: 2.8
327    */
328   g_object_class_install_property (gobject_class,
329                                    PROP_IGNORE_HIDDEN,
330                                    g_param_spec_boolean ("ignore-hidden",
331                                                          P_("Ignore hidden"),
332                                                          P_("If TRUE, unmapped widgets are ignored "
333                                                             "when determining the size of the group"),
334                                                          FALSE,
335                                                          GTK_PARAM_READWRITE));
336
337   g_type_class_add_private (klass, sizeof (GtkSizeGroupPrivate));
338 }
339
340 static void
341 gtk_size_group_init (GtkSizeGroup *size_group)
342 {
343   GtkSizeGroupPrivate *priv;
344
345   size_group->priv = G_TYPE_INSTANCE_GET_PRIVATE (size_group,
346                                                   GTK_TYPE_SIZE_GROUP,
347                                                   GtkSizeGroupPrivate);
348   priv = size_group->priv;
349
350   priv->widgets = NULL;
351   priv->mode = GTK_SIZE_GROUP_HORIZONTAL;
352   priv->ignore_hidden = FALSE;
353 }
354
355 static void
356 gtk_size_group_buildable_init (GtkBuildableIface *iface)
357 {
358   iface->custom_tag_start = gtk_size_group_buildable_custom_tag_start;
359   iface->custom_finished = gtk_size_group_buildable_custom_finished;
360 }
361
362 G_DEFINE_TYPE_WITH_CODE (GtkSizeGroup, gtk_size_group, G_TYPE_OBJECT,
363                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
364                                                 gtk_size_group_buildable_init))
365
366 static void
367 gtk_size_group_set_property (GObject      *object,
368                              guint         prop_id,
369                              const GValue *value,
370                              GParamSpec   *pspec)
371 {
372   GtkSizeGroup *size_group = GTK_SIZE_GROUP (object);
373
374   switch (prop_id)
375     {
376     case PROP_MODE:
377       gtk_size_group_set_mode (size_group, g_value_get_enum (value));
378       break;
379     case PROP_IGNORE_HIDDEN:
380       gtk_size_group_set_ignore_hidden (size_group, g_value_get_boolean (value));
381       break;
382     default:
383       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
384       break;
385     }
386 }
387
388 static void
389 gtk_size_group_get_property (GObject      *object,
390                              guint         prop_id,
391                              GValue       *value,
392                              GParamSpec   *pspec)
393 {
394   GtkSizeGroup *size_group = GTK_SIZE_GROUP (object);
395   GtkSizeGroupPrivate *priv = size_group->priv;
396
397   switch (prop_id)
398     {
399     case PROP_MODE:
400       g_value_set_enum (value, priv->mode);
401       break;
402     case PROP_IGNORE_HIDDEN:
403       g_value_set_boolean (value, priv->ignore_hidden);
404       break;
405     default:
406       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
407       break;
408     }
409 }
410
411 /**
412  * gtk_size_group_new:
413  * @mode: the mode for the new size group.
414  * 
415  * Create a new #GtkSizeGroup.
416  
417  * Return value: a newly created #GtkSizeGroup
418  **/
419 GtkSizeGroup *
420 gtk_size_group_new (GtkSizeGroupMode mode)
421 {
422   GtkSizeGroup *size_group = g_object_new (GTK_TYPE_SIZE_GROUP, NULL);
423   GtkSizeGroupPrivate *priv = size_group->priv;
424
425   priv->mode = mode;
426
427   return size_group;
428 }
429
430 /**
431  * gtk_size_group_set_mode:
432  * @size_group: a #GtkSizeGroup
433  * @mode: the mode to set for the size group.
434  * 
435  * Sets the #GtkSizeGroupMode of the size group. The mode of the size
436  * group determines whether the widgets in the size group should
437  * all have the same horizontal requisition (%GTK_SIZE_GROUP_HORIZONTAL)
438  * all have the same vertical requisition (%GTK_SIZE_GROUP_VERTICAL),
439  * or should all have the same requisition in both directions
440  * (%GTK_SIZE_GROUP_BOTH).
441  **/
442 void
443 gtk_size_group_set_mode (GtkSizeGroup     *size_group,
444                          GtkSizeGroupMode  mode)
445 {
446   GtkSizeGroupPrivate *priv;
447
448   g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
449
450   priv = size_group->priv;
451
452   if (priv->mode != mode)
453     {
454       if (priv->mode != GTK_SIZE_GROUP_NONE)
455         queue_resize_on_group (size_group);
456       priv->mode = mode;
457       if (priv->mode != GTK_SIZE_GROUP_NONE)
458         queue_resize_on_group (size_group);
459
460       g_object_notify (G_OBJECT (size_group), "mode");
461     }
462 }
463
464 /**
465  * gtk_size_group_get_mode:
466  * @size_group: a #GtkSizeGroup
467  * 
468  * Gets the current mode of the size group. See gtk_size_group_set_mode().
469  * 
470  * Return value: the current mode of the size group.
471  **/
472 GtkSizeGroupMode
473 gtk_size_group_get_mode (GtkSizeGroup *size_group)
474 {
475   g_return_val_if_fail (GTK_IS_SIZE_GROUP (size_group), GTK_SIZE_GROUP_BOTH);
476
477   return size_group->priv->mode;
478 }
479
480 /**
481  * gtk_size_group_set_ignore_hidden:
482  * @size_group: a #GtkSizeGroup
483  * @ignore_hidden: whether unmapped widgets should be ignored
484  *   when calculating the size
485  * 
486  * Sets whether unmapped widgets should be ignored when
487  * calculating the size.
488  *
489  * Since: 2.8 
490  */
491 void
492 gtk_size_group_set_ignore_hidden (GtkSizeGroup *size_group,
493                                   gboolean      ignore_hidden)
494 {
495   GtkSizeGroupPrivate *priv;
496
497   g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
498
499   priv = size_group->priv;
500
501   ignore_hidden = ignore_hidden != FALSE;
502
503   if (priv->ignore_hidden != ignore_hidden)
504     {
505       priv->ignore_hidden = ignore_hidden;
506
507       g_object_notify (G_OBJECT (size_group), "ignore-hidden");
508     }
509 }
510
511 /**
512  * gtk_size_group_get_ignore_hidden:
513  * @size_group: a #GtkSizeGroup
514  *
515  * Returns if invisible widgets are ignored when calculating the size.
516  *
517  * Returns: %TRUE if invisible widgets are ignored.
518  *
519  * Since: 2.8
520  */
521 gboolean
522 gtk_size_group_get_ignore_hidden (GtkSizeGroup *size_group)
523 {
524   g_return_val_if_fail (GTK_IS_SIZE_GROUP (size_group), FALSE);
525
526   return size_group->priv->ignore_hidden;
527 }
528
529 static void
530 gtk_size_group_widget_destroyed (GtkWidget    *widget,
531                                  GtkSizeGroup *size_group)
532 {
533   gtk_size_group_remove_widget (size_group, widget);
534 }
535
536 /**
537  * gtk_size_group_add_widget:
538  * @size_group: a #GtkSizeGroup
539  * @widget: the #GtkWidget to add
540  * 
541  * Adds a widget to a #GtkSizeGroup. In the future, the requisition
542  * of the widget will be determined as the maximum of its requisition
543  * and the requisition of the other widgets in the size group.
544  * Whether this applies horizontally, vertically, or in both directions
545  * depends on the mode of the size group. See gtk_size_group_set_mode().
546  *
547  * When the widget is destroyed or no longer referenced elsewhere, it will 
548  * be removed from the size group.
549  */
550 void
551 gtk_size_group_add_widget (GtkSizeGroup     *size_group,
552                            GtkWidget        *widget)
553 {
554   GtkSizeGroupPrivate *priv;
555   GSList *groups;
556   
557   g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
558   g_return_if_fail (GTK_IS_WIDGET (widget));
559
560   priv = size_group->priv;
561
562   groups = _gtk_widget_get_sizegroups (widget);
563
564   if (!g_slist_find (groups, size_group))
565     {
566       _gtk_widget_add_sizegroup (widget, size_group);
567
568       priv->widgets = g_slist_prepend (priv->widgets, widget);
569
570       g_signal_connect (widget, "destroy",
571                         G_CALLBACK (gtk_size_group_widget_destroyed),
572                         size_group);
573
574       g_object_ref (size_group);
575     }
576   
577   queue_resize_on_group (size_group);
578 }
579
580 /**
581  * gtk_size_group_remove_widget:
582  * @size_group: a #GtkSizeGroup
583  * @widget: the #GtkWidget to remove
584  * 
585  * Removes a widget from a #GtkSizeGroup.
586  **/
587 void
588 gtk_size_group_remove_widget (GtkSizeGroup *size_group,
589                               GtkWidget    *widget)
590 {
591   GtkSizeGroupPrivate *priv;
592   
593   g_return_if_fail (GTK_IS_SIZE_GROUP (size_group));
594   g_return_if_fail (GTK_IS_WIDGET (widget));
595
596   priv = size_group->priv;
597
598   g_return_if_fail (g_slist_find (priv->widgets, widget));
599
600   g_signal_handlers_disconnect_by_func (widget,
601                                         gtk_size_group_widget_destroyed,
602                                         size_group);
603   
604   _gtk_widget_remove_sizegroup (widget, size_group);
605
606   priv->widgets = g_slist_remove (priv->widgets, widget);
607   queue_resize_on_group (size_group);
608   gtk_widget_queue_resize (widget);
609
610   g_object_unref (size_group);
611 }
612
613 /**
614  * gtk_size_group_get_widgets:
615  * @size_group: a #GtkSizeGroup
616  * 
617  * Returns the list of widgets associated with @size_group.
618  *
619  * Return value:  (element-type GtkWidget) (transfer none): a #GSList of
620  *   widgets. The list is owned by GTK+ and should not be modified.
621  *
622  * Since: 2.10
623  **/
624 GSList *
625 gtk_size_group_get_widgets (GtkSizeGroup *size_group)
626 {
627   return size_group->priv->widgets;
628 }
629
630 /**
631  * _gtk_size_group_bump_requisition:
632  * @widget: a #GtkWidget
633  * @mode: either %GTK_SIZE_GROUP_HORIZONTAL or %GTK_SIZE_GROUP_VERTICAL, depending
634  *        on the dimension in which to bump the size.
635  * @for_size: Size to request minimum and natural size for
636  * @minimum: a pointer to the widget's minimum size
637  * @natural: a pointer to the widget's natural size
638  *
639  * Refreshes the sizegroup while returning the groups requested
640  * value in the dimension @mode.
641  *
642  * This function is used both to update sizegroup minimum and natural size 
643  * information and widget minimum and natural sizes in multiple passes from 
644  * the size request apis.
645  */
646 void
647 _gtk_size_group_bump_requisition (GtkWidget        *widget,
648                                   GtkSizeGroupMode  mode,
649                                   gint              for_size,
650                                   gint             *minimum,
651                                   gint             *natural)
652 {
653   GSList *widgets;
654   GSList *tmp_list;
655   gint    min_result = 0, nat_result = 0;
656
657   if (!_gtk_widget_get_sizegroups (widget))
658     return;
659
660   widgets = widget_get_size_group_peers (widget, mode);
661
662   g_slist_foreach (widgets, (GFunc)g_object_ref, NULL);
663   
664   for (tmp_list = widgets; tmp_list; tmp_list = tmp_list->next)
665     {
666       GtkWidget *tmp_widget = tmp_list->data;
667       gint min_dimension, nat_dimension;
668
669       if (tmp_widget == widget)
670         {
671           min_dimension = *minimum;
672           nat_dimension = *natural;
673         }
674       else
675         {
676           _gtk_widget_compute_size_for_orientation (tmp_widget, mode, TRUE, for_size, &min_dimension, &nat_dimension);
677         }
678
679       min_result = MAX (min_result, min_dimension);
680       nat_result = MAX (nat_result, nat_dimension);
681     }
682
683   g_slist_foreach (widgets, (GFunc)g_object_unref, NULL);
684
685   g_slist_free (widgets);
686
687   *minimum = min_result;
688   *natural = nat_result;
689 }
690
691 /**
692  * _gtk_size_group_queue_resize:
693  * @widget: a #GtkWidget
694  * 
695  * Queue a resize on a widget, and on all other widgets grouped with this widget.
696  **/
697 void
698 _gtk_size_group_queue_resize (GtkWidget           *widget,
699                               GtkQueueResizeFlags  flags)
700 {
701   queue_resize_on_widget (widget, TRUE, flags);
702 }
703
704 typedef struct {
705   GObject *object;
706   GSList *items;
707 } GSListSubParserData;
708
709 static void
710 size_group_start_element (GMarkupParseContext *context,
711                           const gchar         *element_name,
712                           const gchar        **names,
713                           const gchar        **values,
714                           gpointer            user_data,
715                           GError            **error)
716 {
717   guint i;
718   GSListSubParserData *data = (GSListSubParserData*)user_data;
719
720   if (strcmp (element_name, "widget") == 0)
721     for (i = 0; names[i]; i++)
722       if (strcmp (names[i], "name") == 0)
723         data->items = g_slist_prepend (data->items, g_strdup (values[i]));
724   else if (strcmp (element_name, "widgets") == 0)
725     return;
726   else
727     g_warning ("Unsupported type tag for GtkSizeGroup: %s\n",
728                element_name);
729
730 }
731
732 static const GMarkupParser size_group_parser =
733   {
734     size_group_start_element
735   };
736
737 static gboolean
738 gtk_size_group_buildable_custom_tag_start (GtkBuildable  *buildable,
739                                            GtkBuilder    *builder,
740                                            GObject       *child,
741                                            const gchar   *tagname,
742                                            GMarkupParser *parser,
743                                            gpointer      *data)
744 {
745   GSListSubParserData *parser_data;
746
747   if (child)
748     return FALSE;
749
750   if (strcmp (tagname, "widgets") == 0)
751     {
752       parser_data = g_slice_new0 (GSListSubParserData);
753       parser_data->items = NULL;
754       parser_data->object = G_OBJECT (buildable);
755
756       *parser = size_group_parser;
757       *data = parser_data;
758       return TRUE;
759     }
760
761   return FALSE;
762 }
763
764 static void
765 gtk_size_group_buildable_custom_finished (GtkBuildable  *buildable,
766                                           GtkBuilder    *builder,
767                                           GObject       *child,
768                                           const gchar   *tagname,
769                                           gpointer       user_data)
770 {
771   GSList *l;
772   GSListSubParserData *data;
773   GObject *object;
774
775   if (strcmp (tagname, "widgets"))
776     return;
777   
778   data = (GSListSubParserData*)user_data;
779   data->items = g_slist_reverse (data->items);
780
781   for (l = data->items; l; l = l->next)
782     {
783       object = gtk_builder_get_object (builder, l->data);
784       if (!object)
785         {
786           g_warning ("Unknown object %s specified in sizegroup %s",
787                      (const gchar*)l->data,
788                      gtk_buildable_get_name (GTK_BUILDABLE (data->object)));
789           continue;
790         }
791       gtk_size_group_add_widget (GTK_SIZE_GROUP (data->object),
792                                  GTK_WIDGET (object));
793       g_free (l->data);
794     }
795   g_slist_free (data->items);
796   g_slice_free (GSListSubParserData, data);
797 }