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 "gtktoolbar.h"
27 #include "gtkseparatormenuitem.h"
30 #include "gtkprivate.h"
44 PROP_VISIBLE_HORIZONTAL,
45 PROP_VISIBLE_VERTICAL,
49 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
51 struct _GtkToolItemPrivate
56 guint visible_horizontal : 1;
57 guint visible_vertical : 1;
58 guint homogeneous : 1;
60 guint use_drag_window : 1;
61 guint is_important : 1;
63 GdkWindow *drag_window;
69 static void gtk_tool_item_finalize (GObject *object);
70 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
72 static void gtk_tool_item_set_property (GObject *object,
76 static void gtk_tool_item_get_property (GObject *object,
80 static void gtk_tool_item_property_notify (GObject *object,
82 static void gtk_tool_item_realize (GtkWidget *widget);
83 static void gtk_tool_item_unrealize (GtkWidget *widget);
84 static void gtk_tool_item_map (GtkWidget *widget);
85 static void gtk_tool_item_unmap (GtkWidget *widget);
86 static void gtk_tool_item_size_request (GtkWidget *widget,
87 GtkRequisition *requisition);
88 static void gtk_tool_item_size_allocate (GtkWidget *widget,
89 GtkAllocation *allocation);
90 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
91 GtkTooltips *tooltips,
92 const gchar *tip_text,
93 const gchar *tip_private);
95 static gboolean gtk_tool_item_create_menu_proxy (GtkToolItem *item);
98 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
100 G_DEFINE_TYPE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN)
103 gtk_tool_item_class_init (GtkToolItemClass *klass)
105 GObjectClass *object_class;
106 GtkWidgetClass *widget_class;
108 object_class = (GObjectClass *)klass;
109 widget_class = (GtkWidgetClass *)klass;
111 object_class->set_property = gtk_tool_item_set_property;
112 object_class->get_property = gtk_tool_item_get_property;
113 object_class->finalize = gtk_tool_item_finalize;
114 object_class->notify = gtk_tool_item_property_notify;
116 widget_class->realize = gtk_tool_item_realize;
117 widget_class->unrealize = gtk_tool_item_unrealize;
118 widget_class->map = gtk_tool_item_map;
119 widget_class->unmap = gtk_tool_item_unmap;
120 widget_class->size_request = gtk_tool_item_size_request;
121 widget_class->size_allocate = gtk_tool_item_size_allocate;
122 widget_class->parent_set = gtk_tool_item_parent_set;
124 klass->create_menu_proxy = gtk_tool_item_create_menu_proxy;
125 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
127 g_object_class_install_property (object_class,
128 PROP_VISIBLE_HORIZONTAL,
129 g_param_spec_boolean ("visible-horizontal",
130 P_("Visible when horizontal"),
131 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
133 GTK_PARAM_READWRITE));
134 g_object_class_install_property (object_class,
135 PROP_VISIBLE_VERTICAL,
136 g_param_spec_boolean ("visible-vertical",
137 P_("Visible when vertical"),
138 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
140 GTK_PARAM_READWRITE));
141 g_object_class_install_property (object_class,
143 g_param_spec_boolean ("is-important",
145 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
147 GTK_PARAM_READWRITE));
150 * GtkToolItem::create-menu-proxy:
151 * @tool_item: the object the signal was emitted on
153 * This signal is emitted when the toolbar needs information from @tool_item
154 * about whether the item should appear in the toolbar overflow menu. In
155 * response the tool item should either
157 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
158 * pointer and return %TRUE to indicate that the item should not appear
159 * in the overflow menu
161 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
162 * item and return %TRUE, or
164 * <listitem> return %FALSE to indicate that the signal was not
165 * handled by the item. This means that
166 * the item will not appear in the overflow menu unless a later handler
167 * installs a menu item.
171 * The toolbar may cache the result of this signal. When the tool item changes
172 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
173 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
176 * Return value: %TRUE if the signal was handled, %FALSE if not
178 toolitem_signals[CREATE_MENU_PROXY] =
179 g_signal_new (I_("create_menu_proxy"),
180 G_OBJECT_CLASS_TYPE (klass),
182 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
183 _gtk_boolean_handled_accumulator, NULL,
184 _gtk_marshal_BOOLEAN__VOID,
188 * GtkToolItem::toolbar-reconfigured:
189 * @tool_item: the object the signal was emitted on
191 * This signal is emitted when some property of the toolbar that the
192 * item is a child of changes. For custom subclasses of #GtkToolItem,
193 * the default handler of this signal use the functions
195 * <listitem>gtk_toolbar_get_orientation()</listitem>
196 * <listitem>gtk_toolbar_get_style()</listitem>
197 * <listitem>gtk_toolbar_get_icon_size()</listitem>
198 * <listitem>gtk_toolbar_get_relief_style()</listitem>
200 * to find out what the toolbar should look like and change
201 * themselves accordingly.
203 toolitem_signals[TOOLBAR_RECONFIGURED] =
204 g_signal_new (I_("toolbar_reconfigured"),
205 G_OBJECT_CLASS_TYPE (klass),
207 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
209 _gtk_marshal_VOID__VOID,
212 * GtkToolItem::set-tooltip:
213 * @tool_item: the object the signal was emitted on
214 * @tooltips: the #GtkTooltips
215 * @tip_text: the tooltip text
216 * @tip_private: the tooltip private text
218 * This signal is emitted when the toolitem's tooltip changes.
219 * Application developers can use gtk_tool_item_set_tooltip() to
220 * set the item's tooltip.
222 * Return value: %TRUE if the signal was handled, %FALSE if not
224 * Deprecated: 2.12: With the new tooltip API, there is no
225 * need to use this signal anymore.
227 toolitem_signals[SET_TOOLTIP] =
228 g_signal_new (I_("set_tooltip"),
229 G_OBJECT_CLASS_TYPE (klass),
231 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
232 _gtk_boolean_handled_accumulator, NULL,
233 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
239 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
243 gtk_tool_item_init (GtkToolItem *toolitem)
245 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
247 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
249 toolitem->priv->visible_horizontal = TRUE;
250 toolitem->priv->visible_vertical = TRUE;
251 toolitem->priv->homogeneous = FALSE;
252 toolitem->priv->expand = FALSE;
256 gtk_tool_item_finalize (GObject *object)
258 GtkToolItem *item = GTK_TOOL_ITEM (object);
260 g_free (item->priv->menu_item_id);
262 if (item->priv->menu_item)
263 g_object_unref (item->priv->menu_item);
265 if (G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize)
266 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
270 gtk_tool_item_parent_set (GtkWidget *toolitem,
271 GtkWidget *prev_parent)
273 if (GTK_WIDGET (toolitem)->parent != NULL)
274 _gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
278 gtk_tool_item_set_property (GObject *object,
283 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
287 case PROP_VISIBLE_HORIZONTAL:
288 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
290 case PROP_VISIBLE_VERTICAL:
291 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
293 case PROP_IS_IMPORTANT:
294 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
297 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
302 gtk_tool_item_get_property (GObject *object,
307 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
311 case PROP_VISIBLE_HORIZONTAL:
312 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
314 case PROP_VISIBLE_VERTICAL:
315 g_value_set_boolean (value, toolitem->priv->visible_vertical);
317 case PROP_IS_IMPORTANT:
318 g_value_set_boolean (value, toolitem->priv->is_important);
321 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
326 gtk_tool_item_property_notify (GObject *object,
329 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
331 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
332 gtk_widget_set_sensitive (tool_item->priv->menu_item,
333 GTK_WIDGET_SENSITIVE (tool_item));
337 create_drag_window (GtkToolItem *toolitem)
340 GdkWindowAttr attributes;
341 gint attributes_mask, border_width;
343 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
345 widget = GTK_WIDGET (toolitem);
346 border_width = GTK_CONTAINER (toolitem)->border_width;
348 attributes.window_type = GDK_WINDOW_CHILD;
349 attributes.x = widget->allocation.x + border_width;
350 attributes.y = widget->allocation.y + border_width;
351 attributes.width = widget->allocation.width - border_width * 2;
352 attributes.height = widget->allocation.height - border_width * 2;
353 attributes.wclass = GDK_INPUT_ONLY;
354 attributes.event_mask = gtk_widget_get_events (widget);
355 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
357 attributes_mask = GDK_WA_X | GDK_WA_Y;
359 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
360 &attributes, attributes_mask);
361 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
365 gtk_tool_item_realize (GtkWidget *widget)
367 GtkToolItem *toolitem;
369 toolitem = GTK_TOOL_ITEM (widget);
370 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
372 widget->window = gtk_widget_get_parent_window (widget);
373 g_object_ref (widget->window);
375 if (toolitem->priv->use_drag_window)
376 create_drag_window(toolitem);
378 widget->style = gtk_style_attach (widget->style, widget->window);
382 destroy_drag_window (GtkToolItem *toolitem)
384 if (toolitem->priv->drag_window)
386 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
387 gdk_window_destroy (toolitem->priv->drag_window);
388 toolitem->priv->drag_window = NULL;
393 gtk_tool_item_unrealize (GtkWidget *widget)
395 GtkToolItem *toolitem;
397 toolitem = GTK_TOOL_ITEM (widget);
399 destroy_drag_window (toolitem);
401 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
405 gtk_tool_item_map (GtkWidget *widget)
407 GtkToolItem *toolitem;
409 toolitem = GTK_TOOL_ITEM (widget);
410 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
411 if (toolitem->priv->drag_window)
412 gdk_window_show (toolitem->priv->drag_window);
416 gtk_tool_item_unmap (GtkWidget *widget)
418 GtkToolItem *toolitem;
420 toolitem = GTK_TOOL_ITEM (widget);
421 if (toolitem->priv->drag_window)
422 gdk_window_hide (toolitem->priv->drag_window);
423 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
427 gtk_tool_item_size_request (GtkWidget *widget,
428 GtkRequisition *requisition)
430 GtkWidget *child = GTK_BIN (widget)->child;
432 if (child && GTK_WIDGET_VISIBLE (child))
434 gtk_widget_size_request (child, requisition);
438 requisition->height = 0;
439 requisition->width = 0;
442 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
443 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
447 gtk_tool_item_size_allocate (GtkWidget *widget,
448 GtkAllocation *allocation)
450 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
451 GtkAllocation child_allocation;
453 GtkWidget *child = GTK_BIN (widget)->child;
455 widget->allocation = *allocation;
456 border_width = GTK_CONTAINER (widget)->border_width;
458 if (toolitem->priv->drag_window)
459 gdk_window_move_resize (toolitem->priv->drag_window,
460 widget->allocation.x + border_width,
461 widget->allocation.y + border_width,
462 widget->allocation.width - border_width * 2,
463 widget->allocation.height - border_width * 2);
465 if (child && GTK_WIDGET_VISIBLE (child))
467 child_allocation.x = allocation->x + border_width;
468 child_allocation.y = allocation->y + border_width;
469 child_allocation.width = allocation->width - 2 * border_width;
470 child_allocation.height = allocation->height - 2 * border_width;
472 gtk_widget_size_allocate (child, &child_allocation);
477 gtk_tool_item_create_menu_proxy (GtkToolItem *item)
485 * Creates a new #GtkToolItem
487 * Return value: the new #GtkToolItem
492 gtk_tool_item_new (void)
496 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
502 * gtk_tool_item_get_icon_size:
503 * @tool_item: a #GtkToolItem:
505 * Returns the icon size used for @tool_item. Custom subclasses of
506 * #GtkToolItem should call this function to find out what size icons
509 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
514 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
518 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
520 parent = GTK_WIDGET (tool_item)->parent;
521 if (!parent || !GTK_IS_TOOLBAR (parent))
522 return GTK_ICON_SIZE_LARGE_TOOLBAR;
524 return gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent));
528 * gtk_tool_item_get_orientation:
529 * @tool_item: a #GtkToolItem:
531 * Returns the orientation used for @tool_item. Custom subclasses of
532 * #GtkToolItem should call this function to find out what size icons
535 * Return value: a #GtkOrientation indicating the orientation
536 * used for @tool_item
541 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
545 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
547 parent = GTK_WIDGET (tool_item)->parent;
548 if (!parent || !GTK_IS_TOOLBAR (parent))
549 return GTK_ORIENTATION_HORIZONTAL;
551 return gtk_toolbar_get_orientation (GTK_TOOLBAR (parent));
555 * gtk_tool_item_get_toolbar_style:
556 * @tool_item: a #GtkToolItem:
558 * Returns the toolbar style used for @tool_item. Custom subclasses of
559 * #GtkToolItem should call this function in the handler of the
560 * GtkToolItem::toolbar_reconfigured signal to find out in what style
561 * the toolbar is displayed and change themselves accordingly
565 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
566 * both an icon and a label, stacked vertically </listitem>
567 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
568 * only icons </listitem>
569 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
570 * show text</listitem>
571 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
572 * both an icon and a label, arranged horizontally (however, note the
573 * #GtkToolButton::has_text_horizontally that makes tool buttons not
574 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
578 * Return value: A #GtkToolbarStyle indicating the toolbar style used
584 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
588 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
590 parent = GTK_WIDGET (tool_item)->parent;
591 if (!parent || !GTK_IS_TOOLBAR (parent))
592 return GTK_TOOLBAR_ICONS;
594 return gtk_toolbar_get_style (GTK_TOOLBAR (parent));
598 * gtk_tool_item_get_relief_style:
599 * @tool_item: a #GtkToolItem:
601 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
602 * Custom subclasses of #GtkToolItem should call this function in the handler
603 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
604 * relief style of buttons.
606 * Return value: a #GtkReliefStyle indicating the relief style used
612 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
616 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
618 parent = GTK_WIDGET (tool_item)->parent;
619 if (!parent || !GTK_IS_TOOLBAR (parent))
620 return GTK_RELIEF_NONE;
622 return gtk_toolbar_get_relief_style (GTK_TOOLBAR (parent));
626 * gtk_tool_item_set_expand:
627 * @tool_item: a #GtkToolItem:
628 * @expand: Whether @tool_item is allocated extra space
630 * Sets whether @tool_item is allocated extra space when there
631 * is more room on the toolbar then needed for the items. The
632 * effect is that the item gets bigger when the toolbar gets bigger
633 * and smaller when the toolbar gets smaller.
638 gtk_tool_item_set_expand (GtkToolItem *tool_item,
641 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
643 expand = expand != FALSE;
645 if (tool_item->priv->expand != expand)
647 tool_item->priv->expand = expand;
648 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
649 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
654 * gtk_tool_item_get_expand:
655 * @tool_item: a #GtkToolItem:
657 * Returns whether @tool_item is allocated extra space.
658 * See gtk_tool_item_set_expand().
660 * Return value: %TRUE if @tool_item is allocated extra space.
665 gtk_tool_item_get_expand (GtkToolItem *tool_item)
667 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
669 return tool_item->priv->expand;
673 * gtk_tool_item_set_homogeneous:
674 * @tool_item: a #GtkToolItem:
675 * @homogeneous: whether @tool_item is the same size as other homogeneous items
677 * Sets whether @tool_item is to be allocated the same size as other
678 * homogeneous items. The effect is that all homogeneous items will have
679 * the same width as the widest of the items.
684 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
685 gboolean homogeneous)
687 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
689 homogeneous = homogeneous != FALSE;
691 if (tool_item->priv->homogeneous != homogeneous)
693 tool_item->priv->homogeneous = homogeneous;
694 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
695 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
700 * gtk_tool_item_get_homogeneous:
701 * @tool_item: a #GtkToolItem:
703 * Returns whether @tool_item is the same size as other homogeneous
704 * items. See gtk_tool_item_set_homogeneous().
706 * Return value: %TRUE if the item is the same size as other homogeneous
712 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
714 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
716 return tool_item->priv->homogeneous;
720 * gtk_tool_item_get_is_important:
721 * @tool_item: a #GtkToolItem
723 * Returns whether @tool_item is considered important. See
724 * gtk_tool_item_set_is_important()
726 * Return value: %TRUE if @tool_item is considered important.
731 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
733 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
735 return tool_item->priv->is_important;
739 * gtk_tool_item_set_is_important:
740 * @tool_item: a #GtkToolItem
741 * @is_important: whether the tool item should be considered important
743 * Sets whether @tool_item should be considered important. The #GtkToolButton
744 * class uses this property to determine whether to show or hide its label
745 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
746 * only tool buttons with the "is_important" property set have labels, an
747 * effect known as "priority text"
752 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
754 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
756 is_important = is_important != FALSE;
758 if (is_important != tool_item->priv->is_important)
760 tool_item->priv->is_important = is_important;
762 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
764 g_object_notify (G_OBJECT (tool_item), "is-important");
769 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
770 GtkTooltips *tooltips,
771 const gchar *tip_text,
772 const gchar *tip_private)
774 GtkWidget *child = GTK_BIN (tool_item)->child;
779 gtk_widget_set_tooltip_text (child, tip_text);
785 * gtk_tool_item_set_tooltip:
786 * @tool_item: a #GtkToolItem:
787 * @tooltips: The #GtkTooltips object to be used
788 * @tip_text: text to be used as tooltip text for @tool_item
789 * @tip_private: text to be used as private tooltip text
791 * Sets the #GtkTooltips object to be used for @tool_item, the
792 * text to be displayed as tooltip on the item and the private text
793 * to be used. See gtk_tooltips_set_tip().
797 * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead.
800 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
801 GtkTooltips *tooltips,
802 const gchar *tip_text,
803 const gchar *tip_private)
807 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
809 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
810 tooltips, tip_text, tip_private, &retval);
814 * gtk_tool_item_set_tooltip_text:
815 * @tool_item: a #GtkToolItem:
816 * @text: text to be used as tooltip for @tool_item
818 * Sets the text to be displayed as tooltip on the item.
819 * See gtk_widget_set_tooltip_text().
824 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
829 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
831 child = GTK_BIN (tool_item)->child;
834 gtk_widget_set_tooltip_text (child, text);
838 * gtk_tool_item_set_tooltip_markup:
839 * @tool_item: a #GtkToolItem:
840 * @markup: markup text to be used as tooltip for @tool_item
842 * Sets the markup text to be displayed as tooltip on the item.
843 * See gtk_widget_set_tooltip_markup().
848 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
853 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
855 child = GTK_BIN (tool_item)->child;
858 gtk_widget_set_tooltip_markup (child, markup);
862 * gtk_tool_item_set_use_drag_window:
863 * @tool_item: a #GtkToolItem
864 * @use_drag_window: Whether @tool_item has a drag window.
866 * Sets whether @tool_item has a drag window. When %TRUE the
867 * toolitem can be used as a drag source through gtk_drag_source_set().
868 * When @tool_item has a drag window it will intercept all events,
869 * even those that would otherwise be sent to a child of @tool_item.
874 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
875 gboolean use_drag_window)
877 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
879 use_drag_window = use_drag_window != FALSE;
881 if (toolitem->priv->use_drag_window != use_drag_window)
883 toolitem->priv->use_drag_window = use_drag_window;
887 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
889 create_drag_window(toolitem);
890 if (GTK_WIDGET_MAPPED (toolitem))
891 gdk_window_show (toolitem->priv->drag_window);
896 destroy_drag_window (toolitem);
902 * gtk_tool_item_get_use_drag_window:
903 * @tool_item: a #GtkToolItem
905 * Returns whether @tool_item has a drag window. See
906 * gtk_tool_item_set_use_drag_window().
908 * Return value: %TRUE if @tool_item uses a drag window.
913 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
915 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
917 return toolitem->priv->use_drag_window;
921 * gtk_tool_item_set_visible_horizontal:
922 * @tool_item: a #GtkToolItem
923 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
925 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
930 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
931 gboolean visible_horizontal)
933 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
935 visible_horizontal = visible_horizontal != FALSE;
937 if (toolitem->priv->visible_horizontal != visible_horizontal)
939 toolitem->priv->visible_horizontal = visible_horizontal;
941 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
943 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
948 * gtk_tool_item_get_visible_horizontal:
949 * @tool_item: a #GtkToolItem
951 * Returns whether the @tool_item is visible on toolbars that are
952 * docked horizontally.
954 * Return value: %TRUE if @tool_item is visible on toolbars that are
955 * docked horizontally.
960 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
962 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
964 return toolitem->priv->visible_horizontal;
968 * gtk_tool_item_set_visible_vertical:
969 * @tool_item: a #GtkToolItem
970 * @visible_vertical: whether @tool_item is visible when the toolbar
971 * is in vertical mode
973 * Sets whether @tool_item is visible when the toolbar is docked
974 * vertically. Some tool items, such as text entries, are too wide to be
975 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
976 * @tool_item will not appear on toolbars that are docked vertically.
981 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
982 gboolean visible_vertical)
984 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
986 visible_vertical = visible_vertical != FALSE;
988 if (toolitem->priv->visible_vertical != visible_vertical)
990 toolitem->priv->visible_vertical = visible_vertical;
992 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
994 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
999 * gtk_tool_item_get_visible_vertical:
1000 * @tool_item: a #GtkToolItem
1002 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1003 * See gtk_tool_item_set_visible_vertical().
1005 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1010 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1012 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1014 return toolitem->priv->visible_vertical;
1018 * gtk_tool_item_retrieve_proxy_menu_item:
1019 * @tool_item: a #GtkToolItem:
1021 * Returns the #GtkMenuItem that was last set by
1022 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1023 * that is going to appear in the overflow menu.
1025 * Return value: The #GtkMenuItem that is going to appear in the
1026 * overflow menu for @tool_item.
1031 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1035 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1037 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1040 return tool_item->priv->menu_item;
1044 * gtk_tool_item_get_proxy_menu_item:
1045 * @tool_item: a #GtkToolItem:
1046 * @menu_item_id: a string used to identify the menu item
1048 * If @menu_item_id matches the string passed to
1049 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1051 * Custom subclasses of #GtkToolItem should use this function to update
1052 * their menu item when the #GtkToolItem changes. That the
1053 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1054 * inadvertently change a menu item that they did not create.
1056 * Return value: The #GtkMenuItem passed to
1057 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1062 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1063 const gchar *menu_item_id)
1065 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1066 g_return_val_if_fail (menu_item_id != NULL, NULL);
1068 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1069 return tool_item->priv->menu_item;
1075 * gtk_tool_item_rebuild_menu()
1076 * @tool_item: a #GtkToolItem
1078 * Calling this function signals to the toolbar that the
1079 * overflow menu item for @tool_item has changed. If the
1080 * overflow menu is visible when this function it called,
1081 * the menu will be rebuilt.
1083 * The function must be called when the tool item
1084 * changes what it will do in response to the "create_menu_proxy"
1090 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1094 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1096 widget = GTK_WIDGET (tool_item);
1098 if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
1099 _gtk_toolbar_rebuild_menu (GTK_TOOLBAR (widget->parent));
1103 * gtk_tool_item_set_proxy_menu_item:
1104 * @tool_item: a #GtkToolItem:
1105 * @menu_item_id: a string used to identify @menu_item
1106 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1108 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1109 * @menu_item_id is used to identify the caller of this function and
1110 * should also be used with gtk_tool_item_get_proxy_menu_item().
1115 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1116 const gchar *menu_item_id,
1117 GtkWidget *menu_item)
1119 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1120 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1121 g_return_if_fail (menu_item_id != NULL);
1123 g_free (tool_item->priv->menu_item_id);
1125 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1127 if (tool_item->priv->menu_item != menu_item)
1129 if (tool_item->priv->menu_item)
1130 g_object_unref (tool_item->priv->menu_item);
1134 g_object_ref_sink (menu_item);
1136 gtk_widget_set_sensitive (menu_item,
1137 GTK_WIDGET_SENSITIVE (tool_item));
1140 tool_item->priv->menu_item = menu_item;
1145 * _gtk_tool_item_toolbar_reconfigured:
1146 * @tool_item: a #GtkToolItem:
1148 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item. This
1149 * internal function is called by #GtkToolbar when some aspect of its
1150 * configuration changes.
1155 _gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1157 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1159 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1161 if (tool_item->priv->drag_window)
1162 gdk_window_raise (tool_item->priv->drag_window);
1164 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1167 #define __GTK_TOOL_ITEM_C__
1168 #include "gtkaliasdef.c"