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