]> Pileus Git - ~andy/gtk/blob - gtk/gtkstatusbar.c
Don't install cursors on insensitive widgets. (#358864, Jan Schampera)
[~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 #include "gtkframe.h"
30 #include "gtklabel.h"
31 #include "gtkmarshalers.h"
32 #include "gtkstatusbar.h"
33 #include "gtkwindow.h"
34 #include "gtkprivate.h"
35 #include "gtkintl.h"
36 #include "gtkalias.h"
37
38 typedef struct _GtkStatusbarMsg GtkStatusbarMsg;
39
40 struct _GtkStatusbarMsg
41 {
42   gchar *text;
43   guint context_id;
44   guint message_id;
45 };
46
47 enum
48 {
49   SIGNAL_TEXT_PUSHED,
50   SIGNAL_TEXT_POPPED,
51   SIGNAL_LAST
52 };
53
54 enum 
55 {
56   PROP_ZERO,
57   PROP_HAS_RESIZE_GRIP
58 };
59
60 static void     gtk_statusbar_destroy           (GtkObject         *object);
61 static void     gtk_statusbar_update            (GtkStatusbar      *statusbar,
62                                                  guint              context_id,
63                                                  const gchar       *text);
64 static void     gtk_statusbar_size_allocate     (GtkWidget         *widget,
65                                                  GtkAllocation     *allocation);
66 static void     gtk_statusbar_realize           (GtkWidget         *widget);
67 static void     gtk_statusbar_unrealize         (GtkWidget         *widget);
68 static void     gtk_statusbar_map               (GtkWidget         *widget);
69 static void     gtk_statusbar_unmap             (GtkWidget         *widget);
70 static gboolean gtk_statusbar_button_press      (GtkWidget         *widget,
71                                                  GdkEventButton    *event);
72 static gboolean gtk_statusbar_expose_event      (GtkWidget         *widget,
73                                                  GdkEventExpose    *event);
74 static void     gtk_statusbar_size_request      (GtkWidget         *widget,
75                                                  GtkRequisition    *requisition);
76 static void     gtk_statusbar_size_allocate     (GtkWidget         *widget,
77                                                  GtkAllocation     *allocation);
78 static void     gtk_statusbar_direction_changed (GtkWidget         *widget,
79                                                  GtkTextDirection   prev_dir);
80 static void     gtk_statusbar_state_changed     (GtkWidget        *widget,
81                                                  GtkStateType      previous_state);
82 static void     gtk_statusbar_create_window     (GtkStatusbar      *statusbar);
83 static void     gtk_statusbar_destroy_window    (GtkStatusbar      *statusbar);
84 static void     gtk_statusbar_get_property      (GObject           *object,
85                                                  guint              prop_id,
86                                                  GValue            *value,
87                                                  GParamSpec        *pspec);
88 static void     gtk_statusbar_set_property      (GObject           *object,
89                                                  guint              prop_id,
90                                                  const GValue      *value,
91                                                  GParamSpec        *pspec);
92 static void     label_selectable_changed        (GtkWidget         *label,
93                                                  GParamSpec        *pspec,
94                                                  gpointer           data);
95
96
97 static guint              statusbar_signals[SIGNAL_LAST] = { 0 };
98
99 G_DEFINE_TYPE (GtkStatusbar, gtk_statusbar, GTK_TYPE_HBOX)
100
101 static void
102 gtk_statusbar_class_init (GtkStatusbarClass *class)
103 {
104   GObjectClass *gobject_class;
105   GtkObjectClass *object_class;
106   GtkWidgetClass *widget_class;
107
108   gobject_class = (GObjectClass *) class;
109   object_class = (GtkObjectClass *) class;
110   widget_class = (GtkWidgetClass *) class;
111
112   gobject_class->set_property = gtk_statusbar_set_property;
113   gobject_class->get_property = gtk_statusbar_get_property;
114
115   object_class->destroy = gtk_statusbar_destroy;
116
117   widget_class->realize = gtk_statusbar_realize;
118   widget_class->unrealize = gtk_statusbar_unrealize;
119   widget_class->map = gtk_statusbar_map;
120   widget_class->unmap = gtk_statusbar_unmap;
121   widget_class->button_press_event = gtk_statusbar_button_press;
122   widget_class->expose_event = gtk_statusbar_expose_event;
123   widget_class->size_request = gtk_statusbar_size_request;
124   widget_class->size_allocate = gtk_statusbar_size_allocate;
125   widget_class->direction_changed = gtk_statusbar_direction_changed;
126   widget_class->state_changed = gtk_statusbar_state_changed;
127   
128   class->text_pushed = gtk_statusbar_update;
129   class->text_popped = gtk_statusbar_update;
130   
131   /**
132    * GtkStatusbar:has-resize-grip:
133    *
134    * Whether the statusbar has a grip for resizing the toplevel window.
135    *
136    * Since: 2.4
137    */
138   g_object_class_install_property (gobject_class,
139                                    PROP_HAS_RESIZE_GRIP,
140                                    g_param_spec_boolean ("has-resize-grip",
141                                                          P_("Has Resize Grip"),
142                                                          P_("Whether the statusbar has a grip for resizing the toplevel"),
143                                                          TRUE,
144                                                          GTK_PARAM_READWRITE));
145   statusbar_signals[SIGNAL_TEXT_PUSHED] =
146     g_signal_new (I_("text_pushed"),
147                   G_OBJECT_CLASS_TYPE (class),
148                   G_SIGNAL_RUN_LAST,
149                   G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed),
150                   NULL, NULL,
151                   _gtk_marshal_VOID__UINT_STRING,
152                   G_TYPE_NONE, 2,
153                   G_TYPE_UINT,
154                   G_TYPE_STRING);
155   statusbar_signals[SIGNAL_TEXT_POPPED] =
156     g_signal_new (I_("text_popped"),
157                   G_OBJECT_CLASS_TYPE (class),
158                   G_SIGNAL_RUN_LAST,
159                   G_STRUCT_OFFSET (GtkStatusbarClass, text_popped),
160                   NULL, NULL,
161                   _gtk_marshal_VOID__UINT_STRING,
162                   G_TYPE_NONE, 2,
163                   G_TYPE_UINT,
164                   G_TYPE_STRING);
165
166   gtk_widget_class_install_style_property (widget_class,
167                                            g_param_spec_enum ("shadow-type",
168                                                               P_("Shadow type"),
169                                                               P_("Style of bevel around the statusbar text"),
170                                                               GTK_TYPE_SHADOW_TYPE,
171                                                               GTK_SHADOW_IN,
172                                                               GTK_PARAM_READABLE));
173 }
174
175 static void
176 gtk_statusbar_init (GtkStatusbar *statusbar)
177 {
178   GtkBox *box;
179   GtkShadowType shadow_type;
180   
181   box = GTK_BOX (statusbar);
182
183   box->spacing = 2;
184   box->homogeneous = FALSE;
185
186   statusbar->has_resize_grip = TRUE;
187
188   gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
189   
190   statusbar->frame = gtk_frame_new (NULL);
191   gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
192   gtk_box_pack_start (box, statusbar->frame, TRUE, TRUE, 0);
193   gtk_widget_show (statusbar->frame);
194
195   statusbar->label = gtk_label_new ("");
196   gtk_label_set_single_line_mode (GTK_LABEL (statusbar->label), TRUE);
197   gtk_misc_set_alignment (GTK_MISC (statusbar->label), 0.0, 0.5);
198   g_signal_connect (statusbar->label, "notify::selectable",
199                     G_CALLBACK (label_selectable_changed), statusbar);
200   gtk_label_set_ellipsize (GTK_LABEL (statusbar->label), PANGO_ELLIPSIZE_END);
201   gtk_container_add (GTK_CONTAINER (statusbar->frame), statusbar->label);
202   gtk_widget_show (statusbar->label);
203
204   statusbar->seq_context_id = 1;
205   statusbar->seq_message_id = 1;
206   statusbar->messages = NULL;
207   statusbar->keys = NULL;
208 }
209
210 GtkWidget* 
211 gtk_statusbar_new (void)
212 {
213   return g_object_new (GTK_TYPE_STATUSBAR, NULL);
214 }
215
216 static void
217 gtk_statusbar_update (GtkStatusbar *statusbar,
218                       guint         context_id,
219                       const gchar  *text)
220 {
221   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
222
223   if (!text)
224     text = "";
225
226   gtk_label_set_text (GTK_LABEL (statusbar->label), text);
227 }
228
229 guint
230 gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
231                               const gchar  *context_description)
232 {
233   gchar *string;
234   guint *id;
235   
236   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
237   g_return_val_if_fail (context_description != NULL, 0);
238
239   /* we need to preserve namespaces on object datas */
240   string = g_strconcat ("gtk-status-bar-context:", context_description, NULL);
241
242   id = g_object_get_data (G_OBJECT (statusbar), string);
243   if (!id)
244     {
245       id = g_new (guint, 1);
246       *id = statusbar->seq_context_id++;
247       g_object_set_data_full (G_OBJECT (statusbar), string, id, g_free);
248       statusbar->keys = g_slist_prepend (statusbar->keys, string);
249     }
250   else
251     g_free (string);
252
253   return *id;
254 }
255
256 guint
257 gtk_statusbar_push (GtkStatusbar *statusbar,
258                     guint         context_id,
259                     const gchar  *text)
260 {
261   GtkStatusbarMsg *msg;
262
263   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
264   g_return_val_if_fail (text != NULL, 0);
265
266   msg = g_slice_new (GtkStatusbarMsg);
267   msg->text = g_strdup (text);
268   msg->context_id = context_id;
269   msg->message_id = statusbar->seq_message_id++;
270
271   statusbar->messages = g_slist_prepend (statusbar->messages, msg);
272
273   g_signal_emit (statusbar,
274                  statusbar_signals[SIGNAL_TEXT_PUSHED],
275                  0,
276                  msg->context_id,
277                  msg->text);
278
279   return msg->message_id;
280 }
281
282 void
283 gtk_statusbar_pop (GtkStatusbar *statusbar,
284                    guint         context_id)
285 {
286   GtkStatusbarMsg *msg;
287
288   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
289
290   if (statusbar->messages)
291     {
292       GSList *list;
293
294       for (list = statusbar->messages; list; list = list->next)
295         {
296           msg = list->data;
297
298           if (msg->context_id == context_id)
299             {
300               statusbar->messages = g_slist_remove_link (statusbar->messages,
301                                                          list);
302               g_free (msg->text);
303               g_slice_free (GtkStatusbarMsg, msg);
304               g_slist_free_1 (list);
305               break;
306             }
307         }
308     }
309
310   msg = statusbar->messages ? statusbar->messages->data : NULL;
311
312   g_signal_emit (statusbar,
313                  statusbar_signals[SIGNAL_TEXT_POPPED],
314                  0,
315                  (guint) (msg ? msg->context_id : 0),
316                  msg ? msg->text : NULL);
317 }
318
319 void
320 gtk_statusbar_remove (GtkStatusbar *statusbar,
321                       guint        context_id,
322                       guint        message_id)
323 {
324   GtkStatusbarMsg *msg;
325
326   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
327   g_return_if_fail (message_id > 0);
328
329   msg = statusbar->messages ? statusbar->messages->data : NULL;
330   if (msg)
331     {
332       GSList *list;
333
334       /* care about signal emission if the topmost item is removed */
335       if (msg->context_id == context_id &&
336           msg->message_id == message_id)
337         {
338           gtk_statusbar_pop (statusbar, context_id);
339           return;
340         }
341       
342       for (list = statusbar->messages; list; list = list->next)
343         {
344           msg = list->data;
345           
346           if (msg->context_id == context_id &&
347               msg->message_id == message_id)
348             {
349               statusbar->messages = g_slist_remove_link (statusbar->messages, list);
350               g_free (msg->text);
351               g_slice_free (GtkStatusbarMsg, msg);
352               g_slist_free_1 (list);
353               
354               break;
355             }
356         }
357     }
358 }
359
360 void
361 gtk_statusbar_set_has_resize_grip (GtkStatusbar *statusbar,
362                                    gboolean      setting)
363 {
364   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
365
366   setting = setting != FALSE;
367
368   if (setting != statusbar->has_resize_grip)
369     {
370       statusbar->has_resize_grip = setting;
371       gtk_widget_queue_resize (statusbar->label);
372       gtk_widget_queue_draw (GTK_WIDGET (statusbar));
373
374       if (GTK_WIDGET_REALIZED (statusbar))
375         {
376           if (statusbar->has_resize_grip && statusbar->grip_window == NULL)
377             {
378               gtk_statusbar_create_window (statusbar);
379               if (GTK_WIDGET_MAPPED (statusbar))
380                 gdk_window_show (statusbar->grip_window);
381             }
382           else if (!statusbar->has_resize_grip && statusbar->grip_window != NULL)
383             gtk_statusbar_destroy_window (statusbar);
384         }
385       
386       g_object_notify (G_OBJECT (statusbar), "has-resize-grip");
387     }
388 }
389
390 gboolean
391 gtk_statusbar_get_has_resize_grip (GtkStatusbar *statusbar)
392 {
393   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), FALSE);
394
395   return statusbar->has_resize_grip;
396 }
397
398 static void
399 gtk_statusbar_destroy (GtkObject *object)
400 {
401   GtkStatusbar *statusbar;
402   GSList *list;
403
404   g_return_if_fail (GTK_IS_STATUSBAR (object));
405
406   statusbar = GTK_STATUSBAR (object);
407
408   for (list = statusbar->messages; list; list = list->next)
409     {
410       GtkStatusbarMsg *msg;
411
412       msg = list->data;
413       g_free (msg->text);
414       g_slice_free (GtkStatusbarMsg, msg);
415     }
416   g_slist_free (statusbar->messages);
417   statusbar->messages = NULL;
418
419   for (list = statusbar->keys; list; list = list->next)
420     g_free (list->data);
421   g_slist_free (statusbar->keys);
422   statusbar->keys = NULL;
423
424   GTK_OBJECT_CLASS (gtk_statusbar_parent_class)->destroy (object);
425 }
426
427 static void
428 gtk_statusbar_set_property (GObject      *object, 
429                             guint         prop_id, 
430                             const GValue *value, 
431                             GParamSpec   *pspec)
432 {
433   GtkStatusbar *statusbar = GTK_STATUSBAR (object);
434
435   switch (prop_id) 
436     {
437     case PROP_HAS_RESIZE_GRIP:
438       gtk_statusbar_set_has_resize_grip (statusbar, g_value_get_boolean (value));
439       break;
440     default:
441       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
442       break;
443     }
444 }
445
446 static void
447 gtk_statusbar_get_property (GObject    *object, 
448                             guint       prop_id, 
449                             GValue     *value, 
450                             GParamSpec *pspec)
451 {
452   GtkStatusbar *statusbar = GTK_STATUSBAR (object);
453         
454   switch (prop_id) 
455     {
456     case PROP_HAS_RESIZE_GRIP:
457       g_value_set_boolean (value, statusbar->has_resize_grip);
458       break;
459     default:
460       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
461       break;
462     }
463 }
464
465 static GdkWindowEdge
466 get_grip_edge (GtkStatusbar *statusbar)
467 {
468   GtkWidget *widget = GTK_WIDGET (statusbar);
469
470   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
471     return GDK_WINDOW_EDGE_SOUTH_EAST; 
472   else
473     return GDK_WINDOW_EDGE_SOUTH_WEST; 
474 }
475
476 static void
477 get_grip_rect (GtkStatusbar *statusbar,
478                GdkRectangle *rect)
479 {
480   GtkWidget *widget;
481   gint w, h;
482   
483   widget = GTK_WIDGET (statusbar);
484
485   /* These are in effect the max/default size of the grip. */
486   w = 18;
487   h = 18;
488
489   if (w > widget->allocation.width)
490     w = widget->allocation.width;
491
492   if (h > widget->allocation.height - widget->style->ythickness)
493     h = widget->allocation.height - widget->style->ythickness;
494   
495   rect->width = w;
496   rect->height = h;
497   rect->y = widget->allocation.y + widget->allocation.height - h;
498
499   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
500     rect->x = widget->allocation.x + widget->allocation.width - w;
501   else 
502     rect->x = widget->allocation.x + widget->style->xthickness;
503 }
504
505 static void
506 set_grip_cursor (GtkStatusbar *statusbar)
507 {
508   if (statusbar->has_resize_grip)
509     {
510       GtkWidget *widget = GTK_WIDGET (statusbar);
511       GdkDisplay *display = gtk_widget_get_display (widget);
512       GdkCursorType cursor_type;
513       GdkCursor *cursor;
514       
515       if (GTK_WIDGET_IS_SENSITIVE (widget))
516         {
517           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
518             cursor_type = GDK_BOTTOM_RIGHT_CORNER;
519           else
520             cursor_type = GDK_BOTTOM_LEFT_CORNER;
521
522           cursor = gdk_cursor_new_for_display (display, cursor_type);
523           gdk_window_set_cursor (statusbar->grip_window, cursor);
524           gdk_cursor_unref (cursor);
525         }
526       else
527         gdk_window_set_cursor (statusbar->grip_window, NULL);
528     }
529 }
530
531 static void
532 gtk_statusbar_create_window (GtkStatusbar *statusbar)
533 {
534   GtkWidget *widget;
535   GdkWindowAttr attributes;
536   gint attributes_mask;
537   GdkRectangle rect;
538   
539   g_return_if_fail (GTK_WIDGET_REALIZED (statusbar));
540   g_return_if_fail (statusbar->has_resize_grip);
541   
542   widget = GTK_WIDGET (statusbar);
543
544   get_grip_rect (statusbar, &rect);
545
546   attributes.x = rect.x;
547   attributes.y = rect.y;
548   attributes.width = rect.width;
549   attributes.height = rect.height;
550   attributes.window_type = GDK_WINDOW_CHILD;
551   attributes.wclass = GDK_INPUT_ONLY;
552   attributes.event_mask = gtk_widget_get_events (widget) |
553     GDK_BUTTON_PRESS_MASK;
554
555   attributes_mask = GDK_WA_X | GDK_WA_Y;
556
557   statusbar->grip_window = gdk_window_new (widget->window,
558                                            &attributes, attributes_mask);
559
560   gdk_window_set_user_data (statusbar->grip_window, widget);
561
562   set_grip_cursor (statusbar);
563 }
564
565 static void
566 gtk_statusbar_direction_changed (GtkWidget        *widget,
567                                  GtkTextDirection  prev_dir)
568 {
569   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
570
571   set_grip_cursor (statusbar);
572 }
573
574 static void
575 gtk_statusbar_state_changed (GtkWidget    *widget,
576                              GtkStateType  previous_state)   
577 {
578   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
579
580   set_grip_cursor (statusbar);
581 }
582
583 static void
584 gtk_statusbar_destroy_window (GtkStatusbar *statusbar)
585 {
586   gdk_window_set_user_data (statusbar->grip_window, NULL);
587   gdk_window_destroy (statusbar->grip_window);
588   statusbar->grip_window = NULL;
589 }
590
591 static void
592 gtk_statusbar_realize (GtkWidget *widget)
593 {
594   GtkStatusbar *statusbar;
595
596   statusbar = GTK_STATUSBAR (widget);
597   
598   (* GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize) (widget);
599
600   if (statusbar->has_resize_grip)
601     gtk_statusbar_create_window (statusbar);
602 }
603
604 static void
605 gtk_statusbar_unrealize (GtkWidget *widget)
606 {
607   GtkStatusbar *statusbar;
608
609   statusbar = GTK_STATUSBAR (widget);
610
611   if (statusbar->grip_window)
612     gtk_statusbar_destroy_window (statusbar);
613   
614   (* GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unrealize) (widget);
615 }
616
617 static void
618 gtk_statusbar_map (GtkWidget *widget)
619 {
620   GtkStatusbar *statusbar;
621
622   statusbar = GTK_STATUSBAR (widget);
623   
624   (* GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->map) (widget);
625   
626   if (statusbar->grip_window)
627     gdk_window_show (statusbar->grip_window);
628 }
629
630 static void
631 gtk_statusbar_unmap (GtkWidget *widget)
632 {
633   GtkStatusbar *statusbar;
634
635   statusbar = GTK_STATUSBAR (widget);
636
637   if (statusbar->grip_window)
638     gdk_window_hide (statusbar->grip_window);
639   
640   (* GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unmap) (widget);
641 }
642
643 static gboolean
644 gtk_statusbar_button_press (GtkWidget      *widget,
645                             GdkEventButton *event)
646 {
647   GtkStatusbar *statusbar;
648   GtkWidget *ancestor;
649   GdkWindowEdge edge;
650   
651   statusbar = GTK_STATUSBAR (widget);
652   
653   if (!statusbar->has_resize_grip ||
654       event->type != GDK_BUTTON_PRESS ||
655       event->window != statusbar->grip_window)
656     return FALSE;
657   
658   ancestor = gtk_widget_get_toplevel (widget);
659
660   if (!GTK_IS_WINDOW (ancestor))
661     return FALSE;
662
663   edge = get_grip_edge (statusbar);
664
665   if (event->button == 1)
666     gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
667                                   edge,
668                                   event->button,
669                                   event->x_root, event->y_root,
670                                   event->time);
671   else if (event->button == 2)
672     gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
673                                 event->button,
674                                 event->x_root, event->y_root,
675                                 event->time);
676   else
677     return FALSE;
678   
679   return TRUE;
680 }
681
682 static gboolean
683 gtk_statusbar_expose_event (GtkWidget      *widget,
684                             GdkEventExpose *event)
685 {
686   GtkStatusbar *statusbar;
687   GdkRectangle rect;
688   
689   statusbar = GTK_STATUSBAR (widget);
690
691   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->expose_event (widget, event);
692
693   if (statusbar->has_resize_grip)
694     {
695       GdkWindowEdge edge;
696       
697       edge = get_grip_edge (statusbar);
698
699       get_grip_rect (statusbar, &rect);
700
701       gtk_paint_resize_grip (widget->style,
702                              widget->window,
703                              GTK_WIDGET_STATE (widget),
704                              NULL,
705                              widget,
706                              "statusbar",
707                              edge,
708                              rect.x, rect.y,
709                              /* don't draw grip over the frame, though you
710                               * can click on the frame.
711                               */
712                              rect.width - widget->style->xthickness,
713                              rect.height - widget->style->ythickness);
714     }
715
716   return FALSE;
717 }
718
719 static void
720 gtk_statusbar_size_request (GtkWidget      *widget,
721                             GtkRequisition *requisition)
722 {
723   GtkStatusbar *statusbar;
724   GtkShadowType shadow_type;
725   
726   statusbar = GTK_STATUSBAR (widget);
727
728   gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);  
729   gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
730   
731   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_request (widget, requisition);
732 }
733
734 /* look for extra children between the frame containing
735  * the label and where we want to draw the resize grip 
736  */
737 static gboolean
738 has_extra_children (GtkStatusbar *statusbar)
739 {
740   GList *l;
741   GtkBoxChild *child, *frame;
742
743   frame = NULL;
744   for (l = GTK_BOX (statusbar)->children; l; l = l->next)
745     {
746       frame = l->data;
747
748       if (frame->widget == statusbar->frame)
749         break;
750     }
751   
752   for (l = l->next; l; l = l->next)
753     {
754       child = l->data;
755
756       if (!GTK_WIDGET_VISIBLE (child->widget))
757         continue;
758
759       if (frame->pack == GTK_PACK_START || child->pack == GTK_PACK_END)
760         return TRUE;
761     }
762
763   return FALSE;
764 }
765
766 static void
767 gtk_statusbar_size_allocate  (GtkWidget     *widget,
768                               GtkAllocation *allocation)
769 {
770   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
771   gboolean extra_children = FALSE;
772   GdkRectangle rect;
773
774   if (statusbar->has_resize_grip)
775     {
776       widget->allocation = *allocation;
777       get_grip_rect (statusbar, &rect);    
778       
779       extra_children = has_extra_children (statusbar);
780       
781       /* If there are extra children, we don't want them to occupy
782        * the space where we draw the resize grip, so we temporarily
783        * shrink the allocation.
784        * If there are no extra children, we want the frame to get
785        * the full allocation, and we fix up the allocation of the
786        * label afterwards to make room for the grip.
787        */
788       if (extra_children)
789         {
790           allocation->width -= rect.width;
791           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
792             allocation->x += rect.width;
793         }
794     }
795
796   /* chain up normally */
797   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
798
799   if (statusbar->has_resize_grip)
800     {
801       if (statusbar->grip_window)
802         {
803           gdk_window_raise (statusbar->grip_window);
804           gdk_window_move_resize (statusbar->grip_window,
805                                   rect.x, rect.y,
806                                   rect.width, rect.height);
807         }
808
809       if (extra_children) 
810         {
811           allocation->width += rect.width;
812           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
813             allocation->x -= rect.width;
814           
815           widget->allocation = *allocation;
816         }
817       else
818         {
819           GtkWidget *child;
820
821           /* Use the frame's child instead of statusbar->label directly, in case
822            * the label has been replaced by a container as the frame's child
823            * (and the label reparented into that container).
824            */
825           child = gtk_bin_get_child (GTK_BIN (statusbar->frame));
826
827           if (child->allocation.width + rect.width > statusbar->frame->allocation.width)
828             {
829               /* shrink the label to make room for the grip */
830               *allocation = child->allocation;
831               allocation->width = MAX (1, allocation->width - rect.width);
832               if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
833                 allocation->x += child->allocation.width - allocation->width;
834
835               gtk_widget_size_allocate (child, allocation);
836             }
837         }
838     }
839 }
840
841 static void
842 label_selectable_changed (GtkWidget  *label,
843                           GParamSpec *pspec,
844                           gpointer    data)
845 {
846   GtkStatusbar *statusbar = GTK_STATUSBAR (data);
847
848   if (statusbar && 
849       statusbar->has_resize_grip && statusbar->grip_window)
850     gdk_window_raise (statusbar->grip_window);
851 }
852
853 #define __GTK_STATUSBAR_C__
854 #include "gtkaliasdef.c"