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
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.
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.
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.
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/.
31 #include "gtkmarshalers.h"
32 #include "gtkstatusbar.h"
33 #include "gtkwindow.h"
34 #include "gtkprivate.h"
36 #include "gtkbuildable.h"
39 * SECTION:gtkstatusbar
40 * @title: GtkStatusbar
41 * @short_description: Report messages of minor importance to the user
43 * A #GtkStatusbar is usually placed along the bottom of an application's
44 * main #GtkWindow. It may provide a regular commentary of the application's
45 * status (as is usually the case in a web browser, for example), or may be
46 * used to simply output a message when the status changes, (when an upload
47 * is complete in an FTP client, for example).
48 * It may also have a resize grip (a triangular area in the lower right
49 * corner) which can be clicked on to resize the window containing the
52 * Status bars in GTK+ maintain a stack of messages. The message at
53 * the top of the each bar's stack is the one that will currently be displayed.
55 * Any messages added to a statusbar's stack must specify a
56 * <emphasis>context id</emphasis> that is used to uniquely identify
57 * the source of a message. This context id can be generated by
58 * gtk_statusbar_get_context_id(), given a message and the statusbar that
59 * it will be added to. Note that messages are stored in a stack, and when
60 * choosing which message to display, the stack structure is adhered to,
61 * regardless of the context identifier of a message.
63 * One could say that a statusbar maintains one stack of messages for
64 * display purposes, but allows multiple message producers to maintain
65 * sub-stacks of the messages they produced (via context ids).
67 * Status bars are created using gtk_statusbar_new().
69 * Messages are added to the bar's stack with gtk_statusbar_push().
71 * The message at the top of the stack can be removed using
72 * gtk_statusbar_pop(). A message can be removed from anywhere in the
73 * stack if its message id was recorded at the time it was added. This
74 * is done using gtk_statusbar_remove().
76 typedef struct _GtkStatusbarMsg GtkStatusbarMsg;
78 struct _GtkStatusbarMsg
98 static void gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface);
99 static GObject *gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
101 const gchar *childname);
102 static void gtk_statusbar_destroy (GtkObject *object);
103 static void gtk_statusbar_update (GtkStatusbar *statusbar,
106 static void gtk_statusbar_size_allocate (GtkWidget *widget,
107 GtkAllocation *allocation);
108 static void gtk_statusbar_realize (GtkWidget *widget);
109 static void gtk_statusbar_unrealize (GtkWidget *widget);
110 static void gtk_statusbar_map (GtkWidget *widget);
111 static void gtk_statusbar_unmap (GtkWidget *widget);
112 static gboolean gtk_statusbar_button_press (GtkWidget *widget,
113 GdkEventButton *event);
114 static gboolean gtk_statusbar_expose_event (GtkWidget *widget,
115 GdkEventExpose *event);
116 static void gtk_statusbar_size_request (GtkWidget *widget,
117 GtkRequisition *requisition);
118 static void gtk_statusbar_size_allocate (GtkWidget *widget,
119 GtkAllocation *allocation);
120 static void gtk_statusbar_direction_changed (GtkWidget *widget,
121 GtkTextDirection prev_dir);
122 static void gtk_statusbar_state_changed (GtkWidget *widget,
123 GtkStateType previous_state);
124 static void gtk_statusbar_create_window (GtkStatusbar *statusbar);
125 static void gtk_statusbar_destroy_window (GtkStatusbar *statusbar);
126 static void gtk_statusbar_get_property (GObject *object,
130 static void gtk_statusbar_set_property (GObject *object,
134 static void label_selectable_changed (GtkWidget *label,
139 static guint statusbar_signals[SIGNAL_LAST] = { 0 };
141 G_DEFINE_TYPE_WITH_CODE (GtkStatusbar, gtk_statusbar, GTK_TYPE_HBOX,
142 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
143 gtk_statusbar_buildable_interface_init));
146 gtk_statusbar_class_init (GtkStatusbarClass *class)
148 GObjectClass *gobject_class;
149 GtkObjectClass *object_class;
150 GtkWidgetClass *widget_class;
152 gobject_class = (GObjectClass *) class;
153 object_class = (GtkObjectClass *) class;
154 widget_class = (GtkWidgetClass *) class;
156 gobject_class->set_property = gtk_statusbar_set_property;
157 gobject_class->get_property = gtk_statusbar_get_property;
159 object_class->destroy = gtk_statusbar_destroy;
161 widget_class->realize = gtk_statusbar_realize;
162 widget_class->unrealize = gtk_statusbar_unrealize;
163 widget_class->map = gtk_statusbar_map;
164 widget_class->unmap = gtk_statusbar_unmap;
165 widget_class->button_press_event = gtk_statusbar_button_press;
166 widget_class->expose_event = gtk_statusbar_expose_event;
167 widget_class->size_request = gtk_statusbar_size_request;
168 widget_class->size_allocate = gtk_statusbar_size_allocate;
169 widget_class->direction_changed = gtk_statusbar_direction_changed;
170 widget_class->state_changed = gtk_statusbar_state_changed;
172 class->text_pushed = gtk_statusbar_update;
173 class->text_popped = gtk_statusbar_update;
176 * GtkStatusbar:has-resize-grip:
178 * Whether the statusbar has a grip for resizing the toplevel window.
182 g_object_class_install_property (gobject_class,
183 PROP_HAS_RESIZE_GRIP,
184 g_param_spec_boolean ("has-resize-grip",
185 P_("Has Resize Grip"),
186 P_("Whether the statusbar has a grip for resizing the toplevel"),
188 GTK_PARAM_READWRITE));
191 * GtkStatusbar::text-pushed:
192 * @statusbar: the object which received the signal.
193 * @context_id: the context id of the relevant message/statusbar.
194 * @text: the message that was pushed.
196 * Is emitted whenever a new message gets pushed onto a statusbar's stack.
198 statusbar_signals[SIGNAL_TEXT_PUSHED] =
199 g_signal_new (I_("text-pushed"),
200 G_OBJECT_CLASS_TYPE (class),
202 G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed),
204 _gtk_marshal_VOID__UINT_STRING,
210 * GtkStatusbar::text-popped:
211 * @statusbar: the object which received the signal.
212 * @context_id: the context id of the relevant message/statusbar.
213 * @text: the message that was just popped.
215 * Is emitted whenever a new message is popped off a statusbar's stack.
217 statusbar_signals[SIGNAL_TEXT_POPPED] =
218 g_signal_new (I_("text-popped"),
219 G_OBJECT_CLASS_TYPE (class),
221 G_STRUCT_OFFSET (GtkStatusbarClass, text_popped),
223 _gtk_marshal_VOID__UINT_STRING,
228 gtk_widget_class_install_style_property (widget_class,
229 g_param_spec_enum ("shadow-type",
231 P_("Style of bevel around the statusbar text"),
232 GTK_TYPE_SHADOW_TYPE,
234 GTK_PARAM_READABLE));
238 gtk_statusbar_init (GtkStatusbar *statusbar)
241 GtkWidget *message_area;
242 GtkShadowType shadow_type;
244 box = GTK_BOX (statusbar);
246 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), TRUE);
249 box->homogeneous = FALSE;
251 statusbar->has_resize_grip = TRUE;
253 gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
255 statusbar->frame = gtk_frame_new (NULL);
256 gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
257 gtk_box_pack_start (box, statusbar->frame, TRUE, TRUE, 0);
258 gtk_widget_show (statusbar->frame);
260 message_area = gtk_hbox_new (FALSE, 4);
261 gtk_container_add (GTK_CONTAINER (statusbar->frame), message_area);
262 gtk_widget_show (message_area);
264 statusbar->label = gtk_label_new ("");
265 gtk_label_set_single_line_mode (GTK_LABEL (statusbar->label), TRUE);
266 gtk_misc_set_alignment (GTK_MISC (statusbar->label), 0.0, 0.5);
267 g_signal_connect (statusbar->label, "notify::selectable",
268 G_CALLBACK (label_selectable_changed), statusbar);
269 gtk_label_set_ellipsize (GTK_LABEL (statusbar->label), PANGO_ELLIPSIZE_END);
270 gtk_container_add (GTK_CONTAINER (message_area), statusbar->label);
271 gtk_widget_show (statusbar->label);
273 statusbar->seq_context_id = 1;
274 statusbar->seq_message_id = 1;
275 statusbar->messages = NULL;
276 statusbar->keys = NULL;
279 static GtkBuildableIface *parent_buildable_iface;
282 gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface)
284 parent_buildable_iface = g_type_interface_peek_parent (iface);
285 iface->get_internal_child = gtk_statusbar_buildable_get_internal_child;
289 gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
291 const gchar *childname)
293 if (strcmp (childname, "message_area") == 0)
294 return G_OBJECT (gtk_bin_get_child (GTK_BIN (GTK_STATUSBAR (buildable)->frame)));
296 return parent_buildable_iface->get_internal_child (buildable,
304 * Creates a new #GtkStatusbar ready for messages.
306 * Returns: the new #GtkStatusbar
309 gtk_statusbar_new (void)
311 return g_object_new (GTK_TYPE_STATUSBAR, NULL);
315 gtk_statusbar_update (GtkStatusbar *statusbar,
319 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
324 gtk_label_set_text (GTK_LABEL (statusbar->label), text);
328 * gtk_statusbar_get_context_id:
329 * @statusbar: a #GtkStatusbar
330 * @context_description: textual description of what context
331 * the new message is being used in
333 * Returns a new context identifier, given a description
334 * of the actual context. Note that the description is
335 * <emphasis>not</emphasis> shown in the UI.
337 * Returns: an integer id
340 gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
341 const gchar *context_description)
346 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
347 g_return_val_if_fail (context_description != NULL, 0);
349 /* we need to preserve namespaces on object datas */
350 string = g_strconcat ("gtk-status-bar-context:", context_description, NULL);
352 id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), string));
355 id = statusbar->seq_context_id++;
356 g_object_set_data_full (G_OBJECT (statusbar), string, GUINT_TO_POINTER (id), NULL);
357 statusbar->keys = g_slist_prepend (statusbar->keys, string);
366 * gtk_statusbar_push:
367 * @statusbar: a #GtkStatusbar
368 * @context_id: the message's context id, as returned by
369 * gtk_statusbar_get_context_id()
370 * @text: the message to add to the statusbar
372 * Pushes a new message onto a statusbar's stack.
374 * Returns: a message id that can be used with
375 * gtk_statusbar_remove().
378 gtk_statusbar_push (GtkStatusbar *statusbar,
382 GtkStatusbarMsg *msg;
384 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
385 g_return_val_if_fail (text != NULL, 0);
387 msg = g_slice_new (GtkStatusbarMsg);
388 msg->text = g_strdup (text);
389 msg->context_id = context_id;
390 msg->message_id = statusbar->seq_message_id++;
392 statusbar->messages = g_slist_prepend (statusbar->messages, msg);
394 g_signal_emit (statusbar,
395 statusbar_signals[SIGNAL_TEXT_PUSHED],
400 return msg->message_id;
405 * @statusbar: a #GtkStatusBar
406 * @context_id: a context identifier
408 * Removes the first message in the #GtkStatusBar's stack
409 * with the given context id.
411 * Note that this may not change the displayed message, if
412 * the message at the top of the stack has a different
416 gtk_statusbar_pop (GtkStatusbar *statusbar,
419 GtkStatusbarMsg *msg;
421 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
423 if (statusbar->messages)
427 for (list = statusbar->messages; list; list = list->next)
431 if (msg->context_id == context_id)
433 statusbar->messages = g_slist_remove_link (statusbar->messages,
436 g_slice_free (GtkStatusbarMsg, msg);
437 g_slist_free_1 (list);
443 msg = statusbar->messages ? statusbar->messages->data : NULL;
445 g_signal_emit (statusbar,
446 statusbar_signals[SIGNAL_TEXT_POPPED],
448 (guint) (msg ? msg->context_id : 0),
449 msg ? msg->text : NULL);
453 * gtk_statusbar_remove:
454 * @statusbar: a #GtkStatusBar
455 * @context_id: a context identifier
456 * @message_id: a message identifier, as returned by gtk_statusbar_push()
458 * Forces the removal of a message from a statusbar's stack.
459 * The exact @context_id and @message_id must be specified.
462 gtk_statusbar_remove (GtkStatusbar *statusbar,
466 GtkStatusbarMsg *msg;
468 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
469 g_return_if_fail (message_id > 0);
471 msg = statusbar->messages ? statusbar->messages->data : NULL;
476 /* care about signal emission if the topmost item is removed */
477 if (msg->context_id == context_id &&
478 msg->message_id == message_id)
480 gtk_statusbar_pop (statusbar, context_id);
484 for (list = statusbar->messages; list; list = list->next)
488 if (msg->context_id == context_id &&
489 msg->message_id == message_id)
491 statusbar->messages = g_slist_remove_link (statusbar->messages, list);
493 g_slice_free (GtkStatusbarMsg, msg);
494 g_slist_free_1 (list);
503 * gtk_statusbar_remove_all:
504 * @statusbar: a #GtkStatusBar
505 * @context_id: a context identifier
507 * Forces the removal of all messages from a statusbar's
508 * stack with the exact @context_id.
513 gtk_statusbar_remove_all (GtkStatusbar *statusbar,
516 GtkStatusbarMsg *msg;
519 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
521 if (statusbar->messages == NULL)
524 msg = statusbar->messages->data;
526 /* care about signal emission if the topmost item is removed */
527 if (msg->context_id == context_id)
529 gtk_statusbar_pop (statusbar, context_id);
532 list = statusbar->messages;
536 prev = statusbar->messages;
544 if (msg->context_id == context_id)
547 statusbar->messages = list->next;
549 prev->next = list->next;
552 g_slice_free (GtkStatusbarMsg, msg);
553 g_slist_free_1 (list);
556 prev = statusbar->messages;
569 * gtk_statusbar_set_has_resize_grip:
570 * @statusbar: a #GtkStatusBar
571 * @setting: %TRUE to have a resize grip
573 * Sets whether the statusbar has a resize grip.
577 gtk_statusbar_set_has_resize_grip (GtkStatusbar *statusbar,
580 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
582 setting = setting != FALSE;
584 if (setting != statusbar->has_resize_grip)
586 statusbar->has_resize_grip = setting;
587 gtk_widget_queue_resize (statusbar->label);
588 gtk_widget_queue_draw (GTK_WIDGET (statusbar));
590 if (gtk_widget_get_realized (GTK_WIDGET (statusbar)))
592 if (statusbar->has_resize_grip && statusbar->grip_window == NULL)
594 gtk_statusbar_create_window (statusbar);
595 if (gtk_widget_get_mapped (GTK_WIDGET (statusbar)))
596 gdk_window_show (statusbar->grip_window);
598 else if (!statusbar->has_resize_grip && statusbar->grip_window != NULL)
599 gtk_statusbar_destroy_window (statusbar);
602 g_object_notify (G_OBJECT (statusbar), "has-resize-grip");
607 * gtk_statusbar_get_has_resize_grip:
608 * @statusbar: a #GtkStatusBar
610 * Returns whether the statusbar has a resize grip.
612 * Returns: %TRUE if the statusbar has a resize grip.
615 gtk_statusbar_get_has_resize_grip (GtkStatusbar *statusbar)
617 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), FALSE);
619 return statusbar->has_resize_grip;
623 * gtk_statusbar_get_message_area:
624 * @statusbar: a #GtkStatusBar
626 * Retrieves the box containing the label widget.
633 gtk_statusbar_get_message_area (GtkStatusbar *statusbar)
635 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), NULL);
637 return gtk_bin_get_child (GTK_BIN (statusbar->frame));
641 gtk_statusbar_destroy (GtkObject *object)
643 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
646 for (list = statusbar->messages; list; list = list->next)
648 GtkStatusbarMsg *msg;
652 g_slice_free (GtkStatusbarMsg, msg);
654 g_slist_free (statusbar->messages);
655 statusbar->messages = NULL;
657 for (list = statusbar->keys; list; list = list->next)
659 g_slist_free (statusbar->keys);
660 statusbar->keys = NULL;
662 GTK_OBJECT_CLASS (gtk_statusbar_parent_class)->destroy (object);
666 gtk_statusbar_set_property (GObject *object,
671 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
675 case PROP_HAS_RESIZE_GRIP:
676 gtk_statusbar_set_has_resize_grip (statusbar, g_value_get_boolean (value));
679 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
685 gtk_statusbar_get_property (GObject *object,
690 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
694 case PROP_HAS_RESIZE_GRIP:
695 g_value_set_boolean (value, statusbar->has_resize_grip);
698 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
704 get_grip_edge (GtkStatusbar *statusbar)
706 GtkWidget *widget = GTK_WIDGET (statusbar);
708 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
709 return GDK_WINDOW_EDGE_SOUTH_EAST;
711 return GDK_WINDOW_EDGE_SOUTH_WEST;
715 get_grip_rect (GtkStatusbar *statusbar,
721 widget = GTK_WIDGET (statusbar);
723 /* These are in effect the max/default size of the grip. */
727 if (w > widget->allocation.width)
728 w = widget->allocation.width;
730 if (h > widget->allocation.height - widget->style->ythickness)
731 h = widget->allocation.height - widget->style->ythickness;
735 rect->y = widget->allocation.y + widget->allocation.height - h;
737 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
738 rect->x = widget->allocation.x + widget->allocation.width - w;
740 rect->x = widget->allocation.x + widget->style->xthickness;
744 set_grip_cursor (GtkStatusbar *statusbar)
746 if (statusbar->has_resize_grip && statusbar->grip_window != NULL)
748 GtkWidget *widget = GTK_WIDGET (statusbar);
749 GdkDisplay *display = gtk_widget_get_display (widget);
750 GdkCursorType cursor_type;
753 if (gtk_widget_is_sensitive (widget))
755 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
756 cursor_type = GDK_BOTTOM_RIGHT_CORNER;
758 cursor_type = GDK_BOTTOM_LEFT_CORNER;
760 cursor = gdk_cursor_new_for_display (display, cursor_type);
761 gdk_window_set_cursor (statusbar->grip_window, cursor);
762 gdk_cursor_unref (cursor);
765 gdk_window_set_cursor (statusbar->grip_window, NULL);
770 gtk_statusbar_create_window (GtkStatusbar *statusbar)
773 GdkWindowAttr attributes;
774 gint attributes_mask;
777 widget = GTK_WIDGET (statusbar);
779 g_return_if_fail (gtk_widget_get_realized (widget));
780 g_return_if_fail (statusbar->has_resize_grip);
782 get_grip_rect (statusbar, &rect);
784 attributes.x = rect.x;
785 attributes.y = rect.y;
786 attributes.width = rect.width;
787 attributes.height = rect.height;
788 attributes.window_type = GDK_WINDOW_CHILD;
789 attributes.wclass = GDK_INPUT_ONLY;
790 attributes.event_mask = gtk_widget_get_events (widget) |
791 GDK_BUTTON_PRESS_MASK;
793 attributes_mask = GDK_WA_X | GDK_WA_Y;
795 statusbar->grip_window = gdk_window_new (widget->window,
796 &attributes, attributes_mask);
798 gdk_window_set_user_data (statusbar->grip_window, widget);
800 gdk_window_raise (statusbar->grip_window);
802 set_grip_cursor (statusbar);
806 gtk_statusbar_direction_changed (GtkWidget *widget,
807 GtkTextDirection prev_dir)
809 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
811 set_grip_cursor (statusbar);
815 gtk_statusbar_state_changed (GtkWidget *widget,
816 GtkStateType previous_state)
818 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
820 set_grip_cursor (statusbar);
824 gtk_statusbar_destroy_window (GtkStatusbar *statusbar)
826 gdk_window_set_user_data (statusbar->grip_window, NULL);
827 gdk_window_destroy (statusbar->grip_window);
828 statusbar->grip_window = NULL;
832 gtk_statusbar_realize (GtkWidget *widget)
834 GtkStatusbar *statusbar;
836 statusbar = GTK_STATUSBAR (widget);
838 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize (widget);
840 if (statusbar->has_resize_grip)
841 gtk_statusbar_create_window (statusbar);
845 gtk_statusbar_unrealize (GtkWidget *widget)
847 GtkStatusbar *statusbar;
849 statusbar = GTK_STATUSBAR (widget);
851 if (statusbar->grip_window)
852 gtk_statusbar_destroy_window (statusbar);
854 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unrealize (widget);
858 gtk_statusbar_map (GtkWidget *widget)
860 GtkStatusbar *statusbar;
862 statusbar = GTK_STATUSBAR (widget);
864 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->map (widget);
866 if (statusbar->grip_window)
867 gdk_window_show (statusbar->grip_window);
871 gtk_statusbar_unmap (GtkWidget *widget)
873 GtkStatusbar *statusbar;
875 statusbar = GTK_STATUSBAR (widget);
877 if (statusbar->grip_window)
878 gdk_window_hide (statusbar->grip_window);
880 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unmap (widget);
884 gtk_statusbar_button_press (GtkWidget *widget,
885 GdkEventButton *event)
887 GtkStatusbar *statusbar;
891 statusbar = GTK_STATUSBAR (widget);
893 if (!statusbar->has_resize_grip ||
894 event->type != GDK_BUTTON_PRESS ||
895 event->window != statusbar->grip_window)
898 ancestor = gtk_widget_get_toplevel (widget);
900 if (!GTK_IS_WINDOW (ancestor))
903 edge = get_grip_edge (statusbar);
905 if (event->button == 1)
906 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
909 event->x_root, event->y_root,
911 else if (event->button == 2)
912 gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
914 event->x_root, event->y_root,
923 gtk_statusbar_expose_event (GtkWidget *widget,
924 GdkEventExpose *event)
926 GtkStatusbar *statusbar;
929 statusbar = GTK_STATUSBAR (widget);
931 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->expose_event (widget, event);
933 if (statusbar->has_resize_grip)
937 edge = get_grip_edge (statusbar);
939 get_grip_rect (statusbar, &rect);
941 gtk_paint_resize_grip (widget->style,
943 gtk_widget_get_state (widget),
949 /* don't draw grip over the frame, though you
950 * can click on the frame.
952 rect.width - widget->style->xthickness,
953 rect.height - widget->style->ythickness);
960 gtk_statusbar_size_request (GtkWidget *widget,
961 GtkRequisition *requisition)
963 GtkStatusbar *statusbar;
964 GtkShadowType shadow_type;
966 statusbar = GTK_STATUSBAR (widget);
968 gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
969 gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
971 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_request (widget, requisition);
974 /* look for extra children between the frame containing
975 * the label and where we want to draw the resize grip
978 has_extra_children (GtkStatusbar *statusbar)
981 GtkBoxChild *child, *frame;
983 /* If the internal frame has been modified assume we have extra children */
984 if (gtk_bin_get_child (GTK_BIN (statusbar->frame)) != statusbar->label)
988 for (l = GTK_BOX (statusbar)->children; l; l = l->next)
992 if (frame->widget == statusbar->frame)
996 for (l = l->next; l; l = l->next)
1000 if (!gtk_widget_get_visible (child->widget))
1003 if (frame->pack == GTK_PACK_START || child->pack == GTK_PACK_END)
1011 gtk_statusbar_size_allocate (GtkWidget *widget,
1012 GtkAllocation *allocation)
1014 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
1015 gboolean extra_children = FALSE;
1018 if (statusbar->has_resize_grip)
1020 get_grip_rect (statusbar, &rect);
1022 extra_children = has_extra_children (statusbar);
1024 /* If there are extra children, we don't want them to occupy
1025 * the space where we draw the resize grip, so we temporarily
1026 * shrink the allocation.
1027 * If there are no extra children, we want the frame to get
1028 * the full allocation, and we fix up the allocation of the
1029 * label afterwards to make room for the grip.
1033 allocation->width -= rect.width;
1034 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1035 allocation->x += rect.width;
1039 /* chain up normally */
1040 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
1042 if (statusbar->has_resize_grip)
1046 allocation->width += rect.width;
1047 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1048 allocation->x -= rect.width;
1050 widget->allocation = *allocation;
1056 /* Use the frame's child instead of statusbar->label directly, in case
1057 * the label has been replaced by a container as the frame's child
1058 * (and the label reparented into that container).
1060 child = gtk_bin_get_child (GTK_BIN (statusbar->frame));
1062 if (child->allocation.width + rect.width > statusbar->frame->allocation.width)
1064 /* shrink the label to make room for the grip */
1065 *allocation = child->allocation;
1066 allocation->width = MAX (1, allocation->width - rect.width);
1067 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1068 allocation->x += child->allocation.width - allocation->width;
1070 gtk_widget_size_allocate (child, allocation);
1074 if (statusbar->grip_window)
1076 get_grip_rect (statusbar, &rect);
1078 gdk_window_raise (statusbar->grip_window);
1079 gdk_window_move_resize (statusbar->grip_window,
1081 rect.width, rect.height);
1088 label_selectable_changed (GtkWidget *label,
1092 GtkStatusbar *statusbar = GTK_STATUSBAR (data);
1095 statusbar->has_resize_grip && statusbar->grip_window)
1096 gdk_window_raise (statusbar->grip_window);