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 "gtkprivate.h"
40 * @short_description: The base class of widgets that can be added to GtkToolShell
42 * @see_also: <variablelist>
44 * <term>#GtkToolbar</term>
45 * <listitem><para>The toolbar widget</para></listitem>
48 * <term>#GtkToolButton</term>
49 * <listitem><para>A subclass of #GtkToolItem that displays buttons on
50 * the toolbar</para></listitem>
53 * <term>#GtkSeparatorToolItem</term>
54 * <listitem><para>A subclass of #GtkToolItem that separates groups of
55 * items on a toolbar</para></listitem>
59 * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
60 * create a toolbar item that contain something else than a button, use
61 * gtk_tool_item_new(). Use gtk_container_add() to add a child
62 * widget to the tool item.
64 * For toolbar items that contain buttons, see the #GtkToolButton,
65 * #GtkToggleToolButton and #GtkRadioToolButton classes.
67 * See the #GtkToolbar class for a description of the toolbar widget, and
68 * #GtkToolShell for a description of the tool shell interface.
74 * The GtkToolItem struct contains only private data.
75 * It should only be accessed through the functions described below.
86 PROP_VISIBLE_HORIZONTAL,
87 PROP_VISIBLE_VERTICAL,
90 /* activatable properties */
91 PROP_ACTIVATABLE_RELATED_ACTION,
92 PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
96 struct _GtkToolItemPrivate
101 guint visible_horizontal : 1;
102 guint visible_vertical : 1;
103 guint homogeneous : 1;
105 guint use_drag_window : 1;
106 guint is_important : 1;
107 guint use_action_appearance : 1;
109 GdkWindow *drag_window;
111 GtkWidget *menu_item;
116 static void gtk_tool_item_finalize (GObject *object);
117 static void gtk_tool_item_dispose (GObject *object);
118 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
120 static void gtk_tool_item_set_property (GObject *object,
124 static void gtk_tool_item_get_property (GObject *object,
128 static void gtk_tool_item_property_notify (GObject *object,
130 static void gtk_tool_item_realize (GtkWidget *widget);
131 static void gtk_tool_item_unrealize (GtkWidget *widget);
132 static void gtk_tool_item_map (GtkWidget *widget);
133 static void gtk_tool_item_unmap (GtkWidget *widget);
134 static void gtk_tool_item_get_preferred_width
138 static void gtk_tool_item_get_preferred_height
142 static void gtk_tool_item_size_allocate (GtkWidget *widget,
143 GtkAllocation *allocation);
145 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface);
146 static void gtk_tool_item_update (GtkActivatable *activatable,
148 const gchar *property_name);
149 static void gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
151 static void gtk_tool_item_set_related_action (GtkToolItem *item,
153 static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
154 gboolean use_appearance);
156 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
158 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
159 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
160 gtk_tool_item_activatable_interface_init))
163 gtk_tool_item_class_init (GtkToolItemClass *klass)
165 GObjectClass *object_class;
166 GtkWidgetClass *widget_class;
168 object_class = (GObjectClass *)klass;
169 widget_class = (GtkWidgetClass *)klass;
171 object_class->set_property = gtk_tool_item_set_property;
172 object_class->get_property = gtk_tool_item_get_property;
173 object_class->finalize = gtk_tool_item_finalize;
174 object_class->dispose = gtk_tool_item_dispose;
175 object_class->notify = gtk_tool_item_property_notify;
177 widget_class->realize = gtk_tool_item_realize;
178 widget_class->unrealize = gtk_tool_item_unrealize;
179 widget_class->map = gtk_tool_item_map;
180 widget_class->unmap = gtk_tool_item_unmap;
181 widget_class->get_preferred_width = gtk_tool_item_get_preferred_width;
182 widget_class->get_preferred_height = gtk_tool_item_get_preferred_height;
183 widget_class->size_allocate = gtk_tool_item_size_allocate;
184 widget_class->parent_set = gtk_tool_item_parent_set;
186 gtk_container_class_handle_border_width (GTK_CONTAINER_CLASS (klass));
188 klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
190 g_object_class_install_property (object_class,
191 PROP_VISIBLE_HORIZONTAL,
192 g_param_spec_boolean ("visible-horizontal",
193 P_("Visible when horizontal"),
194 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
196 GTK_PARAM_READWRITE));
197 g_object_class_install_property (object_class,
198 PROP_VISIBLE_VERTICAL,
199 g_param_spec_boolean ("visible-vertical",
200 P_("Visible when vertical"),
201 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
203 GTK_PARAM_READWRITE));
204 g_object_class_install_property (object_class,
206 g_param_spec_boolean ("is-important",
208 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
210 GTK_PARAM_READWRITE));
212 g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
213 g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
217 * GtkToolItem::create-menu-proxy:
218 * @tool_item: the object the signal was emitted on
220 * This signal is emitted when the toolbar needs information from @tool_item
221 * about whether the item should appear in the toolbar overflow menu. In
222 * response the tool item should either
224 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
225 * pointer and return %TRUE to indicate that the item should not appear
226 * in the overflow menu
228 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
229 * item and return %TRUE, or
231 * <listitem> return %FALSE to indicate that the signal was not
232 * handled by the item. This means that
233 * the item will not appear in the overflow menu unless a later handler
234 * installs a menu item.
238 * The toolbar may cache the result of this signal. When the tool item changes
239 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
240 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
243 * Return value: %TRUE if the signal was handled, %FALSE if not
245 toolitem_signals[CREATE_MENU_PROXY] =
246 g_signal_new (I_("create-menu-proxy"),
247 G_OBJECT_CLASS_TYPE (klass),
249 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
250 _gtk_boolean_handled_accumulator, NULL,
251 _gtk_marshal_BOOLEAN__VOID,
255 * GtkToolItem::toolbar-reconfigured:
256 * @tool_item: the object the signal was emitted on
258 * This signal is emitted when some property of the toolbar that the
259 * item is a child of changes. For custom subclasses of #GtkToolItem,
260 * the default handler of this signal use the functions
262 * <listitem>gtk_tool_shell_get_orientation()</listitem>
263 * <listitem>gtk_tool_shell_get_style()</listitem>
264 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
265 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
267 * to find out what the toolbar should look like and change
268 * themselves accordingly.
270 toolitem_signals[TOOLBAR_RECONFIGURED] =
271 g_signal_new (I_("toolbar-reconfigured"),
272 G_OBJECT_CLASS_TYPE (klass),
274 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
276 _gtk_marshal_VOID__VOID,
279 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
283 gtk_tool_item_init (GtkToolItem *toolitem)
285 gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE);
287 toolitem->priv = G_TYPE_INSTANCE_GET_PRIVATE (toolitem,
291 toolitem->priv->visible_horizontal = TRUE;
292 toolitem->priv->visible_vertical = TRUE;
293 toolitem->priv->homogeneous = FALSE;
294 toolitem->priv->expand = FALSE;
296 toolitem->priv->use_action_appearance = TRUE;
300 gtk_tool_item_finalize (GObject *object)
302 GtkToolItem *item = GTK_TOOL_ITEM (object);
304 g_free (item->priv->menu_item_id);
306 if (item->priv->menu_item)
307 g_object_unref (item->priv->menu_item);
309 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
313 gtk_tool_item_dispose (GObject *object)
315 GtkToolItem *item = GTK_TOOL_ITEM (object);
317 if (item->priv->action)
319 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);
320 item->priv->action = NULL;
322 G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
327 gtk_tool_item_parent_set (GtkWidget *toolitem,
328 GtkWidget *prev_parent)
330 if (gtk_widget_get_parent (GTK_WIDGET (toolitem)) != NULL)
331 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
335 gtk_tool_item_set_property (GObject *object,
340 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
344 case PROP_VISIBLE_HORIZONTAL:
345 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
347 case PROP_VISIBLE_VERTICAL:
348 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
350 case PROP_IS_IMPORTANT:
351 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
353 case PROP_ACTIVATABLE_RELATED_ACTION:
354 gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
356 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
357 gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
360 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
366 gtk_tool_item_get_property (GObject *object,
371 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
375 case PROP_VISIBLE_HORIZONTAL:
376 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
378 case PROP_VISIBLE_VERTICAL:
379 g_value_set_boolean (value, toolitem->priv->visible_vertical);
381 case PROP_IS_IMPORTANT:
382 g_value_set_boolean (value, toolitem->priv->is_important);
384 case PROP_ACTIVATABLE_RELATED_ACTION:
385 g_value_set_object (value, toolitem->priv->action);
387 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
388 g_value_set_boolean (value, toolitem->priv->use_action_appearance);
391 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
397 gtk_tool_item_property_notify (GObject *object,
400 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
402 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
403 gtk_widget_set_sensitive (tool_item->priv->menu_item,
404 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
408 create_drag_window (GtkToolItem *toolitem)
410 GtkAllocation allocation;
412 GdkWindowAttr attributes;
413 gint attributes_mask;
415 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
417 widget = GTK_WIDGET (toolitem);
419 gtk_widget_get_allocation (widget, &allocation);
421 attributes.window_type = GDK_WINDOW_CHILD;
422 attributes.x = allocation.x;
423 attributes.y = allocation.y;
424 attributes.width = allocation.width;
425 attributes.height = allocation.height;
426 attributes.wclass = GDK_INPUT_ONLY;
427 attributes.event_mask = gtk_widget_get_events (widget);
428 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
430 attributes_mask = GDK_WA_X | GDK_WA_Y;
432 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
433 &attributes, attributes_mask);
434 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
438 gtk_tool_item_realize (GtkWidget *widget)
440 GtkToolItem *toolitem;
443 toolitem = GTK_TOOL_ITEM (widget);
444 gtk_widget_set_realized (widget, TRUE);
446 window = gtk_widget_get_parent_window (widget);
447 gtk_widget_set_window (widget, window);
448 g_object_ref (window);
450 if (toolitem->priv->use_drag_window)
451 create_drag_window(toolitem);
455 destroy_drag_window (GtkToolItem *toolitem)
457 if (toolitem->priv->drag_window)
459 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
460 gdk_window_destroy (toolitem->priv->drag_window);
461 toolitem->priv->drag_window = NULL;
466 gtk_tool_item_unrealize (GtkWidget *widget)
468 GtkToolItem *toolitem;
470 toolitem = GTK_TOOL_ITEM (widget);
472 destroy_drag_window (toolitem);
474 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
478 gtk_tool_item_map (GtkWidget *widget)
480 GtkToolItem *toolitem;
482 toolitem = GTK_TOOL_ITEM (widget);
483 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
484 if (toolitem->priv->drag_window)
485 gdk_window_show (toolitem->priv->drag_window);
489 gtk_tool_item_unmap (GtkWidget *widget)
491 GtkToolItem *toolitem;
493 toolitem = GTK_TOOL_ITEM (widget);
494 if (toolitem->priv->drag_window)
495 gdk_window_hide (toolitem->priv->drag_window);
496 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
500 gtk_tool_item_get_preferred_width (GtkWidget *widget,
506 *minimum = *natural = 0;
508 child = gtk_bin_get_child (GTK_BIN (widget));
509 if (child && gtk_widget_get_visible (child))
510 gtk_widget_get_preferred_width (child, minimum, natural);
514 gtk_tool_item_get_preferred_height (GtkWidget *widget,
520 *minimum = *natural = 0;
522 child = gtk_bin_get_child (GTK_BIN (widget));
523 if (child && gtk_widget_get_visible (child))
524 gtk_widget_get_preferred_height (child, minimum, natural);
528 gtk_tool_item_size_allocate (GtkWidget *widget,
529 GtkAllocation *allocation)
531 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
532 GtkAllocation child_allocation;
535 gtk_widget_set_allocation (widget, allocation);
537 if (toolitem->priv->drag_window)
538 gdk_window_move_resize (toolitem->priv->drag_window,
544 child = gtk_bin_get_child (GTK_BIN (widget));
545 if (child && gtk_widget_get_visible (child))
547 child_allocation.x = allocation->x;
548 child_allocation.y = allocation->y;
549 child_allocation.width = allocation->width;
550 child_allocation.height = allocation->height;
552 gtk_widget_size_allocate (child, &child_allocation);
557 _gtk_tool_item_create_menu_proxy (GtkToolItem *item)
559 GtkWidget *menu_item;
560 gboolean visible_overflown;
562 if (item->priv->action)
564 g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
566 if (visible_overflown)
568 menu_item = gtk_action_create_menu_item (item->priv->action);
570 g_object_ref_sink (menu_item);
571 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
572 g_object_unref (menu_item);
575 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
584 gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
586 iface->update = gtk_tool_item_update;
587 iface->sync_action_properties = gtk_tool_item_sync_action_properties;
591 gtk_tool_item_update (GtkActivatable *activatable,
593 const gchar *property_name)
595 if (strcmp (property_name, "visible") == 0)
597 if (gtk_action_is_visible (action))
598 gtk_widget_show (GTK_WIDGET (activatable));
600 gtk_widget_hide (GTK_WIDGET (activatable));
602 else if (strcmp (property_name, "sensitive") == 0)
603 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
604 else if (strcmp (property_name, "tooltip") == 0)
605 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
606 gtk_action_get_tooltip (action));
607 else if (strcmp (property_name, "visible-horizontal") == 0)
608 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
609 gtk_action_get_visible_horizontal (action));
610 else if (strcmp (property_name, "visible-vertical") == 0)
611 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
612 gtk_action_get_visible_vertical (action));
613 else if (strcmp (property_name, "is-important") == 0)
614 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
615 gtk_action_get_is_important (action));
619 gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
625 if (gtk_action_is_visible (action))
626 gtk_widget_show (GTK_WIDGET (activatable));
628 gtk_widget_hide (GTK_WIDGET (activatable));
630 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
632 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
633 gtk_action_get_tooltip (action));
634 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
635 gtk_action_get_visible_horizontal (action));
636 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
637 gtk_action_get_visible_vertical (action));
638 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
639 gtk_action_get_is_important (action));
643 gtk_tool_item_set_related_action (GtkToolItem *item,
646 if (item->priv->action == action)
649 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
651 item->priv->action = action;
655 gtk_tool_item_rebuild_menu (item);
660 gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
661 gboolean use_appearance)
663 if (item->priv->use_action_appearance != use_appearance)
665 item->priv->use_action_appearance = use_appearance;
667 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action);
675 * Creates a new #GtkToolItem
677 * Return value: the new #GtkToolItem
682 gtk_tool_item_new (void)
686 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
692 * gtk_tool_item_get_ellipsize_mode:
693 * @tool_item: a #GtkToolItem
695 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
696 * #GtkToolItem should call this function to find out how text should
699 * Return value: a #PangoEllipsizeMode indicating how text in @tool_item
700 * should be ellipsized.
705 gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
709 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
711 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
712 if (!parent || !GTK_IS_TOOL_SHELL (parent))
713 return PANGO_ELLIPSIZE_NONE;
715 return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
719 * gtk_tool_item_get_icon_size:
720 * @tool_item: a #GtkToolItem
722 * Returns the icon size used for @tool_item. Custom subclasses of
723 * #GtkToolItem should call this function to find out what size icons
726 * Return value: (type int): a #GtkIconSize indicating the icon size
727 * used for @tool_item
732 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
736 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
738 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
739 if (!parent || !GTK_IS_TOOL_SHELL (parent))
740 return GTK_ICON_SIZE_LARGE_TOOLBAR;
742 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
746 * gtk_tool_item_get_orientation:
747 * @tool_item: a #GtkToolItem
749 * Returns the orientation used for @tool_item. Custom subclasses of
750 * #GtkToolItem should call this function to find out what size icons
753 * Return value: a #GtkOrientation indicating the orientation
754 * used for @tool_item
759 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
763 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
765 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
766 if (!parent || !GTK_IS_TOOL_SHELL (parent))
767 return GTK_ORIENTATION_HORIZONTAL;
769 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
773 * gtk_tool_item_get_toolbar_style:
774 * @tool_item: a #GtkToolItem
776 * Returns the toolbar style used for @tool_item. Custom subclasses of
777 * #GtkToolItem should call this function in the handler of the
778 * GtkToolItem::toolbar_reconfigured signal to find out in what style
779 * the toolbar is displayed and change themselves accordingly
783 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
784 * both an icon and a label, stacked vertically </listitem>
785 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
786 * only icons </listitem>
787 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
788 * show text</listitem>
789 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
790 * both an icon and a label, arranged horizontally (however, note the
791 * #GtkToolButton:has_text_horizontally property that makes tool buttons not
792 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
796 * Return value: A #GtkToolbarStyle indicating the toolbar style used
802 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
806 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
808 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
809 if (!parent || !GTK_IS_TOOL_SHELL (parent))
810 return GTK_TOOLBAR_ICONS;
812 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
816 * gtk_tool_item_get_relief_style:
817 * @tool_item: a #GtkToolItem
819 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
820 * Custom subclasses of #GtkToolItem should call this function in the handler
821 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
822 * relief style of buttons.
824 * Return value: a #GtkReliefStyle indicating the relief style used
830 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
834 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
836 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
837 if (!parent || !GTK_IS_TOOL_SHELL (parent))
838 return GTK_RELIEF_NONE;
840 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
844 * gtk_tool_item_get_text_alignment:
845 * @tool_item: a #GtkToolItem:
847 * Returns the text alignment used for @tool_item. Custom subclasses of
848 * #GtkToolItem should call this function to find out how text should
851 * Return value: a #gfloat indicating the horizontal text alignment
852 * used for @tool_item
857 gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
861 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
863 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
864 if (!parent || !GTK_IS_TOOL_SHELL (parent))
867 return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
871 * gtk_tool_item_get_text_orientation:
872 * @tool_item: a #GtkToolItem
874 * Returns the text orientation used for @tool_item. Custom subclasses of
875 * #GtkToolItem should call this function to find out how text should
878 * Return value: a #GtkOrientation indicating the text orientation
879 * used for @tool_item
884 gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
888 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
890 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
891 if (!parent || !GTK_IS_TOOL_SHELL (parent))
892 return GTK_ORIENTATION_HORIZONTAL;
894 return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
898 * gtk_tool_item_get_text_size_group:
899 * @tool_item: a #GtkToolItem
901 * Returns the size group used for labels in @tool_item.
902 * Custom subclasses of #GtkToolItem should call this function
903 * and use the size group for labels.
905 * Return value: (transfer none): a #GtkSizeGroup
910 gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
914 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
916 parent = gtk_widget_get_parent (GTK_WIDGET (tool_item));
917 if (!parent || !GTK_IS_TOOL_SHELL (parent))
920 return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
924 * gtk_tool_item_set_expand:
925 * @tool_item: a #GtkToolItem
926 * @expand: Whether @tool_item is allocated extra space
928 * Sets whether @tool_item is allocated extra space when there
929 * is more room on the toolbar then needed for the items. The
930 * effect is that the item gets bigger when the toolbar gets bigger
931 * and smaller when the toolbar gets smaller.
936 gtk_tool_item_set_expand (GtkToolItem *tool_item,
939 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
941 expand = expand != FALSE;
943 if (tool_item->priv->expand != expand)
945 tool_item->priv->expand = expand;
946 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
947 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
952 * gtk_tool_item_get_expand:
953 * @tool_item: a #GtkToolItem
955 * Returns whether @tool_item is allocated extra space.
956 * See gtk_tool_item_set_expand().
958 * Return value: %TRUE if @tool_item is allocated extra space.
963 gtk_tool_item_get_expand (GtkToolItem *tool_item)
965 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
967 return tool_item->priv->expand;
971 * gtk_tool_item_set_homogeneous:
972 * @tool_item: a #GtkToolItem
973 * @homogeneous: whether @tool_item is the same size as other homogeneous items
975 * Sets whether @tool_item is to be allocated the same size as other
976 * homogeneous items. The effect is that all homogeneous items will have
977 * the same width as the widest of the items.
982 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
983 gboolean homogeneous)
985 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
987 homogeneous = homogeneous != FALSE;
989 if (tool_item->priv->homogeneous != homogeneous)
991 tool_item->priv->homogeneous = homogeneous;
992 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
993 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
998 * gtk_tool_item_get_homogeneous:
999 * @tool_item: a #GtkToolItem
1001 * Returns whether @tool_item is the same size as other homogeneous
1002 * items. See gtk_tool_item_set_homogeneous().
1004 * Return value: %TRUE if the item is the same size as other homogeneous
1010 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
1012 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1014 return tool_item->priv->homogeneous;
1018 * gtk_tool_item_get_is_important:
1019 * @tool_item: a #GtkToolItem
1021 * Returns whether @tool_item is considered important. See
1022 * gtk_tool_item_set_is_important()
1024 * Return value: %TRUE if @tool_item is considered important.
1029 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
1031 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1033 return tool_item->priv->is_important;
1037 * gtk_tool_item_set_is_important:
1038 * @tool_item: a #GtkToolItem
1039 * @is_important: whether the tool item should be considered important
1041 * Sets whether @tool_item should be considered important. The #GtkToolButton
1042 * class uses this property to determine whether to show or hide its label
1043 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1044 * only tool buttons with the "is_important" property set have labels, an
1045 * effect known as "priority text"
1050 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
1052 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1054 is_important = is_important != FALSE;
1056 if (is_important != tool_item->priv->is_important)
1058 tool_item->priv->is_important = is_important;
1060 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1062 g_object_notify (G_OBJECT (tool_item), "is-important");
1067 * gtk_tool_item_set_tooltip_text:
1068 * @tool_item: a #GtkToolItem
1069 * @text: text to be used as tooltip for @tool_item
1071 * Sets the text to be displayed as tooltip on the item.
1072 * See gtk_widget_set_tooltip_text().
1077 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1082 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1084 child = gtk_bin_get_child (GTK_BIN (tool_item));
1086 gtk_widget_set_tooltip_text (child, text);
1090 * gtk_tool_item_set_tooltip_markup:
1091 * @tool_item: a #GtkToolItem
1092 * @markup: markup text to be used as tooltip for @tool_item
1094 * Sets the markup text to be displayed as tooltip on the item.
1095 * See gtk_widget_set_tooltip_markup().
1100 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1101 const gchar *markup)
1105 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1107 child = gtk_bin_get_child (GTK_BIN (tool_item));
1109 gtk_widget_set_tooltip_markup (child, markup);
1113 * gtk_tool_item_set_use_drag_window:
1114 * @tool_item: a #GtkToolItem
1115 * @use_drag_window: Whether @tool_item has a drag window.
1117 * Sets whether @tool_item has a drag window. When %TRUE the
1118 * toolitem can be used as a drag source through gtk_drag_source_set().
1119 * When @tool_item has a drag window it will intercept all events,
1120 * even those that would otherwise be sent to a child of @tool_item.
1125 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1126 gboolean use_drag_window)
1128 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1130 use_drag_window = use_drag_window != FALSE;
1132 if (toolitem->priv->use_drag_window != use_drag_window)
1134 toolitem->priv->use_drag_window = use_drag_window;
1136 if (use_drag_window)
1138 if (!toolitem->priv->drag_window &&
1139 gtk_widget_get_realized (GTK_WIDGET (toolitem)))
1141 create_drag_window(toolitem);
1142 if (gtk_widget_get_mapped (GTK_WIDGET (toolitem)))
1143 gdk_window_show (toolitem->priv->drag_window);
1148 destroy_drag_window (toolitem);
1154 * gtk_tool_item_get_use_drag_window:
1155 * @tool_item: a #GtkToolItem
1157 * Returns whether @tool_item has a drag window. See
1158 * gtk_tool_item_set_use_drag_window().
1160 * Return value: %TRUE if @tool_item uses a drag window.
1165 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1167 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1169 return toolitem->priv->use_drag_window;
1173 * gtk_tool_item_set_visible_horizontal:
1174 * @tool_item: a #GtkToolItem
1175 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1177 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1182 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1183 gboolean visible_horizontal)
1185 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1187 visible_horizontal = visible_horizontal != FALSE;
1189 if (toolitem->priv->visible_horizontal != visible_horizontal)
1191 toolitem->priv->visible_horizontal = visible_horizontal;
1193 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1195 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1200 * gtk_tool_item_get_visible_horizontal:
1201 * @tool_item: a #GtkToolItem
1203 * Returns whether the @tool_item is visible on toolbars that are
1204 * docked horizontally.
1206 * Return value: %TRUE if @tool_item is visible on toolbars that are
1207 * docked horizontally.
1212 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1214 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1216 return toolitem->priv->visible_horizontal;
1220 * gtk_tool_item_set_visible_vertical:
1221 * @tool_item: a #GtkToolItem
1222 * @visible_vertical: whether @tool_item is visible when the toolbar
1223 * is in vertical mode
1225 * Sets whether @tool_item is visible when the toolbar is docked
1226 * vertically. Some tool items, such as text entries, are too wide to be
1227 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1228 * @tool_item will not appear on toolbars that are docked vertically.
1233 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1234 gboolean visible_vertical)
1236 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1238 visible_vertical = visible_vertical != FALSE;
1240 if (toolitem->priv->visible_vertical != visible_vertical)
1242 toolitem->priv->visible_vertical = visible_vertical;
1244 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1246 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1251 * gtk_tool_item_get_visible_vertical:
1252 * @tool_item: a #GtkToolItem
1254 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1255 * See gtk_tool_item_set_visible_vertical().
1257 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1262 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1264 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1266 return toolitem->priv->visible_vertical;
1270 * gtk_tool_item_retrieve_proxy_menu_item:
1271 * @tool_item: a #GtkToolItem
1273 * Returns the #GtkMenuItem that was last set by
1274 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1275 * that is going to appear in the overflow menu.
1277 * Return value: (transfer none): The #GtkMenuItem that is going to appear in the
1278 * overflow menu for @tool_item.
1283 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1287 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1289 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1292 return tool_item->priv->menu_item;
1296 * gtk_tool_item_get_proxy_menu_item:
1297 * @tool_item: a #GtkToolItem
1298 * @menu_item_id: a string used to identify the menu item
1300 * If @menu_item_id matches the string passed to
1301 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1303 * Custom subclasses of #GtkToolItem should use this function to
1304 * update their menu item when the #GtkToolItem changes. That the
1305 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem
1306 * will not inadvertently change a menu item that they did not create.
1308 * Return value: (transfer none): The #GtkMenuItem passed to
1309 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s
1315 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1316 const gchar *menu_item_id)
1318 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1319 g_return_val_if_fail (menu_item_id != NULL, NULL);
1321 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1322 return tool_item->priv->menu_item;
1328 * gtk_tool_item_rebuild_menu:
1329 * @tool_item: a #GtkToolItem
1331 * Calling this function signals to the toolbar that the
1332 * overflow menu item for @tool_item has changed. If the
1333 * overflow menu is visible when this function it called,
1334 * the menu will be rebuilt.
1336 * The function must be called when the tool item changes what it
1337 * will do in response to the #GtkToolItem::create-menu-proxy signal.
1342 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1347 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1349 widget = GTK_WIDGET (tool_item);
1351 parent = gtk_widget_get_parent (widget);
1352 if (GTK_IS_TOOL_SHELL (parent))
1353 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (parent));
1357 * gtk_tool_item_set_proxy_menu_item:
1358 * @tool_item: a #GtkToolItem
1359 * @menu_item_id: a string used to identify @menu_item
1360 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1362 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1363 * @menu_item_id is used to identify the caller of this function and
1364 * should also be used with gtk_tool_item_get_proxy_menu_item().
1369 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1370 const gchar *menu_item_id,
1371 GtkWidget *menu_item)
1373 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1374 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1375 g_return_if_fail (menu_item_id != NULL);
1377 g_free (tool_item->priv->menu_item_id);
1379 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1381 if (tool_item->priv->menu_item != menu_item)
1383 if (tool_item->priv->menu_item)
1384 g_object_unref (tool_item->priv->menu_item);
1388 g_object_ref_sink (menu_item);
1390 gtk_widget_set_sensitive (menu_item,
1391 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
1394 tool_item->priv->menu_item = menu_item;
1399 * gtk_tool_item_toolbar_reconfigured:
1400 * @tool_item: a #GtkToolItem
1402 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1403 * #GtkToolbar and other #GtkToolShell implementations use this function
1404 * to notify children, when some aspect of their configuration changes.
1409 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1411 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1412 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1413 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1414 * Its not possible to rename the signal, and emitting another name than
1415 * indicated by the function name would be quite confusing. That's the
1416 * price of providing stable APIs.
1418 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1420 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1422 if (tool_item->priv->drag_window)
1423 gdk_window_raise (tool_item->priv->drag_window);
1425 gtk_widget_queue_resize (GTK_WIDGET (tool_item));