]> Pileus Git - ~andy/gtk/blob - gtk/gtkaction.c
Rearrange things so that setting multiple properties causes not more than
[~andy/gtk] / gtk / gtkaction.c
1 /*
2  * GTK - The GIMP Toolkit
3  * Copyright (C) 1998, 1999 Red Hat, Inc.
4  * All rights reserved.
5  *
6  * This Library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public License as
8  * published by the Free Software Foundation; either version 2 of the
9  * License, or (at your option) any later version.
10  *
11  * This Library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with the Gnome Library; see the file COPYING.LIB.  If not,
18  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 /*
23  * Author: James Henstridge <james@daa.com.au>
24  *
25  * Modified by the GTK+ Team and others 2003.  See the AUTHORS
26  * file for a list of people on the GTK+ Team.  See the ChangeLog
27  * files for a list of changes.  These files are distributed with
28  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
29  */
30
31 #include <config.h>
32
33 #include "gtkaction.h"
34 #include "gtkactiongroup.h"
35 #include "gtkaccellabel.h"
36 #include "gtkbutton.h"
37 #include "gtkiconfactory.h"
38 #include "gtkimage.h"
39 #include "gtkimagemenuitem.h"
40 #include "gtkintl.h"
41 #include "gtklabel.h"
42 #include "gtkmarshalers.h"
43 #include "gtkmenuitem.h"
44 #include "gtkstock.h"
45 #include "gtktearoffmenuitem.h"
46 #include "gtktoolbutton.h"
47 #include "gtktoolbar.h"
48 #include "gtkprivate.h"
49 #include "gtkalias.h"
50
51
52 #define GTK_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION, GtkActionPrivate))
53
54 struct _GtkActionPrivate 
55 {
56   gchar *name;
57   gchar *label;
58   gchar *short_label;
59   gchar *tooltip;
60   gchar *stock_id; /* stock icon */
61   gchar *icon_name; /* themed icon */
62
63   guint sensitive          : 1;
64   guint visible            : 1;
65   guint label_set          : 1; /* these two used so we can set label */
66   guint short_label_set    : 1; /* based on stock id */
67   guint visible_horizontal : 1;
68   guint visible_vertical   : 1;
69   guint is_important       : 1;
70   guint hide_if_empty      : 1;
71   guint visible_overflown  : 1;
72
73   /* accelerator */
74   guint          accel_count;
75   GtkAccelGroup *accel_group;
76   GClosure      *accel_closure;
77   GQuark         accel_quark;
78
79   GtkActionGroup *action_group;
80
81   /* list of proxy widgets */
82   GSList *proxies;
83 };
84
85 enum 
86 {
87   ACTIVATE,
88   LAST_SIGNAL
89 };
90
91 enum 
92 {
93   PROP_0,
94   PROP_NAME,
95   PROP_LABEL,
96   PROP_SHORT_LABEL,
97   PROP_TOOLTIP,
98   PROP_STOCK_ID,
99   PROP_ICON_NAME,
100   PROP_VISIBLE_HORIZONTAL,
101   PROP_VISIBLE_VERTICAL,
102   PROP_VISIBLE_OVERFLOWN,
103   PROP_IS_IMPORTANT,
104   PROP_HIDE_IF_EMPTY,
105   PROP_SENSITIVE,
106   PROP_VISIBLE,
107   PROP_ACTION_GROUP
108 };
109
110
111 static GQuark      accel_path_id  = 0;
112 static GQuark      quark_gtk_action_proxy  = 0;
113 static const gchar accel_path_key[] = "GtkAction::accel_path";
114 static const gchar gtk_action_proxy_key[] = "gtk-action";
115
116 G_DEFINE_TYPE (GtkAction, gtk_action, G_TYPE_OBJECT)
117
118 static void gtk_action_finalize     (GObject *object);
119 static void gtk_action_set_property (GObject         *object,
120                                      guint            prop_id,
121                                      const GValue    *value,
122                                      GParamSpec      *pspec);
123 static void gtk_action_get_property (GObject         *object,
124                                      guint            prop_id,
125                                      GValue          *value,
126                                      GParamSpec      *pspec);
127 static void gtk_action_set_action_group (GtkAction      *action,
128                                          GtkActionGroup *action_group);
129 static void gtk_action_set_is_important (GtkAction      *action,
130                                          gboolean        is_important);
131 static void gtk_action_set_label        (GtkAction      *action,
132                                          const gchar    *label);
133 static void gtk_action_set_short_label  (GtkAction      *action,
134                                          const gchar    *label);
135 static void gtk_action_set_visible_horizontal (GtkAction *action,
136                                                gboolean   visible_horizontal);
137 static void gtk_action_set_visible_vertical   (GtkAction *action,
138                                                gboolean   visible_vertical);
139 static void gtk_action_set_tooltip      (GtkAction      *action,
140                                          const gchar    *tooltip);
141 static void gtk_action_set_stock_id     (GtkAction      *action,
142                                          const gchar    *stock_id);
143 static void gtk_action_set_icon_name     (GtkAction     *action,
144                                          const gchar    *icon_name);
145 static void gtk_action_sync_tooltip     (GtkAction      *action,
146                                          GtkWidget      *proxy);
147
148 static GtkWidget *create_menu_item    (GtkAction *action);
149 static GtkWidget *create_tool_item    (GtkAction *action);
150 static void       connect_proxy       (GtkAction     *action,
151                                        GtkWidget     *proxy);
152 static void       disconnect_proxy    (GtkAction *action,
153                                        GtkWidget *proxy);
154 static void       closure_accel_activate (GClosure     *closure,
155                                           GValue       *return_value,
156                                           guint         n_param_values,
157                                           const GValue *param_values,
158                                           gpointer      invocation_hint,
159                                           gpointer      marshal_data);
160
161 static guint         action_signals[LAST_SIGNAL] = { 0 };
162
163
164 static void
165 gtk_action_class_init (GtkActionClass *klass)
166 {
167   GObjectClass *gobject_class;
168
169   accel_path_id = g_quark_from_static_string (accel_path_key);
170   quark_gtk_action_proxy = g_quark_from_static_string (gtk_action_proxy_key);
171
172   gobject_class = G_OBJECT_CLASS (klass);
173
174   gobject_class->finalize     = gtk_action_finalize;
175   gobject_class->set_property = gtk_action_set_property;
176   gobject_class->get_property = gtk_action_get_property;
177
178   klass->activate = NULL;
179
180   klass->create_menu_item = create_menu_item;
181   klass->create_tool_item = create_tool_item;
182   klass->connect_proxy = connect_proxy;
183   klass->disconnect_proxy = disconnect_proxy;
184
185   klass->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
186   klass->toolbar_item_type = GTK_TYPE_TOOL_BUTTON;
187
188   g_object_class_install_property (gobject_class,
189                                    PROP_NAME,
190                                    g_param_spec_string ("name",
191                                                         P_("Name"),
192                                                         P_("A unique name for the action."),
193                                                         NULL,
194                                                         GTK_PARAM_READWRITE | 
195                                                         G_PARAM_CONSTRUCT_ONLY));
196
197   /**
198    * GtkAction:label:
199    *
200    * The label used for menu items and buttons that activate
201    * this action. If the label is %NULL, GTK+ uses the stock 
202    * label specified via the stock-id property.
203    */
204   g_object_class_install_property (gobject_class,
205                                    PROP_LABEL,
206                                    g_param_spec_string ("label",
207                                                         P_("Label"),
208                                                         P_("The label used for menu items and buttons "
209                                                            "that activate this action."),
210                                                         NULL,
211                                                         GTK_PARAM_READWRITE));
212   g_object_class_install_property (gobject_class,
213                                    PROP_SHORT_LABEL,
214                                    g_param_spec_string ("short-label",
215                                                         P_("Short label"),
216                                                         P_("A shorter label that may be used on toolbar buttons."),
217                                                         NULL,
218                                                         GTK_PARAM_READWRITE));
219   g_object_class_install_property (gobject_class,
220                                    PROP_TOOLTIP,
221                                    g_param_spec_string ("tooltip",
222                                                         P_("Tooltip"),
223                                                         P_("A tooltip for this action."),
224                                                         NULL,
225                                                         GTK_PARAM_READWRITE));
226   g_object_class_install_property (gobject_class,
227                                    PROP_STOCK_ID,
228                                    g_param_spec_string ("stock-id",
229                                                         P_("Stock Icon"),
230                                                         P_("The stock icon displayed in widgets representing "
231                                                            "this action."),
232                                                         NULL,
233                                                         GTK_PARAM_READWRITE));
234   /**
235    * GtkAction:icon-name:
236    *
237    * The name of the icon from the icon theme. 
238    * Note that the stock icon is preferred, if
239    * the ::stock-id property holds the id of an
240    * existing stock icon.
241    *
242    * Since: 2.10
243    */
244   g_object_class_install_property (gobject_class,
245                                    PROP_ICON_NAME,
246                                    g_param_spec_string ("icon-name",
247                                                         P_("Icon Name"),
248                                                         P_("The name of the icon from the icon theme"),
249                                                         NULL,
250                                                         GTK_PARAM_READWRITE));
251   g_object_class_install_property (gobject_class,
252                                    PROP_VISIBLE_HORIZONTAL,
253                                    g_param_spec_boolean ("visible-horizontal",
254                                                          P_("Visible when horizontal"),
255                                                          P_("Whether the toolbar item is visible when the toolbar "
256                                                             "is in a horizontal orientation."),
257                                                          TRUE,
258                                                          GTK_PARAM_READWRITE));
259   /**
260    * GtkAction:visible-overflown:
261    *
262    * When %TRUE, toolitem proxies for this action are represented in the 
263    * toolbar overflow menu.
264    *
265    * Since: 2.6
266    */
267   g_object_class_install_property (gobject_class,
268                                    PROP_VISIBLE_OVERFLOWN,
269                                    g_param_spec_boolean ("visible-overflown",
270                                                          P_("Visible when overflown"),
271                                                          P_("When TRUE, toolitem proxies for this action "
272                                                             "are represented in the toolbar overflow menu."),
273                                                          TRUE,
274                                                          GTK_PARAM_READWRITE));
275   g_object_class_install_property (gobject_class,
276                                    PROP_VISIBLE_VERTICAL,
277                                    g_param_spec_boolean ("visible-vertical",
278                                                          P_("Visible when vertical"),
279                                                          P_("Whether the toolbar item is visible when the toolbar "
280                                                             "is in a vertical orientation."),
281                                                          TRUE,
282                                                          GTK_PARAM_READWRITE));
283   g_object_class_install_property (gobject_class,
284                                    PROP_IS_IMPORTANT,
285                                    g_param_spec_boolean ("is-important",
286                                                          P_("Is important"),
287                                                          P_("Whether the action is considered important. "
288                                                             "When TRUE, toolitem proxies for this action "
289                                                             "show text in GTK_TOOLBAR_BOTH_HORIZ mode."),
290                                                          FALSE,
291                                                          GTK_PARAM_READWRITE));
292   g_object_class_install_property (gobject_class,
293                                    PROP_HIDE_IF_EMPTY,
294                                    g_param_spec_boolean ("hide-if-empty",
295                                                          P_("Hide if empty"),
296                                                          P_("When TRUE, empty menu proxies for this action are hidden."),
297                                                          TRUE,
298                                                          GTK_PARAM_READWRITE));
299   g_object_class_install_property (gobject_class,
300                                    PROP_SENSITIVE,
301                                    g_param_spec_boolean ("sensitive",
302                                                          P_("Sensitive"),
303                                                          P_("Whether the action is enabled."),
304                                                          TRUE,
305                                                          GTK_PARAM_READWRITE));
306   g_object_class_install_property (gobject_class,
307                                    PROP_VISIBLE,
308                                    g_param_spec_boolean ("visible",
309                                                          P_("Visible"),
310                                                          P_("Whether the action is visible."),
311                                                          TRUE,
312                                                          GTK_PARAM_READWRITE));
313   g_object_class_install_property (gobject_class,
314                                    PROP_ACTION_GROUP,
315                                    g_param_spec_object ("action-group",
316                                                          P_("Action Group"),
317                                                          P_("The GtkActionGroup this GtkAction is associated with, or NULL (for internal use)."),
318                                                          GTK_TYPE_ACTION_GROUP,
319                                                          GTK_PARAM_READWRITE));
320
321   /**
322    * GtkAction::activate:
323    * @action: the #GtkAction
324    *
325    * The "activate" signal is emitted when the action is activated.
326    *
327    * Since: 2.4
328    */
329   action_signals[ACTIVATE] =
330     g_signal_new (I_("activate"),
331                   G_OBJECT_CLASS_TYPE (klass),
332                   G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
333                   G_STRUCT_OFFSET (GtkActionClass, activate),  NULL, NULL,
334                   g_cclosure_marshal_VOID__VOID,
335                   G_TYPE_NONE, 0);
336
337   g_type_class_add_private (gobject_class, sizeof (GtkActionPrivate));
338 }
339
340
341 static void
342 gtk_action_init (GtkAction *action)
343 {
344   action->private_data = GTK_ACTION_GET_PRIVATE (action);
345
346   action->private_data->name = NULL;
347   action->private_data->label = NULL;
348   action->private_data->short_label = NULL;
349   action->private_data->tooltip = NULL;
350   action->private_data->stock_id = NULL;
351   action->private_data->icon_name = NULL;
352   action->private_data->visible_horizontal = TRUE;
353   action->private_data->visible_vertical   = TRUE;
354   action->private_data->visible_overflown  = TRUE;
355   action->private_data->is_important = FALSE;
356   action->private_data->hide_if_empty = TRUE;
357
358   action->private_data->sensitive = TRUE;
359   action->private_data->visible = TRUE;
360
361   action->private_data->label_set = FALSE;
362   action->private_data->short_label_set = FALSE;
363
364   action->private_data->accel_count = 0;
365   action->private_data->accel_group = NULL;
366   action->private_data->accel_quark = 0;
367   action->private_data->accel_closure = 
368     g_closure_new_object (sizeof (GClosure), G_OBJECT (action));
369   g_closure_set_marshal (action->private_data->accel_closure, 
370                          closure_accel_activate);
371   g_closure_ref (action->private_data->accel_closure);
372   g_closure_sink (action->private_data->accel_closure);
373
374   action->private_data->action_group = NULL;
375
376   action->private_data->proxies = NULL;
377 }
378
379 /**
380  * gtk_action_new:
381  * @name: A unique name for the action
382  * @label: the label displayed in menu items and on buttons
383  * @tooltip: a tooltip for the action
384  * @stock_id: the stock icon to display in widgets representing the action
385  *
386  * Creates a new #GtkAction object. To add the action to a
387  * #GtkActionGroup and set the accelerator for the action,
388  * call gtk_action_group_add_action_with_accel().
389  * See <xref linkend="XML-UI"/> for information on allowed action
390  * names.
391  *
392  * Return value: a new #GtkAction
393  *
394  * Since: 2.4
395  */
396 GtkAction *
397 gtk_action_new (const gchar *name,
398                 const gchar *label,
399                 const gchar *tooltip,
400                 const gchar *stock_id)
401 {
402   GtkAction *action;
403
404   action = g_object_new (GTK_TYPE_ACTION,
405                          "name", name,
406                          "label", label,
407                          "tooltip", tooltip,
408                          "stock_id", stock_id,
409                          NULL);
410
411   return action;
412 }
413
414 static void
415 gtk_action_finalize (GObject *object)
416 {
417   GtkAction *action;
418   action = GTK_ACTION (object);
419
420   g_free (action->private_data->name);
421   g_free (action->private_data->label);
422   g_free (action->private_data->short_label);
423   g_free (action->private_data->tooltip);
424   g_free (action->private_data->stock_id);
425   g_free (action->private_data->icon_name);
426
427   g_closure_unref (action->private_data->accel_closure);
428   if (action->private_data->accel_group)
429     g_object_unref (action->private_data->accel_group);
430
431   G_OBJECT_CLASS (gtk_action_parent_class)->finalize (object);  
432 }
433
434 static void
435 gtk_action_set_property (GObject         *object,
436                          guint            prop_id,
437                          const GValue    *value,
438                          GParamSpec      *pspec)
439 {
440   GtkAction *action;
441   gchar *tmp;
442   
443   action = GTK_ACTION (object);
444
445   switch (prop_id)
446     {
447     case PROP_NAME:
448       tmp = action->private_data->name;
449       action->private_data->name = g_value_dup_string (value);
450       g_free (tmp);
451       break;
452     case PROP_LABEL:
453       gtk_action_set_label (action, g_value_get_string (value));
454       break;
455     case PROP_SHORT_LABEL:
456       gtk_action_set_short_label (action, g_value_get_string (value));
457       break;
458     case PROP_TOOLTIP:
459       gtk_action_set_tooltip (action, g_value_get_string (value));
460       break;
461     case PROP_STOCK_ID:
462       gtk_action_set_stock_id (action, g_value_get_string (value));
463       break;
464     case PROP_ICON_NAME:
465       gtk_action_set_icon_name (action, g_value_get_string (value));
466       break;
467     case PROP_VISIBLE_HORIZONTAL:
468       gtk_action_set_visible_horizontal (action, g_value_get_boolean (value));
469       break;
470     case PROP_VISIBLE_VERTICAL:
471       gtk_action_set_visible_vertical (action, g_value_get_boolean (value));
472       break;
473     case PROP_VISIBLE_OVERFLOWN:
474       action->private_data->visible_overflown = g_value_get_boolean (value);
475       break;
476     case PROP_IS_IMPORTANT:
477       gtk_action_set_is_important (action, g_value_get_boolean (value));
478       break;
479     case PROP_HIDE_IF_EMPTY:
480       action->private_data->hide_if_empty = g_value_get_boolean (value);
481       break;
482     case PROP_SENSITIVE:
483       gtk_action_set_sensitive (action, g_value_get_boolean (value));
484       break;
485     case PROP_VISIBLE:
486       gtk_action_set_visible (action, g_value_get_boolean (value));
487       break;
488     case PROP_ACTION_GROUP:
489       gtk_action_set_action_group (action, g_value_get_object (value));
490       break;
491     default:
492       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
493       break;
494     }
495 }
496
497 static void
498 gtk_action_get_property (GObject    *object,
499                          guint       prop_id,
500                          GValue     *value,
501                          GParamSpec *pspec)
502 {
503   GtkAction *action;
504
505   action = GTK_ACTION (object);
506
507   switch (prop_id)
508     {
509     case PROP_NAME:
510       g_value_set_string (value, action->private_data->name);
511       break;
512     case PROP_LABEL:
513       g_value_set_string (value, action->private_data->label);
514       break;
515     case PROP_SHORT_LABEL:
516       g_value_set_string (value, action->private_data->short_label);
517       break;
518     case PROP_TOOLTIP:
519       g_value_set_string (value, action->private_data->tooltip);
520       break;
521     case PROP_STOCK_ID:
522       g_value_set_string (value, action->private_data->stock_id);
523       break;
524     case PROP_ICON_NAME:
525       g_value_set_string (value, action->private_data->icon_name);
526       break;
527     case PROP_VISIBLE_HORIZONTAL:
528       g_value_set_boolean (value, action->private_data->visible_horizontal);
529       break;
530     case PROP_VISIBLE_VERTICAL:
531       g_value_set_boolean (value, action->private_data->visible_vertical);
532       break;
533     case PROP_VISIBLE_OVERFLOWN:
534       g_value_set_boolean (value, action->private_data->visible_overflown);
535       break;
536     case PROP_IS_IMPORTANT:
537       g_value_set_boolean (value, action->private_data->is_important);
538       break;
539     case PROP_HIDE_IF_EMPTY:
540       g_value_set_boolean (value, action->private_data->hide_if_empty);
541       break;
542     case PROP_SENSITIVE:
543       g_value_set_boolean (value, action->private_data->sensitive);
544       break;
545     case PROP_VISIBLE:
546       g_value_set_boolean (value, action->private_data->visible);
547       break;
548     case PROP_ACTION_GROUP:
549       g_value_set_object (value, action->private_data->action_group);
550       break;
551     default:
552       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
553       break;
554     }
555 }
556
557 static GtkWidget *
558 create_menu_item (GtkAction *action)
559 {
560   GType menu_item_type;
561
562   menu_item_type = GTK_ACTION_GET_CLASS (action)->menu_item_type;
563
564   return g_object_new (menu_item_type, NULL);
565 }
566
567 static GtkWidget *
568 create_tool_item (GtkAction *action)
569 {
570   GType toolbar_item_type;
571
572   toolbar_item_type = GTK_ACTION_GET_CLASS (action)->toolbar_item_type;
573
574   return g_object_new (toolbar_item_type, NULL);
575 }
576
577 static void
578 remove_proxy (GtkAction *action,
579               GtkWidget *proxy)
580 {
581   if (GTK_IS_MENU_ITEM (proxy))
582     gtk_action_disconnect_accelerator (action);
583   
584   action->private_data->proxies = g_slist_remove (action->private_data->proxies, proxy);
585 }
586
587 /**
588  * _gtk_action_sync_menu_visible:
589  * @action: a #GtkAction, or %NULL to determine the action from @proxy
590  * @proxy: a proxy menu item
591  * @empty: whether the submenu attached to @proxy is empty
592  * 
593  * Updates the visibility of @proxy from the visibility of @action
594  * according to the following rules:
595  * <itemizedlist>
596  * <listitem><para>if @action is invisible, @proxy is too
597  * </para></listitem>
598  * <listitem><para>if @empty is %TRUE, hide @proxy unless the "hide-if-empty" 
599  *   property of @action indicates otherwise
600  * </para></listitem>
601  * </itemizedlist>
602  * 
603  * This function is used in the implementation of #GtkUIManager.
604  **/
605 void
606 _gtk_action_sync_menu_visible (GtkAction *action,
607                                GtkWidget *proxy,
608                                gboolean   empty)
609 {
610   gboolean visible, hide_if_empty;
611
612   g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
613   g_return_if_fail (action == NULL || GTK_IS_ACTION (action));
614
615   if (action == NULL)
616     action = g_object_get_qdata (G_OBJECT (proxy), quark_gtk_action_proxy);
617
618   visible = gtk_action_is_visible (action);
619   hide_if_empty = action->private_data->hide_if_empty;
620
621   if (visible && !(empty && hide_if_empty))
622     gtk_widget_show (proxy);
623   else
624     gtk_widget_hide (proxy);
625 }
626
627 gboolean _gtk_menu_is_empty (GtkWidget *menu);
628
629 static gboolean
630 gtk_action_create_menu_proxy (GtkToolItem *tool_item, 
631                               GtkAction   *action)
632 {
633   GtkWidget *menu_item;
634   
635   if (action->private_data->visible_overflown)
636     {
637       menu_item = gtk_action_create_menu_item (action);
638
639       g_object_ref_sink (menu_item);
640       
641       gtk_tool_item_set_proxy_menu_item (tool_item, 
642                                          "gtk-action-menu-item", menu_item);
643       g_object_unref (menu_item);
644     }
645   else
646     gtk_tool_item_set_proxy_menu_item (tool_item, 
647                                        "gtk-action-menu-item", NULL);
648
649   return TRUE;
650 }
651
652 static void
653 connect_proxy (GtkAction     *action, 
654                GtkWidget     *proxy)
655 {
656   g_object_ref (action);
657   g_object_set_qdata_full (G_OBJECT (proxy), quark_gtk_action_proxy, action,
658                            g_object_unref);
659
660   /* add this widget to the list of proxies */
661   action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy);
662   g_object_weak_ref (G_OBJECT (proxy), (GWeakNotify)remove_proxy, action);
663   
664   gtk_widget_set_sensitive (proxy, gtk_action_is_sensitive (action));
665   if (gtk_action_is_visible (action))
666     gtk_widget_show (proxy);
667   else
668     gtk_widget_hide (proxy);
669   gtk_widget_set_no_show_all (proxy, TRUE);
670
671   if (GTK_IS_MENU_ITEM (proxy))
672     {
673       GtkWidget *label;
674       /* menu item specific synchronisers ... */
675       
676       if (action->private_data->accel_quark)
677         {
678           gtk_action_connect_accelerator (action);
679           gtk_menu_item_set_accel_path (GTK_MENU_ITEM (proxy),
680                                         g_quark_to_string (action->private_data->accel_quark));
681         }
682       
683       label = GTK_BIN (proxy)->child;
684
685       /* make sure label is a label */
686       if (label && !GTK_IS_LABEL (label))
687         {
688           gtk_container_remove (GTK_CONTAINER (proxy), label);
689           label = NULL;
690         }
691
692       if (!label)
693         label = g_object_new (GTK_TYPE_ACCEL_LABEL,
694                               "use-underline", TRUE,
695                               "xalign", 0.0,
696                               "visible", TRUE,
697                               "parent", proxy,
698                               NULL);
699       
700       if (GTK_IS_ACCEL_LABEL (label) && action->private_data->accel_quark)
701         g_object_set (label,
702                       "accel-closure", action->private_data->accel_closure,
703                       NULL);
704
705       gtk_label_set_label (GTK_LABEL (label), action->private_data->label);
706
707       if (GTK_IS_IMAGE_MENU_ITEM (proxy))
708         {
709           GtkWidget *image;
710
711           image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
712           if (image && !GTK_IS_IMAGE (image))
713             {
714               gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), NULL);
715               image = NULL;
716             }
717           if (!image)
718             {
719               image = gtk_image_new ();
720               gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy),
721                                              image);
722               gtk_widget_show (image);
723             }
724           
725           if (action->private_data->stock_id &&
726               gtk_icon_factory_lookup_default (action->private_data->stock_id))
727             gtk_image_set_from_stock (GTK_IMAGE (image),
728                                       action->private_data->stock_id, GTK_ICON_SIZE_MENU);
729           else if (action->private_data->icon_name)
730             gtk_image_set_from_icon_name (GTK_IMAGE (image),
731                                           action->private_data->icon_name, GTK_ICON_SIZE_MENU);
732         }
733       
734       if (gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)) == NULL)
735         g_signal_connect_object (proxy, "activate",
736                                  G_CALLBACK (gtk_action_activate), action,
737                                  G_CONNECT_SWAPPED);
738
739     }
740   else if (GTK_IS_TOOL_ITEM (proxy))
741     {
742       /* toolbar button specific synchronisers ... */
743       if (GTK_IS_TOOL_BUTTON (proxy))
744         {
745           g_object_set (proxy,
746                         "visible-horizontal", action->private_data->visible_horizontal,
747                         "visible-vertical", action->private_data->visible_vertical,
748                         "is-important", action->private_data->is_important,
749                         "label", action->private_data->short_label,
750                         "use-underline", TRUE,
751                         "stock-id", action->private_data->stock_id,
752                         "icon-name", action->private_data->icon_name,
753                         NULL);
754
755           g_signal_connect_object (proxy, "clicked",
756                                    G_CALLBACK (gtk_action_activate), action,
757                                    G_CONNECT_SWAPPED);
758         }
759       else 
760         {
761            g_object_set (proxy,
762                          "visible-horizontal", action->private_data->visible_horizontal,
763                          "visible-vertical", action->private_data->visible_vertical,
764                          "is-important", action->private_data->is_important,
765                          NULL);
766        }
767
768       gtk_action_sync_tooltip (action, proxy);
769
770       g_signal_connect_object (proxy, "create_menu_proxy",
771                                G_CALLBACK (gtk_action_create_menu_proxy),
772                                action, 0);
773
774       gtk_tool_item_rebuild_menu (GTK_TOOL_ITEM (proxy));
775     }
776   else if (GTK_IS_BUTTON (proxy))
777     {
778       /* button specific synchronisers ... */
779       if (gtk_button_get_use_stock (GTK_BUTTON (proxy)))
780         {
781           /* synchronise stock-id */
782           g_object_set (proxy,
783                         "label", action->private_data->stock_id,
784                         NULL);
785         }
786       else 
787         {
788           if (GTK_BIN (proxy)->child == NULL || 
789               GTK_IS_LABEL (GTK_BIN (proxy)->child))
790             {
791               /* synchronise the label */
792               g_object_set (proxy,
793                             "label", action->private_data->short_label,
794                             "use-underline", TRUE,
795                             NULL);
796             }
797         }
798       /* we leave the button alone if there is a custom child */
799       g_signal_connect_object (proxy, "clicked",
800                                G_CALLBACK (gtk_action_activate), action,
801                                G_CONNECT_SWAPPED);
802     }
803
804   if (action->private_data->action_group)
805     _gtk_action_group_emit_connect_proxy (action->private_data->action_group, action, proxy);
806 }
807
808 static void
809 disconnect_proxy (GtkAction *action, 
810                   GtkWidget *proxy)
811 {
812   g_object_set_qdata (G_OBJECT (proxy), quark_gtk_action_proxy, NULL);
813
814   g_object_weak_unref (G_OBJECT (proxy), (GWeakNotify)remove_proxy, action);
815   remove_proxy (action, proxy);
816
817   /* disconnect the activate handler */
818   g_signal_handlers_disconnect_by_func (proxy,
819                                         G_CALLBACK (gtk_action_activate),
820                                         action);
821
822   /* toolbar button specific synchronisers ... */
823   g_signal_handlers_disconnect_by_func (proxy,
824                                         G_CALLBACK (gtk_action_create_menu_proxy),
825                                         action);
826
827   if (action->private_data->action_group)
828     _gtk_action_group_emit_disconnect_proxy (action->private_data->action_group, action, proxy);
829 }
830
831 void
832 _gtk_action_emit_activate (GtkAction *action)
833 {
834   GtkActionGroup *group = action->private_data->action_group;
835
836   if (group != NULL) 
837     {
838       g_object_ref (group);
839       _gtk_action_group_emit_pre_activate (group, action);
840     }
841
842     g_signal_emit (action, action_signals[ACTIVATE], 0);
843
844   if (group != NULL) 
845     {
846       _gtk_action_group_emit_post_activate (group, action);
847       g_object_unref (group);
848     }
849 }
850
851 /**
852  * gtk_action_activate:
853  * @action: the action object
854  *
855  * Emits the "activate" signal on the specified action, if it isn't 
856  * insensitive. This gets called by the proxy widgets when they get 
857  * activated.
858  *
859  * It can also be used to manually activate an action.
860  *
861  * Since: 2.4
862  */
863 void
864 gtk_action_activate (GtkAction *action)
865 {
866   g_return_if_fail (GTK_IS_ACTION (action));
867   
868   if (gtk_action_is_sensitive (action))
869     _gtk_action_emit_activate (action);
870 }
871
872 /**
873  * gtk_action_create_icon:
874  * @action: the action object
875  * @icon_size: the size of the icon that should be created.
876  *
877  * This function is intended for use by action implementations to
878  * create icons displayed in the proxy widgets.
879  *
880  * Returns: a widget that displays the icon for this action.
881  *
882  * Since: 2.4
883  */
884 GtkWidget *
885 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
886 {
887   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
888
889   if (action->private_data->stock_id)
890     return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
891   else if (action->private_data->icon_name)
892     return gtk_image_new_from_icon_name (action->private_data->icon_name, icon_size);
893   else
894     return NULL;
895 }
896
897 /**
898  * gtk_action_create_menu_item:
899  * @action: the action object
900  *
901  * Creates a menu item widget that proxies for the given action.
902  *
903  * Returns: a menu item connected to the action.
904  *
905  * Since: 2.4
906  */
907 GtkWidget *
908 gtk_action_create_menu_item (GtkAction *action)
909 {
910   GtkWidget *menu_item;
911
912   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
913
914   menu_item = (* GTK_ACTION_GET_CLASS (action)->create_menu_item) (action);
915
916   (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, menu_item);
917
918   return menu_item;
919 }
920
921 /**
922  * gtk_action_create_tool_item:
923  * @action: the action object
924  *
925  * Creates a toolbar item widget that proxies for the given action.
926  *
927  * Returns: a toolbar item connected to the action.
928  *
929  * Since: 2.4
930  */
931 GtkWidget *
932 gtk_action_create_tool_item (GtkAction *action)
933 {
934   GtkWidget *button;
935
936   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
937
938   button = (* GTK_ACTION_GET_CLASS (action)->create_tool_item) (action);
939
940   (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, button);
941
942   return button;
943 }
944
945 /**
946  * gtk_action_connect_proxy:
947  * @action: the action object
948  * @proxy: the proxy widget
949  *
950  * Connects a widget to an action object as a proxy.  Synchronises 
951  * various properties of the action with the widget (such as label 
952  * text, icon, tooltip, etc), and attaches a callback so that the 
953  * action gets activated when the proxy widget does.
954  *
955  * If the widget is already connected to an action, it is disconnected
956  * first.
957  *
958  * Since: 2.4
959  */
960 void
961 gtk_action_connect_proxy (GtkAction *action,
962                           GtkWidget *proxy)
963 {
964   GtkAction *prev_action;
965
966   g_return_if_fail (GTK_IS_ACTION (action));
967   g_return_if_fail (GTK_IS_WIDGET (proxy));
968
969   prev_action = g_object_get_qdata (G_OBJECT (proxy), quark_gtk_action_proxy);
970
971   if (prev_action)
972     (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (prev_action, proxy);  
973
974   (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, proxy);
975 }
976
977 /**
978  * gtk_action_disconnect_proxy:
979  * @action: the action object
980  * @proxy: the proxy widget
981  *
982  * Disconnects a proxy widget from an action.  
983  * Does <emphasis>not</emphasis> destroy the widget, however.
984  *
985  * Since: 2.4
986  */
987 void
988 gtk_action_disconnect_proxy (GtkAction *action,
989                              GtkWidget *proxy)
990 {
991   g_return_if_fail (GTK_IS_ACTION (action));
992   g_return_if_fail (GTK_IS_WIDGET (proxy));
993
994   g_return_if_fail (g_object_get_qdata (G_OBJECT (proxy), quark_gtk_action_proxy) == action);
995
996   (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (action, proxy);  
997 }
998
999 /**
1000  * gtk_action_get_proxies:
1001  * @action: the action object
1002  * 
1003  * Returns the proxy widgets for an action.
1004  * See also gtk_widget_get_action().
1005  * 
1006  * Return value: a #GSList of proxy widgets. The list is owned by GTK+
1007  * and must not be modified.
1008  *
1009  * Since: 2.4
1010  **/
1011 GSList*
1012 gtk_action_get_proxies (GtkAction *action)
1013 {
1014   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1015
1016   return action->private_data->proxies;
1017 }
1018
1019
1020 /**
1021  * gtk_widget_get_action:
1022  * @widget: a #GtkWidget
1023  *
1024  * Returns the #GtkAction that @widget is a proxy for. 
1025  * See also gtk_action_get_proxies().
1026  *
1027  * Returns: the action that a widget is a proxy for, or
1028  *  %NULL, if it is not attached to an action.
1029  *
1030  * Since: 2.10
1031  */
1032 GtkAction*
1033 gtk_widget_get_action (GtkWidget *widget)
1034 {
1035   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
1036   
1037   return g_object_get_qdata (G_OBJECT (widget), quark_gtk_action_proxy);
1038 }
1039
1040
1041 /**
1042  * gtk_action_get_name:
1043  * @action: the action object
1044  * 
1045  * Returns the name of the action.
1046  * 
1047  * Return value: the name of the action. The string belongs to GTK+ and should not
1048  *   be freed.
1049  *
1050  * Since: 2.4
1051  **/
1052 G_CONST_RETURN gchar *
1053 gtk_action_get_name (GtkAction *action)
1054 {
1055   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1056
1057   return action->private_data->name;
1058 }
1059
1060 /**
1061  * gtk_action_is_sensitive:
1062  * @action: the action object
1063  * 
1064  * Returns whether the action is effectively sensitive.
1065  *
1066  * Return value: %TRUE if the action and its associated action group 
1067  * are both sensitive.
1068  *
1069  * Since: 2.4
1070  **/
1071 gboolean
1072 gtk_action_is_sensitive (GtkAction *action)
1073 {
1074   GtkActionPrivate *priv;
1075   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1076
1077   priv = action->private_data;
1078   return priv->sensitive &&
1079     (priv->action_group == NULL ||
1080      gtk_action_group_get_sensitive (priv->action_group));
1081 }
1082
1083 /**
1084  * gtk_action_get_sensitive:
1085  * @action: the action object
1086  * 
1087  * Returns whether the action itself is sensitive. Note that this doesn't 
1088  * necessarily mean effective sensitivity. See gtk_action_is_sensitive() 
1089  * for that.
1090  *
1091  * Return value: %TRUE if the action itself is sensitive.
1092  *
1093  * Since: 2.4
1094  **/
1095 gboolean
1096 gtk_action_get_sensitive (GtkAction *action)
1097 {
1098   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1099
1100   return action->private_data->sensitive;
1101 }
1102
1103 void
1104 _gtk_action_sync_sensitive (GtkAction *action)
1105 {
1106   GSList *p;
1107   GtkWidget *proxy;
1108   gboolean sensitive;
1109
1110   sensitive = gtk_action_is_sensitive (action);
1111
1112   for (p = action->private_data->proxies; p; p = p->next)
1113     {
1114       proxy = (GtkWidget *)p->data;
1115       gtk_widget_set_sensitive (proxy, sensitive);
1116     }      
1117 }
1118
1119 /**
1120  * gtk_action_set_sensitive:
1121  * @action: the action object
1122  * @sensitive: %TRUE to make the action sensitive
1123  * 
1124  * Sets the ::sensitive property of the action to @sensitive. Note that 
1125  * this doesn't necessarily mean effective sensitivity. See 
1126  * gtk_action_is_sensitive() 
1127  * for that.
1128  *
1129  * Since: 2.6
1130  **/
1131 void
1132 gtk_action_set_sensitive (GtkAction *action,
1133                           gboolean   sensitive)
1134 {
1135   g_return_if_fail (GTK_IS_ACTION (action));
1136
1137   sensitive = sensitive != FALSE;
1138   
1139   if (action->private_data->sensitive != sensitive)
1140     {
1141       action->private_data->sensitive = sensitive;
1142
1143       _gtk_action_sync_sensitive (action);
1144
1145       g_object_notify (G_OBJECT (action), "sensitive");
1146     }
1147 }
1148
1149 /**
1150  * gtk_action_is_visible:
1151  * @action: the action object
1152  * 
1153  * Returns whether the action is effectively visible.
1154  *
1155  * Return value: %TRUE if the action and its associated action group 
1156  * are both visible.
1157  *
1158  * Since: 2.4
1159  **/
1160 gboolean
1161 gtk_action_is_visible (GtkAction *action)
1162 {
1163   GtkActionPrivate *priv;
1164   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1165
1166   priv = action->private_data;
1167   return priv->visible &&
1168     (priv->action_group == NULL ||
1169      gtk_action_group_get_visible (priv->action_group));
1170 }
1171
1172 /**
1173  * gtk_action_get_visible:
1174  * @action: the action object
1175  * 
1176  * Returns whether the action itself is visible. Note that this doesn't 
1177  * necessarily mean effective visibility. See gtk_action_is_sensitive() 
1178  * for that.
1179  *
1180  * Return value: %TRUE if the action itself is visible.
1181  *
1182  * Since: 2.4
1183  **/
1184 gboolean
1185 gtk_action_get_visible (GtkAction *action)
1186 {
1187   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1188
1189   return action->private_data->visible;
1190 }
1191
1192 void
1193 _gtk_action_sync_visible (GtkAction *action)
1194 {
1195   GSList *p;
1196   GtkWidget *proxy;
1197   GtkWidget *menu;
1198   gboolean visible;
1199
1200   visible = gtk_action_is_visible (action);
1201     
1202   for (p = action->private_data->proxies; p; p = p->next)
1203     {
1204       proxy = (GtkWidget *)p->data;
1205
1206       if (GTK_IS_MENU_ITEM (proxy))
1207         {
1208           menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy));
1209           
1210           _gtk_action_sync_menu_visible (action, proxy, _gtk_menu_is_empty (menu));
1211         }
1212       else
1213         {
1214           if (visible)
1215             gtk_widget_show (proxy);
1216           else
1217             gtk_widget_hide (proxy);
1218         }
1219     } 
1220 }
1221
1222 /**
1223  * gtk_action_set_visible:
1224  * @action: the action object
1225  * @visible: %TRUE to make the action visible
1226  * 
1227  * Sets the ::visible property of the action to @visible. Note that 
1228  * this doesn't necessarily mean effective visibility. See 
1229  * gtk_action_is_visible() 
1230  * for that.
1231  *
1232  * Since: 2.6
1233  **/
1234 void
1235 gtk_action_set_visible (GtkAction *action,
1236                         gboolean   visible)
1237 {
1238   g_return_if_fail (GTK_IS_ACTION (action));
1239
1240   visible = visible != FALSE;
1241   
1242   if (action->private_data->visible != visible)
1243     {
1244       action->private_data->visible = visible;
1245
1246       _gtk_action_sync_visible (action);
1247
1248       g_object_notify (G_OBJECT (action), "visible");
1249     }
1250 }
1251
1252 static void 
1253 gtk_action_set_is_important (GtkAction *action,
1254                              gboolean   is_important)
1255 {
1256   GSList *p;
1257   GtkWidget *proxy;
1258
1259   is_important = is_important != FALSE;
1260   
1261   if (action->private_data->is_important != is_important)
1262     {
1263       action->private_data->is_important = is_important;
1264
1265       for (p = action->private_data->proxies; p; p = p->next)
1266         {
1267           proxy = (GtkWidget *)p->data;
1268
1269           if (GTK_IS_TOOL_ITEM (proxy))
1270             gtk_tool_item_set_is_important (GTK_TOOL_ITEM (proxy),
1271                                             is_important);
1272         }
1273       
1274       g_object_notify (G_OBJECT (action), "is-important");
1275     }  
1276 }
1277
1278 static void 
1279 gtk_action_set_label (GtkAction   *action,
1280                       const gchar *label)
1281 {
1282   GSList *p;
1283   GtkWidget *proxy, *child;
1284   gchar *tmp;
1285   
1286   tmp = action->private_data->label;
1287   action->private_data->label = g_strdup (label);
1288   g_free (tmp);
1289   action->private_data->label_set = (action->private_data->label != NULL);
1290   /* if label is unset, then use the label from the stock item */
1291   if (!action->private_data->label_set && action->private_data->stock_id)
1292     {
1293       GtkStockItem stock_item;
1294       
1295       if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1296         action->private_data->label = g_strdup (stock_item.label);
1297     }
1298   
1299   for (p = action->private_data->proxies; p; p = p->next)
1300     {
1301       proxy = (GtkWidget *)p->data;
1302       
1303       if (GTK_IS_MENU_ITEM (proxy))
1304         {
1305           child = GTK_BIN (proxy)->child;
1306           
1307           if (GTK_IS_LABEL (child))
1308             gtk_label_set_label (GTK_LABEL (child), 
1309                                  action->private_data->label);
1310         }
1311     }
1312   
1313   g_object_notify (G_OBJECT (action), "label");
1314   
1315   /* if short_label is unset, set short_label=label */
1316   if (!action->private_data->short_label_set)
1317     {
1318       gtk_action_set_short_label (action, action->private_data->label);
1319       action->private_data->short_label_set = FALSE;
1320     }
1321 }
1322
1323 static void 
1324 gtk_action_set_short_label (GtkAction   *action,
1325                             const gchar *label)
1326 {
1327   GSList *p;
1328   GtkWidget *proxy, *child;
1329   gchar *tmp;
1330
1331   tmp = action->private_data->short_label;
1332   action->private_data->short_label = g_strdup (label);
1333   g_free (tmp);
1334   action->private_data->short_label_set = (action->private_data->short_label != NULL);
1335   /* if short_label is unset, then use the value of label */
1336   if (!action->private_data->short_label_set)
1337     action->private_data->short_label = g_strdup (action->private_data->label);
1338
1339   for (p = action->private_data->proxies; p; p = p->next)
1340     {
1341       proxy = (GtkWidget *)p->data;
1342
1343       if (GTK_IS_TOOL_BUTTON (proxy))
1344         gtk_tool_button_set_label (GTK_TOOL_BUTTON (proxy), 
1345                                    action->private_data->label);
1346       else if (GTK_IS_BUTTON (proxy) &&
1347                !gtk_button_get_use_stock (GTK_BUTTON (proxy)))
1348         {
1349           child = GTK_BIN (proxy)->child;
1350           
1351           if (child == NULL || GTK_IS_LABEL (child))
1352             gtk_button_set_label (GTK_BUTTON (proxy), 
1353                                   action->private_data->label);
1354         }
1355     }
1356
1357   g_object_notify (G_OBJECT (action), "short-label");
1358 }
1359
1360 static void 
1361 gtk_action_set_visible_horizontal (GtkAction *action,
1362                                    gboolean   visible_horizontal)
1363 {
1364   GSList *p;
1365   GtkWidget *proxy;
1366
1367   visible_horizontal = visible_horizontal != FALSE;
1368   
1369   if (action->private_data->visible_horizontal != visible_horizontal)
1370     {
1371       action->private_data->visible_horizontal = visible_horizontal;
1372
1373       for (p = action->private_data->proxies; p; p = p->next)
1374         {
1375           proxy = (GtkWidget *)p->data;
1376
1377           if (GTK_IS_TOOL_ITEM (proxy))
1378             gtk_tool_item_set_visible_horizontal (GTK_TOOL_ITEM (proxy),
1379                                                   visible_horizontal);
1380         }
1381       
1382       g_object_notify (G_OBJECT (action), "visible-horizontal");
1383     }  
1384 }
1385
1386 static void 
1387 gtk_action_set_visible_vertical (GtkAction *action,
1388                                  gboolean   visible_vertical)
1389 {
1390   GSList *p;
1391   GtkWidget *proxy;
1392
1393   visible_vertical = visible_vertical != FALSE;
1394   
1395   if (action->private_data->visible_vertical != visible_vertical)
1396     {
1397       action->private_data->visible_vertical = visible_vertical;
1398
1399       for (p = action->private_data->proxies; p; p = p->next)
1400         {
1401           proxy = (GtkWidget *)p->data;
1402
1403           if (GTK_IS_TOOL_ITEM (proxy))
1404             gtk_tool_item_set_visible_vertical (GTK_TOOL_ITEM (proxy),
1405                                                 visible_vertical);
1406         }
1407       
1408       g_object_notify (G_OBJECT (action), "visible-vertical");
1409     }  
1410 }
1411
1412 static void 
1413 gtk_action_sync_tooltip (GtkAction *action,
1414                          GtkWidget *proxy)
1415 {
1416   GtkWidget *parent;
1417
1418   parent = gtk_widget_get_parent (proxy);
1419   
1420   if (GTK_IS_TOOL_ITEM (proxy) && GTK_IS_TOOLBAR (parent))
1421     gtk_tool_item_set_tooltip (GTK_TOOL_ITEM (proxy), 
1422                                GTK_TOOLBAR (parent)->tooltips,
1423                                action->private_data->tooltip,
1424                                NULL);
1425 }
1426
1427 static void 
1428 gtk_action_set_tooltip (GtkAction   *action,
1429                         const gchar *tooltip)
1430 {
1431   GSList *p;
1432   GtkWidget *proxy;
1433   gchar *tmp;
1434
1435   tmp = action->private_data->tooltip;
1436   action->private_data->tooltip = g_strdup (tooltip);
1437   g_free (tmp);
1438
1439   for (p = action->private_data->proxies; p; p = p->next)
1440     {
1441       proxy = (GtkWidget *)p->data;
1442       
1443       gtk_action_sync_tooltip (action, proxy);
1444     }
1445
1446   g_object_notify (G_OBJECT (action), "tooltip");
1447 }
1448
1449 static void 
1450 gtk_action_set_stock_id (GtkAction   *action,
1451                          const gchar *stock_id)
1452 {
1453   GSList *p;
1454   GtkWidget *proxy, *image;
1455   gchar *tmp;
1456   
1457   tmp = action->private_data->stock_id;
1458   action->private_data->stock_id = g_strdup (stock_id);
1459   g_free (tmp);
1460
1461   for (p = action->private_data->proxies; p; p = p->next)
1462     {
1463       proxy = (GtkWidget *)p->data;
1464       
1465       if (GTK_IS_IMAGE_MENU_ITEM (proxy))
1466         {
1467           image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
1468           
1469           if (GTK_IS_IMAGE (image))
1470             gtk_image_set_from_stock (GTK_IMAGE (image),
1471                                       action->private_data->stock_id, GTK_ICON_SIZE_MENU);
1472         } 
1473       else if (GTK_IS_TOOL_BUTTON (proxy))
1474         {
1475           gtk_tool_button_set_stock_id (GTK_TOOL_BUTTON (proxy),
1476                                         action->private_data->stock_id);
1477         }
1478       else if (GTK_IS_BUTTON (proxy) &&
1479                gtk_button_get_use_stock (GTK_BUTTON (proxy)))
1480         {
1481           gtk_button_set_label (GTK_BUTTON (proxy),
1482                                 action->private_data->stock_id);
1483         }
1484     }
1485
1486   g_object_notify (G_OBJECT (action), "stock-id");
1487   
1488   /* update label and short_label if appropriate */
1489   if (!action->private_data->label_set)
1490     {
1491       GtkStockItem stock_item;
1492       
1493       if (action->private_data->stock_id &&
1494           gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1495         gtk_action_set_label (action, stock_item.label);
1496       else 
1497         gtk_action_set_label (action, NULL);
1498       
1499       action->private_data->label_set = FALSE;
1500     }
1501 }
1502
1503 static void 
1504 gtk_action_set_icon_name (GtkAction   *action,
1505                           const gchar *icon_name)
1506 {
1507   GSList *p;
1508   GtkWidget *proxy, *image;
1509   gchar *tmp;
1510   
1511   tmp = action->private_data->icon_name;
1512   action->private_data->icon_name = g_strdup (icon_name);
1513   g_free (tmp);
1514
1515   for (p = action->private_data->proxies; p; p = p->next)
1516     {
1517       proxy = (GtkWidget *)p->data;
1518       
1519       if (GTK_IS_IMAGE_MENU_ITEM (proxy))
1520         {
1521           image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
1522           
1523           if (GTK_IS_IMAGE (image) &&
1524               (gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_EMPTY ||
1525                gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_ICON_NAME))
1526             gtk_image_set_from_icon_name (GTK_IMAGE (image),
1527                                           action->private_data->icon_name, GTK_ICON_SIZE_MENU);
1528         } 
1529       else if (GTK_IS_TOOL_BUTTON (proxy))
1530         {
1531           gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (proxy),
1532                                          action->private_data->icon_name);
1533         }
1534       else if (GTK_IS_BUTTON (proxy) &&
1535                !gtk_button_get_use_stock (GTK_BUTTON (proxy)))
1536         {
1537           image = gtk_button_get_image (GTK_BUTTON (proxy));
1538           
1539           if (GTK_IS_IMAGE (image) &&
1540               (gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_EMPTY ||
1541                gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_ICON_NAME))
1542             gtk_image_set_from_icon_name (GTK_IMAGE (image),
1543                                           action->private_data->icon_name, GTK_ICON_SIZE_MENU);
1544         }
1545     }
1546   
1547   g_object_notify (G_OBJECT (action), "icon-name");
1548 }
1549
1550
1551 /**
1552  * gtk_action_block_activate_from:
1553  * @action: the action object
1554  * @proxy: a proxy widget
1555  *
1556  * Disables calls to the gtk_action_activate()
1557  * function by signals on the given proxy widget.  This is used to
1558  * break notification loops for things like check or radio actions.
1559  *
1560  * This function is intended for use by action implementations.
1561  * 
1562  * Since: 2.4
1563  */
1564 void
1565 gtk_action_block_activate_from (GtkAction *action, 
1566                                 GtkWidget *proxy)
1567 {
1568   g_return_if_fail (GTK_IS_ACTION (action));
1569   
1570   g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
1571                                    action);
1572 }
1573
1574 /**
1575  * gtk_action_unblock_activate_from:
1576  * @action: the action object
1577  * @proxy: a proxy widget
1578  *
1579  * Re-enables calls to the gtk_action_activate()
1580  * function by signals on the given proxy widget.  This undoes the
1581  * blocking done by gtk_action_block_activate_from().
1582  *
1583  * This function is intended for use by action implementations.
1584  * 
1585  * Since: 2.4
1586  */
1587 void
1588 gtk_action_unblock_activate_from (GtkAction *action, 
1589                                   GtkWidget *proxy)
1590 {
1591   g_return_if_fail (GTK_IS_ACTION (action));
1592
1593   g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
1594                                      action);
1595 }
1596
1597 static void
1598 closure_accel_activate (GClosure     *closure,
1599                         GValue       *return_value,
1600                         guint         n_param_values,
1601                         const GValue *param_values,
1602                         gpointer      invocation_hint,
1603                         gpointer      marshal_data)
1604 {
1605   if (gtk_action_is_sensitive (GTK_ACTION (closure->data)))
1606     {
1607       _gtk_action_emit_activate (GTK_ACTION (closure->data));
1608       
1609       /* we handled the accelerator */
1610       g_value_set_boolean (return_value, TRUE);
1611     }
1612 }
1613
1614 static void
1615 gtk_action_set_action_group (GtkAction      *action,
1616                              GtkActionGroup *action_group)
1617 {
1618   g_return_if_fail (GTK_IS_ACTION (action));
1619
1620   if (action->private_data->action_group == NULL)
1621     g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1622   else
1623     g_return_if_fail (action_group == NULL);
1624
1625   action->private_data->action_group = action_group;
1626 }
1627
1628 /**
1629  * gtk_action_set_accel_path:
1630  * @action: the action object
1631  * @accel_path: the accelerator path
1632  *
1633  * Sets the accel path for this action.  All proxy widgets associated
1634  * with the action will have this accel path, so that their
1635  * accelerators are consistent.
1636  *
1637  * Since: 2.4
1638  */
1639 void
1640 gtk_action_set_accel_path (GtkAction   *action, 
1641                            const gchar *accel_path)
1642 {
1643   g_return_if_fail (GTK_IS_ACTION (action));
1644
1645   action->private_data->accel_quark = g_quark_from_string (accel_path);
1646 }
1647
1648 /**
1649  * gtk_action_get_accel_path:
1650  * @action: the action object
1651  *
1652  * Returns the accel path for this action.  
1653  *
1654  * Since: 2.6
1655  *
1656  * Returns: the accel path for this action, or %NULL
1657  *   if none is set. The returned string is owned by GTK+ 
1658  *   and must not be freed or modified.
1659  */
1660 G_CONST_RETURN gchar *
1661 gtk_action_get_accel_path (GtkAction *action)
1662 {
1663   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1664
1665   if (action->private_data->accel_quark)
1666     return g_quark_to_string (action->private_data->accel_quark);
1667   else
1668     return NULL;
1669 }
1670
1671 /**
1672  * gtk_action_get_accel_closure:
1673  * @action: the action object
1674  *
1675  * Returns the accel closure for this action.
1676  *
1677  * Since: 2.8
1678  *
1679  * Returns: the accel closure for this action. The returned closure is
1680  *          owned by GTK+ and must not be unreffed or modified.
1681  */
1682 GClosure *
1683 gtk_action_get_accel_closure (GtkAction *action)
1684 {
1685   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1686
1687   return action->private_data->accel_closure;
1688 }
1689
1690
1691 /**
1692  * gtk_action_set_accel_group:
1693  * @action: the action object
1694  * @accel_group: a #GtkAccelGroup or %NULL
1695  * 
1696  * Sets the #GtkAccelGroup in which the accelerator for this action
1697  * will be installed.
1698  *
1699  * Since: 2.4
1700  **/
1701 void
1702 gtk_action_set_accel_group (GtkAction     *action,
1703                             GtkAccelGroup *accel_group)
1704 {
1705   g_return_if_fail (GTK_IS_ACTION (action));
1706   g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
1707   
1708   if (accel_group)
1709     g_object_ref (accel_group);
1710   if (action->private_data->accel_group)
1711     g_object_unref (action->private_data->accel_group);
1712
1713   action->private_data->accel_group = accel_group;
1714 }
1715
1716 /**
1717  * gtk_action_connect_accelerator:
1718  * @action: a #GtkAction
1719  * 
1720  * Installs the accelerator for @action if @action has an
1721  * accel path and group. See gtk_action_set_accel_path() and 
1722  * gtk_action_set_accel_group()
1723  *
1724  * Since multiple proxies may independently trigger the installation
1725  * of the accelerator, the @action counts the number of times this
1726  * function has been called and doesn't remove the accelerator until
1727  * gtk_action_disconnect_accelerator() has been called as many times.
1728  *
1729  * Since: 2.4
1730  **/
1731 void 
1732 gtk_action_connect_accelerator (GtkAction *action)
1733 {
1734   g_return_if_fail (GTK_IS_ACTION (action));
1735
1736   if (!action->private_data->accel_quark ||
1737       !action->private_data->accel_group)
1738     return;
1739
1740   if (action->private_data->accel_count == 0)
1741     {
1742       const gchar *accel_path = 
1743         g_quark_to_string (action->private_data->accel_quark);
1744       
1745       gtk_accel_group_connect_by_path (action->private_data->accel_group,
1746                                        accel_path,
1747                                        action->private_data->accel_closure);
1748     }
1749
1750   action->private_data->accel_count++;
1751 }
1752
1753 /**
1754  * gtk_action_disconnect_accelerator:
1755  * @action: a #GtkAction
1756  * 
1757  * Undoes the effect of one call to gtk_action_connect_accelerator().
1758  *
1759  * Since: 2.4
1760  **/
1761 void 
1762 gtk_action_disconnect_accelerator (GtkAction *action)
1763 {
1764   g_return_if_fail (GTK_IS_ACTION (action));
1765
1766   if (!action->private_data->accel_quark ||
1767       !action->private_data->accel_group)
1768     return;
1769
1770   action->private_data->accel_count--;
1771
1772   if (action->private_data->accel_count == 0)
1773     gtk_accel_group_disconnect (action->private_data->accel_group,
1774                                 action->private_data->accel_closure);
1775 }
1776
1777 #define __GTK_ACTION_C__
1778 #include "gtkaliasdef.c"