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"
35 #include "gtkprivate.h"
40 * @short_description: The base class of widgets that can be added to #GtkToolShell
42 * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
43 * create a toolbar item that contain something else than a button, use
44 * gtk_tool_item_new(). Use gtk_container_add() to add a child
45 * widget to the tool item.
47 * For toolbar items that contain buttons, see the #GtkToolButton,
48 * #GtkToggleToolButton and #GtkRadioToolButton classes.
50 * See the #GtkToolbar class for a description of the toolbar widget, and
51 * #GtkToolShell for a description of the tool shell interface.
57 * The GtkToolItem struct contains only private data.
58 * It should only be accessed through the functions described below.
70 PROP_VISIBLE_HORIZONTAL,
71 PROP_VISIBLE_VERTICAL,
75 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
77 struct _GtkToolItemPrivate
82 guint visible_horizontal : 1;
83 guint visible_vertical : 1;
84 guint homogeneous : 1;
86 guint use_drag_window : 1;
87 guint is_important : 1;
89 GdkWindow *drag_window;
95 static void gtk_tool_item_finalize (GObject *object);
96 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
98 static void gtk_tool_item_set_property (GObject *object,
102 static void gtk_tool_item_get_property (GObject *object,
106 static void gtk_tool_item_property_notify (GObject *object,
108 static void gtk_tool_item_realize (GtkWidget *widget);
109 static void gtk_tool_item_unrealize (GtkWidget *widget);
110 static void gtk_tool_item_map (GtkWidget *widget);
111 static void gtk_tool_item_unmap (GtkWidget *widget);
112 static void gtk_tool_item_size_request (GtkWidget *widget,
113 GtkRequisition *requisition);
114 static void gtk_tool_item_size_allocate (GtkWidget *widget,
115 GtkAllocation *allocation);
116 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
117 GtkTooltips *tooltips,
118 const gchar *tip_text,
119 const gchar *tip_private);
121 static gboolean gtk_tool_item_create_menu_proxy (GtkToolItem *item);
124 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
126 G_DEFINE_TYPE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN)
129 gtk_tool_item_class_init (GtkToolItemClass *klass)
131 GObjectClass *object_class;
132 GtkWidgetClass *widget_class;
134 object_class = (GObjectClass *)klass;
135 widget_class = (GtkWidgetClass *)klass;
137 object_class->set_property = gtk_tool_item_set_property;
138 object_class->get_property = gtk_tool_item_get_property;
139 object_class->finalize = gtk_tool_item_finalize;
140 object_class->notify = gtk_tool_item_property_notify;
142 widget_class->realize = gtk_tool_item_realize;
143 widget_class->unrealize = gtk_tool_item_unrealize;
144 widget_class->map = gtk_tool_item_map;
145 widget_class->unmap = gtk_tool_item_unmap;
146 widget_class->size_request = gtk_tool_item_size_request;
147 widget_class->size_allocate = gtk_tool_item_size_allocate;
148 widget_class->parent_set = gtk_tool_item_parent_set;
150 klass->create_menu_proxy = gtk_tool_item_create_menu_proxy;
151 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
153 g_object_class_install_property (object_class,
154 PROP_VISIBLE_HORIZONTAL,
155 g_param_spec_boolean ("visible-horizontal",
156 P_("Visible when horizontal"),
157 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
159 GTK_PARAM_READWRITE));
160 g_object_class_install_property (object_class,
161 PROP_VISIBLE_VERTICAL,
162 g_param_spec_boolean ("visible-vertical",
163 P_("Visible when vertical"),
164 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
166 GTK_PARAM_READWRITE));
167 g_object_class_install_property (object_class,
169 g_param_spec_boolean ("is-important",
171 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
173 GTK_PARAM_READWRITE));
176 * GtkToolItem::create-menu-proxy:
177 * @tool_item: the object the signal was emitted on
179 * This signal is emitted when the toolbar needs information from @tool_item
180 * about whether the item should appear in the toolbar overflow menu. In
181 * response the tool item should either
183 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
184 * pointer and return %TRUE to indicate that the item should not appear
185 * in the overflow menu
187 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
188 * item and return %TRUE, or
190 * <listitem> return %FALSE to indicate that the signal was not
191 * handled by the item. This means that
192 * the item will not appear in the overflow menu unless a later handler
193 * installs a menu item.
197 * The toolbar may cache the result of this signal. When the tool item changes
198 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
199 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
202 * Return value: %TRUE if the signal was handled, %FALSE if not
204 toolitem_signals[CREATE_MENU_PROXY] =
205 g_signal_new (I_("create_menu_proxy"),
206 G_OBJECT_CLASS_TYPE (klass),
208 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
209 _gtk_boolean_handled_accumulator, NULL,
210 _gtk_marshal_BOOLEAN__VOID,
214 * GtkToolItem::toolbar-reconfigured:
215 * @tool_item: the object the signal was emitted on
217 * This signal is emitted when some property of the toolbar that the
218 * item is a child of changes. For custom subclasses of #GtkToolItem,
219 * the default handler of this signal use the functions
221 * <listitem>gtk_tool_shell_get_orientation()</listitem>
222 * <listitem>gtk_tool_shell_get_style()</listitem>
223 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
224 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
226 * to find out what the toolbar should look like and change
227 * themselves accordingly.
229 toolitem_signals[TOOLBAR_RECONFIGURED] =
230 g_signal_new (I_("toolbar_reconfigured"),
231 G_OBJECT_CLASS_TYPE (klass),
233 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
235 _gtk_marshal_VOID__VOID,
238 * GtkToolItem::set-tooltip:
239 * @tool_item: the object the signal was emitted on
240 * @tooltips: the #GtkTooltips
241 * @tip_text: the tooltip text
242 * @tip_private: the tooltip private text
244 * This signal is emitted when the toolitem's tooltip changes.
245 * Application developers can use gtk_tool_item_set_tooltip() to
246 * set the item's tooltip.
248 * Return value: %TRUE if the signal was handled, %FALSE if not
250 * Deprecated: 2.12: With the new tooltip API, there is no
251 * need to use this signal anymore.
253 toolitem_signals[SET_TOOLTIP] =
254 g_signal_new (I_("set_tooltip"),
255 G_OBJECT_CLASS_TYPE (klass),
257 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
258 _gtk_boolean_handled_accumulator, NULL,
259 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
265 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
269 gtk_tool_item_init (GtkToolItem *toolitem)
271 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
273 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
275 toolitem->priv->visible_horizontal = TRUE;
276 toolitem->priv->visible_vertical = TRUE;
277 toolitem->priv->homogeneous = FALSE;
278 toolitem->priv->expand = FALSE;
282 gtk_tool_item_finalize (GObject *object)
284 GtkToolItem *item = GTK_TOOL_ITEM (object);
286 g_free (item->priv->menu_item_id);
288 if (item->priv->menu_item)
289 g_object_unref (item->priv->menu_item);
291 if (G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize)
292 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
296 gtk_tool_item_parent_set (GtkWidget *toolitem,
297 GtkWidget *prev_parent)
299 if (GTK_WIDGET (toolitem)->parent != NULL)
300 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
304 gtk_tool_item_set_property (GObject *object,
309 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
313 case PROP_VISIBLE_HORIZONTAL:
314 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
316 case PROP_VISIBLE_VERTICAL:
317 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
319 case PROP_IS_IMPORTANT:
320 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
329 gtk_tool_item_get_property (GObject *object,
334 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
338 case PROP_VISIBLE_HORIZONTAL:
339 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
341 case PROP_VISIBLE_VERTICAL:
342 g_value_set_boolean (value, toolitem->priv->visible_vertical);
344 case PROP_IS_IMPORTANT:
345 g_value_set_boolean (value, toolitem->priv->is_important);
348 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
354 gtk_tool_item_property_notify (GObject *object,
357 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
359 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
360 gtk_widget_set_sensitive (tool_item->priv->menu_item,
361 GTK_WIDGET_SENSITIVE (tool_item));
365 create_drag_window (GtkToolItem *toolitem)
368 GdkWindowAttr attributes;
369 gint attributes_mask, border_width;
371 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
373 widget = GTK_WIDGET (toolitem);
374 border_width = GTK_CONTAINER (toolitem)->border_width;
376 attributes.window_type = GDK_WINDOW_CHILD;
377 attributes.x = widget->allocation.x + border_width;
378 attributes.y = widget->allocation.y + border_width;
379 attributes.width = widget->allocation.width - border_width * 2;
380 attributes.height = widget->allocation.height - border_width * 2;
381 attributes.wclass = GDK_INPUT_ONLY;
382 attributes.event_mask = gtk_widget_get_events (widget);
383 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
385 attributes_mask = GDK_WA_X | GDK_WA_Y;
387 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
388 &attributes, attributes_mask);
389 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
393 gtk_tool_item_realize (GtkWidget *widget)
395 GtkToolItem *toolitem;
397 toolitem = GTK_TOOL_ITEM (widget);
398 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
400 widget->window = gtk_widget_get_parent_window (widget);
401 g_object_ref (widget->window);
403 if (toolitem->priv->use_drag_window)
404 create_drag_window(toolitem);
406 widget->style = gtk_style_attach (widget->style, widget->window);
410 destroy_drag_window (GtkToolItem *toolitem)
412 if (toolitem->priv->drag_window)
414 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
415 gdk_window_destroy (toolitem->priv->drag_window);
416 toolitem->priv->drag_window = NULL;
421 gtk_tool_item_unrealize (GtkWidget *widget)
423 GtkToolItem *toolitem;
425 toolitem = GTK_TOOL_ITEM (widget);
427 destroy_drag_window (toolitem);
429 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
433 gtk_tool_item_map (GtkWidget *widget)
435 GtkToolItem *toolitem;
437 toolitem = GTK_TOOL_ITEM (widget);
438 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
439 if (toolitem->priv->drag_window)
440 gdk_window_show (toolitem->priv->drag_window);
444 gtk_tool_item_unmap (GtkWidget *widget)
446 GtkToolItem *toolitem;
448 toolitem = GTK_TOOL_ITEM (widget);
449 if (toolitem->priv->drag_window)
450 gdk_window_hide (toolitem->priv->drag_window);
451 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
455 gtk_tool_item_size_request (GtkWidget *widget,
456 GtkRequisition *requisition)
458 GtkWidget *child = GTK_BIN (widget)->child;
460 if (child && GTK_WIDGET_VISIBLE (child))
462 gtk_widget_size_request (child, requisition);
466 requisition->height = 0;
467 requisition->width = 0;
470 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
471 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
475 gtk_tool_item_size_allocate (GtkWidget *widget,
476 GtkAllocation *allocation)
478 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
479 GtkAllocation child_allocation;
481 GtkWidget *child = GTK_BIN (widget)->child;
483 widget->allocation = *allocation;
484 border_width = GTK_CONTAINER (widget)->border_width;
486 if (toolitem->priv->drag_window)
487 gdk_window_move_resize (toolitem->priv->drag_window,
488 widget->allocation.x + border_width,
489 widget->allocation.y + border_width,
490 widget->allocation.width - border_width * 2,
491 widget->allocation.height - border_width * 2);
493 if (child && GTK_WIDGET_VISIBLE (child))
495 child_allocation.x = allocation->x + border_width;
496 child_allocation.y = allocation->y + border_width;
497 child_allocation.width = allocation->width - 2 * border_width;
498 child_allocation.height = allocation->height - 2 * border_width;
500 gtk_widget_size_allocate (child, &child_allocation);
505 gtk_tool_item_create_menu_proxy (GtkToolItem *item)
513 * Creates a new #GtkToolItem
515 * Return value: the new #GtkToolItem
520 gtk_tool_item_new (void)
524 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
530 * gtk_tool_item_get_icon_size:
531 * @tool_item: a #GtkToolItem:
533 * Returns the icon size used for @tool_item. Custom subclasses of
534 * #GtkToolItem should call this function to find out what size icons
537 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
542 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
546 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
548 parent = GTK_WIDGET (tool_item)->parent;
549 if (!parent || !GTK_IS_TOOL_SHELL (parent))
550 return GTK_ICON_SIZE_LARGE_TOOLBAR;
552 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
556 * gtk_tool_item_get_orientation:
557 * @tool_item: a #GtkToolItem:
559 * Returns the orientation used for @tool_item. Custom subclasses of
560 * #GtkToolItem should call this function to find out what size icons
563 * Return value: a #GtkOrientation indicating the orientation
564 * used for @tool_item
569 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
573 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
575 parent = GTK_WIDGET (tool_item)->parent;
576 if (!parent || !GTK_IS_TOOL_SHELL (parent))
577 return GTK_ORIENTATION_HORIZONTAL;
579 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
583 * gtk_tool_item_get_toolbar_style:
584 * @tool_item: a #GtkToolItem:
586 * Returns the toolbar style used for @tool_item. Custom subclasses of
587 * #GtkToolItem should call this function in the handler of the
588 * GtkToolItem::toolbar_reconfigured signal to find out in what style
589 * the toolbar is displayed and change themselves accordingly
593 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
594 * both an icon and a label, stacked vertically </listitem>
595 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
596 * only icons </listitem>
597 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
598 * show text</listitem>
599 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
600 * both an icon and a label, arranged horizontally (however, note the
601 * #GtkToolButton::has_text_horizontally that makes tool buttons not
602 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
606 * Return value: A #GtkToolbarStyle indicating the toolbar style used
612 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
616 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
618 parent = GTK_WIDGET (tool_item)->parent;
619 if (!parent || !GTK_IS_TOOL_SHELL (parent))
620 return GTK_TOOLBAR_ICONS;
622 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
626 * gtk_tool_item_get_relief_style:
627 * @tool_item: a #GtkToolItem:
629 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
630 * Custom subclasses of #GtkToolItem should call this function in the handler
631 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
632 * relief style of buttons.
634 * Return value: a #GtkReliefStyle indicating the relief style used
640 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
644 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
646 parent = GTK_WIDGET (tool_item)->parent;
647 if (!parent || !GTK_IS_TOOL_SHELL (parent))
648 return GTK_RELIEF_NONE;
650 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
654 * gtk_tool_item_set_expand:
655 * @tool_item: a #GtkToolItem:
656 * @expand: Whether @tool_item is allocated extra space
658 * Sets whether @tool_item is allocated extra space when there
659 * is more room on the toolbar then needed for the items. The
660 * effect is that the item gets bigger when the toolbar gets bigger
661 * and smaller when the toolbar gets smaller.
666 gtk_tool_item_set_expand (GtkToolItem *tool_item,
669 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
671 expand = expand != FALSE;
673 if (tool_item->priv->expand != expand)
675 tool_item->priv->expand = expand;
676 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
677 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
682 * gtk_tool_item_get_expand:
683 * @tool_item: a #GtkToolItem:
685 * Returns whether @tool_item is allocated extra space.
686 * See gtk_tool_item_set_expand().
688 * Return value: %TRUE if @tool_item is allocated extra space.
693 gtk_tool_item_get_expand (GtkToolItem *tool_item)
695 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
697 return tool_item->priv->expand;
701 * gtk_tool_item_set_homogeneous:
702 * @tool_item: a #GtkToolItem:
703 * @homogeneous: whether @tool_item is the same size as other homogeneous items
705 * Sets whether @tool_item is to be allocated the same size as other
706 * homogeneous items. The effect is that all homogeneous items will have
707 * the same width as the widest of the items.
712 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
713 gboolean homogeneous)
715 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
717 homogeneous = homogeneous != FALSE;
719 if (tool_item->priv->homogeneous != homogeneous)
721 tool_item->priv->homogeneous = homogeneous;
722 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
723 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
728 * gtk_tool_item_get_homogeneous:
729 * @tool_item: a #GtkToolItem:
731 * Returns whether @tool_item is the same size as other homogeneous
732 * items. See gtk_tool_item_set_homogeneous().
734 * Return value: %TRUE if the item is the same size as other homogeneous
740 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
742 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
744 return tool_item->priv->homogeneous;
748 * gtk_tool_item_get_is_important:
749 * @tool_item: a #GtkToolItem
751 * Returns whether @tool_item is considered important. See
752 * gtk_tool_item_set_is_important()
754 * Return value: %TRUE if @tool_item is considered important.
759 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
761 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
763 return tool_item->priv->is_important;
767 * gtk_tool_item_set_is_important:
768 * @tool_item: a #GtkToolItem
769 * @is_important: whether the tool item should be considered important
771 * Sets whether @tool_item should be considered important. The #GtkToolButton
772 * class uses this property to determine whether to show or hide its label
773 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
774 * only tool buttons with the "is_important" property set have labels, an
775 * effect known as "priority text"
780 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
782 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
784 is_important = is_important != FALSE;
786 if (is_important != tool_item->priv->is_important)
788 tool_item->priv->is_important = is_important;
790 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
792 g_object_notify (G_OBJECT (tool_item), "is-important");
797 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
798 GtkTooltips *tooltips,
799 const gchar *tip_text,
800 const gchar *tip_private)
802 GtkWidget *child = GTK_BIN (tool_item)->child;
807 gtk_widget_set_tooltip_text (child, tip_text);
813 * gtk_tool_item_set_tooltip:
814 * @tool_item: a #GtkToolItem:
815 * @tooltips: The #GtkTooltips object to be used
816 * @tip_text: text to be used as tooltip text for @tool_item
817 * @tip_private: text to be used as private tooltip text
819 * Sets the #GtkTooltips object to be used for @tool_item, the
820 * text to be displayed as tooltip on the item and the private text
821 * to be used. See gtk_tooltips_set_tip().
825 * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead.
828 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
829 GtkTooltips *tooltips,
830 const gchar *tip_text,
831 const gchar *tip_private)
835 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
837 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
838 tooltips, tip_text, tip_private, &retval);
842 * gtk_tool_item_set_tooltip_text:
843 * @tool_item: a #GtkToolItem:
844 * @text: text to be used as tooltip for @tool_item
846 * Sets the text to be displayed as tooltip on the item.
847 * See gtk_widget_set_tooltip_text().
852 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
857 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
859 child = GTK_BIN (tool_item)->child;
862 gtk_widget_set_tooltip_text (child, text);
866 * gtk_tool_item_set_tooltip_markup:
867 * @tool_item: a #GtkToolItem:
868 * @markup: markup text to be used as tooltip for @tool_item
870 * Sets the markup text to be displayed as tooltip on the item.
871 * See gtk_widget_set_tooltip_markup().
876 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
881 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
883 child = GTK_BIN (tool_item)->child;
886 gtk_widget_set_tooltip_markup (child, markup);
890 * gtk_tool_item_set_use_drag_window:
891 * @tool_item: a #GtkToolItem
892 * @use_drag_window: Whether @tool_item has a drag window.
894 * Sets whether @tool_item has a drag window. When %TRUE the
895 * toolitem can be used as a drag source through gtk_drag_source_set().
896 * When @tool_item has a drag window it will intercept all events,
897 * even those that would otherwise be sent to a child of @tool_item.
902 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
903 gboolean use_drag_window)
905 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
907 use_drag_window = use_drag_window != FALSE;
909 if (toolitem->priv->use_drag_window != use_drag_window)
911 toolitem->priv->use_drag_window = use_drag_window;
915 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
917 create_drag_window(toolitem);
918 if (GTK_WIDGET_MAPPED (toolitem))
919 gdk_window_show (toolitem->priv->drag_window);
924 destroy_drag_window (toolitem);
930 * gtk_tool_item_get_use_drag_window:
931 * @tool_item: a #GtkToolItem
933 * Returns whether @tool_item has a drag window. See
934 * gtk_tool_item_set_use_drag_window().
936 * Return value: %TRUE if @tool_item uses a drag window.
941 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
943 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
945 return toolitem->priv->use_drag_window;
949 * gtk_tool_item_set_visible_horizontal:
950 * @tool_item: a #GtkToolItem
951 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
953 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
958 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
959 gboolean visible_horizontal)
961 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
963 visible_horizontal = visible_horizontal != FALSE;
965 if (toolitem->priv->visible_horizontal != visible_horizontal)
967 toolitem->priv->visible_horizontal = visible_horizontal;
969 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
971 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
976 * gtk_tool_item_get_visible_horizontal:
977 * @tool_item: a #GtkToolItem
979 * Returns whether the @tool_item is visible on toolbars that are
980 * docked horizontally.
982 * Return value: %TRUE if @tool_item is visible on toolbars that are
983 * docked horizontally.
988 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
990 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
992 return toolitem->priv->visible_horizontal;
996 * gtk_tool_item_set_visible_vertical:
997 * @tool_item: a #GtkToolItem
998 * @visible_vertical: whether @tool_item is visible when the toolbar
999 * is in vertical mode
1001 * Sets whether @tool_item is visible when the toolbar is docked
1002 * vertically. Some tool items, such as text entries, are too wide to be
1003 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1004 * @tool_item will not appear on toolbars that are docked vertically.
1009 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1010 gboolean visible_vertical)
1012 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1014 visible_vertical = visible_vertical != FALSE;
1016 if (toolitem->priv->visible_vertical != visible_vertical)
1018 toolitem->priv->visible_vertical = visible_vertical;
1020 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1022 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1027 * gtk_tool_item_get_visible_vertical:
1028 * @tool_item: a #GtkToolItem
1030 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1031 * See gtk_tool_item_set_visible_vertical().
1033 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1038 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1040 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1042 return toolitem->priv->visible_vertical;
1046 * gtk_tool_item_retrieve_proxy_menu_item:
1047 * @tool_item: a #GtkToolItem:
1049 * Returns the #GtkMenuItem that was last set by
1050 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1051 * that is going to appear in the overflow menu.
1053 * Return value: The #GtkMenuItem that is going to appear in the
1054 * overflow menu for @tool_item.
1059 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1063 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1065 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1068 return tool_item->priv->menu_item;
1072 * gtk_tool_item_get_proxy_menu_item:
1073 * @tool_item: a #GtkToolItem:
1074 * @menu_item_id: a string used to identify the menu item
1076 * If @menu_item_id matches the string passed to
1077 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1079 * Custom subclasses of #GtkToolItem should use this function to update
1080 * their menu item when the #GtkToolItem changes. That the
1081 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1082 * inadvertently change a menu item that they did not create.
1084 * Return value: The #GtkMenuItem passed to
1085 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1090 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1091 const gchar *menu_item_id)
1093 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1094 g_return_val_if_fail (menu_item_id != NULL, NULL);
1096 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1097 return tool_item->priv->menu_item;
1103 * gtk_tool_item_rebuild_menu()
1104 * @tool_item: a #GtkToolItem
1106 * Calling this function signals to the toolbar that the
1107 * overflow menu item for @tool_item has changed. If the
1108 * overflow menu is visible when this function it called,
1109 * the menu will be rebuilt.
1111 * The function must be called when the tool item
1112 * changes what it will do in response to the "create_menu_proxy"
1118 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1122 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1124 widget = GTK_WIDGET (tool_item);
1126 if (GTK_IS_TOOL_SHELL (widget->parent))
1127 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent));
1131 * gtk_tool_item_set_proxy_menu_item:
1132 * @tool_item: a #GtkToolItem:
1133 * @menu_item_id: a string used to identify @menu_item
1134 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1136 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1137 * @menu_item_id is used to identify the caller of this function and
1138 * should also be used with gtk_tool_item_get_proxy_menu_item().
1143 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1144 const gchar *menu_item_id,
1145 GtkWidget *menu_item)
1147 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1148 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1149 g_return_if_fail (menu_item_id != NULL);
1151 g_free (tool_item->priv->menu_item_id);
1153 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1155 if (tool_item->priv->menu_item != menu_item)
1157 if (tool_item->priv->menu_item)
1158 g_object_unref (tool_item->priv->menu_item);
1162 g_object_ref_sink (menu_item);
1164 gtk_widget_set_sensitive (menu_item,
1165 GTK_WIDGET_SENSITIVE (tool_item));
1168 tool_item->priv->menu_item = menu_item;
1173 * gtk_tool_item_toolbar_reconfigured:
1174 * @tool_item: a #GtkToolItem
1176 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1177 * #GtkToolbar and other #GtkToolShell implementations use this function
1178 * to notify children, when some aspect of their configuration changes.
1183 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1185 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1186 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1187 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1188 * Its not possible to rename the signal, and emitting another name than
1189 * indicated by the function name would be quite confusing. That's the
1190 * price of providing stable APIs.
1192 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1194 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1196 if (tool_item->priv->drag_window)
1197 gdk_window_raise (tool_item->priv->drag_window);
1199 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1202 #define __GTK_TOOL_ITEM_C__
1203 #include "gtkaliasdef.c"