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 #undef GTK_DISABLE_DEPRECATED /* GtkTooltips */
29 #include "gtktoolitem.h"
30 #include "gtkmarshalers.h"
31 #include "gtktoolshell.h"
32 #include "gtkseparatormenuitem.h"
33 #include "gtkactivatable.h"
36 #include "gtkprivate.h"
41 * @short_description: The base class of widgets that can be added to GtkToolShell
42 * @see_also: <variablelist>
44 * <term>#GtkToolbar</term>
45 * <listitem><para>The toolbar widget</para></listitem>
48 * <term>#GtkToolButton</term>
49 * <listitem><para>A subclass of #GtkToolItem that displays buttons on
50 * the toolbar</para></listitem>
53 * <term>#GtkSeparatorToolItem</term>
54 * <listitem><para>A subclass of #GtkToolItem that separates groups of
55 * items on a toolbar</para></listitem>
59 * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
60 * create a toolbar item that contain something else than a button, use
61 * gtk_tool_item_new(). Use gtk_container_add() to add a child
62 * widget to the tool item.
64 * For toolbar items that contain buttons, see the #GtkToolButton,
65 * #GtkToggleToolButton and #GtkRadioToolButton classes.
67 * See the #GtkToolbar class for a description of the toolbar widget, and
68 * #GtkToolShell for a description of the tool shell interface.
74 * The GtkToolItem struct contains only private data.
75 * It should only be accessed through the functions described below.
87 PROP_VISIBLE_HORIZONTAL,
88 PROP_VISIBLE_VERTICAL,
91 /* activatable properties */
92 PROP_ACTIVATABLE_RELATED_ACTION,
93 PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
96 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
98 struct _GtkToolItemPrivate
103 guint visible_horizontal : 1;
104 guint visible_vertical : 1;
105 guint homogeneous : 1;
107 guint use_drag_window : 1;
108 guint is_important : 1;
110 GdkWindow *drag_window;
113 GtkWidget *menu_item;
116 gboolean use_action_appearance;
119 static void gtk_tool_item_finalize (GObject *object);
120 static void gtk_tool_item_dispose (GObject *object);
121 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
123 static void gtk_tool_item_set_property (GObject *object,
127 static void gtk_tool_item_get_property (GObject *object,
131 static void gtk_tool_item_property_notify (GObject *object,
133 static void gtk_tool_item_realize (GtkWidget *widget);
134 static void gtk_tool_item_unrealize (GtkWidget *widget);
135 static void gtk_tool_item_map (GtkWidget *widget);
136 static void gtk_tool_item_unmap (GtkWidget *widget);
137 static void gtk_tool_item_size_request (GtkWidget *widget,
138 GtkRequisition *requisition);
139 static void gtk_tool_item_size_allocate (GtkWidget *widget,
140 GtkAllocation *allocation);
141 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
142 GtkTooltips *tooltips,
143 const gchar *tip_text,
144 const gchar *tip_private);
146 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface);
147 static void gtk_tool_item_update (GtkActivatable *activatable,
149 const gchar *property_name);
150 static void gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
152 static void gtk_tool_item_set_related_action (GtkToolItem *item,
154 static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
155 gboolean use_appearance);
157 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
159 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
160 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
161 gtk_tool_item_activatable_interface_init))
164 gtk_tool_item_class_init (GtkToolItemClass *klass)
166 GObjectClass *object_class;
167 GtkWidgetClass *widget_class;
169 object_class = (GObjectClass *)klass;
170 widget_class = (GtkWidgetClass *)klass;
172 object_class->set_property = gtk_tool_item_set_property;
173 object_class->get_property = gtk_tool_item_get_property;
174 object_class->finalize = gtk_tool_item_finalize;
175 object_class->dispose = gtk_tool_item_dispose;
176 object_class->notify = gtk_tool_item_property_notify;
178 widget_class->realize = gtk_tool_item_realize;
179 widget_class->unrealize = gtk_tool_item_unrealize;
180 widget_class->map = gtk_tool_item_map;
181 widget_class->unmap = gtk_tool_item_unmap;
182 widget_class->size_request = gtk_tool_item_size_request;
183 widget_class->size_allocate = gtk_tool_item_size_allocate;
184 widget_class->parent_set = gtk_tool_item_parent_set;
186 klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
187 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
189 g_object_class_install_property (object_class,
190 PROP_VISIBLE_HORIZONTAL,
191 g_param_spec_boolean ("visible-horizontal",
192 P_("Visible when horizontal"),
193 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
195 GTK_PARAM_READWRITE));
196 g_object_class_install_property (object_class,
197 PROP_VISIBLE_VERTICAL,
198 g_param_spec_boolean ("visible-vertical",
199 P_("Visible when vertical"),
200 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
202 GTK_PARAM_READWRITE));
203 g_object_class_install_property (object_class,
205 g_param_spec_boolean ("is-important",
207 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
209 GTK_PARAM_READWRITE));
211 g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
212 g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
216 * GtkToolItem::create-menu-proxy:
217 * @tool_item: the object the signal was emitted on
219 * This signal is emitted when the toolbar needs information from @tool_item
220 * about whether the item should appear in the toolbar overflow menu. In
221 * response the tool item should either
223 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
224 * pointer and return %TRUE to indicate that the item should not appear
225 * in the overflow menu
227 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
228 * item and return %TRUE, or
230 * <listitem> return %FALSE to indicate that the signal was not
231 * handled by the item. This means that
232 * the item will not appear in the overflow menu unless a later handler
233 * installs a menu item.
237 * The toolbar may cache the result of this signal. When the tool item changes
238 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
239 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
242 * Return value: %TRUE if the signal was handled, %FALSE if not
244 toolitem_signals[CREATE_MENU_PROXY] =
245 g_signal_new (I_("create-menu-proxy"),
246 G_OBJECT_CLASS_TYPE (klass),
248 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
249 _gtk_boolean_handled_accumulator, NULL,
250 _gtk_marshal_BOOLEAN__VOID,
254 * GtkToolItem::toolbar-reconfigured:
255 * @tool_item: the object the signal was emitted on
257 * This signal is emitted when some property of the toolbar that the
258 * item is a child of changes. For custom subclasses of #GtkToolItem,
259 * the default handler of this signal use the functions
261 * <listitem>gtk_tool_shell_get_orientation()</listitem>
262 * <listitem>gtk_tool_shell_get_style()</listitem>
263 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
264 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
266 * to find out what the toolbar should look like and change
267 * themselves accordingly.
269 toolitem_signals[TOOLBAR_RECONFIGURED] =
270 g_signal_new (I_("toolbar-reconfigured"),
271 G_OBJECT_CLASS_TYPE (klass),
273 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
275 _gtk_marshal_VOID__VOID,
278 * GtkToolItem::set-tooltip:
279 * @tool_item: the object the signal was emitted on
280 * @tooltips: the #GtkTooltips
281 * @tip_text: the tooltip text
282 * @tip_private: the tooltip private text
284 * This signal is emitted when the toolitem's tooltip changes.
285 * Application developers can use gtk_tool_item_set_tooltip() to
286 * set the item's tooltip.
288 * Return value: %TRUE if the signal was handled, %FALSE if not
290 * Deprecated: 2.12: With the new tooltip API, there is no
291 * need to use this signal anymore.
293 toolitem_signals[SET_TOOLTIP] =
294 g_signal_new (I_("set-tooltip"),
295 G_OBJECT_CLASS_TYPE (klass),
297 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
298 _gtk_boolean_handled_accumulator, NULL,
299 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
305 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
309 gtk_tool_item_init (GtkToolItem *toolitem)
311 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
313 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
315 toolitem->priv->visible_horizontal = TRUE;
316 toolitem->priv->visible_vertical = TRUE;
317 toolitem->priv->homogeneous = FALSE;
318 toolitem->priv->expand = FALSE;
320 toolitem->priv->use_action_appearance = TRUE;
324 gtk_tool_item_finalize (GObject *object)
326 GtkToolItem *item = GTK_TOOL_ITEM (object);
328 g_free (item->priv->menu_item_id);
330 if (item->priv->menu_item)
331 g_object_unref (item->priv->menu_item);
333 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
337 gtk_tool_item_dispose (GObject *object)
339 GtkToolItem *item = GTK_TOOL_ITEM (object);
341 if (item->priv->action)
343 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);
344 item->priv->action = NULL;
346 G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
351 gtk_tool_item_parent_set (GtkWidget *toolitem,
352 GtkWidget *prev_parent)
354 if (GTK_WIDGET (toolitem)->parent != NULL)
355 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
359 gtk_tool_item_set_property (GObject *object,
364 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
368 case PROP_VISIBLE_HORIZONTAL:
369 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
371 case PROP_VISIBLE_VERTICAL:
372 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
374 case PROP_IS_IMPORTANT:
375 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
377 case PROP_ACTIVATABLE_RELATED_ACTION:
378 gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
380 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
381 gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
384 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
390 gtk_tool_item_get_property (GObject *object,
395 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
399 case PROP_VISIBLE_HORIZONTAL:
400 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
402 case PROP_VISIBLE_VERTICAL:
403 g_value_set_boolean (value, toolitem->priv->visible_vertical);
405 case PROP_IS_IMPORTANT:
406 g_value_set_boolean (value, toolitem->priv->is_important);
408 case PROP_ACTIVATABLE_RELATED_ACTION:
409 g_value_set_object (value, toolitem->priv->action);
411 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
412 g_value_set_boolean (value, toolitem->priv->use_action_appearance);
415 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
421 gtk_tool_item_property_notify (GObject *object,
424 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
426 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
427 gtk_widget_set_sensitive (tool_item->priv->menu_item,
428 GTK_WIDGET_SENSITIVE (tool_item));
432 create_drag_window (GtkToolItem *toolitem)
435 GdkWindowAttr attributes;
436 gint attributes_mask, border_width;
438 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
440 widget = GTK_WIDGET (toolitem);
441 border_width = GTK_CONTAINER (toolitem)->border_width;
443 attributes.window_type = GDK_WINDOW_CHILD;
444 attributes.x = widget->allocation.x + border_width;
445 attributes.y = widget->allocation.y + border_width;
446 attributes.width = widget->allocation.width - border_width * 2;
447 attributes.height = widget->allocation.height - border_width * 2;
448 attributes.wclass = GDK_INPUT_ONLY;
449 attributes.event_mask = gtk_widget_get_events (widget);
450 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
452 attributes_mask = GDK_WA_X | GDK_WA_Y;
454 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
455 &attributes, attributes_mask);
456 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
460 gtk_tool_item_realize (GtkWidget *widget)
462 GtkToolItem *toolitem;
464 toolitem = GTK_TOOL_ITEM (widget);
465 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
467 widget->window = gtk_widget_get_parent_window (widget);
468 g_object_ref (widget->window);
470 if (toolitem->priv->use_drag_window)
471 create_drag_window(toolitem);
473 widget->style = gtk_style_attach (widget->style, widget->window);
477 destroy_drag_window (GtkToolItem *toolitem)
479 if (toolitem->priv->drag_window)
481 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
482 gdk_window_destroy (toolitem->priv->drag_window);
483 toolitem->priv->drag_window = NULL;
488 gtk_tool_item_unrealize (GtkWidget *widget)
490 GtkToolItem *toolitem;
492 toolitem = GTK_TOOL_ITEM (widget);
494 destroy_drag_window (toolitem);
496 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
500 gtk_tool_item_map (GtkWidget *widget)
502 GtkToolItem *toolitem;
504 toolitem = GTK_TOOL_ITEM (widget);
505 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
506 if (toolitem->priv->drag_window)
507 gdk_window_show (toolitem->priv->drag_window);
511 gtk_tool_item_unmap (GtkWidget *widget)
513 GtkToolItem *toolitem;
515 toolitem = GTK_TOOL_ITEM (widget);
516 if (toolitem->priv->drag_window)
517 gdk_window_hide (toolitem->priv->drag_window);
518 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
522 gtk_tool_item_size_request (GtkWidget *widget,
523 GtkRequisition *requisition)
525 GtkWidget *child = GTK_BIN (widget)->child;
527 if (child && GTK_WIDGET_VISIBLE (child))
529 gtk_widget_size_request (child, requisition);
533 requisition->height = 0;
534 requisition->width = 0;
537 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
538 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
542 gtk_tool_item_size_allocate (GtkWidget *widget,
543 GtkAllocation *allocation)
545 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
546 GtkAllocation child_allocation;
548 GtkWidget *child = GTK_BIN (widget)->child;
550 widget->allocation = *allocation;
551 border_width = GTK_CONTAINER (widget)->border_width;
553 if (toolitem->priv->drag_window)
554 gdk_window_move_resize (toolitem->priv->drag_window,
555 widget->allocation.x + border_width,
556 widget->allocation.y + border_width,
557 widget->allocation.width - border_width * 2,
558 widget->allocation.height - border_width * 2);
560 if (child && GTK_WIDGET_VISIBLE (child))
562 child_allocation.x = allocation->x + border_width;
563 child_allocation.y = allocation->y + border_width;
564 child_allocation.width = allocation->width - 2 * border_width;
565 child_allocation.height = allocation->height - 2 * border_width;
567 gtk_widget_size_allocate (child, &child_allocation);
572 _gtk_tool_item_create_menu_proxy (GtkToolItem *item)
574 GtkWidget *menu_item;
575 gboolean visible_overflown;
577 if (item->priv->action)
579 g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
581 if (visible_overflown)
583 menu_item = gtk_action_create_menu_item (item->priv->action);
585 g_object_ref_sink (menu_item);
586 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
587 g_object_unref (menu_item);
590 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
599 gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
601 iface->update = gtk_tool_item_update;
602 iface->sync_action_properties = gtk_tool_item_sync_action_properties;
606 gtk_tool_item_update (GtkActivatable *activatable,
608 const gchar *property_name)
610 if (strcmp (property_name, "visible") == 0)
612 if (gtk_action_is_visible (action))
613 gtk_widget_show (GTK_WIDGET (activatable));
615 gtk_widget_hide (GTK_WIDGET (activatable));
617 else if (strcmp (property_name, "sensitive") == 0)
618 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
619 else if (strcmp (property_name, "tooltip") == 0)
620 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
621 gtk_action_get_tooltip (action));
622 else if (strcmp (property_name, "visible-horizontal") == 0)
623 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
624 gtk_action_get_visible_horizontal (action));
625 else if (strcmp (property_name, "visible-vertical") == 0)
626 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
627 gtk_action_get_visible_vertical (action));
628 else if (strcmp (property_name, "is-important") == 0)
629 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
630 gtk_action_get_is_important (action));
634 gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
640 if (gtk_action_is_visible (action))
641 gtk_widget_show (GTK_WIDGET (activatable));
643 gtk_widget_hide (GTK_WIDGET (activatable));
645 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
647 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
648 gtk_action_get_tooltip (action));
649 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
650 gtk_action_get_visible_horizontal (action));
651 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
652 gtk_action_get_visible_vertical (action));
653 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
654 gtk_action_get_is_important (action));
658 gtk_tool_item_set_related_action (GtkToolItem *item,
661 if (item->priv->action == action)
664 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
666 item->priv->action = action;
670 gtk_tool_item_rebuild_menu (item);
675 gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
676 gboolean use_appearance)
678 if (item->priv->use_action_appearance != use_appearance)
680 item->priv->use_action_appearance = use_appearance;
682 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action);
690 * Creates a new #GtkToolItem
692 * Return value: the new #GtkToolItem
697 gtk_tool_item_new (void)
701 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
707 * gtk_tool_item_get_ellipsize_mode:
708 * @tool_item: a #GtkToolItem
710 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
711 * #GtkToolItem should call this function to find out how text should
714 * Return value: a #PangoEllipsizeMode indicating how text in @tool_item
715 * should be ellipsized.
720 gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
724 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
726 parent = GTK_WIDGET (tool_item)->parent;
727 if (!parent || !GTK_IS_TOOL_SHELL (parent))
728 return PANGO_ELLIPSIZE_NONE;
730 return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
734 * gtk_tool_item_get_icon_size:
735 * @tool_item: a #GtkToolItem
737 * Returns the icon size used for @tool_item. Custom subclasses of
738 * #GtkToolItem should call this function to find out what size icons
741 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
746 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
750 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
752 parent = GTK_WIDGET (tool_item)->parent;
753 if (!parent || !GTK_IS_TOOL_SHELL (parent))
754 return GTK_ICON_SIZE_LARGE_TOOLBAR;
756 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
760 * gtk_tool_item_get_orientation:
761 * @tool_item: a #GtkToolItem
763 * Returns the orientation used for @tool_item. Custom subclasses of
764 * #GtkToolItem should call this function to find out what size icons
767 * Return value: a #GtkOrientation indicating the orientation
768 * used for @tool_item
773 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
777 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
779 parent = GTK_WIDGET (tool_item)->parent;
780 if (!parent || !GTK_IS_TOOL_SHELL (parent))
781 return GTK_ORIENTATION_HORIZONTAL;
783 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
787 * gtk_tool_item_get_toolbar_style:
788 * @tool_item: a #GtkToolItem
790 * Returns the toolbar style used for @tool_item. Custom subclasses of
791 * #GtkToolItem should call this function in the handler of the
792 * GtkToolItem::toolbar_reconfigured signal to find out in what style
793 * the toolbar is displayed and change themselves accordingly
797 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
798 * both an icon and a label, stacked vertically </listitem>
799 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
800 * only icons </listitem>
801 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
802 * show text</listitem>
803 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
804 * both an icon and a label, arranged horizontally (however, note the
805 * #GtkToolButton::has_text_horizontally that makes tool buttons not
806 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
810 * Return value: A #GtkToolbarStyle indicating the toolbar style used
816 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
820 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
822 parent = GTK_WIDGET (tool_item)->parent;
823 if (!parent || !GTK_IS_TOOL_SHELL (parent))
824 return GTK_TOOLBAR_ICONS;
826 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
830 * gtk_tool_item_get_relief_style:
831 * @tool_item: a #GtkToolItem
833 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
834 * Custom subclasses of #GtkToolItem should call this function in the handler
835 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
836 * relief style of buttons.
838 * Return value: a #GtkReliefStyle indicating the relief style used
844 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
848 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
850 parent = GTK_WIDGET (tool_item)->parent;
851 if (!parent || !GTK_IS_TOOL_SHELL (parent))
852 return GTK_RELIEF_NONE;
854 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
858 * gtk_tool_item_get_text_alignment:
859 * @tool_item: a #GtkToolItem:
861 * Returns the text alignment used for @tool_item. Custom subclasses of
862 * #GtkToolItem should call this function to find out how text should
865 * Return value: a #gfloat indicating the horizontal text alignment
866 * used for @tool_item
871 gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
875 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
877 parent = GTK_WIDGET (tool_item)->parent;
878 if (!parent || !GTK_IS_TOOL_SHELL (parent))
881 return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
885 * gtk_tool_item_get_text_orientation:
886 * @tool_item: a #GtkToolItem
888 * Returns the text orientation used for @tool_item. Custom subclasses of
889 * #GtkToolItem should call this function to find out how text should
892 * Return value: a #GtkOrientation indicating the text orientation
893 * used for @tool_item
898 gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
902 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
904 parent = GTK_WIDGET (tool_item)->parent;
905 if (!parent || !GTK_IS_TOOL_SHELL (parent))
906 return GTK_ORIENTATION_HORIZONTAL;
908 return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
912 * gtk_tool_item_get_text_size_group:
913 * @tool_item: a #GtkToolItem
915 * Returns the size group used for labels in @tool_item. Custom subclasses of
916 * #GtkToolItem should call this function and use the size group for labels.
918 * Return value: a #GtkSizeGroup
923 gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
927 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
929 parent = GTK_WIDGET (tool_item)->parent;
930 if (!parent || !GTK_IS_TOOL_SHELL (parent))
933 return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
937 * gtk_tool_item_set_expand:
938 * @tool_item: a #GtkToolItem
939 * @expand: Whether @tool_item is allocated extra space
941 * Sets whether @tool_item is allocated extra space when there
942 * is more room on the toolbar then needed for the items. The
943 * effect is that the item gets bigger when the toolbar gets bigger
944 * and smaller when the toolbar gets smaller.
949 gtk_tool_item_set_expand (GtkToolItem *tool_item,
952 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
954 expand = expand != FALSE;
956 if (tool_item->priv->expand != expand)
958 tool_item->priv->expand = expand;
959 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
960 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
965 * gtk_tool_item_get_expand:
966 * @tool_item: a #GtkToolItem
968 * Returns whether @tool_item is allocated extra space.
969 * See gtk_tool_item_set_expand().
971 * Return value: %TRUE if @tool_item is allocated extra space.
976 gtk_tool_item_get_expand (GtkToolItem *tool_item)
978 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
980 return tool_item->priv->expand;
984 * gtk_tool_item_set_homogeneous:
985 * @tool_item: a #GtkToolItem
986 * @homogeneous: whether @tool_item is the same size as other homogeneous items
988 * Sets whether @tool_item is to be allocated the same size as other
989 * homogeneous items. The effect is that all homogeneous items will have
990 * the same width as the widest of the items.
995 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
996 gboolean homogeneous)
998 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1000 homogeneous = homogeneous != FALSE;
1002 if (tool_item->priv->homogeneous != homogeneous)
1004 tool_item->priv->homogeneous = homogeneous;
1005 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
1006 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1011 * gtk_tool_item_get_homogeneous:
1012 * @tool_item: a #GtkToolItem
1014 * Returns whether @tool_item is the same size as other homogeneous
1015 * items. See gtk_tool_item_set_homogeneous().
1017 * Return value: %TRUE if the item is the same size as other homogeneous
1023 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
1025 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1027 return tool_item->priv->homogeneous;
1031 * gtk_tool_item_get_is_important:
1032 * @tool_item: a #GtkToolItem
1034 * Returns whether @tool_item is considered important. See
1035 * gtk_tool_item_set_is_important()
1037 * Return value: %TRUE if @tool_item is considered important.
1042 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
1044 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1046 return tool_item->priv->is_important;
1050 * gtk_tool_item_set_is_important:
1051 * @tool_item: a #GtkToolItem
1052 * @is_important: whether the tool item should be considered important
1054 * Sets whether @tool_item should be considered important. The #GtkToolButton
1055 * class uses this property to determine whether to show or hide its label
1056 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1057 * only tool buttons with the "is_important" property set have labels, an
1058 * effect known as "priority text"
1063 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
1065 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1067 is_important = is_important != FALSE;
1069 if (is_important != tool_item->priv->is_important)
1071 tool_item->priv->is_important = is_important;
1073 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1075 g_object_notify (G_OBJECT (tool_item), "is-important");
1080 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
1081 GtkTooltips *tooltips,
1082 const gchar *tip_text,
1083 const gchar *tip_private)
1085 GtkWidget *child = GTK_BIN (tool_item)->child;
1090 gtk_widget_set_tooltip_text (child, tip_text);
1096 * gtk_tool_item_set_tooltip:
1097 * @tool_item: a #GtkToolItem
1098 * @tooltips: The #GtkTooltips object to be used
1099 * @tip_text: text to be used as tooltip text for @tool_item
1100 * @tip_private: text to be used as private tooltip text
1102 * Sets the #GtkTooltips object to be used for @tool_item, the
1103 * text to be displayed as tooltip on the item and the private text
1104 * to be used. See gtk_tooltips_set_tip().
1108 * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead.
1111 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
1112 GtkTooltips *tooltips,
1113 const gchar *tip_text,
1114 const gchar *tip_private)
1118 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1120 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
1121 tooltips, tip_text, tip_private, &retval);
1125 * gtk_tool_item_set_tooltip_text:
1126 * @tool_item: a #GtkToolItem
1127 * @text: text to be used as tooltip for @tool_item
1129 * Sets the text to be displayed as tooltip on the item.
1130 * See gtk_widget_set_tooltip_text().
1135 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1140 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1142 child = GTK_BIN (tool_item)->child;
1145 gtk_widget_set_tooltip_text (child, text);
1149 * gtk_tool_item_set_tooltip_markup:
1150 * @tool_item: a #GtkToolItem
1151 * @markup: markup text to be used as tooltip for @tool_item
1153 * Sets the markup text to be displayed as tooltip on the item.
1154 * See gtk_widget_set_tooltip_markup().
1159 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1160 const gchar *markup)
1164 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1166 child = GTK_BIN (tool_item)->child;
1169 gtk_widget_set_tooltip_markup (child, markup);
1173 * gtk_tool_item_set_use_drag_window:
1174 * @tool_item: a #GtkToolItem
1175 * @use_drag_window: Whether @tool_item has a drag window.
1177 * Sets whether @tool_item has a drag window. When %TRUE the
1178 * toolitem can be used as a drag source through gtk_drag_source_set().
1179 * When @tool_item has a drag window it will intercept all events,
1180 * even those that would otherwise be sent to a child of @tool_item.
1185 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1186 gboolean use_drag_window)
1188 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1190 use_drag_window = use_drag_window != FALSE;
1192 if (toolitem->priv->use_drag_window != use_drag_window)
1194 toolitem->priv->use_drag_window = use_drag_window;
1196 if (use_drag_window)
1198 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
1200 create_drag_window(toolitem);
1201 if (GTK_WIDGET_MAPPED (toolitem))
1202 gdk_window_show (toolitem->priv->drag_window);
1207 destroy_drag_window (toolitem);
1213 * gtk_tool_item_get_use_drag_window:
1214 * @tool_item: a #GtkToolItem
1216 * Returns whether @tool_item has a drag window. See
1217 * gtk_tool_item_set_use_drag_window().
1219 * Return value: %TRUE if @tool_item uses a drag window.
1224 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1226 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1228 return toolitem->priv->use_drag_window;
1232 * gtk_tool_item_set_visible_horizontal:
1233 * @tool_item: a #GtkToolItem
1234 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1236 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1241 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1242 gboolean visible_horizontal)
1244 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1246 visible_horizontal = visible_horizontal != FALSE;
1248 if (toolitem->priv->visible_horizontal != visible_horizontal)
1250 toolitem->priv->visible_horizontal = visible_horizontal;
1252 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1254 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1259 * gtk_tool_item_get_visible_horizontal:
1260 * @tool_item: a #GtkToolItem
1262 * Returns whether the @tool_item is visible on toolbars that are
1263 * docked horizontally.
1265 * Return value: %TRUE if @tool_item is visible on toolbars that are
1266 * docked horizontally.
1271 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1273 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1275 return toolitem->priv->visible_horizontal;
1279 * gtk_tool_item_set_visible_vertical:
1280 * @tool_item: a #GtkToolItem
1281 * @visible_vertical: whether @tool_item is visible when the toolbar
1282 * is in vertical mode
1284 * Sets whether @tool_item is visible when the toolbar is docked
1285 * vertically. Some tool items, such as text entries, are too wide to be
1286 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1287 * @tool_item will not appear on toolbars that are docked vertically.
1292 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1293 gboolean visible_vertical)
1295 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1297 visible_vertical = visible_vertical != FALSE;
1299 if (toolitem->priv->visible_vertical != visible_vertical)
1301 toolitem->priv->visible_vertical = visible_vertical;
1303 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1305 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1310 * gtk_tool_item_get_visible_vertical:
1311 * @tool_item: a #GtkToolItem
1313 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1314 * See gtk_tool_item_set_visible_vertical().
1316 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1321 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1323 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1325 return toolitem->priv->visible_vertical;
1329 * gtk_tool_item_retrieve_proxy_menu_item:
1330 * @tool_item: a #GtkToolItem
1332 * Returns the #GtkMenuItem that was last set by
1333 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1334 * that is going to appear in the overflow menu.
1336 * Return value: The #GtkMenuItem that is going to appear in the
1337 * overflow menu for @tool_item.
1342 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1346 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1348 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1351 return tool_item->priv->menu_item;
1355 * gtk_tool_item_get_proxy_menu_item:
1356 * @tool_item: a #GtkToolItem
1357 * @menu_item_id: a string used to identify the menu item
1359 * If @menu_item_id matches the string passed to
1360 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1362 * Custom subclasses of #GtkToolItem should use this function to update
1363 * their menu item when the #GtkToolItem changes. That the
1364 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1365 * inadvertently change a menu item that they did not create.
1367 * Return value: The #GtkMenuItem passed to
1368 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1373 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1374 const gchar *menu_item_id)
1376 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1377 g_return_val_if_fail (menu_item_id != NULL, NULL);
1379 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1380 return tool_item->priv->menu_item;
1386 * gtk_tool_item_rebuild_menu:
1387 * @tool_item: a #GtkToolItem
1389 * Calling this function signals to the toolbar that the
1390 * overflow menu item for @tool_item has changed. If the
1391 * overflow menu is visible when this function it called,
1392 * the menu will be rebuilt.
1394 * The function must be called when the tool item changes what it
1395 * will do in response to the #GtkToolItem::create-menu-proxy signal.
1400 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1404 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1406 widget = GTK_WIDGET (tool_item);
1408 if (GTK_IS_TOOL_SHELL (widget->parent))
1409 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent));
1413 * gtk_tool_item_set_proxy_menu_item:
1414 * @tool_item: a #GtkToolItem
1415 * @menu_item_id: a string used to identify @menu_item
1416 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1418 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1419 * @menu_item_id is used to identify the caller of this function and
1420 * should also be used with gtk_tool_item_get_proxy_menu_item().
1425 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1426 const gchar *menu_item_id,
1427 GtkWidget *menu_item)
1429 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1430 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1431 g_return_if_fail (menu_item_id != NULL);
1433 g_free (tool_item->priv->menu_item_id);
1435 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1437 if (tool_item->priv->menu_item != menu_item)
1439 if (tool_item->priv->menu_item)
1440 g_object_unref (tool_item->priv->menu_item);
1444 g_object_ref_sink (menu_item);
1446 gtk_widget_set_sensitive (menu_item,
1447 GTK_WIDGET_SENSITIVE (tool_item));
1450 tool_item->priv->menu_item = menu_item;
1455 * gtk_tool_item_toolbar_reconfigured:
1456 * @tool_item: a #GtkToolItem
1458 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1459 * #GtkToolbar and other #GtkToolShell implementations use this function
1460 * to notify children, when some aspect of their configuration changes.
1465 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1467 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1468 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1469 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1470 * Its not possible to rename the signal, and emitting another name than
1471 * indicated by the function name would be quite confusing. That's the
1472 * price of providing stable APIs.
1474 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1476 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1478 if (tool_item->priv->drag_window)
1479 gdk_window_raise (tool_item->priv->drag_window);
1481 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1484 #define __GTK_TOOL_ITEM_C__
1485 #include "gtkaliasdef.c"