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