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