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