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.
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;
57 guint use_drag_window : 1;
58 guint is_important : 1;
60 GdkWindow *drag_window;
66 static void gtk_tool_item_init (GtkToolItem *toolitem);
67 static void gtk_tool_item_class_init (GtkToolItemClass *class);
68 static void gtk_tool_item_finalize (GObject *object);
69 static void gtk_tool_item_parent_set (GtkWidget *toolitem,
71 static void gtk_tool_item_set_property (GObject *object,
75 static void gtk_tool_item_get_property (GObject *object,
79 static void gtk_tool_item_realize (GtkWidget *widget);
80 static void gtk_tool_item_unrealize (GtkWidget *widget);
81 static void gtk_tool_item_map (GtkWidget *widget);
82 static void gtk_tool_item_unmap (GtkWidget *widget);
83 static void gtk_tool_item_size_request (GtkWidget *widget,
84 GtkRequisition *requisition);
85 static void gtk_tool_item_size_allocate (GtkWidget *widget,
86 GtkAllocation *allocation);
87 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
88 GtkTooltips *tooltips,
89 const gchar *tip_text,
90 const gchar *tip_private);
92 static gboolean gtk_tool_item_create_menu_proxy (GtkToolItem *item);
95 static GObjectClass *parent_class = NULL;
96 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
99 gtk_tool_item_get_type (void)
101 static GtkType type = 0;
105 static const GTypeInfo type_info =
107 sizeof (GtkToolItemClass),
108 (GBaseInitFunc) NULL,
109 (GBaseFinalizeFunc) NULL,
110 (GClassInitFunc) gtk_tool_item_class_init,
111 (GClassFinalizeFunc) NULL,
114 sizeof (GtkToolItem),
116 (GInstanceInitFunc) gtk_tool_item_init,
119 type = g_type_register_static (GTK_TYPE_BIN,
127 gtk_tool_item_class_init (GtkToolItemClass *klass)
129 GObjectClass *object_class;
130 GtkWidgetClass *widget_class;
132 parent_class = g_type_class_peek_parent (klass);
133 object_class = (GObjectClass *)klass;
134 widget_class = (GtkWidgetClass *)klass;
136 object_class->set_property = gtk_tool_item_set_property;
137 object_class->get_property = gtk_tool_item_get_property;
138 object_class->finalize = gtk_tool_item_finalize;
140 widget_class->realize = gtk_tool_item_realize;
141 widget_class->unrealize = gtk_tool_item_unrealize;
142 widget_class->map = gtk_tool_item_map;
143 widget_class->unmap = gtk_tool_item_unmap;
144 widget_class->size_request = gtk_tool_item_size_request;
145 widget_class->size_allocate = gtk_tool_item_size_allocate;
146 widget_class->parent_set = gtk_tool_item_parent_set;
148 klass->create_menu_proxy = gtk_tool_item_create_menu_proxy;
149 klass->set_tooltip = gtk_tool_item_real_set_tooltip;
151 g_object_class_install_property (object_class,
152 PROP_VISIBLE_HORIZONTAL,
153 g_param_spec_boolean ("visible_horizontal",
154 _("Visible when horizontal"),
155 _("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
158 g_object_class_install_property (object_class,
159 PROP_VISIBLE_VERTICAL,
160 g_param_spec_boolean ("visible_vertical",
161 _("Visible when vertical"),
162 _("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
165 g_object_class_install_property (object_class,
167 g_param_spec_boolean ("is_important",
169 _("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
174 * GtkToolItem::create-menu-proxy:
175 * @toolitem: the object the signal was emitted on
177 * This signal is emitted when the toolbar is displaying an overflow menu.
178 * In response the tool item should either
180 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a %NULL
181 * pointer and return %TRUE to indicate that the item should not appear
182 * in the overflow menu
184 * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
185 * item and return %TRUE, or
187 * <listitem> return %FALSE to indicate that the signal was not
188 * handled by the item. This means that
189 * the item will not appear in the overflow menu unless a later handler
190 * installs a menu item.
194 * Return value: %TRUE if the signal was handled, %FALSE if not
196 toolitem_signals[CREATE_MENU_PROXY] =
197 g_signal_new ("create_menu_proxy",
198 G_OBJECT_CLASS_TYPE (klass),
200 G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
201 _gtk_boolean_handled_accumulator, NULL,
202 _gtk_marshal_BOOLEAN__VOID,
206 * GtkToolItem::toolbar-reconfigured:
207 * @toolitem: the object the signal was emitted on
209 * This signal is emitted when some property of the toolbar that the
210 * item is a child of changes. For custom subclasses of #GtkToolItem,
211 * the default handler of this signal use the functions
213 * <listitem>gtk_toolbar_get_orientation()</listitem>
214 * <listitem>gtk_toolbar_get_style()</listitem>
215 * <listitem>gtk_toolbar_get_icon_size()</listitem>
216 * <listitem>gtk_toolbar_get_relief_style()</listitem>
218 * to find out what the toolbar should look like and change
219 * themselves accordingly.
221 toolitem_signals[TOOLBAR_RECONFIGURED] =
222 g_signal_new ("toolbar_reconfigured",
223 G_OBJECT_CLASS_TYPE (klass),
225 G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
227 _gtk_marshal_VOID__VOID,
230 * GtkToolItem::set-tooltip:
231 * @toolitem: the object the signal was emitted on
232 * @tooltips: the #GtkTooltips
233 * @tip_text: the tooltip text
234 * @tip_private: the tooltip private text
236 * This signal is emitted when the toolitem's tooltip changes.
237 * Application developers can use gtk_tool_item_set_tooltip() to
238 * set the item's tooltip.
240 * Return value: %TRUE if the signal was handled, %FALSE if not
242 toolitem_signals[SET_TOOLTIP] =
243 g_signal_new ("set_tooltip",
244 G_OBJECT_CLASS_TYPE (klass),
246 G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
247 _gtk_boolean_handled_accumulator, NULL,
248 _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
254 g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
258 gtk_tool_item_init (GtkToolItem *toolitem)
260 GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);
262 toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
264 toolitem->priv->visible_horizontal = TRUE;
265 toolitem->priv->visible_vertical = TRUE;
266 toolitem->priv->homogeneous = FALSE;
267 toolitem->priv->expand = FALSE;
271 gtk_tool_item_finalize (GObject *object)
273 GtkToolItem *item = GTK_TOOL_ITEM (object);
275 if (item->priv->menu_item)
276 g_object_unref (item->priv->menu_item);
278 if (G_OBJECT_CLASS (parent_class)->finalize)
279 G_OBJECT_CLASS (parent_class)->finalize (object);
283 gtk_tool_item_parent_set (GtkWidget *toolitem,
284 GtkWidget *prev_parent)
286 _gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
290 gtk_tool_item_set_property (GObject *object,
295 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
299 case PROP_VISIBLE_HORIZONTAL:
300 gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
302 case PROP_VISIBLE_VERTICAL:
303 gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
305 case PROP_IS_IMPORTANT:
306 gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
309 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
314 gtk_tool_item_get_property (GObject *object,
319 GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
323 case PROP_VISIBLE_HORIZONTAL:
324 g_value_set_boolean (value, toolitem->priv->visible_horizontal);
326 case PROP_VISIBLE_VERTICAL:
327 g_value_set_boolean (value, toolitem->priv->visible_vertical);
329 case PROP_IS_IMPORTANT:
330 g_value_set_boolean (value, toolitem->priv->is_important);
333 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
338 create_drag_window (GtkToolItem *toolitem)
341 GdkWindowAttr attributes;
342 gint attributes_mask, border_width;
344 g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
346 widget = GTK_WIDGET (toolitem);
347 border_width = GTK_CONTAINER (toolitem)->border_width;
349 attributes.window_type = GDK_WINDOW_CHILD;
350 attributes.x = widget->allocation.x + border_width;
351 attributes.y = widget->allocation.y + border_width;
352 attributes.width = widget->allocation.width - border_width * 2;
353 attributes.height = widget->allocation.height - border_width * 2;
354 attributes.wclass = GDK_INPUT_ONLY;
355 attributes.event_mask = gtk_widget_get_events (widget);
356 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
358 attributes_mask = GDK_WA_X | GDK_WA_Y;
360 toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
361 &attributes, attributes_mask);
362 gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
366 gtk_tool_item_realize (GtkWidget *widget)
368 GtkToolItem *toolitem;
370 toolitem = GTK_TOOL_ITEM (widget);
371 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
373 widget->window = gtk_widget_get_parent_window (widget);
374 g_object_ref (widget->window);
376 if (toolitem->priv->use_drag_window)
377 create_drag_window(toolitem);
379 widget->style = gtk_style_attach (widget->style, widget->window);
383 destroy_drag_window (GtkToolItem *toolitem)
385 if (toolitem->priv->drag_window)
387 gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
388 gdk_window_destroy (toolitem->priv->drag_window);
389 toolitem->priv->drag_window = NULL;
394 gtk_tool_item_unrealize (GtkWidget *widget)
396 GtkToolItem *toolitem;
398 toolitem = GTK_TOOL_ITEM (widget);
400 destroy_drag_window (toolitem);
402 GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
406 gtk_tool_item_map (GtkWidget *widget)
408 GtkToolItem *toolitem;
410 toolitem = GTK_TOOL_ITEM (widget);
411 GTK_WIDGET_CLASS (parent_class)->map (widget);
412 if (toolitem->priv->drag_window)
413 gdk_window_show (toolitem->priv->drag_window);
417 gtk_tool_item_unmap (GtkWidget *widget)
419 GtkToolItem *toolitem;
421 toolitem = GTK_TOOL_ITEM (widget);
422 if (toolitem->priv->drag_window)
423 gdk_window_hide (toolitem->priv->drag_window);
424 GTK_WIDGET_CLASS (parent_class)->unmap (widget);
428 gtk_tool_item_size_request (GtkWidget *widget,
429 GtkRequisition *requisition)
431 GtkWidget *child = GTK_BIN (widget)->child;
433 if (child && GTK_WIDGET_VISIBLE (child))
435 gtk_widget_size_request (child, requisition);
439 requisition->height = 0;
440 requisition->width = 0;
443 requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
444 requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
448 gtk_tool_item_size_allocate (GtkWidget *widget,
449 GtkAllocation *allocation)
451 GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
452 GtkAllocation child_allocation;
454 GtkWidget *child = GTK_BIN (widget)->child;
456 widget->allocation = *allocation;
457 border_width = GTK_CONTAINER (widget)->border_width;
459 if (toolitem->priv->drag_window)
460 gdk_window_move_resize (toolitem->priv->drag_window,
461 widget->allocation.x + border_width,
462 widget->allocation.y + border_width,
463 widget->allocation.width - border_width * 2,
464 widget->allocation.height - border_width * 2);
466 if (child && GTK_WIDGET_VISIBLE (child))
468 child_allocation.x = allocation->x + border_width;
469 child_allocation.y = allocation->y + border_width;
470 child_allocation.width = allocation->width - 2 * border_width;
471 child_allocation.height = allocation->height - 2 * border_width;
473 gtk_widget_size_allocate (child, &child_allocation);
478 gtk_tool_item_create_menu_proxy (GtkToolItem *item)
486 * Creates a new #GtkToolItem
488 * Return value: the new #GtkToolItem
493 gtk_tool_item_new (void)
497 item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
503 * gtk_tool_item_get_icon_size:
504 * @tool_item: a #GtkToolItem:
506 * Returns the icon size used for @tool_item. Custom subclasses of
507 * #GtkToolItem should call this function to find out what size icons
510 * Return value: a #GtkIconSize indicating the icon size used for @tool_item
515 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
519 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
521 parent = GTK_WIDGET (tool_item)->parent;
522 if (!parent || !GTK_IS_TOOLBAR (parent))
523 return GTK_ICON_SIZE_LARGE_TOOLBAR;
525 return gtk_toolbar_get_icon_size (GTK_TOOLBAR (parent));
529 * gtk_tool_item_get_orientation:
530 * @tool_item: a #GtkToolItem:
532 * Returns the orientation used for @tool_item. Custom subclasses of
533 * #GtkToolItem should call this function to find out what size icons
536 * Return value: a #GtkOrientation indicating the orientation
537 * used for @tool_item
542 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
546 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
548 parent = GTK_WIDGET (tool_item)->parent;
549 if (!parent || !GTK_IS_TOOLBAR (parent))
550 return GTK_ORIENTATION_HORIZONTAL;
552 return gtk_toolbar_get_orientation (GTK_TOOLBAR (parent));
556 * gtk_tool_item_get_toolbar_style:
557 * @tool_item: a #GtkToolItem:
559 * Returns the toolbar style used for @tool_item. Custom subclasses of
560 * #GtkToolItem should call this function in the handler of the
561 * GtkToolItem::toolbar_reconfigured signal to find out in what style
562 * the toolbar is displayed and change themselves accordingly
566 * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
567 * both an icon and a label, stacked vertically </listitem>
568 * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
569 * only icons </listitem>
570 * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
571 * show text</listitem>
572 * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
573 * both an icon and a label, arranged horizontally (however, note the
574 * #GtkToolButton::has_text_horizontally that makes tool buttons not
575 * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
579 * Return value: A #GtkToolbarStyle indicating the toolbar style used
585 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
589 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
591 parent = GTK_WIDGET (tool_item)->parent;
592 if (!parent || !GTK_IS_TOOLBAR (parent))
593 return GTK_TOOLBAR_ICONS;
595 return gtk_toolbar_get_style (GTK_TOOLBAR (parent));
599 * gtk_tool_item_get_relief_style:
600 * @tool_item: a #GtkToolItem:
602 * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
603 * Custom subclasses of #GtkToolItem should call this function in the handler
604 * of the #GtkToolItem::toolbar_reconfigured signal to find out the
605 * relief style of buttons.
607 * Return value: a #GtkReliefStyle indicating the relief style used
613 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
617 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
619 parent = GTK_WIDGET (tool_item)->parent;
620 if (!parent || !GTK_IS_TOOLBAR (parent))
621 return GTK_RELIEF_NONE;
623 return gtk_toolbar_get_relief_style (GTK_TOOLBAR (parent));
627 * gtk_tool_item_set_expand:
628 * @tool_item: a #GtkToolItem:
629 * @expand: Whether @tool_item is allocated extra space
631 * Sets whether @tool_item is allocated extra space when there
632 * is more room on the toolbar then needed for the items. The
633 * effect is that the item gets bigger when the toolbar gets bigger
634 * and smaller when the toolbar gets smaller.
639 gtk_tool_item_set_expand (GtkToolItem *tool_item,
642 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
644 expand = expand != FALSE;
646 if (tool_item->priv->expand != expand)
648 tool_item->priv->expand = expand;
649 gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
650 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
655 * gtk_tool_item_get_expand:
656 * @tool_item: a #GtkToolItem:
658 * Returns whether @tool_item is allocated extra space.
659 * See gtk_tool_item_set_expand().
661 * Return value: %TRUE if @tool_item is allocated extra space.
666 gtk_tool_item_get_expand (GtkToolItem *tool_item)
668 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
670 return tool_item->priv->expand;
674 * gtk_tool_item_set_homogeneous:
675 * @tool_item: a #GtkToolItem:
676 * @homogeneous: whether @tool_item is the same size as other homogeneous items
678 * Sets whether @tool_item is to be allocated the same size as other
679 * homogeneous items. The effect is that all homogeneous items will have
680 * the same width as the widest of the items.
685 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
686 gboolean homogeneous)
688 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
690 homogeneous = homogeneous != FALSE;
692 if (tool_item->priv->homogeneous != homogeneous)
694 tool_item->priv->homogeneous = homogeneous;
695 gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
696 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
701 * gtk_tool_item_get_homogeneous:
702 * @tool_item: a #GtkToolItem:
704 * Returns whether @tool_item is the same size as other homogeneous
705 * items. See gtk_tool_item_set_homogeneous().
707 * Return value: %TRUE if the item is the same size as other homogeneous
713 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
715 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
717 return tool_item->priv->homogeneous;
721 * gtk_tool_item_get_is_important:
722 * @tool_item: a #GtkToolItem
724 * Returns whether @tool_item is considered important. See
725 * gtk_tool_item_set_is_important()
727 * Return value: %TRUE if @tool_item is considered important.
732 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
734 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
736 return tool_item->priv->is_important;
740 * gtk_tool_item_set_is_important:
741 * @tool_item: a #GtkToolItem
742 * @is_important: whether the tool item should be considered important
744 * Sets whether @tool_item should be considered important. The #GtkToolButton
745 * class uses this property to determine whether to show or hide its label
746 * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
747 * only tool buttons with the "is_important" property set have labels, an
748 * effect known as "priority text"
753 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
755 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
757 is_important = is_important != FALSE;
759 if (is_important != tool_item->priv->is_important)
761 tool_item->priv->is_important = is_important;
763 gtk_widget_queue_resize (GTK_WIDGET (tool_item));
765 g_object_notify (G_OBJECT (tool_item), "is_important");
770 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
771 GtkTooltips *tooltips,
772 const gchar *tip_text,
773 const gchar *tip_private)
775 GtkWidget *child = GTK_BIN (tool_item)->child;
780 gtk_tooltips_set_tip (tooltips, child, tip_text, tip_private);
786 * gtk_tool_item_set_tooltip:
787 * @tool_item: a #GtkToolItem:
788 * @tooltips: The #GtkTooltips object to be used
789 * @tip_text: text to be used as tooltip text for @tool_item
790 * @tip_private: text to be used as private tooltip text
792 * Sets the #GtkTooltips object to be used for @tool_item, the
793 * text to be displayed as tooltip on the item and the private text
794 * to be used. See gtk_tooltips_set_tip().
799 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
800 GtkTooltips *tooltips,
801 const gchar *tip_text,
802 const gchar *tip_private)
806 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
808 g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
809 tooltips, tip_text, tip_private, &retval);
813 * gtk_tool_item_set_use_drag_window:
814 * @toolitem: a #GtkToolItem
815 * @use_drag_window: Whether @toolitem has a drag window.
817 * Sets whether @toolitem has a drag window. When %TRUE the
818 * toolitem can be used as a drag source through gtk_drag_source_set().
819 * When @toolitem has a drag window it will intercept all events,
820 * even those that would otherwise be sent to a child of @toolitem.
825 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
826 gboolean use_drag_window)
828 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
830 use_drag_window = use_drag_window != FALSE;
832 if (toolitem->priv->use_drag_window != use_drag_window)
834 toolitem->priv->use_drag_window = use_drag_window;
838 if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
840 create_drag_window(toolitem);
841 if (GTK_WIDGET_MAPPED (toolitem))
842 gdk_window_show (toolitem->priv->drag_window);
847 destroy_drag_window (toolitem);
853 * gtk_tool_item_get_use_drag_window:
854 * @toolitem: a #GtkToolItem
856 * Returns whether @toolitem has a drag window. See
857 * gtk_tool_item_set_use_drag_window().
859 * Return value: %TRUE if @toolitem uses a drag window.
864 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
866 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
868 return toolitem->priv->use_drag_window;
872 * gtk_tool_item_set_visible_horizontal:
873 * @toolitem: a #GtkToolItem
874 * @visible_horizontal: Whether @toolitem is visible when in horizontal mode
876 * Sets whether @toolitem is visible when the toolbar is docked horizontally.
881 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
882 gboolean visible_horizontal)
884 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
886 visible_horizontal = visible_horizontal != FALSE;
888 if (toolitem->priv->visible_horizontal != visible_horizontal)
890 toolitem->priv->visible_horizontal = visible_horizontal;
892 g_object_notify (G_OBJECT (toolitem), "visible_horizontal");
894 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
899 * gtk_tool_item_get_visible_horizontal:
900 * @toolitem: a #GtkToolItem
902 * Returns whether the @toolitem is visible on toolbars that are
903 * docked horizontally.
905 * Return value: %TRUE if @toolitem is visible on toolbars that are
906 * docked horizontally.
911 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
913 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
915 return toolitem->priv->visible_horizontal;
919 * gtk_tool_item_set_visible_vertical:
920 * @toolitem: a #GtkToolItem
921 * @visible_vertical: whether @toolitem is visible when the toolbar
922 * is in vertical mode
924 * Sets whether @toolitem is visible when the toolbar is docked
925 * vertically. Some tool items, such as text entries, are too wide to be
926 * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
927 * @toolitem will not appear on toolbars that are docked vertically.
932 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
933 gboolean visible_vertical)
935 g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
937 visible_vertical = visible_vertical != FALSE;
939 if (toolitem->priv->visible_vertical != visible_vertical)
941 toolitem->priv->visible_vertical = visible_vertical;
943 g_object_notify (G_OBJECT (toolitem), "visible_vertical");
945 gtk_widget_queue_resize (GTK_WIDGET (toolitem));
950 * gtk_tool_item_get_visible_vertical:
951 * @toolitem: a #GtkToolItem
953 * Returns whether @toolitem is visible when the toolbar is docked vertically.
954 * See gtk_tool_item_set_visible_vertical().
956 * Return value: Whether @toolitem is visible when the toolbar is docked vertically
961 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
963 g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
965 return toolitem->priv->visible_vertical;
969 * gtk_tool_item_retrieve_proxy_menu_item:
970 * @tool_item: a #GtkToolItem:
972 * Returns the #GtkMenuItem that was last set by
973 * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
974 * that is going to appear in the overflow menu.
976 * Return value: The #GtkMenuItem that is going to appear in the
977 * overflow menu for @tool_item.
982 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
986 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
988 g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0, &retval);
990 return tool_item->priv->menu_item;
994 * gtk_tool_item_get_proxy_menu_item:
995 * @tool_item: a #GtkToolItem:
996 * @menu_item_id: a string used to identify the menu item
998 * If @menu_item_id matches the string passed to
999 * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1001 * Custom subclasses of #GtkToolItem should use this function to update
1002 * their menu item when the #GtkToolItem changes. That the
1003 * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1004 * inadvertently change a menu item that they did not create.
1006 * Return value: The #GtkMenuItem passed to
1007 * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1012 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1013 const gchar *menu_item_id)
1015 g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1016 g_return_val_if_fail (menu_item_id != NULL, NULL);
1018 if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1019 return tool_item->priv->menu_item;
1025 * gtk_tool_item_set_proxy_menu_item:
1026 * @tool_item: a #GtkToolItem:
1027 * @menu_item_id: a string used to identify @menu_item
1028 * @menu_item: a #GtkMenuItem to be used in the overflow menu
1030 * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1031 * @menu_item_id is used to identify the caller of this function and
1032 * should also be used with gtk_tool_item_get_proxy_menu_item().
1037 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1038 const gchar *menu_item_id,
1039 GtkWidget *menu_item)
1041 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1042 g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1043 g_return_if_fail (menu_item_id != NULL);
1045 if (tool_item->priv->menu_item_id)
1046 g_free (tool_item->priv->menu_item_id);
1048 tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1050 if (tool_item->priv->menu_item != menu_item)
1052 if (tool_item->priv->menu_item)
1053 g_object_unref (G_OBJECT (tool_item->priv->menu_item));
1057 g_object_ref (menu_item);
1058 gtk_object_sink (GTK_OBJECT (menu_item));
1061 tool_item->priv->menu_item = menu_item;
1066 * _gtk_tool_item_toolbar_reconfigured:
1067 * @tool_item: a #GtkToolItem:
1069 * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item. This
1070 * internal function is called by #GtkToolbar when some aspect of its
1071 * configuration changes.
1076 _gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1078 g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1080 g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1082 gtk_widget_queue_resize (GTK_WIDGET (tool_item));