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