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