]> Pileus Git - ~andy/gtk/blob - gtk/gtkstatusbar.c
Get rid of templates that gtk-doc touches during distcheck
[~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 "gtkbuildable.h"
37 #include "gtkalias.h"
38
39 /**
40  * SECTION:gtkstatusbar
41  * @title: GtkStatusbar
42  * @short_description: Report messages of minor importance to the user
43  *
44  * A #GtkStatusbar is usually placed along the bottom of an application's
45  * main #GtkWindow. It may provide a regular commentary of the application's
46  * status (as is usually the case in a web browser, for example), or may be
47  * used to simply output a message when the status changes, (when an upload
48  * is complete in an FTP client, for example).
49  * It may also have a resize grip (a triangular area in the lower right
50  * corner) which can be clicked on to resize the window containing the
51  * statusbar.
52  *
53  * Status bars in GTK+ maintain a stack of messages. The message at
54  * the top of the each bar's stack is the one that will currently be displayed.
55  *
56  * Any messages added to a statusbar's stack must specify a
57  * <emphasis>context id</emphasis> that is used to uniquely identify
58  * the source of a message. This context id can be generated by
59  * gtk_statusbar_get_context_id(), given a message and the statusbar that
60  * it will be added to. Note that messages are stored in a stack, and when
61  * choosing which message to display, the stack structure is adhered to,
62  * regardless of the context identifier of a message.
63  *
64  * One could say that a statusbar maintains one stack of messages for
65  * display purposes, but allows multiple message producers to maintain
66  * sub-stacks of the messages they produced (via context ids).
67  *
68  * Status bars are created using gtk_statusbar_new().
69  *
70  * Messages are added to the bar's stack with gtk_statusbar_push().
71  *
72  * The message at the top of the stack can be removed using
73  * gtk_statusbar_pop(). A message can be removed from anywhere in the
74  * stack if its message id was recorded at the time it was added. This
75  * is done using gtk_statusbar_remove().
76  */
77 typedef struct _GtkStatusbarMsg GtkStatusbarMsg;
78
79 struct _GtkStatusbarMsg
80 {
81   gchar *text;
82   guint context_id;
83   guint message_id;
84 };
85
86 enum
87 {
88   SIGNAL_TEXT_PUSHED,
89   SIGNAL_TEXT_POPPED,
90   SIGNAL_LAST
91 };
92
93 enum
94 {
95   PROP_0,
96   PROP_HAS_RESIZE_GRIP
97 };
98
99 static void     gtk_statusbar_buildable_interface_init    (GtkBuildableIface *iface);
100 static GObject *gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
101                                                             GtkBuilder   *builder,
102                                                             const gchar  *childname);
103 static void     gtk_statusbar_destroy           (GtkObject         *object);
104 static void     gtk_statusbar_update            (GtkStatusbar      *statusbar,
105                                                  guint              context_id,
106                                                  const gchar       *text);
107 static void     gtk_statusbar_size_allocate     (GtkWidget         *widget,
108                                                  GtkAllocation     *allocation);
109 static void     gtk_statusbar_realize           (GtkWidget         *widget);
110 static void     gtk_statusbar_unrealize         (GtkWidget         *widget);
111 static void     gtk_statusbar_map               (GtkWidget         *widget);
112 static void     gtk_statusbar_unmap             (GtkWidget         *widget);
113 static gboolean gtk_statusbar_button_press      (GtkWidget         *widget,
114                                                  GdkEventButton    *event);
115 static gboolean gtk_statusbar_expose_event      (GtkWidget         *widget,
116                                                  GdkEventExpose    *event);
117 static void     gtk_statusbar_size_request      (GtkWidget         *widget,
118                                                  GtkRequisition    *requisition);
119 static void     gtk_statusbar_size_allocate     (GtkWidget         *widget,
120                                                  GtkAllocation     *allocation);
121 static void     gtk_statusbar_direction_changed (GtkWidget         *widget,
122                                                  GtkTextDirection   prev_dir);
123 static void     gtk_statusbar_state_changed     (GtkWidget        *widget,
124                                                  GtkStateType      previous_state);
125 static void     gtk_statusbar_create_window     (GtkStatusbar      *statusbar);
126 static void     gtk_statusbar_destroy_window    (GtkStatusbar      *statusbar);
127 static void     gtk_statusbar_get_property      (GObject           *object,
128                                                  guint              prop_id,
129                                                  GValue            *value,
130                                                  GParamSpec        *pspec);
131 static void     gtk_statusbar_set_property      (GObject           *object,
132                                                  guint              prop_id,
133                                                  const GValue      *value,
134                                                  GParamSpec        *pspec);
135 static void     label_selectable_changed        (GtkWidget         *label,
136                                                  GParamSpec        *pspec,
137                                                  gpointer           data);
138
139
140 static guint              statusbar_signals[SIGNAL_LAST] = { 0 };
141
142 G_DEFINE_TYPE_WITH_CODE (GtkStatusbar, gtk_statusbar, GTK_TYPE_HBOX,
143                          G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
144                                                 gtk_statusbar_buildable_interface_init));
145
146 static void
147 gtk_statusbar_class_init (GtkStatusbarClass *class)
148 {
149   GObjectClass *gobject_class;
150   GtkObjectClass *object_class;
151   GtkWidgetClass *widget_class;
152
153   gobject_class = (GObjectClass *) class;
154   object_class = (GtkObjectClass *) class;
155   widget_class = (GtkWidgetClass *) class;
156
157   gobject_class->set_property = gtk_statusbar_set_property;
158   gobject_class->get_property = gtk_statusbar_get_property;
159
160   object_class->destroy = gtk_statusbar_destroy;
161
162   widget_class->realize = gtk_statusbar_realize;
163   widget_class->unrealize = gtk_statusbar_unrealize;
164   widget_class->map = gtk_statusbar_map;
165   widget_class->unmap = gtk_statusbar_unmap;
166   widget_class->button_press_event = gtk_statusbar_button_press;
167   widget_class->expose_event = gtk_statusbar_expose_event;
168   widget_class->size_request = gtk_statusbar_size_request;
169   widget_class->size_allocate = gtk_statusbar_size_allocate;
170   widget_class->direction_changed = gtk_statusbar_direction_changed;
171   widget_class->state_changed = gtk_statusbar_state_changed;
172   
173   class->text_pushed = gtk_statusbar_update;
174   class->text_popped = gtk_statusbar_update;
175   
176   /**
177    * GtkStatusbar:has-resize-grip:
178    *
179    * Whether the statusbar has a grip for resizing the toplevel window.
180    *
181    * Since: 2.4
182    */
183   g_object_class_install_property (gobject_class,
184                                    PROP_HAS_RESIZE_GRIP,
185                                    g_param_spec_boolean ("has-resize-grip",
186                                                          P_("Has Resize Grip"),
187                                                          P_("Whether the statusbar has a grip for resizing the toplevel"),
188                                                          TRUE,
189                                                          GTK_PARAM_READWRITE));
190
191   /** 
192    * GtkStatusbar::text-pushed:
193    * @statusbar: the object which received the signal.
194    * @context_id: the context id of the relevant message/statusbar.
195    * @text: the message that was pushed.
196    * 
197    * Is emitted whenever a new message gets pushed onto a statusbar's stack.
198    */
199   statusbar_signals[SIGNAL_TEXT_PUSHED] =
200     g_signal_new (I_("text-pushed"),
201                   G_OBJECT_CLASS_TYPE (class),
202                   G_SIGNAL_RUN_LAST,
203                   G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed),
204                   NULL, NULL,
205                   _gtk_marshal_VOID__UINT_STRING,
206                   G_TYPE_NONE, 2,
207                   G_TYPE_UINT,
208                   G_TYPE_STRING);
209
210   /**
211    * GtkStatusbar::text-popped:
212    * @statusbar: the object which received the signal.
213    * @context_id: the context id of the relevant message/statusbar.
214    * @text: the message that was just popped.
215    *
216    * Is emitted whenever a new message is popped off a statusbar's stack.
217    */
218   statusbar_signals[SIGNAL_TEXT_POPPED] =
219     g_signal_new (I_("text-popped"),
220                   G_OBJECT_CLASS_TYPE (class),
221                   G_SIGNAL_RUN_LAST,
222                   G_STRUCT_OFFSET (GtkStatusbarClass, text_popped),
223                   NULL, NULL,
224                   _gtk_marshal_VOID__UINT_STRING,
225                   G_TYPE_NONE, 2,
226                   G_TYPE_UINT,
227                   G_TYPE_STRING);
228
229   gtk_widget_class_install_style_property (widget_class,
230                                            g_param_spec_enum ("shadow-type",
231                                                               P_("Shadow type"),
232                                                               P_("Style of bevel around the statusbar text"),
233                                                               GTK_TYPE_SHADOW_TYPE,
234                                                               GTK_SHADOW_IN,
235                                                               GTK_PARAM_READABLE));
236 }
237
238 static void
239 gtk_statusbar_init (GtkStatusbar *statusbar)
240 {
241   GtkBox *box;
242   GtkWidget *message_area;
243   GtkShadowType shadow_type;
244   
245   box = GTK_BOX (statusbar);
246
247   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), TRUE);
248
249   box->spacing = 2;
250   box->homogeneous = FALSE;
251
252   statusbar->has_resize_grip = TRUE;
253
254   gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
255   
256   statusbar->frame = gtk_frame_new (NULL);
257   gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
258   gtk_box_pack_start (box, statusbar->frame, TRUE, TRUE, 0);
259   gtk_widget_show (statusbar->frame);
260
261   message_area = gtk_hbox_new (FALSE, 4);
262   gtk_container_add (GTK_CONTAINER (statusbar->frame), message_area);
263   gtk_widget_show (message_area);
264
265   statusbar->label = gtk_label_new ("");
266   gtk_label_set_single_line_mode (GTK_LABEL (statusbar->label), TRUE);
267   gtk_misc_set_alignment (GTK_MISC (statusbar->label), 0.0, 0.5);
268   g_signal_connect (statusbar->label, "notify::selectable",
269                     G_CALLBACK (label_selectable_changed), statusbar);
270   gtk_label_set_ellipsize (GTK_LABEL (statusbar->label), PANGO_ELLIPSIZE_END);
271   gtk_container_add (GTK_CONTAINER (message_area), statusbar->label);
272   gtk_widget_show (statusbar->label);
273
274   statusbar->seq_context_id = 1;
275   statusbar->seq_message_id = 1;
276   statusbar->messages = NULL;
277   statusbar->keys = NULL;
278 }
279
280 static GtkBuildableIface *parent_buildable_iface;
281
282 static void
283 gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface)
284 {
285   parent_buildable_iface = g_type_interface_peek_parent (iface);
286   iface->get_internal_child = gtk_statusbar_buildable_get_internal_child;
287 }
288
289 static GObject *
290 gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
291                                             GtkBuilder   *builder,
292                                             const gchar  *childname)
293 {
294     if (strcmp (childname, "message_area") == 0)
295       return G_OBJECT (gtk_bin_get_child (GTK_BIN (GTK_STATUSBAR (buildable)->frame)));
296
297     return parent_buildable_iface->get_internal_child (buildable,
298                                                        builder,
299                                                        childname);
300 }
301
302 /**
303  * gtk_statusbar_new:
304  *
305  * Creates a new #GtkStatusbar ready for messages.
306  *
307  * Returns: the new #GtkStatusbar
308  */
309 GtkWidget* 
310 gtk_statusbar_new (void)
311 {
312   return g_object_new (GTK_TYPE_STATUSBAR, NULL);
313 }
314
315 static void
316 gtk_statusbar_update (GtkStatusbar *statusbar,
317                       guint         context_id,
318                       const gchar  *text)
319 {
320   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
321
322   if (!text)
323     text = "";
324
325   gtk_label_set_text (GTK_LABEL (statusbar->label), text);
326 }
327
328 /**
329  * gtk_statusbar_get_context_id:
330  * @statusbar: a #GtkStatusbar
331  * @context_description: textual description of what context 
332  *                       the new message is being used in
333  *
334  * Returns a new context identifier, given a description 
335  * of the actual context. Note that the description is 
336  * <emphasis>not</emphasis> shown in the UI.
337  *
338  * Returns: an integer id
339  */
340 guint
341 gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
342                               const gchar  *context_description)
343 {
344   gchar *string;
345   guint id;
346   
347   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
348   g_return_val_if_fail (context_description != NULL, 0);
349
350   /* we need to preserve namespaces on object datas */
351   string = g_strconcat ("gtk-status-bar-context:", context_description, NULL);
352
353   id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), string));
354   if (id == 0)
355     {
356       id = statusbar->seq_context_id++;
357       g_object_set_data_full (G_OBJECT (statusbar), string, GUINT_TO_POINTER (id), NULL);
358       statusbar->keys = g_slist_prepend (statusbar->keys, string);
359     }
360   else
361     g_free (string);
362
363   return id;
364 }
365
366 /**
367  * gtk_statusbar_push:
368  * @statusbar: a #GtkStatusbar
369  * @context_id: the message's context id, as returned by
370  *              gtk_statusbar_get_context_id()
371  * @text: the message to add to the statusbar
372  * 
373  * Pushes a new message onto a statusbar's stack.
374  *
375  * Returns: a message id that can be used with 
376  *          gtk_statusbar_remove().
377  */
378 guint
379 gtk_statusbar_push (GtkStatusbar *statusbar,
380                     guint         context_id,
381                     const gchar  *text)
382 {
383   GtkStatusbarMsg *msg;
384
385   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
386   g_return_val_if_fail (text != NULL, 0);
387
388   msg = g_slice_new (GtkStatusbarMsg);
389   msg->text = g_strdup (text);
390   msg->context_id = context_id;
391   msg->message_id = statusbar->seq_message_id++;
392
393   statusbar->messages = g_slist_prepend (statusbar->messages, msg);
394
395   g_signal_emit (statusbar,
396                  statusbar_signals[SIGNAL_TEXT_PUSHED],
397                  0,
398                  msg->context_id,
399                  msg->text);
400
401   return msg->message_id;
402 }
403
404 /**
405  * gtk_statusbar_pop:
406  * @statusbar: a #GtkStatusBar
407  * @context_id: a context identifier
408  * 
409  * Removes the first message in the #GtkStatusBar's stack
410  * with the given context id. 
411  *
412  * Note that this may not change the displayed message, if 
413  * the message at the top of the stack has a different 
414  * context id.
415  */
416 void
417 gtk_statusbar_pop (GtkStatusbar *statusbar,
418                    guint         context_id)
419 {
420   GtkStatusbarMsg *msg;
421
422   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
423
424   if (statusbar->messages)
425     {
426       GSList *list;
427
428       for (list = statusbar->messages; list; list = list->next)
429         {
430           msg = list->data;
431
432           if (msg->context_id == context_id)
433             {
434               statusbar->messages = g_slist_remove_link (statusbar->messages,
435                                                          list);
436               g_free (msg->text);
437               g_slice_free (GtkStatusbarMsg, msg);
438               g_slist_free_1 (list);
439               break;
440             }
441         }
442     }
443
444   msg = statusbar->messages ? statusbar->messages->data : NULL;
445
446   g_signal_emit (statusbar,
447                  statusbar_signals[SIGNAL_TEXT_POPPED],
448                  0,
449                  (guint) (msg ? msg->context_id : 0),
450                  msg ? msg->text : NULL);
451 }
452
453 /**
454  * gtk_statusbar_remove:
455  * @statusbar: a #GtkStatusBar
456  * @context_id: a context identifier
457  * @message_id: a message identifier, as returned by gtk_statusbar_push()
458  *
459  * Forces the removal of a message from a statusbar's stack. 
460  * The exact @context_id and @message_id must be specified.
461  */
462 void
463 gtk_statusbar_remove (GtkStatusbar *statusbar,
464                       guint        context_id,
465                       guint        message_id)
466 {
467   GtkStatusbarMsg *msg;
468
469   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
470   g_return_if_fail (message_id > 0);
471
472   msg = statusbar->messages ? statusbar->messages->data : NULL;
473   if (msg)
474     {
475       GSList *list;
476
477       /* care about signal emission if the topmost item is removed */
478       if (msg->context_id == context_id &&
479           msg->message_id == message_id)
480         {
481           gtk_statusbar_pop (statusbar, context_id);
482           return;
483         }
484       
485       for (list = statusbar->messages; list; list = list->next)
486         {
487           msg = list->data;
488           
489           if (msg->context_id == context_id &&
490               msg->message_id == message_id)
491             {
492               statusbar->messages = g_slist_remove_link (statusbar->messages, list);
493               g_free (msg->text);
494               g_slice_free (GtkStatusbarMsg, msg);
495               g_slist_free_1 (list);
496               
497               break;
498             }
499         }
500     }
501 }
502
503 /**
504  * gtk_statusbar_remove_all:
505  * @statusbar: a #GtkStatusBar
506  * @context_id: a context identifier
507  *
508  * Forces the removal of all messages from a statusbar's
509  * stack with the exact @context_id.
510  *
511  * Since: 2.22
512  */
513 void
514 gtk_statusbar_remove_all (GtkStatusbar *statusbar,
515                           guint         context_id)
516 {
517   GtkStatusbarMsg *msg;
518   GSList *prev, *list;
519
520   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
521
522   if (statusbar->messages == NULL)
523     return;
524
525   msg = statusbar->messages->data;
526
527   /* care about signal emission if the topmost item is removed */
528   if (msg->context_id == context_id)
529     {
530       gtk_statusbar_pop (statusbar, context_id);
531
532       prev = NULL;
533       list = statusbar->messages;
534     }
535   else
536     {
537       prev = statusbar->messages;
538       list = prev->next;
539     }
540
541   while (list != NULL)
542     {
543       msg = list->data;
544
545       if (msg->context_id == context_id)
546         {
547           if (prev == NULL)
548             statusbar->messages = list->next;
549           else
550             prev->next = list->next;
551
552           g_free (msg->text);
553           g_slice_free (GtkStatusbarMsg, msg);
554           g_slist_free_1 (list);
555
556           if (prev == NULL)
557             prev = statusbar->messages;
558
559           list = prev->next;
560         }
561       else
562         {
563           prev = list;
564           list = prev->next;
565         }
566     }
567 }
568
569 /**
570  * gtk_statusbar_set_has_resize_grip:
571  * @statusbar: a #GtkStatusBar
572  * @setting: %TRUE to have a resize grip
573  *
574  * Sets whether the statusbar has a resize grip. 
575  * %TRUE by default.
576  */
577 void
578 gtk_statusbar_set_has_resize_grip (GtkStatusbar *statusbar,
579                                    gboolean      setting)
580 {
581   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
582
583   setting = setting != FALSE;
584
585   if (setting != statusbar->has_resize_grip)
586     {
587       statusbar->has_resize_grip = setting;
588       gtk_widget_queue_resize (statusbar->label);
589       gtk_widget_queue_draw (GTK_WIDGET (statusbar));
590
591       if (gtk_widget_get_realized (GTK_WIDGET (statusbar)))
592         {
593           if (statusbar->has_resize_grip && statusbar->grip_window == NULL)
594             {
595               gtk_statusbar_create_window (statusbar);
596               if (gtk_widget_get_mapped (GTK_WIDGET (statusbar)))
597                 gdk_window_show (statusbar->grip_window);
598             }
599           else if (!statusbar->has_resize_grip && statusbar->grip_window != NULL)
600             gtk_statusbar_destroy_window (statusbar);
601         }
602       
603       g_object_notify (G_OBJECT (statusbar), "has-resize-grip");
604     }
605 }
606
607 /**
608  * gtk_statusbar_get_has_resize_grip:
609  * @statusbar: a #GtkStatusBar
610  * 
611  * Returns whether the statusbar has a resize grip.
612  *
613  * Returns: %TRUE if the statusbar has a resize grip.
614  */
615 gboolean
616 gtk_statusbar_get_has_resize_grip (GtkStatusbar *statusbar)
617 {
618   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), FALSE);
619
620   return statusbar->has_resize_grip;
621 }
622
623 /**
624  * gtk_statusbar_get_message_area:
625  * @statusbar: a #GtkStatusBar
626  *
627  * Retrieves the box containing the label widget.
628  *
629  * Returns: a #GtkBox
630  *
631  * Since: 2.20
632  */
633 GtkWidget*
634 gtk_statusbar_get_message_area (GtkStatusbar *statusbar)
635 {
636   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), NULL);
637
638   return gtk_bin_get_child (GTK_BIN (statusbar->frame));
639 }
640
641 static void
642 gtk_statusbar_destroy (GtkObject *object)
643 {
644   GtkStatusbar *statusbar = GTK_STATUSBAR (object);
645   GSList *list;
646
647   for (list = statusbar->messages; list; list = list->next)
648     {
649       GtkStatusbarMsg *msg;
650
651       msg = list->data;
652       g_free (msg->text);
653       g_slice_free (GtkStatusbarMsg, msg);
654     }
655   g_slist_free (statusbar->messages);
656   statusbar->messages = NULL;
657
658   for (list = statusbar->keys; list; list = list->next)
659     g_free (list->data);
660   g_slist_free (statusbar->keys);
661   statusbar->keys = NULL;
662
663   GTK_OBJECT_CLASS (gtk_statusbar_parent_class)->destroy (object);
664 }
665
666 static void
667 gtk_statusbar_set_property (GObject      *object, 
668                             guint         prop_id, 
669                             const GValue *value, 
670                             GParamSpec   *pspec)
671 {
672   GtkStatusbar *statusbar = GTK_STATUSBAR (object);
673
674   switch (prop_id) 
675     {
676     case PROP_HAS_RESIZE_GRIP:
677       gtk_statusbar_set_has_resize_grip (statusbar, g_value_get_boolean (value));
678       break;
679     default:
680       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
681       break;
682     }
683 }
684
685 static void
686 gtk_statusbar_get_property (GObject    *object, 
687                             guint       prop_id, 
688                             GValue     *value, 
689                             GParamSpec *pspec)
690 {
691   GtkStatusbar *statusbar = GTK_STATUSBAR (object);
692         
693   switch (prop_id) 
694     {
695     case PROP_HAS_RESIZE_GRIP:
696       g_value_set_boolean (value, statusbar->has_resize_grip);
697       break;
698     default:
699       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
700       break;
701     }
702 }
703
704 static GdkWindowEdge
705 get_grip_edge (GtkStatusbar *statusbar)
706 {
707   GtkWidget *widget = GTK_WIDGET (statusbar);
708
709   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
710     return GDK_WINDOW_EDGE_SOUTH_EAST; 
711   else
712     return GDK_WINDOW_EDGE_SOUTH_WEST; 
713 }
714
715 static void
716 get_grip_rect (GtkStatusbar *statusbar,
717                GdkRectangle *rect)
718 {
719   GtkWidget *widget;
720   gint w, h;
721   
722   widget = GTK_WIDGET (statusbar);
723
724   /* These are in effect the max/default size of the grip. */
725   w = 18;
726   h = 18;
727
728   if (w > widget->allocation.width)
729     w = widget->allocation.width;
730
731   if (h > widget->allocation.height - widget->style->ythickness)
732     h = widget->allocation.height - widget->style->ythickness;
733   
734   rect->width = w;
735   rect->height = h;
736   rect->y = widget->allocation.y + widget->allocation.height - h;
737
738   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
739     rect->x = widget->allocation.x + widget->allocation.width - w;
740   else 
741     rect->x = widget->allocation.x + widget->style->xthickness;
742 }
743
744 static void
745 set_grip_cursor (GtkStatusbar *statusbar)
746 {
747   if (statusbar->has_resize_grip && statusbar->grip_window != NULL)
748     {
749       GtkWidget *widget = GTK_WIDGET (statusbar);
750       GdkDisplay *display = gtk_widget_get_display (widget);
751       GdkCursorType cursor_type;
752       GdkCursor *cursor;
753       
754       if (gtk_widget_is_sensitive (widget))
755         {
756           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
757             cursor_type = GDK_BOTTOM_RIGHT_CORNER;
758           else
759             cursor_type = GDK_BOTTOM_LEFT_CORNER;
760
761           cursor = gdk_cursor_new_for_display (display, cursor_type);
762           gdk_window_set_cursor (statusbar->grip_window, cursor);
763           gdk_cursor_unref (cursor);
764         }
765       else
766         gdk_window_set_cursor (statusbar->grip_window, NULL);
767     }
768 }
769
770 static void
771 gtk_statusbar_create_window (GtkStatusbar *statusbar)
772 {
773   GtkWidget *widget;
774   GdkWindowAttr attributes;
775   gint attributes_mask;
776   GdkRectangle rect;
777
778   widget = GTK_WIDGET (statusbar);
779
780   g_return_if_fail (gtk_widget_get_realized (widget));
781   g_return_if_fail (statusbar->has_resize_grip);
782
783   get_grip_rect (statusbar, &rect);
784
785   attributes.x = rect.x;
786   attributes.y = rect.y;
787   attributes.width = rect.width;
788   attributes.height = rect.height;
789   attributes.window_type = GDK_WINDOW_CHILD;
790   attributes.wclass = GDK_INPUT_ONLY;
791   attributes.event_mask = gtk_widget_get_events (widget) |
792     GDK_BUTTON_PRESS_MASK;
793
794   attributes_mask = GDK_WA_X | GDK_WA_Y;
795
796   statusbar->grip_window = gdk_window_new (widget->window,
797                                            &attributes, attributes_mask);
798
799   gdk_window_set_user_data (statusbar->grip_window, widget);
800
801   gdk_window_raise (statusbar->grip_window);
802
803   set_grip_cursor (statusbar);
804 }
805
806 static void
807 gtk_statusbar_direction_changed (GtkWidget        *widget,
808                                  GtkTextDirection  prev_dir)
809 {
810   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
811
812   set_grip_cursor (statusbar);
813 }
814
815 static void
816 gtk_statusbar_state_changed (GtkWidget    *widget,
817                              GtkStateType  previous_state)   
818 {
819   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
820
821   set_grip_cursor (statusbar);
822 }
823
824 static void
825 gtk_statusbar_destroy_window (GtkStatusbar *statusbar)
826 {
827   gdk_window_set_user_data (statusbar->grip_window, NULL);
828   gdk_window_destroy (statusbar->grip_window);
829   statusbar->grip_window = NULL;
830 }
831
832 static void
833 gtk_statusbar_realize (GtkWidget *widget)
834 {
835   GtkStatusbar *statusbar;
836
837   statusbar = GTK_STATUSBAR (widget);
838
839   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize (widget);
840
841   if (statusbar->has_resize_grip)
842     gtk_statusbar_create_window (statusbar);
843 }
844
845 static void
846 gtk_statusbar_unrealize (GtkWidget *widget)
847 {
848   GtkStatusbar *statusbar;
849
850   statusbar = GTK_STATUSBAR (widget);
851
852   if (statusbar->grip_window)
853     gtk_statusbar_destroy_window (statusbar);
854
855   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unrealize (widget);
856 }
857
858 static void
859 gtk_statusbar_map (GtkWidget *widget)
860 {
861   GtkStatusbar *statusbar;
862
863   statusbar = GTK_STATUSBAR (widget);
864
865   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->map (widget);
866
867   if (statusbar->grip_window)
868     gdk_window_show (statusbar->grip_window);
869 }
870
871 static void
872 gtk_statusbar_unmap (GtkWidget *widget)
873 {
874   GtkStatusbar *statusbar;
875
876   statusbar = GTK_STATUSBAR (widget);
877
878   if (statusbar->grip_window)
879     gdk_window_hide (statusbar->grip_window);
880
881   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unmap (widget);
882 }
883
884 static gboolean
885 gtk_statusbar_button_press (GtkWidget      *widget,
886                             GdkEventButton *event)
887 {
888   GtkStatusbar *statusbar;
889   GtkWidget *ancestor;
890   GdkWindowEdge edge;
891   
892   statusbar = GTK_STATUSBAR (widget);
893   
894   if (!statusbar->has_resize_grip ||
895       event->type != GDK_BUTTON_PRESS ||
896       event->window != statusbar->grip_window)
897     return FALSE;
898   
899   ancestor = gtk_widget_get_toplevel (widget);
900
901   if (!GTK_IS_WINDOW (ancestor))
902     return FALSE;
903
904   edge = get_grip_edge (statusbar);
905
906   if (event->button == 1)
907     gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
908                                   edge,
909                                   event->button,
910                                   event->x_root, event->y_root,
911                                   event->time);
912   else if (event->button == 2)
913     gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
914                                 event->button,
915                                 event->x_root, event->y_root,
916                                 event->time);
917   else
918     return FALSE;
919   
920   return TRUE;
921 }
922
923 static gboolean
924 gtk_statusbar_expose_event (GtkWidget      *widget,
925                             GdkEventExpose *event)
926 {
927   GtkStatusbar *statusbar;
928   GdkRectangle rect;
929   
930   statusbar = GTK_STATUSBAR (widget);
931
932   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->expose_event (widget, event);
933
934   if (statusbar->has_resize_grip)
935     {
936       GdkWindowEdge edge;
937       
938       edge = get_grip_edge (statusbar);
939
940       get_grip_rect (statusbar, &rect);
941
942       gtk_paint_resize_grip (widget->style,
943                              widget->window,
944                              gtk_widget_get_state (widget),
945                              &event->area,
946                              widget,
947                              "statusbar",
948                              edge,
949                              rect.x, rect.y,
950                              /* don't draw grip over the frame, though you
951                               * can click on the frame.
952                               */
953                              rect.width - widget->style->xthickness,
954                              rect.height - widget->style->ythickness);
955     }
956
957   return FALSE;
958 }
959
960 static void
961 gtk_statusbar_size_request (GtkWidget      *widget,
962                             GtkRequisition *requisition)
963 {
964   GtkStatusbar *statusbar;
965   GtkShadowType shadow_type;
966   
967   statusbar = GTK_STATUSBAR (widget);
968
969   gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);  
970   gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
971   
972   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_request (widget, requisition);
973 }
974
975 /* look for extra children between the frame containing
976  * the label and where we want to draw the resize grip 
977  */
978 static gboolean
979 has_extra_children (GtkStatusbar *statusbar)
980 {
981   GList *l;
982   GtkBoxChild *child, *frame;
983
984   /* If the internal frame has been modified assume we have extra children */
985   if (gtk_bin_get_child (GTK_BIN (statusbar->frame)) != statusbar->label)
986     return TRUE;
987
988   frame = NULL;
989   for (l = GTK_BOX (statusbar)->children; l; l = l->next)
990     {
991       frame = l->data;
992
993       if (frame->widget == statusbar->frame)
994         break;
995     }
996   
997   for (l = l->next; l; l = l->next)
998     {
999       child = l->data;
1000
1001       if (!gtk_widget_get_visible (child->widget))
1002         continue;
1003
1004       if (frame->pack == GTK_PACK_START || child->pack == GTK_PACK_END)
1005         return TRUE;
1006     }
1007
1008   return FALSE;
1009 }
1010
1011 static void
1012 gtk_statusbar_size_allocate  (GtkWidget     *widget,
1013                               GtkAllocation *allocation)
1014 {
1015   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
1016   gboolean extra_children = FALSE;
1017   GdkRectangle rect;
1018
1019   if (statusbar->has_resize_grip)
1020     {
1021       get_grip_rect (statusbar, &rect);
1022
1023       extra_children = has_extra_children (statusbar);
1024
1025       /* If there are extra children, we don't want them to occupy
1026        * the space where we draw the resize grip, so we temporarily
1027        * shrink the allocation.
1028        * If there are no extra children, we want the frame to get
1029        * the full allocation, and we fix up the allocation of the
1030        * label afterwards to make room for the grip.
1031        */
1032       if (extra_children)
1033         {
1034           allocation->width -= rect.width;
1035           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
1036             allocation->x += rect.width;
1037         }
1038     }
1039
1040   /* chain up normally */
1041   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
1042
1043   if (statusbar->has_resize_grip)
1044     {
1045       if (extra_children) 
1046         {
1047           allocation->width += rect.width;
1048           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
1049             allocation->x -= rect.width;
1050           
1051           widget->allocation = *allocation;
1052         }
1053       else
1054         {
1055           GtkWidget *child;
1056
1057           /* Use the frame's child instead of statusbar->label directly, in case
1058            * the label has been replaced by a container as the frame's child
1059            * (and the label reparented into that container).
1060            */
1061           child = gtk_bin_get_child (GTK_BIN (statusbar->frame));
1062
1063           if (child->allocation.width + rect.width > statusbar->frame->allocation.width)
1064             {
1065               /* shrink the label to make room for the grip */
1066               *allocation = child->allocation;
1067               allocation->width = MAX (1, allocation->width - rect.width);
1068               if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1069                 allocation->x += child->allocation.width - allocation->width;
1070
1071               gtk_widget_size_allocate (child, allocation);
1072             }
1073         }
1074
1075       if (statusbar->grip_window)
1076         {
1077           get_grip_rect (statusbar, &rect);
1078
1079           gdk_window_raise (statusbar->grip_window);
1080           gdk_window_move_resize (statusbar->grip_window,
1081                                   rect.x, rect.y,
1082                                   rect.width, rect.height);
1083         }
1084
1085     }
1086 }
1087
1088 static void
1089 label_selectable_changed (GtkWidget  *label,
1090                           GParamSpec *pspec,
1091                           gpointer    data)
1092 {
1093   GtkStatusbar *statusbar = GTK_STATUSBAR (data);
1094
1095   if (statusbar && 
1096       statusbar->has_resize_grip && statusbar->grip_window)
1097     gdk_window_raise (statusbar->grip_window);
1098 }
1099
1100 #define __GTK_STATUSBAR_C__
1101 #include "gtkaliasdef.c"