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 "gtkactiongroup.h"
34 #include "gtkiconfactory.h"
35 #include "gtkicontheme.h"
37 #include "gtktoggleaction.h"
38 #include "gtkradioaction.h"
39 #include "gtkaccelmap.h"
40 #include "gtkmarshalers.h"
41 #include "gtkprivate.h"
45 #define GTK_ACTION_GROUP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION_GROUP, GtkActionGroupPrivate))
47 struct _GtkActionGroupPrivate
54 GtkTranslateFunc translate_func;
55 gpointer translate_data;
56 GtkDestroyNotify translate_notify;
76 static void gtk_action_group_init (GtkActionGroup *self);
77 static void gtk_action_group_class_init (GtkActionGroupClass *class);
78 static void gtk_action_group_finalize (GObject *object);
79 static void gtk_action_group_set_property (GObject *object,
83 static void gtk_action_group_get_property (GObject *object,
87 static GtkAction *gtk_action_group_real_get_action (GtkActionGroup *self,
92 gtk_action_group_get_type (void)
94 static GType type = 0;
98 static const GTypeInfo type_info =
100 sizeof (GtkActionGroupClass),
101 NULL, /* base_init */
102 NULL, /* base_finalize */
103 (GClassInitFunc) gtk_action_group_class_init,
104 NULL, /* class_finalize */
105 NULL, /* class_data */
106 sizeof (GtkActionGroup),
108 (GInstanceInitFunc) gtk_action_group_init,
111 type = g_type_register_static (G_TYPE_OBJECT, I_("GtkActionGroup"),
118 static GObjectClass *parent_class = NULL;
119 static guint action_group_signals[LAST_SIGNAL] = { 0 };
122 gtk_action_group_class_init (GtkActionGroupClass *klass)
124 GObjectClass *gobject_class;
126 gobject_class = G_OBJECT_CLASS (klass);
127 parent_class = g_type_class_peek_parent (klass);
129 gobject_class->finalize = gtk_action_group_finalize;
130 gobject_class->set_property = gtk_action_group_set_property;
131 gobject_class->get_property = gtk_action_group_get_property;
132 klass->get_action = gtk_action_group_real_get_action;
134 g_object_class_install_property (gobject_class,
136 g_param_spec_string ("name",
138 P_("A name for the action group."),
140 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
141 g_object_class_install_property (gobject_class,
143 g_param_spec_boolean ("sensitive",
145 P_("Whether the action group is enabled."),
147 GTK_PARAM_READWRITE));
148 g_object_class_install_property (gobject_class,
150 g_param_spec_boolean ("visible",
152 P_("Whether the action group is visible."),
154 GTK_PARAM_READWRITE));
157 * GtkActionGroup::connect-proxy:
158 * @action_group: the group
159 * @action: the action
162 * The connect_proxy signal is emitted after connecting a proxy to
163 * an action in the group. Note that the proxy may have been connected
164 * to a different action before.
166 * This is intended for simple customizations for which a custom action
167 * class would be too clumsy, e.g. showing tooltips for menuitems in the
170 * #GtkUIManager proxies the signal and provides global notification
171 * just before any action is connected to a proxy, which is probably more
176 action_group_signals[CONNECT_PROXY] =
177 g_signal_new (I_("connect_proxy"),
178 G_OBJECT_CLASS_TYPE (klass),
180 _gtk_marshal_VOID__OBJECT_OBJECT,
182 GTK_TYPE_ACTION, GTK_TYPE_WIDGET);
185 * GtkActionGroup::disconnect-proxy:
186 * @action_group: the group
187 * @action: the action
190 * The disconnect_proxy signal is emitted after disconnecting a proxy
191 * from an action in the group.
193 * #GtkUIManager proxies the signal and provides global notification
194 * just before any action is connected to a proxy, which is probably more
199 action_group_signals[DISCONNECT_PROXY] =
200 g_signal_new (I_("disconnect_proxy"),
201 G_OBJECT_CLASS_TYPE (klass),
203 _gtk_marshal_VOID__OBJECT_OBJECT,
205 GTK_TYPE_ACTION, GTK_TYPE_WIDGET);
208 * GtkActionGroup::pre-activate:
209 * @action_group: the group
210 * @action: the action
212 * The pre_activate signal is emitted just before the @action in the
213 * @action_group is activated
215 * This is intended for #GtkUIManager to proxy the signal and provide global
216 * notification just before any action is activated.
220 action_group_signals[PRE_ACTIVATE] =
221 g_signal_new (I_("pre_activate"),
222 G_OBJECT_CLASS_TYPE (klass),
224 _gtk_marshal_VOID__OBJECT,
229 * GtkActionGroup::post-activate:
230 * @action_group: the group
231 * @action: the action
233 * The post_activate signal is emitted just after the @action in the
234 * @action_group is activated
236 * This is intended for #GtkUIManager to proxy the signal and provide global
237 * notification just after any action is activated.
241 action_group_signals[POST_ACTIVATE] =
242 g_signal_new (I_("post_activate"),
243 G_OBJECT_CLASS_TYPE (klass),
245 _gtk_marshal_VOID__OBJECT,
249 g_type_class_add_private (gobject_class, sizeof (GtkActionGroupPrivate));
254 remove_action (GtkAction *action)
256 g_object_set (action, I_("action-group"), NULL, NULL);
257 g_object_unref (action);
261 gtk_action_group_init (GtkActionGroup *self)
263 self->private_data = GTK_ACTION_GROUP_GET_PRIVATE (self);
264 self->private_data->name = NULL;
265 self->private_data->sensitive = TRUE;
266 self->private_data->visible = TRUE;
267 self->private_data->actions = g_hash_table_new_full (g_str_hash, g_str_equal,
268 (GDestroyNotify) g_free,
269 (GDestroyNotify) remove_action);
270 self->private_data->translate_func = NULL;
271 self->private_data->translate_data = NULL;
272 self->private_data->translate_notify = NULL;
276 * gtk_action_group_new:
277 * @name: the name of the action group.
279 * Creates a new #GtkActionGroup object. The name of the action group
280 * is used when associating <link linkend="Action-Accel">keybindings</link>
283 * Returns: the new #GtkActionGroup
288 gtk_action_group_new (const gchar *name)
290 GtkActionGroup *self;
292 self = g_object_new (GTK_TYPE_ACTION_GROUP, NULL);
293 self->private_data->name = g_strdup (name);
299 gtk_action_group_finalize (GObject *object)
301 GtkActionGroup *self;
303 self = GTK_ACTION_GROUP (object);
305 g_free (self->private_data->name);
306 self->private_data->name = NULL;
308 g_hash_table_destroy (self->private_data->actions);
309 self->private_data->actions = NULL;
311 if (self->private_data->translate_notify)
312 self->private_data->translate_notify (self->private_data->translate_data);
314 if (parent_class->finalize)
315 (* parent_class->finalize) (object);
319 gtk_action_group_set_property (GObject *object,
324 GtkActionGroup *self;
327 self = GTK_ACTION_GROUP (object);
332 tmp = self->private_data->name;
333 self->private_data->name = g_value_dup_string (value);
337 gtk_action_group_set_sensitive (self, g_value_get_boolean (value));
340 gtk_action_group_set_visible (self, g_value_get_boolean (value));
343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
349 gtk_action_group_get_property (GObject *object,
354 GtkActionGroup *self;
356 self = GTK_ACTION_GROUP (object);
361 g_value_set_string (value, self->private_data->name);
364 g_value_set_boolean (value, self->private_data->sensitive);
367 g_value_set_boolean (value, self->private_data->visible);
370 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
376 gtk_action_group_real_get_action (GtkActionGroup *self,
377 const gchar *action_name)
379 return g_hash_table_lookup (self->private_data->actions, action_name);
383 * gtk_action_group_get_name:
384 * @action_group: the action group
386 * Gets the name of the action group.
388 * Returns: the name of the action group.
392 G_CONST_RETURN gchar *
393 gtk_action_group_get_name (GtkActionGroup *action_group)
395 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
397 return action_group->private_data->name;
401 * gtk_action_group_get_sensitive:
402 * @action_group: the action group
404 * Returns %TRUE if the group is sensitive. The constituent actions
405 * can only be logically sensitive (see gtk_action_is_sensitive()) if
406 * they are sensitive (see gtk_action_get_sensitive()) and their group
409 * Return value: %TRUE if the group is sensitive.
414 gtk_action_group_get_sensitive (GtkActionGroup *action_group)
416 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), FALSE);
418 return action_group->private_data->sensitive;
422 cb_set_action_sensitivity (const gchar *name,
425 /* Minor optimization, the action_groups state only affects actions
426 * that are themselves sensitive */
427 if (gtk_action_get_sensitive (action))
428 _gtk_action_sync_sensitive (action);
432 * gtk_action_group_set_sensitive:
433 * @action_group: the action group
434 * @sensitive: new sensitivity
436 * Changes the sensitivity of @action_group
441 gtk_action_group_set_sensitive (GtkActionGroup *action_group,
444 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
446 sensitive = sensitive != FALSE;
448 if (action_group->private_data->sensitive != sensitive)
450 action_group->private_data->sensitive = sensitive;
451 g_hash_table_foreach (action_group->private_data->actions,
452 (GHFunc) cb_set_action_sensitivity, NULL);
454 g_object_notify (G_OBJECT (action_group), "sensitive");
459 * gtk_action_group_get_visible:
460 * @action_group: the action group
462 * Returns %TRUE if the group is visible. The constituent actions
463 * can only be logically visible (see gtk_action_is_visible()) if
464 * they are visible (see gtk_action_get_visible()) and their group
467 * Return value: %TRUE if the group is visible.
472 gtk_action_group_get_visible (GtkActionGroup *action_group)
474 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), FALSE);
476 return action_group->private_data->visible;
480 cb_set_action_visiblity (const gchar *name,
483 /* Minor optimization, the action_groups state only affects actions
484 * that are themselves visible */
485 if (gtk_action_get_visible (action))
486 _gtk_action_sync_visible (action);
490 * gtk_action_group_set_visible:
491 * @action_group: the action group
492 * @visible: new visiblity
494 * Changes the visible of @action_group.
499 gtk_action_group_set_visible (GtkActionGroup *action_group,
502 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
504 visible = visible != FALSE;
506 if (action_group->private_data->visible != visible)
508 action_group->private_data->visible = visible;
509 g_hash_table_foreach (action_group->private_data->actions,
510 (GHFunc) cb_set_action_visiblity, NULL);
512 g_object_notify (G_OBJECT (action_group), "visible");
517 * gtk_action_group_get_action:
518 * @action_group: the action group
519 * @action_name: the name of the action
521 * Looks up an action in the action group by name.
523 * Returns: the action, or %NULL if no action by that name exists
528 gtk_action_group_get_action (GtkActionGroup *action_group,
529 const gchar *action_name)
531 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
532 g_return_val_if_fail (GTK_ACTION_GROUP_GET_CLASS (action_group)->get_action != NULL, NULL);
534 return (* GTK_ACTION_GROUP_GET_CLASS (action_group)->get_action)
535 (action_group, action_name);
539 * gtk_action_group_add_action:
540 * @action_group: the action group
543 * Adds an action object to the action group. Note that this function
544 * does not set up the accel path of the action, which can lead to problems
545 * if a user tries to modify the accelerator of a menuitem associated with
546 * the action. Therefore you must either set the accel path yourself with
547 * gtk_action_set_accel_path(), or use
548 * <literal>gtk_action_group_add_action_with_accel (..., NULL)</literal>.
553 gtk_action_group_add_action (GtkActionGroup *action_group,
556 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
557 g_return_if_fail (GTK_IS_ACTION (action));
558 g_return_if_fail (gtk_action_get_name (action) != NULL);
560 g_hash_table_insert (action_group->private_data->actions,
561 g_strdup (gtk_action_get_name (action)),
562 g_object_ref (action));
563 g_object_set (action, I_("action-group"), action_group, NULL);
567 * gtk_action_group_add_action_with_accel:
568 * @action_group: the action group
569 * @action: the action to add
570 * @accelerator: the accelerator for the action, in
571 * the format understood by gtk_accelerator_parse(), or "" for no accelerator, or
572 * %NULL to use the stock accelerator
574 * Adds an action object to the action group and sets up the accelerator.
576 * If @accelerator is %NULL, attempts to use the accelerator associated
577 * with the stock_id of the action.
579 * Accel paths are set to
580 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
585 gtk_action_group_add_action_with_accel (GtkActionGroup *action_group,
587 const gchar *accelerator)
591 GdkModifierType accel_mods;
592 GtkStockItem stock_item;
596 g_object_get (action, "name", &name, "stock-id", &stock_id, NULL);
598 accel_path = g_strconcat ("<Actions>/",
599 action_group->private_data->name, "/", name, NULL);
603 if (accelerator[0] == 0)
607 gtk_accelerator_parse (accelerator, &accel_key, &accel_mods);
609 g_warning ("Unable to parse accelerator '%s' for action '%s'",
613 else if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
615 accel_key = stock_item.keyval;
616 accel_mods = stock_item.modifier;
620 gtk_accel_map_add_entry (accel_path, accel_key, accel_mods);
622 gtk_action_set_accel_path (action, accel_path);
623 gtk_action_group_add_action (action_group, action);
631 * gtk_action_group_remove_action:
632 * @action_group: the action group
635 * Removes an action object from the action group.
640 gtk_action_group_remove_action (GtkActionGroup *action_group,
643 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
644 g_return_if_fail (GTK_IS_ACTION (action));
645 g_return_if_fail (gtk_action_get_name (action) != NULL);
647 /* extra protection to make sure action->name is valid */
648 g_object_ref (action);
649 g_hash_table_remove (action_group->private_data->actions, gtk_action_get_name (action));
650 g_object_unref (action);
654 add_single_action (gpointer key,
658 GList **list = user_data;
660 *list = g_list_prepend (*list, value);
664 * gtk_action_group_list_actions:
665 * @action_group: the action group
667 * Lists the actions in the action group.
669 * Returns: an allocated list of the action objects in the action group
674 gtk_action_group_list_actions (GtkActionGroup *action_group)
676 GList *actions = NULL;
677 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
679 g_hash_table_foreach (action_group->private_data->actions, add_single_action, &actions);
681 return g_list_reverse (actions);
686 * gtk_action_group_add_actions:
687 * @action_group: the action group
688 * @entries: an array of action descriptions
689 * @n_entries: the number of entries
690 * @user_data: data to pass to the action callbacks
692 * This is a convenience function to create a number of actions and add them
693 * to the action group.
695 * The "activate" signals of the actions are connected to the callbacks and
696 * their accel paths are set to
697 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
702 gtk_action_group_add_actions (GtkActionGroup *action_group,
703 const GtkActionEntry *entries,
707 gtk_action_group_add_actions_full (action_group,
712 typedef struct _SharedData SharedData;
717 GDestroyNotify destroy;
721 shared_data_unref (gpointer data)
723 SharedData *shared_data = (SharedData *)data;
725 shared_data->ref_count--;
726 if (shared_data->ref_count == 0)
728 if (shared_data->destroy)
729 (*shared_data->destroy) (shared_data->data);
731 g_slice_free (SharedData, shared_data);
737 * gtk_action_group_add_actions_full:
738 * @action_group: the action group
739 * @entries: an array of action descriptions
740 * @n_entries: the number of entries
741 * @user_data: data to pass to the action callbacks
742 * @destroy: destroy notification callback for @user_data
744 * This variant of gtk_action_group_add_actions() adds a #GDestroyNotify
745 * callback for @user_data.
750 gtk_action_group_add_actions_full (GtkActionGroup *action_group,
751 const GtkActionEntry *entries,
754 GDestroyNotify destroy)
757 /* Keep this in sync with the other
758 * gtk_action_group_add_..._actions_full() functions.
761 SharedData *shared_data;
763 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
765 shared_data = g_slice_new0 (SharedData);
766 shared_data->ref_count = 1;
767 shared_data->data = user_data;
768 shared_data->destroy = destroy;
770 for (i = 0; i < n_entries; i++)
774 const gchar *tooltip;
776 label = gtk_action_group_translate_string (action_group, entries[i].label);
777 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
779 action = gtk_action_new (entries[i].name,
784 if (entries[i].stock_id)
786 g_object_set (action, "stock-id", entries[i].stock_id, NULL);
787 if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
788 entries[i].stock_id))
789 g_object_set (action, "icon-name", entries[i].stock_id, NULL);
792 if (entries[i].callback)
796 closure = g_cclosure_new (entries[i].callback, user_data, NULL);
797 g_closure_add_finalize_notifier (closure, shared_data,
798 (GClosureNotify)shared_data_unref);
799 shared_data->ref_count++;
801 g_signal_connect_closure (action, "activate", closure, FALSE);
804 gtk_action_group_add_action_with_accel (action_group,
806 entries[i].accelerator);
807 g_object_unref (action);
810 shared_data_unref (shared_data);
814 * gtk_action_group_add_toggle_actions:
815 * @action_group: the action group
816 * @entries: an array of toggle action descriptions
817 * @n_entries: the number of entries
818 * @user_data: data to pass to the action callbacks
820 * This is a convenience function to create a number of toggle actions and add them
821 * to the action group.
823 * The "activate" signals of the actions are connected to the callbacks and
824 * their accel paths are set to
825 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
830 gtk_action_group_add_toggle_actions (GtkActionGroup *action_group,
831 const GtkToggleActionEntry *entries,
835 gtk_action_group_add_toggle_actions_full (action_group,
842 * gtk_action_group_add_toggle_actions_full:
843 * @action_group: the action group
844 * @entries: an array of toggle action descriptions
845 * @n_entries: the number of entries
846 * @user_data: data to pass to the action callbacks
847 * @destroy: destroy notification callback for @user_data
849 * This variant of gtk_action_group_add_toggle_actions() adds a
850 * #GDestroyNotify callback for @user_data.
855 gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group,
856 const GtkToggleActionEntry *entries,
859 GDestroyNotify destroy)
861 /* Keep this in sync with the other
862 * gtk_action_group_add_..._actions_full() functions.
865 SharedData *shared_data;
867 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
869 shared_data = g_slice_new0 (SharedData);
870 shared_data->ref_count = 1;
871 shared_data->data = user_data;
872 shared_data->destroy = destroy;
874 for (i = 0; i < n_entries; i++)
876 GtkToggleAction *action;
878 const gchar *tooltip;
880 label = gtk_action_group_translate_string (action_group, entries[i].label);
881 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
883 action = gtk_toggle_action_new (entries[i].name,
888 if (entries[i].stock_id)
890 if (gtk_icon_factory_lookup_default (entries[i].stock_id))
891 g_object_set (action, "stock-id", entries[i].stock_id, NULL);
893 g_object_set (action, "icon-name", entries[i].stock_id, NULL);
896 gtk_toggle_action_set_active (action, entries[i].is_active);
898 if (entries[i].callback)
902 closure = g_cclosure_new (entries[i].callback, user_data, NULL);
903 g_closure_add_finalize_notifier (closure, shared_data,
904 (GClosureNotify)shared_data_unref);
905 shared_data->ref_count++;
907 g_signal_connect_closure (action, "activate", closure, FALSE);
910 gtk_action_group_add_action_with_accel (action_group,
912 entries[i].accelerator);
913 g_object_unref (action);
916 shared_data_unref (shared_data);
920 * gtk_action_group_add_radio_actions:
921 * @action_group: the action group
922 * @entries: an array of radio action descriptions
923 * @n_entries: the number of entries
924 * @value: the value of the action to activate initially, or -1 if
925 * no action should be activated
926 * @on_change: the callback to connect to the changed signal
927 * @user_data: data to pass to the action callbacks
929 * This is a convenience routine to create a group of radio actions and
930 * add them to the action group.
932 * The "changed" signal of the first radio action is connected to the
933 * @on_change callback and the accel paths of the actions are set to
934 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
939 gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
940 const GtkRadioActionEntry *entries,
946 gtk_action_group_add_radio_actions_full (action_group,
949 on_change, user_data, NULL);
953 * gtk_action_group_add_radio_actions_full:
954 * @action_group: the action group
955 * @entries: an array of radio action descriptions
956 * @n_entries: the number of entries
957 * @value: the value of the action to activate initially, or -1 if
958 * no action should be activated
959 * @on_change: the callback to connect to the changed signal
960 * @user_data: data to pass to the action callbacks
961 * @destroy: destroy notification callback for @user_data
963 * This variant of gtk_action_group_add_radio_actions() adds a
964 * #GDestroyNotify callback for @user_data.
969 gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
970 const GtkRadioActionEntry *entries,
975 GDestroyNotify destroy)
977 /* Keep this in sync with the other
978 * gtk_action_group_add_..._actions_full() functions.
981 GSList *group = NULL;
982 GtkRadioAction *first_action = NULL;
984 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
986 for (i = 0; i < n_entries; i++)
988 GtkRadioAction *action;
990 const gchar *tooltip;
992 label = gtk_action_group_translate_string (action_group, entries[i].label);
993 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
995 action = gtk_radio_action_new (entries[i].name,
1001 if (entries[i].stock_id)
1003 if (gtk_icon_factory_lookup_default (entries[i].stock_id))
1004 g_object_set (action, "stock-id", entries[i].stock_id, NULL);
1006 g_object_set (action, "icon-name", entries[i].stock_id, NULL);
1010 first_action = action;
1012 gtk_radio_action_set_group (action, group);
1013 group = gtk_radio_action_get_group (action);
1015 if (value == entries[i].value)
1016 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
1018 gtk_action_group_add_action_with_accel (action_group,
1019 GTK_ACTION (action),
1020 entries[i].accelerator);
1021 g_object_unref (action);
1024 if (on_change && first_action)
1025 g_signal_connect_data (first_action, "changed",
1026 on_change, user_data,
1027 (GClosureNotify)destroy, 0);
1031 * gtk_action_group_set_translate_func:
1032 * @action_group: a #GtkActionGroup
1033 * @func: a #GtkTranslateFunc
1034 * @data: data to be passed to @func and @notify
1035 * @notify: a #GtkDestroyNotify function to be called when @action_group is
1036 * destroyed and when the translation function is changed again
1038 * Sets a function to be used for translating the @label and @tooltip of
1039 * #GtkActionGroupEntry<!-- -->s added by gtk_action_group_add_actions().
1041 * If you're using gettext(), it is enough to set the translation domain
1042 * with gtk_action_group_set_translation_domain().
1047 gtk_action_group_set_translate_func (GtkActionGroup *action_group,
1048 GtkTranslateFunc func,
1050 GtkDestroyNotify notify)
1052 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1054 if (action_group->private_data->translate_notify)
1055 action_group->private_data->translate_notify (action_group->private_data->translate_data);
1057 action_group->private_data->translate_func = func;
1058 action_group->private_data->translate_data = data;
1059 action_group->private_data->translate_notify = notify;
1063 dgettext_swapped (const gchar *msgid,
1064 const gchar *domainname)
1066 /* Pass through dgettext if and only if msgid is nonempty. */
1067 if (msgid && *msgid)
1068 return dgettext (domainname, msgid);
1070 return (gchar*) msgid;
1074 * gtk_action_group_set_translation_domain:
1075 * @action_group: a #GtkActionGroup
1076 * @domain: the translation domain to use for dgettext() calls
1078 * Sets the translation domain and uses dgettext() for translating the
1079 * @label and @tooltip of #GtkActionEntry<!-- -->s added by
1080 * gtk_action_group_add_actions().
1082 * If you're not using gettext() for localization, see
1083 * gtk_action_group_set_translate_func().
1088 gtk_action_group_set_translation_domain (GtkActionGroup *action_group,
1089 const gchar *domain)
1091 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1093 gtk_action_group_set_translate_func (action_group,
1094 (GtkTranslateFunc)dgettext_swapped,
1101 * gtk_action_group_translate_string:
1102 * @action_group: a #GtkActionGroup
1105 * Translates a string using the specified translate_func(). This
1106 * is mainly intended for language bindings.
1108 * Returns: the translation of @string
1112 G_CONST_RETURN gchar *
1113 gtk_action_group_translate_string (GtkActionGroup *action_group,
1114 const gchar *string)
1116 GtkTranslateFunc translate_func;
1117 gpointer translate_data;
1119 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), string);
1124 translate_func = action_group->private_data->translate_func;
1125 translate_data = action_group->private_data->translate_data;
1128 return translate_func (string, translate_data);
1133 /* Protected for use by GtkAction */
1135 _gtk_action_group_emit_connect_proxy (GtkActionGroup *action_group,
1139 g_signal_emit (action_group, action_group_signals[CONNECT_PROXY], 0,
1144 _gtk_action_group_emit_disconnect_proxy (GtkActionGroup *action_group,
1148 g_signal_emit (action_group, action_group_signals[DISCONNECT_PROXY], 0,
1153 _gtk_action_group_emit_pre_activate (GtkActionGroup *action_group,
1156 g_signal_emit (action_group, action_group_signals[PRE_ACTIVATE], 0, action);
1160 _gtk_action_group_emit_post_activate (GtkActionGroup *action_group,
1163 g_signal_emit (action_group, action_group_signals[POST_ACTIVATE], 0, action);
1166 #define __GTK_ACTION_GROUP_C__
1167 #include "gtkaliasdef.c"