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