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