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