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