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