]> Pileus Git - ~andy/gtk/blob - gtk/gtkstatusbar.c
Remove gtktypeutils altogether
[~andy/gtk] / gtk / gtkstatusbar.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  * GtkStatusbar Copyright (C) 1998 Shawn T. Amundson
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, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 /*
22  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
23  * file for a list of people on the GTK+ Team.  See the ChangeLog
24  * files for a list of changes.  These files are distributed with
25  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
26  */
27
28 #include "config.h"
29
30 #include "gtkframe.h"
31 #include "gtklabel.h"
32 #include "gtkmarshalers.h"
33 #include "gtkstatusbar.h"
34 #include "gtkwindow.h"
35 #include "gtkprivate.h"
36 #include "gtkintl.h"
37 #include "gtkbuildable.h"
38 #include "gtktypebuiltins.h"
39
40 /**
41  * SECTION:gtkstatusbar
42  * @title: GtkStatusbar
43  * @short_description: Report messages of minor importance to the user
44  *
45  * A #GtkStatusbar is usually placed along the bottom of an application's
46  * main #GtkWindow. It may provide a regular commentary of the application's
47  * status (as is usually the case in a web browser, for example), or may be
48  * used to simply output a message when the status changes, (when an upload
49  * is complete in an FTP client, for example).
50  *
51  * Status bars in GTK+ maintain a stack of messages. The message at
52  * the top of the each bar's stack is the one that will currently be displayed.
53  *
54  * Any messages added to a statusbar's stack must specify a
55  * <emphasis>context id</emphasis> that is used to uniquely identify
56  * the source of a message. This context id can be generated by
57  * gtk_statusbar_get_context_id(), given a message and the statusbar that
58  * it will be added to. Note that messages are stored in a stack, and when
59  * choosing which message to display, the stack structure is adhered to,
60  * regardless of the context identifier of a message.
61  *
62  * One could say that a statusbar maintains one stack of messages for
63  * display purposes, but allows multiple message producers to maintain
64  * sub-stacks of the messages they produced (via context ids).
65  *
66  * Status bars are created using gtk_statusbar_new().
67  *
68  * Messages are added to the bar's stack with gtk_statusbar_push().
69  *
70  * The message at the top of the stack can be removed using
71  * gtk_statusbar_pop(). A message can be removed from anywhere in the
72  * stack if its message id was recorded at the time it was added. This
73  * is done using gtk_statusbar_remove().
74  */
75 typedef struct _GtkStatusbarMsg GtkStatusbarMsg;
76
77 struct _GtkStatusbarPrivate
78 {
79   GtkWidget     *frame;
80   GtkWidget     *label;
81
82   GSList        *messages;
83   GSList        *keys;
84
85   guint          seq_context_id;
86   guint          seq_message_id;
87 };
88
89
90 struct _GtkStatusbarMsg
91 {
92   gchar *text;
93   guint context_id;
94   guint message_id;
95 };
96
97 enum
98 {
99   SIGNAL_TEXT_PUSHED,
100   SIGNAL_TEXT_POPPED,
101   SIGNAL_LAST
102 };
103
104 static void     gtk_statusbar_buildable_interface_init    (GtkBuildableIface *iface);
105 static GObject *gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
106                                                             GtkBuilder   *builder,
107                                                             const gchar  *childname);
108 static void     gtk_statusbar_update            (GtkStatusbar      *statusbar,
109                                                  guint              context_id,
110                                                  const gchar       *text);
111 static void     gtk_statusbar_realize           (GtkWidget         *widget);
112 static void     gtk_statusbar_destroy           (GtkWidget         *widget);
113 static void     gtk_statusbar_size_allocate     (GtkWidget         *widget,
114                                                  GtkAllocation     *allocation);
115 static void     gtk_statusbar_hierarchy_changed (GtkWidget         *widget,
116                                                  GtkWidget         *previous_toplevel);
117
118
119 static guint              statusbar_signals[SIGNAL_LAST] = { 0 };
120
121 G_DEFINE_TYPE_WITH_CODE (GtkStatusbar, gtk_statusbar, GTK_TYPE_HBOX,
122                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
123                                                 gtk_statusbar_buildable_interface_init));
124
125 static void
126 gtk_statusbar_class_init (GtkStatusbarClass *class)
127 {
128   GObjectClass *gobject_class;
129   GtkWidgetClass *widget_class;
130
131   gobject_class = (GObjectClass *) class;
132   widget_class = (GtkWidgetClass *) class;
133
134   widget_class->realize = gtk_statusbar_realize;
135   widget_class->destroy = gtk_statusbar_destroy;
136   widget_class->size_allocate = gtk_statusbar_size_allocate;
137   widget_class->hierarchy_changed = gtk_statusbar_hierarchy_changed;
138
139   class->text_pushed = gtk_statusbar_update;
140   class->text_popped = gtk_statusbar_update;
141
142   /** 
143    * GtkStatusbar::text-pushed:
144    * @statusbar: the object which received the signal.
145    * @context_id: the context id of the relevant message/statusbar.
146    * @text: the message that was pushed.
147    * 
148    * Is emitted whenever a new message gets pushed onto a statusbar's stack.
149    */
150   statusbar_signals[SIGNAL_TEXT_PUSHED] =
151     g_signal_new (I_("text-pushed"),
152                   G_OBJECT_CLASS_TYPE (class),
153                   G_SIGNAL_RUN_LAST,
154                   G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed),
155                   NULL, NULL,
156                   _gtk_marshal_VOID__UINT_STRING,
157                   G_TYPE_NONE, 2,
158                   G_TYPE_UINT,
159                   G_TYPE_STRING);
160
161   /**
162    * GtkStatusbar::text-popped:
163    * @statusbar: the object which received the signal.
164    * @context_id: the context id of the relevant message/statusbar.
165    * @text: the message that was just popped.
166    *
167    * Is emitted whenever a new message is popped off a statusbar's stack.
168    */
169   statusbar_signals[SIGNAL_TEXT_POPPED] =
170     g_signal_new (I_("text-popped"),
171                   G_OBJECT_CLASS_TYPE (class),
172                   G_SIGNAL_RUN_LAST,
173                   G_STRUCT_OFFSET (GtkStatusbarClass, text_popped),
174                   NULL, NULL,
175                   _gtk_marshal_VOID__UINT_STRING,
176                   G_TYPE_NONE, 2,
177                   G_TYPE_UINT,
178                   G_TYPE_STRING);
179
180   gtk_widget_class_install_style_property (widget_class,
181                                            g_param_spec_enum ("shadow-type",
182                                                               P_("Shadow type"),
183                                                               P_("Style of bevel around the statusbar text"),
184                                                               GTK_TYPE_SHADOW_TYPE,
185                                                               GTK_SHADOW_IN,
186                                                               GTK_PARAM_READABLE));
187
188    g_type_class_add_private (class, sizeof (GtkStatusbarPrivate));
189 }
190
191 static void
192 gtk_statusbar_init (GtkStatusbar *statusbar)
193 {
194   GtkStatusbarPrivate *priv;
195   GtkBox *box = GTK_BOX (statusbar);
196   GtkWidget *message_area;
197   GtkShadowType shadow_type;
198
199   statusbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (statusbar,
200                                                  GTK_TYPE_STATUSBAR,
201                                                  GtkStatusbarPrivate);
202   priv = statusbar->priv;
203
204   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), TRUE);
205
206   gtk_box_set_spacing (box, 2);
207   gtk_box_set_homogeneous (box, FALSE);
208
209   gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
210
211   priv->frame = gtk_frame_new (NULL);
212   gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), shadow_type);
213   gtk_box_pack_start (box, priv->frame, TRUE, TRUE, 0);
214   gtk_widget_show (priv->frame);
215
216   message_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
217   gtk_container_add (GTK_CONTAINER (priv->frame), message_area);
218   gtk_widget_show (message_area);
219
220   priv->label = gtk_label_new ("");
221   gtk_label_set_single_line_mode (GTK_LABEL (priv->label), TRUE);
222   gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
223   gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END);
224   gtk_container_add (GTK_CONTAINER (message_area), priv->label);
225   gtk_widget_show (priv->label);
226
227   priv->seq_context_id = 1;
228   priv->seq_message_id = 1;
229   priv->messages = NULL;
230   priv->keys = NULL;
231 }
232
233 static GtkBuildableIface *parent_buildable_iface;
234
235 static void
236 gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface)
237 {
238   parent_buildable_iface = g_type_interface_peek_parent (iface);
239   iface->get_internal_child = gtk_statusbar_buildable_get_internal_child;
240 }
241
242 static GObject *
243 gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
244                                             GtkBuilder   *builder,
245                                             const gchar  *childname)
246 {
247   GtkStatusbar *statusbar = GTK_STATUSBAR (buildable);
248   GtkStatusbarPrivate *priv = statusbar->priv;
249
250     if (strcmp (childname, "message_area") == 0)
251       return G_OBJECT (gtk_bin_get_child (GTK_BIN (priv->frame)));
252
253     return parent_buildable_iface->get_internal_child (buildable,
254                                                        builder,
255                                                        childname);
256 }
257
258 /**
259  * gtk_statusbar_new:
260  *
261  * Creates a new #GtkStatusbar ready for messages.
262  *
263  * Returns: the new #GtkStatusbar
264  */
265 GtkWidget* 
266 gtk_statusbar_new (void)
267 {
268   return g_object_new (GTK_TYPE_STATUSBAR, NULL);
269 }
270
271 static void
272 gtk_statusbar_update (GtkStatusbar *statusbar,
273                       guint         context_id,
274                       const gchar  *text)
275 {
276   GtkStatusbarPrivate *priv;
277
278   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
279
280   priv = statusbar->priv;
281
282   if (!text)
283     text = "";
284
285   gtk_label_set_text (GTK_LABEL (priv->label), text);
286 }
287
288 /**
289  * gtk_statusbar_get_context_id:
290  * @statusbar: a #GtkStatusbar
291  * @context_description: textual description of what context 
292  *                       the new message is being used in
293  *
294  * Returns a new context identifier, given a description 
295  * of the actual context. Note that the description is 
296  * <emphasis>not</emphasis> shown in the UI.
297  *
298  * Returns: an integer id
299  */
300 guint
301 gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
302                               const gchar  *context_description)
303 {
304   GtkStatusbarPrivate *priv;
305   gchar *string;
306   guint id;
307   
308   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
309   g_return_val_if_fail (context_description != NULL, 0);
310
311   priv = statusbar->priv;
312
313   /* we need to preserve namespaces on object datas */
314   string = g_strconcat ("gtk-status-bar-context:", context_description, NULL);
315
316   id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), string));
317   if (id == 0)
318     {
319       id = priv->seq_context_id++;
320       g_object_set_data_full (G_OBJECT (statusbar), string, GUINT_TO_POINTER (id), NULL);
321       priv->keys = g_slist_prepend (priv->keys, string);
322     }
323   else
324     g_free (string);
325
326   return id;
327 }
328
329 /**
330  * gtk_statusbar_push:
331  * @statusbar: a #GtkStatusbar
332  * @context_id: the message's context id, as returned by
333  *              gtk_statusbar_get_context_id()
334  * @text: the message to add to the statusbar
335  * 
336  * Pushes a new message onto a statusbar's stack.
337  *
338  * Returns: a message id that can be used with 
339  *          gtk_statusbar_remove().
340  */
341 guint
342 gtk_statusbar_push (GtkStatusbar *statusbar,
343                     guint         context_id,
344                     const gchar  *text)
345 {
346   GtkStatusbarPrivate *priv;
347   GtkStatusbarMsg *msg;
348
349   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
350   g_return_val_if_fail (text != NULL, 0);
351
352   priv = statusbar->priv;
353
354   msg = g_slice_new (GtkStatusbarMsg);
355   msg->text = g_strdup (text);
356   msg->context_id = context_id;
357   msg->message_id = priv->seq_message_id++;
358
359   priv->messages = g_slist_prepend (priv->messages, msg);
360
361   g_signal_emit (statusbar,
362                  statusbar_signals[SIGNAL_TEXT_PUSHED],
363                  0,
364                  msg->context_id,
365                  msg->text);
366
367   return msg->message_id;
368 }
369
370 /**
371  * gtk_statusbar_pop:
372  * @statusbar: a #GtkStatusBar
373  * @context_id: a context identifier
374  * 
375  * Removes the first message in the #GtkStatusBar's stack
376  * with the given context id. 
377  *
378  * Note that this may not change the displayed message, if 
379  * the message at the top of the stack has a different 
380  * context id.
381  */
382 void
383 gtk_statusbar_pop (GtkStatusbar *statusbar,
384                    guint         context_id)
385 {
386   GtkStatusbarPrivate *priv;
387   GtkStatusbarMsg *msg;
388
389   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
390
391   priv = statusbar->priv;
392
393   if (priv->messages)
394     {
395       GSList *list;
396
397       for (list = priv->messages; list; list = list->next)
398         {
399           msg = list->data;
400
401           if (msg->context_id == context_id)
402             {
403               priv->messages = g_slist_remove_link (priv->messages,
404                                                          list);
405               g_free (msg->text);
406               g_slice_free (GtkStatusbarMsg, msg);
407               g_slist_free_1 (list);
408               break;
409             }
410         }
411     }
412
413   msg = priv->messages ? priv->messages->data : NULL;
414
415   g_signal_emit (statusbar,
416                  statusbar_signals[SIGNAL_TEXT_POPPED],
417                  0,
418                  (guint) (msg ? msg->context_id : 0),
419                  msg ? msg->text : NULL);
420 }
421
422 /**
423  * gtk_statusbar_remove:
424  * @statusbar: a #GtkStatusBar
425  * @context_id: a context identifier
426  * @message_id: a message identifier, as returned by gtk_statusbar_push()
427  *
428  * Forces the removal of a message from a statusbar's stack. 
429  * The exact @context_id and @message_id must be specified.
430  */
431 void
432 gtk_statusbar_remove (GtkStatusbar *statusbar,
433                       guint        context_id,
434                       guint        message_id)
435 {
436   GtkStatusbarPrivate *priv;
437   GtkStatusbarMsg *msg;
438
439   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
440   g_return_if_fail (message_id > 0);
441
442   priv = statusbar->priv;
443
444   msg = priv->messages ? priv->messages->data : NULL;
445   if (msg)
446     {
447       GSList *list;
448
449       /* care about signal emission if the topmost item is removed */
450       if (msg->context_id == context_id &&
451           msg->message_id == message_id)
452         {
453           gtk_statusbar_pop (statusbar, context_id);
454           return;
455         }
456       
457       for (list = priv->messages; list; list = list->next)
458         {
459           msg = list->data;
460           
461           if (msg->context_id == context_id &&
462               msg->message_id == message_id)
463             {
464               priv->messages = g_slist_remove_link (priv->messages, list);
465               g_free (msg->text);
466               g_slice_free (GtkStatusbarMsg, msg);
467               g_slist_free_1 (list);
468               
469               break;
470             }
471         }
472     }
473 }
474
475 /**
476  * gtk_statusbar_remove_all:
477  * @statusbar: a #GtkStatusBar
478  * @context_id: a context identifier
479  *
480  * Forces the removal of all messages from a statusbar's
481  * stack with the exact @context_id.
482  *
483  * Since: 2.22
484  */
485 void
486 gtk_statusbar_remove_all (GtkStatusbar *statusbar,
487                           guint         context_id)
488 {
489   GtkStatusbarPrivate *priv;
490   GtkStatusbarMsg *msg;
491   GSList *prev, *list;
492
493   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
494
495   priv = statusbar->priv;
496
497   if (priv->messages == NULL)
498     return;
499
500   msg = priv->messages->data;
501
502   /* care about signal emission if the topmost item is removed */
503   if (msg->context_id == context_id)
504     {
505       gtk_statusbar_pop (statusbar, context_id);
506
507       prev = NULL;
508       list = priv->messages;
509     }
510   else
511     {
512       prev = priv->messages;
513       list = prev->next;
514     }
515
516   while (list != NULL)
517     {
518       msg = list->data;
519
520       if (msg->context_id == context_id)
521         {
522           if (prev == NULL)
523             priv->messages = list->next;
524           else
525             prev->next = list->next;
526
527           g_free (msg->text);
528           g_slice_free (GtkStatusbarMsg, msg);
529           g_slist_free_1 (list);
530
531           if (prev == NULL)
532             prev = priv->messages;
533
534           list = prev->next;
535         }
536       else
537         {
538           prev = list;
539           list = prev->next;
540         }
541     }
542 }
543
544 /**
545  * gtk_statusbar_get_message_area:
546  * @statusbar: a #GtkStatusBar
547  *
548  * Retrieves the box containing the label widget.
549  *
550  * Returns: (transfer none): a #GtkBox
551  *
552  * Since: 2.20
553  */
554 GtkWidget*
555 gtk_statusbar_get_message_area (GtkStatusbar *statusbar)
556 {
557   GtkStatusbarPrivate *priv;
558
559   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), NULL);
560
561   priv = statusbar->priv;
562
563   return gtk_bin_get_child (GTK_BIN (priv->frame));
564 }
565
566 static void
567 gtk_statusbar_destroy (GtkWidget *widget)
568 {
569   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
570   GtkStatusbarPrivate *priv = statusbar->priv;
571   GSList *list;
572
573   for (list = priv->messages; list; list = list->next)
574     {
575       GtkStatusbarMsg *msg;
576
577       msg = list->data;
578       g_free (msg->text);
579       g_slice_free (GtkStatusbarMsg, msg);
580     }
581   g_slist_free (priv->messages);
582   priv->messages = NULL;
583
584   for (list = priv->keys; list; list = list->next)
585     g_free (list->data);
586   g_slist_free (priv->keys);
587   priv->keys = NULL;
588
589   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->destroy (widget);
590 }
591
592 /* look for extra children between the frame containing
593  * the label and where we want to draw the resize grip
594  */
595 static gboolean
596 has_extra_children (GtkStatusbar *statusbar)
597 {
598   GtkStatusbarPrivate *priv = statusbar->priv;
599   GtkPackType child_pack_type, frame_pack_type;
600   GtkWidget *child, *frame;
601   GList *l, *children;
602   gboolean retval = FALSE;
603
604   frame = NULL;
605   children = _gtk_box_get_children (GTK_BOX (statusbar));
606   for (l = children; l; l = l->next)
607     {
608       frame = l->data;
609
610       if (frame == priv->frame)
611         break;
612     }
613
614   gtk_box_query_child_packing (GTK_BOX (statusbar), frame,
615                                NULL, NULL, NULL, &frame_pack_type);
616
617   for (l = l->next; l; l = l->next)
618     {
619       child = l->data;
620
621       if (!gtk_widget_get_visible (child))
622         continue;
623
624       gtk_box_query_child_packing (GTK_BOX (statusbar), child,
625                                    NULL, NULL, NULL, &child_pack_type);
626
627       if (frame_pack_type == GTK_PACK_START || child_pack_type == GTK_PACK_END)
628         {
629           retval = TRUE;
630           break;
631         }
632     }
633
634   g_list_free (children);
635
636   return retval;
637 }
638
639 static void
640 gtk_statusbar_size_allocate (GtkWidget     *widget,
641                              GtkAllocation *allocation)
642 {
643   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
644   GtkStatusbarPrivate *priv = statusbar->priv;
645   gboolean extra_children = FALSE;
646   gboolean has_resize_grip = FALSE;
647   GdkRectangle rect;
648   GtkWidget *window;
649   gint x, y;
650   GdkRectangle translated_rect;
651
652   window = gtk_widget_get_toplevel (widget);
653
654   if (GTK_IS_WINDOW (window) &&
655       gtk_window_resize_grip_is_visible (GTK_WINDOW (window)))
656     {
657       gtk_window_get_resize_grip_area (GTK_WINDOW (window), &rect);
658       if (gtk_widget_translate_coordinates (gtk_widget_get_parent (widget),
659                                             window,
660                                             allocation->x,
661                                             allocation->y,
662                                             &x,
663                                             &y))
664         {
665           translated_rect.x = x;
666           translated_rect.y = y;
667           translated_rect.width = allocation->width;
668           translated_rect.height = allocation->height;
669
670           if (gdk_rectangle_intersect (&rect, &translated_rect, NULL))
671             {
672               has_resize_grip = TRUE;
673               extra_children = has_extra_children (statusbar);
674
675               /* If there are extra children, we don't want them to occupy
676                * the space where we draw the resize grip, so we temporarily
677                * shrink the allocation.
678                * If there are no extra children, we want the frame to get
679                * the full allocation, and we fix up the allocation of the
680                * label afterwards to make room for the grip.
681                */
682               if (extra_children)
683                 {
684                   allocation->width -= rect.width;
685                   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
686                     allocation->x += rect.width;
687                 }
688             }
689         }
690     }
691
692   /* chain up normally */
693   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
694
695   if (has_resize_grip)
696     {
697       if (extra_children)
698         {
699           allocation->width += rect.width;
700           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
701             allocation->x -= rect.width;
702
703           gtk_widget_set_allocation (widget, allocation);
704         }
705       else
706         {
707           GtkAllocation child_allocation, frame_allocation;
708           GtkWidget *child;
709
710           /* Use the frame's child instead of statusbar->label directly, in case
711            * the label has been replaced by a container as the frame's child
712            * (and the label reparented into that container).
713            */
714           child = gtk_bin_get_child (GTK_BIN (priv->frame));
715
716           gtk_widget_get_allocation (child, &child_allocation);
717           gtk_widget_get_allocation (priv->frame, &frame_allocation);
718           if (child_allocation.width + rect.width > frame_allocation.width)
719             {
720               /* shrink the label to make room for the grip */
721               *allocation = child_allocation;
722               allocation->width = MAX (1, allocation->width - rect.width);
723               if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
724                 allocation->x += child_allocation.width - allocation->width;
725
726               gtk_widget_size_allocate (child, allocation);
727             }
728         }
729     }
730 }
731
732 static void
733 resize_grip_visible_changed (GObject    *object,
734                              GParamSpec *pspec,
735                              gpointer    user_data)
736 {
737   GtkStatusbar *statusbar = GTK_STATUSBAR (user_data);
738   GtkStatusbarPrivate *priv = statusbar->priv;
739
740   gtk_widget_queue_resize (priv->label);
741   gtk_widget_queue_resize (priv->frame);
742   gtk_widget_queue_resize (GTK_WIDGET (statusbar));
743 }
744
745 static void
746 gtk_statusbar_hierarchy_changed (GtkWidget *widget,
747                                  GtkWidget *previous_toplevel)
748 {
749   GtkWidget *window;
750
751   if (previous_toplevel)
752     g_signal_handlers_disconnect_by_func (previous_toplevel,
753                                           G_CALLBACK (resize_grip_visible_changed),
754                                           widget);
755   window = gtk_widget_get_toplevel (widget);
756   if (GTK_IS_WINDOW (window))
757     g_signal_connect (window, "notify::resize-grip-visible",
758                       G_CALLBACK (resize_grip_visible_changed), widget);
759
760   resize_grip_visible_changed (NULL, NULL, widget);
761 }
762
763 static void
764 gtk_statusbar_realize (GtkWidget *widget)
765 {
766   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize (widget);
767
768   resize_grip_visible_changed (NULL, NULL, widget);
769 }