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"
29 #include "gtkmarshalers.h"
30 #include "gtktoolshell.h"
31 #include "gtkseparatormenuitem.h"
32 #include "gtksizerequest.h"
33 #include "gtkactivatable.h"
35 #include "gtkmainprivate.h"
36 #include "gtkprivate.h"
41 * @short_description: The base class of widgets that can be added to GtkToolShell
43 * @see_also: <variablelist>
45 * <term>#GtkToolbar</term>
46 * <listitem><para>The toolbar widget</para></listitem>
49 * <term>#GtkToolButton</term>
50 * <listitem><para>A subclass of #GtkToolItem that displays buttons on
51 * the toolbar</para></listitem>
54 * <term>#GtkSeparatorToolItem</term>
55 * <listitem><para>A subclass of #GtkToolItem that separates groups of
56 * items on a toolbar</para></listitem>
60 * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
61 * create a toolbar item that contain something else than a button, use
62 * gtk_tool_item_new(). Use gtk_container_add() to add a child
63 * widget to the tool item.
65 * For toolbar items that contain buttons, see the #GtkToolButton,
66 * #GtkToggleToolButton and #GtkRadioToolButton classes.
68 * See the #GtkToolbar class for a description of the toolbar widget, and
69 * #GtkToolShell for a description of the tool shell interface.
75 * The GtkToolItem struct contains only private data.
76 * It should only be accessed through the functions described below.
87 PROP_VISIBLE_HORIZONTAL,
88 PROP_VISIBLE_VERTICAL,
91 /* activatable properties */
92 PROP_ACTIVATABLE_RELATED_ACTION,
93 PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
97 struct _GtkToolItemPrivate
102 guint visible_horizontal : 1;
103 guint visible_vertical : 1;
104 guint homogeneous : 1;
106 guint use_drag_window : 1;
107 guint is_important : 1;
108 guint use_action_appearance : 1;
110 GdkWindow *drag_window;
112 GtkWidget *menu_item;
117 static void gtk_tool_item_finalize (GObject *object);
118 static void gtk_tool_item_dispose (GObject *object);
119 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
121 static void gtk_tool_item_set_property (GObject *object,
125 static void gtk_tool_item_get_property (GObject *object,
129 static void gtk_tool_item_property_notify (GObject *object,
131 static void gtk_tool_item_realize (GtkWidget *widget);
132 static void gtk_tool_item_unrealize (GtkWidget *widget);
133 static void gtk_tool_item_map (GtkWidget *widget);
134 static void gtk_tool_item_unmap (GtkWidget *widget);
135 static void gtk_tool_item_get_preferred_width
139 static void gtk_tool_item_get_preferred_height
143 static void gtk_tool_item_size_allocate (GtkWidget *widget,
144 GtkAllocation *allocation);
146 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface);
147 static void gtk_tool_item_update (GtkActivatable *activatable,
149 const gchar *property_name);
150 static void gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
152 static void gtk_tool_item_set_related_action (GtkToolItem *item,
154 static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
155 gboolean use_appearance);
157 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
159 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
160 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
161 gtk_tool_item_activatable_interface_init))
164 gtk_tool_item_class_init (GtkToolItemClass *klass)
166 GObjectClass *object_class;
167 GtkWidgetClass *widget_class;
169 object_class = (GObjectClass *)klass;
170 widget_class = (GtkWidgetClass *)klass;
172 object_class->set_property = gtk_tool_item_set_property;
173 object_class->get_property = gtk_tool_item_get_property;
174 object_class->finalize = gtk_tool_item_finalize;
175 object_class->dispose = gtk_tool_item_dispose;
176 object_class->notify = gtk_tool_item_property_notify;
178 widget_class->realize = gtk_tool_item_realize;
179 widget_class->unrealize = gtk_tool_item_unrealize;
180 widget_class->map = gtk_tool_item_map;
181 widget_class->unmap = gtk_tool_item_unmap;
182 widget_class->get_preferred_width = gtk_tool_item_get_preferred_width;
183 widget_class->get_preferred_height = gtk_tool_item_get_preferred_height;
184 widget_class->size_allocate = gtk_tool_item_size_allocate;
185 widget_class->parent_set = gtk_tool_item_parent_set;
187 gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (klass));
189 klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
191 g_object_class_install_property (object_class,
192 PROP_VISIBLE_HORIZONTAL,
193 g_param_spec_boolean ("visible-horizontal",
194 P_("Visible when horizontal"),
195 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
197 GTK_PARAM_READWRITE));
198 g_object_class_install_property (object_class,
199 PROP_VISIBLE_VERTICAL,
200 g_param_spec_boolean ("visible-vertical",
201 P_("Visible when vertical"),
202 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
204 GTK_PARAM_READWRITE));
205 g_object_class_install_property (object_class,
207 g_param_spec_boolean ("is-important",
209 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
211 GTK_PARAM_READWRITE));
213 g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
214 g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
218 * GtkToolItem::create-menu-proxy:
219 * @tool_item: the object the signal was emitted on
221 * This signal is emitted when the toolbar needs information from @tool_item
222 * about whether the item should appear in the toolbar overflow menu. In
223 * response the tool item should either
225 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
226 * pointer and return %TRUE to indicate that the item should not appear
227 * in the overflow menu
229 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
230 * item and return %TRUE, or
232 * <listitem> return %FALSE to indicate that the signal was not
233 * handled by the item. This means that
234 * the item will not appear in the overflow menu unless a later handler
235 * installs a menu item.
239 * The toolbar may cache the result of this signal. When the tool item changes
240 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
241 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
244 * Return value: %TRUE if the signal was handled, %FALSE if not
246 toolitem_signals[CREATE_MENU_PROXY] =
247 g_signal_new (I_("create-menu-proxy"),
248 G_OBJECT_CLASS_TYPE (klass),
250 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
251 _gtk_boolean_handled_accumulator, NULL,
252 _gtk_marshal_BOOLEAN__VOID,
256 * GtkToolItem::toolbar-reconfigured:
257 * @tool_item: the object the signal was emitted on
259 * This signal is emitted when some property of the toolbar that the
260 * item is a child of changes. For custom subclasses of #GtkToolItem,
261 * the default handler of this signal use the functions
263 * <listitem>gtk_tool_shell_get_orientation()</listitem>
264 * <listitem>gtk_tool_shell_get_style()</listitem>
265 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
266 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
268 * to find out what the toolbar should look like and change
269 * themselves accordingly.
271 toolitem_signals[TOOLBAR_RECONFIGURED] =
272 g_signal_new (I_("toolbar-reconfigured"),
273 G_OBJECT_CLASS_TYPE (klass),
275 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
277 _gtk_marshal_VOID__VOID,
280 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
284 gtk_tool_item_init (GtkToolItem *toolitem)
286 gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE);
288 toolitem->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolitem,
292 toolitem->priv->visible_horizontal = TRUE;
293 toolitem->priv->visible_vertical = TRUE;
294 toolitem->priv->homogeneous = FALSE;
295 toolitem->priv->expand = FALSE;
297 toolitem->priv->use_action_appearance = TRUE;
301 gtk_tool_item_finalize (GObject *object)
303 GtkToolItem *item = GTK_TOOL_ITEM (object);
305 g_free (item->priv->menu_item_id);
307 if (item->priv->menu_item)
308 g_object_unref (item->priv->menu_item);
310 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
314 gtk_tool_item_dispose (GObject *object)
316 GtkToolItem *item = GTK_TOOL_ITEM (object);
318 if (item->priv->action)
320 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);
321 item->priv->action = NULL;
323 G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
328 gtk_tool_item_parent_set (GtkWidget *toolitem,
329 GtkWidget *prev_parent)
331 if (gtk_widget_get_parent (GTK_WIDGET (toolitem)) != NULL)
332 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
336 gtk_tool_item_set_property (GObject *object,
341 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
345 case PROP_VISIBLE_HORIZONTAL:
346 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
348 case PROP_VISIBLE_VERTICAL:
349 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
351 case PROP_IS_IMPORTANT:
352 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
354 case PROP_ACTIVATABLE_RELATED_ACTION:
355 gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
357 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
358 gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
361 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
367 gtk_tool_item_get_property (GObject *object,
372 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
376 case PROP_VISIBLE_HORIZONTAL:
377 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
379 case PROP_VISIBLE_VERTICAL:
380 g_value_set_boolean (value, toolitem->priv->visible_vertical);
382 case PROP_IS_IMPORTANT:
383 g_value_set_boolean (value, toolitem->priv->is_important);
385 case PROP_ACTIVATABLE_RELATED_ACTION:
386 g_value_set_object (value, toolitem->priv->action);
388 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
389 g_value_set_boolean (value, toolitem->priv->use_action_appearance);
392 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
398 gtk_tool_item_property_notify (GObject *object,
401 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
403 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
404 gtk_widget_set_sensitive (tool_item->priv->menu_item,
405 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
409 create_drag_window (GtkToolItem *toolitem)
411 GtkAllocation allocation;
413 GdkWindowAttr attributes;
414 gint attributes_mask;
416 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
418 widget = GTK_WIDGET (toolitem);
420 gtk_widget_get_allocation (widget, &allocation);
422 attributes.window_type = GDK_WINDOW_CHILD;
423 attributes.x = allocation.x;
424 attributes.y = allocation.y;
425 attributes.width = allocation.width;
426 attributes.height = allocation.height;
427 attributes.wclass = GDK_INPUT_ONLY;
428 attributes.event_mask = gtk_widget_get_events (widget);
429 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
431 attributes_mask = GDK_WA_X | GDK_WA_Y;
433 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
434 &attributes, attributes_mask);
435 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
439 gtk_tool_item_realize (GtkWidget *widget)
441 GtkToolItem *toolitem;
444 toolitem = GTK_TOOL_ITEM (widget);
445 gtk_widget_set_realized (widget, TRUE);
447 window = gtk_widget_get_parent_window (widget);
448 gtk_widget_set_window (widget, window);
449 g_object_ref (window);
451 if (toolitem->priv->use_drag_window)
452 create_drag_window(toolitem);
456 destroy_drag_window (GtkToolItem *toolitem)
458 if (toolitem->priv->drag_window)
460 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
461 gdk_window_destroy (toolitem->priv->drag_window);
462 toolitem->priv->drag_window = NULL;
467 gtk_tool_item_unrealize (GtkWidget *widget)
469 GtkToolItem *toolitem;
471 toolitem = GTK_TOOL_ITEM (widget);
473 destroy_drag_window (toolitem);
475 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
479 gtk_tool_item_map (GtkWidget *widget)
481 GtkToolItem *toolitem;
483 toolitem = GTK_TOOL_ITEM (widget);
484 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
485 if (toolitem->priv->drag_window)
486 gdk_window_show (toolitem->priv->drag_window);
490 gtk_tool_item_unmap (GtkWidget *widget)
492 GtkToolItem *toolitem;
494 toolitem = GTK_TOOL_ITEM (widget);
495 if (toolitem->priv->drag_window)
496 gdk_window_hide (toolitem->priv->drag_window);
497 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
501 gtk_tool_item_get_preferred_width (GtkWidget *widget,
507 *minimum = *natural = 0;
509 child = gtk_bin_get_child (GTK_BIN (widget));
510 if (child && gtk_widget_get_visible (child))
511 gtk_widget_get_preferred_width (child, minimum, natural);
515 gtk_tool_item_get_preferred_height (GtkWidget *widget,
521 *minimum = *natural = 0;
523 child = gtk_bin_get_child (GTK_BIN (widget));
524 if (child && gtk_widget_get_visible (child))
525 gtk_widget_get_preferred_height (child, minimum, natural);
529 gtk_tool_item_size_allocate (GtkWidget *widget,
530 GtkAllocation *allocation)
532 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
533 GtkAllocation child_allocation;
536 gtk_widget_set_allocation (widget, allocation);
538 if (toolitem->priv->drag_window)
539 gdk_window_move_resize (toolitem->priv->drag_window,
545 child = gtk_bin_get_child (GTK_BIN (widget));
546 if (child && gtk_widget_get_visible (child))
548 child_allocation.x = allocation->x;
549 child_allocation.y = allocation->y;
550 child_allocation.width = allocation->width;
551 child_allocation.height = allocation->height;
553 gtk_widget_size_allocate (child, &child_allocation);
558 _gtk_tool_item_create_menu_proxy (GtkToolItem *item)
560 GtkWidget *menu_item;
561 gboolean visible_overflown;
563 if (item->priv->action)
565 g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
567 if (visible_overflown)
569 menu_item = gtk_action_create_menu_item (item->priv->action);
571 g_object_ref_sink (menu_item);
572 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
573 g_object_unref (menu_item);
576 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
585 gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
587 iface->update = gtk_tool_item_update;
588 iface->sync_action_properties = gtk_tool_item_sync_action_properties;
592 gtk_tool_item_update (GtkActivatable *activatable,
594 const gchar *property_name)
596 if (strcmp (property_name, "visible") == 0)
598 if (gtk_action_is_visible (action))
599 gtk_widget_show (GTK_WIDGET (activatable));
601 gtk_widget_hide (GTK_WIDGET (activatable));
603 else if (strcmp (property_name, "sensitive") == 0)
604 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
605 else if (strcmp (property_name, "tooltip") == 0)
606 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
607 gtk_action_get_tooltip (action));
608 else if (strcmp (property_name, "visible-horizontal") == 0)
609 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
610 gtk_action_get_visible_horizontal (action));
611 else if (strcmp (property_name, "visible-vertical") == 0)
612 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
613 gtk_action_get_visible_vertical (action));
614 else if (strcmp (property_name, "is-important") == 0)
615 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
616 gtk_action_get_is_important (action));
620 gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
626 if (gtk_action_is_visible (action))
627 gtk_widget_show (GTK_WIDGET (activatable));
629 gtk_widget_hide (GTK_WIDGET (activatable));
631 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
633 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
634 gtk_action_get_tooltip (action));
635 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
636 gtk_action_get_visible_horizontal (action));
637 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
638 gtk_action_get_visible_vertical (action));
639 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
640 gtk_action_get_is_important (action));
644 gtk_tool_item_set_related_action (GtkToolItem *item,
647 if (item->priv->action == action)
650 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
652 item->priv->action = action;
656 gtk_tool_item_rebuild_menu (item);
661 gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
662 gboolean use_appearance)
664 if (item->priv->use_action_appearance != use_appearance)
666 item->priv->use_action_appearance = use_appearance;
668 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action);
676 * Creates a new #GtkToolItem
678 * Return value: the new #GtkToolItem
683 gtk_tool_item_new (void)
687 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
693 * gtk_tool_item_get_ellipsize_mode:
694 * @tool_item: a #GtkToolItem
696 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
697 * #GtkToolItem should call this function to find out how text should
700 * Return value: a #PangoEllipsizeMode indicating how text in @tool_item
701 * should be ellipsized.
706 gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
710 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
712 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
713 if (!parent || !GTK_IS_TOOL_SHELL (parent))
714 return PANGO_ELLIPSIZE_NONE;
716 return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
720 * gtk_tool_item_get_icon_size:
721 * @tool_item: a #GtkToolItem
723 * Returns the icon size used for @tool_item. Custom subclasses of
724 * #GtkToolItem should call this function to find out what size icons
727 * Return value: (type int): a #GtkIconSize indicating the icon size
728 * used for @tool_item
733 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
737 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
739 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
740 if (!parent || !GTK_IS_TOOL_SHELL (parent))
741 return GTK_ICON_SIZE_LARGE_TOOLBAR;
743 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
747 * gtk_tool_item_get_orientation:
748 * @tool_item: a #GtkToolItem
750 * Returns the orientation used for @tool_item. Custom subclasses of
751 * #GtkToolItem should call this function to find out what size icons
754 * Return value: a #GtkOrientation indicating the orientation
755 * used for @tool_item
760 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
764 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
766 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
767 if (!parent || !GTK_IS_TOOL_SHELL (parent))
768 return GTK_ORIENTATION_HORIZONTAL;
770 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
774 * gtk_tool_item_get_toolbar_style:
775 * @tool_item: a #GtkToolItem
777 * Returns the toolbar style used for @tool_item. Custom subclasses of
778 * #GtkToolItem should call this function in the handler of the
779 * GtkToolItem::toolbar_reconfigured signal to find out in what style
780 * the toolbar is displayed and change themselves accordingly
784 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
785 * both an icon and a label, stacked vertically </listitem>
786 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
787 * only icons </listitem>
788 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
789 * show text</listitem>
790 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
791 * both an icon and a label, arranged horizontally (however, note the
792 * #GtkToolButton::has_text_horizontally that makes tool buttons not
793 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
797 * Return value: A #GtkToolbarStyle indicating the toolbar style used
803 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
807 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
809 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
810 if (!parent || !GTK_IS_TOOL_SHELL (parent))
811 return GTK_TOOLBAR_ICONS;
813 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
817 * gtk_tool_item_get_relief_style:
818 * @tool_item: a #GtkToolItem
820 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
821 * Custom subclasses of #GtkToolItem should call this function in the handler
822 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
823 * relief style of buttons.
825 * Return value: a #GtkReliefStyle indicating the relief style used
831 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
835 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
837 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
838 if (!parent || !GTK_IS_TOOL_SHELL (parent))
839 return GTK_RELIEF_NONE;
841 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
845 * gtk_tool_item_get_text_alignment:
846 * @tool_item: a #GtkToolItem:
848 * Returns the text alignment used for @tool_item. Custom subclasses of
849 * #GtkToolItem should call this function to find out how text should
852 * Return value: a #gfloat indicating the horizontal text alignment
853 * used for @tool_item
858 gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
862 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
864 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
865 if (!parent || !GTK_IS_TOOL_SHELL (parent))
868 return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
872 * gtk_tool_item_get_text_orientation:
873 * @tool_item: a #GtkToolItem
875 * Returns the text orientation used for @tool_item. Custom subclasses of
876 * #GtkToolItem should call this function to find out how text should
879 * Return value: a #GtkOrientation indicating the text orientation
880 * used for @tool_item
885 gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
889 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
891 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
892 if (!parent || !GTK_IS_TOOL_SHELL (parent))
893 return GTK_ORIENTATION_HORIZONTAL;
895 return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
899 * gtk_tool_item_get_text_size_group:
900 * @tool_item: a #GtkToolItem
902 * Returns the size group used for labels in @tool_item.
903 * Custom subclasses of #GtkToolItem should call this function
904 * and use the size group for labels.
906 * Return value: (transfer none): a #GtkSizeGroup
911 gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
915 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
917 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
918 if (!parent || !GTK_IS_TOOL_SHELL (parent))
921 return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
925 * gtk_tool_item_set_expand:
926 * @tool_item: a #GtkToolItem
927 * @expand: Whether @tool_item is allocated extra space
929 * Sets whether @tool_item is allocated extra space when there
930 * is more room on the toolbar then needed for the items. The
931 * effect is that the item gets bigger when the toolbar gets bigger
932 * and smaller when the toolbar gets smaller.
937 gtk_tool_item_set_expand (GtkToolItem *tool_item,
940 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
942 expand = expand != FALSE;
944 if (tool_item->priv->expand != expand)
946 tool_item->priv->expand = expand;
947 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
948 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
953 * gtk_tool_item_get_expand:
954 * @tool_item: a #GtkToolItem
956 * Returns whether @tool_item is allocated extra space.
957 * See gtk_tool_item_set_expand().
959 * Return value: %TRUE if @tool_item is allocated extra space.
964 gtk_tool_item_get_expand (GtkToolItem *tool_item)
966 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
968 return tool_item->priv->expand;
972 * gtk_tool_item_set_homogeneous:
973 * @tool_item: a #GtkToolItem
974 * @homogeneous: whether @tool_item is the same size as other homogeneous items
976 * Sets whether @tool_item is to be allocated the same size as other
977 * homogeneous items. The effect is that all homogeneous items will have
978 * the same width as the widest of the items.
983 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
984 gboolean homogeneous)
986 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
988 homogeneous = homogeneous != FALSE;
990 if (tool_item->priv->homogeneous != homogeneous)
992 tool_item->priv->homogeneous = homogeneous;
993 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
994 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
999 * gtk_tool_item_get_homogeneous:
1000 * @tool_item: a #GtkToolItem
1002 * Returns whether @tool_item is the same size as other homogeneous
1003 * items. See gtk_tool_item_set_homogeneous().
1005 * Return value: %TRUE if the item is the same size as other homogeneous
1011 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
1013 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1015 return tool_item->priv->homogeneous;
1019 * gtk_tool_item_get_is_important:
1020 * @tool_item: a #GtkToolItem
1022 * Returns whether @tool_item is considered important. See
1023 * gtk_tool_item_set_is_important()
1025 * Return value: %TRUE if @tool_item is considered important.
1030 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
1032 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1034 return tool_item->priv->is_important;
1038 * gtk_tool_item_set_is_important:
1039 * @tool_item: a #GtkToolItem
1040 * @is_important: whether the tool item should be considered important
1042 * Sets whether @tool_item should be considered important. The #GtkToolButton
1043 * class uses this property to determine whether to show or hide its label
1044 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1045 * only tool buttons with the "is_important" property set have labels, an
1046 * effect known as "priority text"
1051 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
1053 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1055 is_important = is_important != FALSE;
1057 if (is_important != tool_item->priv->is_important)
1059 tool_item->priv->is_important = is_important;
1061 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1063 g_object_notify (G_OBJECT (tool_item), "is-important");
1068 * gtk_tool_item_set_tooltip_text:
1069 * @tool_item: a #GtkToolItem
1070 * @text: text to be used as tooltip for @tool_item
1072 * Sets the text to be displayed as tooltip on the item.
1073 * See gtk_widget_set_tooltip_text().
1078 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1083 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1085 child = gtk_bin_get_child (GTK_BIN (tool_item));
1087 gtk_widget_set_tooltip_text (child, text);
1091 * gtk_tool_item_set_tooltip_markup:
1092 * @tool_item: a #GtkToolItem
1093 * @markup: markup text to be used as tooltip for @tool_item
1095 * Sets the markup text to be displayed as tooltip on the item.
1096 * See gtk_widget_set_tooltip_markup().
1101 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1102 const gchar *markup)
1106 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1108 child = gtk_bin_get_child (GTK_BIN (tool_item));
1110 gtk_widget_set_tooltip_markup (child, markup);
1114 * gtk_tool_item_set_use_drag_window:
1115 * @tool_item: a #GtkToolItem
1116 * @use_drag_window: Whether @tool_item has a drag window.
1118 * Sets whether @tool_item has a drag window. When %TRUE the
1119 * toolitem can be used as a drag source through gtk_drag_source_set().
1120 * When @tool_item has a drag window it will intercept all events,
1121 * even those that would otherwise be sent to a child of @tool_item.
1126 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1127 gboolean use_drag_window)
1129 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1131 use_drag_window = use_drag_window != FALSE;
1133 if (toolitem->priv->use_drag_window != use_drag_window)
1135 toolitem->priv->use_drag_window = use_drag_window;
1137 if (use_drag_window)
1139 if (!toolitem->priv->drag_window &&
1140 gtk_widget_get_realized (GTK_WIDGET (toolitem)))
1142 create_drag_window(toolitem);
1143 if (gtk_widget_get_mapped (GTK_WIDGET (toolitem)))
1144 gdk_window_show (toolitem->priv->drag_window);
1149 destroy_drag_window (toolitem);
1155 * gtk_tool_item_get_use_drag_window:
1156 * @tool_item: a #GtkToolItem
1158 * Returns whether @tool_item has a drag window. See
1159 * gtk_tool_item_set_use_drag_window().
1161 * Return value: %TRUE if @tool_item uses a drag window.
1166 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1168 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1170 return toolitem->priv->use_drag_window;
1174 * gtk_tool_item_set_visible_horizontal:
1175 * @tool_item: a #GtkToolItem
1176 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1178 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1183 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1184 gboolean visible_horizontal)
1186 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1188 visible_horizontal = visible_horizontal != FALSE;
1190 if (toolitem->priv->visible_horizontal != visible_horizontal)
1192 toolitem->priv->visible_horizontal = visible_horizontal;
1194 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1196 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1201 * gtk_tool_item_get_visible_horizontal:
1202 * @tool_item: a #GtkToolItem
1204 * Returns whether the @tool_item is visible on toolbars that are
1205 * docked horizontally.
1207 * Return value: %TRUE if @tool_item is visible on toolbars that are
1208 * docked horizontally.
1213 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1215 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1217 return toolitem->priv->visible_horizontal;
1221 * gtk_tool_item_set_visible_vertical:
1222 * @tool_item: a #GtkToolItem
1223 * @visible_vertical: whether @tool_item is visible when the toolbar
1224 * is in vertical mode
1226 * Sets whether @tool_item is visible when the toolbar is docked
1227 * vertically. Some tool items, such as text entries, are too wide to be
1228 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1229 * @tool_item will not appear on toolbars that are docked vertically.
1234 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1235 gboolean visible_vertical)
1237 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1239 visible_vertical = visible_vertical != FALSE;
1241 if (toolitem->priv->visible_vertical != visible_vertical)
1243 toolitem->priv->visible_vertical = visible_vertical;
1245 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1247 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1252 * gtk_tool_item_get_visible_vertical:
1253 * @tool_item: a #GtkToolItem
1255 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1256 * See gtk_tool_item_set_visible_vertical().
1258 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1263 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1265 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1267 return toolitem->priv->visible_vertical;
1271 * gtk_tool_item_retrieve_proxy_menu_item:
1272 * @tool_item: a #GtkToolItem
1274 * Returns the #GtkMenuItem that was last set by
1275 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1276 * that is going to appear in the overflow menu.
1278 * Return value: (transfer none): The #GtkMenuItem that is going to appear in the
1279 * overflow menu for @tool_item.
1284 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1288 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1290 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1293 return tool_item->priv->menu_item;
1297 * gtk_tool_item_get_proxy_menu_item:
1298 * @tool_item: a #GtkToolItem
1299 * @menu_item_id: a string used to identify the menu item
1301 * If @menu_item_id matches the string passed to
1302 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1304 * Custom subclasses of #GtkToolItem should use this function to
1305 * update their menu item when the #GtkToolItem changes. That the
1306 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem
1307 * will not inadvertently change a menu item that they did not create.
1309 * Return value: (transfer none): The #GtkMenuItem passed to
1310 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s
1316 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1317 const gchar *menu_item_id)
1319 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1320 g_return_val_if_fail (menu_item_id != NULL, NULL);
1322 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1323 return tool_item->priv->menu_item;
1329 * gtk_tool_item_rebuild_menu:
1330 * @tool_item: a #GtkToolItem
1332 * Calling this function signals to the toolbar that the
1333 * overflow menu item for @tool_item has changed. If the
1334 * overflow menu is visible when this function it called,
1335 * the menu will be rebuilt.
1337 * The function must be called when the tool item changes what it
1338 * will do in response to the #GtkToolItem::create-menu-proxy signal.
1343 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1348 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1350 widget = GTK_WIDGET (tool_item);
1352 parent = gtk_widget_get_parent (widget);
1353 if (GTK_IS_TOOL_SHELL (parent))
1354 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (parent));
1358 * gtk_tool_item_set_proxy_menu_item:
1359 * @tool_item: a #GtkToolItem
1360 * @menu_item_id: a string used to identify @menu_item
1361 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1363 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1364 * @menu_item_id is used to identify the caller of this function and
1365 * should also be used with gtk_tool_item_get_proxy_menu_item().
1370 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1371 const gchar *menu_item_id,
1372 GtkWidget *menu_item)
1374 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1375 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1376 g_return_if_fail (menu_item_id != NULL);
1378 g_free (tool_item->priv->menu_item_id);
1380 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1382 if (tool_item->priv->menu_item != menu_item)
1384 if (tool_item->priv->menu_item)
1385 g_object_unref (tool_item->priv->menu_item);
1389 g_object_ref_sink (menu_item);
1391 gtk_widget_set_sensitive (menu_item,
1392 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
1395 tool_item->priv->menu_item = menu_item;
1400 * gtk_tool_item_toolbar_reconfigured:
1401 * @tool_item: a #GtkToolItem
1403 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1404 * #GtkToolbar and other #GtkToolShell implementations use this function
1405 * to notify children, when some aspect of their configuration changes.
1410 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1412 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1413 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1414 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1415 * Its not possible to rename the signal, and emitting another name than
1416 * indicated by the function name would be quite confusing. That's the
1417 * price of providing stable APIs.
1419 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1421 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1423 if (tool_item->priv->drag_window)
1424 gdk_window_raise (tool_item->priv->drag_window);
1426 gtk_widget_queue_resize (GTK_WIDGET (tool_item));