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"
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;
109 GdkWindow *drag_window;
112 GtkWidget *menu_item;
115 gboolean use_action_appearance;
118 static void gtk_tool_item_finalize (GObject *object);
119 static void gtk_tool_item_dispose (GObject *object);
120 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
122 static void gtk_tool_item_set_property (GObject *object,
126 static void gtk_tool_item_get_property (GObject *object,
130 static void gtk_tool_item_property_notify (GObject *object,
132 static void gtk_tool_item_realize (GtkWidget *widget);
133 static void gtk_tool_item_unrealize (GtkWidget *widget);
134 static void gtk_tool_item_map (GtkWidget *widget);
135 static void gtk_tool_item_unmap (GtkWidget *widget);
136 static void gtk_tool_item_get_preferred_width
140 static void gtk_tool_item_get_preferred_height
144 static void gtk_tool_item_size_allocate (GtkWidget *widget,
145 GtkAllocation *allocation);
147 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface);
148 static void gtk_tool_item_update (GtkActivatable *activatable,
150 const gchar *property_name);
151 static void gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
153 static void gtk_tool_item_set_related_action (GtkToolItem *item,
155 static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
156 gboolean use_appearance);
158 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
160 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
161 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
162 gtk_tool_item_activatable_interface_init))
165 gtk_tool_item_class_init (GtkToolItemClass *klass)
167 GObjectClass *object_class;
168 GtkWidgetClass *widget_class;
170 object_class = (GObjectClass *)klass;
171 widget_class = (GtkWidgetClass *)klass;
173 object_class->set_property = gtk_tool_item_set_property;
174 object_class->get_property = gtk_tool_item_get_property;
175 object_class->finalize = gtk_tool_item_finalize;
176 object_class->dispose = gtk_tool_item_dispose;
177 object_class->notify = gtk_tool_item_property_notify;
179 widget_class->realize = gtk_tool_item_realize;
180 widget_class->unrealize = gtk_tool_item_unrealize;
181 widget_class->map = gtk_tool_item_map;
182 widget_class->unmap = gtk_tool_item_unmap;
183 widget_class->get_preferred_width = gtk_tool_item_get_preferred_width;
184 widget_class->get_preferred_height = gtk_tool_item_get_preferred_height;
185 widget_class->size_allocate = gtk_tool_item_size_allocate;
186 widget_class->parent_set = gtk_tool_item_parent_set;
188 gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (klass));
190 klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
192 g_object_class_install_property (object_class,
193 PROP_VISIBLE_HORIZONTAL,
194 g_param_spec_boolean ("visible-horizontal",
195 P_("Visible when horizontal"),
196 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
198 GTK_PARAM_READWRITE));
199 g_object_class_install_property (object_class,
200 PROP_VISIBLE_VERTICAL,
201 g_param_spec_boolean ("visible-vertical",
202 P_("Visible when vertical"),
203 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
205 GTK_PARAM_READWRITE));
206 g_object_class_install_property (object_class,
208 g_param_spec_boolean ("is-important",
210 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
212 GTK_PARAM_READWRITE));
214 g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
215 g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
219 * GtkToolItem::create-menu-proxy:
220 * @tool_item: the object the signal was emitted on
222 * This signal is emitted when the toolbar needs information from @tool_item
223 * about whether the item should appear in the toolbar overflow menu. In
224 * response the tool item should either
226 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
227 * pointer and return %TRUE to indicate that the item should not appear
228 * in the overflow menu
230 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
231 * item and return %TRUE, or
233 * <listitem> return %FALSE to indicate that the signal was not
234 * handled by the item. This means that
235 * the item will not appear in the overflow menu unless a later handler
236 * installs a menu item.
240 * The toolbar may cache the result of this signal. When the tool item changes
241 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
242 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
245 * Return value: %TRUE if the signal was handled, %FALSE if not
247 toolitem_signals[CREATE_MENU_PROXY] =
248 g_signal_new (I_("create-menu-proxy"),
249 G_OBJECT_CLASS_TYPE (klass),
251 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
252 _gtk_boolean_handled_accumulator, NULL,
253 _gtk_marshal_BOOLEAN__VOID,
257 * GtkToolItem::toolbar-reconfigured:
258 * @tool_item: the object the signal was emitted on
260 * This signal is emitted when some property of the toolbar that the
261 * item is a child of changes. For custom subclasses of #GtkToolItem,
262 * the default handler of this signal use the functions
264 * <listitem>gtk_tool_shell_get_orientation()</listitem>
265 * <listitem>gtk_tool_shell_get_style()</listitem>
266 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
267 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
269 * to find out what the toolbar should look like and change
270 * themselves accordingly.
272 toolitem_signals[TOOLBAR_RECONFIGURED] =
273 g_signal_new (I_("toolbar-reconfigured"),
274 G_OBJECT_CLASS_TYPE (klass),
276 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
278 _gtk_marshal_VOID__VOID,
281 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
285 gtk_tool_item_init (GtkToolItem *toolitem)
287 gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE);
289 toolitem->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolitem,
293 toolitem->priv->visible_horizontal = TRUE;
294 toolitem->priv->visible_vertical = TRUE;
295 toolitem->priv->homogeneous = FALSE;
296 toolitem->priv->expand = FALSE;
298 toolitem->priv->use_action_appearance = TRUE;
302 gtk_tool_item_finalize (GObject *object)
304 GtkToolItem *item = GTK_TOOL_ITEM (object);
306 g_free (item->priv->menu_item_id);
308 if (item->priv->menu_item)
309 g_object_unref (item->priv->menu_item);
311 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
315 gtk_tool_item_dispose (GObject *object)
317 GtkToolItem *item = GTK_TOOL_ITEM (object);
319 if (item->priv->action)
321 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);
322 item->priv->action = NULL;
324 G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
329 gtk_tool_item_parent_set (GtkWidget *toolitem,
330 GtkWidget *prev_parent)
332 if (gtk_widget_get_parent (GTK_WIDGET (toolitem)) != NULL)
333 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
337 gtk_tool_item_set_property (GObject *object,
342 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
346 case PROP_VISIBLE_HORIZONTAL:
347 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
349 case PROP_VISIBLE_VERTICAL:
350 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
352 case PROP_IS_IMPORTANT:
353 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
355 case PROP_ACTIVATABLE_RELATED_ACTION:
356 gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
358 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
359 gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
362 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
368 gtk_tool_item_get_property (GObject *object,
373 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
377 case PROP_VISIBLE_HORIZONTAL:
378 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
380 case PROP_VISIBLE_VERTICAL:
381 g_value_set_boolean (value, toolitem->priv->visible_vertical);
383 case PROP_IS_IMPORTANT:
384 g_value_set_boolean (value, toolitem->priv->is_important);
386 case PROP_ACTIVATABLE_RELATED_ACTION:
387 g_value_set_object (value, toolitem->priv->action);
389 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
390 g_value_set_boolean (value, toolitem->priv->use_action_appearance);
393 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
399 gtk_tool_item_property_notify (GObject *object,
402 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
404 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
405 gtk_widget_set_sensitive (tool_item->priv->menu_item,
406 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
410 create_drag_window (GtkToolItem *toolitem)
412 GtkAllocation allocation;
414 GdkWindowAttr attributes;
415 gint attributes_mask;
417 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
419 widget = GTK_WIDGET (toolitem);
421 gtk_widget_get_allocation (widget, &allocation);
423 attributes.window_type = GDK_WINDOW_CHILD;
424 attributes.x = allocation.x;
425 attributes.y = allocation.y;
426 attributes.width = allocation.width;
427 attributes.height = allocation.height;
428 attributes.wclass = GDK_INPUT_ONLY;
429 attributes.event_mask = gtk_widget_get_events (widget);
430 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
432 attributes_mask = GDK_WA_X | GDK_WA_Y;
434 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
435 &attributes, attributes_mask);
436 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
440 gtk_tool_item_realize (GtkWidget *widget)
442 GtkToolItem *toolitem;
445 toolitem = GTK_TOOL_ITEM (widget);
446 gtk_widget_set_realized (widget, TRUE);
448 window = gtk_widget_get_parent_window (widget);
449 gtk_widget_set_window (widget, window);
450 g_object_ref (window);
452 if (toolitem->priv->use_drag_window)
453 create_drag_window(toolitem);
455 gtk_widget_style_attach (widget);
459 destroy_drag_window (GtkToolItem *toolitem)
461 if (toolitem->priv->drag_window)
463 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
464 gdk_window_destroy (toolitem->priv->drag_window);
465 toolitem->priv->drag_window = NULL;
470 gtk_tool_item_unrealize (GtkWidget *widget)
472 GtkToolItem *toolitem;
474 toolitem = GTK_TOOL_ITEM (widget);
476 destroy_drag_window (toolitem);
478 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
482 gtk_tool_item_map (GtkWidget *widget)
484 GtkToolItem *toolitem;
486 toolitem = GTK_TOOL_ITEM (widget);
487 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
488 if (toolitem->priv->drag_window)
489 gdk_window_show (toolitem->priv->drag_window);
493 gtk_tool_item_unmap (GtkWidget *widget)
495 GtkToolItem *toolitem;
497 toolitem = GTK_TOOL_ITEM (widget);
498 if (toolitem->priv->drag_window)
499 gdk_window_hide (toolitem->priv->drag_window);
500 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
504 gtk_tool_item_get_preferred_width (GtkWidget *widget,
510 *minimum = *natural = 0;
512 child = gtk_bin_get_child (GTK_BIN (widget));
513 if (child && gtk_widget_get_visible (child))
514 gtk_widget_get_preferred_width (child, minimum, natural);
518 gtk_tool_item_get_preferred_height (GtkWidget *widget,
524 *minimum = *natural = 0;
526 child = gtk_bin_get_child (GTK_BIN (widget));
527 if (child && gtk_widget_get_visible (child))
528 gtk_widget_get_preferred_height (child, minimum, natural);
532 gtk_tool_item_size_allocate (GtkWidget *widget,
533 GtkAllocation *allocation)
535 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
536 GtkAllocation child_allocation;
539 gtk_widget_set_allocation (widget, allocation);
541 if (toolitem->priv->drag_window)
542 gdk_window_move_resize (toolitem->priv->drag_window,
548 child = gtk_bin_get_child (GTK_BIN (widget));
549 if (child && gtk_widget_get_visible (child))
551 child_allocation.x = allocation->x;
552 child_allocation.y = allocation->y;
553 child_allocation.width = allocation->width;
554 child_allocation.height = allocation->height;
556 gtk_widget_size_allocate (child, &child_allocation);
561 _gtk_tool_item_create_menu_proxy (GtkToolItem *item)
563 GtkWidget *menu_item;
564 gboolean visible_overflown;
566 if (item->priv->action)
568 g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
570 if (visible_overflown)
572 menu_item = gtk_action_create_menu_item (item->priv->action);
574 g_object_ref_sink (menu_item);
575 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
576 g_object_unref (menu_item);
579 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
588 gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
590 iface->update = gtk_tool_item_update;
591 iface->sync_action_properties = gtk_tool_item_sync_action_properties;
595 gtk_tool_item_update (GtkActivatable *activatable,
597 const gchar *property_name)
599 if (strcmp (property_name, "visible") == 0)
601 if (gtk_action_is_visible (action))
602 gtk_widget_show (GTK_WIDGET (activatable));
604 gtk_widget_hide (GTK_WIDGET (activatable));
606 else if (strcmp (property_name, "sensitive") == 0)
607 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
608 else if (strcmp (property_name, "tooltip") == 0)
609 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
610 gtk_action_get_tooltip (action));
611 else if (strcmp (property_name, "visible-horizontal") == 0)
612 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
613 gtk_action_get_visible_horizontal (action));
614 else if (strcmp (property_name, "visible-vertical") == 0)
615 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
616 gtk_action_get_visible_vertical (action));
617 else if (strcmp (property_name, "is-important") == 0)
618 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
619 gtk_action_get_is_important (action));
623 gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
629 if (gtk_action_is_visible (action))
630 gtk_widget_show (GTK_WIDGET (activatable));
632 gtk_widget_hide (GTK_WIDGET (activatable));
634 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
636 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
637 gtk_action_get_tooltip (action));
638 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
639 gtk_action_get_visible_horizontal (action));
640 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
641 gtk_action_get_visible_vertical (action));
642 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
643 gtk_action_get_is_important (action));
647 gtk_tool_item_set_related_action (GtkToolItem *item,
650 if (item->priv->action == action)
653 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
655 item->priv->action = action;
659 gtk_tool_item_rebuild_menu (item);
664 gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
665 gboolean use_appearance)
667 if (item->priv->use_action_appearance != use_appearance)
669 item->priv->use_action_appearance = use_appearance;
671 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action);
679 * Creates a new #GtkToolItem
681 * Return value: the new #GtkToolItem
686 gtk_tool_item_new (void)
690 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
696 * gtk_tool_item_get_ellipsize_mode:
697 * @tool_item: a #GtkToolItem
699 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
700 * #GtkToolItem should call this function to find out how text should
703 * Return value: a #PangoEllipsizeMode indicating how text in @tool_item
704 * should be ellipsized.
709 gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
713 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
715 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
716 if (!parent || !GTK_IS_TOOL_SHELL (parent))
717 return PANGO_ELLIPSIZE_NONE;
719 return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
723 * gtk_tool_item_get_icon_size:
724 * @tool_item: a #GtkToolItem
726 * Returns the icon size used for @tool_item. Custom subclasses of
727 * #GtkToolItem should call this function to find out what size icons
730 * Return value: (type int): a #GtkIconSize indicating the icon size
731 * used for @tool_item
736 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
740 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
742 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
743 if (!parent || !GTK_IS_TOOL_SHELL (parent))
744 return GTK_ICON_SIZE_LARGE_TOOLBAR;
746 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
750 * gtk_tool_item_get_orientation:
751 * @tool_item: a #GtkToolItem
753 * Returns the orientation used for @tool_item. Custom subclasses of
754 * #GtkToolItem should call this function to find out what size icons
757 * Return value: a #GtkOrientation indicating the orientation
758 * used for @tool_item
763 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
767 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
769 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
770 if (!parent || !GTK_IS_TOOL_SHELL (parent))
771 return GTK_ORIENTATION_HORIZONTAL;
773 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
777 * gtk_tool_item_get_toolbar_style:
778 * @tool_item: a #GtkToolItem
780 * Returns the toolbar style used for @tool_item. Custom subclasses of
781 * #GtkToolItem should call this function in the handler of the
782 * GtkToolItem::toolbar_reconfigured signal to find out in what style
783 * the toolbar is displayed and change themselves accordingly
787 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
788 * both an icon and a label, stacked vertically </listitem>
789 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
790 * only icons </listitem>
791 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
792 * show text</listitem>
793 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
794 * both an icon and a label, arranged horizontally (however, note the
795 * #GtkToolButton::has_text_horizontally that makes tool buttons not
796 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
800 * Return value: A #GtkToolbarStyle indicating the toolbar style used
806 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
810 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
812 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
813 if (!parent || !GTK_IS_TOOL_SHELL (parent))
814 return GTK_TOOLBAR_ICONS;
816 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
820 * gtk_tool_item_get_relief_style:
821 * @tool_item: a #GtkToolItem
823 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
824 * Custom subclasses of #GtkToolItem should call this function in the handler
825 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
826 * relief style of buttons.
828 * Return value: a #GtkReliefStyle indicating the relief style used
834 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
838 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
840 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
841 if (!parent || !GTK_IS_TOOL_SHELL (parent))
842 return GTK_RELIEF_NONE;
844 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
848 * gtk_tool_item_get_text_alignment:
849 * @tool_item: a #GtkToolItem:
851 * Returns the text alignment used for @tool_item. Custom subclasses of
852 * #GtkToolItem should call this function to find out how text should
855 * Return value: a #gfloat indicating the horizontal text alignment
856 * used for @tool_item
861 gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
865 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
867 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
868 if (!parent || !GTK_IS_TOOL_SHELL (parent))
871 return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
875 * gtk_tool_item_get_text_orientation:
876 * @tool_item: a #GtkToolItem
878 * Returns the text orientation used for @tool_item. Custom subclasses of
879 * #GtkToolItem should call this function to find out how text should
882 * Return value: a #GtkOrientation indicating the text orientation
883 * used for @tool_item
888 gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
892 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
894 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
895 if (!parent || !GTK_IS_TOOL_SHELL (parent))
896 return GTK_ORIENTATION_HORIZONTAL;
898 return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
902 * gtk_tool_item_get_text_size_group:
903 * @tool_item: a #GtkToolItem
905 * Returns the size group used for labels in @tool_item.
906 * Custom subclasses of #GtkToolItem should call this function
907 * and use the size group for labels.
909 * Return value: (transfer none): a #GtkSizeGroup
914 gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
918 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
920 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
921 if (!parent || !GTK_IS_TOOL_SHELL (parent))
924 return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
928 * gtk_tool_item_set_expand:
929 * @tool_item: a #GtkToolItem
930 * @expand: Whether @tool_item is allocated extra space
932 * Sets whether @tool_item is allocated extra space when there
933 * is more room on the toolbar then needed for the items. The
934 * effect is that the item gets bigger when the toolbar gets bigger
935 * and smaller when the toolbar gets smaller.
940 gtk_tool_item_set_expand (GtkToolItem *tool_item,
943 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
945 expand = expand != FALSE;
947 if (tool_item->priv->expand != expand)
949 tool_item->priv->expand = expand;
950 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
951 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
956 * gtk_tool_item_get_expand:
957 * @tool_item: a #GtkToolItem
959 * Returns whether @tool_item is allocated extra space.
960 * See gtk_tool_item_set_expand().
962 * Return value: %TRUE if @tool_item is allocated extra space.
967 gtk_tool_item_get_expand (GtkToolItem *tool_item)
969 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
971 return tool_item->priv->expand;
975 * gtk_tool_item_set_homogeneous:
976 * @tool_item: a #GtkToolItem
977 * @homogeneous: whether @tool_item is the same size as other homogeneous items
979 * Sets whether @tool_item is to be allocated the same size as other
980 * homogeneous items. The effect is that all homogeneous items will have
981 * the same width as the widest of the items.
986 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
987 gboolean homogeneous)
989 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
991 homogeneous = homogeneous != FALSE;
993 if (tool_item->priv->homogeneous != homogeneous)
995 tool_item->priv->homogeneous = homogeneous;
996 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
997 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1002 * gtk_tool_item_get_homogeneous:
1003 * @tool_item: a #GtkToolItem
1005 * Returns whether @tool_item is the same size as other homogeneous
1006 * items. See gtk_tool_item_set_homogeneous().
1008 * Return value: %TRUE if the item is the same size as other homogeneous
1014 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
1016 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1018 return tool_item->priv->homogeneous;
1022 * gtk_tool_item_get_is_important:
1023 * @tool_item: a #GtkToolItem
1025 * Returns whether @tool_item is considered important. See
1026 * gtk_tool_item_set_is_important()
1028 * Return value: %TRUE if @tool_item is considered important.
1033 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
1035 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1037 return tool_item->priv->is_important;
1041 * gtk_tool_item_set_is_important:
1042 * @tool_item: a #GtkToolItem
1043 * @is_important: whether the tool item should be considered important
1045 * Sets whether @tool_item should be considered important. The #GtkToolButton
1046 * class uses this property to determine whether to show or hide its label
1047 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1048 * only tool buttons with the "is_important" property set have labels, an
1049 * effect known as "priority text"
1054 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
1056 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1058 is_important = is_important != FALSE;
1060 if (is_important != tool_item->priv->is_important)
1062 tool_item->priv->is_important = is_important;
1064 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1066 g_object_notify (G_OBJECT (tool_item), "is-important");
1071 * gtk_tool_item_set_tooltip_text:
1072 * @tool_item: a #GtkToolItem
1073 * @text: text to be used as tooltip for @tool_item
1075 * Sets the text to be displayed as tooltip on the item.
1076 * See gtk_widget_set_tooltip_text().
1081 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1086 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1088 child = gtk_bin_get_child (GTK_BIN (tool_item));
1090 gtk_widget_set_tooltip_text (child, text);
1094 * gtk_tool_item_set_tooltip_markup:
1095 * @tool_item: a #GtkToolItem
1096 * @markup: markup text to be used as tooltip for @tool_item
1098 * Sets the markup text to be displayed as tooltip on the item.
1099 * See gtk_widget_set_tooltip_markup().
1104 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1105 const gchar *markup)
1109 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1111 child = gtk_bin_get_child (GTK_BIN (tool_item));
1113 gtk_widget_set_tooltip_markup (child, markup);
1117 * gtk_tool_item_set_use_drag_window:
1118 * @tool_item: a #GtkToolItem
1119 * @use_drag_window: Whether @tool_item has a drag window.
1121 * Sets whether @tool_item has a drag window. When %TRUE the
1122 * toolitem can be used as a drag source through gtk_drag_source_set().
1123 * When @tool_item has a drag window it will intercept all events,
1124 * even those that would otherwise be sent to a child of @tool_item.
1129 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1130 gboolean use_drag_window)
1132 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1134 use_drag_window = use_drag_window != FALSE;
1136 if (toolitem->priv->use_drag_window != use_drag_window)
1138 toolitem->priv->use_drag_window = use_drag_window;
1140 if (use_drag_window)
1142 if (!toolitem->priv->drag_window &&
1143 gtk_widget_get_realized (GTK_WIDGET (toolitem)))
1145 create_drag_window(toolitem);
1146 if (gtk_widget_get_mapped (GTK_WIDGET (toolitem)))
1147 gdk_window_show (toolitem->priv->drag_window);
1152 destroy_drag_window (toolitem);
1158 * gtk_tool_item_get_use_drag_window:
1159 * @tool_item: a #GtkToolItem
1161 * Returns whether @tool_item has a drag window. See
1162 * gtk_tool_item_set_use_drag_window().
1164 * Return value: %TRUE if @tool_item uses a drag window.
1169 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1171 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1173 return toolitem->priv->use_drag_window;
1177 * gtk_tool_item_set_visible_horizontal:
1178 * @tool_item: a #GtkToolItem
1179 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1181 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1186 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1187 gboolean visible_horizontal)
1189 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1191 visible_horizontal = visible_horizontal != FALSE;
1193 if (toolitem->priv->visible_horizontal != visible_horizontal)
1195 toolitem->priv->visible_horizontal = visible_horizontal;
1197 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1199 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1204 * gtk_tool_item_get_visible_horizontal:
1205 * @tool_item: a #GtkToolItem
1207 * Returns whether the @tool_item is visible on toolbars that are
1208 * docked horizontally.
1210 * Return value: %TRUE if @tool_item is visible on toolbars that are
1211 * docked horizontally.
1216 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1218 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1220 return toolitem->priv->visible_horizontal;
1224 * gtk_tool_item_set_visible_vertical:
1225 * @tool_item: a #GtkToolItem
1226 * @visible_vertical: whether @tool_item is visible when the toolbar
1227 * is in vertical mode
1229 * Sets whether @tool_item is visible when the toolbar is docked
1230 * vertically. Some tool items, such as text entries, are too wide to be
1231 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1232 * @tool_item will not appear on toolbars that are docked vertically.
1237 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1238 gboolean visible_vertical)
1240 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1242 visible_vertical = visible_vertical != FALSE;
1244 if (toolitem->priv->visible_vertical != visible_vertical)
1246 toolitem->priv->visible_vertical = visible_vertical;
1248 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1250 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1255 * gtk_tool_item_get_visible_vertical:
1256 * @tool_item: a #GtkToolItem
1258 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1259 * See gtk_tool_item_set_visible_vertical().
1261 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1266 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1268 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1270 return toolitem->priv->visible_vertical;
1274 * gtk_tool_item_retrieve_proxy_menu_item:
1275 * @tool_item: a #GtkToolItem
1277 * Returns the #GtkMenuItem that was last set by
1278 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1279 * that is going to appear in the overflow menu.
1281 * Return value: (transfer none): The #GtkMenuItem that is going to appear in the
1282 * overflow menu for @tool_item.
1287 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1291 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1293 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1296 return tool_item->priv->menu_item;
1300 * gtk_tool_item_get_proxy_menu_item:
1301 * @tool_item: a #GtkToolItem
1302 * @menu_item_id: a string used to identify the menu item
1304 * If @menu_item_id matches the string passed to
1305 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1307 * Custom subclasses of #GtkToolItem should use this function to
1308 * update their menu item when the #GtkToolItem changes. That the
1309 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem
1310 * will not inadvertently change a menu item that they did not create.
1312 * Return value: (transfer none): The #GtkMenuItem passed to
1313 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s
1319 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1320 const gchar *menu_item_id)
1322 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1323 g_return_val_if_fail (menu_item_id != NULL, NULL);
1325 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1326 return tool_item->priv->menu_item;
1332 * gtk_tool_item_rebuild_menu:
1333 * @tool_item: a #GtkToolItem
1335 * Calling this function signals to the toolbar that the
1336 * overflow menu item for @tool_item has changed. If the
1337 * overflow menu is visible when this function it called,
1338 * the menu will be rebuilt.
1340 * The function must be called when the tool item changes what it
1341 * will do in response to the #GtkToolItem::create-menu-proxy signal.
1346 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1351 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1353 widget = GTK_WIDGET (tool_item);
1355 parent = gtk_widget_get_parent (widget);
1356 if (GTK_IS_TOOL_SHELL (parent))
1357 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (parent));
1361 * gtk_tool_item_set_proxy_menu_item:
1362 * @tool_item: a #GtkToolItem
1363 * @menu_item_id: a string used to identify @menu_item
1364 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1366 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1367 * @menu_item_id is used to identify the caller of this function and
1368 * should also be used with gtk_tool_item_get_proxy_menu_item().
1373 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1374 const gchar *menu_item_id,
1375 GtkWidget *menu_item)
1377 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1378 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1379 g_return_if_fail (menu_item_id != NULL);
1381 g_free (tool_item->priv->menu_item_id);
1383 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1385 if (tool_item->priv->menu_item != menu_item)
1387 if (tool_item->priv->menu_item)
1388 g_object_unref (tool_item->priv->menu_item);
1392 g_object_ref_sink (menu_item);
1394 gtk_widget_set_sensitive (menu_item,
1395 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
1398 tool_item->priv->menu_item = menu_item;
1403 * gtk_tool_item_toolbar_reconfigured:
1404 * @tool_item: a #GtkToolItem
1406 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1407 * #GtkToolbar and other #GtkToolShell implementations use this function
1408 * to notify children, when some aspect of their configuration changes.
1413 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1415 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1416 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1417 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1418 * Its not possible to rename the signal, and emitting another name than
1419 * indicated by the function name would be quite confusing. That's the
1420 * price of providing stable APIs.
1422 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1424 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1426 if (tool_item->priv->drag_window)
1427 gdk_window_raise (tool_item->priv->drag_window);
1429 gtk_widget_queue_resize (GTK_WIDGET (tool_item));