]> Pileus Git - ~andy/gtk/blob - gtk/gtktoolitem.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / gtk / gtktoolitem.c
1 /* gtktoolitem.c
2  *
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>
6  *
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.
11  *
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.
16  *
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.
21  */
22
23 #include "config.h"
24
25 #include <string.h>
26
27 #undef GTK_DISABLE_DEPRECATED /* GtkTooltips */
28
29 #include "gtktoolitem.h"
30 #include "gtkmarshalers.h"
31 #include "gtktoolshell.h"
32 #include "gtkseparatormenuitem.h"
33 #include "gtkactivatable.h"
34 #include "gtkintl.h"
35 #include "gtkmain.h"
36 #include "gtkprivate.h"
37 #include "gtkalias.h"
38
39 /**
40  * SECTION:gtktoolitem
41  * @short_description: The base class of widgets that can be added to GtkToolShell
42  * @see_also: <variablelist>
43  *   <varlistentry>
44  *     <term>#GtkToolbar</term>
45  *     <listitem><para>The toolbar widget</para></listitem>
46  *   </varlistentry>
47  *   <varlistentry>
48  *     <term>#GtkToolButton</term>
49  *     <listitem><para>A subclass of #GtkToolItem that displays buttons on
50  *         the toolbar</para></listitem>
51  *   </varlistentry>
52  *   <varlistentry>
53  *     <term>#GtkSeparatorToolItem</term>
54  *     <listitem><para>A subclass of #GtkToolItem that separates groups of
55  *         items on a toolbar</para></listitem>
56  *   </varlistentry>
57  * </variablelist>
58  *
59  * #GtkToolItem<!-- -->s are widgets that can appear on a toolbar. To
60  * create a toolbar item that contain something else than a button, use
61  * gtk_tool_item_new(). Use gtk_container_add() to add a child
62  * widget to the tool item.
63  *
64  * For toolbar items that contain buttons, see the #GtkToolButton,
65  * #GtkToggleToolButton and #GtkRadioToolButton classes.
66  *
67  * See the #GtkToolbar class for a description of the toolbar widget, and
68  * #GtkToolShell for a description of the tool shell interface.
69  */
70
71 /**
72  * GtkToolItem:
73  *
74  * The GtkToolItem struct contains only private data.
75  * It should only be accessed through the functions described below.
76  */
77
78 enum {
79   CREATE_MENU_PROXY,
80   TOOLBAR_RECONFIGURED,
81   SET_TOOLTIP,
82   LAST_SIGNAL
83 };
84
85 enum {
86   PROP_0,
87   PROP_VISIBLE_HORIZONTAL,
88   PROP_VISIBLE_VERTICAL,
89   PROP_IS_IMPORTANT,
90
91   /* activatable properties */
92   PROP_ACTIVATABLE_RELATED_ACTION,
93   PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
94 };
95
96 #define GTK_TOOL_ITEM_GET_PRIVATE(o)  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_TOOL_ITEM, GtkToolItemPrivate))
97
98 struct _GtkToolItemPrivate
99 {
100   gchar *tip_text;
101   gchar *tip_private;
102
103   guint visible_horizontal : 1;
104   guint visible_vertical : 1;
105   guint homogeneous : 1;
106   guint expand : 1;
107   guint use_drag_window : 1;
108   guint is_important : 1;
109
110   GdkWindow *drag_window;
111   
112   gchar *menu_item_id;
113   GtkWidget *menu_item;
114
115   GtkAction *action;
116   gboolean   use_action_appearance;
117 };
118   
119 static void gtk_tool_item_finalize     (GObject         *object);
120 static void gtk_tool_item_dispose      (GObject         *object);
121 static void gtk_tool_item_parent_set   (GtkWidget       *toolitem,
122                                         GtkWidget       *parent);
123 static void gtk_tool_item_set_property (GObject         *object,
124                                         guint            prop_id,
125                                         const GValue    *value,
126                                         GParamSpec      *pspec);
127 static void gtk_tool_item_get_property (GObject         *object,
128                                         guint            prop_id,
129                                         GValue          *value,
130                                         GParamSpec      *pspec);
131 static void gtk_tool_item_property_notify (GObject      *object,
132                                            GParamSpec   *pspec);
133 static void gtk_tool_item_realize       (GtkWidget      *widget);
134 static void gtk_tool_item_unrealize     (GtkWidget      *widget);
135 static void gtk_tool_item_map           (GtkWidget      *widget);
136 static void gtk_tool_item_unmap         (GtkWidget      *widget);
137 static void gtk_tool_item_size_request  (GtkWidget      *widget,
138                                          GtkRequisition *requisition);
139 static void gtk_tool_item_size_allocate (GtkWidget      *widget,
140                                          GtkAllocation  *allocation);
141 static gboolean gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
142                                                 GtkTooltips *tooltips,
143                                                 const gchar *tip_text,
144                                                 const gchar *tip_private);
145
146 static void gtk_tool_item_activatable_interface_init (GtkActivatableIface  *iface);
147 static void gtk_tool_item_update                     (GtkActivatable       *activatable,
148                                                       GtkAction            *action,
149                                                       const gchar          *property_name);
150 static void gtk_tool_item_sync_action_properties     (GtkActivatable       *activatable,
151                                                       GtkAction            *action);
152 static void gtk_tool_item_set_related_action         (GtkToolItem          *item, 
153                                                       GtkAction            *action);
154 static void gtk_tool_item_set_use_action_appearance  (GtkToolItem          *item, 
155                                                       gboolean              use_appearance);
156
157 static guint toolitem_signals[LAST_SIGNAL] = { 0 };
158
159 G_DEFINE_TYPE_WITH_CODE (GtkToolItem, gtk_tool_item, GTK_TYPE_BIN,
160                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
161                                                 gtk_tool_item_activatable_interface_init))
162
163 static void
164 gtk_tool_item_class_init (GtkToolItemClass *klass)
165 {
166   GObjectClass *object_class;
167   GtkWidgetClass *widget_class;
168   
169   object_class = (GObjectClass *)klass;
170   widget_class = (GtkWidgetClass *)klass;
171   
172   object_class->set_property = gtk_tool_item_set_property;
173   object_class->get_property = gtk_tool_item_get_property;
174   object_class->finalize     = gtk_tool_item_finalize;
175   object_class->dispose      = gtk_tool_item_dispose;
176   object_class->notify       = gtk_tool_item_property_notify;
177
178   widget_class->realize       = gtk_tool_item_realize;
179   widget_class->unrealize     = gtk_tool_item_unrealize;
180   widget_class->map           = gtk_tool_item_map;
181   widget_class->unmap         = gtk_tool_item_unmap;
182   widget_class->size_request  = gtk_tool_item_size_request;
183   widget_class->size_allocate = gtk_tool_item_size_allocate;
184   widget_class->parent_set    = gtk_tool_item_parent_set;
185
186   klass->create_menu_proxy = _gtk_tool_item_create_menu_proxy;
187   klass->set_tooltip       = gtk_tool_item_real_set_tooltip;
188   
189   g_object_class_install_property (object_class,
190                                    PROP_VISIBLE_HORIZONTAL,
191                                    g_param_spec_boolean ("visible-horizontal",
192                                                          P_("Visible when horizontal"),
193                                                          P_("Whether the toolbar item is visible when the toolbar is in a horizontal orientation."),
194                                                          TRUE,
195                                                          GTK_PARAM_READWRITE));
196   g_object_class_install_property (object_class,
197                                    PROP_VISIBLE_VERTICAL,
198                                    g_param_spec_boolean ("visible-vertical",
199                                                          P_("Visible when vertical"),
200                                                          P_("Whether the toolbar item is visible when the toolbar is in a vertical orientation."),
201                                                          TRUE,
202                                                          GTK_PARAM_READWRITE));
203   g_object_class_install_property (object_class,
204                                    PROP_IS_IMPORTANT,
205                                    g_param_spec_boolean ("is-important",
206                                                          P_("Is important"),
207                                                          P_("Whether the toolbar item is considered important. When TRUE, toolbar buttons show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
208                                                          FALSE,
209                                                          GTK_PARAM_READWRITE));
210
211   g_object_class_override_property (object_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
212   g_object_class_override_property (object_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
213
214
215 /**
216  * GtkToolItem::create-menu-proxy:
217  * @tool_item: the object the signal was emitted on
218  *
219  * This signal is emitted when the toolbar needs information from @tool_item
220  * about whether the item should appear in the toolbar overflow menu. In
221  * response the tool item should either
222  * <itemizedlist>
223  * <listitem>call gtk_tool_item_set_proxy_menu_item() with a %NULL
224  * pointer and return %TRUE to indicate that the item should not appear
225  * in the overflow menu
226  * </listitem>
227  * <listitem> call gtk_tool_item_set_proxy_menu_item() with a new menu
228  * item and return %TRUE, or 
229  * </listitem>
230  * <listitem> return %FALSE to indicate that the signal was not
231  * handled by the item. This means that
232  * the item will not appear in the overflow menu unless a later handler
233  * installs a menu item.
234  * </listitem>
235  * </itemizedlist>
236  *
237  * The toolbar may cache the result of this signal. When the tool item changes
238  * how it will respond to this signal it must call gtk_tool_item_rebuild_menu()
239  * to invalidate the cache and ensure that the toolbar rebuilds its overflow
240  * menu.
241  *
242  * Return value: %TRUE if the signal was handled, %FALSE if not
243  **/
244   toolitem_signals[CREATE_MENU_PROXY] =
245     g_signal_new (I_("create-menu-proxy"),
246                   G_OBJECT_CLASS_TYPE (klass),
247                   G_SIGNAL_RUN_LAST,
248                   G_STRUCT_OFFSET (GtkToolItemClass, create_menu_proxy),
249                   _gtk_boolean_handled_accumulator, NULL,
250                   _gtk_marshal_BOOLEAN__VOID,
251                   G_TYPE_BOOLEAN, 0);
252
253 /**
254  * GtkToolItem::toolbar-reconfigured:
255  * @tool_item: the object the signal was emitted on
256  *
257  * This signal is emitted when some property of the toolbar that the
258  * item is a child of changes. For custom subclasses of #GtkToolItem,
259  * the default handler of this signal use the functions
260  * <itemizedlist>
261  * <listitem>gtk_tool_shell_get_orientation()</listitem>
262  * <listitem>gtk_tool_shell_get_style()</listitem>
263  * <listitem>gtk_tool_shell_get_icon_size()</listitem>
264  * <listitem>gtk_tool_shell_get_relief_style()</listitem>
265  * </itemizedlist>
266  * to find out what the toolbar should look like and change
267  * themselves accordingly.
268  **/
269   toolitem_signals[TOOLBAR_RECONFIGURED] =
270     g_signal_new (I_("toolbar-reconfigured"),
271                   G_OBJECT_CLASS_TYPE (klass),
272                   G_SIGNAL_RUN_LAST,
273                   G_STRUCT_OFFSET (GtkToolItemClass, toolbar_reconfigured),
274                   NULL, NULL,
275                   _gtk_marshal_VOID__VOID,
276                   G_TYPE_NONE, 0);
277 /**
278  * GtkToolItem::set-tooltip:
279  * @tool_item: the object the signal was emitted on
280  * @tooltips: the #GtkTooltips
281  * @tip_text: the tooltip text
282  * @tip_private: the tooltip private text
283  *
284  * This signal is emitted when the toolitem's tooltip changes.
285  * Application developers can use gtk_tool_item_set_tooltip() to
286  * set the item's tooltip.
287  *
288  * Return value: %TRUE if the signal was handled, %FALSE if not
289  *
290  * Deprecated: 2.12: With the new tooltip API, there is no
291  *   need to use this signal anymore.
292  **/
293   toolitem_signals[SET_TOOLTIP] =
294     g_signal_new (I_("set-tooltip"),
295                   G_OBJECT_CLASS_TYPE (klass),
296                   G_SIGNAL_RUN_LAST,
297                   G_STRUCT_OFFSET (GtkToolItemClass, set_tooltip),
298                   _gtk_boolean_handled_accumulator, NULL,
299                   _gtk_marshal_BOOLEAN__OBJECT_STRING_STRING,
300                   G_TYPE_BOOLEAN, 3,
301                   GTK_TYPE_TOOLTIPS,
302                   G_TYPE_STRING,
303                   G_TYPE_STRING);                 
304
305   g_type_class_add_private (object_class, sizeof (GtkToolItemPrivate));
306 }
307
308 static void
309 gtk_tool_item_init (GtkToolItem *toolitem)
310 {
311   GTK_WIDGET_UNSET_FLAGS (toolitem, GTK_CAN_FOCUS);  
312
313   toolitem->priv = GTK_TOOL_ITEM_GET_PRIVATE (toolitem);
314
315   toolitem->priv->visible_horizontal = TRUE;
316   toolitem->priv->visible_vertical = TRUE;
317   toolitem->priv->homogeneous = FALSE;
318   toolitem->priv->expand = FALSE;
319
320   toolitem->priv->use_action_appearance = TRUE;
321 }
322
323 static void
324 gtk_tool_item_finalize (GObject *object)
325 {
326   GtkToolItem *item = GTK_TOOL_ITEM (object);
327
328   g_free (item->priv->menu_item_id);
329
330   if (item->priv->menu_item)
331     g_object_unref (item->priv->menu_item);
332
333   G_OBJECT_CLASS (gtk_tool_item_parent_class)->finalize (object);
334 }
335
336 static void
337 gtk_tool_item_dispose (GObject *object)
338 {
339   GtkToolItem *item = GTK_TOOL_ITEM (object);
340
341   if (item->priv->action)
342     {
343       gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), NULL);      
344       item->priv->action = NULL;
345     }
346   G_OBJECT_CLASS (gtk_tool_item_parent_class)->dispose (object);
347 }
348
349
350 static void
351 gtk_tool_item_parent_set (GtkWidget   *toolitem,
352                           GtkWidget   *prev_parent)
353 {
354   if (GTK_WIDGET (toolitem)->parent != NULL)
355     gtk_tool_item_toolbar_reconfigured (GTK_TOOL_ITEM (toolitem));
356 }
357
358 static void
359 gtk_tool_item_set_property (GObject      *object,
360                             guint         prop_id,
361                             const GValue *value,
362                             GParamSpec   *pspec)
363 {
364   GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
365
366   switch (prop_id)
367     {
368     case PROP_VISIBLE_HORIZONTAL:
369       gtk_tool_item_set_visible_horizontal (toolitem, g_value_get_boolean (value));
370       break;
371     case PROP_VISIBLE_VERTICAL:
372       gtk_tool_item_set_visible_vertical (toolitem, g_value_get_boolean (value));
373       break;
374     case PROP_IS_IMPORTANT:
375       gtk_tool_item_set_is_important (toolitem, g_value_get_boolean (value));
376       break;
377     case PROP_ACTIVATABLE_RELATED_ACTION:
378       gtk_tool_item_set_related_action (toolitem, g_value_get_object (value));
379       break;
380     case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
381       gtk_tool_item_set_use_action_appearance (toolitem, g_value_get_boolean (value));
382       break;
383     default:
384       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
385       break;
386     }
387 }
388
389 static void
390 gtk_tool_item_get_property (GObject    *object,
391                             guint       prop_id,
392                             GValue     *value,
393                             GParamSpec *pspec)
394 {
395   GtkToolItem *toolitem = GTK_TOOL_ITEM (object);
396
397   switch (prop_id)
398     {
399     case PROP_VISIBLE_HORIZONTAL:
400       g_value_set_boolean (value, toolitem->priv->visible_horizontal);
401       break;
402     case PROP_VISIBLE_VERTICAL:
403       g_value_set_boolean (value, toolitem->priv->visible_vertical);
404       break;
405     case PROP_IS_IMPORTANT:
406       g_value_set_boolean (value, toolitem->priv->is_important);
407       break;
408     case PROP_ACTIVATABLE_RELATED_ACTION:
409       g_value_set_object (value, toolitem->priv->action);
410       break;
411     case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
412       g_value_set_boolean (value, toolitem->priv->use_action_appearance);
413       break;
414     default:
415       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
416       break;
417     }
418 }
419
420 static void
421 gtk_tool_item_property_notify (GObject    *object,
422                                GParamSpec *pspec)
423 {
424   GtkToolItem *tool_item = GTK_TOOL_ITEM (object);
425
426   if (tool_item->priv->menu_item && strcmp (pspec->name, "sensitive") == 0)
427     gtk_widget_set_sensitive (tool_item->priv->menu_item,
428                               gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
429 }
430
431 static void
432 create_drag_window (GtkToolItem *toolitem)
433 {
434   GtkWidget *widget;
435   GdkWindowAttr attributes;
436   gint attributes_mask, border_width;
437
438   g_return_if_fail (toolitem->priv->use_drag_window == TRUE);
439
440   widget = GTK_WIDGET (toolitem);
441   border_width = GTK_CONTAINER (toolitem)->border_width;
442
443   attributes.window_type = GDK_WINDOW_CHILD;
444   attributes.x = widget->allocation.x + border_width;
445   attributes.y = widget->allocation.y + border_width;
446   attributes.width = widget->allocation.width - border_width * 2;
447   attributes.height = widget->allocation.height - border_width * 2;
448   attributes.wclass = GDK_INPUT_ONLY;
449   attributes.event_mask = gtk_widget_get_events (widget);
450   attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
451
452   attributes_mask = GDK_WA_X | GDK_WA_Y;
453
454   toolitem->priv->drag_window = gdk_window_new (gtk_widget_get_parent_window (widget),
455                                           &attributes, attributes_mask);
456   gdk_window_set_user_data (toolitem->priv->drag_window, toolitem);
457 }
458
459 static void
460 gtk_tool_item_realize (GtkWidget *widget)
461 {
462   GtkToolItem *toolitem;
463
464   toolitem = GTK_TOOL_ITEM (widget);
465   GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
466
467   widget->window = gtk_widget_get_parent_window (widget);
468   g_object_ref (widget->window);
469
470   if (toolitem->priv->use_drag_window)
471     create_drag_window(toolitem);
472
473   widget->style = gtk_style_attach (widget->style, widget->window);
474 }
475
476 static void
477 destroy_drag_window (GtkToolItem *toolitem)
478 {
479   if (toolitem->priv->drag_window)
480     {
481       gdk_window_set_user_data (toolitem->priv->drag_window, NULL);
482       gdk_window_destroy (toolitem->priv->drag_window);
483       toolitem->priv->drag_window = NULL;
484     }
485 }
486
487 static void
488 gtk_tool_item_unrealize (GtkWidget *widget)
489 {
490   GtkToolItem *toolitem;
491
492   toolitem = GTK_TOOL_ITEM (widget);
493
494   destroy_drag_window (toolitem);
495   
496   GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unrealize (widget);
497 }
498
499 static void
500 gtk_tool_item_map (GtkWidget *widget)
501 {
502   GtkToolItem *toolitem;
503
504   toolitem = GTK_TOOL_ITEM (widget);
505   GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->map (widget);
506   if (toolitem->priv->drag_window)
507     gdk_window_show (toolitem->priv->drag_window);
508 }
509
510 static void
511 gtk_tool_item_unmap (GtkWidget *widget)
512 {
513   GtkToolItem *toolitem;
514
515   toolitem = GTK_TOOL_ITEM (widget);
516   if (toolitem->priv->drag_window)
517     gdk_window_hide (toolitem->priv->drag_window);
518   GTK_WIDGET_CLASS (gtk_tool_item_parent_class)->unmap (widget);
519 }
520
521 static void
522 gtk_tool_item_size_request (GtkWidget      *widget,
523                             GtkRequisition *requisition)
524 {
525   GtkWidget *child = GTK_BIN (widget)->child;
526
527   if (child && gtk_widget_get_visible (child))
528     {
529       gtk_widget_size_request (child, requisition);
530     }
531   else
532     {
533       requisition->height = 0;
534       requisition->width = 0;
535     }
536   
537   requisition->width += (GTK_CONTAINER (widget)->border_width) * 2;
538   requisition->height += (GTK_CONTAINER (widget)->border_width) * 2;
539 }
540
541 static void
542 gtk_tool_item_size_allocate (GtkWidget     *widget,
543                              GtkAllocation *allocation)
544 {
545   GtkToolItem *toolitem = GTK_TOOL_ITEM (widget);
546   GtkAllocation child_allocation;
547   gint border_width;
548   GtkWidget *child = GTK_BIN (widget)->child;
549
550   widget->allocation = *allocation;
551   border_width = GTK_CONTAINER (widget)->border_width;
552
553   if (toolitem->priv->drag_window)
554     gdk_window_move_resize (toolitem->priv->drag_window,
555                             widget->allocation.x + border_width,
556                             widget->allocation.y + border_width,
557                             widget->allocation.width - border_width * 2,
558                             widget->allocation.height - border_width * 2);
559   
560   if (child && gtk_widget_get_visible (child))
561     {
562       child_allocation.x = allocation->x + border_width;
563       child_allocation.y = allocation->y + border_width;
564       child_allocation.width = allocation->width - 2 * border_width;
565       child_allocation.height = allocation->height - 2 * border_width;
566       
567       gtk_widget_size_allocate (child, &child_allocation);
568     }
569 }
570
571 gboolean
572 _gtk_tool_item_create_menu_proxy (GtkToolItem *item)
573 {
574   GtkWidget *menu_item;
575   gboolean visible_overflown;
576
577   if (item->priv->action)
578     {
579       g_object_get (item->priv->action, "visible-overflown", &visible_overflown, NULL);
580     
581       if (visible_overflown)
582         {
583           menu_item = gtk_action_create_menu_item (item->priv->action);
584
585           g_object_ref_sink (menu_item);
586           gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", menu_item);
587           g_object_unref (menu_item);
588         }
589       else
590         gtk_tool_item_set_proxy_menu_item (item, "gtk-action-menu-item", NULL);
591
592       return TRUE;
593     }
594
595   return FALSE;
596 }
597
598 static void
599 gtk_tool_item_activatable_interface_init (GtkActivatableIface *iface)
600 {
601   iface->update = gtk_tool_item_update;
602   iface->sync_action_properties = gtk_tool_item_sync_action_properties;
603 }
604
605 static void
606 gtk_tool_item_update (GtkActivatable *activatable,
607                       GtkAction      *action,
608                       const gchar    *property_name)
609 {
610   if (strcmp (property_name, "visible") == 0)
611     {
612       if (gtk_action_is_visible (action))
613         gtk_widget_show (GTK_WIDGET (activatable));
614       else
615         gtk_widget_hide (GTK_WIDGET (activatable));
616     }
617   else if (strcmp (property_name, "sensitive") == 0)
618     gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
619   else if (strcmp (property_name, "tooltip") == 0)
620     gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
621                                     gtk_action_get_tooltip (action));
622   else if (strcmp (property_name, "visible-horizontal") == 0)
623     gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
624                                           gtk_action_get_visible_horizontal (action));
625   else if (strcmp (property_name, "visible-vertical") == 0)
626     gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
627                                         gtk_action_get_visible_vertical (action));
628   else if (strcmp (property_name, "is-important") == 0)
629     gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
630                                     gtk_action_get_is_important (action));
631 }
632
633 static void
634 gtk_tool_item_sync_action_properties (GtkActivatable *activatable,
635                                       GtkAction      *action)
636 {
637   if (!action)
638     return;
639
640   if (gtk_action_is_visible (action))
641     gtk_widget_show (GTK_WIDGET (activatable));
642   else
643     gtk_widget_hide (GTK_WIDGET (activatable));
644   
645   gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
646   
647   gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (activatable),
648                                   gtk_action_get_tooltip (action));
649   gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (activatable),
650                                         gtk_action_get_visible_horizontal (action));
651   gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (activatable),
652                                       gtk_action_get_visible_vertical (action));
653   gtk_tool_item_set_is_important (GTK_TOOL_ITEM (activatable),
654                                   gtk_action_get_is_important (action));
655 }
656
657 static void
658 gtk_tool_item_set_related_action (GtkToolItem *item, 
659                                   GtkAction   *action)
660 {
661   if (item->priv->action == action)
662     return;
663
664   gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (item), action);
665
666   item->priv->action = action;
667
668   if (action)
669     {
670       gtk_tool_item_rebuild_menu (item);
671     }
672 }
673
674 static void
675 gtk_tool_item_set_use_action_appearance (GtkToolItem *item,
676                                          gboolean     use_appearance)
677 {
678   if (item->priv->use_action_appearance != use_appearance)
679     {
680       item->priv->use_action_appearance = use_appearance;
681
682       gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (item), item->priv->action);
683     }
684 }
685
686
687 /**
688  * gtk_tool_item_new:
689  * 
690  * Creates a new #GtkToolItem
691  * 
692  * Return value: the new #GtkToolItem
693  * 
694  * Since: 2.4
695  **/
696 GtkToolItem *
697 gtk_tool_item_new (void)
698 {
699   GtkToolItem *item;
700
701   item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL);
702
703   return item;
704 }
705
706 /**
707  * gtk_tool_item_get_ellipsize_mode:
708  * @tool_item: a #GtkToolItem
709  *
710  * Returns the ellipsize mode used for @tool_item. Custom subclasses of
711  * #GtkToolItem should call this function to find out how text should
712  * be ellipsized.
713  *
714  * Return value: a #PangoEllipsizeMode indicating how text in @tool_item
715  * should be ellipsized.
716  *
717  * Since: 2.20
718  **/
719 PangoEllipsizeMode
720 gtk_tool_item_get_ellipsize_mode (GtkToolItem *tool_item)
721 {
722   GtkWidget *parent;
723   
724   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
725
726   parent = GTK_WIDGET (tool_item)->parent;
727   if (!parent || !GTK_IS_TOOL_SHELL (parent))
728     return PANGO_ELLIPSIZE_NONE;
729
730   return gtk_tool_shell_get_ellipsize_mode (GTK_TOOL_SHELL (parent));
731 }
732
733 /**
734  * gtk_tool_item_get_icon_size:
735  * @tool_item: a #GtkToolItem
736  * 
737  * Returns the icon size used for @tool_item. Custom subclasses of
738  * #GtkToolItem should call this function to find out what size icons
739  * they should use.
740  * 
741  * Return value: (type int): a #GtkIconSize indicating the icon size
742  * used for @tool_item
743  * 
744  * Since: 2.4
745  **/
746 GtkIconSize
747 gtk_tool_item_get_icon_size (GtkToolItem *tool_item)
748 {
749   GtkWidget *parent;
750
751   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ICON_SIZE_LARGE_TOOLBAR);
752
753   parent = GTK_WIDGET (tool_item)->parent;
754   if (!parent || !GTK_IS_TOOL_SHELL (parent))
755     return GTK_ICON_SIZE_LARGE_TOOLBAR;
756
757   return gtk_tool_shell_get_icon_size (GTK_TOOL_SHELL (parent));
758 }
759
760 /**
761  * gtk_tool_item_get_orientation:
762  * @tool_item: a #GtkToolItem 
763  * 
764  * Returns the orientation used for @tool_item. Custom subclasses of
765  * #GtkToolItem should call this function to find out what size icons
766  * they should use.
767  * 
768  * Return value: a #GtkOrientation indicating the orientation
769  * used for @tool_item
770  * 
771  * Since: 2.4
772  **/
773 GtkOrientation
774 gtk_tool_item_get_orientation (GtkToolItem *tool_item)
775 {
776   GtkWidget *parent;
777   
778   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
779
780   parent = GTK_WIDGET (tool_item)->parent;
781   if (!parent || !GTK_IS_TOOL_SHELL (parent))
782     return GTK_ORIENTATION_HORIZONTAL;
783
784   return gtk_tool_shell_get_orientation (GTK_TOOL_SHELL (parent));
785 }
786
787 /**
788  * gtk_tool_item_get_toolbar_style:
789  * @tool_item: a #GtkToolItem 
790  * 
791  * Returns the toolbar style used for @tool_item. Custom subclasses of
792  * #GtkToolItem should call this function in the handler of the
793  * GtkToolItem::toolbar_reconfigured signal to find out in what style
794  * the toolbar is displayed and change themselves accordingly 
795  *
796  * Possibilities are:
797  * <itemizedlist>
798  * <listitem> GTK_TOOLBAR_BOTH, meaning the tool item should show
799  * both an icon and a label, stacked vertically </listitem>
800  * <listitem> GTK_TOOLBAR_ICONS, meaning the toolbar shows
801  * only icons </listitem>
802  * <listitem> GTK_TOOLBAR_TEXT, meaning the tool item should only
803  * show text</listitem>
804  * <listitem> GTK_TOOLBAR_BOTH_HORIZ, meaning the tool item should show
805  * both an icon and a label, arranged horizontally (however, note the 
806  * #GtkToolButton::has_text_horizontally that makes tool buttons not
807  * show labels when the toolbar style is GTK_TOOLBAR_BOTH_HORIZ.
808  * </listitem>
809  * </itemizedlist>
810  * 
811  * Return value: A #GtkToolbarStyle indicating the toolbar style used
812  * for @tool_item.
813  * 
814  * Since: 2.4
815  **/
816 GtkToolbarStyle
817 gtk_tool_item_get_toolbar_style (GtkToolItem *tool_item)
818 {
819   GtkWidget *parent;
820   
821   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_TOOLBAR_ICONS);
822
823   parent = GTK_WIDGET (tool_item)->parent;
824   if (!parent || !GTK_IS_TOOL_SHELL (parent))
825     return GTK_TOOLBAR_ICONS;
826
827   return gtk_tool_shell_get_style (GTK_TOOL_SHELL (parent));
828 }
829
830 /**
831  * gtk_tool_item_get_relief_style:
832  * @tool_item: a #GtkToolItem 
833  * 
834  * Returns the relief style of @tool_item. See gtk_button_set_relief_style().
835  * Custom subclasses of #GtkToolItem should call this function in the handler
836  * of the #GtkToolItem::toolbar_reconfigured signal to find out the
837  * relief style of buttons.
838  * 
839  * Return value: a #GtkReliefStyle indicating the relief style used
840  * for @tool_item.
841  * 
842  * Since: 2.4
843  **/
844 GtkReliefStyle 
845 gtk_tool_item_get_relief_style (GtkToolItem *tool_item)
846 {
847   GtkWidget *parent;
848   
849   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_RELIEF_NONE);
850
851   parent = GTK_WIDGET (tool_item)->parent;
852   if (!parent || !GTK_IS_TOOL_SHELL (parent))
853     return GTK_RELIEF_NONE;
854
855   return gtk_tool_shell_get_relief_style (GTK_TOOL_SHELL (parent));
856 }
857
858 /**
859  * gtk_tool_item_get_text_alignment:
860  * @tool_item: a #GtkToolItem: 
861  * 
862  * Returns the text alignment used for @tool_item. Custom subclasses of
863  * #GtkToolItem should call this function to find out how text should
864  * be aligned.
865  * 
866  * Return value: a #gfloat indicating the horizontal text alignment
867  * used for @tool_item
868  * 
869  * Since: 2.20
870  **/
871 gfloat
872 gtk_tool_item_get_text_alignment (GtkToolItem *tool_item)
873 {
874   GtkWidget *parent;
875   
876   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
877
878   parent = GTK_WIDGET (tool_item)->parent;
879   if (!parent || !GTK_IS_TOOL_SHELL (parent))
880     return 0.5;
881
882   return gtk_tool_shell_get_text_alignment (GTK_TOOL_SHELL (parent));
883 }
884
885 /**
886  * gtk_tool_item_get_text_orientation:
887  * @tool_item: a #GtkToolItem
888  *
889  * Returns the text orientation used for @tool_item. Custom subclasses of
890  * #GtkToolItem should call this function to find out how text should
891  * be orientated.
892  *
893  * Return value: a #GtkOrientation indicating the text orientation
894  * used for @tool_item
895  *
896  * Since: 2.20
897  */
898 GtkOrientation
899 gtk_tool_item_get_text_orientation (GtkToolItem *tool_item)
900 {
901   GtkWidget *parent;
902   
903   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), GTK_ORIENTATION_HORIZONTAL);
904
905   parent = GTK_WIDGET (tool_item)->parent;
906   if (!parent || !GTK_IS_TOOL_SHELL (parent))
907     return GTK_ORIENTATION_HORIZONTAL;
908
909   return gtk_tool_shell_get_text_orientation (GTK_TOOL_SHELL (parent));
910 }
911
912 /**
913  * gtk_tool_item_get_text_size_group:
914  * @tool_item: a #GtkToolItem
915  *
916  * Returns the size group used for labels in @tool_item. Custom subclasses of
917  * #GtkToolItem should call this function and use the size group for labels.
918  *
919  * Return value: a #GtkSizeGroup
920  *
921  * Since: 2.20
922  */
923 GtkSizeGroup *
924 gtk_tool_item_get_text_size_group (GtkToolItem *tool_item)
925 {
926   GtkWidget *parent;
927   
928   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
929
930   parent = GTK_WIDGET (tool_item)->parent;
931   if (!parent || !GTK_IS_TOOL_SHELL (parent))
932     return NULL;
933
934   return gtk_tool_shell_get_text_size_group (GTK_TOOL_SHELL (parent));
935 }
936
937 /**
938  * gtk_tool_item_set_expand:
939  * @tool_item: a #GtkToolItem
940  * @expand: Whether @tool_item is allocated extra space
941  *
942  * Sets whether @tool_item is allocated extra space when there
943  * is more room on the toolbar then needed for the items. The
944  * effect is that the item gets bigger when the toolbar gets bigger
945  * and smaller when the toolbar gets smaller.
946  *
947  * Since: 2.4
948  */
949 void
950 gtk_tool_item_set_expand (GtkToolItem *tool_item,
951                           gboolean     expand)
952 {
953   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
954     
955   expand = expand != FALSE;
956
957   if (tool_item->priv->expand != expand)
958     {
959       tool_item->priv->expand = expand;
960       gtk_widget_child_notify (GTK_WIDGET (tool_item), "expand");
961       gtk_widget_queue_resize (GTK_WIDGET (tool_item));
962     }
963 }
964
965 /**
966  * gtk_tool_item_get_expand:
967  * @tool_item: a #GtkToolItem 
968  * 
969  * Returns whether @tool_item is allocated extra space.
970  * See gtk_tool_item_set_expand().
971  * 
972  * Return value: %TRUE if @tool_item is allocated extra space.
973  * 
974  * Since: 2.4
975  **/
976 gboolean
977 gtk_tool_item_get_expand (GtkToolItem *tool_item)
978 {
979   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
980
981   return tool_item->priv->expand;
982 }
983
984 /**
985  * gtk_tool_item_set_homogeneous:
986  * @tool_item: a #GtkToolItem 
987  * @homogeneous: whether @tool_item is the same size as other homogeneous items
988  * 
989  * Sets whether @tool_item is to be allocated the same size as other
990  * homogeneous items. The effect is that all homogeneous items will have
991  * the same width as the widest of the items.
992  * 
993  * Since: 2.4
994  **/
995 void
996 gtk_tool_item_set_homogeneous (GtkToolItem *tool_item,
997                                gboolean     homogeneous)
998 {
999   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1000     
1001   homogeneous = homogeneous != FALSE;
1002
1003   if (tool_item->priv->homogeneous != homogeneous)
1004     {
1005       tool_item->priv->homogeneous = homogeneous;
1006       gtk_widget_child_notify (GTK_WIDGET (tool_item), "homogeneous");
1007       gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1008     }
1009 }
1010
1011 /**
1012  * gtk_tool_item_get_homogeneous:
1013  * @tool_item: a #GtkToolItem 
1014  * 
1015  * Returns whether @tool_item is the same size as other homogeneous
1016  * items. See gtk_tool_item_set_homogeneous().
1017  * 
1018  * Return value: %TRUE if the item is the same size as other homogeneous
1019  * items.
1020  * 
1021  * Since: 2.4
1022  **/
1023 gboolean
1024 gtk_tool_item_get_homogeneous (GtkToolItem *tool_item)
1025 {
1026   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1027
1028   return tool_item->priv->homogeneous;
1029 }
1030
1031 /**
1032  * gtk_tool_item_get_is_important:
1033  * @tool_item: a #GtkToolItem
1034  * 
1035  * Returns whether @tool_item is considered important. See
1036  * gtk_tool_item_set_is_important()
1037  * 
1038  * Return value: %TRUE if @tool_item is considered important.
1039  * 
1040  * Since: 2.4
1041  **/
1042 gboolean
1043 gtk_tool_item_get_is_important (GtkToolItem *tool_item)
1044 {
1045   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE);
1046
1047   return tool_item->priv->is_important;
1048 }
1049
1050 /**
1051  * gtk_tool_item_set_is_important:
1052  * @tool_item: a #GtkToolItem
1053  * @is_important: whether the tool item should be considered important
1054  * 
1055  * Sets whether @tool_item should be considered important. The #GtkToolButton
1056  * class uses this property to determine whether to show or hide its label
1057  * when the toolbar style is %GTK_TOOLBAR_BOTH_HORIZ. The result is that
1058  * only tool buttons with the "is_important" property set have labels, an
1059  * effect known as "priority text"
1060  * 
1061  * Since: 2.4
1062  **/
1063 void
1064 gtk_tool_item_set_is_important (GtkToolItem *tool_item, gboolean is_important)
1065 {
1066   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1067
1068   is_important = is_important != FALSE;
1069
1070   if (is_important != tool_item->priv->is_important)
1071     {
1072       tool_item->priv->is_important = is_important;
1073
1074       gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1075
1076       g_object_notify (G_OBJECT (tool_item), "is-important");
1077     }
1078 }
1079
1080 static gboolean
1081 gtk_tool_item_real_set_tooltip (GtkToolItem *tool_item,
1082                                 GtkTooltips *tooltips,
1083                                 const gchar *tip_text,
1084                                 const gchar *tip_private)
1085 {
1086   GtkWidget *child = GTK_BIN (tool_item)->child;
1087
1088   if (!child)
1089     return FALSE;
1090
1091   gtk_widget_set_tooltip_text (child, tip_text);
1092
1093   return TRUE;
1094 }
1095
1096 /**
1097  * gtk_tool_item_set_tooltip:
1098  * @tool_item: a #GtkToolItem
1099  * @tooltips: The #GtkTooltips object to be used
1100  * @tip_text: (allow-none): text to be used as tooltip text for @tool_item
1101  * @tip_private: (allow-none): text to be used as private tooltip text
1102  *
1103  * Sets the #GtkTooltips object to be used for @tool_item, the
1104  * text to be displayed as tooltip on the item and the private text
1105  * to be used. See gtk_tooltips_set_tip().
1106  * 
1107  * Since: 2.4
1108  *
1109  * Deprecated: 2.12: Use gtk_tool_item_set_tooltip_text() instead.
1110  **/
1111 void
1112 gtk_tool_item_set_tooltip (GtkToolItem *tool_item,
1113                            GtkTooltips *tooltips,
1114                            const gchar *tip_text,
1115                            const gchar *tip_private)
1116 {
1117   gboolean retval;
1118   
1119   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1120
1121   g_signal_emit (tool_item, toolitem_signals[SET_TOOLTIP], 0,
1122                  tooltips, tip_text, tip_private, &retval);
1123 }
1124
1125 /**
1126  * gtk_tool_item_set_tooltip_text:
1127  * @tool_item: a #GtkToolItem 
1128  * @text: text to be used as tooltip for @tool_item
1129  *
1130  * Sets the text to be displayed as tooltip on the item.
1131  * See gtk_widget_set_tooltip_text().
1132  *
1133  * Since: 2.12
1134  **/
1135 void
1136 gtk_tool_item_set_tooltip_text (GtkToolItem *tool_item,
1137                                 const gchar *text)
1138 {
1139   GtkWidget *child;
1140
1141   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1142
1143   child = GTK_BIN (tool_item)->child;
1144
1145   if (child)
1146     gtk_widget_set_tooltip_text (child, text);
1147 }
1148
1149 /**
1150  * gtk_tool_item_set_tooltip_markup:
1151  * @tool_item: a #GtkToolItem 
1152  * @markup: markup text to be used as tooltip for @tool_item
1153  *
1154  * Sets the markup text to be displayed as tooltip on the item.
1155  * See gtk_widget_set_tooltip_markup().
1156  *
1157  * Since: 2.12
1158  **/
1159 void
1160 gtk_tool_item_set_tooltip_markup (GtkToolItem *tool_item,
1161                                   const gchar *markup)
1162 {
1163   GtkWidget *child;
1164
1165   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1166
1167   child = GTK_BIN (tool_item)->child;
1168
1169   if (child)
1170     gtk_widget_set_tooltip_markup (child, markup);
1171 }
1172
1173 /**
1174  * gtk_tool_item_set_use_drag_window:
1175  * @tool_item: a #GtkToolItem 
1176  * @use_drag_window: Whether @tool_item has a drag window.
1177  * 
1178  * Sets whether @tool_item has a drag window. When %TRUE the
1179  * toolitem can be used as a drag source through gtk_drag_source_set().
1180  * When @tool_item has a drag window it will intercept all events,
1181  * even those that would otherwise be sent to a child of @tool_item.
1182  * 
1183  * Since: 2.4
1184  **/
1185 void
1186 gtk_tool_item_set_use_drag_window (GtkToolItem *toolitem,
1187                                    gboolean     use_drag_window)
1188 {
1189   g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1190
1191   use_drag_window = use_drag_window != FALSE;
1192
1193   if (toolitem->priv->use_drag_window != use_drag_window)
1194     {
1195       toolitem->priv->use_drag_window = use_drag_window;
1196       
1197       if (use_drag_window)
1198         {
1199           if (!toolitem->priv->drag_window && GTK_WIDGET_REALIZED (toolitem))
1200             {
1201               create_drag_window(toolitem);
1202               if (GTK_WIDGET_MAPPED (toolitem))
1203                 gdk_window_show (toolitem->priv->drag_window);
1204             }
1205         }
1206       else
1207         {
1208           destroy_drag_window (toolitem);
1209         }
1210     }
1211 }
1212
1213 /**
1214  * gtk_tool_item_get_use_drag_window:
1215  * @tool_item: a #GtkToolItem 
1216  * 
1217  * Returns whether @tool_item has a drag window. See
1218  * gtk_tool_item_set_use_drag_window().
1219  * 
1220  * Return value: %TRUE if @tool_item uses a drag window.
1221  * 
1222  * Since: 2.4
1223  **/
1224 gboolean
1225 gtk_tool_item_get_use_drag_window (GtkToolItem *toolitem)
1226 {
1227   g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1228
1229   return toolitem->priv->use_drag_window;
1230 }
1231
1232 /**
1233  * gtk_tool_item_set_visible_horizontal:
1234  * @tool_item: a #GtkToolItem
1235  * @visible_horizontal: Whether @tool_item is visible when in horizontal mode
1236  * 
1237  * Sets whether @tool_item is visible when the toolbar is docked horizontally.
1238  * 
1239  * Since: 2.4
1240  **/
1241 void
1242 gtk_tool_item_set_visible_horizontal (GtkToolItem *toolitem,
1243                                       gboolean     visible_horizontal)
1244 {
1245   g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1246
1247   visible_horizontal = visible_horizontal != FALSE;
1248
1249   if (toolitem->priv->visible_horizontal != visible_horizontal)
1250     {
1251       toolitem->priv->visible_horizontal = visible_horizontal;
1252
1253       g_object_notify (G_OBJECT (toolitem), "visible-horizontal");
1254
1255       gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1256     }
1257 }
1258
1259 /**
1260  * gtk_tool_item_get_visible_horizontal:
1261  * @tool_item: a #GtkToolItem 
1262  * 
1263  * Returns whether the @tool_item is visible on toolbars that are
1264  * docked horizontally.
1265  * 
1266  * Return value: %TRUE if @tool_item is visible on toolbars that are
1267  * docked horizontally.
1268  * 
1269  * Since: 2.4
1270  **/
1271 gboolean
1272 gtk_tool_item_get_visible_horizontal (GtkToolItem *toolitem)
1273 {
1274   g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1275
1276   return toolitem->priv->visible_horizontal;
1277 }
1278
1279 /**
1280  * gtk_tool_item_set_visible_vertical:
1281  * @tool_item: a #GtkToolItem 
1282  * @visible_vertical: whether @tool_item is visible when the toolbar
1283  * is in vertical mode
1284  *
1285  * Sets whether @tool_item is visible when the toolbar is docked
1286  * vertically. Some tool items, such as text entries, are too wide to be
1287  * useful on a vertically docked toolbar. If @visible_vertical is %FALSE
1288  * @tool_item will not appear on toolbars that are docked vertically.
1289  * 
1290  * Since: 2.4
1291  **/
1292 void
1293 gtk_tool_item_set_visible_vertical (GtkToolItem *toolitem,
1294                                     gboolean     visible_vertical)
1295 {
1296   g_return_if_fail (GTK_IS_TOOL_ITEM (toolitem));
1297
1298   visible_vertical = visible_vertical != FALSE;
1299
1300   if (toolitem->priv->visible_vertical != visible_vertical)
1301     {
1302       toolitem->priv->visible_vertical = visible_vertical;
1303
1304       g_object_notify (G_OBJECT (toolitem), "visible-vertical");
1305
1306       gtk_widget_queue_resize (GTK_WIDGET (toolitem));
1307     }
1308 }
1309
1310 /**
1311  * gtk_tool_item_get_visible_vertical:
1312  * @tool_item: a #GtkToolItem 
1313  * 
1314  * Returns whether @tool_item is visible when the toolbar is docked vertically.
1315  * See gtk_tool_item_set_visible_vertical().
1316  * 
1317  * Return value: Whether @tool_item is visible when the toolbar is docked vertically
1318  * 
1319  * Since: 2.4
1320  **/
1321 gboolean
1322 gtk_tool_item_get_visible_vertical (GtkToolItem *toolitem)
1323 {
1324   g_return_val_if_fail (GTK_IS_TOOL_ITEM (toolitem), FALSE);
1325
1326   return toolitem->priv->visible_vertical;
1327 }
1328
1329 /**
1330  * gtk_tool_item_retrieve_proxy_menu_item:
1331  * @tool_item: a #GtkToolItem 
1332  * 
1333  * Returns the #GtkMenuItem that was last set by
1334  * gtk_tool_item_set_proxy_menu_item(), ie. the #GtkMenuItem
1335  * that is going to appear in the overflow menu.
1336  *
1337  * Return value: (transfer none): The #GtkMenuItem that is going to appear in the
1338  * overflow menu for @tool_item.
1339  *
1340  * Since: 2.4
1341  **/
1342 GtkWidget *
1343 gtk_tool_item_retrieve_proxy_menu_item (GtkToolItem *tool_item)
1344 {
1345   gboolean retval;
1346   
1347   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1348
1349   g_signal_emit (tool_item, toolitem_signals[CREATE_MENU_PROXY], 0,
1350                  &retval);
1351   
1352   return tool_item->priv->menu_item;
1353 }
1354
1355 /**
1356  * gtk_tool_item_get_proxy_menu_item:
1357  * @tool_item: a #GtkToolItem 
1358  * @menu_item_id: a string used to identify the menu item
1359  * 
1360  * If @menu_item_id matches the string passed to
1361  * gtk_tool_item_set_proxy_menu_item() return the corresponding #GtkMenuItem.
1362  *
1363  * Custom subclasses of #GtkToolItem should use this function to update
1364  * their menu item when the #GtkToolItem changes. That the
1365  * @menu_item_id<!-- -->s must match ensures that a #GtkToolItem will not
1366  * inadvertently change a menu item that they did not create.
1367  * 
1368  * Return value: The #GtkMenuItem passed to
1369  * gtk_tool_item_set_proxy_menu_item(), if the @menu_item_id<!-- -->s match.
1370  * 
1371  * Since: 2.4
1372  **/
1373 GtkWidget *
1374 gtk_tool_item_get_proxy_menu_item (GtkToolItem *tool_item,
1375                                    const gchar *menu_item_id)
1376 {
1377   g_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), NULL);
1378   g_return_val_if_fail (menu_item_id != NULL, NULL);
1379
1380   if (tool_item->priv->menu_item_id && strcmp (tool_item->priv->menu_item_id, menu_item_id) == 0)
1381     return tool_item->priv->menu_item;
1382
1383   return NULL;
1384 }
1385
1386 /**
1387  * gtk_tool_item_rebuild_menu:
1388  * @tool_item: a #GtkToolItem
1389  *
1390  * Calling this function signals to the toolbar that the
1391  * overflow menu item for @tool_item has changed. If the
1392  * overflow menu is visible when this function it called,
1393  * the menu will be rebuilt.
1394  *
1395  * The function must be called when the tool item changes what it
1396  * will do in response to the #GtkToolItem::create-menu-proxy signal.
1397  *
1398  * Since: 2.6
1399  */
1400 void
1401 gtk_tool_item_rebuild_menu (GtkToolItem *tool_item)
1402 {
1403   GtkWidget *widget;
1404   
1405   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1406
1407   widget = GTK_WIDGET (tool_item);
1408
1409   if (GTK_IS_TOOL_SHELL (widget->parent))
1410     gtk_tool_shell_rebuild_menu (GTK_TOOL_SHELL (widget->parent));
1411 }
1412
1413 /**
1414  * gtk_tool_item_set_proxy_menu_item:
1415  * @tool_item: a #GtkToolItem
1416  * @menu_item_id: a string used to identify @menu_item
1417  * @menu_item: a #GtkMenuItem to be used in the overflow menu
1418  * 
1419  * Sets the #GtkMenuItem used in the toolbar overflow menu. The
1420  * @menu_item_id is used to identify the caller of this function and
1421  * should also be used with gtk_tool_item_get_proxy_menu_item().
1422  * 
1423  * Since: 2.4
1424  **/
1425 void
1426 gtk_tool_item_set_proxy_menu_item (GtkToolItem *tool_item,
1427                                    const gchar *menu_item_id,
1428                                    GtkWidget   *menu_item)
1429 {
1430   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1431   g_return_if_fail (menu_item == NULL || GTK_IS_MENU_ITEM (menu_item));
1432   g_return_if_fail (menu_item_id != NULL);
1433
1434   g_free (tool_item->priv->menu_item_id);
1435       
1436   tool_item->priv->menu_item_id = g_strdup (menu_item_id);
1437
1438   if (tool_item->priv->menu_item != menu_item)
1439     {
1440       if (tool_item->priv->menu_item)
1441         g_object_unref (tool_item->priv->menu_item);
1442       
1443       if (menu_item)
1444         {
1445           g_object_ref_sink (menu_item);
1446
1447           gtk_widget_set_sensitive (menu_item,
1448                                     gtk_widget_get_sensitive (GTK_WIDGET (tool_item)));
1449         }
1450       
1451       tool_item->priv->menu_item = menu_item;
1452     }
1453 }
1454
1455 /**
1456  * gtk_tool_item_toolbar_reconfigured:
1457  * @tool_item: a #GtkToolItem
1458  *
1459  * Emits the signal #GtkToolItem::toolbar_reconfigured on @tool_item.
1460  * #GtkToolbar and other #GtkToolShell implementations use this function
1461  * to notify children, when some aspect of their configuration changes.
1462  *
1463  * Since: 2.14
1464  **/
1465 void
1466 gtk_tool_item_toolbar_reconfigured (GtkToolItem *tool_item)
1467 {
1468   /* The slightely inaccurate name "gtk_tool_item_toolbar_reconfigured" was
1469    * choosen over "gtk_tool_item_tool_shell_reconfigured", since the function
1470    * emits the "toolbar-reconfigured" signal, not "tool-shell-reconfigured".
1471    * Its not possible to rename the signal, and emitting another name than
1472    * indicated by the function name would be quite confusing. That's the
1473    * price of providing stable APIs.
1474    */
1475   g_return_if_fail (GTK_IS_TOOL_ITEM (tool_item));
1476
1477   g_signal_emit (tool_item, toolitem_signals[TOOLBAR_RECONFIGURED], 0);
1478   
1479   if (tool_item->priv->drag_window)
1480     gdk_window_raise (tool_item->priv->drag_window);
1481
1482   gtk_widget_queue_resize (GTK_WIDGET (tool_item));
1483 }
1484
1485 #define __GTK_TOOL_ITEM_C__
1486 #include "gtkaliasdef.c"