3 * Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
4 * Copyright (C) 2002 James Henstridge <james@daa.com.au>
5 * Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
27 #include "gtktoolitem.h"
28 #include "gtkmarshalers.h"
29 #include "gtktoolshell.h"
30 #include "gtkseparatormenuitem.h"
31 #include "gtkactivatable.h"
34 #include "gtkprivate.h"
39 * @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
93 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
95 struct _GtkToolItemPrivate
100 guint visible_horizontal : 1;
101 guint visible_vertical : 1;
102 guint homogeneous : 1;
104 guint use_drag_window : 1;
105 guint is_important : 1;
107 GdkWindow *drag_window;
110 GtkWidget *menu_item;
113 gboolean use_action_appearance;
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_size_request (GtkWidget *widget,
135 GtkRequisition *requisition);
136 static void gtk_tool_item_size_allocate (GtkWidget *widget,
137 GtkAllocation *allocation);
139 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface);
140 static void gtk_tool_item_update (GtkActivatable *activatable,
142 const gchar *property_name);
143 static void gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
145 static void gtk_tool_item_set_related_action (GtkToolItem *item,
147 static void gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
148 gboolean use_appearance);
150 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
152 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
153 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
154 gtk_tool_item_activatable_interface_init))
157 gtk_tool_item_class_init (GtkToolItemClass *klass)
159 GObjectClass *object_class;
160 GtkWidgetClass *widget_class;
162 object_class = (GObjectClass *)klass;
163 widget_class = (GtkWidgetClass *)klass;
165 object_class->set_property = gtk_tool_item_set_property;
166 object_class->get_property = gtk_tool_item_get_property;
167 object_class->finalize = gtk_tool_item_finalize;
168 object_class->dispose = gtk_tool_item_dispose;
169 object_class->notify = gtk_tool_item_property_notify;
171 widget_class->realize = gtk_tool_item_realize;
172 widget_class->unrealize = gtk_tool_item_unrealize;
173 widget_class->map = gtk_tool_item_map;
174 widget_class->unmap = gtk_tool_item_unmap;
175 widget_class->size_request = gtk_tool_item_size_request;
176 widget_class->size_allocate = gtk_tool_item_size_allocate;
177 widget_class->parent_set = gtk_tool_item_parent_set;
179 klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
181 g_object_class_install_property (object_class,
182 PROP_VISIBLE_HORIZONTAL,
183 g_param_spec_boolean ("visible-horizontal",
184 P_("Visible when horizontal"),
185 P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
187 GTK_PARAM_READWRITE));
188 g_object_class_install_property (object_class,
189 PROP_VISIBLE_VERTICAL,
190 g_param_spec_boolean ("visible-vertical",
191 P_("Visible when vertical"),
192 P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
194 GTK_PARAM_READWRITE));
195 g_object_class_install_property (object_class,
197 g_param_spec_boolean ("is-important",
199 P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
201 GTK_PARAM_READWRITE));
203 g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
204 g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
208 * GtkToolItem::create-menu-proxy:
209 * @tool_item: the object the signal was emitted on
211 * This signal is emitted when the toolbar needs information from @tool_item
212 * about whether the item should appear in the toolbar overflow menu. In
213 * response the tool item should either
215 * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
216 * pointer and return %TRUE to indicate that the item should not appear
217 * in the overflow menu
219 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
220 * item and return %TRUE, or
222 * <listitem> return %FALSE to indicate that the signal was not
223 * handled by the item. This means that
224 * the item will not appear in the overflow menu unless a later handler
225 * installs a menu item.
229 * The toolbar may cache the result of this signal. When the tool item changes
230 * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
231 * to invalidate the cache and ensure that the toolbar rebuilds its overflow
234 * Return value: %TRUE if the signal was handled, %FALSE if not
236 toolitem_signals[CREATE_MENU_PROXY] =
237 g_signal_new (I_("create-menu-proxy"),
238 G_OBJECT_CLASS_TYPE (klass),
240 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
241 _gtk_boolean_handled_accumulator, NULL,
242 _gtk_marshal_BOOLEAN__VOID,
246 * GtkToolItem::toolbar-reconfigured:
247 * @tool_item: the object the signal was emitted on
249 * This signal is emitted when some property of the toolbar that the
250 * item is a child of changes. For custom subclasses of #GtkToolItem,
251 * the default handler of this signal use the functions
253 * <listitem>gtk_tool_shell_get_orientation()</listitem>
254 * <listitem>gtk_tool_shell_get_style()</listitem>
255 * <listitem>gtk_tool_shell_get_icon_size()</listitem>
256 * <listitem>gtk_tool_shell_get_relief_style()</listitem>
258 * to find out what the toolbar should look like and change
259 * themselves accordingly.
261 toolitem_signals[TOOLBAR_RECONFIGURED] =
262 g_signal_new (I_("toolbar-reconfigured"),
263 G_OBJECT_CLASS_TYPE (klass),
265 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
267 _gtk_marshal_VOID__VOID,
270 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
274 gtk_tool_item_init (GtkToolItem *toolitem)
276 gtk_widget_set_can_focus (GTK_WIDGET (toolitem), FALSE);
278 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
280 toolitem->priv->visible_horizontal = TRUE;
281 toolitem->priv->visible_vertical = TRUE;
282 toolitem->priv->homogeneous = FALSE;
283 toolitem->priv->expand = FALSE;
285 toolitem->priv->use_action_appearance = TRUE;
289 gtk_tool_item_finalize (GObject *object)
291 GtkToolItem *item = GTK_TOOL_ITEM (object);
293 g_free (item->priv->menu_item_id);
295 if (item->priv->menu_item)
296 g_object_unref (item->priv->menu_item);
298 G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
302 gtk_tool_item_dispose (GObject *object)
304 GtkToolItem *item = GTK_TOOL_ITEM (object);
306 if (item->priv->action)
308 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);
309 item->priv->action = NULL;
311 G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
316 gtk_tool_item_parent_set (GtkWidget *toolitem,
317 GtkWidget *prev_parent)
319 if (GTK_WIDGET (toolitem)->parent != NULL)
320 gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
324 gtk_tool_item_set_property (GObject *object,
329 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
333 case PROP_VISIBLE_HORIZONTAL:
334 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
336 case PROP_VISIBLE_VERTICAL:
337 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
339 case PROP_IS_IMPORTANT:
340 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
342 case PROP_ACTIVATABLE_RELATED_ACTION:
343 gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
345 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
346 gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
349 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
355 gtk_tool_item_get_property (GObject *object,
360 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
364 case PROP_VISIBLE_HORIZONTAL:
365 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
367 case PROP_VISIBLE_VERTICAL:
368 g_value_set_boolean (value, toolitem->priv->visible_vertical);
370 case PROP_IS_IMPORTANT:
371 g_value_set_boolean (value, toolitem->priv->is_important);
373 case PROP_ACTIVATABLE_RELATED_ACTION:
374 g_value_set_object (value, toolitem->priv->action);
376 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
377 g_value_set_boolean (value, toolitem->priv->use_action_appearance);
380 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
386 gtk_tool_item_property_notify (GObject *object,
389 GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
391 if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
392 gtk_widget_set_sensitive (tool_item->priv->menu_item,
393 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
397 create_drag_window (GtkToolItem *toolitem)
400 GdkWindowAttr attributes;
401 gint attributes_mask, border_width;
403 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
405 widget = GTK_WIDGET (toolitem);
406 border_width = GTK_CONTAINER (toolitem)->border_width;
408 attributes.window_type = GDK_WINDOW_CHILD;
409 attributes.x = widget->allocation.x + border_width;
410 attributes.y = widget->allocation.y + border_width;
411 attributes.width = widget->allocation.width - border_width * 2;
412 attributes.height = widget->allocation.height - border_width * 2;
413 attributes.wclass = GDK_INPUT_ONLY;
414 attributes.event_mask = gtk_widget_get_events (widget);
415 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
417 attributes_mask = GDK_WA_X | GDK_WA_Y;
419 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
420 &attributes, attributes_mask);
421 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
425 gtk_tool_item_realize (GtkWidget *widget)
427 GtkToolItem *toolitem;
429 toolitem = GTK_TOOL_ITEM (widget);
430 gtk_widget_set_realized (widget, TRUE);
432 widget->window = gtk_widget_get_parent_window (widget);
433 g_object_ref (widget->window);
435 if (toolitem->priv->use_drag_window)
436 create_drag_window(toolitem);
438 widget->style = gtk_style_attach (widget->style, widget->window);
442 destroy_drag_window (GtkToolItem *toolitem)
444 if (toolitem->priv->drag_window)
446 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
447 gdk_window_destroy (toolitem->priv->drag_window);
448 toolitem->priv->drag_window = NULL;
453 gtk_tool_item_unrealize (GtkWidget *widget)
455 GtkToolItem *toolitem;
457 toolitem = GTK_TOOL_ITEM (widget);
459 destroy_drag_window (toolitem);
461 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
465 gtk_tool_item_map (GtkWidget *widget)
467 GtkToolItem *toolitem;
469 toolitem = GTK_TOOL_ITEM (widget);
470 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
471 if (toolitem->priv->drag_window)
472 gdk_window_show (toolitem->priv->drag_window);
476 gtk_tool_item_unmap (GtkWidget *widget)
478 GtkToolItem *toolitem;
480 toolitem = GTK_TOOL_ITEM (widget);
481 if (toolitem->priv->drag_window)
482 gdk_window_hide (toolitem->priv->drag_window);
483 GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
487 gtk_tool_item_size_request (GtkWidget *widget,
488 GtkRequisition *requisition)
490 GtkWidget *child = GTK_BIN (widget)->child;
492 if (child && gtk_widget_get_visible (child))
494 gtk_widget_size_request (child, requisition);
498 requisition->height = 0;
499 requisition->width = 0;
502 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
503 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
507 gtk_tool_item_size_allocate (GtkWidget *widget,
508 GtkAllocation *allocation)
510 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
511 GtkAllocation child_allocation;
513 GtkWidget *child = GTK_BIN (widget)->child;
515 widget->allocation = *allocation;
516 border_width = GTK_CONTAINER (widget)->border_width;
518 if (toolitem->priv->drag_window)
519 gdk_window_move_resize (toolitem->priv->drag_window,
520 widget->allocation.x + border_width,
521 widget->allocation.y + border_width,
522 widget->allocation.width - border_width * 2,
523 widget->allocation.height - border_width * 2);
525 if (child && gtk_widget_get_visible (child))
527 child_allocation.x = allocation->x + border_width;
528 child_allocation.y = allocation->y + border_width;
529 child_allocation.width = allocation->width - 2 * border_width;
530 child_allocation.height = allocation->height - 2 * border_width;
532 gtk_widget_size_allocate (child, &child_allocation);
537 _gtk_tool_item_create_menu_proxy (GtkToolItem *item)
539 GtkWidget *menu_item;
540 gboolean visible_overflown;
542 if (item->priv->action)
544 g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
546 if (visible_overflown)
548 menu_item = gtk_action_create_menu_item (item->priv->action);
550 g_object_ref_sink (menu_item);
551 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
552 g_object_unref (menu_item);
555 gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
564 gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
566 iface->update = gtk_tool_item_update;
567 iface->sync_action_properties = gtk_tool_item_sync_action_properties;
571 gtk_tool_item_update (GtkActivatable *activatable,
573 const gchar *property_name)
575 if (strcmp (property_name, "visible") == 0)
577 if (gtk_action_is_visible (action))
578 gtk_widget_show (GTK_WIDGET (activatable));
580 gtk_widget_hide (GTK_WIDGET (activatable));
582 else if (strcmp (property_name, "sensitive") == 0)
583 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
584 else if (strcmp (property_name, "tooltip") == 0)
585 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
586 gtk_action_get_tooltip (action));
587 else if (strcmp (property_name, "visible-horizontal") == 0)
588 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
589 gtk_action_get_visible_horizontal (action));
590 else if (strcmp (property_name, "visible-vertical") == 0)
591 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
592 gtk_action_get_visible_vertical (action));
593 else if (strcmp (property_name, "is-important") == 0)
594 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
595 gtk_action_get_is_important (action));
599 gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
605 if (gtk_action_is_visible (action))
606 gtk_widget_show (GTK_WIDGET (activatable));
608 gtk_widget_hide (GTK_WIDGET (activatable));
610 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
612 gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
613 gtk_action_get_tooltip (action));
614 gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
615 gtk_action_get_visible_horizontal (action));
616 gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
617 gtk_action_get_visible_vertical (action));
618 gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
619 gtk_action_get_is_important (action));
623 gtk_tool_item_set_related_action (GtkToolItem *item,
626 if (item->priv->action == action)
629 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
631 item->priv->action = action;
635 gtk_tool_item_rebuild_menu (item);
640 gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
641 gboolean use_appearance)
643 if (item->priv->use_action_appearance != use_appearance)
645 item->priv->use_action_appearance = use_appearance;
647 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action);
655 * Creates a new #GtkToolItem
657 * Return value: the new #GtkToolItem
662 gtk_tool_item_new (void)
666 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
672 * gtk_tool_item_get_ellipsize_mode:
673 * @tool_item: a #GtkToolItem
675 * Returns the ellipsize mode used for @tool_item. Custom subclasses of
676 * #GtkToolItem should call this function to find out how text should
679 * Return value: a #PangoEllipsizeMode indicating how text in @tool_item
680 * should be ellipsized.
685 gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
689 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
691 parent = GTK_WIDGET (tool_item)->parent;
692 if (!parent || !GTK_IS_TOOL_SHELL (parent))
693 return PANGO_ELLIPSIZE_NONE;
695 return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
699 * gtk_tool_item_get_icon_size:
700 * @tool_item: a #GtkToolItem
702 * Returns the icon size used for @tool_item. Custom subclasses of
703 * #GtkToolItem should call this function to find out what size icons
706 * Return value: (type int): a #GtkIconSize indicating the icon size
707 * used for @tool_item
712 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
716 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
718 parent = GTK_WIDGET (tool_item)->parent;
719 if (!parent || !GTK_IS_TOOL_SHELL (parent))
720 return GTK_ICON_SIZE_LARGE_TOOLBAR;
722 return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
726 * gtk_tool_item_get_orientation:
727 * @tool_item: a #GtkToolItem
729 * Returns the orientation used for @tool_item. Custom subclasses of
730 * #GtkToolItem should call this function to find out what size icons
733 * Return value: a #GtkOrientation indicating the orientation
734 * used for @tool_item
739 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
743 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
745 parent = GTK_WIDGET (tool_item)->parent;
746 if (!parent || !GTK_IS_TOOL_SHELL (parent))
747 return GTK_ORIENTATION_HORIZONTAL;
749 return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
753 * gtk_tool_item_get_toolbar_style:
754 * @tool_item: a #GtkToolItem
756 * Returns the toolbar style used for @tool_item. Custom subclasses of
757 * #GtkToolItem should call this function in the handler of the
758 * GtkToolItem::toolbar_reconfigured signal to find out in what style
759 * the toolbar is displayed and change themselves accordingly
763 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
764 * both an icon and a label, stacked vertically </listitem>
765 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
766 * only icons </listitem>
767 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
768 * show text</listitem>
769 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
770 * both an icon and a label, arranged horizontally (however, note the
771 * #GtkToolButton::has_text_horizontally that makes tool buttons not
772 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
776 * Return value: A #GtkToolbarStyle indicating the toolbar style used
782 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
786 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
788 parent = GTK_WIDGET (tool_item)->parent;
789 if (!parent || !GTK_IS_TOOL_SHELL (parent))
790 return GTK_TOOLBAR_ICONS;
792 return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
796 * gtk_tool_item_get_relief_style:
797 * @tool_item: a #GtkToolItem
799 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
800 * Custom subclasses of #GtkToolItem should call this function in the handler
801 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
802 * relief style of buttons.
804 * Return value: a #GtkReliefStyle indicating the relief style used
810 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
814 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
816 parent = GTK_WIDGET (tool_item)->parent;
817 if (!parent || !GTK_IS_TOOL_SHELL (parent))
818 return GTK_RELIEF_NONE;
820 return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
824 * gtk_tool_item_get_text_alignment:
825 * @tool_item: a #GtkToolItem:
827 * Returns the text alignment used for @tool_item. Custom subclasses of
828 * #GtkToolItem should call this function to find out how text should
831 * Return value: a #gfloat indicating the horizontal text alignment
832 * used for @tool_item
837 gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
841 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
843 parent = GTK_WIDGET (tool_item)->parent;
844 if (!parent || !GTK_IS_TOOL_SHELL (parent))
847 return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
851 * gtk_tool_item_get_text_orientation:
852 * @tool_item: a #GtkToolItem
854 * Returns the text orientation used for @tool_item. Custom subclasses of
855 * #GtkToolItem should call this function to find out how text should
858 * Return value: a #GtkOrientation indicating the text orientation
859 * used for @tool_item
864 gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
868 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
870 parent = GTK_WIDGET (tool_item)->parent;
871 if (!parent || !GTK_IS_TOOL_SHELL (parent))
872 return GTK_ORIENTATION_HORIZONTAL;
874 return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
878 * gtk_tool_item_get_text_size_group:
879 * @tool_item: a #GtkToolItem
881 * Returns the size group used for labels in @tool_item. Custom subclasses of
882 * #GtkToolItem should call this function and use the size group for labels.
884 * Return value: a #GtkSizeGroup
889 gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
893 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
895 parent = GTK_WIDGET (tool_item)->parent;
896 if (!parent || !GTK_IS_TOOL_SHELL (parent))
899 return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
903 * gtk_tool_item_set_expand:
904 * @tool_item: a #GtkToolItem
905 * @expand: Whether @tool_item is allocated extra space
907 * Sets whether @tool_item is allocated extra space when there
908 * is more room on the toolbar then needed for the items. The
909 * effect is that the item gets bigger when the toolbar gets bigger
910 * and smaller when the toolbar gets smaller.
915 gtk_tool_item_set_expand (GtkToolItem *tool_item,
918 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
920 expand = expand != FALSE;
922 if (tool_item->priv->expand != expand)
924 tool_item->priv->expand = expand;
925 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
926 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
931 * gtk_tool_item_get_expand:
932 * @tool_item: a #GtkToolItem
934 * Returns whether @tool_item is allocated extra space.
935 * See gtk_tool_item_set_expand().
937 * Return value: %TRUE if @tool_item is allocated extra space.
942 gtk_tool_item_get_expand (GtkToolItem *tool_item)
944 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
946 return tool_item->priv->expand;
950 * gtk_tool_item_set_homogeneous:
951 * @tool_item: a #GtkToolItem
952 * @homogeneous: whether @tool_item is the same size as other homogeneous items
954 * Sets whether @tool_item is to be allocated the same size as other
955 * homogeneous items. The effect is that all homogeneous items will have
956 * the same width as the widest of the items.
961 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
962 gboolean homogeneous)
964 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
966 homogeneous = homogeneous != FALSE;
968 if (tool_item->priv->homogeneous != homogeneous)
970 tool_item->priv->homogeneous = homogeneous;
971 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
972 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
977 * gtk_tool_item_get_homogeneous:
978 * @tool_item: a #GtkToolItem
980 * Returns whether @tool_item is the same size as other homogeneous
981 * items. See gtk_tool_item_set_homogeneous().
983 * Return value: %TRUE if the item is the same size as other homogeneous
989 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
991 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
993 return tool_item->priv->homogeneous;
997 * gtk_tool_item_get_is_important:
998 * @tool_item: a #GtkToolItem
1000 * Returns whether @tool_item is considered important. See
1001 * gtk_tool_item_set_is_important()
1003 * Return value: %TRUE if @tool_item is considered important.
1008 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
1010 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1012 return tool_item->priv->is_important;
1016 * gtk_tool_item_set_is_important:
1017 * @tool_item: a #GtkToolItem
1018 * @is_important: whether the tool item should be considered important
1020 * Sets whether @tool_item should be considered important. The #GtkToolButton
1021 * class uses this property to determine whether to show or hide its label
1022 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1023 * only tool buttons with the "is_important" property set have labels, an
1024 * effect known as "priority text"
1029 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
1031 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1033 is_important = is_important != FALSE;
1035 if (is_important != tool_item->priv->is_important)
1037 tool_item->priv->is_important = is_important;
1039 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1041 g_object_notify (G_OBJECT (tool_item), "is-important");
1046 * gtk_tool_item_set_tooltip_text:
1047 * @tool_item: a #GtkToolItem
1048 * @text: text to be used as tooltip for @tool_item
1050 * Sets the text to be displayed as tooltip on the item.
1051 * See gtk_widget_set_tooltip_text().
1056 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1061 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1063 child = GTK_BIN (tool_item)->child;
1066 gtk_widget_set_tooltip_text (child, text);
1070 * gtk_tool_item_set_tooltip_markup:
1071 * @tool_item: a #GtkToolItem
1072 * @markup: markup text to be used as tooltip for @tool_item
1074 * Sets the markup text to be displayed as tooltip on the item.
1075 * See gtk_widget_set_tooltip_markup().
1080 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1081 const gchar *markup)
1085 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1087 child = GTK_BIN (tool_item)->child;
1090 gtk_widget_set_tooltip_markup (child, markup);
1094 * gtk_tool_item_set_use_drag_window:
1095 * @tool_item: a #GtkToolItem
1096 * @use_drag_window: Whether @tool_item has a drag window.
1098 * Sets whether @tool_item has a drag window. When %TRUE the
1099 * toolitem can be used as a drag source through gtk_drag_source_set().
1100 * When @tool_item has a drag window it will intercept all events,
1101 * even those that would otherwise be sent to a child of @tool_item.
1106 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1107 gboolean use_drag_window)
1109 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1111 use_drag_window = use_drag_window != FALSE;
1113 if (toolitem->priv->use_drag_window != use_drag_window)
1115 toolitem->priv->use_drag_window = use_drag_window;
1117 if (use_drag_window)
1119 if (!toolitem->priv->drag_window &&
1120 gtk_widget_get_realized (GTK_WIDGET (toolitem)))
1122 create_drag_window(toolitem);
1123 if (gtk_widget_get_mapped (GTK_WIDGET (toolitem)))
1124 gdk_window_show (toolitem->priv->drag_window);
1129 destroy_drag_window (toolitem);
1135 * gtk_tool_item_get_use_drag_window:
1136 * @tool_item: a #GtkToolItem
1138 * Returns whether @tool_item has a drag window. See
1139 * gtk_tool_item_set_use_drag_window().
1141 * Return value: %TRUE if @tool_item uses a drag window.
1146 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1148 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1150 return toolitem->priv->use_drag_window;
1154 * gtk_tool_item_set_visible_horizontal:
1155 * @tool_item: a #GtkToolItem
1156 * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1158 * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1163 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1164 gboolean visible_horizontal)
1166 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1168 visible_horizontal = visible_horizontal != FALSE;
1170 if (toolitem->priv->visible_horizontal != visible_horizontal)
1172 toolitem->priv->visible_horizontal = visible_horizontal;
1174 g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1176 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1181 * gtk_tool_item_get_visible_horizontal:
1182 * @tool_item: a #GtkToolItem
1184 * Returns whether the @tool_item is visible on toolbars that are
1185 * docked horizontally.
1187 * Return value: %TRUE if @tool_item is visible on toolbars that are
1188 * docked horizontally.
1193 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1195 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1197 return toolitem->priv->visible_horizontal;
1201 * gtk_tool_item_set_visible_vertical:
1202 * @tool_item: a #GtkToolItem
1203 * @visible_vertical: whether @tool_item is visible when the toolbar
1204 * is in vertical mode
1206 * Sets whether @tool_item is visible when the toolbar is docked
1207 * vertically. Some tool items, such as text entries, are too wide to be
1208 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1209 * @tool_item will not appear on toolbars that are docked vertically.
1214 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1215 gboolean visible_vertical)
1217 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1219 visible_vertical = visible_vertical != FALSE;
1221 if (toolitem->priv->visible_vertical != visible_vertical)
1223 toolitem->priv->visible_vertical = visible_vertical;
1225 g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1227 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1232 * gtk_tool_item_get_visible_vertical:
1233 * @tool_item: a #GtkToolItem
1235 * Returns whether @tool_item is visible when the toolbar is docked vertically.
1236 * See gtk_tool_item_set_visible_vertical().
1238 * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1243 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1245 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1247 return toolitem->priv->visible_vertical;
1251 * gtk_tool_item_retrieve_proxy_menu_item:
1252 * @tool_item: a #GtkToolItem
1254 * Returns the #GtkMenuItem that was last set by
1255 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1256 * that is going to appear in the overflow menu.
1258 * Return value: (transfer none): The #GtkMenuItem that is going to appear in the
1259 * overflow menu for @tool_item.
1264 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1268 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1270 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1273 return tool_item->priv->menu_item;
1277 * gtk_tool_item_get_proxy_menu_item:
1278 * @tool_item: a #GtkToolItem
1279 * @menu_item_id: a string used to identify the menu item
1281 * If @menu_item_id matches the string passed to
1282 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1284 * Custom subclasses of #GtkToolItem should use this function to update
1285 * their menu item when the #GtkToolItem changes. That the
1286 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1287 * inadvertently change a menu item that they did not create.
1289 * Return value: The #GtkMenuItem passed to
1290 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1295 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1296 const gchar *menu_item_id)
1298 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1299 g_return_val_if_fail (menu_item_id != NULL, NULL);
1301 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1302 return tool_item->priv->menu_item;
1308 * gtk_tool_item_rebuild_menu:
1309 * @tool_item: a #GtkToolItem
1311 * Calling this function signals to the toolbar that the
1312 * overflow menu item for @tool_item has changed. If the
1313 * overflow menu is visible when this function it called,
1314 * the menu will be rebuilt.
1316 * The function must be called when the tool item changes what it
1317 * will do in response to the #GtkToolItem::create-menu-proxy signal.
1322 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1326 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1328 widget = GTK_WIDGET (tool_item);
1330 if (GTK_IS_TOOL_SHELL (widget->parent))
1331 gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent));
1335 * gtk_tool_item_set_proxy_menu_item:
1336 * @tool_item: a #GtkToolItem
1337 * @menu_item_id: a string used to identify @menu_item
1338 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1340 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1341 * @menu_item_id is used to identify the caller of this function and
1342 * should also be used with gtk_tool_item_get_proxy_menu_item().
1347 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1348 const gchar *menu_item_id,
1349 GtkWidget *menu_item)
1351 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1352 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1353 g_return_if_fail (menu_item_id != NULL);
1355 g_free (tool_item->priv->menu_item_id);
1357 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1359 if (tool_item->priv->menu_item != menu_item)
1361 if (tool_item->priv->menu_item)
1362 g_object_unref (tool_item->priv->menu_item);
1366 g_object_ref_sink (menu_item);
1368 gtk_widget_set_sensitive (menu_item,
1369 gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
1372 tool_item->priv->menu_item = menu_item;
1377 * gtk_tool_item_toolbar_reconfigured:
1378 * @tool_item: a #GtkToolItem
1380 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1381 * #GtkToolbar and other #GtkToolShell implementations use this function
1382 * to notify children, when some aspect of their configuration changes.
1387 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1389 /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1390 * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1391 * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1392 * Its not possible to rename the signal, and emitting another name than
1393 * indicated by the function name would be quite confusing. That's the
1394 * price of providing stable APIs.
1396 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1398 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1400 if (tool_item->priv->drag_window)
1401 gdk_window_raise (tool_item->priv->drag_window);
1403 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1406 #define __GTK_TOOL_ITEM_C__
1407 #include "gtkaliasdef.c"