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