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, see <http://www.gnu.org/licenses/>.
23 #include "gtktoolitem.h"
27 #include "gtkmarshalers.h"
28 #include "gtktoolshell.h"
29 #include "gtkseparatormenuitem.h"
30 #include "gtksizerequest.h"
31 #include "gtkactivatable.h"
33 #include "gtkprivate.h"
38 * @short_description: The base class of widgets that can be added to GtkToolShell
40 * @see_also: <variablelist>
42 * <term>#GtkToolbar</term>
43 * <listitem><para>The toolbar widget</para></listitem>
46 * <term>#GtkToolButton</term>
47 * <listitem><para>A subclass of #GtkToolItem that displays buttons on
48 * the toolbar</para></listitem>
51 * <term>#GtkSeparatorToolItem</term>
52 * <listitem><para>A subclass of #GtkToolItem that separates groups of
53 * items on a toolbar</para></listitem>
57 * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
58 * create a toolbar item that contain something else than a button, use
59 * gtk_tool_item_new(). Use gtk_container_add() to add a child
60 * widget to the tool item.
62 * For toolbar items that contain buttons, see the #GtkToolButton,
63 * #GtkToggleToolButton and #GtkRadioToolButton classes.
65 * See the #GtkToolbar class for a description of the toolbar widget, and
66 * #GtkToolShell for a description of the tool shell interface.
72 * The GtkToolItem struct contains only private data.
73 * It should only be accessed through the functions described below.
84 PROP_VISIBLE_HORIZONTAL,
85 PROP_VISIBLE_VERTICAL,
88 /* activatable properties */
89 PROP_ACTIVATABLE_RELATED_ACTION,
90 PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
94 struct _GtkToolItemPrivate
99 guint visible_horizontal : 1;
100 guint visible_vertical : 1;
101 guint homogeneous : 1;
103 guint use_drag_window : 1;
104 guint is_important : 1;
105 guint use_action_appearance : 1;
107 GdkWindow *drag_window;
109 GtkWidget *menu_item;
114 static void gtk_tool_item_finalize (GObject *object);
115 static void gtk_tool_item_dispose (GObject *object);
116 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
118 static void gtk_tool_item_set_property (GObject *object,
122 static void gtk_tool_item_get_property (GObject *object,
126 static void gtk_tool_item_property_notify (GObject *object,
128 static void gtk_tool_item_realize (GtkWidget *widget);
129 static void gtk_tool_item_unrealize (GtkWidget *widget);
130 static void gtk_tool_item_map (GtkWidget *widget);
131 static void gtk_tool_item_unmap (GtkWidget *widget);
132 static void gtk_tool_item_get_preferred_width
136 static void gtk_tool_item_get_preferred_height
140 static void gtk_tool_item_size_allocate (GtkWidget *widget,
141 GtkAllocation *allocation);
143 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface);
144 static void gtk_tool_item_update (GtkActivatable *activatable,
146 const gchar *property_name);
147 static void gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
149 static void gtk_tool_item_set_related_action (GtkToolItem *item,
151 static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
152 gboolean use_appearance);
154 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
156 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
157 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
158 gtk_tool_item_activatable_interface_init))
161 gtk_tool_item_class_init (GtkToolItemClass *klass)
163 GObjectClass *object_class;
164 GtkWidgetClass *widget_class;
166 object_class = (GObjectClass *)klass;
167 widget_class = (GtkWidgetClass *)klass;
169 object_class->set_property = gtk_tool_item_set_property;
170 object_class->get_property = gtk_tool_item_get_property;
171 object_class->finalize = gtk_tool_item_finalize;
172 object_class->dispose = gtk_tool_item_dispose;
173 object_class->notify = gtk_tool_item_property_notify;
175 widget_class->realize = gtk_tool_item_realize;
176 widget_class->unrealize = gtk_tool_item_unrealize;
177 widget_class->map = gtk_tool_item_map;
178 widget_class->unmap = gtk_tool_item_unmap;
179 widget_class->get_preferred_width = gtk_tool_item_get_preferred_width;
180 widget_class->get_preferred_height = gtk_tool_item_get_preferred_height;
181 widget_class->size_allocate = gtk_tool_item_size_allocate;
182 widget_class->parent_set = gtk_tool_item_parent_set;
184 gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (klass));
186 klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
188 g_object_class_install_property (object_class,
189 PROP_VISIBLE_HORIZONTAL,
190 g_param_spec_boolean ("visible-horizontal",
191 P_("Visible when horizontal"),
192 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
194 GTK_PARAM_READWRITE));
195 g_object_class_install_property (object_class,
196 PROP_VISIBLE_VERTICAL,
197 g_param_spec_boolean ("visible-vertical",
198 P_("Visible when vertical"),
199 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
201 GTK_PARAM_READWRITE));
202 g_object_class_install_property (object_class,
204 g_param_spec_boolean ("is-important",
206 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
208 GTK_PARAM_READWRITE));
210 g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
211 g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
215 * GtkToolItem::create-menu-proxy:
216 * @tool_item: the object the signal was emitted on
218 * This signal is emitted when the toolbar needs information from @tool_item
219 * about whether the item should appear in the toolbar overflow menu. In
220 * response the tool item should either
222 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
223 * pointer and return %TRUE to indicate that the item should not appear
224 * in the overflow menu
226 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
227 * item and return %TRUE, or
229 * <listitem> return %FALSE to indicate that the signal was not
230 * handled by the item. This means that
231 * the item will not appear in the overflow menu unless a later handler
232 * installs a menu item.
236 * The toolbar may cache the result of this signal. When the tool item changes
237 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
238 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
241 * Return value: %TRUE if the signal was handled, %FALSE if not
243 toolitem_signals[CREATE_MENU_PROXY] =
244 g_signal_new (I_("create-menu-proxy"),
245 G_OBJECT_CLASS_TYPE (klass),
247 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
248 _gtk_boolean_handled_accumulator, NULL,
249 _gtk_marshal_BOOLEAN__VOID,
253 * GtkToolItem::toolbar-reconfigured:
254 * @tool_item: the object the signal was emitted on
256 * This signal is emitted when some property of the toolbar that the
257 * item is a child of changes. For custom subclasses of #GtkToolItem,
258 * the default handler of this signal use the functions
260 * <listitem>gtk_tool_shell_get_orientation()</listitem>
261 * <listitem>gtk_tool_shell_get_style()</listitem>
262 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
263 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
265 * to find out what the toolbar should look like and change
266 * themselves accordingly.
268 toolitem_signals[TOOLBAR_RECONFIGURED] =
269 g_signal_new (I_("toolbar-reconfigured"),
270 G_OBJECT_CLASS_TYPE (klass),
272 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
274 _gtk_marshal_VOID__VOID,
277 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
281 gtk_tool_item_init (GtkToolItem *toolitem)
283 gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE);
285 toolitem->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolitem,
289 toolitem->priv->visible_horizontal = TRUE;
290 toolitem->priv->visible_vertical = TRUE;
291 toolitem->priv->homogeneous = FALSE;
292 toolitem->priv->expand = FALSE;
294 toolitem->priv->use_action_appearance = TRUE;
298 gtk_tool_item_finalize (GObject *object)
300 GtkToolItem *item = GTK_TOOL_ITEM (object);
302 g_free (item->priv->menu_item_id);
304 if (item->priv->menu_item)
305 g_object_unref (item->priv->menu_item);
307 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
311 gtk_tool_item_dispose (GObject *object)
313 GtkToolItem *item = GTK_TOOL_ITEM (object);
315 if (item->priv->action)
317 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);
318 item->priv->action = NULL;
320 G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
325 gtk_tool_item_parent_set (GtkWidget *toolitem,
326 GtkWidget *prev_parent)
328 if (gtk_widget_get_parent (GTK_WIDGET (toolitem)) != NULL)
329 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
333 gtk_tool_item_set_property (GObject *object,
338 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
342 case PROP_VISIBLE_HORIZONTAL:
343 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
345 case PROP_VISIBLE_VERTICAL:
346 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
348 case PROP_IS_IMPORTANT:
349 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
351 case PROP_ACTIVATABLE_RELATED_ACTION:
352 gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
354 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
355 gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
358 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
364 gtk_tool_item_get_property (GObject *object,
369 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
373 case PROP_VISIBLE_HORIZONTAL:
374 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
376 case PROP_VISIBLE_VERTICAL:
377 g_value_set_boolean (value, toolitem->priv->visible_vertical);
379 case PROP_IS_IMPORTANT:
380 g_value_set_boolean (value, toolitem->priv->is_important);
382 case PROP_ACTIVATABLE_RELATED_ACTION:
383 g_value_set_object (value, toolitem->priv->action);
385 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
386 g_value_set_boolean (value, toolitem->priv->use_action_appearance);
389 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
395 gtk_tool_item_property_notify (GObject *object,
398 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
400 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
401 gtk_widget_set_sensitive (tool_item->priv->menu_item,
402 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
404 if (G_OBJECT_CLASS (gtk_tool_item_parent_class)->notify)
405 G_OBJECT_CLASS (gtk_tool_item_parent_class)->notify (object, pspec);
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</listitem>
794 * Return value: A #GtkToolbarStyle indicating the toolbar style used
800 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
804 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
806 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
807 if (!parent || !GTK_IS_TOOL_SHELL (parent))
808 return GTK_TOOLBAR_ICONS;
810 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
814 * gtk_tool_item_get_relief_style:
815 * @tool_item: a #GtkToolItem
817 * Returns the relief style of @tool_item. See gtk_button_set_relief().
818 * Custom subclasses of #GtkToolItem should call this function in the handler
819 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
820 * relief style of buttons.
822 * Return value: a #GtkReliefStyle indicating the relief style used
828 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
832 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
834 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
835 if (!parent || !GTK_IS_TOOL_SHELL (parent))
836 return GTK_RELIEF_NONE;
838 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
842 * gtk_tool_item_get_text_alignment:
843 * @tool_item: a #GtkToolItem:
845 * Returns the text alignment used for @tool_item. Custom subclasses of
846 * #GtkToolItem should call this function to find out how text should
849 * Return value: a #gfloat indicating the horizontal text alignment
850 * used for @tool_item
855 gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
859 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
861 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
862 if (!parent || !GTK_IS_TOOL_SHELL (parent))
865 return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
869 * gtk_tool_item_get_text_orientation:
870 * @tool_item: a #GtkToolItem
872 * Returns the text orientation used for @tool_item. Custom subclasses of
873 * #GtkToolItem should call this function to find out how text should
876 * Return value: a #GtkOrientation indicating the text orientation
877 * used for @tool_item
882 gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
886 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
888 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
889 if (!parent || !GTK_IS_TOOL_SHELL (parent))
890 return GTK_ORIENTATION_HORIZONTAL;
892 return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
896 * gtk_tool_item_get_text_size_group:
897 * @tool_item: a #GtkToolItem
899 * Returns the size group used for labels in @tool_item.
900 * Custom subclasses of #GtkToolItem should call this function
901 * and use the size group for labels.
903 * Return value: (transfer none): a #GtkSizeGroup
908 gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
912 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
914 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
915 if (!parent || !GTK_IS_TOOL_SHELL (parent))
918 return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
922 * gtk_tool_item_set_expand:
923 * @tool_item: a #GtkToolItem
924 * @expand: Whether @tool_item is allocated extra space
926 * Sets whether @tool_item is allocated extra space when there
927 * is more room on the toolbar then needed for the items. The
928 * effect is that the item gets bigger when the toolbar gets bigger
929 * and smaller when the toolbar gets smaller.
934 gtk_tool_item_set_expand (GtkToolItem *tool_item,
937 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
939 expand = expand != FALSE;
941 if (tool_item->priv->expand != expand)
943 tool_item->priv->expand = expand;
944 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
945 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
950 * gtk_tool_item_get_expand:
951 * @tool_item: a #GtkToolItem
953 * Returns whether @tool_item is allocated extra space.
954 * See gtk_tool_item_set_expand().
956 * Return value: %TRUE if @tool_item is allocated extra space.
961 gtk_tool_item_get_expand (GtkToolItem *tool_item)
963 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
965 return tool_item->priv->expand;
969 * gtk_tool_item_set_homogeneous:
970 * @tool_item: a #GtkToolItem
971 * @homogeneous: whether @tool_item is the same size as other homogeneous items
973 * Sets whether @tool_item is to be allocated the same size as other
974 * homogeneous items. The effect is that all homogeneous items will have
975 * the same width as the widest of the items.
980 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
981 gboolean homogeneous)
983 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
985 homogeneous = homogeneous != FALSE;
987 if (tool_item->priv->homogeneous != homogeneous)
989 tool_item->priv->homogeneous = homogeneous;
990 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
991 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
996 * gtk_tool_item_get_homogeneous:
997 * @tool_item: a #GtkToolItem
999 * Returns whether @tool_item is the same size as other homogeneous
1000 * items. See gtk_tool_item_set_homogeneous().
1002 * Return value: %TRUE if the item is the same size as other homogeneous
1008 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
1010 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1012 return tool_item->priv->homogeneous;
1016 * gtk_tool_item_get_is_important:
1017 * @tool_item: a #GtkToolItem
1019 * Returns whether @tool_item is considered important. See
1020 * gtk_tool_item_set_is_important()
1022 * Return value: %TRUE if @tool_item is considered important.
1027 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
1029 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1031 return tool_item->priv->is_important;
1035 * gtk_tool_item_set_is_important:
1036 * @tool_item: a #GtkToolItem
1037 * @is_important: whether the tool item should be considered important
1039 * Sets whether @tool_item should be considered important. The #GtkToolButton
1040 * class uses this property to determine whether to show or hide its label
1041 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1042 * only tool buttons with the "is_important" property set have labels, an
1043 * effect known as "priority text"
1048 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
1050 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1052 is_important = is_important != FALSE;
1054 if (is_important != tool_item->priv->is_important)
1056 tool_item->priv->is_important = is_important;
1058 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1060 g_object_notify (G_OBJECT (tool_item), "is-important");
1065 * gtk_tool_item_set_tooltip_text:
1066 * @tool_item: a #GtkToolItem
1067 * @text: text to be used as tooltip for @tool_item
1069 * Sets the text to be displayed as tooltip on the item.
1070 * See gtk_widget_set_tooltip_text().
1075 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1080 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1082 child = gtk_bin_get_child (GTK_BIN (tool_item));
1084 gtk_widget_set_tooltip_text (child, text);
1088 * gtk_tool_item_set_tooltip_markup:
1089 * @tool_item: a #GtkToolItem
1090 * @markup: markup text to be used as tooltip for @tool_item
1092 * Sets the markup text to be displayed as tooltip on the item.
1093 * See gtk_widget_set_tooltip_markup().
1098 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1099 const gchar *markup)
1103 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1105 child = gtk_bin_get_child (GTK_BIN (tool_item));
1107 gtk_widget_set_tooltip_markup (child, markup);
1111 * gtk_tool_item_set_use_drag_window:
1112 * @tool_item: a #GtkToolItem
1113 * @use_drag_window: Whether @tool_item has a drag window.
1115 * Sets whether @tool_item has a drag window. When %TRUE the
1116 * toolitem can be used as a drag source through gtk_drag_source_set().
1117 * When @tool_item has a drag window it will intercept all events,
1118 * even those that would otherwise be sent to a child of @tool_item.
1123 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1124 gboolean use_drag_window)
1126 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1128 use_drag_window = use_drag_window != FALSE;
1130 if (toolitem->priv->use_drag_window != use_drag_window)
1132 toolitem->priv->use_drag_window = use_drag_window;
1134 if (use_drag_window)
1136 if (!toolitem->priv->drag_window &&
1137 gtk_widget_get_realized (GTK_WIDGET (toolitem)))
1139 create_drag_window(toolitem);
1140 if (gtk_widget_get_mapped (GTK_WIDGET (toolitem)))
1141 gdk_window_show (toolitem->priv->drag_window);
1146 destroy_drag_window (toolitem);
1152 * gtk_tool_item_get_use_drag_window:
1153 * @tool_item: a #GtkToolItem
1155 * Returns whether @tool_item has a drag window. See
1156 * gtk_tool_item_set_use_drag_window().
1158 * Return value: %TRUE if @tool_item uses a drag window.
1163 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1165 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1167 return toolitem->priv->use_drag_window;
1171 * gtk_tool_item_set_visible_horizontal:
1172 * @tool_item: a #GtkToolItem
1173 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1175 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1180 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1181 gboolean visible_horizontal)
1183 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1185 visible_horizontal = visible_horizontal != FALSE;
1187 if (toolitem->priv->visible_horizontal != visible_horizontal)
1189 toolitem->priv->visible_horizontal = visible_horizontal;
1191 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1193 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1198 * gtk_tool_item_get_visible_horizontal:
1199 * @tool_item: a #GtkToolItem
1201 * Returns whether the @tool_item is visible on toolbars that are
1202 * docked horizontally.
1204 * Return value: %TRUE if @tool_item is visible on toolbars that are
1205 * docked horizontally.
1210 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1212 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1214 return toolitem->priv->visible_horizontal;
1218 * gtk_tool_item_set_visible_vertical:
1219 * @tool_item: a #GtkToolItem
1220 * @visible_vertical: whether @tool_item is visible when the toolbar
1221 * is in vertical mode
1223 * Sets whether @tool_item is visible when the toolbar is docked
1224 * vertically. Some tool items, such as text entries, are too wide to be
1225 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1226 * @tool_item will not appear on toolbars that are docked vertically.
1231 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1232 gboolean visible_vertical)
1234 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1236 visible_vertical = visible_vertical != FALSE;
1238 if (toolitem->priv->visible_vertical != visible_vertical)
1240 toolitem->priv->visible_vertical = visible_vertical;
1242 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1244 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1249 * gtk_tool_item_get_visible_vertical:
1250 * @tool_item: a #GtkToolItem
1252 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1253 * See gtk_tool_item_set_visible_vertical().
1255 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1260 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1262 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1264 return toolitem->priv->visible_vertical;
1268 * gtk_tool_item_retrieve_proxy_menu_item:
1269 * @tool_item: a #GtkToolItem
1271 * Returns the #GtkMenuItem that was last set by
1272 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1273 * that is going to appear in the overflow menu.
1275 * Return value: (transfer none): The #GtkMenuItem that is going to appear in the
1276 * overflow menu for @tool_item.
1281 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1285 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1287 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1290 return tool_item->priv->menu_item;
1294 * gtk_tool_item_get_proxy_menu_item:
1295 * @tool_item: a #GtkToolItem
1296 * @menu_item_id: a string used to identify the menu item
1298 * If @menu_item_id matches the string passed to
1299 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1301 * Custom subclasses of #GtkToolItem should use this function to
1302 * update their menu item when the #GtkToolItem changes. That the
1303 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem
1304 * will not inadvertently change a menu item that they did not create.
1306 * Return value: (transfer none): The #GtkMenuItem passed to
1307 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s
1313 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1314 const gchar *menu_item_id)
1316 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1317 g_return_val_if_fail (menu_item_id != NULL, NULL);
1319 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1320 return tool_item->priv->menu_item;
1326 * gtk_tool_item_rebuild_menu:
1327 * @tool_item: a #GtkToolItem
1329 * Calling this function signals to the toolbar that the
1330 * overflow menu item for @tool_item has changed. If the
1331 * overflow menu is visible when this function it called,
1332 * the menu will be rebuilt.
1334 * The function must be called when the tool item changes what it
1335 * will do in response to the #GtkToolItem::create-menu-proxy signal.
1340 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1345 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1347 widget = GTK_WIDGET (tool_item);
1349 parent = gtk_widget_get_parent (widget);
1350 if (GTK_IS_TOOL_SHELL (parent))
1351 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (parent));
1355 * gtk_tool_item_set_proxy_menu_item:
1356 * @tool_item: a #GtkToolItem
1357 * @menu_item_id: a string used to identify @menu_item
1358 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1360 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1361 * @menu_item_id is used to identify the caller of this function and
1362 * should also be used with gtk_tool_item_get_proxy_menu_item().
1367 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1368 const gchar *menu_item_id,
1369 GtkWidget *menu_item)
1371 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1372 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1373 g_return_if_fail (menu_item_id != NULL);
1375 g_free (tool_item->priv->menu_item_id);
1377 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1379 if (tool_item->priv->menu_item != menu_item)
1381 if (tool_item->priv->menu_item)
1382 g_object_unref (tool_item->priv->menu_item);
1386 g_object_ref_sink (menu_item);
1388 gtk_widget_set_sensitive (menu_item,
1389 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
1392 tool_item->priv->menu_item = menu_item;
1397 * gtk_tool_item_toolbar_reconfigured:
1398 * @tool_item: a #GtkToolItem
1400 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1401 * #GtkToolbar and other #GtkToolShell implementations use this function
1402 * to notify children, when some aspect of their configuration changes.
1407 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1409 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1410 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1411 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1412 * Its not possible to rename the signal, and emitting another name than
1413 * indicated by the function name would be quite confusing. That's the
1414 * price of providing stable APIs.
1416 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1418 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1420 if (tool_item->priv->drag_window)
1421 gdk_window_raise (tool_item->priv->drag_window);
1423 gtk_widget_queue_resize (GTK_WIDGET (tool_item));