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