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"
40 * SECTION:gtkstatusbar
41 * @title: GtkStatusbar
42 * @short_description: Report messages of minor importance to the user
44 * A #GtkStatusbar is usually placed along the bottom of an application's
45 * main #GtkWindow. It may provide a regular commentary of the application's
46 * status (as is usually the case in a web browser, for example), or may be
47 * used to simply output a message when the status changes, (when an upload
48 * is complete in an FTP client, for example).
49 * It may also have a resize grip (a triangular area in the lower right
50 * corner) which can be clicked on to resize the window containing the
53 * Status bars in GTK+ maintain a stack of messages. The message at
54 * the top of the each bar's stack is the one that will currently be displayed.
56 * Any messages added to a statusbar's stack must specify a
57 * <emphasis>context id</emphasis> that is used to uniquely identify
58 * the source of a message. This context id can be generated by
59 * gtk_statusbar_get_context_id(), given a message and the statusbar that
60 * it will be added to. Note that messages are stored in a stack, and when
61 * choosing which message to display, the stack structure is adhered to,
62 * regardless of the context identifier of a message.
64 * One could say that a statusbar maintains one stack of messages for
65 * display purposes, but allows multiple message producers to maintain
66 * sub-stacks of the messages they produced (via context ids).
68 * Status bars are created using gtk_statusbar_new().
70 * Messages are added to the bar's stack with gtk_statusbar_push().
72 * The message at the top of the stack can be removed using
73 * gtk_statusbar_pop(). A message can be removed from anywhere in the
74 * stack if its message id was recorded at the time it was added. This
75 * is done using gtk_statusbar_remove().
77 typedef struct _GtkStatusbarMsg GtkStatusbarMsg;
79 struct _GtkStatusbarMsg
99 static void gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface);
100 static GObject *gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
102 const gchar *childname);
103 static void gtk_statusbar_destroy (GtkObject *object);
104 static void gtk_statusbar_update (GtkStatusbar *statusbar,
107 static void gtk_statusbar_size_allocate (GtkWidget *widget,
108 GtkAllocation *allocation);
109 static void gtk_statusbar_realize (GtkWidget *widget);
110 static void gtk_statusbar_unrealize (GtkWidget *widget);
111 static void gtk_statusbar_map (GtkWidget *widget);
112 static void gtk_statusbar_unmap (GtkWidget *widget);
113 static gboolean gtk_statusbar_button_press (GtkWidget *widget,
114 GdkEventButton *event);
115 static gboolean gtk_statusbar_expose_event (GtkWidget *widget,
116 GdkEventExpose *event);
117 static void gtk_statusbar_size_request (GtkWidget *widget,
118 GtkRequisition *requisition);
119 static void gtk_statusbar_size_allocate (GtkWidget *widget,
120 GtkAllocation *allocation);
121 static void gtk_statusbar_direction_changed (GtkWidget *widget,
122 GtkTextDirection prev_dir);
123 static void gtk_statusbar_state_changed (GtkWidget *widget,
124 GtkStateType previous_state);
125 static void gtk_statusbar_create_window (GtkStatusbar *statusbar);
126 static void gtk_statusbar_destroy_window (GtkStatusbar *statusbar);
127 static void gtk_statusbar_get_property (GObject *object,
131 static void gtk_statusbar_set_property (GObject *object,
135 static void label_selectable_changed (GtkWidget *label,
140 static guint statusbar_signals[SIGNAL_LAST] = { 0 };
142 G_DEFINE_TYPE_WITH_CODE (GtkStatusbar, gtk_statusbar, GTK_TYPE_HBOX,
143 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
144 gtk_statusbar_buildable_interface_init));
147 gtk_statusbar_class_init (GtkStatusbarClass *class)
149 GObjectClass *gobject_class;
150 GtkObjectClass *object_class;
151 GtkWidgetClass *widget_class;
153 gobject_class = (GObjectClass *) class;
154 object_class = (GtkObjectClass *) class;
155 widget_class = (GtkWidgetClass *) class;
157 gobject_class->set_property = gtk_statusbar_set_property;
158 gobject_class->get_property = gtk_statusbar_get_property;
160 object_class->destroy = gtk_statusbar_destroy;
162 widget_class->realize = gtk_statusbar_realize;
163 widget_class->unrealize = gtk_statusbar_unrealize;
164 widget_class->map = gtk_statusbar_map;
165 widget_class->unmap = gtk_statusbar_unmap;
166 widget_class->button_press_event = gtk_statusbar_button_press;
167 widget_class->expose_event = gtk_statusbar_expose_event;
168 widget_class->size_request = gtk_statusbar_size_request;
169 widget_class->size_allocate = gtk_statusbar_size_allocate;
170 widget_class->direction_changed = gtk_statusbar_direction_changed;
171 widget_class->state_changed = gtk_statusbar_state_changed;
173 class->text_pushed = gtk_statusbar_update;
174 class->text_popped = gtk_statusbar_update;
177 * GtkStatusbar:has-resize-grip:
179 * Whether the statusbar has a grip for resizing the toplevel window.
183 g_object_class_install_property (gobject_class,
184 PROP_HAS_RESIZE_GRIP,
185 g_param_spec_boolean ("has-resize-grip",
186 P_("Has Resize Grip"),
187 P_("Whether the statusbar has a grip for resizing the toplevel"),
189 GTK_PARAM_READWRITE));
192 * GtkStatusbar::text-pushed:
193 * @statusbar: the object which received the signal.
194 * @context_id: the context id of the relevant message/statusbar.
195 * @text: the message that was pushed.
197 * Is emitted whenever a new message gets pushed onto a statusbar's stack.
199 statusbar_signals[SIGNAL_TEXT_PUSHED] =
200 g_signal_new (I_("text-pushed"),
201 G_OBJECT_CLASS_TYPE (class),
203 G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed),
205 _gtk_marshal_VOID__UINT_STRING,
211 * GtkStatusbar::text-popped:
212 * @statusbar: the object which received the signal.
213 * @context_id: the context id of the relevant message/statusbar.
214 * @text: the message that was just popped.
216 * Is emitted whenever a new message is popped off a statusbar's stack.
218 statusbar_signals[SIGNAL_TEXT_POPPED] =
219 g_signal_new (I_("text-popped"),
220 G_OBJECT_CLASS_TYPE (class),
222 G_STRUCT_OFFSET (GtkStatusbarClass, text_popped),
224 _gtk_marshal_VOID__UINT_STRING,
229 gtk_widget_class_install_style_property (widget_class,
230 g_param_spec_enum ("shadow-type",
232 P_("Style of bevel around the statusbar text"),
233 GTK_TYPE_SHADOW_TYPE,
235 GTK_PARAM_READABLE));
239 gtk_statusbar_init (GtkStatusbar *statusbar)
242 GtkWidget *message_area;
243 GtkShadowType shadow_type;
245 box = GTK_BOX (statusbar);
247 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), TRUE);
250 box->homogeneous = FALSE;
252 statusbar->has_resize_grip = TRUE;
254 gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
256 statusbar->frame = gtk_frame_new (NULL);
257 gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
258 gtk_box_pack_start (box, statusbar->frame, TRUE, TRUE, 0);
259 gtk_widget_show (statusbar->frame);
261 message_area = gtk_hbox_new (FALSE, 4);
262 gtk_container_add (GTK_CONTAINER (statusbar->frame), message_area);
263 gtk_widget_show (message_area);
265 statusbar->label = gtk_label_new ("");
266 gtk_label_set_single_line_mode (GTK_LABEL (statusbar->label), TRUE);
267 gtk_misc_set_alignment (GTK_MISC (statusbar->label), 0.0, 0.5);
268 g_signal_connect (statusbar->label, "notify::selectable",
269 G_CALLBACK (label_selectable_changed), statusbar);
270 gtk_label_set_ellipsize (GTK_LABEL (statusbar->label), PANGO_ELLIPSIZE_END);
271 gtk_container_add (GTK_CONTAINER (message_area), statusbar->label);
272 gtk_widget_show (statusbar->label);
274 statusbar->seq_context_id = 1;
275 statusbar->seq_message_id = 1;
276 statusbar->messages = NULL;
277 statusbar->keys = NULL;
280 static GtkBuildableIface *parent_buildable_iface;
283 gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface)
285 parent_buildable_iface = g_type_interface_peek_parent (iface);
286 iface->get_internal_child = gtk_statusbar_buildable_get_internal_child;
290 gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
292 const gchar *childname)
294 if (strcmp (childname, "message_area") == 0)
295 return G_OBJECT (gtk_bin_get_child (GTK_BIN (GTK_STATUSBAR (buildable)->frame)));
297 return parent_buildable_iface->get_internal_child (buildable,
305 * Creates a new #GtkStatusbar ready for messages.
307 * Returns: the new #GtkStatusbar
310 gtk_statusbar_new (void)
312 return g_object_new (GTK_TYPE_STATUSBAR, NULL);
316 gtk_statusbar_update (GtkStatusbar *statusbar,
320 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
325 gtk_label_set_text (GTK_LABEL (statusbar->label), text);
329 * gtk_statusbar_get_context_id:
330 * @statusbar: a #GtkStatusbar
331 * @context_description: textual description of what context
332 * the new message is being used in
334 * Returns a new context identifier, given a description
335 * of the actual context. Note that the description is
336 * <emphasis>not</emphasis> shown in the UI.
338 * Returns: an integer id
341 gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
342 const gchar *context_description)
347 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
348 g_return_val_if_fail (context_description != NULL, 0);
350 /* we need to preserve namespaces on object datas */
351 string = g_strconcat ("gtk-status-bar-context:", context_description, NULL);
353 id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), string));
356 id = statusbar->seq_context_id++;
357 g_object_set_data_full (G_OBJECT (statusbar), string, GUINT_TO_POINTER (id), NULL);
358 statusbar->keys = g_slist_prepend (statusbar->keys, string);
367 * gtk_statusbar_push:
368 * @statusbar: a #GtkStatusbar
369 * @context_id: the message's context id, as returned by
370 * gtk_statusbar_get_context_id()
371 * @text: the message to add to the statusbar
373 * Pushes a new message onto a statusbar's stack.
375 * Returns: a message id that can be used with
376 * gtk_statusbar_remove().
379 gtk_statusbar_push (GtkStatusbar *statusbar,
383 GtkStatusbarMsg *msg;
385 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
386 g_return_val_if_fail (text != NULL, 0);
388 msg = g_slice_new (GtkStatusbarMsg);
389 msg->text = g_strdup (text);
390 msg->context_id = context_id;
391 msg->message_id = statusbar->seq_message_id++;
393 statusbar->messages = g_slist_prepend (statusbar->messages, msg);
395 g_signal_emit (statusbar,
396 statusbar_signals[SIGNAL_TEXT_PUSHED],
401 return msg->message_id;
406 * @statusbar: a #GtkStatusBar
407 * @context_id: a context identifier
409 * Removes the first message in the #GtkStatusBar's stack
410 * with the given context id.
412 * Note that this may not change the displayed message, if
413 * the message at the top of the stack has a different
417 gtk_statusbar_pop (GtkStatusbar *statusbar,
420 GtkStatusbarMsg *msg;
422 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
424 if (statusbar->messages)
428 for (list = statusbar->messages; list; list = list->next)
432 if (msg->context_id == context_id)
434 statusbar->messages = g_slist_remove_link (statusbar->messages,
437 g_slice_free (GtkStatusbarMsg, msg);
438 g_slist_free_1 (list);
444 msg = statusbar->messages ? statusbar->messages->data : NULL;
446 g_signal_emit (statusbar,
447 statusbar_signals[SIGNAL_TEXT_POPPED],
449 (guint) (msg ? msg->context_id : 0),
450 msg ? msg->text : NULL);
454 * gtk_statusbar_remove:
455 * @statusbar: a #GtkStatusBar
456 * @context_id: a context identifier
457 * @message_id: a message identifier, as returned by gtk_statusbar_push()
459 * Forces the removal of a message from a statusbar's stack.
460 * The exact @context_id and @message_id must be specified.
463 gtk_statusbar_remove (GtkStatusbar *statusbar,
467 GtkStatusbarMsg *msg;
469 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
470 g_return_if_fail (message_id > 0);
472 msg = statusbar->messages ? statusbar->messages->data : NULL;
477 /* care about signal emission if the topmost item is removed */
478 if (msg->context_id == context_id &&
479 msg->message_id == message_id)
481 gtk_statusbar_pop (statusbar, context_id);
485 for (list = statusbar->messages; list; list = list->next)
489 if (msg->context_id == context_id &&
490 msg->message_id == message_id)
492 statusbar->messages = g_slist_remove_link (statusbar->messages, list);
494 g_slice_free (GtkStatusbarMsg, msg);
495 g_slist_free_1 (list);
504 * gtk_statusbar_remove_all:
505 * @statusbar: a #GtkStatusBar
506 * @context_id: a context identifier
508 * Forces the removal of all messages from a statusbar's
509 * stack with the exact @context_id.
514 gtk_statusbar_remove_all (GtkStatusbar *statusbar,
517 GtkStatusbarMsg *msg;
520 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
522 if (statusbar->messages == NULL)
525 msg = statusbar->messages->data;
527 /* care about signal emission if the topmost item is removed */
528 if (msg->context_id == context_id)
530 gtk_statusbar_pop (statusbar, context_id);
533 list = statusbar->messages;
537 prev = statusbar->messages;
545 if (msg->context_id == context_id)
548 statusbar->messages = list->next;
550 prev->next = list->next;
553 g_slice_free (GtkStatusbarMsg, msg);
554 g_slist_free_1 (list);
557 prev = statusbar->messages;
570 * gtk_statusbar_set_has_resize_grip:
571 * @statusbar: a #GtkStatusBar
572 * @setting: %TRUE to have a resize grip
574 * Sets whether the statusbar has a resize grip.
578 gtk_statusbar_set_has_resize_grip (GtkStatusbar *statusbar,
581 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
583 setting = setting != FALSE;
585 if (setting != statusbar->has_resize_grip)
587 statusbar->has_resize_grip = setting;
588 gtk_widget_queue_resize (statusbar->label);
589 gtk_widget_queue_draw (GTK_WIDGET (statusbar));
591 if (gtk_widget_get_realized (GTK_WIDGET (statusbar)))
593 if (statusbar->has_resize_grip && statusbar->grip_window == NULL)
595 gtk_statusbar_create_window (statusbar);
596 if (gtk_widget_get_mapped (GTK_WIDGET (statusbar)))
597 gdk_window_show (statusbar->grip_window);
599 else if (!statusbar->has_resize_grip && statusbar->grip_window != NULL)
600 gtk_statusbar_destroy_window (statusbar);
603 g_object_notify (G_OBJECT (statusbar), "has-resize-grip");
608 * gtk_statusbar_get_has_resize_grip:
609 * @statusbar: a #GtkStatusBar
611 * Returns whether the statusbar has a resize grip.
613 * Returns: %TRUE if the statusbar has a resize grip.
616 gtk_statusbar_get_has_resize_grip (GtkStatusbar *statusbar)
618 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), FALSE);
620 return statusbar->has_resize_grip;
624 * gtk_statusbar_get_message_area:
625 * @statusbar: a #GtkStatusBar
627 * Retrieves the box containing the label widget.
634 gtk_statusbar_get_message_area (GtkStatusbar *statusbar)
636 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), NULL);
638 return gtk_bin_get_child (GTK_BIN (statusbar->frame));
642 gtk_statusbar_destroy (GtkObject *object)
644 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
647 for (list = statusbar->messages; list; list = list->next)
649 GtkStatusbarMsg *msg;
653 g_slice_free (GtkStatusbarMsg, msg);
655 g_slist_free (statusbar->messages);
656 statusbar->messages = NULL;
658 for (list = statusbar->keys; list; list = list->next)
660 g_slist_free (statusbar->keys);
661 statusbar->keys = NULL;
663 GTK_OBJECT_CLASS (gtk_statusbar_parent_class)->destroy (object);
667 gtk_statusbar_set_property (GObject *object,
672 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
676 case PROP_HAS_RESIZE_GRIP:
677 gtk_statusbar_set_has_resize_grip (statusbar, g_value_get_boolean (value));
680 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
686 gtk_statusbar_get_property (GObject *object,
691 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
695 case PROP_HAS_RESIZE_GRIP:
696 g_value_set_boolean (value, statusbar->has_resize_grip);
699 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
705 get_grip_edge (GtkStatusbar *statusbar)
707 GtkWidget *widget = GTK_WIDGET (statusbar);
709 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
710 return GDK_WINDOW_EDGE_SOUTH_EAST;
712 return GDK_WINDOW_EDGE_SOUTH_WEST;
716 get_grip_rect (GtkStatusbar *statusbar,
722 widget = GTK_WIDGET (statusbar);
724 /* These are in effect the max/default size of the grip. */
728 if (w > widget->allocation.width)
729 w = widget->allocation.width;
731 if (h > widget->allocation.height - widget->style->ythickness)
732 h = widget->allocation.height - widget->style->ythickness;
736 rect->y = widget->allocation.y + widget->allocation.height - h;
738 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
739 rect->x = widget->allocation.x + widget->allocation.width - w;
741 rect->x = widget->allocation.x + widget->style->xthickness;
745 set_grip_cursor (GtkStatusbar *statusbar)
747 if (statusbar->has_resize_grip && statusbar->grip_window != NULL)
749 GtkWidget *widget = GTK_WIDGET (statusbar);
750 GdkDisplay *display = gtk_widget_get_display (widget);
751 GdkCursorType cursor_type;
754 if (gtk_widget_is_sensitive (widget))
756 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
757 cursor_type = GDK_BOTTOM_RIGHT_CORNER;
759 cursor_type = GDK_BOTTOM_LEFT_CORNER;
761 cursor = gdk_cursor_new_for_display (display, cursor_type);
762 gdk_window_set_cursor (statusbar->grip_window, cursor);
763 gdk_cursor_unref (cursor);
766 gdk_window_set_cursor (statusbar->grip_window, NULL);
771 gtk_statusbar_create_window (GtkStatusbar *statusbar)
774 GdkWindowAttr attributes;
775 gint attributes_mask;
778 widget = GTK_WIDGET (statusbar);
780 g_return_if_fail (gtk_widget_get_realized (widget));
781 g_return_if_fail (statusbar->has_resize_grip);
783 get_grip_rect (statusbar, &rect);
785 attributes.x = rect.x;
786 attributes.y = rect.y;
787 attributes.width = rect.width;
788 attributes.height = rect.height;
789 attributes.window_type = GDK_WINDOW_CHILD;
790 attributes.wclass = GDK_INPUT_ONLY;
791 attributes.event_mask = gtk_widget_get_events (widget) |
792 GDK_BUTTON_PRESS_MASK;
794 attributes_mask = GDK_WA_X | GDK_WA_Y;
796 statusbar->grip_window = gdk_window_new (widget->window,
797 &attributes, attributes_mask);
799 gdk_window_set_user_data (statusbar->grip_window, widget);
801 gdk_window_raise (statusbar->grip_window);
803 set_grip_cursor (statusbar);
807 gtk_statusbar_direction_changed (GtkWidget *widget,
808 GtkTextDirection prev_dir)
810 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
812 set_grip_cursor (statusbar);
816 gtk_statusbar_state_changed (GtkWidget *widget,
817 GtkStateType previous_state)
819 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
821 set_grip_cursor (statusbar);
825 gtk_statusbar_destroy_window (GtkStatusbar *statusbar)
827 gdk_window_set_user_data (statusbar->grip_window, NULL);
828 gdk_window_destroy (statusbar->grip_window);
829 statusbar->grip_window = NULL;
833 gtk_statusbar_realize (GtkWidget *widget)
835 GtkStatusbar *statusbar;
837 statusbar = GTK_STATUSBAR (widget);
839 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize (widget);
841 if (statusbar->has_resize_grip)
842 gtk_statusbar_create_window (statusbar);
846 gtk_statusbar_unrealize (GtkWidget *widget)
848 GtkStatusbar *statusbar;
850 statusbar = GTK_STATUSBAR (widget);
852 if (statusbar->grip_window)
853 gtk_statusbar_destroy_window (statusbar);
855 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unrealize (widget);
859 gtk_statusbar_map (GtkWidget *widget)
861 GtkStatusbar *statusbar;
863 statusbar = GTK_STATUSBAR (widget);
865 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->map (widget);
867 if (statusbar->grip_window)
868 gdk_window_show (statusbar->grip_window);
872 gtk_statusbar_unmap (GtkWidget *widget)
874 GtkStatusbar *statusbar;
876 statusbar = GTK_STATUSBAR (widget);
878 if (statusbar->grip_window)
879 gdk_window_hide (statusbar->grip_window);
881 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unmap (widget);
885 gtk_statusbar_button_press (GtkWidget *widget,
886 GdkEventButton *event)
888 GtkStatusbar *statusbar;
892 statusbar = GTK_STATUSBAR (widget);
894 if (!statusbar->has_resize_grip ||
895 event->type != GDK_BUTTON_PRESS ||
896 event->window != statusbar->grip_window)
899 ancestor = gtk_widget_get_toplevel (widget);
901 if (!GTK_IS_WINDOW (ancestor))
904 edge = get_grip_edge (statusbar);
906 if (event->button == 1)
907 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
910 event->x_root, event->y_root,
912 else if (event->button == 2)
913 gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
915 event->x_root, event->y_root,
924 gtk_statusbar_expose_event (GtkWidget *widget,
925 GdkEventExpose *event)
927 GtkStatusbar *statusbar;
930 statusbar = GTK_STATUSBAR (widget);
932 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->expose_event (widget, event);
934 if (statusbar->has_resize_grip)
938 edge = get_grip_edge (statusbar);
940 get_grip_rect (statusbar, &rect);
942 gtk_paint_resize_grip (widget->style,
944 gtk_widget_get_state (widget),
950 /* don't draw grip over the frame, though you
951 * can click on the frame.
953 rect.width - widget->style->xthickness,
954 rect.height - widget->style->ythickness);
961 gtk_statusbar_size_request (GtkWidget *widget,
962 GtkRequisition *requisition)
964 GtkStatusbar *statusbar;
965 GtkShadowType shadow_type;
967 statusbar = GTK_STATUSBAR (widget);
969 gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
970 gtk_frame_set_shadow_type (GTK_FRAME (statusbar->frame), shadow_type);
972 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_request (widget, requisition);
975 /* look for extra children between the frame containing
976 * the label and where we want to draw the resize grip
979 has_extra_children (GtkStatusbar *statusbar)
982 GtkBoxChild *child, *frame;
984 /* If the internal frame has been modified assume we have extra children */
985 if (gtk_bin_get_child (GTK_BIN (statusbar->frame)) != statusbar->label)
989 for (l = GTK_BOX (statusbar)->children; l; l = l->next)
993 if (frame->widget == statusbar->frame)
997 for (l = l->next; l; l = l->next)
1001 if (!gtk_widget_get_visible (child->widget))
1004 if (frame->pack == GTK_PACK_START || child->pack == GTK_PACK_END)
1012 gtk_statusbar_size_allocate (GtkWidget *widget,
1013 GtkAllocation *allocation)
1015 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
1016 gboolean extra_children = FALSE;
1019 if (statusbar->has_resize_grip)
1021 get_grip_rect (statusbar, &rect);
1023 extra_children = has_extra_children (statusbar);
1025 /* If there are extra children, we don't want them to occupy
1026 * the space where we draw the resize grip, so we temporarily
1027 * shrink the allocation.
1028 * If there are no extra children, we want the frame to get
1029 * the full allocation, and we fix up the allocation of the
1030 * label afterwards to make room for the grip.
1034 allocation->width -= rect.width;
1035 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1036 allocation->x += rect.width;
1040 /* chain up normally */
1041 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
1043 if (statusbar->has_resize_grip)
1047 allocation->width += rect.width;
1048 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1049 allocation->x -= rect.width;
1051 widget->allocation = *allocation;
1057 /* Use the frame's child instead of statusbar->label directly, in case
1058 * the label has been replaced by a container as the frame's child
1059 * (and the label reparented into that container).
1061 child = gtk_bin_get_child (GTK_BIN (statusbar->frame));
1063 if (child->allocation.width + rect.width > statusbar->frame->allocation.width)
1065 /* shrink the label to make room for the grip */
1066 *allocation = child->allocation;
1067 allocation->width = MAX (1, allocation->width - rect.width);
1068 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1069 allocation->x += child->allocation.width - allocation->width;
1071 gtk_widget_size_allocate (child, allocation);
1075 if (statusbar->grip_window)
1077 get_grip_rect (statusbar, &rect);
1079 gdk_window_raise (statusbar->grip_window);
1080 gdk_window_move_resize (statusbar->grip_window,
1082 rect.width, rect.height);
1089 label_selectable_changed (GtkWidget *label,
1093 GtkStatusbar *statusbar = GTK_STATUSBAR (data);
1096 statusbar->has_resize_grip && statusbar->grip_window)
1097 gdk_window_raise (statusbar->grip_window);
1100 #define __GTK_STATUSBAR_C__
1101 #include "gtkaliasdef.c"