3 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
4 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
5 * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #undef GTK_DISABLE_DEPRECATED /* GtkTooltips */
29 #include "gtktoolitem.h"
30 #include "gtkmarshalers.h"
31 #include "gtktoolshell.h"
32 #include "gtkseparatormenuitem.h"
33 #include "gtkactivatable.h"
36 #include "gtkprivate.h"
41 * @short_description: The base class of widgets that can be added to GtkToolShell
43 * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
44 * create a toolbar item that contain something else than a button, use
45 * gtk_tool_item_new(). Use gtk_container_add() to add a child
46 * widget to the tool item.
48 * For toolbar items that contain buttons, see the #GtkToolButton,
49 * #GtkToggleToolButton and #GtkRadioToolButton classes.
51 * See the #GtkToolbar class for a description of the toolbar widget, and
52 * #GtkToolShell for a description of the tool shell interface.
58 * The GtkToolItem struct contains only private data.
59 * It should only be accessed through the functions described below.
71 PROP_VISIBLE_HORIZONTAL,
72 PROP_VISIBLE_VERTICAL,
75 /* activatable properties */
76 PROP_ACTIVATABLE_RELATED_ACTION,
77 PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
80 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
82 struct _GtkToolItemPrivate
87 guint visible_horizontal : 1;
88 guint visible_vertical : 1;
89 guint homogeneous : 1;
91 guint use_drag_window : 1;
92 guint is_important : 1;
94 GdkWindow *drag_window;
100 gboolean use_action_appearance;
103 static void gtk_tool_item_finalize (GObject *object);
104 static void gtk_tool_item_dispose (GObject *object);
105 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
107 static void gtk_tool_item_set_property (GObject *object,
111 static void gtk_tool_item_get_property (GObject *object,
115 static void gtk_tool_item_property_notify (GObject *object,
117 static void gtk_tool_item_realize (GtkWidget *widget);
118 static void gtk_tool_item_unrealize (GtkWidget *widget);
119 static void gtk_tool_item_map (GtkWidget *widget);
120 static void gtk_tool_item_unmap (GtkWidget *widget);
121 static void gtk_tool_item_size_request (GtkWidget *widget,
122 GtkRequisition *requisition);
123 static void gtk_tool_item_size_allocate (GtkWidget *widget,
124 GtkAllocation *allocation);
125 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
126 GtkTooltips *tooltips,
127 const gchar *tip_text,
128 const gchar *tip_private);
130 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface);
131 static void gtk_tool_item_activatable_update (GtkActivatable *activatable,
133 const gchar *property_name);
134 static void gtk_tool_item_activatable_reset (GtkActivatable *activatable,
136 static void gtk_tool_item_set_related_action (GtkToolItem *item,
138 static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
139 gboolean use_appearance);
141 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
143 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
144 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
145 gtk_tool_item_activatable_interface_init))
148 gtk_tool_item_class_init (GtkToolItemClass *klass)
150 GObjectClass *object_class;
151 GtkWidgetClass *widget_class;
153 object_class = (GObjectClass *)klass;
154 widget_class = (GtkWidgetClass *)klass;
156 object_class->set_property = gtk_tool_item_set_property;
157 object_class->get_property = gtk_tool_item_get_property;
158 object_class->finalize = gtk_tool_item_finalize;
159 object_class->dispose = gtk_tool_item_dispose;
160 object_class->notify = gtk_tool_item_property_notify;
162 widget_class->realize = gtk_tool_item_realize;
163 widget_class->unrealize = gtk_tool_item_unrealize;
164 widget_class->map = gtk_tool_item_map;
165 widget_class->unmap = gtk_tool_item_unmap;
166 widget_class->size_request = gtk_tool_item_size_request;
167 widget_class->size_allocate = gtk_tool_item_size_allocate;
168 widget_class->parent_set = gtk_tool_item_parent_set;
170 klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
171 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
173 g_object_class_install_property (object_class,
174 PROP_VISIBLE_HORIZONTAL,
175 g_param_spec_boolean ("visible-horizontal",
176 P_("Visible when horizontal"),
177 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
179 GTK_PARAM_READWRITE));
180 g_object_class_install_property (object_class,
181 PROP_VISIBLE_VERTICAL,
182 g_param_spec_boolean ("visible-vertical",
183 P_("Visible when vertical"),
184 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
186 GTK_PARAM_READWRITE));
187 g_object_class_install_property (object_class,
189 g_param_spec_boolean ("is-important",
191 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
193 GTK_PARAM_READWRITE));
195 g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
196 g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
200 * GtkToolItem::create-menu-proxy:
201 * @tool_item: the object the signal was emitted on
203 * This signal is emitted when the toolbar needs information from @tool_item
204 * about whether the item should appear in the toolbar overflow menu. In
205 * response the tool item should either
207 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
208 * pointer and return %TRUE to indicate that the item should not appear
209 * in the overflow menu
211 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
212 * item and return %TRUE, or
214 * <listitem> return %FALSE to indicate that the signal was not
215 * handled by the item. This means that
216 * the item will not appear in the overflow menu unless a later handler
217 * installs a menu item.
221 * The toolbar may cache the result of this signal. When the tool item changes
222 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
223 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
226 * Return value: %TRUE if the signal was handled, %FALSE if not
228 toolitem_signals[CREATE_MENU_PROXY] =
229 g_signal_new (I_("create-menu-proxy"),
230 G_OBJECT_CLASS_TYPE (klass),
232 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
233 _gtk_boolean_handled_accumulator, NULL,
234 _gtk_marshal_BOOLEAN__VOID,
238 * GtkToolItem::toolbar-reconfigured:
239 * @tool_item: the object the signal was emitted on
241 * This signal is emitted when some property of the toolbar that the
242 * item is a child of changes. For custom subclasses of #GtkToolItem,
243 * the default handler of this signal use the functions
245 * <listitem>gtk_tool_shell_get_orientation()</listitem>
246 * <listitem>gtk_tool_shell_get_style()</listitem>
247 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
248 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
250 * to find out what the toolbar should look like and change
251 * themselves accordingly.
253 toolitem_signals[TOOLBAR_RECONFIGURED] =
254 g_signal_new (I_("toolbar-reconfigured"),
255 G_OBJECT_CLASS_TYPE (klass),
257 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
259 _gtk_marshal_VOID__VOID,
262 * GtkToolItem::set-tooltip:
263 * @tool_item: the object the signal was emitted on
264 * @tooltips: the #GtkTooltips
265 * @tip_text: the tooltip text
266 * @tip_private: the tooltip private text
268 * This signal is emitted when the toolitem's tooltip changes.
269 * Application developers can use gtk_tool_item_set_tooltip() to
270 * set the item's tooltip.
272 * Return value: %TRUE if the signal was handled, %FALSE if not
274 * Deprecated: 2.12: With the new tooltip API, there is no
275 * need to use this signal anymore.
277 toolitem_signals[SET_TOOLTIP] =
278 g_signal_new (I_("set-tooltip"),
279 G_OBJECT_CLASS_TYPE (klass),
281 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
282 _gtk_boolean_handled_accumulator, NULL,
283 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
289 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
293 gtk_tool_item_init (GtkToolItem *toolitem)
295 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
297 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
299 toolitem->priv->visible_horizontal = TRUE;
300 toolitem->priv->visible_vertical = TRUE;
301 toolitem->priv->homogeneous = FALSE;
302 toolitem->priv->expand = FALSE;
304 toolitem->priv->use_action_appearance = TRUE;
308 gtk_tool_item_finalize (GObject *object)
310 GtkToolItem *item = GTK_TOOL_ITEM (object);
312 g_free (item->priv->menu_item_id);
314 if (item->priv->menu_item)
315 g_object_unref (item->priv->menu_item);
317 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
321 gtk_tool_item_dispose (GObject *object)
323 GtkToolItem *item = GTK_TOOL_ITEM (object);
325 if (item->priv->action)
327 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);
328 item->priv->action = NULL;
330 G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
335 gtk_tool_item_parent_set (GtkWidget *toolitem,
336 GtkWidget *prev_parent)
338 if (GTK_WIDGET (toolitem)->parent != NULL)
339 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
343 gtk_tool_item_set_property (GObject *object,
348 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
352 case PROP_VISIBLE_HORIZONTAL:
353 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
355 case PROP_VISIBLE_VERTICAL:
356 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
358 case PROP_IS_IMPORTANT:
359 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
361 case PROP_ACTIVATABLE_RELATED_ACTION:
362 gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
364 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
365 gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
368 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
374 gtk_tool_item_get_property (GObject *object,
379 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
383 case PROP_VISIBLE_HORIZONTAL:
384 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
386 case PROP_VISIBLE_VERTICAL:
387 g_value_set_boolean (value, toolitem->priv->visible_vertical);
389 case PROP_IS_IMPORTANT:
390 g_value_set_boolean (value, toolitem->priv->is_important);
392 case PROP_ACTIVATABLE_RELATED_ACTION:
393 g_value_set_object (value, toolitem->priv->action);
395 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
396 g_value_set_boolean (value, toolitem->priv->use_action_appearance);
399 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
405 gtk_tool_item_property_notify (GObject *object,
408 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
410 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
411 gtk_widget_set_sensitive (tool_item->priv->menu_item,
412 GTK_WIDGET_SENSITIVE (tool_item));
416 create_drag_window (GtkToolItem *toolitem)
419 GdkWindowAttr attributes;
420 gint attributes_mask, border_width;
422 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
424 widget = GTK_WIDGET (toolitem);
425 border_width = GTK_CONTAINER (toolitem)->border_width;
427 attributes.window_type = GDK_WINDOW_CHILD;
428 attributes.x = widget->allocation.x + border_width;
429 attributes.y = widget->allocation.y + border_width;
430 attributes.width = widget->allocation.width - border_width * 2;
431 attributes.height = widget->allocation.height - border_width * 2;
432 attributes.wclass = GDK_INPUT_ONLY;
433 attributes.event_mask = gtk_widget_get_events (widget);
434 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
436 attributes_mask = GDK_WA_X | GDK_WA_Y;
438 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
439 &attributes, attributes_mask);
440 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
444 gtk_tool_item_realize (GtkWidget *widget)
446 GtkToolItem *toolitem;
448 toolitem = GTK_TOOL_ITEM (widget);
449 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
451 widget->window = gtk_widget_get_parent_window (widget);
452 g_object_ref (widget->window);
454 if (toolitem->priv->use_drag_window)
455 create_drag_window(toolitem);
457 widget->style = gtk_style_attach (widget->style, widget->window);
461 destroy_drag_window (GtkToolItem *toolitem)
463 if (toolitem->priv->drag_window)
465 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
466 gdk_window_destroy (toolitem->priv->drag_window);
467 toolitem->priv->drag_window = NULL;
472 gtk_tool_item_unrealize (GtkWidget *widget)
474 GtkToolItem *toolitem;
476 toolitem = GTK_TOOL_ITEM (widget);
478 destroy_drag_window (toolitem);
480 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
484 gtk_tool_item_map (GtkWidget *widget)
486 GtkToolItem *toolitem;
488 toolitem = GTK_TOOL_ITEM (widget);
489 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
490 if (toolitem->priv->drag_window)
491 gdk_window_show (toolitem->priv->drag_window);
495 gtk_tool_item_unmap (GtkWidget *widget)
497 GtkToolItem *toolitem;
499 toolitem = GTK_TOOL_ITEM (widget);
500 if (toolitem->priv->drag_window)
501 gdk_window_hide (toolitem->priv->drag_window);
502 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
506 gtk_tool_item_size_request (GtkWidget *widget,
507 GtkRequisition *requisition)
509 GtkWidget *child = GTK_BIN (widget)->child;
511 if (child && GTK_WIDGET_VISIBLE (child))
513 gtk_widget_size_request (child, requisition);
517 requisition->height = 0;
518 requisition->width = 0;
521 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
522 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
526 gtk_tool_item_size_allocate (GtkWidget *widget,
527 GtkAllocation *allocation)
529 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
530 GtkAllocation child_allocation;
532 GtkWidget *child = GTK_BIN (widget)->child;
534 widget->allocation = *allocation;
535 border_width = GTK_CONTAINER (widget)->border_width;
537 if (toolitem->priv->drag_window)
538 gdk_window_move_resize (toolitem->priv->drag_window,
539 widget->allocation.x + border_width,
540 widget->allocation.y + border_width,
541 widget->allocation.width - border_width * 2,
542 widget->allocation.height - border_width * 2);
544 if (child && GTK_WIDGET_VISIBLE (child))
546 child_allocation.x = allocation->x + border_width;
547 child_allocation.y = allocation->y + border_width;
548 child_allocation.width = allocation->width - 2 * border_width;
549 child_allocation.height = allocation->height - 2 * border_width;
551 gtk_widget_size_allocate (child, &child_allocation);
556 _gtk_tool_item_create_menu_proxy (GtkToolItem *item)
558 GtkWidget *menu_item;
559 gboolean visible_overflown;
561 if (item->priv->action)
563 g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
565 if (visible_overflown)
567 menu_item = gtk_action_create_menu_item (item->priv->action);
569 g_object_ref_sink (menu_item);
570 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
571 g_object_unref (menu_item);
574 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
583 gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
585 iface->update = gtk_tool_item_activatable_update;
586 iface->reset = gtk_tool_item_activatable_reset;
590 gtk_tool_item_activatable_update (GtkActivatable *activatable,
592 const gchar *property_name)
594 if (strcmp (property_name, "visible") == 0)
596 if (gtk_action_is_visible (action))
597 gtk_widget_show (GTK_WIDGET (activatable));
599 gtk_widget_hide (GTK_WIDGET (activatable));
601 else if (strcmp (property_name, "sensitive") == 0)
602 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
603 else if (strcmp (property_name, "tooltip") == 0)
604 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
605 gtk_action_get_tooltip (action));
606 else if (strcmp (property_name, "visible-horizontal") == 0)
607 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
608 gtk_action_get_visible_horizontal (action));
609 else if (strcmp (property_name, "visible-vertical") == 0)
610 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
611 gtk_action_get_visible_vertical (action));
612 else if (strcmp (property_name, "is-important") == 0)
613 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
614 gtk_action_get_is_important (action));
618 gtk_tool_item_activatable_reset (GtkActivatable *activatable,
624 if (gtk_action_is_visible (action))
625 gtk_widget_show (GTK_WIDGET (activatable));
627 gtk_widget_hide (GTK_WIDGET (activatable));
629 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
631 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
632 gtk_action_get_tooltip (action));
633 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
634 gtk_action_get_visible_horizontal (action));
635 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
636 gtk_action_get_visible_vertical (action));
637 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
638 gtk_action_get_is_important (action));
642 gtk_tool_item_set_related_action (GtkToolItem *item,
645 if (item->priv->action == action)
648 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
650 item->priv->action = action;
654 gtk_tool_item_rebuild_menu (item);
659 gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
660 gboolean use_appearance)
662 if (item->priv->use_action_appearance != use_appearance)
664 item->priv->use_action_appearance = use_appearance;
666 gtk_activatable_reset (GTK_ACTIVATABLE (item), item->priv->action);
674 * Creates a new #GtkToolItem
676 * Return value: the new #GtkToolItem
681 gtk_tool_item_new (void)
685 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
691 * gtk_tool_item_get_icon_size:
692 * @tool_item: a #GtkToolItem
694 * Returns the icon size used for @tool_item. Custom subclasses of
695 * #GtkToolItem should call this function to find out what size icons
698 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
703 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
707 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
709 parent = GTK_WIDGET (tool_item)->parent;
710 if (!parent || !GTK_IS_TOOL_SHELL (parent))
711 return GTK_ICON_SIZE_LARGE_TOOLBAR;
713 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
717 * gtk_tool_item_get_orientation:
718 * @tool_item: a #GtkToolItem
720 * Returns the orientation used for @tool_item. Custom subclasses of
721 * #GtkToolItem should call this function to find out what size icons
724 * Return value: a #GtkOrientation indicating the orientation
725 * used for @tool_item
730 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
734 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
736 parent = GTK_WIDGET (tool_item)->parent;
737 if (!parent || !GTK_IS_TOOL_SHELL (parent))
738 return GTK_ORIENTATION_HORIZONTAL;
740 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
744 * gtk_tool_item_get_toolbar_style:
745 * @tool_item: a #GtkToolItem
747 * Returns the toolbar style used for @tool_item. Custom subclasses of
748 * #GtkToolItem should call this function in the handler of the
749 * GtkToolItem::toolbar_reconfigured signal to find out in what style
750 * the toolbar is displayed and change themselves accordingly
754 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
755 * both an icon and a label, stacked vertically </listitem>
756 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
757 * only icons </listitem>
758 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
759 * show text</listitem>
760 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
761 * both an icon and a label, arranged horizontally (however, note the
762 * #GtkToolButton::has_text_horizontally that makes tool buttons not
763 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
767 * Return value: A #GtkToolbarStyle indicating the toolbar style used
773 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
777 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
779 parent = GTK_WIDGET (tool_item)->parent;
780 if (!parent || !GTK_IS_TOOL_SHELL (parent))
781 return GTK_TOOLBAR_ICONS;
783 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
787 * gtk_tool_item_get_relief_style:
788 * @tool_item: a #GtkToolItem
790 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
791 * Custom subclasses of #GtkToolItem should call this function in the handler
792 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
793 * relief style of buttons.
795 * Return value: a #GtkReliefStyle indicating the relief style used
801 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
805 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
807 parent = GTK_WIDGET (tool_item)->parent;
808 if (!parent || !GTK_IS_TOOL_SHELL (parent))
809 return GTK_RELIEF_NONE;
811 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
815 * gtk_tool_item_set_expand:
816 * @tool_item: a #GtkToolItem
817 * @expand: Whether @tool_item is allocated extra space
819 * Sets whether @tool_item is allocated extra space when there
820 * is more room on the toolbar then needed for the items. The
821 * effect is that the item gets bigger when the toolbar gets bigger
822 * and smaller when the toolbar gets smaller.
827 gtk_tool_item_set_expand (GtkToolItem *tool_item,
830 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
832 expand = expand != FALSE;
834 if (tool_item->priv->expand != expand)
836 tool_item->priv->expand = expand;
837 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
838 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
843 * gtk_tool_item_get_expand:
844 * @tool_item: a #GtkToolItem
846 * Returns whether @tool_item is allocated extra space.
847 * See gtk_tool_item_set_expand().
849 * Return value: %TRUE if @tool_item is allocated extra space.
854 gtk_tool_item_get_expand (GtkToolItem *tool_item)
856 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
858 return tool_item->priv->expand;
862 * gtk_tool_item_set_homogeneous:
863 * @tool_item: a #GtkToolItem
864 * @homogeneous: whether @tool_item is the same size as other homogeneous items
866 * Sets whether @tool_item is to be allocated the same size as other
867 * homogeneous items. The effect is that all homogeneous items will have
868 * the same width as the widest of the items.
873 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
874 gboolean homogeneous)
876 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
878 homogeneous = homogeneous != FALSE;
880 if (tool_item->priv->homogeneous != homogeneous)
882 tool_item->priv->homogeneous = homogeneous;
883 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
884 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
889 * gtk_tool_item_get_homogeneous:
890 * @tool_item: a #GtkToolItem
892 * Returns whether @tool_item is the same size as other homogeneous
893 * items. See gtk_tool_item_set_homogeneous().
895 * Return value: %TRUE if the item is the same size as other homogeneous
901 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
903 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
905 return tool_item->priv->homogeneous;
909 * gtk_tool_item_get_is_important:
910 * @tool_item: a #GtkToolItem
912 * Returns whether @tool_item is considered important. See
913 * gtk_tool_item_set_is_important()
915 * Return value: %TRUE if @tool_item is considered important.
920 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
922 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
924 return tool_item->priv->is_important;
928 * gtk_tool_item_set_is_important:
929 * @tool_item: a #GtkToolItem
930 * @is_important: whether the tool item should be considered important
932 * Sets whether @tool_item should be considered important. The #GtkToolButton
933 * class uses this property to determine whether to show or hide its label
934 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
935 * only tool buttons with the "is_important" property set have labels, an
936 * effect known as "priority text"
941 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
943 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
945 is_important = is_important != FALSE;
947 if (is_important != tool_item->priv->is_important)
949 tool_item->priv->is_important = is_important;
951 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
953 g_object_notify (G_OBJECT (tool_item), "is-important");
958 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
959 GtkTooltips *tooltips,
960 const gchar *tip_text,
961 const gchar *tip_private)
963 GtkWidget *child = GTK_BIN (tool_item)->child;
968 gtk_widget_set_tooltip_text (child, tip_text);
974 * gtk_tool_item_set_tooltip:
975 * @tool_item: a #GtkToolItem
976 * @tooltips: The #GtkTooltips object to be used
977 * @tip_text: text to be used as tooltip text for @tool_item
978 * @tip_private: text to be used as private tooltip text
980 * Sets the #GtkTooltips object to be used for @tool_item, the
981 * text to be displayed as tooltip on the item and the private text
982 * to be used. See gtk_tooltips_set_tip().
986 * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead.
989 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
990 GtkTooltips *tooltips,
991 const gchar *tip_text,
992 const gchar *tip_private)
996 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
998 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
999 tooltips, tip_text, tip_private, &retval);
1003 * gtk_tool_item_set_tooltip_text:
1004 * @tool_item: a #GtkToolItem
1005 * @text: text to be used as tooltip for @tool_item
1007 * Sets the text to be displayed as tooltip on the item.
1008 * See gtk_widget_set_tooltip_text().
1013 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1018 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1020 child = GTK_BIN (tool_item)->child;
1023 gtk_widget_set_tooltip_text (child, text);
1027 * gtk_tool_item_set_tooltip_markup:
1028 * @tool_item: a #GtkToolItem
1029 * @markup: markup text to be used as tooltip for @tool_item
1031 * Sets the markup text to be displayed as tooltip on the item.
1032 * See gtk_widget_set_tooltip_markup().
1037 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1038 const gchar *markup)
1042 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1044 child = GTK_BIN (tool_item)->child;
1047 gtk_widget_set_tooltip_markup (child, markup);
1051 * gtk_tool_item_set_use_drag_window:
1052 * @tool_item: a #GtkToolItem
1053 * @use_drag_window: Whether @tool_item has a drag window.
1055 * Sets whether @tool_item has a drag window. When %TRUE the
1056 * toolitem can be used as a drag source through gtk_drag_source_set().
1057 * When @tool_item has a drag window it will intercept all events,
1058 * even those that would otherwise be sent to a child of @tool_item.
1063 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1064 gboolean use_drag_window)
1066 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1068 use_drag_window = use_drag_window != FALSE;
1070 if (toolitem->priv->use_drag_window != use_drag_window)
1072 toolitem->priv->use_drag_window = use_drag_window;
1074 if (use_drag_window)
1076 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
1078 create_drag_window(toolitem);
1079 if (GTK_WIDGET_MAPPED (toolitem))
1080 gdk_window_show (toolitem->priv->drag_window);
1085 destroy_drag_window (toolitem);
1091 * gtk_tool_item_get_use_drag_window:
1092 * @tool_item: a #GtkToolItem
1094 * Returns whether @tool_item has a drag window. See
1095 * gtk_tool_item_set_use_drag_window().
1097 * Return value: %TRUE if @tool_item uses a drag window.
1102 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1104 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1106 return toolitem->priv->use_drag_window;
1110 * gtk_tool_item_set_visible_horizontal:
1111 * @tool_item: a #GtkToolItem
1112 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1114 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1119 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1120 gboolean visible_horizontal)
1122 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1124 visible_horizontal = visible_horizontal != FALSE;
1126 if (toolitem->priv->visible_horizontal != visible_horizontal)
1128 toolitem->priv->visible_horizontal = visible_horizontal;
1130 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1132 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1137 * gtk_tool_item_get_visible_horizontal:
1138 * @tool_item: a #GtkToolItem
1140 * Returns whether the @tool_item is visible on toolbars that are
1141 * docked horizontally.
1143 * Return value: %TRUE if @tool_item is visible on toolbars that are
1144 * docked horizontally.
1149 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1151 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1153 return toolitem->priv->visible_horizontal;
1157 * gtk_tool_item_set_visible_vertical:
1158 * @tool_item: a #GtkToolItem
1159 * @visible_vertical: whether @tool_item is visible when the toolbar
1160 * is in vertical mode
1162 * Sets whether @tool_item is visible when the toolbar is docked
1163 * vertically. Some tool items, such as text entries, are too wide to be
1164 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1165 * @tool_item will not appear on toolbars that are docked vertically.
1170 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1171 gboolean visible_vertical)
1173 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1175 visible_vertical = visible_vertical != FALSE;
1177 if (toolitem->priv->visible_vertical != visible_vertical)
1179 toolitem->priv->visible_vertical = visible_vertical;
1181 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1183 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1188 * gtk_tool_item_get_visible_vertical:
1189 * @tool_item: a #GtkToolItem
1191 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1192 * See gtk_tool_item_set_visible_vertical().
1194 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1199 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1201 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1203 return toolitem->priv->visible_vertical;
1207 * gtk_tool_item_retrieve_proxy_menu_item:
1208 * @tool_item: a #GtkToolItem
1210 * Returns the #GtkMenuItem that was last set by
1211 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1212 * that is going to appear in the overflow menu.
1214 * Return value: The #GtkMenuItem that is going to appear in the
1215 * overflow menu for @tool_item.
1220 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1224 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1226 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1229 return tool_item->priv->menu_item;
1233 * gtk_tool_item_get_proxy_menu_item:
1234 * @tool_item: a #GtkToolItem
1235 * @menu_item_id: a string used to identify the menu item
1237 * If @menu_item_id matches the string passed to
1238 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1240 * Custom subclasses of #GtkToolItem should use this function to update
1241 * their menu item when the #GtkToolItem changes. That the
1242 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1243 * inadvertently change a menu item that they did not create.
1245 * Return value: The #GtkMenuItem passed to
1246 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1251 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1252 const gchar *menu_item_id)
1254 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1255 g_return_val_if_fail (menu_item_id != NULL, NULL);
1257 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1258 return tool_item->priv->menu_item;
1264 * gtk_tool_item_rebuild_menu()
1265 * @tool_item: a #GtkToolItem
1267 * Calling this function signals to the toolbar that the
1268 * overflow menu item for @tool_item has changed. If the
1269 * overflow menu is visible when this function it called,
1270 * the menu will be rebuilt.
1272 * The function must be called when the tool item
1273 * changes what it will do in response to the "create_menu_proxy"
1279 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1283 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1285 widget = GTK_WIDGET (tool_item);
1287 if (GTK_IS_TOOL_SHELL (widget->parent))
1288 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent));
1292 * gtk_tool_item_set_proxy_menu_item:
1293 * @tool_item: a #GtkToolItem
1294 * @menu_item_id: a string used to identify @menu_item
1295 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1297 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1298 * @menu_item_id is used to identify the caller of this function and
1299 * should also be used with gtk_tool_item_get_proxy_menu_item().
1304 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1305 const gchar *menu_item_id,
1306 GtkWidget *menu_item)
1308 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1309 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1310 g_return_if_fail (menu_item_id != NULL);
1312 g_free (tool_item->priv->menu_item_id);
1314 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1316 if (tool_item->priv->menu_item != menu_item)
1318 if (tool_item->priv->menu_item)
1319 g_object_unref (tool_item->priv->menu_item);
1323 g_object_ref_sink (menu_item);
1325 gtk_widget_set_sensitive (menu_item,
1326 GTK_WIDGET_SENSITIVE (tool_item));
1329 tool_item->priv->menu_item = menu_item;
1334 * gtk_tool_item_toolbar_reconfigured:
1335 * @tool_item: a #GtkToolItem
1337 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1338 * #GtkToolbar and other #GtkToolShell implementations use this function
1339 * to notify children, when some aspect of their configuration changes.
1344 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1346 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1347 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1348 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1349 * Its not possible to rename the signal, and emitting another name than
1350 * indicated by the function name would be quite confusing. That's the
1351 * price of providing stable APIs.
1353 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1355 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1357 if (tool_item->priv->drag_window)
1358 gdk_window_raise (tool_item->priv->drag_window);
1360 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1363 #define __GTK_TOOL_ITEM_C__
1364 #include "gtkaliasdef.c"