]> Pileus Git - ~andy/gtk/blob - gtk/gtkaction.c
Use gssize for length, not gsize.
[~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 "gtktoolbutton.h"
35 #include "gtkmenuitem.h"
36 #include "gtkimagemenuitem.h"
37 #include "gtkstock.h"
38 #include "gtklabel.h"
39 #include "gtkimage.h"
40 #include "gtkaccellabel.h"
41 #include "gtkintl.h"
42
43
44 #define GTK_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION, GtkActionPrivate))
45
46 struct _GtkActionPrivate 
47 {
48   gchar *name;
49   gchar *label;
50   gchar *short_label;
51   gchar *tooltip;
52   gchar *stock_id; /* icon */
53
54   guint sensitive : 1;
55   guint visible : 1;
56   guint label_set : 1;       /* these two used so we can set label */
57   guint short_label_set : 1; /* based on stock id */
58
59   /* accelerator */
60   GQuark accel_quark;
61
62   /* list of proxy widgets */
63   GSList *proxies;
64 };
65
66 enum 
67 {
68   ACTIVATE,
69   LAST_SIGNAL
70 };
71
72 enum 
73 {
74   PROP_0,
75   PROP_NAME,
76   PROP_LABEL,
77   PROP_SHORT_LABEL,
78   PROP_TOOLTIP,
79   PROP_STOCK_ID,
80   PROP_SENSITIVE,
81   PROP_VISIBLE,
82 };
83
84 static void gtk_action_init       (GtkAction *action);
85 static void gtk_action_class_init (GtkActionClass *class);
86
87 static GQuark       accel_path_id  = 0;
88 static const gchar *accel_path_key = "GtkAction::accel_path";
89
90 GType
91 gtk_action_get_type (void)
92 {
93   static GtkType type = 0;
94
95   if (!type)
96     {
97       static const GTypeInfo type_info =
98       {
99         sizeof (GtkActionClass),
100         (GBaseInitFunc) NULL,
101         (GBaseFinalizeFunc) NULL,
102         (GClassInitFunc) gtk_action_class_init,
103         (GClassFinalizeFunc) NULL,
104         NULL,
105         
106         sizeof (GtkAction),
107         0, /* n_preallocs */
108         (GInstanceInitFunc) gtk_action_init,
109       };
110
111       type = g_type_register_static (G_TYPE_OBJECT,
112                                      "GtkAction",
113                                      &type_info, 0);
114     }
115   return type;
116 }
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
128 static GtkWidget *create_menu_item    (GtkAction *action);
129 static GtkWidget *create_tool_item    (GtkAction *action);
130 static void       connect_proxy       (GtkAction *action,
131                                        GtkWidget *proxy);
132 static void       disconnect_proxy    (GtkAction *action,
133                                        GtkWidget *proxy);
134
135 static GObjectClass *parent_class = NULL;
136 static guint         action_signals[LAST_SIGNAL] = { 0 };
137
138
139 static void
140 gtk_action_class_init (GtkActionClass *klass)
141 {
142   GObjectClass *gobject_class;
143
144   accel_path_id = g_quark_from_static_string (accel_path_key);
145
146   parent_class = g_type_class_peek_parent (klass);
147   gobject_class = G_OBJECT_CLASS (klass);
148
149   gobject_class->finalize     = gtk_action_finalize;
150   gobject_class->set_property = gtk_action_set_property;
151   gobject_class->get_property = gtk_action_get_property;
152
153   klass->activate = NULL;
154
155   klass->create_menu_item = create_menu_item;
156   klass->create_tool_item = create_tool_item;
157   klass->connect_proxy = connect_proxy;
158   klass->disconnect_proxy = disconnect_proxy;
159
160   klass->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
161   klass->toolbar_item_type = GTK_TYPE_TOOL_BUTTON;
162
163   g_object_class_install_property (gobject_class,
164                                    PROP_NAME,
165                                    g_param_spec_string ("name",
166                                                         _("Name"),
167                                                         _("A unique name for the action."),
168                                                         NULL,
169                                                         G_PARAM_READWRITE |
170                                                         G_PARAM_CONSTRUCT_ONLY));
171   g_object_class_install_property (gobject_class,
172                                    PROP_LABEL,
173                                    g_param_spec_string ("label",
174                                                         _("Label"),
175                                                         _("The label used for menu items and buttons that activate this action."),
176                                                         NULL,
177                                                         G_PARAM_READWRITE));
178   g_object_class_install_property (gobject_class,
179                                    PROP_SHORT_LABEL,
180                                    g_param_spec_string ("short_label",
181                                                         _("Short label"),
182                                                         _("A shorter label that may be used on toolbar buttons."),
183                                                         NULL,
184                                                         G_PARAM_READWRITE));
185   g_object_class_install_property (gobject_class,
186                                    PROP_TOOLTIP,
187                                    g_param_spec_string ("tooltip",
188                                                         _("Tooltip"),
189                                                         _("A tooltip for this action."),
190                                                         NULL,
191                                                         G_PARAM_READWRITE));
192   g_object_class_install_property (gobject_class,
193                                    PROP_STOCK_ID,
194                                    g_param_spec_string ("stock_id",
195                                                         _("Stock Icon"),
196                                                         _("The stock icon displayed in widgets representing this action."),
197                                                         NULL,
198                                                         G_PARAM_READWRITE));
199   g_object_class_install_property (gobject_class,
200                                    PROP_SENSITIVE,
201                                    g_param_spec_boolean ("sensitive",
202                                                          _("Sensitive"),
203                                                          _("Whether the action is enabled."),
204                                                          TRUE,
205                                                          G_PARAM_READWRITE));
206
207   g_object_class_install_property (gobject_class,
208                                    PROP_VISIBLE,
209                                    g_param_spec_boolean ("visible",
210                                                          _("Visible"),
211                                                          _("Whether the action is visible."),
212                                                          TRUE,
213                                                          G_PARAM_READWRITE));
214
215   action_signals[ACTIVATE] =
216     g_signal_new ("activate",
217                   G_OBJECT_CLASS_TYPE (klass),
218                   G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
219                   G_STRUCT_OFFSET (GtkActionClass, activate),  NULL, NULL,
220                   g_cclosure_marshal_VOID__VOID,
221                   G_TYPE_NONE, 0);
222
223   g_type_class_add_private (gobject_class, sizeof (GtkActionPrivate));
224 }
225
226
227 static void
228 gtk_action_init (GtkAction *action)
229 {
230   action->private_data = GTK_ACTION_GET_PRIVATE (action);
231
232   action->private_data->name = NULL;
233   action->private_data->label = NULL;
234   action->private_data->short_label = NULL;
235   action->private_data->tooltip = NULL;
236   action->private_data->stock_id = NULL;
237
238   action->private_data->sensitive = TRUE;
239   action->private_data->visible = TRUE;
240
241   action->private_data->label_set = FALSE;
242   action->private_data->short_label_set = FALSE;
243
244   action->private_data->accel_quark = 0;
245
246   action->private_data->proxies = NULL;
247 }
248
249 static void
250 gtk_action_finalize (GObject *object)
251 {
252   GtkAction *action;
253
254   action = GTK_ACTION (object);
255
256   g_free (action->private_data->name);
257   g_free (action->private_data->label);
258   g_free (action->private_data->short_label);
259   g_free (action->private_data->tooltip);
260   g_free (action->private_data->stock_id);
261 }
262
263 static void
264 gtk_action_set_property (GObject         *object,
265                          guint            prop_id,
266                          const GValue    *value,
267                          GParamSpec      *pspec)
268 {
269   GtkAction *action;
270   gchar *tmp;
271   
272   action = GTK_ACTION (object);
273
274   switch (prop_id)
275     {
276     case PROP_NAME:
277       tmp = action->private_data->name;
278       action->private_data->name = g_value_dup_string (value);
279       g_free (tmp);
280       break;
281     case PROP_LABEL:
282       tmp = action->private_data->label;
283       action->private_data->label = g_value_dup_string (value);
284       g_free (tmp);
285       action->private_data->label_set = (action->private_data->label != NULL);
286       /* if label is unset, then use the label from the stock item */
287       if (!action->private_data->label_set && action->private_data->stock_id)
288         {
289           GtkStockItem stock_item;
290
291           if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
292             action->private_data->label = g_strdup (stock_item.label);
293         }
294       /* if short_label is unset, set short_label=label */
295       if (!action->private_data->short_label_set)
296         {
297           tmp = action->private_data->short_label;
298           action->private_data->short_label = g_strdup (action->private_data->label);
299           g_free (tmp);
300           g_object_notify (object, "short_label");
301         }
302       break;
303     case PROP_SHORT_LABEL:
304       tmp = action->private_data->short_label;
305       action->private_data->short_label = g_value_dup_string (value);
306       g_free (tmp);
307       action->private_data->short_label_set = (action->private_data->short_label != NULL);
308       /* if short_label is unset, then use the value of label */
309       if (!action->private_data->short_label_set)
310         {
311           action->private_data->short_label = g_strdup (action->private_data->label);
312         }
313       break;
314     case PROP_TOOLTIP:
315       tmp = action->private_data->tooltip;
316       action->private_data->tooltip = g_value_dup_string (value);
317       g_free (tmp);
318       break;
319     case PROP_STOCK_ID:
320       tmp = action->private_data->stock_id;
321       action->private_data->stock_id = g_value_dup_string (value);
322       g_free (tmp);
323       /* update label and short_label if appropriate */
324       if (!action->private_data->label_set)
325         {
326           GtkStockItem stock_item;
327
328           g_free (action->private_data->label);
329           if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
330             action->private_data->label = g_strdup (stock_item.label);
331           else
332             action->private_data->label = NULL;
333           g_object_notify (object, "label");
334         }
335       if (!action->private_data->short_label_set)
336         {
337           tmp = action->private_data->short_label;
338           action->private_data->short_label = g_strdup (action->private_data->label);
339           g_free (tmp);
340           g_object_notify (object, "short_label");
341         }
342       break;
343     case PROP_SENSITIVE:
344       action->private_data->sensitive = g_value_get_boolean (value);
345       break;
346     case PROP_VISIBLE:
347       action->private_data->visible = g_value_get_boolean (value);
348       break;
349     default:
350       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
351       break;
352     }
353 }
354
355 static void
356 gtk_action_get_property (GObject    *object,
357                          guint       prop_id,
358                          GValue     *value,
359                          GParamSpec *pspec)
360 {
361   GtkAction *action;
362
363   action = GTK_ACTION (object);
364
365   switch (prop_id)
366     {
367     case PROP_NAME:
368       g_value_set_string (value, action->private_data->name);
369       break;
370     case PROP_LABEL:
371       g_value_set_string (value, action->private_data->label);
372       break;
373     case PROP_SHORT_LABEL:
374       g_value_set_string (value, action->private_data->short_label);
375       break;
376     case PROP_TOOLTIP:
377       g_value_set_string (value, action->private_data->tooltip);
378       break;
379     case PROP_STOCK_ID:
380       g_value_set_string (value, action->private_data->stock_id);
381       break;
382     case PROP_SENSITIVE:
383       g_value_set_boolean (value, action->private_data->sensitive);
384       break;
385     case PROP_VISIBLE:
386       g_value_set_boolean (value, action->private_data->visible);
387       break;
388     default:
389       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
390       break;
391     }
392 }
393
394 static GtkWidget *
395 create_menu_item (GtkAction *action)
396 {
397   GType menu_item_type;
398
399   menu_item_type = GTK_ACTION_GET_CLASS (action)->menu_item_type;
400
401   return g_object_new (menu_item_type, NULL);
402 }
403
404 static GtkWidget *
405 create_tool_item (GtkAction *action)
406 {
407   GType toolbar_item_type;
408
409   toolbar_item_type = GTK_ACTION_GET_CLASS (action)->toolbar_item_type;
410
411   return g_object_new (toolbar_item_type, NULL);
412 }
413
414 static void
415 gtk_action_remove_proxy (GtkWidget *widget, 
416                          GtkAction *action)
417 {
418   action->private_data->proxies = g_slist_remove (action->private_data->proxies, widget);
419 }
420
421 static void
422 gtk_action_sync_property (GtkAction  *action, 
423                           GParamSpec *pspec,
424                           GtkWidget  *proxy)
425 {
426   const gchar *property;
427   GValue value = { 0, };
428
429   property = g_param_spec_get_name (pspec);
430
431   g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
432   g_object_get_property (G_OBJECT (action), property, &value);
433
434   g_object_set_property (G_OBJECT (proxy), property, &value);
435   g_value_unset (&value);
436 }
437
438 static void
439 gtk_action_sync_label (GtkAction  *action, 
440                        GParamSpec *pspec, 
441                        GtkWidget  *proxy)
442 {
443   GtkWidget *label = NULL;
444
445   g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
446   label = GTK_BIN (proxy)->child;
447
448   if (GTK_IS_LABEL (label))
449     gtk_label_set_label (GTK_LABEL (label), action->private_data->label);
450 }
451
452 static void
453 gtk_action_sync_short_label (GtkAction  *action, 
454                              GParamSpec *pspec,
455                              GtkWidget  *proxy)
456 {
457   GValue value = { 0, };
458
459   g_value_init (&value, G_TYPE_STRING);
460   g_object_get_property (G_OBJECT (action), "short_label", &value);
461
462   g_object_set_property (G_OBJECT (proxy), "label", &value);
463   g_value_unset (&value);
464 }
465
466 static void
467 gtk_action_sync_stock_id (GtkAction  *action, 
468                           GParamSpec *pspec,
469                           GtkWidget  *proxy)
470 {
471   GtkWidget *image = NULL;
472
473   if (GTK_IS_IMAGE_MENU_ITEM (proxy))
474     {
475       image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
476
477       if (GTK_IS_IMAGE (image))
478         gtk_image_set_from_stock (GTK_IMAGE (image),
479                                   action->private_data->stock_id, GTK_ICON_SIZE_MENU);
480     }
481 }
482
483 static gboolean
484 gtk_action_create_menu_proxy (GtkToolItem *tool_item, 
485                               GtkAction   *action)
486 {
487   GtkWidget *menu_item = gtk_action_create_menu_item (action);
488
489   g_object_ref (menu_item);
490   gtk_object_sink (GTK_OBJECT (menu_item));
491   
492   gtk_tool_item_set_proxy_menu_item (tool_item, "gtk-action-menu-item", menu_item);
493   g_object_unref (menu_item);
494
495   return TRUE;
496 }
497
498 static void
499 connect_proxy (GtkAction *action, 
500                GtkWidget *proxy)
501 {
502   g_object_ref (action);
503   g_object_set_data_full (G_OBJECT (proxy), "gtk-action", action,
504                           g_object_unref);
505
506   /* add this widget to the list of proxies */
507   action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy);
508   g_signal_connect (proxy, "destroy",
509                     G_CALLBACK (gtk_action_remove_proxy), action);
510
511   g_signal_connect_object (action, "notify::sensitive",
512                            G_CALLBACK (gtk_action_sync_property), proxy, 0);
513   gtk_widget_set_sensitive (proxy, action->private_data->sensitive);
514
515   g_signal_connect_object (action, "notify::visible",
516                            G_CALLBACK (gtk_action_sync_property), proxy, 0);
517   if (action->private_data->visible)
518     gtk_widget_show (proxy);
519   else
520     gtk_widget_hide (proxy);
521
522   if (GTK_IS_MENU_ITEM (proxy))
523     {
524       GtkWidget *label;
525       /* menu item specific synchronisers ... */
526       
527       label = GTK_BIN (proxy)->child;
528
529       /* make sure label is a label */
530       if (label && !GTK_IS_LABEL (label))
531         {
532           gtk_container_remove (GTK_CONTAINER (proxy), label);
533           label = NULL;
534         }
535       if (!label)
536         {
537           label = g_object_new (GTK_TYPE_ACCEL_LABEL,
538                                 "use_underline", TRUE,
539                                 "xalign", 0.0,
540                                 "visible", TRUE,
541                                 "parent", proxy,
542                                 "accel_widget", proxy,
543                                 NULL);
544         }
545       gtk_label_set_label (GTK_LABEL (label), action->private_data->label);
546       g_signal_connect_object (action, "notify::label",
547                                G_CALLBACK (gtk_action_sync_label), proxy, 0);
548
549       if (GTK_IS_IMAGE_MENU_ITEM (proxy))
550         {
551           GtkWidget *image;
552
553           image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
554           if (image && !GTK_IS_IMAGE (image))
555             {
556               gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), NULL);
557               image = NULL;
558             }
559           if (!image)
560             {
561               image = gtk_image_new_from_stock (NULL,
562                                                 GTK_ICON_SIZE_MENU);
563               gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy),
564                                              image);
565               gtk_widget_show (image);
566             }
567           gtk_image_set_from_stock (GTK_IMAGE (image),
568                                     action->private_data->stock_id, GTK_ICON_SIZE_MENU);
569           g_signal_connect_object (action, "notify::stock_id",
570                                    G_CALLBACK (gtk_action_sync_stock_id),
571                                    proxy, 0);
572         }
573
574       if (action->private_data->accel_quark)
575         {
576           gtk_menu_item_set_accel_path (GTK_MENU_ITEM (proxy),
577                                 g_quark_to_string (action->private_data->accel_quark));
578         }
579
580       g_signal_connect_object (proxy, "activate",
581                                G_CALLBACK (gtk_action_activate), action,
582                                G_CONNECT_SWAPPED);
583     }
584   else if (GTK_IS_TOOL_BUTTON (proxy))
585     {
586       /* toolbar button specific synchronisers ... */
587
588       /* synchronise the label */
589       g_object_set (G_OBJECT (proxy),
590                     "label", action->private_data->short_label,
591                     "use_underline", TRUE,
592                     NULL);
593       g_signal_connect_object (action, "notify::short_label",
594                                G_CALLBACK (gtk_action_sync_short_label),
595                                proxy, 0);
596       
597       g_object_set (G_OBJECT (proxy), "stock_id", action->private_data->stock_id, NULL);
598       g_signal_connect_object (action, "notify::stock_id",
599                         G_CALLBACK (gtk_action_sync_property), proxy, 0);
600
601       g_signal_connect_object (proxy, "create_menu_proxy",
602                                G_CALLBACK (gtk_action_create_menu_proxy),
603                                action, 0);
604
605       g_signal_connect_object (proxy, "clicked",
606                                G_CALLBACK (gtk_action_activate), action,
607                                G_CONNECT_SWAPPED);
608     }
609 }
610
611 static void
612 disconnect_proxy (GtkAction *action, 
613                   GtkWidget *proxy)
614 {
615   static guint notify_id = 0;
616
617   if (!notify_id)
618     notify_id = g_signal_lookup ("notify", G_TYPE_OBJECT);
619
620   g_object_set_data (G_OBJECT (proxy), "gtk-action", NULL);
621
622   /* remove proxy from list of proxies */
623   g_signal_handlers_disconnect_by_func (proxy,
624                                         G_CALLBACK (gtk_action_remove_proxy),
625                                         action);
626   gtk_action_remove_proxy (proxy, action);
627
628   /* disconnect the activate handler */
629   g_signal_handlers_disconnect_by_func (proxy,
630                                         G_CALLBACK (gtk_action_activate),
631                                         action);
632
633   /* disconnect handlers for notify::* signals */
634   g_signal_handlers_disconnect_by_func (proxy,
635                                         G_CALLBACK (gtk_action_sync_property),
636                                         action);
637
638   g_signal_handlers_disconnect_by_func (action,
639                                 G_CALLBACK (gtk_action_sync_stock_id), proxy);
640
641   /* menu item specific synchronisers ... */
642   g_signal_handlers_disconnect_by_func (action,
643                                         G_CALLBACK (gtk_action_sync_label),
644                                         proxy);
645
646   gtk_menu_item_set_accel_path (GTK_MENU_ITEM (proxy), NULL);
647
648   /* toolbar button specific synchronisers ... */
649   g_signal_handlers_disconnect_by_func (action,
650                                         G_CALLBACK (gtk_action_sync_short_label),
651                                         proxy);
652   g_signal_handlers_disconnect_by_func (proxy,
653                                         G_CALLBACK (gtk_action_create_menu_proxy),
654                                         action);
655 }
656
657 /**
658  * gtk_action_activate:
659  * @action: the action object
660  *
661  * Emits the "activate" signal on the specified action. 
662  * This gets called by the proxy widgets when they get activated.
663  *
664  * It can also be used to manually activate an action.
665  *
666  * Since: 2.4
667  */
668 void
669 gtk_action_activate (GtkAction *action)
670 {
671   g_signal_emit (action, action_signals[ACTIVATE], 0);
672 }
673
674 /**
675  * gtk_action_create_icon:
676  * @action: the action object
677  * @icon_size: the size of the icon that should be created.
678  *
679  * This function is intended for use by action implementations to
680  * create icons displayed in the proxy widgets.
681  *
682  * Returns: a widget that displays the icon for this action.
683  *
684  * Since: 2.4
685  */
686 GtkWidget *
687 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
688 {
689   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
690
691   if (action->private_data->stock_id)
692     return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
693   else
694     return NULL;
695 }
696
697 /**
698  * gtk_action_create_menu_item:
699  * @action: the action object
700  *
701  * Creates a menu item widget that proxies for the given action.
702  *
703  * Returns: a menu item connected to the action.
704  *
705  * Since: 2.4
706  */
707 GtkWidget *
708 gtk_action_create_menu_item (GtkAction *action)
709 {
710   GtkWidget *menu_item;
711
712   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
713
714   menu_item = (* GTK_ACTION_GET_CLASS (action)->create_menu_item) (action);
715
716   (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, menu_item);
717
718   return menu_item;
719 }
720
721 /**
722  * gtk_action_create_tool_item:
723  * @action: the action object
724  *
725  * Creates a toolbar item widget that proxies for the given action.
726  *
727  * Returns: a toolbar item connected to the action.
728  *
729  * Since: 2.4
730  */
731 GtkWidget *
732 gtk_action_create_tool_item (GtkAction *action)
733 {
734   GtkWidget *button;
735
736   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
737
738   button = (* GTK_ACTION_GET_CLASS (action)->create_tool_item) (action);
739
740   (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, button);
741
742   return button;
743 }
744
745 /**
746  * gtk_action_connect_proxy:
747  * @action: the action object
748  * @proxy: the proxy widget
749  *
750  * Connects a widget to an action object as a proxy.  Synchronises 
751  * various properties of the action with the widget (such as label 
752  * text, icon, tooltip, etc), and attaches a callback so that the 
753  * action gets activated when the proxy widget does.
754  *
755  * If the widget is already connected to an action, it is disconnected
756  * first.
757  *
758  * Since: 2.4
759  */
760 void
761 gtk_action_connect_proxy (GtkAction *action,
762                           GtkWidget *proxy)
763 {
764   GtkAction *prev_action;
765
766   g_return_if_fail (GTK_IS_ACTION (action));
767   g_return_if_fail (GTK_IS_WIDGET (proxy));
768
769   prev_action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
770
771   if (prev_action)
772     {
773       (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (action, proxy);  
774     }
775
776   (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, proxy);
777 }
778
779 /**
780  * gtk_action_disconnect_proxy:
781  * @action: the action object
782  * @proxy: the proxy widget
783  *
784  * Disconnects a proxy widget from an action.  
785  * Does <emphasis>not</emphasis> destroy the widget, however.
786  *
787  * Since: 2.4
788  */
789 void
790 gtk_action_disconnect_proxy (GtkAction *action,
791                              GtkWidget *proxy)
792 {
793   g_return_if_fail (GTK_IS_ACTION (action));
794   g_return_if_fail (GTK_IS_WIDGET (proxy));
795
796   g_return_if_fail (g_object_get_data (G_OBJECT (proxy), "gtk-action") != action);
797
798   (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (action, proxy);  
799 }
800
801 /**
802  * gtk_action_get_proxies:
803  * @action: the action object
804  * 
805  * Returns the proxy widgets for an action.
806  * 
807  * Return value: a #GSList of proxy widgets. The list is owned by the action and
808  * must not be modified.
809  *
810  * Since: 2.4
811  **/
812 GSList*
813 gtk_action_get_proxies (GtkAction *action)
814 {
815   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
816
817   return action->private_data->proxies;
818 }
819
820
821 /**
822  * gtk_action_get_name:
823  * @action: the action object
824  * 
825  * Returns the name of the action.
826  * 
827  * Return value: the name of the action. The string belongs to GTK+ and should not
828  *   be freed.
829  *
830  * Since: 2.4
831  **/
832 const gchar *
833 gtk_action_get_name (GtkAction *action)
834 {
835   g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
836
837   return action->private_data->name;
838 }
839
840 /**
841  * gtk_action_block_activate_from:
842  * @action: the action object
843  * @proxy: a proxy widget
844  *
845  * Disables calls to the gtk_action_activate()
846  * function by signals on the given proxy widget.  This is used to
847  * break notification loops for things like check or radio actions.
848  *
849  * This function is intended for use by action implementations.
850  * 
851  * Since: 2.4
852  */
853 void
854 gtk_action_block_activate_from (GtkAction *action, 
855                                 GtkWidget *proxy)
856 {
857   g_return_if_fail (GTK_IS_ACTION (action));
858   
859   g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
860                                    action);
861 }
862
863 /**
864  * gtk_action_unblock_activate_from:
865  * @action: the action object
866  * @proxy: a proxy widget
867  *
868  * Re-enables calls to the gtk_action_activate()
869  * function by signals on the given proxy widget.  This undoes the
870  * blocking done by gtk_action_block_activate_from().
871  *
872  * This function is intended for use by action implementations.
873  * 
874  * Since: 2.4
875  */
876 void
877 gtk_action_unblock_activate_from (GtkAction *action, 
878                                   GtkWidget *proxy)
879 {
880   g_return_if_fail (GTK_IS_ACTION (action));
881
882   g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
883                                      action);
884 }
885
886 /**
887  * gtk_action_set_accel_path:
888  * @action: the action object
889  * @accel_path: the accelerator path
890  *
891  * Sets the accel path for this action.  All proxy widgets associated
892  * with the action will have this accel path, so that their
893  * accelerators are consistent.
894  *
895  * Since: 2.4
896  */
897 void
898 gtk_action_set_accel_path (GtkAction   *action, 
899                            const gchar *accel_path)
900 {
901   action->private_data->accel_quark = g_quark_from_string (accel_path);
902 }