3 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
4 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
5 * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #include "gtktoolitem.h"
28 #include "gtkmarshalers.h"
29 #include "gtktoolshell.h"
30 #include "gtkseparatormenuitem.h"
31 #include "gtkactivatable.h"
34 #include "gtkprivate.h"
39 * @short_description: The base class of widgets that can be added to GtkToolShell
41 * @see_also: <variablelist>
43 * <term>#GtkToolbar</term>
44 * <listitem><para>The toolbar widget</para></listitem>
47 * <term>#GtkToolButton</term>
48 * <listitem><para>A subclass of #GtkToolItem that displays buttons on
49 * the toolbar</para></listitem>
52 * <term>#GtkSeparatorToolItem</term>
53 * <listitem><para>A subclass of #GtkToolItem that separates groups of
54 * items on a toolbar</para></listitem>
58 * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
59 * create a toolbar item that contain something else than a button, use
60 * gtk_tool_item_new(). Use gtk_container_add() to add a child
61 * widget to the tool item.
63 * For toolbar items that contain buttons, see the #GtkToolButton,
64 * #GtkToggleToolButton and #GtkRadioToolButton classes.
66 * See the #GtkToolbar class for a description of the toolbar widget, and
67 * #GtkToolShell for a description of the tool shell interface.
73 * The GtkToolItem struct contains only private data.
74 * It should only be accessed through the functions described below.
85 PROP_VISIBLE_HORIZONTAL,
86 PROP_VISIBLE_VERTICAL,
89 /* activatable properties */
90 PROP_ACTIVATABLE_RELATED_ACTION,
91 PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
94 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
96 struct _GtkToolItemPrivate
101 guint visible_horizontal : 1;
102 guint visible_vertical : 1;
103 guint homogeneous : 1;
105 guint use_drag_window : 1;
106 guint is_important : 1;
108 GdkWindow *drag_window;
111 GtkWidget *menu_item;
114 gboolean use_action_appearance;
117 static void gtk_tool_item_finalize (GObject *object);
118 static void gtk_tool_item_dispose (GObject *object);
119 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
121 static void gtk_tool_item_set_property (GObject *object,
125 static void gtk_tool_item_get_property (GObject *object,
129 static void gtk_tool_item_property_notify (GObject *object,
131 static void gtk_tool_item_realize (GtkWidget *widget);
132 static void gtk_tool_item_unrealize (GtkWidget *widget);
133 static void gtk_tool_item_map (GtkWidget *widget);
134 static void gtk_tool_item_unmap (GtkWidget *widget);
135 static void gtk_tool_item_size_request (GtkWidget *widget,
136 GtkRequisition *requisition);
137 static void gtk_tool_item_size_allocate (GtkWidget *widget,
138 GtkAllocation *allocation);
140 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface);
141 static void gtk_tool_item_update (GtkActivatable *activatable,
143 const gchar *property_name);
144 static void gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
146 static void gtk_tool_item_set_related_action (GtkToolItem *item,
148 static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
149 gboolean use_appearance);
151 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
153 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
154 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
155 gtk_tool_item_activatable_interface_init))
158 gtk_tool_item_class_init (GtkToolItemClass *klass)
160 GObjectClass *object_class;
161 GtkWidgetClass *widget_class;
163 object_class = (GObjectClass *)klass;
164 widget_class = (GtkWidgetClass *)klass;
166 object_class->set_property = gtk_tool_item_set_property;
167 object_class->get_property = gtk_tool_item_get_property;
168 object_class->finalize = gtk_tool_item_finalize;
169 object_class->dispose = gtk_tool_item_dispose;
170 object_class->notify = gtk_tool_item_property_notify;
172 widget_class->realize = gtk_tool_item_realize;
173 widget_class->unrealize = gtk_tool_item_unrealize;
174 widget_class->map = gtk_tool_item_map;
175 widget_class->unmap = gtk_tool_item_unmap;
176 widget_class->size_request = gtk_tool_item_size_request;
177 widget_class->size_allocate = gtk_tool_item_size_allocate;
178 widget_class->parent_set = gtk_tool_item_parent_set;
180 klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
182 g_object_class_install_property (object_class,
183 PROP_VISIBLE_HORIZONTAL,
184 g_param_spec_boolean ("visible-horizontal",
185 P_("Visible when horizontal"),
186 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
188 GTK_PARAM_READWRITE));
189 g_object_class_install_property (object_class,
190 PROP_VISIBLE_VERTICAL,
191 g_param_spec_boolean ("visible-vertical",
192 P_("Visible when vertical"),
193 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
195 GTK_PARAM_READWRITE));
196 g_object_class_install_property (object_class,
198 g_param_spec_boolean ("is-important",
200 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
202 GTK_PARAM_READWRITE));
204 g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
205 g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
209 * GtkToolItem::create-menu-proxy:
210 * @tool_item: the object the signal was emitted on
212 * This signal is emitted when the toolbar needs information from @tool_item
213 * about whether the item should appear in the toolbar overflow menu. In
214 * response the tool item should either
216 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
217 * pointer and return %TRUE to indicate that the item should not appear
218 * in the overflow menu
220 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
221 * item and return %TRUE, or
223 * <listitem> return %FALSE to indicate that the signal was not
224 * handled by the item. This means that
225 * the item will not appear in the overflow menu unless a later handler
226 * installs a menu item.
230 * The toolbar may cache the result of this signal. When the tool item changes
231 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
232 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
235 * Return value: %TRUE if the signal was handled, %FALSE if not
237 toolitem_signals[CREATE_MENU_PROXY] =
238 g_signal_new (I_("create-menu-proxy"),
239 G_OBJECT_CLASS_TYPE (klass),
241 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
242 _gtk_boolean_handled_accumulator, NULL,
243 _gtk_marshal_BOOLEAN__VOID,
247 * GtkToolItem::toolbar-reconfigured:
248 * @tool_item: the object the signal was emitted on
250 * This signal is emitted when some property of the toolbar that the
251 * item is a child of changes. For custom subclasses of #GtkToolItem,
252 * the default handler of this signal use the functions
254 * <listitem>gtk_tool_shell_get_orientation()</listitem>
255 * <listitem>gtk_tool_shell_get_style()</listitem>
256 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
257 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
259 * to find out what the toolbar should look like and change
260 * themselves accordingly.
262 toolitem_signals[TOOLBAR_RECONFIGURED] =
263 g_signal_new (I_("toolbar-reconfigured"),
264 G_OBJECT_CLASS_TYPE (klass),
266 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
268 _gtk_marshal_VOID__VOID,
271 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
275 gtk_tool_item_init (GtkToolItem *toolitem)
277 gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE);
279 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
281 toolitem->priv->visible_horizontal = TRUE;
282 toolitem->priv->visible_vertical = TRUE;
283 toolitem->priv->homogeneous = FALSE;
284 toolitem->priv->expand = FALSE;
286 toolitem->priv->use_action_appearance = TRUE;
290 gtk_tool_item_finalize (GObject *object)
292 GtkToolItem *item = GTK_TOOL_ITEM (object);
294 g_free (item->priv->menu_item_id);
296 if (item->priv->menu_item)
297 g_object_unref (item->priv->menu_item);
299 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
303 gtk_tool_item_dispose (GObject *object)
305 GtkToolItem *item = GTK_TOOL_ITEM (object);
307 if (item->priv->action)
309 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);
310 item->priv->action = NULL;
312 G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
317 gtk_tool_item_parent_set (GtkWidget *toolitem,
318 GtkWidget *prev_parent)
320 if (GTK_WIDGET (toolitem)->parent != NULL)
321 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
325 gtk_tool_item_set_property (GObject *object,
330 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
334 case PROP_VISIBLE_HORIZONTAL:
335 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
337 case PROP_VISIBLE_VERTICAL:
338 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
340 case PROP_IS_IMPORTANT:
341 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
343 case PROP_ACTIVATABLE_RELATED_ACTION:
344 gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
346 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
347 gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
350 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
356 gtk_tool_item_get_property (GObject *object,
361 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
365 case PROP_VISIBLE_HORIZONTAL:
366 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
368 case PROP_VISIBLE_VERTICAL:
369 g_value_set_boolean (value, toolitem->priv->visible_vertical);
371 case PROP_IS_IMPORTANT:
372 g_value_set_boolean (value, toolitem->priv->is_important);
374 case PROP_ACTIVATABLE_RELATED_ACTION:
375 g_value_set_object (value, toolitem->priv->action);
377 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
378 g_value_set_boolean (value, toolitem->priv->use_action_appearance);
381 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
387 gtk_tool_item_property_notify (GObject *object,
390 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
392 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
393 gtk_widget_set_sensitive (tool_item->priv->menu_item,
394 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
398 create_drag_window (GtkToolItem *toolitem)
401 GdkWindowAttr attributes;
402 gint attributes_mask, border_width;
404 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
406 widget = GTK_WIDGET (toolitem);
407 border_width = GTK_CONTAINER (toolitem)->border_width;
409 attributes.window_type = GDK_WINDOW_CHILD;
410 attributes.x = widget->allocation.x + border_width;
411 attributes.y = widget->allocation.y + border_width;
412 attributes.width = widget->allocation.width - border_width * 2;
413 attributes.height = widget->allocation.height - border_width * 2;
414 attributes.wclass = GDK_INPUT_ONLY;
415 attributes.event_mask = gtk_widget_get_events (widget);
416 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
418 attributes_mask = GDK_WA_X | GDK_WA_Y;
420 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
421 &attributes, attributes_mask);
422 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
426 gtk_tool_item_realize (GtkWidget *widget)
428 GtkToolItem *toolitem;
430 toolitem = GTK_TOOL_ITEM (widget);
431 gtk_widget_set_realized (widget, TRUE);
433 widget->window = gtk_widget_get_parent_window (widget);
434 g_object_ref (widget->window);
436 if (toolitem->priv->use_drag_window)
437 create_drag_window(toolitem);
439 widget->style = gtk_style_attach (widget->style, widget->window);
443 destroy_drag_window (GtkToolItem *toolitem)
445 if (toolitem->priv->drag_window)
447 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
448 gdk_window_destroy (toolitem->priv->drag_window);
449 toolitem->priv->drag_window = NULL;
454 gtk_tool_item_unrealize (GtkWidget *widget)
456 GtkToolItem *toolitem;
458 toolitem = GTK_TOOL_ITEM (widget);
460 destroy_drag_window (toolitem);
462 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
466 gtk_tool_item_map (GtkWidget *widget)
468 GtkToolItem *toolitem;
470 toolitem = GTK_TOOL_ITEM (widget);
471 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
472 if (toolitem->priv->drag_window)
473 gdk_window_show (toolitem->priv->drag_window);
477 gtk_tool_item_unmap (GtkWidget *widget)
479 GtkToolItem *toolitem;
481 toolitem = GTK_TOOL_ITEM (widget);
482 if (toolitem->priv->drag_window)
483 gdk_window_hide (toolitem->priv->drag_window);
484 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
488 gtk_tool_item_size_request (GtkWidget *widget,
489 GtkRequisition *requisition)
491 GtkWidget *child = GTK_BIN (widget)->child;
493 if (child && gtk_widget_get_visible (child))
495 gtk_widget_size_request (child, requisition);
499 requisition->height = 0;
500 requisition->width = 0;
503 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
504 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
508 gtk_tool_item_size_allocate (GtkWidget *widget,
509 GtkAllocation *allocation)
511 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
512 GtkAllocation child_allocation;
514 GtkWidget *child = GTK_BIN (widget)->child;
516 widget->allocation = *allocation;
517 border_width = GTK_CONTAINER (widget)->border_width;
519 if (toolitem->priv->drag_window)
520 gdk_window_move_resize (toolitem->priv->drag_window,
521 widget->allocation.x + border_width,
522 widget->allocation.y + border_width,
523 widget->allocation.width - border_width * 2,
524 widget->allocation.height - border_width * 2);
526 if (child && gtk_widget_get_visible (child))
528 child_allocation.x = allocation->x + border_width;
529 child_allocation.y = allocation->y + border_width;
530 child_allocation.width = allocation->width - 2 * border_width;
531 child_allocation.height = allocation->height - 2 * border_width;
533 gtk_widget_size_allocate (child, &child_allocation);
538 _gtk_tool_item_create_menu_proxy (GtkToolItem *item)
540 GtkWidget *menu_item;
541 gboolean visible_overflown;
543 if (item->priv->action)
545 g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
547 if (visible_overflown)
549 menu_item = gtk_action_create_menu_item (item->priv->action);
551 g_object_ref_sink (menu_item);
552 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
553 g_object_unref (menu_item);
556 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
565 gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
567 iface->update = gtk_tool_item_update;
568 iface->sync_action_properties = gtk_tool_item_sync_action_properties;
572 gtk_tool_item_update (GtkActivatable *activatable,
574 const gchar *property_name)
576 if (strcmp (property_name, "visible") == 0)
578 if (gtk_action_is_visible (action))
579 gtk_widget_show (GTK_WIDGET (activatable));
581 gtk_widget_hide (GTK_WIDGET (activatable));
583 else if (strcmp (property_name, "sensitive") == 0)
584 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
585 else if (strcmp (property_name, "tooltip") == 0)
586 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
587 gtk_action_get_tooltip (action));
588 else if (strcmp (property_name, "visible-horizontal") == 0)
589 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
590 gtk_action_get_visible_horizontal (action));
591 else if (strcmp (property_name, "visible-vertical") == 0)
592 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
593 gtk_action_get_visible_vertical (action));
594 else if (strcmp (property_name, "is-important") == 0)
595 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
596 gtk_action_get_is_important (action));
600 gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
606 if (gtk_action_is_visible (action))
607 gtk_widget_show (GTK_WIDGET (activatable));
609 gtk_widget_hide (GTK_WIDGET (activatable));
611 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
613 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
614 gtk_action_get_tooltip (action));
615 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
616 gtk_action_get_visible_horizontal (action));
617 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
618 gtk_action_get_visible_vertical (action));
619 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
620 gtk_action_get_is_important (action));
624 gtk_tool_item_set_related_action (GtkToolItem *item,
627 if (item->priv->action == action)
630 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
632 item->priv->action = action;
636 gtk_tool_item_rebuild_menu (item);
641 gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
642 gboolean use_appearance)
644 if (item->priv->use_action_appearance != use_appearance)
646 item->priv->use_action_appearance = use_appearance;
648 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action);
656 * Creates a new #GtkToolItem
658 * Return value: the new #GtkToolItem
663 gtk_tool_item_new (void)
667 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
673 * gtk_tool_item_get_ellipsize_mode:
674 * @tool_item: a #GtkToolItem
676 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
677 * #GtkToolItem should call this function to find out how text should
680 * Return value: a #PangoEllipsizeMode indicating how text in @tool_item
681 * should be ellipsized.
686 gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
690 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
692 parent = GTK_WIDGET (tool_item)->parent;
693 if (!parent || !GTK_IS_TOOL_SHELL (parent))
694 return PANGO_ELLIPSIZE_NONE;
696 return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
700 * gtk_tool_item_get_icon_size:
701 * @tool_item: a #GtkToolItem
703 * Returns the icon size used for @tool_item. Custom subclasses of
704 * #GtkToolItem should call this function to find out what size icons
707 * Return value: (type int): a #GtkIconSize indicating the icon size
708 * used for @tool_item
713 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
717 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
719 parent = GTK_WIDGET (tool_item)->parent;
720 if (!parent || !GTK_IS_TOOL_SHELL (parent))
721 return GTK_ICON_SIZE_LARGE_TOOLBAR;
723 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
727 * gtk_tool_item_get_orientation:
728 * @tool_item: a #GtkToolItem
730 * Returns the orientation used for @tool_item. Custom subclasses of
731 * #GtkToolItem should call this function to find out what size icons
734 * Return value: a #GtkOrientation indicating the orientation
735 * used for @tool_item
740 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
744 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
746 parent = GTK_WIDGET (tool_item)->parent;
747 if (!parent || !GTK_IS_TOOL_SHELL (parent))
748 return GTK_ORIENTATION_HORIZONTAL;
750 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
754 * gtk_tool_item_get_toolbar_style:
755 * @tool_item: a #GtkToolItem
757 * Returns the toolbar style used for @tool_item. Custom subclasses of
758 * #GtkToolItem should call this function in the handler of the
759 * GtkToolItem::toolbar_reconfigured signal to find out in what style
760 * the toolbar is displayed and change themselves accordingly
764 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
765 * both an icon and a label, stacked vertically </listitem>
766 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
767 * only icons </listitem>
768 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
769 * show text</listitem>
770 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
771 * both an icon and a label, arranged horizontally (however, note the
772 * #GtkToolButton::has_text_horizontally that makes tool buttons not
773 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
777 * Return value: A #GtkToolbarStyle indicating the toolbar style used
783 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
787 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
789 parent = GTK_WIDGET (tool_item)->parent;
790 if (!parent || !GTK_IS_TOOL_SHELL (parent))
791 return GTK_TOOLBAR_ICONS;
793 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
797 * gtk_tool_item_get_relief_style:
798 * @tool_item: a #GtkToolItem
800 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
801 * Custom subclasses of #GtkToolItem should call this function in the handler
802 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
803 * relief style of buttons.
805 * Return value: a #GtkReliefStyle indicating the relief style used
811 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
815 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
817 parent = GTK_WIDGET (tool_item)->parent;
818 if (!parent || !GTK_IS_TOOL_SHELL (parent))
819 return GTK_RELIEF_NONE;
821 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
825 * gtk_tool_item_get_text_alignment:
826 * @tool_item: a #GtkToolItem:
828 * Returns the text alignment used for @tool_item. Custom subclasses of
829 * #GtkToolItem should call this function to find out how text should
832 * Return value: a #gfloat indicating the horizontal text alignment
833 * used for @tool_item
838 gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
842 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
844 parent = GTK_WIDGET (tool_item)->parent;
845 if (!parent || !GTK_IS_TOOL_SHELL (parent))
848 return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
852 * gtk_tool_item_get_text_orientation:
853 * @tool_item: a #GtkToolItem
855 * Returns the text orientation used for @tool_item. Custom subclasses of
856 * #GtkToolItem should call this function to find out how text should
859 * Return value: a #GtkOrientation indicating the text orientation
860 * used for @tool_item
865 gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
869 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
871 parent = GTK_WIDGET (tool_item)->parent;
872 if (!parent || !GTK_IS_TOOL_SHELL (parent))
873 return GTK_ORIENTATION_HORIZONTAL;
875 return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
879 * gtk_tool_item_get_text_size_group:
880 * @tool_item: a #GtkToolItem
882 * Returns the size group used for labels in @tool_item. Custom subclasses of
883 * #GtkToolItem should call this function and use the size group for labels.
885 * Return value: a #GtkSizeGroup
890 gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
894 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
896 parent = GTK_WIDGET (tool_item)->parent;
897 if (!parent || !GTK_IS_TOOL_SHELL (parent))
900 return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
904 * gtk_tool_item_set_expand:
905 * @tool_item: a #GtkToolItem
906 * @expand: Whether @tool_item is allocated extra space
908 * Sets whether @tool_item is allocated extra space when there
909 * is more room on the toolbar then needed for the items. The
910 * effect is that the item gets bigger when the toolbar gets bigger
911 * and smaller when the toolbar gets smaller.
916 gtk_tool_item_set_expand (GtkToolItem *tool_item,
919 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
921 expand = expand != FALSE;
923 if (tool_item->priv->expand != expand)
925 tool_item->priv->expand = expand;
926 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
927 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
932 * gtk_tool_item_get_expand:
933 * @tool_item: a #GtkToolItem
935 * Returns whether @tool_item is allocated extra space.
936 * See gtk_tool_item_set_expand().
938 * Return value: %TRUE if @tool_item is allocated extra space.
943 gtk_tool_item_get_expand (GtkToolItem *tool_item)
945 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
947 return tool_item->priv->expand;
951 * gtk_tool_item_set_homogeneous:
952 * @tool_item: a #GtkToolItem
953 * @homogeneous: whether @tool_item is the same size as other homogeneous items
955 * Sets whether @tool_item is to be allocated the same size as other
956 * homogeneous items. The effect is that all homogeneous items will have
957 * the same width as the widest of the items.
962 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
963 gboolean homogeneous)
965 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
967 homogeneous = homogeneous != FALSE;
969 if (tool_item->priv->homogeneous != homogeneous)
971 tool_item->priv->homogeneous = homogeneous;
972 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
973 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
978 * gtk_tool_item_get_homogeneous:
979 * @tool_item: a #GtkToolItem
981 * Returns whether @tool_item is the same size as other homogeneous
982 * items. See gtk_tool_item_set_homogeneous().
984 * Return value: %TRUE if the item is the same size as other homogeneous
990 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
992 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
994 return tool_item->priv->homogeneous;
998 * gtk_tool_item_get_is_important:
999 * @tool_item: a #GtkToolItem
1001 * Returns whether @tool_item is considered important. See
1002 * gtk_tool_item_set_is_important()
1004 * Return value: %TRUE if @tool_item is considered important.
1009 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
1011 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1013 return tool_item->priv->is_important;
1017 * gtk_tool_item_set_is_important:
1018 * @tool_item: a #GtkToolItem
1019 * @is_important: whether the tool item should be considered important
1021 * Sets whether @tool_item should be considered important. The #GtkToolButton
1022 * class uses this property to determine whether to show or hide its label
1023 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1024 * only tool buttons with the "is_important" property set have labels, an
1025 * effect known as "priority text"
1030 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
1032 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1034 is_important = is_important != FALSE;
1036 if (is_important != tool_item->priv->is_important)
1038 tool_item->priv->is_important = is_important;
1040 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1042 g_object_notify (G_OBJECT (tool_item), "is-important");
1047 * gtk_tool_item_set_tooltip_text:
1048 * @tool_item: a #GtkToolItem
1049 * @text: text to be used as tooltip for @tool_item
1051 * Sets the text to be displayed as tooltip on the item.
1052 * See gtk_widget_set_tooltip_text().
1057 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1062 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1064 child = GTK_BIN (tool_item)->child;
1067 gtk_widget_set_tooltip_text (child, text);
1071 * gtk_tool_item_set_tooltip_markup:
1072 * @tool_item: a #GtkToolItem
1073 * @markup: markup text to be used as tooltip for @tool_item
1075 * Sets the markup text to be displayed as tooltip on the item.
1076 * See gtk_widget_set_tooltip_markup().
1081 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1082 const gchar *markup)
1086 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1088 child = GTK_BIN (tool_item)->child;
1091 gtk_widget_set_tooltip_markup (child, markup);
1095 * gtk_tool_item_set_use_drag_window:
1096 * @tool_item: a #GtkToolItem
1097 * @use_drag_window: Whether @tool_item has a drag window.
1099 * Sets whether @tool_item has a drag window. When %TRUE the
1100 * toolitem can be used as a drag source through gtk_drag_source_set().
1101 * When @tool_item has a drag window it will intercept all events,
1102 * even those that would otherwise be sent to a child of @tool_item.
1107 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1108 gboolean use_drag_window)
1110 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1112 use_drag_window = use_drag_window != FALSE;
1114 if (toolitem->priv->use_drag_window != use_drag_window)
1116 toolitem->priv->use_drag_window = use_drag_window;
1118 if (use_drag_window)
1120 if (!toolitem->priv->drag_window &&
1121 gtk_widget_get_realized (GTK_WIDGET (toolitem)))
1123 create_drag_window(toolitem);
1124 if (gtk_widget_get_mapped (GTK_WIDGET (toolitem)))
1125 gdk_window_show (toolitem->priv->drag_window);
1130 destroy_drag_window (toolitem);
1136 * gtk_tool_item_get_use_drag_window:
1137 * @tool_item: a #GtkToolItem
1139 * Returns whether @tool_item has a drag window. See
1140 * gtk_tool_item_set_use_drag_window().
1142 * Return value: %TRUE if @tool_item uses a drag window.
1147 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1149 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1151 return toolitem->priv->use_drag_window;
1155 * gtk_tool_item_set_visible_horizontal:
1156 * @tool_item: a #GtkToolItem
1157 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1159 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1164 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1165 gboolean visible_horizontal)
1167 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1169 visible_horizontal = visible_horizontal != FALSE;
1171 if (toolitem->priv->visible_horizontal != visible_horizontal)
1173 toolitem->priv->visible_horizontal = visible_horizontal;
1175 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1177 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1182 * gtk_tool_item_get_visible_horizontal:
1183 * @tool_item: a #GtkToolItem
1185 * Returns whether the @tool_item is visible on toolbars that are
1186 * docked horizontally.
1188 * Return value: %TRUE if @tool_item is visible on toolbars that are
1189 * docked horizontally.
1194 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1196 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1198 return toolitem->priv->visible_horizontal;
1202 * gtk_tool_item_set_visible_vertical:
1203 * @tool_item: a #GtkToolItem
1204 * @visible_vertical: whether @tool_item is visible when the toolbar
1205 * is in vertical mode
1207 * Sets whether @tool_item is visible when the toolbar is docked
1208 * vertically. Some tool items, such as text entries, are too wide to be
1209 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1210 * @tool_item will not appear on toolbars that are docked vertically.
1215 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1216 gboolean visible_vertical)
1218 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1220 visible_vertical = visible_vertical != FALSE;
1222 if (toolitem->priv->visible_vertical != visible_vertical)
1224 toolitem->priv->visible_vertical = visible_vertical;
1226 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1228 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1233 * gtk_tool_item_get_visible_vertical:
1234 * @tool_item: a #GtkToolItem
1236 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1237 * See gtk_tool_item_set_visible_vertical().
1239 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1244 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1246 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1248 return toolitem->priv->visible_vertical;
1252 * gtk_tool_item_retrieve_proxy_menu_item:
1253 * @tool_item: a #GtkToolItem
1255 * Returns the #GtkMenuItem that was last set by
1256 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1257 * that is going to appear in the overflow menu.
1259 * Return value: (transfer none): The #GtkMenuItem that is going to appear in the
1260 * overflow menu for @tool_item.
1265 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1269 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1271 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1274 return tool_item->priv->menu_item;
1278 * gtk_tool_item_get_proxy_menu_item:
1279 * @tool_item: a #GtkToolItem
1280 * @menu_item_id: a string used to identify the menu item
1282 * If @menu_item_id matches the string passed to
1283 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1285 * Custom subclasses of #GtkToolItem should use this function to update
1286 * their menu item when the #GtkToolItem changes. That the
1287 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1288 * inadvertently change a menu item that they did not create.
1290 * Return value: The #GtkMenuItem passed to
1291 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1296 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1297 const gchar *menu_item_id)
1299 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1300 g_return_val_if_fail (menu_item_id != NULL, NULL);
1302 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1303 return tool_item->priv->menu_item;
1309 * gtk_tool_item_rebuild_menu:
1310 * @tool_item: a #GtkToolItem
1312 * Calling this function signals to the toolbar that the
1313 * overflow menu item for @tool_item has changed. If the
1314 * overflow menu is visible when this function it called,
1315 * the menu will be rebuilt.
1317 * The function must be called when the tool item changes what it
1318 * will do in response to the #GtkToolItem::create-menu-proxy signal.
1323 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1327 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1329 widget = GTK_WIDGET (tool_item);
1331 if (GTK_IS_TOOL_SHELL (widget->parent))
1332 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent));
1336 * gtk_tool_item_set_proxy_menu_item:
1337 * @tool_item: a #GtkToolItem
1338 * @menu_item_id: a string used to identify @menu_item
1339 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1341 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1342 * @menu_item_id is used to identify the caller of this function and
1343 * should also be used with gtk_tool_item_get_proxy_menu_item().
1348 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1349 const gchar *menu_item_id,
1350 GtkWidget *menu_item)
1352 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1353 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1354 g_return_if_fail (menu_item_id != NULL);
1356 g_free (tool_item->priv->menu_item_id);
1358 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1360 if (tool_item->priv->menu_item != menu_item)
1362 if (tool_item->priv->menu_item)
1363 g_object_unref (tool_item->priv->menu_item);
1367 g_object_ref_sink (menu_item);
1369 gtk_widget_set_sensitive (menu_item,
1370 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
1373 tool_item->priv->menu_item = menu_item;
1378 * gtk_tool_item_toolbar_reconfigured:
1379 * @tool_item: a #GtkToolItem
1381 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1382 * #GtkToolbar and other #GtkToolShell implementations use this function
1383 * to notify children, when some aspect of their configuration changes.
1388 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1390 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1391 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1392 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1393 * Its not possible to rename the signal, and emitting another name than
1394 * indicated by the function name would be quite confusing. That's the
1395 * price of providing stable APIs.
1397 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1399 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1401 if (tool_item->priv->drag_window)
1402 gdk_window_raise (tool_item->priv->drag_window);
1404 gtk_widget_queue_resize (GTK_WIDGET (tool_item));