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