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 needs information from @tool_item
183 * about whether the item should appear in the toolbar overflow menu. In
184 * response the tool item should either
186 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a %NULL
187 * pointer and return %TRUE to indicate that the item should not appear
188 * in the overflow menu
190 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
191 * item and return %TRUE, or
193 * <listitem> return %FALSE to indicate that the signal was not
194 * handled by the item. This means that
195 * the item will not appear in the overflow menu unless a later handler
196 * installs a menu item.
200 * The toolbar may cache the result of this signal. When the tool item changes
201 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
202 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
205 * Return value: %TRUE if the signal was handled, %FALSE if not
207 toolitem_signals[CREATE_MENU_PROXY] =
208 g_signal_new ("create_menu_proxy",
209 G_OBJECT_CLASS_TYPE (klass),
211 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
212 _gtk_boolean_handled_accumulator, NULL,
213 _gtk_marshal_BOOLEAN__VOID,
217 * GtkToolItem::toolbar-reconfigured:
218 * @toolitem: the object the signal was emitted on
220 * This signal is emitted when some property of the toolbar that the
221 * item is a child of changes. For custom subclasses of #GtkToolItem,
222 * the default handler of this signal use the functions
224 * <listitem>gtk_toolbar_get_orientation()</listitem>
225 * <listitem>gtk_toolbar_get_style()</listitem>
226 * <listitem>gtk_toolbar_get_icon_size()</listitem>
227 * <listitem>gtk_toolbar_get_relief_style()</listitem>
229 * to find out what the toolbar should look like and change
230 * themselves accordingly.
232 toolitem_signals[TOOLBAR_RECONFIGURED] =
233 g_signal_new ("toolbar_reconfigured",
234 G_OBJECT_CLASS_TYPE (klass),
236 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
238 _gtk_marshal_VOID__VOID,
241 * GtkToolItem::set-tooltip:
242 * @toolitem: the object the signal was emitted on
243 * @tooltips: the #GtkTooltips
244 * @tip_text: the tooltip text
245 * @tip_private: the tooltip private text
247 * This signal is emitted when the toolitem's tooltip changes.
248 * Application developers can use gtk_tool_item_set_tooltip() to
249 * set the item's tooltip.
251 * Return value: %TRUE if the signal was handled, %FALSE if not
253 toolitem_signals[SET_TOOLTIP] =
254 g_signal_new ("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 if (item->priv->menu_item_id)
287 g_free (item->priv->menu_item_id);
289 if (item->priv->menu_item)
290 g_object_unref (item->priv->menu_item);
292 if (G_OBJECT_CLASS (parent_class)->finalize)
293 G_OBJECT_CLASS (parent_class)->finalize (object);
297 gtk_tool_item_parent_set (GtkWidget *toolitem,
298 GtkWidget *prev_parent)
300 _gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
304 gtk_tool_item_set_property (GObject *object,
309 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
313 case PROP_VISIBLE_HORIZONTAL:
314 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
316 case PROP_VISIBLE_VERTICAL:
317 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
319 case PROP_IS_IMPORTANT:
320 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
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);
352 gtk_tool_item_property_notify (GObject *object,
355 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
357 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
358 gtk_widget_set_sensitive (tool_item->priv->menu_item,
359 GTK_WIDGET_SENSITIVE (tool_item));
363 create_drag_window (GtkToolItem *toolitem)
366 GdkWindowAttr attributes;
367 gint attributes_mask, border_width;
369 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
371 widget = GTK_WIDGET (toolitem);
372 border_width = GTK_CONTAINER (toolitem)->border_width;
374 attributes.window_type = GDK_WINDOW_CHILD;
375 attributes.x = widget->allocation.x + border_width;
376 attributes.y = widget->allocation.y + border_width;
377 attributes.width = widget->allocation.width - border_width * 2;
378 attributes.height = widget->allocation.height - border_width * 2;
379 attributes.wclass = GDK_INPUT_ONLY;
380 attributes.event_mask = gtk_widget_get_events (widget);
381 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
383 attributes_mask = GDK_WA_X | GDK_WA_Y;
385 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
386 &attributes, attributes_mask);
387 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
391 gtk_tool_item_realize (GtkWidget *widget)
393 GtkToolItem *toolitem;
395 toolitem = GTK_TOOL_ITEM (widget);
396 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
398 widget->window = gtk_widget_get_parent_window (widget);
399 g_object_ref (widget->window);
401 if (toolitem->priv->use_drag_window)
402 create_drag_window(toolitem);
404 widget->style = gtk_style_attach (widget->style, widget->window);
408 destroy_drag_window (GtkToolItem *toolitem)
410 if (toolitem->priv->drag_window)
412 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
413 gdk_window_destroy (toolitem->priv->drag_window);
414 toolitem->priv->drag_window = NULL;
419 gtk_tool_item_unrealize (GtkWidget *widget)
421 GtkToolItem *toolitem;
423 toolitem = GTK_TOOL_ITEM (widget);
425 destroy_drag_window (toolitem);
427 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
431 gtk_tool_item_map (GtkWidget *widget)
433 GtkToolItem *toolitem;
435 toolitem = GTK_TOOL_ITEM (widget);
436 GTK_WIDGET_CLASS (parent_class)->map (widget);
437 if (toolitem->priv->drag_window)
438 gdk_window_show (toolitem->priv->drag_window);
442 gtk_tool_item_unmap (GtkWidget *widget)
444 GtkToolItem *toolitem;
446 toolitem = GTK_TOOL_ITEM (widget);
447 if (toolitem->priv->drag_window)
448 gdk_window_hide (toolitem->priv->drag_window);
449 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
453 gtk_tool_item_size_request (GtkWidget *widget,
454 GtkRequisition *requisition)
456 GtkWidget *child = GTK_BIN (widget)->child;
458 if (child && GTK_WIDGET_VISIBLE (child))
460 gtk_widget_size_request (child, requisition);
464 requisition->height = 0;
465 requisition->width = 0;
468 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
469 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
473 gtk_tool_item_size_allocate (GtkWidget *widget,
474 GtkAllocation *allocation)
476 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
477 GtkAllocation child_allocation;
479 GtkWidget *child = GTK_BIN (widget)->child;
481 widget->allocation = *allocation;
482 border_width = GTK_CONTAINER (widget)->border_width;
484 if (toolitem->priv->drag_window)
485 gdk_window_move_resize (toolitem->priv->drag_window,
486 widget->allocation.x + border_width,
487 widget->allocation.y + border_width,
488 widget->allocation.width - border_width * 2,
489 widget->allocation.height - border_width * 2);
491 if (child && GTK_WIDGET_VISIBLE (child))
493 child_allocation.x = allocation->x + border_width;
494 child_allocation.y = allocation->y + border_width;
495 child_allocation.width = allocation->width - 2 * border_width;
496 child_allocation.height = allocation->height - 2 * border_width;
498 gtk_widget_size_allocate (child, &child_allocation);
503 gtk_tool_item_create_menu_proxy (GtkToolItem *item)
511 * Creates a new #GtkToolItem
513 * Return value: the new #GtkToolItem
518 gtk_tool_item_new (void)
522 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
528 * gtk_tool_item_get_icon_size:
529 * @tool_item: a #GtkToolItem:
531 * Returns the icon size used for @tool_item. Custom subclasses of
532 * #GtkToolItem should call this function to find out what size icons
535 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
540 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
544 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
546 parent = GTK_WIDGET (tool_item)->parent;
547 if (!parent || !GTK_IS_TOOLBAR (parent))
548 return GTK_ICON_SIZE_LARGE_TOOLBAR;
550 return gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent));
554 * gtk_tool_item_get_orientation:
555 * @tool_item: a #GtkToolItem:
557 * Returns the orientation used for @tool_item. Custom subclasses of
558 * #GtkToolItem should call this function to find out what size icons
561 * Return value: a #GtkOrientation indicating the orientation
562 * used for @tool_item
567 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
571 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
573 parent = GTK_WIDGET (tool_item)->parent;
574 if (!parent || !GTK_IS_TOOLBAR (parent))
575 return GTK_ORIENTATION_HORIZONTAL;
577 return gtk_toolbar_get_orientation (GTK_TOOLBAR (parent));
581 * gtk_tool_item_get_toolbar_style:
582 * @tool_item: a #GtkToolItem:
584 * Returns the toolbar style used for @tool_item. Custom subclasses of
585 * #GtkToolItem should call this function in the handler of the
586 * GtkToolItem::toolbar_reconfigured signal to find out in what style
587 * the toolbar is displayed and change themselves accordingly
591 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
592 * both an icon and a label, stacked vertically </listitem>
593 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
594 * only icons </listitem>
595 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
596 * show text</listitem>
597 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
598 * both an icon and a label, arranged horizontally (however, note the
599 * #GtkToolButton::has_text_horizontally that makes tool buttons not
600 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
604 * Return value: A #GtkToolbarStyle indicating the toolbar style used
610 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
614 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
616 parent = GTK_WIDGET (tool_item)->parent;
617 if (!parent || !GTK_IS_TOOLBAR (parent))
618 return GTK_TOOLBAR_ICONS;
620 return gtk_toolbar_get_style (GTK_TOOLBAR (parent));
624 * gtk_tool_item_get_relief_style:
625 * @tool_item: a #GtkToolItem:
627 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
628 * Custom subclasses of #GtkToolItem should call this function in the handler
629 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
630 * relief style of buttons.
632 * Return value: a #GtkReliefStyle indicating the relief style used
638 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
642 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
644 parent = GTK_WIDGET (tool_item)->parent;
645 if (!parent || !GTK_IS_TOOLBAR (parent))
646 return GTK_RELIEF_NONE;
648 return gtk_toolbar_get_relief_style (GTK_TOOLBAR (parent));
652 * gtk_tool_item_set_expand:
653 * @tool_item: a #GtkToolItem:
654 * @expand: Whether @tool_item is allocated extra space
656 * Sets whether @tool_item is allocated extra space when there
657 * is more room on the toolbar then needed for the items. The
658 * effect is that the item gets bigger when the toolbar gets bigger
659 * and smaller when the toolbar gets smaller.
664 gtk_tool_item_set_expand (GtkToolItem *tool_item,
667 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
669 expand = expand != FALSE;
671 if (tool_item->priv->expand != expand)
673 tool_item->priv->expand = expand;
674 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
675 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
680 * gtk_tool_item_get_expand:
681 * @tool_item: a #GtkToolItem:
683 * Returns whether @tool_item is allocated extra space.
684 * See gtk_tool_item_set_expand().
686 * Return value: %TRUE if @tool_item is allocated extra space.
691 gtk_tool_item_get_expand (GtkToolItem *tool_item)
693 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
695 return tool_item->priv->expand;
699 * gtk_tool_item_set_homogeneous:
700 * @tool_item: a #GtkToolItem:
701 * @homogeneous: whether @tool_item is the same size as other homogeneous items
703 * Sets whether @tool_item is to be allocated the same size as other
704 * homogeneous items. The effect is that all homogeneous items will have
705 * the same width as the widest of the items.
710 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
711 gboolean homogeneous)
713 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
715 homogeneous = homogeneous != FALSE;
717 if (tool_item->priv->homogeneous != homogeneous)
719 tool_item->priv->homogeneous = homogeneous;
720 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
721 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
726 * gtk_tool_item_get_homogeneous:
727 * @tool_item: a #GtkToolItem:
729 * Returns whether @tool_item is the same size as other homogeneous
730 * items. See gtk_tool_item_set_homogeneous().
732 * Return value: %TRUE if the item is the same size as other homogeneous
738 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
740 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
742 return tool_item->priv->homogeneous;
746 * gtk_tool_item_get_is_important:
747 * @tool_item: a #GtkToolItem
749 * Returns whether @tool_item is considered important. See
750 * gtk_tool_item_set_is_important()
752 * Return value: %TRUE if @tool_item is considered important.
757 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
759 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
761 return tool_item->priv->is_important;
765 * gtk_tool_item_set_is_important:
766 * @tool_item: a #GtkToolItem
767 * @is_important: whether the tool item should be considered important
769 * Sets whether @tool_item should be considered important. The #GtkToolButton
770 * class uses this property to determine whether to show or hide its label
771 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
772 * only tool buttons with the "is_important" property set have labels, an
773 * effect known as "priority text"
778 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
780 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
782 is_important = is_important != FALSE;
784 if (is_important != tool_item->priv->is_important)
786 tool_item->priv->is_important = is_important;
788 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
790 g_object_notify (G_OBJECT (tool_item), "is_important");
795 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
796 GtkTooltips *tooltips,
797 const gchar *tip_text,
798 const gchar *tip_private)
800 GtkWidget *child = GTK_BIN (tool_item)->child;
805 gtk_tooltips_set_tip (tooltips, child, tip_text, tip_private);
811 * gtk_tool_item_set_tooltip:
812 * @tool_item: a #GtkToolItem:
813 * @tooltips: The #GtkTooltips object to be used
814 * @tip_text: text to be used as tooltip text for @tool_item
815 * @tip_private: text to be used as private tooltip text
817 * Sets the #GtkTooltips object to be used for @tool_item, the
818 * text to be displayed as tooltip on the item and the private text
819 * to be used. See gtk_tooltips_set_tip().
824 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
825 GtkTooltips *tooltips,
826 const gchar *tip_text,
827 const gchar *tip_private)
831 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
833 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
834 tooltips, tip_text, tip_private, &retval);
838 * gtk_tool_item_set_use_drag_window:
839 * @toolitem: a #GtkToolItem
840 * @use_drag_window: Whether @toolitem has a drag window.
842 * Sets whether @toolitem has a drag window. When %TRUE the
843 * toolitem can be used as a drag source through gtk_drag_source_set().
844 * When @toolitem has a drag window it will intercept all events,
845 * even those that would otherwise be sent to a child of @toolitem.
850 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
851 gboolean use_drag_window)
853 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
855 use_drag_window = use_drag_window != FALSE;
857 if (toolitem->priv->use_drag_window != use_drag_window)
859 toolitem->priv->use_drag_window = use_drag_window;
863 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
865 create_drag_window(toolitem);
866 if (GTK_WIDGET_MAPPED (toolitem))
867 gdk_window_show (toolitem->priv->drag_window);
872 destroy_drag_window (toolitem);
878 * gtk_tool_item_get_use_drag_window:
879 * @toolitem: a #GtkToolItem
881 * Returns whether @toolitem has a drag window. See
882 * gtk_tool_item_set_use_drag_window().
884 * Return value: %TRUE if @toolitem uses a drag window.
889 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
891 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
893 return toolitem->priv->use_drag_window;
897 * gtk_tool_item_set_visible_horizontal:
898 * @toolitem: a #GtkToolItem
899 * @visible_horizontal: Whether @toolitem is visible when in horizontal mode
901 * Sets whether @toolitem is visible when the toolbar is docked horizontally.
906 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
907 gboolean visible_horizontal)
909 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
911 visible_horizontal = visible_horizontal != FALSE;
913 if (toolitem->priv->visible_horizontal != visible_horizontal)
915 toolitem->priv->visible_horizontal = visible_horizontal;
917 g_object_notify (G_OBJECT (toolitem), "visible_horizontal");
919 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
924 * gtk_tool_item_get_visible_horizontal:
925 * @toolitem: a #GtkToolItem
927 * Returns whether the @toolitem is visible on toolbars that are
928 * docked horizontally.
930 * Return value: %TRUE if @toolitem is visible on toolbars that are
931 * docked horizontally.
936 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
938 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
940 return toolitem->priv->visible_horizontal;
944 * gtk_tool_item_set_visible_vertical:
945 * @toolitem: a #GtkToolItem
946 * @visible_vertical: whether @toolitem is visible when the toolbar
947 * is in vertical mode
949 * Sets whether @toolitem is visible when the toolbar is docked
950 * vertically. Some tool items, such as text entries, are too wide to be
951 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
952 * @toolitem will not appear on toolbars that are docked vertically.
957 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
958 gboolean visible_vertical)
960 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
962 visible_vertical = visible_vertical != FALSE;
964 if (toolitem->priv->visible_vertical != visible_vertical)
966 toolitem->priv->visible_vertical = visible_vertical;
968 g_object_notify (G_OBJECT (toolitem), "visible_vertical");
970 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
975 * gtk_tool_item_get_visible_vertical:
976 * @toolitem: a #GtkToolItem
978 * Returns whether @toolitem is visible when the toolbar is docked vertically.
979 * See gtk_tool_item_set_visible_vertical().
981 * Return value: Whether @toolitem is visible when the toolbar is docked vertically
986 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
988 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
990 return toolitem->priv->visible_vertical;
994 * gtk_tool_item_retrieve_proxy_menu_item:
995 * @tool_item: a #GtkToolItem:
997 * Returns the #GtkMenuItem that was last set by
998 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
999 * that is going to appear in the overflow menu.
1001 * Return value: The #GtkMenuItem that is going to appear in the
1002 * overflow menu for @tool_item.
1007 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1011 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1013 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1016 return tool_item->priv->menu_item;
1020 * gtk_tool_item_get_proxy_menu_item:
1021 * @tool_item: a #GtkToolItem:
1022 * @menu_item_id: a string used to identify the menu item
1024 * If @menu_item_id matches the string passed to
1025 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1027 * Custom subclasses of #GtkToolItem should use this function to update
1028 * their menu item when the #GtkToolItem changes. That the
1029 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1030 * inadvertently change a menu item that they did not create.
1032 * Return value: The #GtkMenuItem passed to
1033 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1038 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1039 const gchar *menu_item_id)
1041 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1042 g_return_val_if_fail (menu_item_id != NULL, NULL);
1044 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1045 return tool_item->priv->menu_item;
1051 * gtk_tool_item_rebuild_menu()
1052 * @tool_item: a #GtkToolItem
1054 * Calling this function signals to the toolbar that the
1055 * overflow menu item for @tool_item has changed. If the
1056 * overflow menu is visible when this function it called,
1057 * the menu will be rebuilt.
1059 * The function must be called when the tool item
1060 * changes what it will do in response to the "create_menu_proxy"
1066 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1070 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1072 widget = GTK_WIDGET (tool_item);
1074 if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
1075 _gtk_toolbar_rebuild_menu (GTK_TOOLBAR (widget->parent));
1079 * gtk_tool_item_set_proxy_menu_item:
1080 * @tool_item: a #GtkToolItem:
1081 * @menu_item_id: a string used to identify @menu_item
1082 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1084 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1085 * @menu_item_id is used to identify the caller of this function and
1086 * should also be used with gtk_tool_item_get_proxy_menu_item().
1091 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1092 const gchar *menu_item_id,
1093 GtkWidget *menu_item)
1095 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1096 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1097 g_return_if_fail (menu_item_id != NULL);
1099 if (tool_item->priv->menu_item_id)
1100 g_free (tool_item->priv->menu_item_id);
1102 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1104 if (tool_item->priv->menu_item != menu_item)
1106 if (tool_item->priv->menu_item)
1107 g_object_unref (G_OBJECT (tool_item->priv->menu_item));
1111 g_object_ref (menu_item);
1112 gtk_object_sink (GTK_OBJECT (menu_item));
1114 gtk_widget_set_sensitive (menu_item,
1115 GTK_WIDGET_SENSITIVE (tool_item));
1118 tool_item->priv->menu_item = menu_item;
1123 * _gtk_tool_item_toolbar_reconfigured:
1124 * @tool_item: a #GtkToolItem:
1126 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item. This
1127 * internal function is called by #GtkToolbar when some aspect of its
1128 * configuration changes.
1133 _gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1135 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1137 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1139 gtk_widget_queue_resize (GTK_WIDGET (tool_item));