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