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.
24 #include "gtktoolitem.h"
25 #include "gtkmarshalers.h"
26 #include "gtktoolshell.h"
27 #include "gtkseparatormenuitem.h"
30 #include "gtkprivate.h"
37 * @short_description: The base class of widgets that can be added to #GtkToolShell
39 * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
40 * create a toolbar item that contain something else than a button, use
41 * gtk_tool_item_new(). Use gtk_container_add() to add a child
42 * widget to the tool item.
44 * For toolbar items that contain buttons, see the #GtkToolButton,
45 * #GtkToggleToolButton and #GtkRadioToolButton classes.
47 * See the #GtkToolbar class for a description of the toolbar widget, and
48 * #GtkToolShell for a description of the tool shell interface.
54 * The GtkToolItem struct contains only private data.
55 * It should only be accessed through the functions described below.
67 PROP_VISIBLE_HORIZONTAL,
68 PROP_VISIBLE_VERTICAL,
72 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
74 struct _GtkToolItemPrivate
79 guint visible_horizontal : 1;
80 guint visible_vertical : 1;
81 guint homogeneous : 1;
83 guint use_drag_window : 1;
84 guint is_important : 1;
86 GdkWindow *drag_window;
92 static void gtk_tool_item_finalize (GObject *object);
93 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
95 static void gtk_tool_item_set_property (GObject *object,
99 static void gtk_tool_item_get_property (GObject *object,
103 static void gtk_tool_item_property_notify (GObject *object,
105 static void gtk_tool_item_realize (GtkWidget *widget);
106 static void gtk_tool_item_unrealize (GtkWidget *widget);
107 static void gtk_tool_item_map (GtkWidget *widget);
108 static void gtk_tool_item_unmap (GtkWidget *widget);
109 static void gtk_tool_item_size_request (GtkWidget *widget,
110 GtkRequisition *requisition);
111 static void gtk_tool_item_size_allocate (GtkWidget *widget,
112 GtkAllocation *allocation);
113 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
114 GtkTooltips *tooltips,
115 const gchar *tip_text,
116 const gchar *tip_private);
118 static gboolean gtk_tool_item_create_menu_proxy (GtkToolItem *item);
121 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
123 G_DEFINE_TYPE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN)
126 gtk_tool_item_class_init (GtkToolItemClass *klass)
128 GObjectClass *object_class;
129 GtkWidgetClass *widget_class;
131 object_class = (GObjectClass *)klass;
132 widget_class = (GtkWidgetClass *)klass;
134 object_class->set_property = gtk_tool_item_set_property;
135 object_class->get_property = gtk_tool_item_get_property;
136 object_class->finalize = gtk_tool_item_finalize;
137 object_class->notify = gtk_tool_item_property_notify;
139 widget_class->realize = gtk_tool_item_realize;
140 widget_class->unrealize = gtk_tool_item_unrealize;
141 widget_class->map = gtk_tool_item_map;
142 widget_class->unmap = gtk_tool_item_unmap;
143 widget_class->size_request = gtk_tool_item_size_request;
144 widget_class->size_allocate = gtk_tool_item_size_allocate;
145 widget_class->parent_set = gtk_tool_item_parent_set;
147 klass->create_menu_proxy = gtk_tool_item_create_menu_proxy;
148 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
150 g_object_class_install_property (object_class,
151 PROP_VISIBLE_HORIZONTAL,
152 g_param_spec_boolean ("visible-horizontal",
153 P_("Visible when horizontal"),
154 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
156 GTK_PARAM_READWRITE));
157 g_object_class_install_property (object_class,
158 PROP_VISIBLE_VERTICAL,
159 g_param_spec_boolean ("visible-vertical",
160 P_("Visible when vertical"),
161 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
163 GTK_PARAM_READWRITE));
164 g_object_class_install_property (object_class,
166 g_param_spec_boolean ("is-important",
168 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
170 GTK_PARAM_READWRITE));
173 * GtkToolItem::create-menu-proxy:
174 * @tool_item: the object the signal was emitted on
176 * This signal is emitted when the toolbar needs information from @tool_item
177 * about whether the item should appear in the toolbar overflow menu. In
178 * response the tool item should either
180 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
181 * pointer and return %TRUE to indicate that the item should not appear
182 * in the overflow menu
184 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
185 * item and return %TRUE, or
187 * <listitem> return %FALSE to indicate that the signal was not
188 * handled by the item. This means that
189 * the item will not appear in the overflow menu unless a later handler
190 * installs a menu item.
194 * The toolbar may cache the result of this signal. When the tool item changes
195 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
196 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
199 * Return value: %TRUE if the signal was handled, %FALSE if not
201 toolitem_signals[CREATE_MENU_PROXY] =
202 g_signal_new (I_("create_menu_proxy"),
203 G_OBJECT_CLASS_TYPE (klass),
205 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
206 _gtk_boolean_handled_accumulator, NULL,
207 _gtk_marshal_BOOLEAN__VOID,
211 * GtkToolItem::toolbar-reconfigured:
212 * @tool_item: the object the signal was emitted on
214 * This signal is emitted when some property of the toolbar that the
215 * item is a child of changes. For custom subclasses of #GtkToolItem,
216 * the default handler of this signal use the functions
218 * <listitem>gtk_tool_shell_get_orientation()</listitem>
219 * <listitem>gtk_tool_shell_get_style()</listitem>
220 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
221 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
223 * to find out what the toolbar should look like and change
224 * themselves accordingly.
226 toolitem_signals[TOOLBAR_RECONFIGURED] =
227 g_signal_new (I_("toolbar_reconfigured"),
228 G_OBJECT_CLASS_TYPE (klass),
230 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
232 _gtk_marshal_VOID__VOID,
235 * GtkToolItem::set-tooltip:
236 * @tool_item: the object the signal was emitted on
237 * @tooltips: the #GtkTooltips
238 * @tip_text: the tooltip text
239 * @tip_private: the tooltip private text
241 * This signal is emitted when the toolitem's tooltip changes.
242 * Application developers can use gtk_tool_item_set_tooltip() to
243 * set the item's tooltip.
245 * Return value: %TRUE if the signal was handled, %FALSE if not
247 * Deprecated: 2.12: With the new tooltip API, there is no
248 * need to use this signal anymore.
250 toolitem_signals[SET_TOOLTIP] =
251 g_signal_new (I_("set_tooltip"),
252 G_OBJECT_CLASS_TYPE (klass),
254 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
255 _gtk_boolean_handled_accumulator, NULL,
256 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
262 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
266 gtk_tool_item_init (GtkToolItem *toolitem)
268 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
270 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
272 toolitem->priv->visible_horizontal = TRUE;
273 toolitem->priv->visible_vertical = TRUE;
274 toolitem->priv->homogeneous = FALSE;
275 toolitem->priv->expand = FALSE;
279 gtk_tool_item_finalize (GObject *object)
281 GtkToolItem *item = GTK_TOOL_ITEM (object);
283 g_free (item->priv->menu_item_id);
285 if (item->priv->menu_item)
286 g_object_unref (item->priv->menu_item);
288 if (G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize)
289 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
293 gtk_tool_item_parent_set (GtkWidget *toolitem,
294 GtkWidget *prev_parent)
296 if (GTK_WIDGET (toolitem)->parent != NULL)
297 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
301 gtk_tool_item_set_property (GObject *object,
306 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
310 case PROP_VISIBLE_HORIZONTAL:
311 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
313 case PROP_VISIBLE_VERTICAL:
314 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
316 case PROP_IS_IMPORTANT:
317 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
320 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
326 gtk_tool_item_get_property (GObject *object,
331 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
335 case PROP_VISIBLE_HORIZONTAL:
336 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
338 case PROP_VISIBLE_VERTICAL:
339 g_value_set_boolean (value, toolitem->priv->visible_vertical);
341 case PROP_IS_IMPORTANT:
342 g_value_set_boolean (value, toolitem->priv->is_important);
345 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
351 gtk_tool_item_property_notify (GObject *object,
354 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
356 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
357 gtk_widget_set_sensitive (tool_item->priv->menu_item,
358 GTK_WIDGET_SENSITIVE (tool_item));
362 create_drag_window (GtkToolItem *toolitem)
365 GdkWindowAttr attributes;
366 gint attributes_mask, border_width;
368 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
370 widget = GTK_WIDGET (toolitem);
371 border_width = GTK_CONTAINER (toolitem)->border_width;
373 attributes.window_type = GDK_WINDOW_CHILD;
374 attributes.x = widget->allocation.x + border_width;
375 attributes.y = widget->allocation.y + border_width;
376 attributes.width = widget->allocation.width - border_width * 2;
377 attributes.height = widget->allocation.height - border_width * 2;
378 attributes.wclass = GDK_INPUT_ONLY;
379 attributes.event_mask = gtk_widget_get_events (widget);
380 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
382 attributes_mask = GDK_WA_X | GDK_WA_Y;
384 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
385 &attributes, attributes_mask);
386 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
390 gtk_tool_item_realize (GtkWidget *widget)
392 GtkToolItem *toolitem;
394 toolitem = GTK_TOOL_ITEM (widget);
395 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
397 widget->window = gtk_widget_get_parent_window (widget);
398 g_object_ref (widget->window);
400 if (toolitem->priv->use_drag_window)
401 create_drag_window(toolitem);
403 widget->style = gtk_style_attach (widget->style, widget->window);
407 destroy_drag_window (GtkToolItem *toolitem)
409 if (toolitem->priv->drag_window)
411 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
412 gdk_window_destroy (toolitem->priv->drag_window);
413 toolitem->priv->drag_window = NULL;
418 gtk_tool_item_unrealize (GtkWidget *widget)
420 GtkToolItem *toolitem;
422 toolitem = GTK_TOOL_ITEM (widget);
424 destroy_drag_window (toolitem);
426 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
430 gtk_tool_item_map (GtkWidget *widget)
432 GtkToolItem *toolitem;
434 toolitem = GTK_TOOL_ITEM (widget);
435 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
436 if (toolitem->priv->drag_window)
437 gdk_window_show (toolitem->priv->drag_window);
441 gtk_tool_item_unmap (GtkWidget *widget)
443 GtkToolItem *toolitem;
445 toolitem = GTK_TOOL_ITEM (widget);
446 if (toolitem->priv->drag_window)
447 gdk_window_hide (toolitem->priv->drag_window);
448 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
452 gtk_tool_item_size_request (GtkWidget *widget,
453 GtkRequisition *requisition)
455 GtkWidget *child = GTK_BIN (widget)->child;
457 if (child && GTK_WIDGET_VISIBLE (child))
459 gtk_widget_size_request (child, requisition);
463 requisition->height = 0;
464 requisition->width = 0;
467 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
468 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
472 gtk_tool_item_size_allocate (GtkWidget *widget,
473 GtkAllocation *allocation)
475 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
476 GtkAllocation child_allocation;
478 GtkWidget *child = GTK_BIN (widget)->child;
480 widget->allocation = *allocation;
481 border_width = GTK_CONTAINER (widget)->border_width;
483 if (toolitem->priv->drag_window)
484 gdk_window_move_resize (toolitem->priv->drag_window,
485 widget->allocation.x + border_width,
486 widget->allocation.y + border_width,
487 widget->allocation.width - border_width * 2,
488 widget->allocation.height - border_width * 2);
490 if (child && GTK_WIDGET_VISIBLE (child))
492 child_allocation.x = allocation->x + border_width;
493 child_allocation.y = allocation->y + border_width;
494 child_allocation.width = allocation->width - 2 * border_width;
495 child_allocation.height = allocation->height - 2 * border_width;
497 gtk_widget_size_allocate (child, &child_allocation);
502 gtk_tool_item_create_menu_proxy (GtkToolItem *item)
510 * Creates a new #GtkToolItem
512 * Return value: the new #GtkToolItem
517 gtk_tool_item_new (void)
521 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
527 * gtk_tool_item_get_icon_size:
528 * @tool_item: a #GtkToolItem:
530 * Returns the icon size used for @tool_item. Custom subclasses of
531 * #GtkToolItem should call this function to find out what size icons
534 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
539 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
543 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
545 parent = GTK_WIDGET (tool_item)->parent;
546 if (!parent || !GTK_IS_TOOL_SHELL (parent))
547 return GTK_ICON_SIZE_LARGE_TOOLBAR;
549 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
553 * gtk_tool_item_get_orientation:
554 * @tool_item: a #GtkToolItem:
556 * Returns the orientation used for @tool_item. Custom subclasses of
557 * #GtkToolItem should call this function to find out what size icons
560 * Return value: a #GtkOrientation indicating the orientation
561 * used for @tool_item
566 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
570 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
572 parent = GTK_WIDGET (tool_item)->parent;
573 if (!parent || !GTK_IS_TOOL_SHELL (parent))
574 return GTK_ORIENTATION_HORIZONTAL;
576 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
580 * gtk_tool_item_get_toolbar_style:
581 * @tool_item: a #GtkToolItem:
583 * Returns the toolbar style used for @tool_item. Custom subclasses of
584 * #GtkToolItem should call this function in the handler of the
585 * GtkToolItem::toolbar_reconfigured signal to find out in what style
586 * the toolbar is displayed and change themselves accordingly
590 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
591 * both an icon and a label, stacked vertically </listitem>
592 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
593 * only icons </listitem>
594 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
595 * show text</listitem>
596 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
597 * both an icon and a label, arranged horizontally (however, note the
598 * #GtkToolButton::has_text_horizontally that makes tool buttons not
599 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
603 * Return value: A #GtkToolbarStyle indicating the toolbar style used
609 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
613 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
615 parent = GTK_WIDGET (tool_item)->parent;
616 if (!parent || !GTK_IS_TOOL_SHELL (parent))
617 return GTK_TOOLBAR_ICONS;
619 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
623 * gtk_tool_item_get_relief_style:
624 * @tool_item: a #GtkToolItem:
626 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
627 * Custom subclasses of #GtkToolItem should call this function in the handler
628 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
629 * relief style of buttons.
631 * Return value: a #GtkReliefStyle indicating the relief style used
637 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
641 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
643 parent = GTK_WIDGET (tool_item)->parent;
644 if (!parent || !GTK_IS_TOOL_SHELL (parent))
645 return GTK_RELIEF_NONE;
647 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
651 * gtk_tool_item_set_expand:
652 * @tool_item: a #GtkToolItem:
653 * @expand: Whether @tool_item is allocated extra space
655 * Sets whether @tool_item is allocated extra space when there
656 * is more room on the toolbar then needed for the items. The
657 * effect is that the item gets bigger when the toolbar gets bigger
658 * and smaller when the toolbar gets smaller.
663 gtk_tool_item_set_expand (GtkToolItem *tool_item,
666 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
668 expand = expand != FALSE;
670 if (tool_item->priv->expand != expand)
672 tool_item->priv->expand = expand;
673 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
674 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
679 * gtk_tool_item_get_expand:
680 * @tool_item: a #GtkToolItem:
682 * Returns whether @tool_item is allocated extra space.
683 * See gtk_tool_item_set_expand().
685 * Return value: %TRUE if @tool_item is allocated extra space.
690 gtk_tool_item_get_expand (GtkToolItem *tool_item)
692 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
694 return tool_item->priv->expand;
698 * gtk_tool_item_set_homogeneous:
699 * @tool_item: a #GtkToolItem:
700 * @homogeneous: whether @tool_item is the same size as other homogeneous items
702 * Sets whether @tool_item is to be allocated the same size as other
703 * homogeneous items. The effect is that all homogeneous items will have
704 * the same width as the widest of the items.
709 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
710 gboolean homogeneous)
712 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
714 homogeneous = homogeneous != FALSE;
716 if (tool_item->priv->homogeneous != homogeneous)
718 tool_item->priv->homogeneous = homogeneous;
719 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
720 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
725 * gtk_tool_item_get_homogeneous:
726 * @tool_item: a #GtkToolItem:
728 * Returns whether @tool_item is the same size as other homogeneous
729 * items. See gtk_tool_item_set_homogeneous().
731 * Return value: %TRUE if the item is the same size as other homogeneous
737 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
739 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
741 return tool_item->priv->homogeneous;
745 * gtk_tool_item_get_is_important:
746 * @tool_item: a #GtkToolItem
748 * Returns whether @tool_item is considered important. See
749 * gtk_tool_item_set_is_important()
751 * Return value: %TRUE if @tool_item is considered important.
756 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
758 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
760 return tool_item->priv->is_important;
764 * gtk_tool_item_set_is_important:
765 * @tool_item: a #GtkToolItem
766 * @is_important: whether the tool item should be considered important
768 * Sets whether @tool_item should be considered important. The #GtkToolButton
769 * class uses this property to determine whether to show or hide its label
770 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
771 * only tool buttons with the "is_important" property set have labels, an
772 * effect known as "priority text"
777 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
779 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
781 is_important = is_important != FALSE;
783 if (is_important != tool_item->priv->is_important)
785 tool_item->priv->is_important = is_important;
787 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
789 g_object_notify (G_OBJECT (tool_item), "is-important");
794 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
795 GtkTooltips *tooltips,
796 const gchar *tip_text,
797 const gchar *tip_private)
799 GtkWidget *child = GTK_BIN (tool_item)->child;
804 gtk_widget_set_tooltip_text (child, tip_text);
810 * gtk_tool_item_set_tooltip:
811 * @tool_item: a #GtkToolItem:
812 * @tooltips: The #GtkTooltips object to be used
813 * @tip_text: text to be used as tooltip text for @tool_item
814 * @tip_private: text to be used as private tooltip text
816 * Sets the #GtkTooltips object to be used for @tool_item, the
817 * text to be displayed as tooltip on the item and the private text
818 * to be used. See gtk_tooltips_set_tip().
822 * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead.
825 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
826 GtkTooltips *tooltips,
827 const gchar *tip_text,
828 const gchar *tip_private)
832 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
834 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
835 tooltips, tip_text, tip_private, &retval);
839 * gtk_tool_item_set_tooltip_text:
840 * @tool_item: a #GtkToolItem:
841 * @text: text to be used as tooltip for @tool_item
843 * Sets the text to be displayed as tooltip on the item.
844 * See gtk_widget_set_tooltip_text().
849 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
854 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
856 child = GTK_BIN (tool_item)->child;
859 gtk_widget_set_tooltip_text (child, text);
863 * gtk_tool_item_set_tooltip_markup:
864 * @tool_item: a #GtkToolItem:
865 * @markup: markup text to be used as tooltip for @tool_item
867 * Sets the markup text to be displayed as tooltip on the item.
868 * See gtk_widget_set_tooltip_markup().
873 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
878 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
880 child = GTK_BIN (tool_item)->child;
883 gtk_widget_set_tooltip_markup (child, markup);
887 * gtk_tool_item_set_use_drag_window:
888 * @tool_item: a #GtkToolItem
889 * @use_drag_window: Whether @tool_item has a drag window.
891 * Sets whether @tool_item has a drag window. When %TRUE the
892 * toolitem can be used as a drag source through gtk_drag_source_set().
893 * When @tool_item has a drag window it will intercept all events,
894 * even those that would otherwise be sent to a child of @tool_item.
899 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
900 gboolean use_drag_window)
902 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
904 use_drag_window = use_drag_window != FALSE;
906 if (toolitem->priv->use_drag_window != use_drag_window)
908 toolitem->priv->use_drag_window = use_drag_window;
912 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
914 create_drag_window(toolitem);
915 if (GTK_WIDGET_MAPPED (toolitem))
916 gdk_window_show (toolitem->priv->drag_window);
921 destroy_drag_window (toolitem);
927 * gtk_tool_item_get_use_drag_window:
928 * @tool_item: a #GtkToolItem
930 * Returns whether @tool_item has a drag window. See
931 * gtk_tool_item_set_use_drag_window().
933 * Return value: %TRUE if @tool_item uses a drag window.
938 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
940 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
942 return toolitem->priv->use_drag_window;
946 * gtk_tool_item_set_visible_horizontal:
947 * @tool_item: a #GtkToolItem
948 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
950 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
955 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
956 gboolean visible_horizontal)
958 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
960 visible_horizontal = visible_horizontal != FALSE;
962 if (toolitem->priv->visible_horizontal != visible_horizontal)
964 toolitem->priv->visible_horizontal = visible_horizontal;
966 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
968 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
973 * gtk_tool_item_get_visible_horizontal:
974 * @tool_item: a #GtkToolItem
976 * Returns whether the @tool_item is visible on toolbars that are
977 * docked horizontally.
979 * Return value: %TRUE if @tool_item is visible on toolbars that are
980 * docked horizontally.
985 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
987 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
989 return toolitem->priv->visible_horizontal;
993 * gtk_tool_item_set_visible_vertical:
994 * @tool_item: a #GtkToolItem
995 * @visible_vertical: whether @tool_item is visible when the toolbar
996 * is in vertical mode
998 * Sets whether @tool_item is visible when the toolbar is docked
999 * vertically. Some tool items, such as text entries, are too wide to be
1000 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1001 * @tool_item will not appear on toolbars that are docked vertically.
1006 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1007 gboolean visible_vertical)
1009 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1011 visible_vertical = visible_vertical != FALSE;
1013 if (toolitem->priv->visible_vertical != visible_vertical)
1015 toolitem->priv->visible_vertical = visible_vertical;
1017 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1019 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1024 * gtk_tool_item_get_visible_vertical:
1025 * @tool_item: a #GtkToolItem
1027 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1028 * See gtk_tool_item_set_visible_vertical().
1030 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1035 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1037 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1039 return toolitem->priv->visible_vertical;
1043 * gtk_tool_item_retrieve_proxy_menu_item:
1044 * @tool_item: a #GtkToolItem:
1046 * Returns the #GtkMenuItem that was last set by
1047 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1048 * that is going to appear in the overflow menu.
1050 * Return value: The #GtkMenuItem that is going to appear in the
1051 * overflow menu for @tool_item.
1056 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1060 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1062 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1065 return tool_item->priv->menu_item;
1069 * gtk_tool_item_get_proxy_menu_item:
1070 * @tool_item: a #GtkToolItem:
1071 * @menu_item_id: a string used to identify the menu item
1073 * If @menu_item_id matches the string passed to
1074 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1076 * Custom subclasses of #GtkToolItem should use this function to update
1077 * their menu item when the #GtkToolItem changes. That the
1078 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1079 * inadvertently change a menu item that they did not create.
1081 * Return value: The #GtkMenuItem passed to
1082 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1087 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1088 const gchar *menu_item_id)
1090 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1091 g_return_val_if_fail (menu_item_id != NULL, NULL);
1093 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1094 return tool_item->priv->menu_item;
1100 * gtk_tool_item_rebuild_menu()
1101 * @tool_item: a #GtkToolItem
1103 * Calling this function signals to the toolbar that the
1104 * overflow menu item for @tool_item has changed. If the
1105 * overflow menu is visible when this function it called,
1106 * the menu will be rebuilt.
1108 * The function must be called when the tool item
1109 * changes what it will do in response to the "create_menu_proxy"
1115 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1119 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1121 widget = GTK_WIDGET (tool_item);
1123 if (GTK_IS_TOOL_SHELL (widget->parent))
1124 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent));
1128 * gtk_tool_item_set_proxy_menu_item:
1129 * @tool_item: a #GtkToolItem:
1130 * @menu_item_id: a string used to identify @menu_item
1131 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1133 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1134 * @menu_item_id is used to identify the caller of this function and
1135 * should also be used with gtk_tool_item_get_proxy_menu_item().
1140 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1141 const gchar *menu_item_id,
1142 GtkWidget *menu_item)
1144 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1145 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1146 g_return_if_fail (menu_item_id != NULL);
1148 g_free (tool_item->priv->menu_item_id);
1150 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1152 if (tool_item->priv->menu_item != menu_item)
1154 if (tool_item->priv->menu_item)
1155 g_object_unref (tool_item->priv->menu_item);
1159 g_object_ref_sink (menu_item);
1161 gtk_widget_set_sensitive (menu_item,
1162 GTK_WIDGET_SENSITIVE (tool_item));
1165 tool_item->priv->menu_item = menu_item;
1170 * gtk_tool_item_toolbar_reconfigured:
1171 * @tool_item: a #GtkToolItem
1173 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1174 * #GtkToolbar and other #GtkToolShell implementations use this function
1175 * to notify children, when some aspect of their configuration changes.
1180 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1182 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1183 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1184 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1185 * Its not possible to rename the signal, and emitting another name than
1186 * indicated by the function name would be quite confusing. That's the
1187 * price of providing stable APIs.
1189 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1191 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1193 if (tool_item->priv->drag_window)
1194 gdk_window_raise (tool_item->priv->drag_window);
1196 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1199 #define __GTK_TOOL_ITEM_C__
1200 #include "gtkaliasdef.c"