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