2 * GTK - The GIMP Toolkit
3 * Copyright (C) 1998, 1999 Red Hat, Inc.
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.
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.
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.
23 * Author: James Henstridge <james@daa.com.au>
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/.
33 #include "gtkaction.h"
34 #include "gtkaccellabel.h"
35 #include "gtkbutton.h"
37 #include "gtkimagemenuitem.h"
40 #include "gtkmarshalers.h"
41 #include "gtkmenuitem.h"
43 #include "gtktoolbutton.h"
44 #include "gtktoolbar.h"
47 #define GTK_ACTION_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION, GtkActionPrivate))
49 struct _GtkActionPrivate
55 gchar *stock_id; /* icon */
59 guint label_set : 1; /* these two used so we can set label */
60 guint short_label_set : 1; /* based on stock id */
61 guint is_important : 1;
65 GtkAccelGroup *accel_group;
66 GClosure *accel_closure;
69 /* list of proxy widgets */
94 static void gtk_action_init (GtkAction *action);
95 static void gtk_action_class_init (GtkActionClass *class);
97 static GQuark accel_path_id = 0;
98 static const gchar *accel_path_key = "GtkAction::accel_path";
101 gtk_action_get_type (void)
103 static GtkType type = 0;
107 static const GTypeInfo type_info =
109 sizeof (GtkActionClass),
110 (GBaseInitFunc) NULL,
111 (GBaseFinalizeFunc) NULL,
112 (GClassInitFunc) gtk_action_class_init,
113 (GClassFinalizeFunc) NULL,
118 (GInstanceInitFunc) gtk_action_init,
121 type = g_type_register_static (G_TYPE_OBJECT,
128 static void gtk_action_finalize (GObject *object);
129 static void gtk_action_set_property (GObject *object,
133 static void gtk_action_get_property (GObject *object,
138 static GtkWidget *create_menu_item (GtkAction *action);
139 static GtkWidget *create_tool_item (GtkAction *action);
140 static void connect_proxy (GtkAction *action,
142 static void disconnect_proxy (GtkAction *action,
144 static void closure_accel_activate (GClosure *closure,
145 GValue *return_value,
146 guint n_param_values,
147 const GValue *param_values,
148 gpointer invocation_hint,
149 gpointer marshal_data);
151 static GObjectClass *parent_class = NULL;
152 static guint action_signals[LAST_SIGNAL] = { 0 };
156 gtk_action_class_init (GtkActionClass *klass)
158 GObjectClass *gobject_class;
160 accel_path_id = g_quark_from_static_string (accel_path_key);
162 parent_class = g_type_class_peek_parent (klass);
163 gobject_class = G_OBJECT_CLASS (klass);
165 gobject_class->finalize = gtk_action_finalize;
166 gobject_class->set_property = gtk_action_set_property;
167 gobject_class->get_property = gtk_action_get_property;
169 klass->activate = NULL;
171 klass->create_menu_item = create_menu_item;
172 klass->create_tool_item = create_tool_item;
173 klass->connect_proxy = connect_proxy;
174 klass->disconnect_proxy = disconnect_proxy;
176 klass->menu_item_type = GTK_TYPE_IMAGE_MENU_ITEM;
177 klass->toolbar_item_type = GTK_TYPE_TOOL_BUTTON;
179 g_object_class_install_property (gobject_class,
181 g_param_spec_string ("name",
183 _("A unique name for the action."),
186 G_PARAM_CONSTRUCT_ONLY));
187 g_object_class_install_property (gobject_class,
189 g_param_spec_string ("label",
191 _("The label used for menu items and buttons that activate this action."),
194 g_object_class_install_property (gobject_class,
196 g_param_spec_string ("short_label",
198 _("A shorter label that may be used on toolbar buttons."),
201 g_object_class_install_property (gobject_class,
203 g_param_spec_string ("tooltip",
205 _("A tooltip for this action."),
208 g_object_class_install_property (gobject_class,
210 g_param_spec_string ("stock_id",
212 _("The stock icon displayed in widgets representing this action."),
215 g_object_class_install_property (gobject_class,
217 g_param_spec_boolean ("is_important",
219 _("Whether the action is considered important. When TRUE, toolitem proxies for this action show text in GTK_TOOLBAR_BOTH_HORIZ mode"),
222 g_object_class_install_property (gobject_class,
224 g_param_spec_boolean ("sensitive",
226 _("Whether the action is enabled."),
229 g_object_class_install_property (gobject_class,
231 g_param_spec_boolean ("visible",
233 _("Whether the action is visible."),
239 * GtkAction::activate:
240 * @action: the #GtkAction
242 * The "activate" signal is emitted when the action is activated.
246 action_signals[ACTIVATE] =
247 g_signal_new ("activate",
248 G_OBJECT_CLASS_TYPE (klass),
249 G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE,
250 G_STRUCT_OFFSET (GtkActionClass, activate), NULL, NULL,
251 g_cclosure_marshal_VOID__VOID,
255 * GtkAction::connect-proxy:
256 * @action: the action
259 * The connect_proxy signal is emitted after connecting a proxy to
260 * an action. Note that the proxy may have been connected to a different
263 * This is intended for simple customizations for which a custom action
264 * class would be too clumsy, e.g. showing tooltips for menuitems in the
269 action_signals[CONNECT_PROXY] =
270 g_signal_new ("connect_proxy",
271 G_OBJECT_CLASS_TYPE (klass),
273 _gtk_marshal_VOID__OBJECT,
278 * GtkAction::disconnect-proxy:
279 * @action: the action
282 * The disconnect_proxy signal is emitted after disconnecting a proxy
287 action_signals[DISCONNECT_PROXY] =
288 g_signal_new ("disconnect_proxy",
289 G_OBJECT_CLASS_TYPE (klass),
291 _gtk_marshal_VOID__OBJECT,
295 g_type_class_add_private (gobject_class, sizeof (GtkActionPrivate));
300 gtk_action_init (GtkAction *action)
302 action->private_data = GTK_ACTION_GET_PRIVATE (action);
304 action->private_data->name = NULL;
305 action->private_data->label = NULL;
306 action->private_data->short_label = NULL;
307 action->private_data->tooltip = NULL;
308 action->private_data->stock_id = NULL;
309 action->private_data->is_important = FALSE;
311 action->private_data->sensitive = TRUE;
312 action->private_data->visible = TRUE;
314 action->private_data->label_set = FALSE;
315 action->private_data->short_label_set = FALSE;
317 action->private_data->accel_count = 0;
318 action->private_data->accel_closure =
319 g_closure_new_object (sizeof (GClosure), G_OBJECT (action));
320 g_closure_set_marshal (action->private_data->accel_closure,
321 closure_accel_activate);
322 g_closure_ref (action->private_data->accel_closure);
323 g_closure_sink (action->private_data->accel_closure);
325 action->private_data->accel_quark = 0;
326 action->private_data->accel_count = 0;
327 action->private_data->accel_group = NULL;
329 action->private_data->proxies = NULL;
333 gtk_action_finalize (GObject *object)
336 action = GTK_ACTION (object);
338 g_free (action->private_data->name);
339 g_free (action->private_data->label);
340 g_free (action->private_data->short_label);
341 g_free (action->private_data->tooltip);
342 g_free (action->private_data->stock_id);
344 g_closure_unref (action->private_data->accel_closure);
345 if (action->private_data->accel_group)
346 g_object_unref (action->private_data->accel_group);
350 gtk_action_set_property (GObject *object,
358 action = GTK_ACTION (object);
363 tmp = action->private_data->name;
364 action->private_data->name = g_value_dup_string (value);
368 tmp = action->private_data->label;
369 action->private_data->label = g_value_dup_string (value);
371 action->private_data->label_set = (action->private_data->label != NULL);
372 /* if label is unset, then use the label from the stock item */
373 if (!action->private_data->label_set && action->private_data->stock_id)
375 GtkStockItem stock_item;
377 if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
378 action->private_data->label = g_strdup (stock_item.label);
380 /* if short_label is unset, set short_label=label */
381 if (!action->private_data->short_label_set)
383 tmp = action->private_data->short_label;
384 action->private_data->short_label = g_strdup (action->private_data->label);
386 g_object_notify (object, "short_label");
389 case PROP_SHORT_LABEL:
390 tmp = action->private_data->short_label;
391 action->private_data->short_label = g_value_dup_string (value);
393 action->private_data->short_label_set = (action->private_data->short_label != NULL);
394 /* if short_label is unset, then use the value of label */
395 if (!action->private_data->short_label_set)
397 action->private_data->short_label = g_strdup (action->private_data->label);
401 tmp = action->private_data->tooltip;
402 action->private_data->tooltip = g_value_dup_string (value);
406 tmp = action->private_data->stock_id;
407 action->private_data->stock_id = g_value_dup_string (value);
409 /* update label and short_label if appropriate */
410 if (!action->private_data->label_set)
412 GtkStockItem stock_item;
414 g_free (action->private_data->label);
415 if (gtk_stock_lookup (action->private_data->stock_id, &stock_item))
416 action->private_data->label = g_strdup (stock_item.label);
418 action->private_data->label = NULL;
419 g_object_notify (object, "label");
421 if (!action->private_data->short_label_set)
423 tmp = action->private_data->short_label;
424 action->private_data->short_label = g_strdup (action->private_data->label);
426 g_object_notify (object, "short_label");
429 case PROP_IS_IMPORTANT:
430 action->private_data->is_important = g_value_get_boolean (value);
433 action->private_data->sensitive = g_value_get_boolean (value);
436 action->private_data->visible = g_value_get_boolean (value);
439 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
445 gtk_action_get_property (GObject *object,
452 action = GTK_ACTION (object);
457 g_value_set_string (value, action->private_data->name);
460 g_value_set_string (value, action->private_data->label);
462 case PROP_SHORT_LABEL:
463 g_value_set_string (value, action->private_data->short_label);
466 g_value_set_string (value, action->private_data->tooltip);
469 g_value_set_string (value, action->private_data->stock_id);
471 case PROP_IS_IMPORTANT:
472 g_value_set_boolean (value, action->private_data->is_important);
475 g_value_set_boolean (value, action->private_data->sensitive);
478 g_value_set_boolean (value, action->private_data->visible);
481 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
487 create_menu_item (GtkAction *action)
489 GType menu_item_type;
491 menu_item_type = GTK_ACTION_GET_CLASS (action)->menu_item_type;
493 return g_object_new (menu_item_type, NULL);
497 create_tool_item (GtkAction *action)
499 GType toolbar_item_type;
501 toolbar_item_type = GTK_ACTION_GET_CLASS (action)->toolbar_item_type;
503 return g_object_new (toolbar_item_type, NULL);
507 remove_proxy (GtkWidget *proxy,
510 if (GTK_IS_MENU_ITEM (proxy))
511 gtk_action_disconnect_accelerator (action);
513 action->private_data->proxies = g_slist_remove (action->private_data->proxies, proxy);
517 gtk_action_sync_property (GtkAction *action,
521 const gchar *property;
522 GValue value = { 0, };
524 property = g_param_spec_get_name (pspec);
526 g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
527 g_object_get_property (G_OBJECT (action), property, &value);
529 g_object_set_property (G_OBJECT (proxy), property, &value);
530 g_value_unset (&value);
534 gtk_action_sync_label (GtkAction *action,
538 GtkWidget *label = NULL;
540 g_return_if_fail (GTK_IS_MENU_ITEM (proxy));
541 label = GTK_BIN (proxy)->child;
543 if (GTK_IS_LABEL (label))
544 gtk_label_set_label (GTK_LABEL (label), action->private_data->label);
548 gtk_action_sync_short_label (GtkAction *action,
552 GValue value = { 0, };
554 g_value_init (&value, G_TYPE_STRING);
555 g_object_get_property (G_OBJECT (action), "short_label", &value);
557 g_object_set_property (G_OBJECT (proxy), "label", &value);
558 g_value_unset (&value);
562 gtk_action_sync_stock_id (GtkAction *action,
566 GtkWidget *image = NULL;
568 if (GTK_IS_IMAGE_MENU_ITEM (proxy))
570 image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
572 if (GTK_IS_IMAGE (image))
573 gtk_image_set_from_stock (GTK_IMAGE (image),
574 action->private_data->stock_id, GTK_ICON_SIZE_MENU);
579 gtk_action_sync_tooltip (GtkAction *action,
583 g_return_if_fail (GTK_IS_TOOL_ITEM (proxy));
585 if (GTK_IS_TOOLBAR (gtk_widget_get_parent (proxy)))
587 GtkToolbar *toolbar = GTK_TOOLBAR (gtk_widget_get_parent (proxy));
589 gtk_tool_item_set_tooltip (GTK_TOOL_ITEM (proxy),
591 action->private_data->tooltip,
598 gtk_action_create_menu_proxy (GtkToolItem *tool_item,
601 GtkWidget *menu_item = gtk_action_create_menu_item (action);
603 g_object_ref (menu_item);
604 gtk_object_sink (GTK_OBJECT (menu_item));
606 gtk_tool_item_set_proxy_menu_item (tool_item, "gtk-action-menu-item", menu_item);
607 g_object_unref (menu_item);
613 connect_proxy (GtkAction *action,
616 g_object_ref (action);
617 g_object_set_data_full (G_OBJECT (proxy), "gtk-action", action,
620 /* add this widget to the list of proxies */
621 action->private_data->proxies = g_slist_prepend (action->private_data->proxies, proxy);
622 g_signal_connect (proxy, "destroy",
623 G_CALLBACK (remove_proxy), action);
625 g_signal_connect_object (action, "notify::sensitive",
626 G_CALLBACK (gtk_action_sync_property), proxy, 0);
627 gtk_widget_set_sensitive (proxy, action->private_data->sensitive);
629 g_signal_connect_object (action, "notify::visible",
630 G_CALLBACK (gtk_action_sync_property), proxy, 0);
631 if (action->private_data->visible)
632 gtk_widget_show (proxy);
634 gtk_widget_hide (proxy);
635 gtk_widget_set_no_show_all (proxy, TRUE);
637 if (GTK_IS_MENU_ITEM (proxy))
640 /* menu item specific synchronisers ... */
642 if (action->private_data->accel_quark)
644 gtk_action_connect_accelerator (action);
645 gtk_menu_item_set_accel_path (GTK_MENU_ITEM (proxy),
646 g_quark_to_string (action->private_data->accel_quark));
649 label = GTK_BIN (proxy)->child;
651 /* make sure label is a label */
652 if (label && !GTK_IS_LABEL (label))
654 gtk_container_remove (GTK_CONTAINER (proxy), label);
659 label = g_object_new (GTK_TYPE_ACCEL_LABEL,
660 "use_underline", TRUE,
666 if (GTK_IS_ACCEL_LABEL (label) && action->private_data->accel_quark)
667 g_object_set (G_OBJECT (label),
668 "accel_closure", action->private_data->accel_closure,
671 gtk_label_set_label (GTK_LABEL (label), action->private_data->label);
672 g_signal_connect_object (action, "notify::label",
673 G_CALLBACK (gtk_action_sync_label), proxy, 0);
675 if (GTK_IS_IMAGE_MENU_ITEM (proxy))
679 image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (proxy));
680 if (image && !GTK_IS_IMAGE (image))
682 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy), NULL);
687 image = gtk_image_new_from_stock (NULL,
689 gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (proxy),
691 gtk_widget_show (image);
693 gtk_image_set_from_stock (GTK_IMAGE (image),
694 action->private_data->stock_id, GTK_ICON_SIZE_MENU);
695 g_signal_connect_object (action, "notify::stock_id",
696 G_CALLBACK (gtk_action_sync_stock_id),
700 g_signal_connect_object (proxy, "activate",
701 G_CALLBACK (gtk_action_activate), action,
705 else if (GTK_IS_TOOL_BUTTON (proxy))
707 /* toolbar button specific synchronisers ... */
709 g_object_set (G_OBJECT (proxy),
710 "label", action->private_data->short_label,
711 "use_underline", TRUE,
712 "stock_id", action->private_data->stock_id,
713 "is_important", action->private_data->is_important,
715 /* FIXME: we should set the tooltip here, but the current api
716 * doesn't allow it before the item is added to a toolbar.
718 g_signal_connect_object (action, "notify::short_label",
719 G_CALLBACK (gtk_action_sync_short_label),
721 g_signal_connect_object (action, "notify::stock_id",
722 G_CALLBACK (gtk_action_sync_property),
724 g_signal_connect_object (action, "notify::is_important",
725 G_CALLBACK (gtk_action_sync_property),
727 g_signal_connect_object (action, "notify::tooltip",
728 G_CALLBACK (gtk_action_sync_tooltip),
731 g_signal_connect_object (proxy, "create_menu_proxy",
732 G_CALLBACK (gtk_action_create_menu_proxy),
735 g_signal_connect_object (proxy, "clicked",
736 G_CALLBACK (gtk_action_activate), action,
739 else if (GTK_IS_BUTTON (proxy))
741 /* button specific synchronisers ... */
743 /* synchronise the label */
744 g_object_set (G_OBJECT (proxy),
745 "label", action->private_data->short_label,
746 "use_underline", TRUE,
748 g_signal_connect_object (action, "notify::short_label",
749 G_CALLBACK (gtk_action_sync_short_label),
752 g_signal_connect_object (proxy, "clicked",
753 G_CALLBACK (gtk_action_activate), action,
757 g_signal_emit (action, action_signals[CONNECT_PROXY], 0, proxy);
761 disconnect_proxy (GtkAction *action,
764 g_object_set_data (G_OBJECT (proxy), "gtk-action", NULL);
766 /* remove proxy from list of proxies */
767 g_signal_handlers_disconnect_by_func (proxy,
768 G_CALLBACK (remove_proxy),
770 remove_proxy (proxy, action);
772 /* disconnect the activate handler */
773 g_signal_handlers_disconnect_by_func (proxy,
774 G_CALLBACK (gtk_action_activate),
777 /* disconnect handlers for notify::* signals */
778 g_signal_handlers_disconnect_by_func (proxy,
779 G_CALLBACK (gtk_action_sync_property),
782 g_signal_handlers_disconnect_by_func (action,
783 G_CALLBACK (gtk_action_sync_stock_id), proxy);
785 /* menu item specific synchronisers ... */
786 g_signal_handlers_disconnect_by_func (action,
787 G_CALLBACK (gtk_action_sync_label),
790 /* toolbar button specific synchronisers ... */
791 g_signal_handlers_disconnect_by_func (action,
792 G_CALLBACK (gtk_action_sync_short_label),
795 g_signal_handlers_disconnect_by_func (proxy,
796 G_CALLBACK (gtk_action_create_menu_proxy),
799 g_signal_emit (action, action_signals[DISCONNECT_PROXY], 0, proxy);
803 * gtk_action_activate:
804 * @action: the action object
806 * Emits the "activate" signal on the specified action.
807 * This gets called by the proxy widgets when they get activated.
809 * It can also be used to manually activate an action.
814 gtk_action_activate (GtkAction *action)
816 g_signal_emit (action, action_signals[ACTIVATE], 0);
820 * gtk_action_create_icon:
821 * @action: the action object
822 * @icon_size: the size of the icon that should be created.
824 * This function is intended for use by action implementations to
825 * create icons displayed in the proxy widgets.
827 * Returns: a widget that displays the icon for this action.
832 gtk_action_create_icon (GtkAction *action, GtkIconSize icon_size)
834 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
836 if (action->private_data->stock_id)
837 return gtk_image_new_from_stock (action->private_data->stock_id, icon_size);
843 * gtk_action_create_menu_item:
844 * @action: the action object
846 * Creates a menu item widget that proxies for the given action.
848 * Returns: a menu item connected to the action.
853 gtk_action_create_menu_item (GtkAction *action)
855 GtkWidget *menu_item;
857 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
859 menu_item = (* GTK_ACTION_GET_CLASS (action)->create_menu_item) (action);
861 (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, menu_item);
867 * gtk_action_create_tool_item:
868 * @action: the action object
870 * Creates a toolbar item widget that proxies for the given action.
872 * Returns: a toolbar item connected to the action.
877 gtk_action_create_tool_item (GtkAction *action)
881 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
883 button = (* GTK_ACTION_GET_CLASS (action)->create_tool_item) (action);
885 (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, button);
891 * gtk_action_connect_proxy:
892 * @action: the action object
893 * @proxy: the proxy widget
895 * Connects a widget to an action object as a proxy. Synchronises
896 * various properties of the action with the widget (such as label
897 * text, icon, tooltip, etc), and attaches a callback so that the
898 * action gets activated when the proxy widget does.
900 * If the widget is already connected to an action, it is disconnected
906 gtk_action_connect_proxy (GtkAction *action,
909 GtkAction *prev_action;
911 g_return_if_fail (GTK_IS_ACTION (action));
912 g_return_if_fail (GTK_IS_WIDGET (proxy));
914 prev_action = g_object_get_data (G_OBJECT (proxy), "gtk-action");
917 (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (prev_action, proxy);
919 (* GTK_ACTION_GET_CLASS (action)->connect_proxy) (action, proxy);
923 * gtk_action_disconnect_proxy:
924 * @action: the action object
925 * @proxy: the proxy widget
927 * Disconnects a proxy widget from an action.
928 * Does <emphasis>not</emphasis> destroy the widget, however.
933 gtk_action_disconnect_proxy (GtkAction *action,
936 g_return_if_fail (GTK_IS_ACTION (action));
937 g_return_if_fail (GTK_IS_WIDGET (proxy));
939 g_return_if_fail (g_object_get_data (G_OBJECT (proxy), "gtk-action") == action);
941 (* GTK_ACTION_GET_CLASS (action)->disconnect_proxy) (action, proxy);
945 * gtk_action_get_proxies:
946 * @action: the action object
948 * Returns the proxy widgets for an action.
950 * Return value: a #GSList of proxy widgets. The list is owned by the action and
951 * must not be modified.
956 gtk_action_get_proxies (GtkAction *action)
958 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
960 return action->private_data->proxies;
965 * gtk_action_get_name:
966 * @action: the action object
968 * Returns the name of the action.
970 * Return value: the name of the action. The string belongs to GTK+ and should not
976 gtk_action_get_name (GtkAction *action)
978 g_return_val_if_fail (GTK_IS_ACTION (action), NULL);
980 return action->private_data->name;
984 * gtk_action_block_activate_from:
985 * @action: the action object
986 * @proxy: a proxy widget
988 * Disables calls to the gtk_action_activate()
989 * function by signals on the given proxy widget. This is used to
990 * break notification loops for things like check or radio actions.
992 * This function is intended for use by action implementations.
997 gtk_action_block_activate_from (GtkAction *action,
1000 g_return_if_fail (GTK_IS_ACTION (action));
1002 g_signal_handlers_block_by_func (proxy, G_CALLBACK (gtk_action_activate),
1007 * gtk_action_unblock_activate_from:
1008 * @action: the action object
1009 * @proxy: a proxy widget
1011 * Re-enables calls to the gtk_action_activate()
1012 * function by signals on the given proxy widget. This undoes the
1013 * blocking done by gtk_action_block_activate_from().
1015 * This function is intended for use by action implementations.
1020 gtk_action_unblock_activate_from (GtkAction *action,
1023 g_return_if_fail (GTK_IS_ACTION (action));
1025 g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (gtk_action_activate),
1030 closure_accel_activate (GClosure *closure,
1031 GValue *return_value,
1032 guint n_param_values,
1033 const GValue *param_values,
1034 gpointer invocation_hint,
1035 gpointer marshal_data)
1037 if (GTK_ACTION (closure->data)->private_data->sensitive)
1038 g_signal_emit (closure->data, action_signals[ACTIVATE], 0);
1040 /* we handled the accelerator */
1041 g_value_set_boolean (return_value, TRUE);
1045 * gtk_action_set_accel_path:
1046 * @action: the action object
1047 * @accel_path: the accelerator path
1049 * Sets the accel path for this action. All proxy widgets associated
1050 * with the action will have this accel path, so that their
1051 * accelerators are consistent.
1056 gtk_action_set_accel_path (GtkAction *action,
1057 const gchar *accel_path)
1059 g_return_if_fail (GTK_IS_ACTION (action));
1061 action->private_data->accel_quark = g_quark_from_string (accel_path);
1065 * gtk_action_set_accel_group:
1066 * @action: the action object
1067 * @accel_group: a #GtkAccelGroup or %NULL
1069 * Sets the #GtkAccelGroup in which the accelerator for this action
1070 * will be installed.
1075 gtk_action_set_accel_group (GtkAction *action,
1076 GtkAccelGroup *accel_group)
1078 g_return_if_fail (GTK_IS_ACTION (action));
1079 g_return_if_fail (accel_group == NULL || GTK_IS_ACCEL_GROUP (accel_group));
1082 g_object_ref (accel_group);
1083 if (action->private_data->accel_group)
1084 g_object_unref (action->private_data->accel_group);
1086 action->private_data->accel_group = accel_group;
1090 * gtk_action_connect_accelerator:
1091 * @action: a #GtkAction
1093 * Installs the accelerator for @action if @action has an
1094 * accel path and group. See gtk_action_set_accel_path() and
1095 * gtk_action_set_accel_group()
1097 * Since multiple proxies may independently trigger the installation
1098 * of the accelerator, the @action counts the number of times this
1099 * function has been called and doesn't remove the accelerator until
1100 * gtk_action_disconnect_accelerator() has been called as many times.
1105 gtk_action_connect_accelerator (GtkAction *action)
1107 g_return_if_fail (GTK_IS_ACTION (action));
1109 if (!action->private_data->accel_quark ||
1110 !action->private_data->accel_group)
1113 if (action->private_data->accel_count == 0)
1115 const gchar *accel_path =
1116 g_quark_to_string (action->private_data->accel_quark);
1118 gtk_accel_group_connect_by_path (action->private_data->accel_group,
1120 action->private_data->accel_closure);
1123 action->private_data->accel_count++;
1127 * gtk_action_disconnect_accelerator:
1128 * @action: a #GtkAction
1130 * Undoes the effect of one call to gtk_action_connect_accelerator().
1135 gtk_action_disconnect_accelerator (GtkAction *action)
1137 g_return_if_fail (GTK_IS_ACTION (action));
1139 if (!action->private_data->accel_quark ||
1140 !action->private_data->accel_group)
1143 action->private_data->accel_count--;
1145 if (action->private_data->accel_count == 0)
1146 gtk_accel_group_disconnect (action->private_data->accel_group,
1147 action->private_data->accel_closure);