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