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 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
295 gtk_tool_item_parent_set (GtkWidget *toolitem,
296 GtkWidget *prev_parent)
298 if (GTK_WIDGET (toolitem)->parent != NULL)
299 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
303 gtk_tool_item_set_property (GObject *object,
308 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
312 case PROP_VISIBLE_HORIZONTAL:
313 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
315 case PROP_VISIBLE_VERTICAL:
316 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
318 case PROP_IS_IMPORTANT:
319 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
322 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
328 gtk_tool_item_get_property (GObject *object,
333 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
337 case PROP_VISIBLE_HORIZONTAL:
338 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
340 case PROP_VISIBLE_VERTICAL:
341 g_value_set_boolean (value, toolitem->priv->visible_vertical);
343 case PROP_IS_IMPORTANT:
344 g_value_set_boolean (value, toolitem->priv->is_important);
347 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
353 gtk_tool_item_property_notify (GObject *object,
356 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
358 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
359 gtk_widget_set_sensitive (tool_item->priv->menu_item,
360 GTK_WIDGET_SENSITIVE (tool_item));
364 create_drag_window (GtkToolItem *toolitem)
367 GdkWindowAttr attributes;
368 gint attributes_mask, border_width;
370 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
372 widget = GTK_WIDGET (toolitem);
373 border_width = GTK_CONTAINER (toolitem)->border_width;
375 attributes.window_type = GDK_WINDOW_CHILD;
376 attributes.x = widget->allocation.x + border_width;
377 attributes.y = widget->allocation.y + border_width;
378 attributes.width = widget->allocation.width - border_width * 2;
379 attributes.height = widget->allocation.height - border_width * 2;
380 attributes.wclass = GDK_INPUT_ONLY;
381 attributes.event_mask = gtk_widget_get_events (widget);
382 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
384 attributes_mask = GDK_WA_X | GDK_WA_Y;
386 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
387 &attributes, attributes_mask);
388 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
392 gtk_tool_item_realize (GtkWidget *widget)
394 GtkToolItem *toolitem;
396 toolitem = GTK_TOOL_ITEM (widget);
397 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
399 widget->window = gtk_widget_get_parent_window (widget);
400 g_object_ref (widget->window);
402 if (toolitem->priv->use_drag_window)
403 create_drag_window(toolitem);
405 widget->style = gtk_style_attach (widget->style, widget->window);
409 destroy_drag_window (GtkToolItem *toolitem)
411 if (toolitem->priv->drag_window)
413 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
414 gdk_window_destroy (toolitem->priv->drag_window);
415 toolitem->priv->drag_window = NULL;
420 gtk_tool_item_unrealize (GtkWidget *widget)
422 GtkToolItem *toolitem;
424 toolitem = GTK_TOOL_ITEM (widget);
426 destroy_drag_window (toolitem);
428 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
432 gtk_tool_item_map (GtkWidget *widget)
434 GtkToolItem *toolitem;
436 toolitem = GTK_TOOL_ITEM (widget);
437 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
438 if (toolitem->priv->drag_window)
439 gdk_window_show (toolitem->priv->drag_window);
443 gtk_tool_item_unmap (GtkWidget *widget)
445 GtkToolItem *toolitem;
447 toolitem = GTK_TOOL_ITEM (widget);
448 if (toolitem->priv->drag_window)
449 gdk_window_hide (toolitem->priv->drag_window);
450 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
454 gtk_tool_item_size_request (GtkWidget *widget,
455 GtkRequisition *requisition)
457 GtkWidget *child = GTK_BIN (widget)->child;
459 if (child && GTK_WIDGET_VISIBLE (child))
461 gtk_widget_size_request (child, requisition);
465 requisition->height = 0;
466 requisition->width = 0;
469 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
470 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
474 gtk_tool_item_size_allocate (GtkWidget *widget,
475 GtkAllocation *allocation)
477 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
478 GtkAllocation child_allocation;
480 GtkWidget *child = GTK_BIN (widget)->child;
482 widget->allocation = *allocation;
483 border_width = GTK_CONTAINER (widget)->border_width;
485 if (toolitem->priv->drag_window)
486 gdk_window_move_resize (toolitem->priv->drag_window,
487 widget->allocation.x + border_width,
488 widget->allocation.y + border_width,
489 widget->allocation.width - border_width * 2,
490 widget->allocation.height - border_width * 2);
492 if (child && GTK_WIDGET_VISIBLE (child))
494 child_allocation.x = allocation->x + border_width;
495 child_allocation.y = allocation->y + border_width;
496 child_allocation.width = allocation->width - 2 * border_width;
497 child_allocation.height = allocation->height - 2 * border_width;
499 gtk_widget_size_allocate (child, &child_allocation);
504 gtk_tool_item_create_menu_proxy (GtkToolItem *item)
512 * Creates a new #GtkToolItem
514 * Return value: the new #GtkToolItem
519 gtk_tool_item_new (void)
523 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
529 * gtk_tool_item_get_icon_size:
530 * @tool_item: a #GtkToolItem:
532 * Returns the icon size used for @tool_item. Custom subclasses of
533 * #GtkToolItem should call this function to find out what size icons
536 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
541 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
545 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
547 parent = GTK_WIDGET (tool_item)->parent;
548 if (!parent || !GTK_IS_TOOL_SHELL (parent))
549 return GTK_ICON_SIZE_LARGE_TOOLBAR;
551 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
555 * gtk_tool_item_get_orientation:
556 * @tool_item: a #GtkToolItem:
558 * Returns the orientation used for @tool_item. Custom subclasses of
559 * #GtkToolItem should call this function to find out what size icons
562 * Return value: a #GtkOrientation indicating the orientation
563 * used for @tool_item
568 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
572 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
574 parent = GTK_WIDGET (tool_item)->parent;
575 if (!parent || !GTK_IS_TOOL_SHELL (parent))
576 return GTK_ORIENTATION_HORIZONTAL;
578 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
582 * gtk_tool_item_get_toolbar_style:
583 * @tool_item: a #GtkToolItem:
585 * Returns the toolbar style used for @tool_item. Custom subclasses of
586 * #GtkToolItem should call this function in the handler of the
587 * GtkToolItem::toolbar_reconfigured signal to find out in what style
588 * the toolbar is displayed and change themselves accordingly
592 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
593 * both an icon and a label, stacked vertically </listitem>
594 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
595 * only icons </listitem>
596 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
597 * show text</listitem>
598 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
599 * both an icon and a label, arranged horizontally (however, note the
600 * #GtkToolButton::has_text_horizontally that makes tool buttons not
601 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
605 * Return value: A #GtkToolbarStyle indicating the toolbar style used
611 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
615 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
617 parent = GTK_WIDGET (tool_item)->parent;
618 if (!parent || !GTK_IS_TOOL_SHELL (parent))
619 return GTK_TOOLBAR_ICONS;
621 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
625 * gtk_tool_item_get_relief_style:
626 * @tool_item: a #GtkToolItem:
628 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
629 * Custom subclasses of #GtkToolItem should call this function in the handler
630 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
631 * relief style of buttons.
633 * Return value: a #GtkReliefStyle indicating the relief style used
639 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
643 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
645 parent = GTK_WIDGET (tool_item)->parent;
646 if (!parent || !GTK_IS_TOOL_SHELL (parent))
647 return GTK_RELIEF_NONE;
649 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
653 * gtk_tool_item_set_expand:
654 * @tool_item: a #GtkToolItem:
655 * @expand: Whether @tool_item is allocated extra space
657 * Sets whether @tool_item is allocated extra space when there
658 * is more room on the toolbar then needed for the items. The
659 * effect is that the item gets bigger when the toolbar gets bigger
660 * and smaller when the toolbar gets smaller.
665 gtk_tool_item_set_expand (GtkToolItem *tool_item,
668 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
670 expand = expand != FALSE;
672 if (tool_item->priv->expand != expand)
674 tool_item->priv->expand = expand;
675 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
676 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
681 * gtk_tool_item_get_expand:
682 * @tool_item: a #GtkToolItem:
684 * Returns whether @tool_item is allocated extra space.
685 * See gtk_tool_item_set_expand().
687 * Return value: %TRUE if @tool_item is allocated extra space.
692 gtk_tool_item_get_expand (GtkToolItem *tool_item)
694 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
696 return tool_item->priv->expand;
700 * gtk_tool_item_set_homogeneous:
701 * @tool_item: a #GtkToolItem:
702 * @homogeneous: whether @tool_item is the same size as other homogeneous items
704 * Sets whether @tool_item is to be allocated the same size as other
705 * homogeneous items. The effect is that all homogeneous items will have
706 * the same width as the widest of the items.
711 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
712 gboolean homogeneous)
714 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
716 homogeneous = homogeneous != FALSE;
718 if (tool_item->priv->homogeneous != homogeneous)
720 tool_item->priv->homogeneous = homogeneous;
721 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
722 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
727 * gtk_tool_item_get_homogeneous:
728 * @tool_item: a #GtkToolItem:
730 * Returns whether @tool_item is the same size as other homogeneous
731 * items. See gtk_tool_item_set_homogeneous().
733 * Return value: %TRUE if the item is the same size as other homogeneous
739 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
741 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
743 return tool_item->priv->homogeneous;
747 * gtk_tool_item_get_is_important:
748 * @tool_item: a #GtkToolItem
750 * Returns whether @tool_item is considered important. See
751 * gtk_tool_item_set_is_important()
753 * Return value: %TRUE if @tool_item is considered important.
758 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
760 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
762 return tool_item->priv->is_important;
766 * gtk_tool_item_set_is_important:
767 * @tool_item: a #GtkToolItem
768 * @is_important: whether the tool item should be considered important
770 * Sets whether @tool_item should be considered important. The #GtkToolButton
771 * class uses this property to determine whether to show or hide its label
772 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
773 * only tool buttons with the "is_important" property set have labels, an
774 * effect known as "priority text"
779 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
781 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
783 is_important = is_important != FALSE;
785 if (is_important != tool_item->priv->is_important)
787 tool_item->priv->is_important = is_important;
789 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
791 g_object_notify (G_OBJECT (tool_item), "is-important");
796 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
797 GtkTooltips *tooltips,
798 const gchar *tip_text,
799 const gchar *tip_private)
801 GtkWidget *child = GTK_BIN (tool_item)->child;
806 gtk_widget_set_tooltip_text (child, tip_text);
812 * gtk_tool_item_set_tooltip:
813 * @tool_item: a #GtkToolItem:
814 * @tooltips: The #GtkTooltips object to be used
815 * @tip_text: text to be used as tooltip text for @tool_item
816 * @tip_private: text to be used as private tooltip text
818 * Sets the #GtkTooltips object to be used for @tool_item, the
819 * text to be displayed as tooltip on the item and the private text
820 * to be used. See gtk_tooltips_set_tip().
824 * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead.
827 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
828 GtkTooltips *tooltips,
829 const gchar *tip_text,
830 const gchar *tip_private)
834 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
836 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
837 tooltips, tip_text, tip_private, &retval);
841 * gtk_tool_item_set_tooltip_text:
842 * @tool_item: a #GtkToolItem:
843 * @text: text to be used as tooltip for @tool_item
845 * Sets the text to be displayed as tooltip on the item.
846 * See gtk_widget_set_tooltip_text().
851 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
856 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
858 child = GTK_BIN (tool_item)->child;
861 gtk_widget_set_tooltip_text (child, text);
865 * gtk_tool_item_set_tooltip_markup:
866 * @tool_item: a #GtkToolItem:
867 * @markup: markup text to be used as tooltip for @tool_item
869 * Sets the markup text to be displayed as tooltip on the item.
870 * See gtk_widget_set_tooltip_markup().
875 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
880 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
882 child = GTK_BIN (tool_item)->child;
885 gtk_widget_set_tooltip_markup (child, markup);
889 * gtk_tool_item_set_use_drag_window:
890 * @tool_item: a #GtkToolItem
891 * @use_drag_window: Whether @tool_item has a drag window.
893 * Sets whether @tool_item has a drag window. When %TRUE the
894 * toolitem can be used as a drag source through gtk_drag_source_set().
895 * When @tool_item has a drag window it will intercept all events,
896 * even those that would otherwise be sent to a child of @tool_item.
901 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
902 gboolean use_drag_window)
904 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
906 use_drag_window = use_drag_window != FALSE;
908 if (toolitem->priv->use_drag_window != use_drag_window)
910 toolitem->priv->use_drag_window = use_drag_window;
914 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
916 create_drag_window(toolitem);
917 if (GTK_WIDGET_MAPPED (toolitem))
918 gdk_window_show (toolitem->priv->drag_window);
923 destroy_drag_window (toolitem);
929 * gtk_tool_item_get_use_drag_window:
930 * @tool_item: a #GtkToolItem
932 * Returns whether @tool_item has a drag window. See
933 * gtk_tool_item_set_use_drag_window().
935 * Return value: %TRUE if @tool_item uses a drag window.
940 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
942 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
944 return toolitem->priv->use_drag_window;
948 * gtk_tool_item_set_visible_horizontal:
949 * @tool_item: a #GtkToolItem
950 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
952 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
957 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
958 gboolean visible_horizontal)
960 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
962 visible_horizontal = visible_horizontal != FALSE;
964 if (toolitem->priv->visible_horizontal != visible_horizontal)
966 toolitem->priv->visible_horizontal = visible_horizontal;
968 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
970 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
975 * gtk_tool_item_get_visible_horizontal:
976 * @tool_item: a #GtkToolItem
978 * Returns whether the @tool_item is visible on toolbars that are
979 * docked horizontally.
981 * Return value: %TRUE if @tool_item is visible on toolbars that are
982 * docked horizontally.
987 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
989 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
991 return toolitem->priv->visible_horizontal;
995 * gtk_tool_item_set_visible_vertical:
996 * @tool_item: a #GtkToolItem
997 * @visible_vertical: whether @tool_item is visible when the toolbar
998 * is in vertical mode
1000 * Sets whether @tool_item is visible when the toolbar is docked
1001 * vertically. Some tool items, such as text entries, are too wide to be
1002 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1003 * @tool_item will not appear on toolbars that are docked vertically.
1008 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1009 gboolean visible_vertical)
1011 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1013 visible_vertical = visible_vertical != FALSE;
1015 if (toolitem->priv->visible_vertical != visible_vertical)
1017 toolitem->priv->visible_vertical = visible_vertical;
1019 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1021 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1026 * gtk_tool_item_get_visible_vertical:
1027 * @tool_item: a #GtkToolItem
1029 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1030 * See gtk_tool_item_set_visible_vertical().
1032 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1037 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1039 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1041 return toolitem->priv->visible_vertical;
1045 * gtk_tool_item_retrieve_proxy_menu_item:
1046 * @tool_item: a #GtkToolItem:
1048 * Returns the #GtkMenuItem that was last set by
1049 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1050 * that is going to appear in the overflow menu.
1052 * Return value: The #GtkMenuItem that is going to appear in the
1053 * overflow menu for @tool_item.
1058 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1062 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1064 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1067 return tool_item->priv->menu_item;
1071 * gtk_tool_item_get_proxy_menu_item:
1072 * @tool_item: a #GtkToolItem:
1073 * @menu_item_id: a string used to identify the menu item
1075 * If @menu_item_id matches the string passed to
1076 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1078 * Custom subclasses of #GtkToolItem should use this function to update
1079 * their menu item when the #GtkToolItem changes. That the
1080 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1081 * inadvertently change a menu item that they did not create.
1083 * Return value: The #GtkMenuItem passed to
1084 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1089 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1090 const gchar *menu_item_id)
1092 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1093 g_return_val_if_fail (menu_item_id != NULL, NULL);
1095 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1096 return tool_item->priv->menu_item;
1102 * gtk_tool_item_rebuild_menu()
1103 * @tool_item: a #GtkToolItem
1105 * Calling this function signals to the toolbar that the
1106 * overflow menu item for @tool_item has changed. If the
1107 * overflow menu is visible when this function it called,
1108 * the menu will be rebuilt.
1110 * The function must be called when the tool item
1111 * changes what it will do in response to the "create_menu_proxy"
1117 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1121 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1123 widget = GTK_WIDGET (tool_item);
1125 if (GTK_IS_TOOL_SHELL (widget->parent))
1126 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent));
1130 * gtk_tool_item_set_proxy_menu_item:
1131 * @tool_item: a #GtkToolItem:
1132 * @menu_item_id: a string used to identify @menu_item
1133 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1135 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1136 * @menu_item_id is used to identify the caller of this function and
1137 * should also be used with gtk_tool_item_get_proxy_menu_item().
1142 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1143 const gchar *menu_item_id,
1144 GtkWidget *menu_item)
1146 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1147 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1148 g_return_if_fail (menu_item_id != NULL);
1150 g_free (tool_item->priv->menu_item_id);
1152 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1154 if (tool_item->priv->menu_item != menu_item)
1156 if (tool_item->priv->menu_item)
1157 g_object_unref (tool_item->priv->menu_item);
1161 g_object_ref_sink (menu_item);
1163 gtk_widget_set_sensitive (menu_item,
1164 GTK_WIDGET_SENSITIVE (tool_item));
1167 tool_item->priv->menu_item = menu_item;
1172 * gtk_tool_item_toolbar_reconfigured:
1173 * @tool_item: a #GtkToolItem
1175 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1176 * #GtkToolbar and other #GtkToolShell implementations use this function
1177 * to notify children, when some aspect of their configuration changes.
1182 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1184 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1185 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1186 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1187 * Its not possible to rename the signal, and emitting another name than
1188 * indicated by the function name would be quite confusing. That's the
1189 * price of providing stable APIs.
1191 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1193 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1195 if (tool_item->priv->drag_window)
1196 gdk_window_raise (tool_item->priv->drag_window);
1198 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1201 #define __GTK_TOOL_ITEM_C__
1202 #include "gtkaliasdef.c"