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 _GtkStatusbarPriv
83 GdkWindow *grip_window;
91 guint has_resize_grip : 1;
95 struct _GtkStatusbarMsg
115 static void gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface);
116 static GObject *gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
118 const gchar *childname);
119 static void gtk_statusbar_destroy (GtkObject *object);
120 static void gtk_statusbar_update (GtkStatusbar *statusbar,
123 static void gtk_statusbar_size_allocate (GtkWidget *widget,
124 GtkAllocation *allocation);
125 static void gtk_statusbar_realize (GtkWidget *widget);
126 static void gtk_statusbar_unrealize (GtkWidget *widget);
127 static void gtk_statusbar_map (GtkWidget *widget);
128 static void gtk_statusbar_unmap (GtkWidget *widget);
129 static gboolean gtk_statusbar_button_press (GtkWidget *widget,
130 GdkEventButton *event);
131 static gboolean gtk_statusbar_expose_event (GtkWidget *widget,
132 GdkEventExpose *event);
133 static void gtk_statusbar_size_request (GtkWidget *widget,
134 GtkRequisition *requisition);
135 static void gtk_statusbar_size_allocate (GtkWidget *widget,
136 GtkAllocation *allocation);
137 static void gtk_statusbar_direction_changed (GtkWidget *widget,
138 GtkTextDirection prev_dir);
139 static void gtk_statusbar_state_changed (GtkWidget *widget,
140 GtkStateType previous_state);
141 static void gtk_statusbar_create_window (GtkStatusbar *statusbar);
142 static void gtk_statusbar_destroy_window (GtkStatusbar *statusbar);
143 static void gtk_statusbar_get_property (GObject *object,
147 static void gtk_statusbar_set_property (GObject *object,
151 static void label_selectable_changed (GtkWidget *label,
156 static guint statusbar_signals[SIGNAL_LAST] = { 0 };
158 G_DEFINE_TYPE_WITH_CODE (GtkStatusbar, gtk_statusbar, GTK_TYPE_HBOX,
159 G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
160 gtk_statusbar_buildable_interface_init));
163 gtk_statusbar_class_init (GtkStatusbarClass *class)
165 GObjectClass *gobject_class;
166 GtkObjectClass *object_class;
167 GtkWidgetClass *widget_class;
169 gobject_class = (GObjectClass *) class;
170 object_class = (GtkObjectClass *) class;
171 widget_class = (GtkWidgetClass *) class;
173 gobject_class->set_property = gtk_statusbar_set_property;
174 gobject_class->get_property = gtk_statusbar_get_property;
176 object_class->destroy = gtk_statusbar_destroy;
178 widget_class->realize = gtk_statusbar_realize;
179 widget_class->unrealize = gtk_statusbar_unrealize;
180 widget_class->map = gtk_statusbar_map;
181 widget_class->unmap = gtk_statusbar_unmap;
182 widget_class->button_press_event = gtk_statusbar_button_press;
183 widget_class->expose_event = gtk_statusbar_expose_event;
184 widget_class->size_request = gtk_statusbar_size_request;
185 widget_class->size_allocate = gtk_statusbar_size_allocate;
186 widget_class->direction_changed = gtk_statusbar_direction_changed;
187 widget_class->state_changed = gtk_statusbar_state_changed;
189 class->text_pushed = gtk_statusbar_update;
190 class->text_popped = gtk_statusbar_update;
193 * GtkStatusbar:has-resize-grip:
195 * Whether the statusbar has a grip for resizing the toplevel window.
199 g_object_class_install_property (gobject_class,
200 PROP_HAS_RESIZE_GRIP,
201 g_param_spec_boolean ("has-resize-grip",
202 P_("Has Resize Grip"),
203 P_("Whether the statusbar has a grip for resizing the toplevel"),
205 GTK_PARAM_READWRITE));
208 * GtkStatusbar::text-pushed:
209 * @statusbar: the object which received the signal.
210 * @context_id: the context id of the relevant message/statusbar.
211 * @text: the message that was pushed.
213 * Is emitted whenever a new message gets pushed onto a statusbar's stack.
215 statusbar_signals[SIGNAL_TEXT_PUSHED] =
216 g_signal_new (I_("text-pushed"),
217 G_OBJECT_CLASS_TYPE (class),
219 G_STRUCT_OFFSET (GtkStatusbarClass, text_pushed),
221 _gtk_marshal_VOID__UINT_STRING,
227 * GtkStatusbar::text-popped:
228 * @statusbar: the object which received the signal.
229 * @context_id: the context id of the relevant message/statusbar.
230 * @text: the message that was just popped.
232 * Is emitted whenever a new message is popped off a statusbar's stack.
234 statusbar_signals[SIGNAL_TEXT_POPPED] =
235 g_signal_new (I_("text-popped"),
236 G_OBJECT_CLASS_TYPE (class),
238 G_STRUCT_OFFSET (GtkStatusbarClass, text_popped),
240 _gtk_marshal_VOID__UINT_STRING,
245 gtk_widget_class_install_style_property (widget_class,
246 g_param_spec_enum ("shadow-type",
248 P_("Style of bevel around the statusbar text"),
249 GTK_TYPE_SHADOW_TYPE,
251 GTK_PARAM_READABLE));
253 g_type_class_add_private (class, sizeof (GtkStatusbarPriv));
257 gtk_statusbar_init (GtkStatusbar *statusbar)
259 GtkStatusbarPriv *priv;
260 GtkBox *box = GTK_BOX (statusbar);
261 GtkWidget *message_area;
262 GtkShadowType shadow_type;
264 statusbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (statusbar,
267 priv = statusbar->priv;
269 gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), TRUE);
271 gtk_box_set_spacing (box, 2);
272 gtk_box_set_homogeneous (box, FALSE);
274 priv->has_resize_grip = TRUE;
276 gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
278 priv->frame = gtk_frame_new (NULL);
279 gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), shadow_type);
280 gtk_box_pack_start (box, priv->frame, TRUE, TRUE, 0);
281 gtk_widget_show (priv->frame);
283 message_area = gtk_hbox_new (FALSE, 4);
284 gtk_container_add (GTK_CONTAINER (priv->frame), message_area);
285 gtk_widget_show (message_area);
287 priv->label = gtk_label_new ("");
288 gtk_label_set_single_line_mode (GTK_LABEL (priv->label), TRUE);
289 gtk_misc_set_alignment (GTK_MISC (priv->label), 0.0, 0.5);
290 g_signal_connect (priv->label, "notify::selectable",
291 G_CALLBACK (label_selectable_changed), statusbar);
292 gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END);
293 gtk_container_add (GTK_CONTAINER (message_area), priv->label);
294 gtk_widget_show (priv->label);
296 priv->seq_context_id = 1;
297 priv->seq_message_id = 1;
298 priv->messages = NULL;
302 static GtkBuildableIface *parent_buildable_iface;
305 gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface)
307 parent_buildable_iface = g_type_interface_peek_parent (iface);
308 iface->get_internal_child = gtk_statusbar_buildable_get_internal_child;
312 gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
314 const gchar *childname)
316 GtkStatusbar *statusbar = GTK_STATUSBAR (buildable);
317 GtkStatusbarPriv *priv = statusbar->priv;
319 if (strcmp (childname, "message_area") == 0)
320 return G_OBJECT (gtk_bin_get_child (GTK_BIN (priv->frame)));
322 return parent_buildable_iface->get_internal_child (buildable,
330 * Creates a new #GtkStatusbar ready for messages.
332 * Returns: the new #GtkStatusbar
335 gtk_statusbar_new (void)
337 return g_object_new (GTK_TYPE_STATUSBAR, NULL);
341 gtk_statusbar_update (GtkStatusbar *statusbar,
345 GtkStatusbarPriv *priv;
347 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
349 priv = statusbar->priv;
354 gtk_label_set_text (GTK_LABEL (priv->label), text);
358 * gtk_statusbar_get_context_id:
359 * @statusbar: a #GtkStatusbar
360 * @context_description: textual description of what context
361 * the new message is being used in
363 * Returns a new context identifier, given a description
364 * of the actual context. Note that the description is
365 * <emphasis>not</emphasis> shown in the UI.
367 * Returns: an integer id
370 gtk_statusbar_get_context_id (GtkStatusbar *statusbar,
371 const gchar *context_description)
373 GtkStatusbarPriv *priv;
377 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
378 g_return_val_if_fail (context_description != NULL, 0);
380 priv = statusbar->priv;
382 /* we need to preserve namespaces on object datas */
383 string = g_strconcat ("gtk-status-bar-context:", context_description, NULL);
385 id = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (statusbar), string));
388 id = priv->seq_context_id++;
389 g_object_set_data_full (G_OBJECT (statusbar), string, GUINT_TO_POINTER (id), NULL);
390 priv->keys = g_slist_prepend (priv->keys, string);
399 * gtk_statusbar_push:
400 * @statusbar: a #GtkStatusbar
401 * @context_id: the message's context id, as returned by
402 * gtk_statusbar_get_context_id()
403 * @text: the message to add to the statusbar
405 * Pushes a new message onto a statusbar's stack.
407 * Returns: a message id that can be used with
408 * gtk_statusbar_remove().
411 gtk_statusbar_push (GtkStatusbar *statusbar,
415 GtkStatusbarPriv *priv;
416 GtkStatusbarMsg *msg;
418 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), 0);
419 g_return_val_if_fail (text != NULL, 0);
421 priv = statusbar->priv;
423 msg = g_slice_new (GtkStatusbarMsg);
424 msg->text = g_strdup (text);
425 msg->context_id = context_id;
426 msg->message_id = priv->seq_message_id++;
428 priv->messages = g_slist_prepend (priv->messages, msg);
430 g_signal_emit (statusbar,
431 statusbar_signals[SIGNAL_TEXT_PUSHED],
436 return msg->message_id;
441 * @statusbar: a #GtkStatusBar
442 * @context_id: a context identifier
444 * Removes the first message in the #GtkStatusBar's stack
445 * with the given context id.
447 * Note that this may not change the displayed message, if
448 * the message at the top of the stack has a different
452 gtk_statusbar_pop (GtkStatusbar *statusbar,
455 GtkStatusbarPriv *priv;
456 GtkStatusbarMsg *msg;
458 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
460 priv = statusbar->priv;
466 for (list = priv->messages; list; list = list->next)
470 if (msg->context_id == context_id)
472 priv->messages = g_slist_remove_link (priv->messages,
475 g_slice_free (GtkStatusbarMsg, msg);
476 g_slist_free_1 (list);
482 msg = priv->messages ? priv->messages->data : NULL;
484 g_signal_emit (statusbar,
485 statusbar_signals[SIGNAL_TEXT_POPPED],
487 (guint) (msg ? msg->context_id : 0),
488 msg ? msg->text : NULL);
492 * gtk_statusbar_remove:
493 * @statusbar: a #GtkStatusBar
494 * @context_id: a context identifier
495 * @message_id: a message identifier, as returned by gtk_statusbar_push()
497 * Forces the removal of a message from a statusbar's stack.
498 * The exact @context_id and @message_id must be specified.
501 gtk_statusbar_remove (GtkStatusbar *statusbar,
505 GtkStatusbarPriv *priv;
506 GtkStatusbarMsg *msg;
508 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
509 g_return_if_fail (message_id > 0);
511 priv = statusbar->priv;
513 msg = priv->messages ? priv->messages->data : NULL;
518 /* care about signal emission if the topmost item is removed */
519 if (msg->context_id == context_id &&
520 msg->message_id == message_id)
522 gtk_statusbar_pop (statusbar, context_id);
526 for (list = priv->messages; list; list = list->next)
530 if (msg->context_id == context_id &&
531 msg->message_id == message_id)
533 priv->messages = g_slist_remove_link (priv->messages, list);
535 g_slice_free (GtkStatusbarMsg, msg);
536 g_slist_free_1 (list);
545 * gtk_statusbar_remove_all:
546 * @statusbar: a #GtkStatusBar
547 * @context_id: a context identifier
549 * Forces the removal of all messages from a statusbar's
550 * stack with the exact @context_id.
555 gtk_statusbar_remove_all (GtkStatusbar *statusbar,
558 GtkStatusbarPriv *priv;
559 GtkStatusbarMsg *msg;
562 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
564 priv = statusbar->priv;
566 if (priv->messages == NULL)
569 msg = priv->messages->data;
571 /* care about signal emission if the topmost item is removed */
572 if (msg->context_id == context_id)
574 gtk_statusbar_pop (statusbar, context_id);
577 list = priv->messages;
581 prev = priv->messages;
589 if (msg->context_id == context_id)
592 priv->messages = list->next;
594 prev->next = list->next;
597 g_slice_free (GtkStatusbarMsg, msg);
598 g_slist_free_1 (list);
601 prev = priv->messages;
614 * gtk_statusbar_set_has_resize_grip:
615 * @statusbar: a #GtkStatusBar
616 * @setting: %TRUE to have a resize grip
618 * Sets whether the statusbar has a resize grip.
622 gtk_statusbar_set_has_resize_grip (GtkStatusbar *statusbar,
625 GtkStatusbarPriv *priv;
627 g_return_if_fail (GTK_IS_STATUSBAR (statusbar));
629 priv = statusbar->priv;
631 setting = setting != FALSE;
633 if (setting != priv->has_resize_grip)
635 priv->has_resize_grip = setting;
636 gtk_widget_queue_resize (priv->label);
637 gtk_widget_queue_draw (GTK_WIDGET (statusbar));
639 if (gtk_widget_get_realized (GTK_WIDGET (statusbar)))
641 if (priv->has_resize_grip && priv->grip_window == NULL)
643 gtk_statusbar_create_window (statusbar);
644 if (gtk_widget_get_mapped (GTK_WIDGET (statusbar)))
645 gdk_window_show (priv->grip_window);
647 else if (!priv->has_resize_grip && priv->grip_window != NULL)
648 gtk_statusbar_destroy_window (statusbar);
651 g_object_notify (G_OBJECT (statusbar), "has-resize-grip");
656 * gtk_statusbar_get_has_resize_grip:
657 * @statusbar: a #GtkStatusBar
659 * Returns whether the statusbar has a resize grip.
661 * Returns: %TRUE if the statusbar has a resize grip.
664 gtk_statusbar_get_has_resize_grip (GtkStatusbar *statusbar)
666 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), FALSE);
668 return statusbar->priv->has_resize_grip;
672 * gtk_statusbar_get_message_area:
673 * @statusbar: a #GtkStatusBar
675 * Retrieves the box containing the label widget.
682 gtk_statusbar_get_message_area (GtkStatusbar *statusbar)
684 GtkStatusbarPriv *priv;
686 g_return_val_if_fail (GTK_IS_STATUSBAR (statusbar), NULL);
688 priv = statusbar->priv;
690 return gtk_bin_get_child (GTK_BIN (priv->frame));
694 gtk_statusbar_destroy (GtkObject *object)
696 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
697 GtkStatusbarPriv *priv = statusbar->priv;
700 for (list = priv->messages; list; list = list->next)
702 GtkStatusbarMsg *msg;
706 g_slice_free (GtkStatusbarMsg, msg);
708 g_slist_free (priv->messages);
709 priv->messages = NULL;
711 for (list = priv->keys; list; list = list->next)
713 g_slist_free (priv->keys);
716 GTK_OBJECT_CLASS (gtk_statusbar_parent_class)->destroy (object);
720 gtk_statusbar_set_property (GObject *object,
725 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
729 case PROP_HAS_RESIZE_GRIP:
730 gtk_statusbar_set_has_resize_grip (statusbar, g_value_get_boolean (value));
733 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
739 gtk_statusbar_get_property (GObject *object,
744 GtkStatusbar *statusbar = GTK_STATUSBAR (object);
745 GtkStatusbarPriv *priv = statusbar->priv;
749 case PROP_HAS_RESIZE_GRIP:
750 g_value_set_boolean (value, priv->has_resize_grip);
753 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
759 get_grip_edge (GtkStatusbar *statusbar)
761 GtkWidget *widget = GTK_WIDGET (statusbar);
763 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
764 return GDK_WINDOW_EDGE_SOUTH_EAST;
766 return GDK_WINDOW_EDGE_SOUTH_WEST;
770 get_grip_rect (GtkStatusbar *statusbar,
773 GtkAllocation allocation;
775 GtkWidget *widget = GTK_WIDGET (statusbar);
778 gtk_widget_get_allocation (widget, &allocation);
779 style = gtk_widget_get_style (widget);
781 /* These are in effect the max/default size of the grip. */
785 if (w > allocation.width)
786 w = allocation.width;
788 if (h > allocation.height - style->ythickness)
789 h = allocation.height - style->ythickness;
793 rect->y = allocation.y + allocation.height - h;
795 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
796 rect->x = allocation.x + allocation.width - w;
798 rect->x = allocation.x + style->xthickness;
802 set_grip_cursor (GtkStatusbar *statusbar)
804 GtkStatusbarPriv *priv = statusbar->priv;
806 if (priv->has_resize_grip && priv->grip_window != NULL)
808 GtkWidget *widget = GTK_WIDGET (statusbar);
809 GdkDisplay *display = gtk_widget_get_display (widget);
810 GdkCursorType cursor_type;
813 if (gtk_widget_is_sensitive (widget))
815 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
816 cursor_type = GDK_BOTTOM_RIGHT_CORNER;
818 cursor_type = GDK_BOTTOM_LEFT_CORNER;
820 cursor = gdk_cursor_new_for_display (display, cursor_type);
821 gdk_window_set_cursor (priv->grip_window, cursor);
822 gdk_cursor_unref (cursor);
825 gdk_window_set_cursor (priv->grip_window, NULL);
830 gtk_statusbar_create_window (GtkStatusbar *statusbar)
833 GtkStatusbarPriv *priv = statusbar->priv;
834 GdkWindowAttr attributes;
835 gint attributes_mask;
838 widget = GTK_WIDGET (statusbar);
840 g_return_if_fail (gtk_widget_get_realized (widget));
841 g_return_if_fail (priv->has_resize_grip);
843 get_grip_rect (statusbar, &rect);
845 attributes.x = rect.x;
846 attributes.y = rect.y;
847 attributes.width = rect.width;
848 attributes.height = rect.height;
849 attributes.window_type = GDK_WINDOW_CHILD;
850 attributes.wclass = GDK_INPUT_ONLY;
851 attributes.event_mask = gtk_widget_get_events (widget) |
852 GDK_BUTTON_PRESS_MASK;
854 attributes_mask = GDK_WA_X | GDK_WA_Y;
856 priv->grip_window = gdk_window_new (gtk_widget_get_window (widget),
857 &attributes, attributes_mask);
858 gdk_window_set_user_data (priv->grip_window, widget);
860 gdk_window_raise (priv->grip_window);
862 set_grip_cursor (statusbar);
866 gtk_statusbar_direction_changed (GtkWidget *widget,
867 GtkTextDirection prev_dir)
869 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
871 set_grip_cursor (statusbar);
875 gtk_statusbar_state_changed (GtkWidget *widget,
876 GtkStateType previous_state)
878 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
880 set_grip_cursor (statusbar);
884 gtk_statusbar_destroy_window (GtkStatusbar *statusbar)
886 GtkStatusbarPriv *priv = statusbar->priv;
888 gdk_window_set_user_data (priv->grip_window, NULL);
889 gdk_window_destroy (priv->grip_window);
890 priv->grip_window = NULL;
894 gtk_statusbar_realize (GtkWidget *widget)
896 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
897 GtkStatusbarPriv *priv = statusbar->priv;
899 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize (widget);
901 if (priv->has_resize_grip)
902 gtk_statusbar_create_window (statusbar);
906 gtk_statusbar_unrealize (GtkWidget *widget)
908 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
909 GtkStatusbarPriv *priv = statusbar->priv;
911 if (priv->grip_window)
912 gtk_statusbar_destroy_window (statusbar);
914 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unrealize (widget);
918 gtk_statusbar_map (GtkWidget *widget)
920 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
921 GtkStatusbarPriv *priv = statusbar->priv;
923 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->map (widget);
925 if (priv->grip_window)
926 gdk_window_show (priv->grip_window);
930 gtk_statusbar_unmap (GtkWidget *widget)
932 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
933 GtkStatusbarPriv *priv = statusbar->priv;
935 if (priv->grip_window)
936 gdk_window_hide (priv->grip_window);
938 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unmap (widget);
942 gtk_statusbar_button_press (GtkWidget *widget,
943 GdkEventButton *event)
945 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
946 GtkStatusbarPriv *priv = statusbar->priv;
950 if (!priv->has_resize_grip ||
951 event->type != GDK_BUTTON_PRESS ||
952 event->window != priv->grip_window)
955 ancestor = gtk_widget_get_toplevel (widget);
957 if (!GTK_IS_WINDOW (ancestor))
960 edge = get_grip_edge (statusbar);
962 if (event->button == 1)
963 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
966 event->x_root, event->y_root,
968 else if (event->button == 2)
969 gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
971 event->x_root, event->y_root,
980 gtk_statusbar_expose_event (GtkWidget *widget,
981 GdkEventExpose *event)
983 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
984 GtkStatusbarPriv *priv = statusbar->priv;
988 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->expose_event (widget, event);
990 if (priv->has_resize_grip)
994 edge = get_grip_edge (statusbar);
996 get_grip_rect (statusbar, &rect);
998 style = gtk_widget_get_style (widget);
999 gtk_paint_resize_grip (style,
1000 gtk_widget_get_window (widget),
1001 gtk_widget_get_state (widget),
1007 /* don't draw grip over the frame, though you
1008 * can click on the frame.
1010 rect.width - style->xthickness,
1011 rect.height - style->ythickness);
1018 gtk_statusbar_size_request (GtkWidget *widget,
1019 GtkRequisition *requisition)
1021 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
1022 GtkStatusbarPriv *priv = statusbar->priv;
1023 GtkShadowType shadow_type;
1025 gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
1026 gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), shadow_type);
1028 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_request (widget, requisition);
1031 /* look for extra children between the frame containing
1032 * the label and where we want to draw the resize grip
1035 has_extra_children (GtkStatusbar *statusbar)
1037 GtkStatusbarPriv *priv = statusbar->priv;
1038 GtkPackType child_pack_type, frame_pack_type;
1039 GtkWidget *child, *frame;
1040 GList *l, *children;
1041 gboolean retval = FALSE;
1043 /* If the internal frame has been modified assume we have extra children */
1044 if (gtk_bin_get_child (GTK_BIN (priv->frame)) != priv->label)
1048 children = _gtk_box_get_children (GTK_BOX (statusbar));
1049 for (l = children; l; l = l->next)
1053 if (frame == priv->frame)
1057 gtk_box_query_child_packing (GTK_BOX (statusbar), frame,
1058 NULL, NULL, NULL, &frame_pack_type);
1060 for (l = l->next; l; l = l->next)
1064 if (!gtk_widget_get_visible (child))
1067 gtk_box_query_child_packing (GTK_BOX (statusbar), frame,
1068 NULL, NULL, NULL, &child_pack_type);
1070 if (frame_pack_type == GTK_PACK_START || child_pack_type == GTK_PACK_END)
1077 g_list_free (children);
1083 gtk_statusbar_size_allocate (GtkWidget *widget,
1084 GtkAllocation *allocation)
1086 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
1087 GtkStatusbarPriv *priv = statusbar->priv;
1088 gboolean extra_children = FALSE;
1091 if (priv->has_resize_grip)
1093 get_grip_rect (statusbar, &rect);
1095 extra_children = has_extra_children (statusbar);
1097 /* If there are extra children, we don't want them to occupy
1098 * the space where we draw the resize grip, so we temporarily
1099 * shrink the allocation.
1100 * If there are no extra children, we want the frame to get
1101 * the full allocation, and we fix up the allocation of the
1102 * label afterwards to make room for the grip.
1106 allocation->width -= rect.width;
1107 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1108 allocation->x += rect.width;
1112 /* chain up normally */
1113 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
1115 if (priv->has_resize_grip)
1119 allocation->width += rect.width;
1120 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1121 allocation->x -= rect.width;
1123 gtk_widget_set_allocation (widget, allocation);
1127 GtkAllocation child_allocation, frame_allocation;
1130 /* Use the frame's child instead of priv->label directly, in case
1131 * the label has been replaced by a container as the frame's child
1132 * (and the label reparented into that container).
1134 child = gtk_bin_get_child (GTK_BIN (priv->frame));
1136 gtk_widget_get_allocation (child, &child_allocation);
1137 gtk_widget_get_allocation (priv->frame, &frame_allocation);
1138 if (child_allocation.width + rect.width > frame_allocation.width)
1140 /* shrink the label to make room for the grip */
1141 *allocation = child_allocation;
1142 allocation->width = MAX (1, allocation->width - rect.width);
1143 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1144 allocation->x += child_allocation.width - allocation->width;
1146 gtk_widget_size_allocate (child, allocation);
1150 if (priv->grip_window)
1152 get_grip_rect (statusbar, &rect);
1154 gdk_window_raise (priv->grip_window);
1155 gdk_window_move_resize (priv->grip_window,
1157 rect.width, rect.height);
1164 label_selectable_changed (GtkWidget *label,
1168 GtkStatusbar *statusbar = GTK_STATUSBAR (data);
1169 GtkStatusbarPriv *priv = statusbar->priv;
1172 priv->has_resize_grip && priv->grip_window)
1173 gdk_window_raise (priv->grip_window);