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"
31 #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_init (GtkToolItem *toolitem);
70 static void gtk_tool_item_class_init (GtkToolItemClass *class);
71 static void gtk_tool_item_finalize (GObject *object);
72 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
74 static void gtk_tool_item_set_property (GObject *object,
78 static void gtk_tool_item_get_property (GObject *object,
82 static void gtk_tool_item_property_notify (GObject *object,
84 static void gtk_tool_item_realize (GtkWidget *widget);
85 static void gtk_tool_item_unrealize (GtkWidget *widget);
86 static void gtk_tool_item_map (GtkWidget *widget);
87 static void gtk_tool_item_unmap (GtkWidget *widget);
88 static void gtk_tool_item_size_request (GtkWidget *widget,
89 GtkRequisition *requisition);
90 static void gtk_tool_item_size_allocate (GtkWidget *widget,
91 GtkAllocation *allocation);
92 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
93 GtkTooltips *tooltips,
94 const gchar *tip_text,
95 const gchar *tip_private);
97 static gboolean gtk_tool_item_create_menu_proxy (GtkToolItem *item);
100 static GObjectClass *parent_class = NULL;
101 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
104 gtk_tool_item_get_type (void)
106 static GtkType type = 0;
110 static const GTypeInfo type_info =
112 sizeof (GtkToolItemClass),
113 (GBaseInitFunc) NULL,
114 (GBaseFinalizeFunc) NULL,
115 (GClassInitFunc) gtk_tool_item_class_init,
116 (GClassFinalizeFunc) NULL,
119 sizeof (GtkToolItem),
121 (GInstanceInitFunc) gtk_tool_item_init,
124 type = g_type_register_static (GTK_TYPE_BIN,
132 gtk_tool_item_class_init (GtkToolItemClass *klass)
134 GObjectClass *object_class;
135 GtkWidgetClass *widget_class;
137 parent_class = g_type_class_peek_parent (klass);
138 object_class = (GObjectClass *)klass;
139 widget_class = (GtkWidgetClass *)klass;
141 object_class->set_property = gtk_tool_item_set_property;
142 object_class->get_property = gtk_tool_item_get_property;
143 object_class->finalize = gtk_tool_item_finalize;
144 object_class->notify = gtk_tool_item_property_notify;
146 widget_class->realize = gtk_tool_item_realize;
147 widget_class->unrealize = gtk_tool_item_unrealize;
148 widget_class->map = gtk_tool_item_map;
149 widget_class->unmap = gtk_tool_item_unmap;
150 widget_class->size_request = gtk_tool_item_size_request;
151 widget_class->size_allocate = gtk_tool_item_size_allocate;
152 widget_class->parent_set = gtk_tool_item_parent_set;
154 klass->create_menu_proxy = gtk_tool_item_create_menu_proxy;
155 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
157 g_object_class_install_property (object_class,
158 PROP_VISIBLE_HORIZONTAL,
159 g_param_spec_boolean ("visible-horizontal",
160 P_("Visible when horizontal"),
161 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
163 GTK_PARAM_READWRITE));
164 g_object_class_install_property (object_class,
165 PROP_VISIBLE_VERTICAL,
166 g_param_spec_boolean ("visible-vertical",
167 P_("Visible when vertical"),
168 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
170 GTK_PARAM_READWRITE));
171 g_object_class_install_property (object_class,
173 g_param_spec_boolean ("is-important",
175 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
177 GTK_PARAM_READWRITE));
180 * GtkToolItem::create-menu-proxy:
181 * @toolitem: the object the signal was emitted on
183 * This signal is emitted when the toolbar needs information from @tool_item
184 * about whether the item should appear in the toolbar overflow menu. In
185 * response the tool item should either
187 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a %NULL
188 * pointer and return %TRUE to indicate that the item should not appear
189 * in the overflow menu
191 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
192 * item and return %TRUE, or
194 * <listitem> return %FALSE to indicate that the signal was not
195 * handled by the item. This means that
196 * the item will not appear in the overflow menu unless a later handler
197 * installs a menu item.
201 * The toolbar may cache the result of this signal. When the tool item changes
202 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
203 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
206 * Return value: %TRUE if the signal was handled, %FALSE if not
208 toolitem_signals[CREATE_MENU_PROXY] =
209 g_signal_new ("create_menu_proxy",
210 G_OBJECT_CLASS_TYPE (klass),
212 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
213 _gtk_boolean_handled_accumulator, NULL,
214 _gtk_marshal_BOOLEAN__VOID,
218 * GtkToolItem::toolbar-reconfigured:
219 * @toolitem: the object the signal was emitted on
221 * This signal is emitted when some property of the toolbar that the
222 * item is a child of changes. For custom subclasses of #GtkToolItem,
223 * the default handler of this signal use the functions
225 * <listitem>gtk_toolbar_get_orientation()</listitem>
226 * <listitem>gtk_toolbar_get_style()</listitem>
227 * <listitem>gtk_toolbar_get_icon_size()</listitem>
228 * <listitem>gtk_toolbar_get_relief_style()</listitem>
230 * to find out what the toolbar should look like and change
231 * themselves accordingly.
233 toolitem_signals[TOOLBAR_RECONFIGURED] =
234 g_signal_new ("toolbar_reconfigured",
235 G_OBJECT_CLASS_TYPE (klass),
237 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
239 _gtk_marshal_VOID__VOID,
242 * GtkToolItem::set-tooltip:
243 * @toolitem: the object the signal was emitted on
244 * @tooltips: the #GtkTooltips
245 * @tip_text: the tooltip text
246 * @tip_private: the tooltip private text
248 * This signal is emitted when the toolitem's tooltip changes.
249 * Application developers can use gtk_tool_item_set_tooltip() to
250 * set the item's tooltip.
252 * Return value: %TRUE if the signal was handled, %FALSE if not
254 toolitem_signals[SET_TOOLTIP] =
255 g_signal_new ("set_tooltip",
256 G_OBJECT_CLASS_TYPE (klass),
258 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
259 _gtk_boolean_handled_accumulator, NULL,
260 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
266 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
270 gtk_tool_item_init (GtkToolItem *toolitem)
272 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
274 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
276 toolitem->priv->visible_horizontal = TRUE;
277 toolitem->priv->visible_vertical = TRUE;
278 toolitem->priv->homogeneous = FALSE;
279 toolitem->priv->expand = FALSE;
283 gtk_tool_item_finalize (GObject *object)
285 GtkToolItem *item = GTK_TOOL_ITEM (object);
287 if (item->priv->menu_item_id)
288 g_free (item->priv->menu_item_id);
290 if (item->priv->menu_item)
291 g_object_unref (item->priv->menu_item);
293 if (G_OBJECT_CLASS (parent_class)->finalize)
294 G_OBJECT_CLASS (parent_class)->finalize (object);
298 gtk_tool_item_parent_set (GtkWidget *toolitem,
299 GtkWidget *prev_parent)
301 _gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
305 gtk_tool_item_set_property (GObject *object,
310 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
314 case PROP_VISIBLE_HORIZONTAL:
315 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
317 case PROP_VISIBLE_VERTICAL:
318 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
320 case PROP_IS_IMPORTANT:
321 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
324 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
329 gtk_tool_item_get_property (GObject *object,
334 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
338 case PROP_VISIBLE_HORIZONTAL:
339 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
341 case PROP_VISIBLE_VERTICAL:
342 g_value_set_boolean (value, toolitem->priv->visible_vertical);
344 case PROP_IS_IMPORTANT:
345 g_value_set_boolean (value, toolitem->priv->is_important);
348 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 (parent_class)->unrealize (widget);
432 gtk_tool_item_map (GtkWidget *widget)
434 GtkToolItem *toolitem;
436 toolitem = GTK_TOOL_ITEM (widget);
437 GTK_WIDGET_CLASS (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 (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_TOOLBAR (parent))
549 return GTK_ICON_SIZE_LARGE_TOOLBAR;
551 return gtk_toolbar_get_icon_size (GTK_TOOLBAR (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_TOOLBAR (parent))
576 return GTK_ORIENTATION_HORIZONTAL;
578 return gtk_toolbar_get_orientation (GTK_TOOLBAR (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_TOOLBAR (parent))
619 return GTK_TOOLBAR_ICONS;
621 return gtk_toolbar_get_style (GTK_TOOLBAR (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_TOOLBAR (parent))
647 return GTK_RELIEF_NONE;
649 return gtk_toolbar_get_relief_style (GTK_TOOLBAR (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_tooltips_set_tip (tooltips, child, tip_text, tip_private);
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().
825 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
826 GtkTooltips *tooltips,
827 const gchar *tip_text,
828 const gchar *tip_private)
832 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
834 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
835 tooltips, tip_text, tip_private, &retval);
839 * gtk_tool_item_set_use_drag_window:
840 * @toolitem: a #GtkToolItem
841 * @use_drag_window: Whether @toolitem has a drag window.
843 * Sets whether @toolitem has a drag window. When %TRUE the
844 * toolitem can be used as a drag source through gtk_drag_source_set().
845 * When @toolitem has a drag window it will intercept all events,
846 * even those that would otherwise be sent to a child of @toolitem.
851 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
852 gboolean use_drag_window)
854 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
856 use_drag_window = use_drag_window != FALSE;
858 if (toolitem->priv->use_drag_window != use_drag_window)
860 toolitem->priv->use_drag_window = use_drag_window;
864 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
866 create_drag_window(toolitem);
867 if (GTK_WIDGET_MAPPED (toolitem))
868 gdk_window_show (toolitem->priv->drag_window);
873 destroy_drag_window (toolitem);
879 * gtk_tool_item_get_use_drag_window:
880 * @toolitem: a #GtkToolItem
882 * Returns whether @toolitem has a drag window. See
883 * gtk_tool_item_set_use_drag_window().
885 * Return value: %TRUE if @toolitem uses a drag window.
890 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
892 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
894 return toolitem->priv->use_drag_window;
898 * gtk_tool_item_set_visible_horizontal:
899 * @toolitem: a #GtkToolItem
900 * @visible_horizontal: Whether @toolitem is visible when in horizontal mode
902 * Sets whether @toolitem is visible when the toolbar is docked horizontally.
907 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
908 gboolean visible_horizontal)
910 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
912 visible_horizontal = visible_horizontal != FALSE;
914 if (toolitem->priv->visible_horizontal != visible_horizontal)
916 toolitem->priv->visible_horizontal = visible_horizontal;
918 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
920 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
925 * gtk_tool_item_get_visible_horizontal:
926 * @toolitem: a #GtkToolItem
928 * Returns whether the @toolitem is visible on toolbars that are
929 * docked horizontally.
931 * Return value: %TRUE if @toolitem is visible on toolbars that are
932 * docked horizontally.
937 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
939 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
941 return toolitem->priv->visible_horizontal;
945 * gtk_tool_item_set_visible_vertical:
946 * @toolitem: a #GtkToolItem
947 * @visible_vertical: whether @toolitem is visible when the toolbar
948 * is in vertical mode
950 * Sets whether @toolitem is visible when the toolbar is docked
951 * vertically. Some tool items, such as text entries, are too wide to be
952 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
953 * @toolitem will not appear on toolbars that are docked vertically.
958 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
959 gboolean visible_vertical)
961 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
963 visible_vertical = visible_vertical != FALSE;
965 if (toolitem->priv->visible_vertical != visible_vertical)
967 toolitem->priv->visible_vertical = visible_vertical;
969 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
971 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
976 * gtk_tool_item_get_visible_vertical:
977 * @toolitem: a #GtkToolItem
979 * Returns whether @toolitem is visible when the toolbar is docked vertically.
980 * See gtk_tool_item_set_visible_vertical().
982 * Return value: Whether @toolitem is visible when the toolbar is docked vertically
987 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
989 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
991 return toolitem->priv->visible_vertical;
995 * gtk_tool_item_retrieve_proxy_menu_item:
996 * @tool_item: a #GtkToolItem:
998 * Returns the #GtkMenuItem that was last set by
999 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1000 * that is going to appear in the overflow menu.
1002 * Return value: The #GtkMenuItem that is going to appear in the
1003 * overflow menu for @tool_item.
1008 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1012 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1014 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1017 return tool_item->priv->menu_item;
1021 * gtk_tool_item_get_proxy_menu_item:
1022 * @tool_item: a #GtkToolItem:
1023 * @menu_item_id: a string used to identify the menu item
1025 * If @menu_item_id matches the string passed to
1026 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1028 * Custom subclasses of #GtkToolItem should use this function to update
1029 * their menu item when the #GtkToolItem changes. That the
1030 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1031 * inadvertently change a menu item that they did not create.
1033 * Return value: The #GtkMenuItem passed to
1034 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1039 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1040 const gchar *menu_item_id)
1042 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1043 g_return_val_if_fail (menu_item_id != NULL, NULL);
1045 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1046 return tool_item->priv->menu_item;
1052 * gtk_tool_item_rebuild_menu()
1053 * @tool_item: a #GtkToolItem
1055 * Calling this function signals to the toolbar that the
1056 * overflow menu item for @tool_item has changed. If the
1057 * overflow menu is visible when this function it called,
1058 * the menu will be rebuilt.
1060 * The function must be called when the tool item
1061 * changes what it will do in response to the "create_menu_proxy"
1067 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1071 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1073 widget = GTK_WIDGET (tool_item);
1075 if (widget->parent && GTK_IS_TOOLBAR (widget->parent))
1076 _gtk_toolbar_rebuild_menu (GTK_TOOLBAR (widget->parent));
1080 * gtk_tool_item_set_proxy_menu_item:
1081 * @tool_item: a #GtkToolItem:
1082 * @menu_item_id: a string used to identify @menu_item
1083 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1085 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1086 * @menu_item_id is used to identify the caller of this function and
1087 * should also be used with gtk_tool_item_get_proxy_menu_item().
1092 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1093 const gchar *menu_item_id,
1094 GtkWidget *menu_item)
1096 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1097 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1098 g_return_if_fail (menu_item_id != NULL);
1100 if (tool_item->priv->menu_item_id)
1101 g_free (tool_item->priv->menu_item_id);
1103 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1105 if (tool_item->priv->menu_item != menu_item)
1107 if (tool_item->priv->menu_item)
1108 g_object_unref (tool_item->priv->menu_item);
1112 g_object_ref (menu_item);
1113 gtk_object_sink (GTK_OBJECT (menu_item));
1115 gtk_widget_set_sensitive (menu_item,
1116 GTK_WIDGET_SENSITIVE (tool_item));
1119 tool_item->priv->menu_item = menu_item;
1124 * _gtk_tool_item_toolbar_reconfigured:
1125 * @tool_item: a #GtkToolItem:
1127 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item. This
1128 * internal function is called by #GtkToolbar when some aspect of its
1129 * configuration changes.
1134 _gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1136 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1138 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1140 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1143 #define __GTK_TOOL_ITEM_C__
1144 #include "gtkaliasdef.c"