3 * Copyright (C) 2002 Anders Carlsson <andersca@codefactory.se>
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.
23 #include "gtktoolitem.h"
24 #include "gtkmarshalers.h"
25 #include "gtktoolbar.h"
26 #include "gtkseparatormenuitem.h"
41 PROP_VISIBLE_HORIZONTAL,
42 PROP_VISIBLE_VERTICAL,
46 #define GTK_TOOL_ITEM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
48 struct _GtkToolItemPrivate
53 guint visible_horizontal : 1;
54 guint visible_vertical : 1;
55 guint homogeneous : 1;
58 guint use_drag_window : 1;
59 guint is_important : 1;
61 GdkWindow *drag_window;
67 static void gtk_tool_item_init (GtkToolItem *toolitem);
68 static void gtk_tool_item_class_init (GtkToolItemClass *class);
69 static void gtk_tool_item_finalize (GObject *object);
70 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
72 static void gtk_tool_item_set_property (GObject *object,
76 static void gtk_tool_item_get_property (GObject *object,
80 static void gtk_tool_item_realize (GtkWidget *widget);
81 static void gtk_tool_item_unrealize (GtkWidget *widget);
82 static void gtk_tool_item_map (GtkWidget *widget);
83 static void gtk_tool_item_unmap (GtkWidget *widget);
84 static void gtk_tool_item_size_request (GtkWidget *widget,
85 GtkRequisition *requisition);
86 static void gtk_tool_item_size_allocate (GtkWidget *widget,
87 GtkAllocation *allocation);
88 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
89 GtkTooltips *tooltips,
90 const gchar *tip_text,
91 const gchar *tip_private);
93 static gboolean gtk_tool_item_create_menu_proxy (GtkToolItem *item);
96 static GObjectClass *parent_class = NULL;
97 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
100 gtk_tool_item_get_type (void)
102 static GtkType type = 0;
106 static const GTypeInfo type_info =
108 sizeof (GtkToolItemClass),
109 (GBaseInitFunc) NULL,
110 (GBaseFinalizeFunc) NULL,
111 (GClassInitFunc) gtk_tool_item_class_init,
112 (GClassFinalizeFunc) NULL,
115 sizeof (GtkToolItem),
117 (GInstanceInitFunc) gtk_tool_item_init,
120 type = g_type_register_static (GTK_TYPE_BIN,
128 gtk_tool_item_class_init (GtkToolItemClass *klass)
130 GObjectClass *object_class;
131 GtkWidgetClass *widget_class;
133 parent_class = g_type_class_peek_parent (klass);
134 object_class = (GObjectClass *)klass;
135 widget_class = (GtkWidgetClass *)klass;
137 object_class->set_property = gtk_tool_item_set_property;
138 object_class->get_property = gtk_tool_item_get_property;
139 object_class->finalize = gtk_tool_item_finalize;
141 widget_class->realize = gtk_tool_item_realize;
142 widget_class->unrealize = gtk_tool_item_unrealize;
143 widget_class->map = gtk_tool_item_map;
144 widget_class->unmap = gtk_tool_item_unmap;
145 widget_class->size_request = gtk_tool_item_size_request;
146 widget_class->size_allocate = gtk_tool_item_size_allocate;
147 widget_class->parent_set = gtk_tool_item_parent_set;
149 klass->create_menu_proxy = gtk_tool_item_create_menu_proxy;
150 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
152 g_object_class_install_property (object_class,
153 PROP_VISIBLE_HORIZONTAL,
154 g_param_spec_boolean ("visible_horizontal",
155 _("Visible when horizontal"),
156 _("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
159 g_object_class_install_property (object_class,
160 PROP_VISIBLE_VERTICAL,
161 g_param_spec_boolean ("visible_vertical",
162 _("Visible when vertical"),
163 _("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
166 g_object_class_install_property (object_class,
168 g_param_spec_boolean ("is_important",
170 _("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
175 * GtkToolItem::create-menu-proxy:
176 * @toolitem: the object the signal was emitted on
178 * This signal is emitted when the toolbar is displaying an overflow menu.
179 * In response the tool item should either
181 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a %NULL
182 * pointer and return %TRUE to indicate that the item should not appear
183 * in the overflow menu
185 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
186 * item and return %TRUE, or
188 * <listitem> return %FALSE to indicate that the signal was not
189 * handled by the item. This means that
190 * the item will not appear in the overflow menu unless a later handler
191 * installs a menu item.
195 * Return value: %TRUE if the signal was handled, %FALSE if not
197 toolitem_signals[CREATE_MENU_PROXY] =
198 g_signal_new ("create_menu_proxy",
199 G_OBJECT_CLASS_TYPE (klass),
201 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
202 _gtk_boolean_handled_accumulator, NULL,
203 _gtk_marshal_BOOLEAN__VOID,
207 * GtkToolItem::toolbar-reconfigured:
208 * @toolitem: the object the signal was emitted on
210 * This signal is emitted when some property of the toolbar that the
211 * item is a child of changes. For custom subclasses of #GtkToolItem,
212 * the default handler of this signal use the functions
214 * <listitem>gtk_toolbar_get_orientation()</listitem>
215 * <listitem>gtk_toolbar_get_style()</listitem>
216 * <listitem>gtk_toolbar_get_icon_size()</listitem>
217 * <listitem>gtk_toolbar_get_relief_style()</listitem>
219 * to find out what the toolbar should look like and change
220 * themselves accordingly.
222 toolitem_signals[TOOLBAR_RECONFIGURED] =
223 g_signal_new ("toolbar_reconfigured",
224 G_OBJECT_CLASS_TYPE (klass),
226 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
228 _gtk_marshal_VOID__VOID,
231 * GtkToolItem::set-tooltip:
232 * @toolitem: the object the signal was emitted on
233 * @tooltips: the #GtkTooltips
234 * @tip_text: the tooltip text
235 * @tip_private: the tooltip private text
237 * This signal is emitted when the toolitem's tooltip changes.
238 * Application developers can use gtk_tool_item_set_tooltip() to
239 * set the item's tooltip.
241 * Return value: %TRUE if the signal was handled, %FALSE if not
243 toolitem_signals[SET_TOOLTIP] =
244 g_signal_new ("set_tooltip",
245 G_OBJECT_CLASS_TYPE (klass),
247 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
248 _gtk_boolean_handled_accumulator, NULL,
249 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
255 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
259 gtk_tool_item_init (GtkToolItem *toolitem)
261 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
263 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
265 toolitem->priv->visible_horizontal = TRUE;
266 toolitem->priv->visible_vertical = TRUE;
267 toolitem->priv->homogeneous = FALSE;
268 toolitem->priv->expand = FALSE;
272 gtk_tool_item_finalize (GObject *object)
274 GtkToolItem *item = GTK_TOOL_ITEM (object);
276 if (item->priv->menu_item)
277 g_object_unref (item->priv->menu_item);
279 if (G_OBJECT_CLASS (parent_class)->finalize)
280 G_OBJECT_CLASS (parent_class)->finalize (object);
284 gtk_tool_item_parent_set (GtkWidget *toolitem,
285 GtkWidget *prev_parent)
287 _gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
291 gtk_tool_item_set_property (GObject *object,
296 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
300 case PROP_VISIBLE_HORIZONTAL:
301 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
303 case PROP_VISIBLE_VERTICAL:
304 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
306 case PROP_IS_IMPORTANT:
307 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
310 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
315 gtk_tool_item_get_property (GObject *object,
320 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
324 case PROP_VISIBLE_HORIZONTAL:
325 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
327 case PROP_VISIBLE_VERTICAL:
328 g_value_set_boolean (value, toolitem->priv->visible_vertical);
330 case PROP_IS_IMPORTANT:
331 g_value_set_boolean (value, toolitem->priv->is_important);
334 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
339 create_drag_window (GtkToolItem *toolitem)
342 GdkWindowAttr attributes;
343 gint attributes_mask, border_width;
345 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
347 widget = GTK_WIDGET (toolitem);
348 border_width = GTK_CONTAINER (toolitem)->border_width;
350 attributes.window_type = GDK_WINDOW_CHILD;
351 attributes.x = widget->allocation.x + border_width;
352 attributes.y = widget->allocation.y + border_width;
353 attributes.width = widget->allocation.width - border_width * 2;
354 attributes.height = widget->allocation.height - border_width * 2;
355 attributes.wclass = GDK_INPUT_ONLY;
356 attributes.event_mask = gtk_widget_get_events (widget);
357 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
359 attributes_mask = GDK_WA_X | GDK_WA_Y;
361 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
362 &attributes, attributes_mask);
363 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
367 gtk_tool_item_realize (GtkWidget *widget)
369 GtkToolItem *toolitem;
371 toolitem = GTK_TOOL_ITEM (widget);
372 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
374 widget->window = gtk_widget_get_parent_window (widget);
375 g_object_ref (widget->window);
377 if (toolitem->priv->use_drag_window)
378 create_drag_window(toolitem);
380 widget->style = gtk_style_attach (widget->style, widget->window);
384 destroy_drag_window (GtkToolItem *toolitem)
386 if (toolitem->priv->drag_window)
388 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
389 gdk_window_destroy (toolitem->priv->drag_window);
390 toolitem->priv->drag_window = NULL;
395 gtk_tool_item_unrealize (GtkWidget *widget)
397 GtkToolItem *toolitem;
399 toolitem = GTK_TOOL_ITEM (widget);
401 destroy_drag_window (toolitem);
403 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
407 gtk_tool_item_map (GtkWidget *widget)
409 GtkToolItem *toolitem;
411 toolitem = GTK_TOOL_ITEM (widget);
412 GTK_WIDGET_CLASS (parent_class)->map (widget);
413 if (toolitem->priv->drag_window)
414 gdk_window_show (toolitem->priv->drag_window);
418 gtk_tool_item_unmap (GtkWidget *widget)
420 GtkToolItem *toolitem;
422 toolitem = GTK_TOOL_ITEM (widget);
423 if (toolitem->priv->drag_window)
424 gdk_window_hide (toolitem->priv->drag_window);
425 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
429 gtk_tool_item_size_request (GtkWidget *widget,
430 GtkRequisition *requisition)
432 GtkWidget *child = GTK_BIN (widget)->child;
434 if (child && GTK_WIDGET_VISIBLE (child))
436 gtk_widget_size_request (child, requisition);
440 requisition->height = 0;
441 requisition->width = 0;
444 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
445 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
449 gtk_tool_item_size_allocate (GtkWidget *widget,
450 GtkAllocation *allocation)
452 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
453 GtkAllocation child_allocation;
455 GtkWidget *child = GTK_BIN (widget)->child;
457 widget->allocation = *allocation;
458 border_width = GTK_CONTAINER (widget)->border_width;
460 if (toolitem->priv->drag_window)
461 gdk_window_move_resize (toolitem->priv->drag_window,
462 widget->allocation.x + border_width,
463 widget->allocation.y + border_width,
464 widget->allocation.width - border_width * 2,
465 widget->allocation.height - border_width * 2);
467 if (child && GTK_WIDGET_VISIBLE (child))
469 child_allocation.x = allocation->x + border_width;
470 child_allocation.y = allocation->y + border_width;
471 child_allocation.width = allocation->width - 2 * border_width;
472 child_allocation.height = allocation->height - 2 * border_width;
474 gtk_widget_size_allocate (child, &child_allocation);
479 gtk_tool_item_create_menu_proxy (GtkToolItem *item)
487 * Creates a new #GtkToolItem
489 * Return value: the new #GtkToolItem
494 gtk_tool_item_new (void)
498 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
504 * gtk_tool_item_get_icon_size:
505 * @tool_item: a #GtkToolItem:
507 * Returns the icon size used for @tool_item. Custom subclasses of
508 * #GtkToolItem should call this function to find out what size icons
511 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
516 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
520 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
522 parent = GTK_WIDGET (tool_item)->parent;
523 if (!parent || !GTK_IS_TOOLBAR (parent))
524 return GTK_ICON_SIZE_LARGE_TOOLBAR;
526 return gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent));
530 * gtk_tool_item_get_orientation:
531 * @tool_item: a #GtkToolItem:
533 * Returns the orientation used for @tool_item. Custom subclasses of
534 * #GtkToolItem should call this function to find out what size icons
537 * Return value: a #GtkOrientation indicating the orientation
538 * used for @tool_item
543 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
547 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
549 parent = GTK_WIDGET (tool_item)->parent;
550 if (!parent || !GTK_IS_TOOLBAR (parent))
551 return GTK_ORIENTATION_HORIZONTAL;
553 return gtk_toolbar_get_orientation (GTK_TOOLBAR (parent));
557 * gtk_tool_item_get_toolbar_style:
558 * @tool_item: a #GtkToolItem:
560 * Returns the toolbar style used for @tool_item. Custom subclasses of
561 * #GtkToolItem should call this function in the handler of the
562 * GtkToolItem::toolbar_reconfigured signal to find out in what style
563 * the toolbar is displayed and change themselves accordingly
567 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
568 * both an icon and a label, stacked vertically </listitem>
569 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
570 * only icons </listitem>
571 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
572 * show text</listitem>
573 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
574 * both an icon and a label, arranged horizontally (however, note the
575 * #GtkToolButton::has_text_horizontally that makes tool buttons not
576 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
580 * Return value: A #GtkToolbarStyle indicating the toolbar style used
586 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
590 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
592 parent = GTK_WIDGET (tool_item)->parent;
593 if (!parent || !GTK_IS_TOOLBAR (parent))
594 return GTK_TOOLBAR_ICONS;
596 return gtk_toolbar_get_style (GTK_TOOLBAR (parent));
600 * gtk_tool_item_get_relief_style:
601 * @tool_item: a #GtkToolItem:
603 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
604 * Custom subclasses of #GtkToolItem should call this function in the handler
605 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
606 * relief style of buttons.
608 * Return value: a #GtkReliefStyle indicating the relief style used
614 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
618 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
620 parent = GTK_WIDGET (tool_item)->parent;
621 if (!parent || !GTK_IS_TOOLBAR (parent))
622 return GTK_RELIEF_NONE;
624 return gtk_toolbar_get_relief_style (GTK_TOOLBAR (parent));
628 * gtk_tool_item_set_expand:
629 * @tool_item: a #GtkToolItem:
630 * @expand: Whether @tool_item is allocated extra space
632 * Sets whether @tool_item is allocated extra space when there
633 * is more room on the toolbar then needed for the items. The
634 * effect is that the item gets bigger when the toolbar gets bigger
635 * and smaller when the toolbar gets smaller.
640 gtk_tool_item_set_expand (GtkToolItem *tool_item,
643 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
645 expand = expand != FALSE;
647 if (tool_item->priv->expand != expand)
649 tool_item->priv->expand = expand;
650 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
651 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
656 * gtk_tool_item_get_expand:
657 * @tool_item: a #GtkToolItem:
659 * Returns whether @tool_item is allocated extra space.
660 * See gtk_tool_item_set_expand().
662 * Return value: %TRUE if @tool_item is allocated extra space.
667 gtk_tool_item_get_expand (GtkToolItem *tool_item)
669 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
671 return tool_item->priv->expand;
675 * gtk_tool_item_set_pack_end:
676 * @tool_item: a #GtkToolItem:
677 * @pack_end: whether @tool_item is allocated at the end of the toolbar.
679 * Sets whether @tool_item is allocated at the end of the toolbar. This is
680 * useful for #GtkToolItem<!-- -->s that are used as "throbbers" in
681 * web-browser-type applications.
686 gtk_tool_item_set_pack_end (GtkToolItem *tool_item,
689 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
691 pack_end = pack_end != FALSE;
693 if (tool_item->priv->pack_end != pack_end)
695 tool_item->priv->pack_end = pack_end;
696 gtk_widget_child_notify (GTK_WIDGET (tool_item), "pack_end");
697 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
702 * gtk_tool_item_get_pack_end:
703 * @tool_item: a #GtkToolItem:
705 * Returns whether @tool_item is packed at the end of the toolbar.
706 * See gtk_tool_item_set_pack_end().
708 * Return value: %TRUE if @tool_item is packed at the end of the toolbar.
713 gtk_tool_item_get_pack_end (GtkToolItem *tool_item)
715 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
717 return tool_item->priv->pack_end;
721 * gtk_tool_item_set_homogeneous:
722 * @tool_item: a #GtkToolItem:
723 * @homogeneous: whether @tool_item is the same size as other homogeneous items
725 * Sets whether @tool_item is to be allocated the same size as other
726 * homogeneous items. The effect is that all homogeneous items will have
727 * the same width as the widest of the items.
732 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
733 gboolean homogeneous)
735 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
737 homogeneous = homogeneous != FALSE;
739 if (tool_item->priv->homogeneous != homogeneous)
741 tool_item->priv->homogeneous = homogeneous;
742 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
743 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
748 * gtk_tool_item_get_homogeneous:
749 * @tool_item: a #GtkToolItem:
751 * Returns whether @tool_item is the same size as other homogeneous
752 * items. See gtk_tool_item_set_homogeneous().
754 * Return value: %TRUE if the item is the same size as other homogeneous
760 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
762 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
764 return tool_item->priv->homogeneous;
768 * gtk_tool_item_get_is_important:
769 * @tool_item: a #GtkToolItem
771 * Returns whether @tool_item is considered important. See
772 * gtk_tool_item_set_is_important()
774 * Return value: %TRUE if @tool_item is considered important.
779 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
781 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
783 return tool_item->priv->is_important;
787 * gtk_tool_item_set_is_important:
788 * @tool_item: a #GtkToolItem
789 * @is_important: whether the tool item should be considered important
791 * Sets whether @tool_item should be considered important. The #GtkToolButton
792 * class uses this property to determine whether to show or hide its label
793 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
794 * only tool buttons with the "is_important" property set have labels, an
795 * effect known as "priority text"
800 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
802 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
804 is_important = is_important != FALSE;
806 if (is_important != tool_item->priv->is_important)
808 tool_item->priv->is_important = is_important;
810 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
812 g_object_notify (G_OBJECT (tool_item), "is_important");
817 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
818 GtkTooltips *tooltips,
819 const gchar *tip_text,
820 const gchar *tip_private)
822 GtkWidget *child = GTK_BIN (tool_item)->child;
827 gtk_tooltips_set_tip (tooltips, child, tip_text, tip_private);
833 * gtk_tool_item_set_tooltip:
834 * @tool_item: a #GtkToolItem:
835 * @tooltips: The #GtkTooltips object to be used
836 * @tip_text: text to be used as tooltip text for @tool_item
837 * @tip_private: text to be used as rpivate tooltip text
839 * Sets the #GtkTooltips object to be used for @tool_item, the
840 * text to be displayed as tooltip on the item and the private text
841 * to be used. See gtk_tooltips_set_tip().
846 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
847 GtkTooltips *tooltips,
848 const gchar *tip_text,
849 const gchar *tip_private)
853 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
855 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
856 tooltips, tip_text, tip_private, &retval);
860 * gtk_tool_item_set_use_drag_window:
861 * @toolitem: a #GtkToolItem
862 * @use_drag_window: Whether @toolitem has a drag window.
864 * Sets whether @toolitem has a drag window. When %TRUE the
865 * toolitem can be used as a drag source through gtk_drag_source_set().
866 * When @toolitem has a drag window it will intercept all events,
867 * even those that would otherwise be sent to a child of @toolitem.
872 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
873 gboolean use_drag_window)
875 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
877 use_drag_window = use_drag_window != FALSE;
879 if (toolitem->priv->use_drag_window != use_drag_window)
881 toolitem->priv->use_drag_window = use_drag_window;
885 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
887 create_drag_window(toolitem);
888 if (GTK_WIDGET_MAPPED (toolitem))
889 gdk_window_show (toolitem->priv->drag_window);
894 destroy_drag_window (toolitem);
900 * gtk_tool_item_get_use_drag_window:
901 * @toolitem: a #GtkToolItem
903 * Returns whether @toolitem has a drag window. See
904 * gtk_tool_item_set_use_drag_window().
906 * Return value: %TRUE if @toolitem uses a drag window.
911 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
913 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
915 return toolitem->priv->use_drag_window;
919 * gtk_tool_item_set_visible_horizontal:
920 * @toolitem: a #GtkToolItem
921 * @visible_horizontal: Whether @toolitem is visible when in horizontal mode
923 * Sets whether @toolitem is visible when the toolbar is docked horizontally.
928 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
929 gboolean visible_horizontal)
931 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
933 visible_horizontal = visible_horizontal != FALSE;
935 if (toolitem->priv->visible_horizontal != visible_horizontal)
937 toolitem->priv->visible_horizontal = visible_horizontal;
939 g_object_notify (G_OBJECT (toolitem), "visible_horizontal");
941 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
946 * gtk_tool_item_get_visible_horizontal:
947 * @toolitem: a #GtkToolItem
949 * Returns whether the @toolitem is visible on toolbars that are
950 * docked horizontally.
952 * Return value: %TRUE if @toolitem is visible on toolbars that are
953 * docked horizontally.
958 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
960 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
962 return toolitem->priv->visible_horizontal;
966 * gtk_tool_item_set_visible_vertical:
967 * @toolitem: a #GtkToolItem
968 * @visible_vertical: whether @toolitem is visible when the toolbar
969 * is in vertical mode
971 * Sets whether @toolitem is visible when the toolbar is docked
972 * vertically. Some tool items, such as text entries, are too wide to be
973 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
974 * @toolitem will not appear on toolbars that are docked vertically.
979 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
980 gboolean visible_vertical)
982 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
984 visible_vertical = visible_vertical != FALSE;
986 if (toolitem->priv->visible_vertical != visible_vertical)
988 toolitem->priv->visible_vertical = visible_vertical;
990 g_object_notify (G_OBJECT (toolitem), "visible_vertical");
992 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
997 * gtk_tool_item_get_visible_vertical:
998 * @toolitem: a #GtkToolItem
1000 * Returns whether @toolitem is visible when the toolbar is docked vertically.
1001 * See gtk_tool_item_set_visible_vertical().
1003 * Return value: Whether @toolitem is visible when the toolbar is docked vertically
1008 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1010 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1012 return toolitem->priv->visible_vertical;
1016 * gtk_tool_item_retrieve_proxy_menu_item:
1017 * @tool_item: a #GtkToolItem:
1019 * Returns the #GtkMenuItem that was last set by
1020 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1021 * that is going to appear in the overflow menu.
1023 * Return value: The #GtkMenuItem that is going to appear in the
1024 * overflow menu for @tool_item.
1029 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1033 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1035 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0, &retval);
1037 return tool_item->priv->menu_item;
1041 * gtk_tool_item_get_proxy_menu_item:
1042 * @tool_item: a #GtkToolItem:
1043 * @menu_item_id: a string used to identify the menu item
1045 * If @menu_item_id matches the string passed to
1046 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1048 * Custom subclasses of #GtkToolItem should use this function to update
1049 * their menu item when the #GtkToolItem changes. That the
1050 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1051 * inadvertently change a menu item that they did not create.
1053 * Return value: The #GtkMenuItem passed to
1054 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1059 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1060 const gchar *menu_item_id)
1062 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1063 g_return_val_if_fail (menu_item_id != NULL, NULL);
1065 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1066 return tool_item->priv->menu_item;
1072 * gtk_tool_item_set_proxy_menu_item:
1073 * @tool_item: a #GtkToolItem:
1074 * @menu_item_id: a string used to identify @menu_item
1075 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1077 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1078 * @menu_item_id is used to identify the caller of this function and
1079 * should also be used with gtk_tool_item_get_proxy_menu_item().
1084 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1085 const gchar *menu_item_id,
1086 GtkWidget *menu_item)
1088 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1089 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1090 g_return_if_fail (menu_item_id != NULL);
1092 if (tool_item->priv->menu_item_id)
1093 g_free (tool_item->priv->menu_item_id);
1095 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1097 if (tool_item->priv->menu_item != menu_item)
1099 if (tool_item->priv->menu_item)
1100 g_object_unref (G_OBJECT (tool_item->priv->menu_item));
1104 g_object_ref (menu_item);
1105 gtk_object_sink (GTK_OBJECT (menu_item));
1108 tool_item->priv->menu_item = menu_item;
1113 * _gtk_tool_item_toolbar_reconfigured:
1114 * @tool_item: a #GtkToolItem:
1116 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item. This
1117 * internal function is called by #GtkToolbar when some aspect of its
1118 * configuration changes.
1123 _gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1125 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1127 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1129 gtk_widget_queue_resize (GTK_WIDGET (tool_item));