]> Pileus Git - ~andy/gtk/blob - gtk/gtkstatusbar.c
Apply a cleanup patch by Kjartan Maraas (#341812)
[~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
263   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
264   g_return_val_if_fail (text != NULL, 0);
265
266   msg = g_slice_new (GtkStatusbarMsg);
267   msg->text = g_strdup (text);
268   msg->context_id = context_id;
269   msg->message_id = statusbar->seq_message_id++;
270
271   statusbar->messages = g_slist_prepend (statusbar->messages, msg);
272
273   g_signal_emit (statusbar,
274                  statusbar_signals[SIGNAL_TEXT_PUSHED],
275                  0,
276                  msg->context_id,
277                  msg->text);
278
279   return msg->message_id;
280 }
281
282 void
283 gtk_statusbar_pop (GtkStatusbar *statusbar,
284                    guint         context_id)
285 {
286   GtkStatusbarMsg *msg;
287
288   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
289
290   if (statusbar->messages)
291     {
292       GSList *list;
293
294       for (list = statusbar->messages; list; list = list->next)
295         {
296           msg = list->data;
297
298           if (msg->context_id == context_id)
299             {
300               statusbar->messages = g_slist_remove_link (statusbar->messages,
301                                                          list);
302               g_free (msg->text);
303               g_slice_free (GtkStatusbarMsg, msg);
304               g_slist_free_1 (list);
305               break;
306             }
307         }
308     }
309
310   msg = statusbar->messages ? statusbar->messages->data : NULL;
311
312   g_signal_emit (statusbar,
313                  statusbar_signals[SIGNAL_TEXT_POPPED],
314                  0,
315                  (guint) (msg ? msg->context_id : 0),
316                  msg ? msg->text : NULL);
317 }
318
319 void
320 gtk_statusbar_remove (GtkStatusbar *statusbar,
321                       guint        context_id,
322                       guint        message_id)
323 {
324   GtkStatusbarMsg *msg;
325
326   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
327   g_return_if_fail (message_id > 0);
328
329   msg = statusbar->messages ? statusbar->messages->data : NULL;
330   if (msg)
331     {
332       GSList *list;
333
334       /* care about signal emission if the topmost item is removed */
335       if (msg->context_id == context_id &&
336           msg->message_id == message_id)
337         {
338           gtk_statusbar_pop (statusbar, context_id);
339           return;
340         }
341       
342       for (list = statusbar->messages; list; list = list->next)
343         {
344           msg = list->data;
345           
346           if (msg->context_id == context_id &&
347               msg->message_id == message_id)
348             {
349               statusbar->messages = g_slist_remove_link (statusbar->messages, list);
350               g_free (msg->text);
351               g_slice_free (GtkStatusbarMsg, msg);
352               g_slist_free_1 (list);
353               
354               break;
355             }
356         }
357     }
358 }
359
360 void
361 gtk_statusbar_set_has_resize_grip (GtkStatusbar *statusbar,
362                                    gboolean      setting)
363 {
364   g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
365
366   setting = setting != FALSE;
367
368   if (setting != statusbar->has_resize_grip)
369     {
370       statusbar->has_resize_grip = setting;
371       gtk_widget_queue_resize (statusbar->label);
372       gtk_widget_queue_draw (GTK_WIDGET (statusbar));
373
374       if (GTK_WIDGET_REALIZED (statusbar))
375         {
376           if (statusbar->has_resize_grip && statusbar->grip_window == NULL)
377             {
378               gtk_statusbar_create_window (statusbar);
379               if (GTK_WIDGET_MAPPED (statusbar))
380                 gdk_window_show (statusbar->grip_window);
381             }
382           else if (!statusbar->has_resize_grip && statusbar->grip_window != NULL)
383             gtk_statusbar_destroy_window (statusbar);
384         }
385       
386       g_object_notify (G_OBJECT (statusbar), "has-resize-grip");
387     }
388 }
389
390 gboolean
391 gtk_statusbar_get_has_resize_grip (GtkStatusbar *statusbar)
392 {
393   g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), FALSE);
394
395   return statusbar->has_resize_grip;
396 }
397
398 static void
399 gtk_statusbar_destroy (GtkObject *object)
400 {
401   GtkStatusbar *statusbar;
402   GSList *list;
403
404   g_return_if_fail (GTK_IS_STATUSBAR (object));
405
406   statusbar = GTK_STATUSBAR (object);
407
408   for (list = statusbar->messages; list; list = list->next)
409     {
410       GtkStatusbarMsg *msg;
411
412       msg = list->data;
413       g_free (msg->text);
414       g_slice_free (GtkStatusbarMsg, msg);
415     }
416   g_slist_free (statusbar->messages);
417   statusbar->messages = NULL;
418
419   for (list = statusbar->keys; list; list = list->next)
420     g_free (list->data);
421   g_slist_free (statusbar->keys);
422   statusbar->keys = NULL;
423
424   GTK_OBJECT_CLASS (gtk_statusbar_parent_class)->destroy (object);
425 }
426
427 static void
428 gtk_statusbar_set_property (GObject      *object, 
429                             guint         prop_id, 
430                             const GValue *value, 
431                             GParamSpec   *pspec)
432 {
433   GtkStatusbar *statusbar = GTK_STATUSBAR (object);
434
435   switch (prop_id) 
436     {
437     case PROP_HAS_RESIZE_GRIP:
438       gtk_statusbar_set_has_resize_grip (statusbar, g_value_get_boolean (value));
439       break;
440     default:
441       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
442       break;
443     }
444 }
445
446 static void
447 gtk_statusbar_get_property (GObject    *object, 
448                             guint       prop_id, 
449                             GValue     *value, 
450                             GParamSpec *pspec)
451 {
452   GtkStatusbar *statusbar = GTK_STATUSBAR (object);
453         
454   switch (prop_id) 
455     {
456     case PROP_HAS_RESIZE_GRIP:
457       g_value_set_boolean (value, statusbar->has_resize_grip);
458       break;
459     default:
460       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
461       break;
462     }
463 }
464
465 static GdkWindowEdge
466 get_grip_edge (GtkStatusbar *statusbar)
467 {
468   GtkWidget *widget = GTK_WIDGET (statusbar);
469
470   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
471     return GDK_WINDOW_EDGE_SOUTH_EAST; 
472   else
473     return GDK_WINDOW_EDGE_SOUTH_WEST; 
474 }
475
476 static void
477 get_grip_rect (GtkStatusbar *statusbar,
478                GdkRectangle *rect)
479 {
480   GtkWidget *widget;
481   gint w, h;
482   
483   widget = GTK_WIDGET (statusbar);
484
485   /* These are in effect the max/default size of the grip. */
486   w = 18;
487   h = 18;
488
489   if (w > widget->allocation.width)
490     w = widget->allocation.width;
491
492   if (h > widget->allocation.height - widget->style->ythickness)
493     h = widget->allocation.height - widget->style->ythickness;
494   
495   rect->width = w;
496   rect->height = h;
497   rect->y = widget->allocation.y + widget->allocation.height - h;
498
499   if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
500     rect->x = widget->allocation.x + widget->allocation.width - w;
501   else 
502     rect->x = widget->allocation.x + widget->style->xthickness;
503 }
504
505 static void
506 set_grip_cursor (GtkStatusbar *statusbar)
507 {
508   if (statusbar->has_resize_grip)
509     {
510       GtkWidget *widget = GTK_WIDGET (statusbar);
511       GdkDisplay *display = gtk_widget_get_display (widget);
512       GdkCursorType cursor_type;
513       GdkCursor *cursor;
514       
515       if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
516         cursor_type = GDK_BOTTOM_RIGHT_CORNER;
517       else
518         cursor_type = GDK_BOTTOM_LEFT_CORNER;
519
520       cursor = gdk_cursor_new_for_display (display, cursor_type);
521       gdk_window_set_cursor (statusbar->grip_window, cursor);
522       gdk_cursor_unref (cursor);
523     }
524 }
525
526 static void
527 gtk_statusbar_create_window (GtkStatusbar *statusbar)
528 {
529   GtkWidget *widget;
530   GdkWindowAttr attributes;
531   gint attributes_mask;
532   GdkRectangle rect;
533   
534   g_return_if_fail (GTK_WIDGET_REALIZED (statusbar));
535   g_return_if_fail (statusbar->has_resize_grip);
536   
537   widget = GTK_WIDGET (statusbar);
538
539   get_grip_rect (statusbar, &rect);
540
541   attributes.x = rect.x;
542   attributes.y = rect.y;
543   attributes.width = rect.width;
544   attributes.height = rect.height;
545   attributes.window_type = GDK_WINDOW_CHILD;
546   attributes.wclass = GDK_INPUT_ONLY;
547   attributes.event_mask = gtk_widget_get_events (widget) |
548     GDK_BUTTON_PRESS_MASK;
549
550   attributes_mask = GDK_WA_X | GDK_WA_Y;
551
552   statusbar->grip_window = gdk_window_new (widget->window,
553                                            &attributes, attributes_mask);
554
555   gdk_window_set_user_data (statusbar->grip_window, widget);
556
557   set_grip_cursor (statusbar);
558 }
559
560 static void
561 gtk_statusbar_direction_changed (GtkWidget        *widget,
562                                  GtkTextDirection  prev_dir)
563 {
564   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
565
566   set_grip_cursor (statusbar);
567 }
568
569 static void
570 gtk_statusbar_destroy_window (GtkStatusbar *statusbar)
571 {
572   gdk_window_set_user_data (statusbar->grip_window, NULL);
573   gdk_window_destroy (statusbar->grip_window);
574   statusbar->grip_window = NULL;
575 }
576
577 static void
578 gtk_statusbar_realize (GtkWidget *widget)
579 {
580   GtkStatusbar *statusbar;
581
582   statusbar = GTK_STATUSBAR (widget);
583   
584   (* GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize) (widget);
585
586   if (statusbar->has_resize_grip)
587     gtk_statusbar_create_window (statusbar);
588 }
589
590 static void
591 gtk_statusbar_unrealize (GtkWidget *widget)
592 {
593   GtkStatusbar *statusbar;
594
595   statusbar = GTK_STATUSBAR (widget);
596
597   if (statusbar->grip_window)
598     gtk_statusbar_destroy_window (statusbar);
599   
600   (* GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unrealize) (widget);
601 }
602
603 static void
604 gtk_statusbar_map (GtkWidget *widget)
605 {
606   GtkStatusbar *statusbar;
607
608   statusbar = GTK_STATUSBAR (widget);
609   
610   (* GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->map) (widget);
611   
612   if (statusbar->grip_window)
613     gdk_window_show (statusbar->grip_window);
614 }
615
616 static void
617 gtk_statusbar_unmap (GtkWidget *widget)
618 {
619   GtkStatusbar *statusbar;
620
621   statusbar = GTK_STATUSBAR (widget);
622
623   if (statusbar->grip_window)
624     gdk_window_hide (statusbar->grip_window);
625   
626   (* GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unmap) (widget);
627 }
628
629 static gboolean
630 gtk_statusbar_button_press (GtkWidget      *widget,
631                             GdkEventButton *event)
632 {
633   GtkStatusbar *statusbar;
634   GtkWidget *ancestor;
635   GdkWindowEdge edge;
636   
637   statusbar = GTK_STATUSBAR (widget);
638   
639   if (!statusbar->has_resize_grip ||
640       event->type != GDK_BUTTON_PRESS ||
641       event->window != statusbar->grip_window)
642     return FALSE;
643   
644   ancestor = gtk_widget_get_toplevel (widget);
645
646   if (!GTK_IS_WINDOW (ancestor))
647     return FALSE;
648
649   edge = get_grip_edge (statusbar);
650
651   if (event->button == 1)
652     gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
653                                   edge,
654                                   event->button,
655                                   event->x_root, event->y_root,
656                                   event->time);
657   else if (event->button == 2)
658     gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
659                                 event->button,
660                                 event->x_root, event->y_root,
661                                 event->time);
662   else
663     return FALSE;
664   
665   return TRUE;
666 }
667
668 static gboolean
669 gtk_statusbar_expose_event (GtkWidget      *widget,
670                             GdkEventExpose *event)
671 {
672   GtkStatusbar *statusbar;
673   GdkRectangle rect;
674   
675   statusbar = GTK_STATUSBAR (widget);
676
677   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->expose_event (widget, event);
678
679   if (statusbar->has_resize_grip)
680     {
681       GdkWindowEdge edge;
682       
683       edge = get_grip_edge (statusbar);
684
685       get_grip_rect (statusbar, &rect);
686
687       gtk_paint_resize_grip (widget->style,
688                              widget->window,
689                              GTK_WIDGET_STATE (widget),
690                              NULL,
691                              widget,
692                              "statusbar",
693                              edge,
694                              rect.x, rect.y,
695                              /* don't draw grip over the frame, though you
696                               * can click on the frame.
697                               */
698                              rect.width - widget->style->xthickness,
699                              rect.height - widget->style->ythickness);
700     }
701
702   return FALSE;
703 }
704
705 static void
706 gtk_statusbar_size_request (GtkWidget      *widget,
707                             GtkRequisition *requisition)
708 {
709   GtkStatusbar *statusbar;
710   GtkShadowType shadow_type;
711   
712   statusbar = GTK_STATUSBAR (widget);
713
714   gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);  
715   gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
716   
717   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_request (widget, requisition);
718 }
719
720 /* look for extra children between the frame containing
721  * the label and where we want to draw the resize grip 
722  */
723 static gboolean
724 has_extra_children (GtkStatusbar *statusbar)
725 {
726   GList *l;
727   GtkBoxChild *child, *frame;
728
729   frame = NULL;
730   for (l = GTK_BOX (statusbar)->children; l; l = l->next)
731     {
732       frame = l->data;
733
734       if (frame->widget == statusbar->frame)
735         break;
736     }
737   
738   for (l = l->next; l; l = l->next)
739     {
740       child = l->data;
741
742       if (!GTK_WIDGET_VISIBLE (child->widget))
743         continue;
744
745       if (frame->pack == GTK_PACK_START || child->pack == GTK_PACK_END)
746         return TRUE;
747     }
748
749   return FALSE;
750 }
751
752 static void
753 gtk_statusbar_size_allocate  (GtkWidget     *widget,
754                               GtkAllocation *allocation)
755 {
756   GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
757   gboolean extra_children = FALSE;
758   GdkRectangle rect;
759
760   if (statusbar->has_resize_grip)
761     {
762       widget->allocation = *allocation;
763       get_grip_rect (statusbar, &rect);    
764       
765       extra_children = has_extra_children (statusbar);
766       
767       /* If there are extra children, we don't want them to occupy
768        * the space where we draw the resize grip, so we temporarily
769        * shrink the allocation.
770        * If there are no extra children, we want the frame to get
771        * the full allocation, and we fix up the allocation of the
772        * label afterwards to make room for the grip.
773        */
774       if (extra_children)
775         {
776           allocation->width -= rect.width;
777           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
778             allocation->x += rect.width;
779         }
780     }
781
782   /* chain up normally */
783   GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
784
785   if (statusbar->has_resize_grip)
786     {
787       if (statusbar->grip_window)
788         {
789           gdk_window_raise (statusbar->grip_window);
790           gdk_window_move_resize (statusbar->grip_window,
791                                   rect.x, rect.y,
792                                   rect.width, rect.height);
793         }
794
795       if (extra_children) 
796         {
797           allocation->width += rect.width;
798           if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
799             allocation->x -= rect.width;
800           
801           widget->allocation = *allocation;
802         }
803       else
804         {
805           if (statusbar->label->allocation.width + rect.width > statusbar->frame->allocation.width)
806             {
807               /* shrink the label to make room for the grip */
808               *allocation = statusbar->label->allocation;
809               allocation->width = MAX (1, allocation->width - rect.width);
810               if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) 
811                 allocation->x += statusbar->label->allocation.width - allocation->width;
812
813               gtk_widget_size_allocate (statusbar->label, allocation);
814             }
815         }
816     }
817 }
818
819 static void
820 label_selectable_changed (GtkWidget  *label,
821                           GParamSpec *pspec,
822                           gpointer    data)
823 {
824   GtkStatusbar *statusbar = GTK_STATUSBAR (data);
825
826   if (statusbar && 
827       statusbar->has_resize_grip && statusbar->grip_window)
828     gdk_window_raise (statusbar->grip_window);
829 }
830
831 #define __GTK_STATUSBAR_C__
832 #include "gtkaliasdef.c"