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