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 _GtkStatusbarPrivate
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_draw (GtkWidget *widget,
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->draw = gtk_statusbar_draw;
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 (GtkStatusbarPrivate));
257 gtk_statusbar_init (GtkStatusbar *statusbar)
259 GtkStatusbarPrivate *priv;
260 GtkBox *box = GTK_BOX (statusbar);
261 GtkWidget *message_area;
262 GtkShadowType shadow_type;
264 statusbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (statusbar,
266 GtkStatusbarPrivate);
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 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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.
677 * Returns: (transfer none): a #GtkBox
682 gtk_statusbar_get_message_area (GtkStatusbar *statusbar)
684 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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 GtkStatusbarPrivate *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,
771 gboolean include_allocation_offset,
774 GtkAllocation allocation;
776 GtkWidget *widget = GTK_WIDGET (statusbar);
779 gtk_widget_get_allocation (widget, &allocation);
780 style = gtk_widget_get_style (widget);
782 /* These are in effect the max/default size of the grip. */
786 if (w > allocation.width)
787 w = allocation.width;
789 if (h > allocation.height - style->ythickness)
790 h = allocation.height - style->ythickness;
794 rect->y = allocation.height - h;
796 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
797 rect->x = allocation.width - w;
799 rect->x = style->xthickness;
801 if (include_allocation_offset)
803 rect->x += allocation.x;
804 rect->y += allocation.y;
809 set_grip_cursor (GtkStatusbar *statusbar)
811 GtkStatusbarPrivate *priv = statusbar->priv;
813 if (priv->has_resize_grip && priv->grip_window != NULL)
815 GtkWidget *widget = GTK_WIDGET (statusbar);
816 GdkDisplay *display = gtk_widget_get_display (widget);
817 GdkCursorType cursor_type;
820 if (gtk_widget_is_sensitive (widget))
822 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
823 cursor_type = GDK_BOTTOM_RIGHT_CORNER;
825 cursor_type = GDK_BOTTOM_LEFT_CORNER;
827 cursor = gdk_cursor_new_for_display (display, cursor_type);
828 gdk_window_set_cursor (priv->grip_window, cursor);
829 gdk_cursor_unref (cursor);
832 gdk_window_set_cursor (priv->grip_window, NULL);
837 gtk_statusbar_create_window (GtkStatusbar *statusbar)
840 GtkStatusbarPrivate *priv = statusbar->priv;
841 GdkWindowAttr attributes;
842 gint attributes_mask;
845 widget = GTK_WIDGET (statusbar);
847 g_return_if_fail (gtk_widget_get_realized (widget));
848 g_return_if_fail (priv->has_resize_grip);
850 get_grip_rect (statusbar, TRUE, &rect);
852 attributes.x = rect.x;
853 attributes.y = rect.y;
854 attributes.width = rect.width;
855 attributes.height = rect.height;
856 attributes.window_type = GDK_WINDOW_CHILD;
857 attributes.wclass = GDK_INPUT_ONLY;
858 attributes.event_mask = gtk_widget_get_events (widget) |
859 GDK_BUTTON_PRESS_MASK;
861 attributes_mask = GDK_WA_X | GDK_WA_Y;
863 priv->grip_window = gdk_window_new (gtk_widget_get_window (widget),
864 &attributes, attributes_mask);
865 gdk_window_set_user_data (priv->grip_window, widget);
867 gdk_window_raise (priv->grip_window);
869 set_grip_cursor (statusbar);
873 gtk_statusbar_direction_changed (GtkWidget *widget,
874 GtkTextDirection prev_dir)
876 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
878 set_grip_cursor (statusbar);
882 gtk_statusbar_state_changed (GtkWidget *widget,
883 GtkStateType previous_state)
885 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
887 set_grip_cursor (statusbar);
891 gtk_statusbar_destroy_window (GtkStatusbar *statusbar)
893 GtkStatusbarPrivate *priv = statusbar->priv;
895 gdk_window_set_user_data (priv->grip_window, NULL);
896 gdk_window_destroy (priv->grip_window);
897 priv->grip_window = NULL;
901 gtk_statusbar_realize (GtkWidget *widget)
903 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
904 GtkStatusbarPrivate *priv = statusbar->priv;
906 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->realize (widget);
908 if (priv->has_resize_grip)
909 gtk_statusbar_create_window (statusbar);
913 gtk_statusbar_unrealize (GtkWidget *widget)
915 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
916 GtkStatusbarPrivate *priv = statusbar->priv;
918 if (priv->grip_window)
919 gtk_statusbar_destroy_window (statusbar);
921 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unrealize (widget);
925 gtk_statusbar_map (GtkWidget *widget)
927 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
928 GtkStatusbarPrivate *priv = statusbar->priv;
930 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->map (widget);
932 if (priv->grip_window)
933 gdk_window_show (priv->grip_window);
937 gtk_statusbar_unmap (GtkWidget *widget)
939 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
940 GtkStatusbarPrivate *priv = statusbar->priv;
942 if (priv->grip_window)
943 gdk_window_hide (priv->grip_window);
945 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->unmap (widget);
949 gtk_statusbar_button_press (GtkWidget *widget,
950 GdkEventButton *event)
952 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
953 GtkStatusbarPrivate *priv = statusbar->priv;
957 if (!priv->has_resize_grip ||
958 event->type != GDK_BUTTON_PRESS ||
959 event->window != priv->grip_window)
962 ancestor = gtk_widget_get_toplevel (widget);
964 if (!GTK_IS_WINDOW (ancestor))
967 edge = get_grip_edge (statusbar);
969 if (event->button == 1)
970 gtk_window_begin_resize_drag (GTK_WINDOW (ancestor),
973 event->x_root, event->y_root,
975 else if (event->button == 2)
976 gtk_window_begin_move_drag (GTK_WINDOW (ancestor),
978 event->x_root, event->y_root,
987 gtk_statusbar_draw (GtkWidget *widget,
990 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
991 GtkStatusbarPrivate *priv = statusbar->priv;
995 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->draw (widget, cr);
997 if (priv->has_resize_grip)
1001 edge = get_grip_edge (statusbar);
1003 get_grip_rect (statusbar, FALSE, &rect);
1005 style = gtk_widget_get_style (widget);
1006 gtk_cairo_paint_resize_grip (style,
1008 gtk_widget_get_state (widget),
1013 /* don't draw grip over the frame, though you
1014 * can click on the frame.
1016 rect.width - style->xthickness,
1017 rect.height - style->ythickness);
1024 gtk_statusbar_size_request (GtkWidget *widget,
1025 GtkRequisition *requisition)
1027 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
1028 GtkStatusbarPrivate *priv = statusbar->priv;
1029 GtkShadowType shadow_type;
1031 gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
1032 gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), shadow_type);
1034 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_request (widget, requisition);
1037 /* look for extra children between the frame containing
1038 * the label and where we want to draw the resize grip
1041 has_extra_children (GtkStatusbar *statusbar)
1043 GtkStatusbarPrivate *priv = statusbar->priv;
1044 GtkPackType child_pack_type, frame_pack_type;
1045 GtkWidget *child, *frame;
1046 GList *l, *children;
1047 gboolean retval = FALSE;
1049 /* If the internal frame has been modified assume we have extra children */
1050 if (gtk_bin_get_child (GTK_BIN (priv->frame)) != priv->label)
1054 children = _gtk_box_get_children (GTK_BOX (statusbar));
1055 for (l = children; l; l = l->next)
1059 if (frame == priv->frame)
1063 gtk_box_query_child_packing (GTK_BOX (statusbar), frame,
1064 NULL, NULL, NULL, &frame_pack_type);
1066 for (l = l->next; l; l = l->next)
1070 if (!gtk_widget_get_visible (child))
1073 gtk_box_query_child_packing (GTK_BOX (statusbar), frame,
1074 NULL, NULL, NULL, &child_pack_type);
1076 if (frame_pack_type == GTK_PACK_START || child_pack_type == GTK_PACK_END)
1083 g_list_free (children);
1089 gtk_statusbar_size_allocate (GtkWidget *widget,
1090 GtkAllocation *allocation)
1092 GtkStatusbar *statusbar = GTK_STATUSBAR (widget);
1093 GtkStatusbarPrivate *priv = statusbar->priv;
1094 gboolean extra_children = FALSE;
1097 if (priv->has_resize_grip)
1099 get_grip_rect (statusbar, TRUE, &rect);
1101 extra_children = has_extra_children (statusbar);
1103 /* If there are extra children, we don't want them to occupy
1104 * the space where we draw the resize grip, so we temporarily
1105 * shrink the allocation.
1106 * If there are no extra children, we want the frame to get
1107 * the full allocation, and we fix up the allocation of the
1108 * label afterwards to make room for the grip.
1112 allocation->width -= rect.width;
1113 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1114 allocation->x += rect.width;
1118 /* chain up normally */
1119 GTK_WIDGET_CLASS (gtk_statusbar_parent_class)->size_allocate (widget, allocation);
1121 if (priv->has_resize_grip)
1125 allocation->width += rect.width;
1126 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1127 allocation->x -= rect.width;
1129 gtk_widget_set_allocation (widget, allocation);
1133 GtkAllocation child_allocation, frame_allocation;
1136 /* Use the frame's child instead of priv->label directly, in case
1137 * the label has been replaced by a container as the frame's child
1138 * (and the label reparented into that container).
1140 child = gtk_bin_get_child (GTK_BIN (priv->frame));
1142 gtk_widget_get_allocation (child, &child_allocation);
1143 gtk_widget_get_allocation (priv->frame, &frame_allocation);
1144 if (child_allocation.width + rect.width > frame_allocation.width)
1146 /* shrink the label to make room for the grip */
1147 *allocation = child_allocation;
1148 allocation->width = MAX (1, allocation->width - rect.width);
1149 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1150 allocation->x += child_allocation.width - allocation->width;
1152 gtk_widget_size_allocate (child, allocation);
1156 if (priv->grip_window)
1158 get_grip_rect (statusbar, TRUE, &rect);
1160 gdk_window_raise (priv->grip_window);
1161 gdk_window_move_resize (priv->grip_window,
1163 rect.width, rect.height);
1170 label_selectable_changed (GtkWidget *label,
1174 GtkStatusbar *statusbar = GTK_STATUSBAR (data);
1175 GtkStatusbarPrivate *priv = statusbar->priv;
1178 priv->has_resize_grip && priv->grip_window)
1179 gdk_window_raise (priv->grip_window);