]> Pileus Git - ~andy/gtk/blob - gtk/gtkaction.c
Block the previous action when calling reset() to prevent accidental
[~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  *
763  * Disable activation signals from the action 
764  *
765  * This is needed when updating the state of your proxy
766  * #GtkActivatable widget could result in calling gtk_action_activate(),
767  * this is a convenience function to avoid recursing in those
768  * cases (updating toggle state for instance).
769  */
770 void
771 gtk_action_block_activate (GtkAction *action)
772 {
773   g_return_if_fail (GTK_IS_ACTION (action));
774
775   action->private_data->activate_blocked = TRUE;
776 }
777
778 /**
779  * gtk_action_unblock_activate:
780  *
781  * Reenable activation signals from the action 
782  */
783 void
784 gtk_action_unblock_activate (GtkAction *action)
785 {
786   g_return_if_fail (GTK_IS_ACTION (action));
787
788   action->private_data->activate_blocked = FALSE;
789 }
790
791 /**
792  * gtk_action_create_icon:
793  * @action: the action object
794  * @icon_size: the size of the icon that should be created.
795  *
796  * This function is intended for use by action implementations to
797  * create icons displayed in the proxy widgets.
798  *
799  * Returns: a widget that displays the icon for this action.
800  *
801  * Since: 2.4
802  */
803 GtkWidget *
804 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
805 {
806   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
807
808   if (action->private_data->stock_id &&
809       gtk_icon_factory_lookup_default (action->private_data->stock_id))
810     return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
811   else if (action->private_data->gicon)
812     return gtk_image_new_from_gicon (action->private_data->gicon, icon_size);
813   else if (action->private_data->icon_name)
814     return gtk_image_new_from_icon_name (action->private_data->icon_name, icon_size);
815   else
816     return NULL;
817 }
818
819 /**
820  * gtk_action_create_menu_item:
821  * @action: the action object
822  *
823  * Creates a menu item widget that proxies for the given action.
824  *
825  * Returns: a menu item connected to the action.
826  *
827  * Since: 2.4
828  */
829 GtkWidget *
830 gtk_action_create_menu_item (GtkAction *action)
831 {
832   GtkWidget *menu_item;
833
834   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
835
836   menu_item = GTK_ACTION_GET_CLASS (action)->create_menu_item (action);
837
838   gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (menu_item), TRUE);
839   gtk_activatable_set_related_action (GTK_ACTIVATABLE (menu_item), action);
840
841   return menu_item;
842 }
843
844 /**
845  * gtk_action_create_tool_item:
846  * @action: the action object
847  *
848  * Creates a toolbar item widget that proxies for the given action.
849  *
850  * Returns: a toolbar item connected to the action.
851  *
852  * Since: 2.4
853  */
854 GtkWidget *
855 gtk_action_create_tool_item (GtkAction *action)
856 {
857   GtkWidget *button;
858
859   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
860
861   button = GTK_ACTION_GET_CLASS (action)->create_tool_item (action);
862
863   gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (button), TRUE);
864   gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action);
865
866   return button;
867 }
868
869 void
870 _gtk_action_add_to_proxy_list (GtkAction     *action,
871                                GtkWidget     *proxy)
872 {
873   g_return_if_fail (GTK_IS_ACTION (action));
874   g_return_if_fail (GTK_IS_WIDGET (proxy));
875  
876   GTK_ACTION_GET_CLASS (action)->connect_proxy (action, proxy);
877 }
878
879 void
880 _gtk_action_remove_from_proxy_list (GtkAction     *action,
881                                     GtkWidget     *proxy)
882 {
883   g_return_if_fail (GTK_IS_ACTION (action));
884   g_return_if_fail (GTK_IS_WIDGET (proxy));
885
886   GTK_ACTION_GET_CLASS (action)->disconnect_proxy (action, proxy);
887 }
888
889 /**
890  * gtk_action_connect_proxy:
891  * @action: the action object
892  * @proxy: the proxy widget
893  *
894  * Connects a widget to an action object as a proxy.  Synchronises 
895  * various properties of the action with the widget (such as label 
896  * text, icon, tooltip, etc), and attaches a callback so that the 
897  * action gets activated when the proxy widget does.
898  *
899  * If the widget is already connected to an action, it is disconnected
900  * first.
901  *
902  * Since: 2.4
903  *
904  * Deprecated 2.16: Use gtk_activatable_set_related_action() instead.
905  */
906 void
907 gtk_action_connect_proxy (GtkAction *action,
908                           GtkWidget *proxy)
909 {
910   g_return_if_fail (GTK_IS_ACTION (action));
911   g_return_if_fail (GTK_IS_WIDGET (proxy));
912   g_return_if_fail (GTK_IS_ACTIVATABLE (proxy));
913
914   gtk_activatable_set_use_action_appearance (GTK_ACTIVATABLE (proxy), TRUE);
915
916   gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), action);
917 }
918
919 /**
920  * gtk_action_disconnect_proxy:
921  * @action: the action object
922  * @proxy: the proxy widget
923  *
924  * Disconnects a proxy widget from an action.  
925  * Does <emphasis>not</emphasis> destroy the widget, however.
926  *
927  * Since: 2.4
928  *
929  * Deprecated 2.16: Use gtk_activatable_set_related_action() instead.
930  */
931 void
932 gtk_action_disconnect_proxy (GtkAction *action,
933                              GtkWidget *proxy)
934 {
935   g_return_if_fail (GTK_IS_ACTION (action));
936   g_return_if_fail (GTK_IS_WIDGET (proxy));
937
938   gtk_activatable_set_related_action (GTK_ACTIVATABLE (proxy), NULL);
939 }
940
941 /**
942  * gtk_action_get_proxies:
943  * @action: the action object
944  * 
945  * Returns the proxy widgets for an action.
946  * See also gtk_widget_get_action().
947  * 
948  * Return value: a #GSList of proxy widgets. The list is owned by GTK+
949  * and must not be modified.
950  *
951  * Since: 2.4
952  **/
953 GSList*
954 gtk_action_get_proxies (GtkAction *action)
955 {
956   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
957
958   return action->private_data->proxies;
959 }
960
961
962 /**
963  * gtk_widget_get_action:
964  * @widget: a #GtkWidget
965  *
966  * Returns the #GtkAction that @widget is a proxy for. 
967  * See also gtk_action_get_proxies().
968  *
969  * Returns: the action that a widget is a proxy for, or
970  *  %NULL, if it is not attached to an action.
971  *
972  * Since: 2.10
973  *
974  * Deprecated 2.16: Use gtk_activatable_get_related_action() instead.
975  */
976 GtkAction*
977 gtk_widget_get_action (GtkWidget *widget)
978 {
979   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
980
981   if (GTK_IS_ACTIVATABLE (widget))
982     return gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget));
983
984   return NULL;
985 }
986
987 /**
988  * gtk_action_get_name:
989  * @action: the action object
990  * 
991  * Returns the name of the action.
992  * 
993  * Return value: the name of the action. The string belongs to GTK+ and should not
994  *   be freed.
995  *
996  * Since: 2.4
997  **/
998 G_CONST_RETURN gchar *
999 gtk_action_get_name (GtkAction *action)
1000 {
1001   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1002
1003   return action->private_data->name;
1004 }
1005
1006 /**
1007  * gtk_action_is_sensitive:
1008  * @action: the action object
1009  * 
1010  * Returns whether the action is effectively sensitive.
1011  *
1012  * Return value: %TRUE if the action and its associated action group 
1013  * are both sensitive.
1014  *
1015  * Since: 2.4
1016  **/
1017 gboolean
1018 gtk_action_is_sensitive (GtkAction *action)
1019 {
1020   GtkActionPrivate *priv;
1021   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1022
1023   priv = action->private_data;
1024   return priv->sensitive &&
1025     (priv->action_group == NULL ||
1026      gtk_action_group_get_sensitive (priv->action_group));
1027 }
1028
1029 /**
1030  * gtk_action_get_sensitive:
1031  * @action: the action object
1032  * 
1033  * Returns whether the action itself is sensitive. Note that this doesn't 
1034  * necessarily mean effective sensitivity. See gtk_action_is_sensitive() 
1035  * for that.
1036  *
1037  * Return value: %TRUE if the action itself is sensitive.
1038  *
1039  * Since: 2.4
1040  **/
1041 gboolean
1042 gtk_action_get_sensitive (GtkAction *action)
1043 {
1044   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1045
1046   return action->private_data->sensitive;
1047 }
1048
1049 /**
1050  * gtk_action_set_sensitive:
1051  * @action: the action object
1052  * @sensitive: %TRUE to make the action sensitive
1053  * 
1054  * Sets the ::sensitive property of the action to @sensitive. Note that 
1055  * this doesn't necessarily mean effective sensitivity. See 
1056  * gtk_action_is_sensitive() 
1057  * for that.
1058  *
1059  * Since: 2.6
1060  **/
1061 void
1062 gtk_action_set_sensitive (GtkAction *action,
1063                           gboolean   sensitive)
1064 {
1065   g_return_if_fail (GTK_IS_ACTION (action));
1066
1067   sensitive = sensitive != FALSE;
1068   
1069   if (action->private_data->sensitive != sensitive)
1070     {
1071       action->private_data->sensitive = sensitive;
1072
1073       g_object_notify (G_OBJECT (action), "sensitive");
1074     }
1075 }
1076
1077 /**
1078  * gtk_action_is_visible:
1079  * @action: the action object
1080  * 
1081  * Returns whether the action is effectively visible.
1082  *
1083  * Return value: %TRUE if the action and its associated action group 
1084  * are both visible.
1085  *
1086  * Since: 2.4
1087  **/
1088 gboolean
1089 gtk_action_is_visible (GtkAction *action)
1090 {
1091   GtkActionPrivate *priv;
1092   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1093
1094   priv = action->private_data;
1095   return priv->visible &&
1096     (priv->action_group == NULL ||
1097      gtk_action_group_get_visible (priv->action_group));
1098 }
1099
1100 /**
1101  * gtk_action_get_visible:
1102  * @action: the action object
1103  * 
1104  * Returns whether the action itself is visible. Note that this doesn't 
1105  * necessarily mean effective visibility. See gtk_action_is_sensitive() 
1106  * for that.
1107  *
1108  * Return value: %TRUE if the action itself is visible.
1109  *
1110  * Since: 2.4
1111  **/
1112 gboolean
1113 gtk_action_get_visible (GtkAction *action)
1114 {
1115   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1116
1117   return action->private_data->visible;
1118 }
1119
1120 /**
1121  * gtk_action_set_visible:
1122  * @action: the action object
1123  * @visible: %TRUE to make the action visible
1124  * 
1125  * Sets the ::visible property of the action to @visible. Note that 
1126  * this doesn't necessarily mean effective visibility. See 
1127  * gtk_action_is_visible() 
1128  * for that.
1129  *
1130  * Since: 2.6
1131  **/
1132 void
1133 gtk_action_set_visible (GtkAction *action,
1134                         gboolean   visible)
1135 {
1136   g_return_if_fail (GTK_IS_ACTION (action));
1137
1138   visible = visible != FALSE;
1139   
1140   if (action->private_data->visible != visible)
1141     {
1142       action->private_data->visible = visible;
1143
1144       g_object_notify (G_OBJECT (action), "visible");
1145     }
1146 }
1147 /**
1148  * gtk_action_set_is_important:
1149  * @action: the action object
1150  * @is_important: %TRUE to make the action important
1151  *
1152  * Sets whether the action is important, this attribute is used
1153  * primarily by toolbar items to decide whether to show a label
1154  * or not.
1155  *
1156  * Since: 2.16
1157  */
1158 void 
1159 gtk_action_set_is_important (GtkAction *action,
1160                              gboolean   is_important)
1161 {
1162   g_return_if_fail (GTK_IS_ACTION (action));
1163
1164   g_return_if_fail (GTK_IS_ACTION (action));
1165
1166   is_important = is_important != FALSE;
1167   
1168   if (action->private_data->is_important != is_important)
1169     {
1170       action->private_data->is_important = is_important;
1171       
1172       g_object_notify (G_OBJECT (action), "is-important");
1173     }  
1174 }
1175
1176 /**
1177  * gtk_action_get_is_important:
1178  * @action: a #GtkAction
1179  *
1180  * Checks whether @action is important or not
1181  * 
1182  * Returns: whether @action is important
1183  *
1184  * Since: 2.16
1185  */
1186 gboolean 
1187 gtk_action_get_is_important (GtkAction *action)
1188 {
1189   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1190
1191   return action->private_data->is_important;
1192 }
1193
1194 /**
1195  * gtk_action_set_label:
1196  * @action: a #GtkAction
1197  * @label: the label text to set
1198  *
1199  * Sets the label of @action.
1200  *
1201  * Since: 2.16
1202  */
1203 void 
1204 gtk_action_set_label (GtkAction   *action,
1205                       const gchar *label)
1206 {
1207   gchar *tmp;
1208   
1209   g_return_if_fail (GTK_IS_ACTION (action));
1210   
1211   tmp = action->private_data->label;
1212   action->private_data->label = g_strdup (label);
1213   g_free (tmp);
1214   action->private_data->label_set = (action->private_data->label != NULL);
1215   /* if label is unset, then use the label from the stock item */
1216   if (!action->private_data->label_set && action->private_data->stock_id)
1217     {
1218       GtkStockItem stock_item;
1219       
1220       if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1221         action->private_data->label = g_strdup (stock_item.label);
1222     }
1223
1224   g_object_notify (G_OBJECT (action), "label");
1225   
1226   /* if short_label is unset, set short_label=label */
1227   if (!action->private_data->short_label_set)
1228     {
1229       gtk_action_set_short_label (action, action->private_data->label);
1230       action->private_data->short_label_set = FALSE;
1231     }
1232 }
1233
1234 /**
1235  * gtk_action_get_label:
1236  * @action: a #GtkAction
1237  *
1238  * Gets the label text of @action.
1239  *
1240  * Returns: the label text
1241  *
1242  * Since: 2.16
1243  */
1244 G_CONST_RETURN gchar * 
1245 gtk_action_get_label (GtkAction *action)
1246 {
1247   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1248
1249   return action->private_data->label;
1250 }
1251
1252 /**
1253  * gtk_action_set_short_label:
1254  * @action: a #GtkAction
1255  * @label: the label text to set
1256  *
1257  * Sets a shorter label text on @action.
1258  *
1259  * Since: 2.16
1260  */
1261 void 
1262 gtk_action_set_short_label (GtkAction   *action,
1263                             const gchar *label)
1264 {
1265   gchar *tmp;
1266
1267   g_return_if_fail (GTK_IS_ACTION (action));
1268
1269   tmp = action->private_data->short_label;
1270   action->private_data->short_label = g_strdup (label);
1271   g_free (tmp);
1272   action->private_data->short_label_set = (action->private_data->short_label != NULL);
1273   /* if short_label is unset, then use the value of label */
1274   if (!action->private_data->short_label_set)
1275     action->private_data->short_label = g_strdup (action->private_data->label);
1276
1277   g_object_notify (G_OBJECT (action), "short-label");
1278 }
1279
1280 /**
1281  * gtk_action_get_short_label:
1282  * @action: a #GtkAction
1283  * @label: the label text to set
1284  *
1285  * Gets the short label text of @action.
1286  *
1287  * Returns: the short label text.
1288  *
1289  * Since: 2.16
1290  */
1291 G_CONST_RETURN gchar * 
1292 gtk_action_get_short_label (GtkAction *action)
1293 {
1294   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1295
1296   return action->private_data->short_label;
1297 }
1298
1299 /**
1300  * gtk_action_set_visible_horizontal:
1301  * @action: a #GtkAction
1302  * @visible_horizontal: whether the action is visible horizontally
1303  *
1304  * Sets whether @action is visible when horizontal
1305  *
1306  * Since: 2.16
1307  */
1308 void 
1309 gtk_action_set_visible_horizontal (GtkAction *action,
1310                                    gboolean   visible_horizontal)
1311 {
1312   g_return_if_fail (GTK_IS_ACTION (action));
1313
1314   g_return_if_fail (GTK_IS_ACTION (action));
1315
1316   visible_horizontal = visible_horizontal != FALSE;
1317   
1318   if (action->private_data->visible_horizontal != visible_horizontal)
1319     {
1320       action->private_data->visible_horizontal = visible_horizontal;
1321       
1322       g_object_notify (G_OBJECT (action), "visible-horizontal");
1323     }  
1324 }
1325
1326 /**
1327  * gtk_action_get_visible_horizontal:
1328  * @action: a #GtkAction
1329  *
1330  * Checks whether @action is visible when horizontal
1331  * 
1332  * Returns: whether @action is visible when horizontal
1333  *
1334  * Since: 2.16
1335  */
1336 gboolean 
1337 gtk_action_get_visible_horizontal (GtkAction *action)
1338 {
1339   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1340
1341   return action->private_data->visible_horizontal;
1342 }
1343
1344 /**
1345  * gtk_action_set_visible_vertical:
1346  * @action: a #GtkAction
1347  * @visible_vertical: whether the action is visible vertically
1348  *
1349  * Sets whether @action is visible when vertical 
1350  *
1351  * Since: 2.16
1352  */
1353 void 
1354 gtk_action_set_visible_vertical (GtkAction *action,
1355                                  gboolean   visible_vertical)
1356 {
1357   g_return_if_fail (GTK_IS_ACTION (action));
1358
1359   g_return_if_fail (GTK_IS_ACTION (action));
1360
1361   visible_vertical = visible_vertical != FALSE;
1362   
1363   if (action->private_data->visible_vertical != visible_vertical)
1364     {
1365       action->private_data->visible_vertical = visible_vertical;
1366       
1367       g_object_notify (G_OBJECT (action), "visible-vertical");
1368     }  
1369 }
1370
1371 /**
1372  * gtk_action_get_visible_vertical:
1373  * @action: a #GtkAction
1374  *
1375  * Checks whether @action is visible when horizontal
1376  * 
1377  * Returns: whether @action is visible when horizontal
1378  *
1379  * Since: 2.16
1380  */
1381 gboolean 
1382 gtk_action_get_visible_vertical (GtkAction *action)
1383 {
1384   g_return_val_if_fail (GTK_IS_ACTION (action), FALSE);
1385
1386   return action->private_data->visible_vertical;
1387 }
1388
1389 /**
1390  * gtk_action_set_tooltip:
1391  * @action: a #GtkAction
1392  * @tooltip: the tooltip text
1393  *
1394  * Sets the tooltip text on @action
1395  *
1396  * Since: 2.16
1397  */
1398 void 
1399 gtk_action_set_tooltip (GtkAction   *action,
1400                         const gchar *tooltip)
1401 {
1402   gchar *tmp;
1403
1404   g_return_if_fail (GTK_IS_ACTION (action));
1405
1406   tmp = action->private_data->tooltip;
1407   action->private_data->tooltip = g_strdup (tooltip);
1408   g_free (tmp);
1409
1410   g_object_notify (G_OBJECT (action), "tooltip");
1411 }
1412
1413 /**
1414  * gtk_action_get_tooltip:
1415  * @action: a #GtkAction
1416  *
1417  * Gets the tooltip text of @action.
1418  *
1419  * Returns: the tooltip text
1420  *
1421  * Since: 2.16
1422  */
1423 G_CONST_RETURN gchar * 
1424 gtk_action_get_tooltip (GtkAction *action)
1425 {
1426   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1427
1428   return action->private_data->tooltip;
1429 }
1430
1431 /**
1432  * gtk_action_set_stock_id:
1433  * @action: a #GtkAction
1434  * @tooltip: the tooltip text
1435  *
1436  * Sets the stock id on @action
1437  *
1438  * Since: 2.16
1439  */
1440 void 
1441 gtk_action_set_stock_id (GtkAction   *action,
1442                          const gchar *stock_id)
1443 {
1444   gchar *tmp;
1445
1446   g_return_if_fail (GTK_IS_ACTION (action));
1447
1448   g_return_if_fail (GTK_IS_ACTION (action));
1449
1450   tmp = action->private_data->stock_id;
1451   action->private_data->stock_id = g_strdup (stock_id);
1452   g_free (tmp);
1453
1454   g_object_notify (G_OBJECT (action), "stock-id");
1455   
1456   /* update label and short_label if appropriate */
1457   if (!action->private_data->label_set)
1458     {
1459       GtkStockItem stock_item;
1460       
1461       if (action->private_data->stock_id &&
1462           gtk_stock_lookup (action->private_data->stock_id, &stock_item))
1463         gtk_action_set_label (action, stock_item.label);
1464       else 
1465         gtk_action_set_label (action, NULL);
1466       
1467       action->private_data->label_set = FALSE;
1468     }
1469 }
1470
1471 /**
1472  * gtk_action_get_stock_id:
1473  * @action: a #GtkAction
1474  *
1475  * Gets the stock id of @action.
1476  *
1477  * Returns: the stock id
1478  *
1479  * Since: 2.16
1480  */
1481 G_CONST_RETURN gchar * 
1482 gtk_action_get_stock_id (GtkAction *action)
1483 {
1484   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1485
1486   return action->private_data->stock_id;
1487 }
1488
1489 /**
1490  * gtk_action_set_icon_name:
1491  * @action: a #GtkAction
1492  * @tooltip: the icon name to set
1493  *
1494  * Sets the icon name on @action
1495  *
1496  * Since: 2.16
1497  */
1498 void 
1499 gtk_action_set_icon_name (GtkAction   *action,
1500                           const gchar *icon_name)
1501 {
1502   gchar *tmp;
1503
1504   g_return_if_fail (GTK_IS_ACTION (action));
1505
1506   g_return_if_fail (GTK_IS_ACTION (action));
1507
1508   tmp = action->private_data->icon_name;
1509   action->private_data->icon_name = g_strdup (icon_name);
1510   g_free (tmp);
1511
1512   g_object_notify (G_OBJECT (action), "icon-name");
1513 }
1514
1515 /**
1516  * gtk_action_get_icon_name:
1517  * @action: a #GtkAction
1518  *
1519  * Gets the icon name of @action.
1520  *
1521  * Returns: the icon name
1522  *
1523  * Since: 2.16
1524  */
1525 G_CONST_RETURN gchar * 
1526 gtk_action_get_icon_name (GtkAction *action)
1527 {
1528   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1529
1530   return action->private_data->icon_name;
1531 }
1532
1533 /**
1534  * gtk_action_set_gicon:
1535  * @action: a #GtkAction
1536  * @icon: the #GIcon to set
1537  *
1538  * Sets the icon of @action.
1539  *
1540  * Since: 2.16
1541  */
1542 void
1543 gtk_action_set_gicon (GtkAction *action,
1544                       GIcon     *icon)
1545 {
1546   g_return_if_fail (GTK_IS_ACTION (action));
1547
1548   if (action->private_data->gicon)
1549     g_object_unref (action->private_data->gicon);
1550
1551   action->private_data->gicon = icon;
1552
1553   if (action->private_data->gicon)
1554     g_object_ref (action->private_data->gicon);
1555
1556   g_object_notify (G_OBJECT (action), "gicon");
1557 }
1558
1559 /**
1560  * gtk_action_get_gicon:
1561  * @action: a #GtkAction
1562  *
1563  * Gets the gicon of @action.
1564  *
1565  * Returns: The action's #GIcon if one is set.
1566  *
1567  * Since: 2.16
1568  */
1569 GIcon *
1570 gtk_action_get_gicon (GtkAction *action)
1571 {
1572   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1573
1574   return action->private_data->gicon;
1575 }
1576
1577 /**
1578  * gtk_action_block_activate_from:
1579  * @action: the action object
1580  * @proxy: a proxy widget
1581  *
1582  * Disables calls to the gtk_action_activate()
1583  * function by signals on the given proxy widget.  This is used to
1584  * break notification loops for things like check or radio actions.
1585  *
1586  * This function is intended for use by action implementations.
1587  * 
1588  * Since: 2.4
1589  *
1590  * Deprecated 2.16: activatables are now responsible for activating the
1591  * action directly so this doesnt apply anymore.
1592  */
1593 void
1594 gtk_action_block_activate_from (GtkAction *action, 
1595                                 GtkWidget *proxy)
1596 {
1597   g_return_if_fail (GTK_IS_ACTION (action));
1598   
1599   g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
1600                                    action);
1601 }
1602
1603 /**
1604  * gtk_action_unblock_activate_from:
1605  * @action: the action object
1606  * @proxy: a proxy widget
1607  *
1608  * Re-enables calls to the gtk_action_activate()
1609  * function by signals on the given proxy widget.  This undoes the
1610  * blocking done by gtk_action_block_activate_from().
1611  *
1612  * This function is intended for use by action implementations.
1613  * 
1614  * Since: 2.4
1615  *
1616  * Deprecated 2.16: activatables are now responsible for activating the
1617  * action directly so this doesnt apply anymore.
1618  */
1619 void
1620 gtk_action_unblock_activate_from (GtkAction *action, 
1621                                   GtkWidget *proxy)
1622 {
1623   g_return_if_fail (GTK_IS_ACTION (action));
1624
1625   g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
1626                                      action);
1627 }
1628
1629 static void
1630 closure_accel_activate (GClosure     *closure,
1631                         GValue       *return_value,
1632                         guint         n_param_values,
1633                         const GValue *param_values,
1634                         gpointer      invocation_hint,
1635                         gpointer      marshal_data)
1636 {
1637   if (gtk_action_is_sensitive (GTK_ACTION (closure->data)))
1638     {
1639       _gtk_action_emit_activate (GTK_ACTION (closure->data));
1640       
1641       /* we handled the accelerator */
1642       g_value_set_boolean (return_value, TRUE);
1643     }
1644 }
1645
1646 static void
1647 gtk_action_set_action_group (GtkAction      *action,
1648                              GtkActionGroup *action_group)
1649 {
1650   if (action->private_data->action_group == NULL)
1651     g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1652   else
1653     g_return_if_fail (action_group == NULL);
1654
1655   action->private_data->action_group = action_group;
1656 }
1657
1658 /**
1659  * gtk_action_set_accel_path:
1660  * @action: the action object
1661  * @accel_path: the accelerator path
1662  *
1663  * Sets the accel path for this action.  All proxy widgets associated
1664  * with the action will have this accel path, so that their
1665  * accelerators are consistent.
1666  *
1667  * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
1668  * pass a static string, you can save some memory by interning it first with 
1669  * g_intern_static_string().
1670  *
1671  * Since: 2.4
1672  */
1673 void
1674 gtk_action_set_accel_path (GtkAction   *action, 
1675                            const gchar *accel_path)
1676 {
1677   g_return_if_fail (GTK_IS_ACTION (action));
1678
1679   action->private_data->accel_quark = g_quark_from_string (accel_path);
1680 }
1681
1682 /**
1683  * gtk_action_get_accel_path:
1684  * @action: the action object
1685  *
1686  * Returns the accel path for this action.  
1687  *
1688  * Since: 2.6
1689  *
1690  * Returns: the accel path for this action, or %NULL
1691  *   if none is set. The returned string is owned by GTK+ 
1692  *   and must not be freed or modified.
1693  */
1694 G_CONST_RETURN gchar *
1695 gtk_action_get_accel_path (GtkAction *action)
1696 {
1697   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1698
1699   if (action->private_data->accel_quark)
1700     return g_quark_to_string (action->private_data->accel_quark);
1701   else
1702     return NULL;
1703 }
1704
1705 /**
1706  * gtk_action_get_accel_closure:
1707  * @action: the action object
1708  *
1709  * Returns the accel closure for this action.
1710  *
1711  * Since: 2.8
1712  *
1713  * Returns: the accel closure for this action. The returned closure is
1714  *          owned by GTK+ and must not be unreffed or modified.
1715  */
1716 GClosure *
1717 gtk_action_get_accel_closure (GtkAction *action)
1718 {
1719   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1720
1721   return action->private_data->accel_closure;
1722 }
1723
1724
1725 /**
1726  * gtk_action_set_accel_group:
1727  * @action: the action object
1728  * @accel_group: a #GtkAccelGroup or %NULL
1729  * 
1730  * Sets the #GtkAccelGroup in which the accelerator for this action
1731  * will be installed.
1732  *
1733  * Since: 2.4
1734  **/
1735 void
1736 gtk_action_set_accel_group (GtkAction     *action,
1737                             GtkAccelGroup *accel_group)
1738 {
1739   g_return_if_fail (GTK_IS_ACTION (action));
1740   g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
1741   
1742   if (accel_group)
1743     g_object_ref (accel_group);
1744   if (action->private_data->accel_group)
1745     g_object_unref (action->private_data->accel_group);
1746
1747   action->private_data->accel_group = accel_group;
1748 }
1749
1750 /**
1751  * gtk_action_connect_accelerator:
1752  * @action: a #GtkAction
1753  * 
1754  * Installs the accelerator for @action if @action has an
1755  * accel path and group. See gtk_action_set_accel_path() and 
1756  * gtk_action_set_accel_group()
1757  *
1758  * Since multiple proxies may independently trigger the installation
1759  * of the accelerator, the @action counts the number of times this
1760  * function has been called and doesn't remove the accelerator until
1761  * gtk_action_disconnect_accelerator() has been called as many times.
1762  *
1763  * Since: 2.4
1764  **/
1765 void 
1766 gtk_action_connect_accelerator (GtkAction *action)
1767 {
1768   g_return_if_fail (GTK_IS_ACTION (action));
1769
1770   if (!action->private_data->accel_quark ||
1771       !action->private_data->accel_group)
1772     return;
1773
1774   if (action->private_data->accel_count == 0)
1775     {
1776       const gchar *accel_path = 
1777         g_quark_to_string (action->private_data->accel_quark);
1778       
1779       gtk_accel_group_connect_by_path (action->private_data->accel_group,
1780                                        accel_path,
1781                                        action->private_data->accel_closure);
1782     }
1783
1784   action->private_data->accel_count++;
1785 }
1786
1787 /**
1788  * gtk_action_disconnect_accelerator:
1789  * @action: a #GtkAction
1790  * 
1791  * Undoes the effect of one call to gtk_action_connect_accelerator().
1792  *
1793  * Since: 2.4
1794  **/
1795 void 
1796 gtk_action_disconnect_accelerator (GtkAction *action)
1797 {
1798   g_return_if_fail (GTK_IS_ACTION (action));
1799
1800   if (!action->private_data->accel_quark ||
1801       !action->private_data->accel_group)
1802     return;
1803
1804   action->private_data->accel_count--;
1805
1806   if (action->private_data->accel_count == 0)
1807     gtk_accel_group_disconnect (action->private_data->accel_group,
1808                                 action->private_data->accel_closure);
1809 }
1810
1811 /**
1812  * gtk_action_create_menu:
1813  * @action: a #GtkAction
1814  *
1815  * If @action provides a #GtkMenu widget as a submenu for the menu
1816  * item or the toolbar item it creates, this function returns an
1817  * instance of that menu.
1818  *
1819  * Return value: the menu item provided by the action, or %NULL.
1820  *
1821  * Since: 2.12
1822  */
1823 GtkWidget *
1824 gtk_action_create_menu (GtkAction *action)
1825 {
1826   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
1827
1828   if (GTK_ACTION_GET_CLASS (action)->create_menu)
1829     return GTK_ACTION_GET_CLASS (action)->create_menu (action);
1830
1831   return NULL;
1832 }
1833
1834 #define __GTK_ACTION_C__
1835 #include "gtkaliasdef.c"