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.
25 #include "gtktoolitem.h"
26 #include "gtkmarshalers.h"
27 #include "gtktoolbar.h"
28 #include "gtkseparatormenuitem.h"
43 PROP_VISIBLE_HORIZONTAL,
44 PROP_VISIBLE_VERTICAL,
48 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
50 struct _GtkToolItemPrivate
55 guint visible_horizontal : 1;
56 guint visible_vertical : 1;
57 guint homogeneous : 1;
59 guint use_drag_window : 1;
60 guint is_important : 1;
62 GdkWindow *drag_window;
68 static void gtk_tool_item_init (GtkToolItem *toolitem);
69 static void gtk_tool_item_class_init (GtkToolItemClass *class);
70 static void gtk_tool_item_finalize (GObject *object);
71 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
73 static void gtk_tool_item_set_property (GObject *object,
77 static void gtk_tool_item_get_property (GObject *object,
81 static void gtk_tool_item_property_notify (GObject *object,
83 static void gtk_tool_item_realize (GtkWidget *widget);
84 static void gtk_tool_item_unrealize (GtkWidget *widget);
85 static void gtk_tool_item_map (GtkWidget *widget);
86 static void gtk_tool_item_unmap (GtkWidget *widget);
87 static void gtk_tool_item_size_request (GtkWidget *widget,
88 GtkRequisition *requisition);
89 static void gtk_tool_item_size_allocate (GtkWidget *widget,
90 GtkAllocation *allocation);
91 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
92 GtkTooltips *tooltips,
93 const gchar *tip_text,
94 const gchar *tip_private);
96 static gboolean gtk_tool_item_create_menu_proxy (GtkToolItem *item);
99 static GObjectClass *parent_class = NULL;
100 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
103 gtk_tool_item_get_type (void)
105 static GtkType type = 0;
109 static const GTypeInfo type_info =
111 sizeof (GtkToolItemClass),
112 (GBaseInitFunc) NULL,
113 (GBaseFinalizeFunc) NULL,
114 (GClassInitFunc) gtk_tool_item_class_init,
115 (GClassFinalizeFunc) NULL,
118 sizeof (GtkToolItem),
120 (GInstanceInitFunc) gtk_tool_item_init,
123 type = g_type_register_static (GTK_TYPE_BIN,
131 gtk_tool_item_class_init (GtkToolItemClass *klass)
133 GObjectClass *object_class;
134 GtkWidgetClass *widget_class;
136 parent_class = g_type_class_peek_parent (klass);
137 object_class = (GObjectClass *)klass;
138 widget_class = (GtkWidgetClass *)klass;
140 object_class->set_property = gtk_tool_item_set_property;
141 object_class->get_property = gtk_tool_item_get_property;
142 object_class->finalize = gtk_tool_item_finalize;
143 object_class->notify = gtk_tool_item_property_notify;
145 widget_class->realize = gtk_tool_item_realize;
146 widget_class->unrealize = gtk_tool_item_unrealize;
147 widget_class->map = gtk_tool_item_map;
148 widget_class->unmap = gtk_tool_item_unmap;
149 widget_class->size_request = gtk_tool_item_size_request;
150 widget_class->size_allocate = gtk_tool_item_size_allocate;
151 widget_class->parent_set = gtk_tool_item_parent_set;
153 klass->create_menu_proxy = gtk_tool_item_create_menu_proxy;
154 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
156 g_object_class_install_property (object_class,
157 PROP_VISIBLE_HORIZONTAL,
158 g_param_spec_boolean ("visible_horizontal",
159 P_("Visible when horizontal"),
160 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
163 g_object_class_install_property (object_class,
164 PROP_VISIBLE_VERTICAL,
165 g_param_spec_boolean ("visible_vertical",
166 P_("Visible when vertical"),
167 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
170 g_object_class_install_property (object_class,
172 g_param_spec_boolean ("is_important",
174 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
179 * GtkToolItem::create-menu-proxy:
180 * @toolitem: the object the signal was emitted on
182 * This signal is emitted when the toolbar is displaying an overflow menu.
183 * In response the tool item should either
185 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a %NULL
186 * pointer and return %TRUE to indicate that the item should not appear
187 * in the overflow menu
189 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
190 * item and return %TRUE, or
192 * <listitem> return %FALSE to indicate that the signal was not
193 * handled by the item. This means that
194 * the item will not appear in the overflow menu unless a later handler
195 * installs a menu item.
199 * Return value: %TRUE if the signal was handled, %FALSE if not
201 toolitem_signals[CREATE_MENU_PROXY] =
202 g_signal_new ("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 * @toolitem: 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_toolbar_get_orientation()</listitem>
219 * <listitem>gtk_toolbar_get_style()</listitem>
220 * <listitem>gtk_toolbar_get_icon_size()</listitem>
221 * <listitem>gtk_toolbar_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 ("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 * @toolitem: 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 toolitem_signals[SET_TOOLTIP] =
248 g_signal_new ("set_tooltip",
249 G_OBJECT_CLASS_TYPE (klass),
251 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
252 _gtk_boolean_handled_accumulator, NULL,
253 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
259 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
263 gtk_tool_item_init (GtkToolItem *toolitem)
265 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
267 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
269 toolitem->priv->visible_horizontal = TRUE;
270 toolitem->priv->visible_vertical = TRUE;
271 toolitem->priv->homogeneous = FALSE;
272 toolitem->priv->expand = FALSE;
276 gtk_tool_item_finalize (GObject *object)
278 GtkToolItem *item = GTK_TOOL_ITEM (object);
280 if (item->priv->menu_item_id)
281 g_free (item->priv->menu_item_id);
283 if (item->priv->menu_item)
284 g_object_unref (item->priv->menu_item);
286 if (G_OBJECT_CLASS (parent_class)->finalize)
287 G_OBJECT_CLASS (parent_class)->finalize (object);
291 gtk_tool_item_parent_set (GtkWidget *toolitem,
292 GtkWidget *prev_parent)
294 _gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
298 gtk_tool_item_set_property (GObject *object,
303 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
307 case PROP_VISIBLE_HORIZONTAL:
308 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
310 case PROP_VISIBLE_VERTICAL:
311 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
313 case PROP_IS_IMPORTANT:
314 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
317 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
322 gtk_tool_item_get_property (GObject *object,
327 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
331 case PROP_VISIBLE_HORIZONTAL:
332 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
334 case PROP_VISIBLE_VERTICAL:
335 g_value_set_boolean (value, toolitem->priv->visible_vertical);
337 case PROP_IS_IMPORTANT:
338 g_value_set_boolean (value, toolitem->priv->is_important);
341 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
346 gtk_tool_item_property_notify (GObject *object,
349 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
351 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
352 gtk_widget_set_sensitive (tool_item->priv->menu_item,
353 GTK_WIDGET_SENSITIVE (tool_item));
357 create_drag_window (GtkToolItem *toolitem)
360 GdkWindowAttr attributes;
361 gint attributes_mask, border_width;
363 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
365 widget = GTK_WIDGET (toolitem);
366 border_width = GTK_CONTAINER (toolitem)->border_width;
368 attributes.window_type = GDK_WINDOW_CHILD;
369 attributes.x = widget->allocation.x + border_width;
370 attributes.y = widget->allocation.y + border_width;
371 attributes.width = widget->allocation.width - border_width * 2;
372 attributes.height = widget->allocation.height - border_width * 2;
373 attributes.wclass = GDK_INPUT_ONLY;
374 attributes.event_mask = gtk_widget_get_events (widget);
375 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
377 attributes_mask = GDK_WA_X | GDK_WA_Y;
379 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
380 &attributes, attributes_mask);
381 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
385 gtk_tool_item_realize (GtkWidget *widget)
387 GtkToolItem *toolitem;
389 toolitem = GTK_TOOL_ITEM (widget);
390 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
392 widget->window = gtk_widget_get_parent_window (widget);
393 g_object_ref (widget->window);
395 if (toolitem->priv->use_drag_window)
396 create_drag_window(toolitem);
398 widget->style = gtk_style_attach (widget->style, widget->window);
402 destroy_drag_window (GtkToolItem *toolitem)
404 if (toolitem->priv->drag_window)
406 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
407 gdk_window_destroy (toolitem->priv->drag_window);
408 toolitem->priv->drag_window = NULL;
413 gtk_tool_item_unrealize (GtkWidget *widget)
415 GtkToolItem *toolitem;
417 toolitem = GTK_TOOL_ITEM (widget);
419 destroy_drag_window (toolitem);
421 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
425 gtk_tool_item_map (GtkWidget *widget)
427 GtkToolItem *toolitem;
429 toolitem = GTK_TOOL_ITEM (widget);
430 GTK_WIDGET_CLASS (parent_class)->map (widget);
431 if (toolitem->priv->drag_window)
432 gdk_window_show (toolitem->priv->drag_window);
436 gtk_tool_item_unmap (GtkWidget *widget)
438 GtkToolItem *toolitem;
440 toolitem = GTK_TOOL_ITEM (widget);
441 if (toolitem->priv->drag_window)
442 gdk_window_hide (toolitem->priv->drag_window);
443 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
447 gtk_tool_item_size_request (GtkWidget *widget,
448 GtkRequisition *requisition)
450 GtkWidget *child = GTK_BIN (widget)->child;
452 if (child && GTK_WIDGET_VISIBLE (child))
454 gtk_widget_size_request (child, requisition);
458 requisition->height = 0;
459 requisition->width = 0;
462 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
463 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
467 gtk_tool_item_size_allocate (GtkWidget *widget,
468 GtkAllocation *allocation)
470 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
471 GtkAllocation child_allocation;
473 GtkWidget *child = GTK_BIN (widget)->child;
475 widget->allocation = *allocation;
476 border_width = GTK_CONTAINER (widget)->border_width;
478 if (toolitem->priv->drag_window)
479 gdk_window_move_resize (toolitem->priv->drag_window,
480 widget->allocation.x + border_width,
481 widget->allocation.y + border_width,
482 widget->allocation.width - border_width * 2,
483 widget->allocation.height - border_width * 2);
485 if (child && GTK_WIDGET_VISIBLE (child))
487 child_allocation.x = allocation->x + border_width;
488 child_allocation.y = allocation->y + border_width;
489 child_allocation.width = allocation->width - 2 * border_width;
490 child_allocation.height = allocation->height - 2 * border_width;
492 gtk_widget_size_allocate (child, &child_allocation);
497 gtk_tool_item_create_menu_proxy (GtkToolItem *item)
505 * Creates a new #GtkToolItem
507 * Return value: the new #GtkToolItem
512 gtk_tool_item_new (void)
516 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
522 * gtk_tool_item_get_icon_size:
523 * @tool_item: a #GtkToolItem:
525 * Returns the icon size used for @tool_item. Custom subclasses of
526 * #GtkToolItem should call this function to find out what size icons
529 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
534 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
538 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
540 parent = GTK_WIDGET (tool_item)->parent;
541 if (!parent || !GTK_IS_TOOLBAR (parent))
542 return GTK_ICON_SIZE_LARGE_TOOLBAR;
544 return gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent));
548 * gtk_tool_item_get_orientation:
549 * @tool_item: a #GtkToolItem:
551 * Returns the orientation used for @tool_item. Custom subclasses of
552 * #GtkToolItem should call this function to find out what size icons
555 * Return value: a #GtkOrientation indicating the orientation
556 * used for @tool_item
561 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
565 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
567 parent = GTK_WIDGET (tool_item)->parent;
568 if (!parent || !GTK_IS_TOOLBAR (parent))
569 return GTK_ORIENTATION_HORIZONTAL;
571 return gtk_toolbar_get_orientation (GTK_TOOLBAR (parent));
575 * gtk_tool_item_get_toolbar_style:
576 * @tool_item: a #GtkToolItem:
578 * Returns the toolbar style used for @tool_item. Custom subclasses of
579 * #GtkToolItem should call this function in the handler of the
580 * GtkToolItem::toolbar_reconfigured signal to find out in what style
581 * the toolbar is displayed and change themselves accordingly
585 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
586 * both an icon and a label, stacked vertically </listitem>
587 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
588 * only icons </listitem>
589 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
590 * show text</listitem>
591 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
592 * both an icon and a label, arranged horizontally (however, note the
593 * #GtkToolButton::has_text_horizontally that makes tool buttons not
594 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
598 * Return value: A #GtkToolbarStyle indicating the toolbar style used
604 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
608 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
610 parent = GTK_WIDGET (tool_item)->parent;
611 if (!parent || !GTK_IS_TOOLBAR (parent))
612 return GTK_TOOLBAR_ICONS;
614 return gtk_toolbar_get_style (GTK_TOOLBAR (parent));
618 * gtk_tool_item_get_relief_style:
619 * @tool_item: a #GtkToolItem:
621 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
622 * Custom subclasses of #GtkToolItem should call this function in the handler
623 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
624 * relief style of buttons.
626 * Return value: a #GtkReliefStyle indicating the relief style used
632 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
636 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
638 parent = GTK_WIDGET (tool_item)->parent;
639 if (!parent || !GTK_IS_TOOLBAR (parent))
640 return GTK_RELIEF_NONE;
642 return gtk_toolbar_get_relief_style (GTK_TOOLBAR (parent));
646 * gtk_tool_item_set_expand:
647 * @tool_item: a #GtkToolItem:
648 * @expand: Whether @tool_item is allocated extra space
650 * Sets whether @tool_item is allocated extra space when there
651 * is more room on the toolbar then needed for the items. The
652 * effect is that the item gets bigger when the toolbar gets bigger
653 * and smaller when the toolbar gets smaller.
658 gtk_tool_item_set_expand (GtkToolItem *tool_item,
661 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
663 expand = expand != FALSE;
665 if (tool_item->priv->expand != expand)
667 tool_item->priv->expand = expand;
668 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
669 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
674 * gtk_tool_item_get_expand:
675 * @tool_item: a #GtkToolItem:
677 * Returns whether @tool_item is allocated extra space.
678 * See gtk_tool_item_set_expand().
680 * Return value: %TRUE if @tool_item is allocated extra space.
685 gtk_tool_item_get_expand (GtkToolItem *tool_item)
687 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
689 return tool_item->priv->expand;
693 * gtk_tool_item_set_homogeneous:
694 * @tool_item: a #GtkToolItem:
695 * @homogeneous: whether @tool_item is the same size as other homogeneous items
697 * Sets whether @tool_item is to be allocated the same size as other
698 * homogeneous items. The effect is that all homogeneous items will have
699 * the same width as the widest of the items.
704 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
705 gboolean homogeneous)
707 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
709 homogeneous = homogeneous != FALSE;
711 if (tool_item->priv->homogeneous != homogeneous)
713 tool_item->priv->homogeneous = homogeneous;
714 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
715 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
720 * gtk_tool_item_get_homogeneous:
721 * @tool_item: a #GtkToolItem:
723 * Returns whether @tool_item is the same size as other homogeneous
724 * items. See gtk_tool_item_set_homogeneous().
726 * Return value: %TRUE if the item is the same size as other homogeneous
732 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
734 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
736 return tool_item->priv->homogeneous;
740 * gtk_tool_item_get_is_important:
741 * @tool_item: a #GtkToolItem
743 * Returns whether @tool_item is considered important. See
744 * gtk_tool_item_set_is_important()
746 * Return value: %TRUE if @tool_item is considered important.
751 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
753 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
755 return tool_item->priv->is_important;
759 * gtk_tool_item_set_is_important:
760 * @tool_item: a #GtkToolItem
761 * @is_important: whether the tool item should be considered important
763 * Sets whether @tool_item should be considered important. The #GtkToolButton
764 * class uses this property to determine whether to show or hide its label
765 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
766 * only tool buttons with the "is_important" property set have labels, an
767 * effect known as "priority text"
772 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
774 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
776 is_important = is_important != FALSE;
778 if (is_important != tool_item->priv->is_important)
780 tool_item->priv->is_important = is_important;
782 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
784 g_object_notify (G_OBJECT (tool_item), "is_important");
789 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
790 GtkTooltips *tooltips,
791 const gchar *tip_text,
792 const gchar *tip_private)
794 GtkWidget *child = GTK_BIN (tool_item)->child;
799 gtk_tooltips_set_tip (tooltips, child, tip_text, tip_private);
805 * gtk_tool_item_set_tooltip:
806 * @tool_item: a #GtkToolItem:
807 * @tooltips: The #GtkTooltips object to be used
808 * @tip_text: text to be used as tooltip text for @tool_item
809 * @tip_private: text to be used as private tooltip text
811 * Sets the #GtkTooltips object to be used for @tool_item, the
812 * text to be displayed as tooltip on the item and the private text
813 * to be used. See gtk_tooltips_set_tip().
818 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
819 GtkTooltips *tooltips,
820 const gchar *tip_text,
821 const gchar *tip_private)
825 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
827 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
828 tooltips, tip_text, tip_private, &retval);
832 * gtk_tool_item_set_use_drag_window:
833 * @toolitem: a #GtkToolItem
834 * @use_drag_window: Whether @toolitem has a drag window.
836 * Sets whether @toolitem has a drag window. When %TRUE the
837 * toolitem can be used as a drag source through gtk_drag_source_set().
838 * When @toolitem has a drag window it will intercept all events,
839 * even those that would otherwise be sent to a child of @toolitem.
844 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
845 gboolean use_drag_window)
847 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
849 use_drag_window = use_drag_window != FALSE;
851 if (toolitem->priv->use_drag_window != use_drag_window)
853 toolitem->priv->use_drag_window = use_drag_window;
857 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
859 create_drag_window(toolitem);
860 if (GTK_WIDGET_MAPPED (toolitem))
861 gdk_window_show (toolitem->priv->drag_window);
866 destroy_drag_window (toolitem);
872 * gtk_tool_item_get_use_drag_window:
873 * @toolitem: a #GtkToolItem
875 * Returns whether @toolitem has a drag window. See
876 * gtk_tool_item_set_use_drag_window().
878 * Return value: %TRUE if @toolitem uses a drag window.
883 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
885 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
887 return toolitem->priv->use_drag_window;
891 * gtk_tool_item_set_visible_horizontal:
892 * @toolitem: a #GtkToolItem
893 * @visible_horizontal: Whether @toolitem is visible when in horizontal mode
895 * Sets whether @toolitem is visible when the toolbar is docked horizontally.
900 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
901 gboolean visible_horizontal)
903 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
905 visible_horizontal = visible_horizontal != FALSE;
907 if (toolitem->priv->visible_horizontal != visible_horizontal)
909 toolitem->priv->visible_horizontal = visible_horizontal;
911 g_object_notify (G_OBJECT (toolitem), "visible_horizontal");
913 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
918 * gtk_tool_item_get_visible_horizontal:
919 * @toolitem: a #GtkToolItem
921 * Returns whether the @toolitem is visible on toolbars that are
922 * docked horizontally.
924 * Return value: %TRUE if @toolitem is visible on toolbars that are
925 * docked horizontally.
930 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
932 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
934 return toolitem->priv->visible_horizontal;
938 * gtk_tool_item_set_visible_vertical:
939 * @toolitem: a #GtkToolItem
940 * @visible_vertical: whether @toolitem is visible when the toolbar
941 * is in vertical mode
943 * Sets whether @toolitem is visible when the toolbar is docked
944 * vertically. Some tool items, such as text entries, are too wide to be
945 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
946 * @toolitem will not appear on toolbars that are docked vertically.
951 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
952 gboolean visible_vertical)
954 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
956 visible_vertical = visible_vertical != FALSE;
958 if (toolitem->priv->visible_vertical != visible_vertical)
960 toolitem->priv->visible_vertical = visible_vertical;
962 g_object_notify (G_OBJECT (toolitem), "visible_vertical");
964 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
969 * gtk_tool_item_get_visible_vertical:
970 * @toolitem: a #GtkToolItem
972 * Returns whether @toolitem is visible when the toolbar is docked vertically.
973 * See gtk_tool_item_set_visible_vertical().
975 * Return value: Whether @toolitem is visible when the toolbar is docked vertically
980 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
982 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
984 return toolitem->priv->visible_vertical;
988 * gtk_tool_item_retrieve_proxy_menu_item:
989 * @tool_item: a #GtkToolItem:
991 * Returns the #GtkMenuItem that was last set by
992 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
993 * that is going to appear in the overflow menu.
995 * Return value: The #GtkMenuItem that is going to appear in the
996 * overflow menu for @tool_item.
1001 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1005 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1007 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0, &retval);
1009 return tool_item->priv->menu_item;
1013 * gtk_tool_item_get_proxy_menu_item:
1014 * @tool_item: a #GtkToolItem:
1015 * @menu_item_id: a string used to identify the menu item
1017 * If @menu_item_id matches the string passed to
1018 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1020 * Custom subclasses of #GtkToolItem should use this function to update
1021 * their menu item when the #GtkToolItem changes. That the
1022 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1023 * inadvertently change a menu item that they did not create.
1025 * Return value: The #GtkMenuItem passed to
1026 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1031 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1032 const gchar *menu_item_id)
1034 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1035 g_return_val_if_fail (menu_item_id != NULL, NULL);
1037 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1038 return tool_item->priv->menu_item;
1044 * gtk_tool_item_set_proxy_menu_item:
1045 * @tool_item: a #GtkToolItem:
1046 * @menu_item_id: a string used to identify @menu_item
1047 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1049 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1050 * @menu_item_id is used to identify the caller of this function and
1051 * should also be used with gtk_tool_item_get_proxy_menu_item().
1056 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1057 const gchar *menu_item_id,
1058 GtkWidget *menu_item)
1060 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1061 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1062 g_return_if_fail (menu_item_id != NULL);
1064 if (tool_item->priv->menu_item_id)
1065 g_free (tool_item->priv->menu_item_id);
1067 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1069 if (tool_item->priv->menu_item != menu_item)
1071 if (tool_item->priv->menu_item)
1072 g_object_unref (G_OBJECT (tool_item->priv->menu_item));
1076 g_object_ref (menu_item);
1077 gtk_object_sink (GTK_OBJECT (menu_item));
1079 gtk_widget_set_sensitive (menu_item,
1080 GTK_WIDGET_SENSITIVE (tool_item));
1083 tool_item->priv->menu_item = menu_item;
1088 * _gtk_tool_item_toolbar_reconfigured:
1089 * @tool_item: a #GtkToolItem:
1091 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item. This
1092 * internal function is called by #GtkToolbar when some aspect of its
1093 * configuration changes.
1098 _gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1100 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1102 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1104 gtk_widget_queue_resize (GTK_WIDGET (tool_item));