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