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 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 check_unique_action (GtkActionGroup *action_group,
540 const gchar *action_name)
542 if (gtk_action_group_get_action (action_group, action_name) != NULL)
544 g_warning ("Refusing to add non-unique action '%s' to action group '%s'",
546 action_group->private_data->name);
554 * gtk_action_group_add_action:
555 * @action_group: the action group
558 * Adds an action object to the action group. Note that this function
559 * does not set up the accel path of the action, which can lead to problems
560 * if a user tries to modify the accelerator of a menuitem associated with
561 * the action. Therefore you must either set the accel path yourself with
562 * gtk_action_set_accel_path(), or use
563 * <literal>gtk_action_group_add_action_with_accel (..., NULL)</literal>.
568 gtk_action_group_add_action (GtkActionGroup *action_group,
571 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
572 g_return_if_fail (GTK_IS_ACTION (action));
573 g_return_if_fail (gtk_action_get_name (action) != NULL);
575 if (!check_unique_action (action_group, gtk_action_get_name (action)))
578 g_hash_table_insert (action_group->private_data->actions,
579 g_strdup (gtk_action_get_name (action)),
580 g_object_ref (action));
581 g_object_set (action, I_("action-group"), action_group, NULL);
585 * gtk_action_group_add_action_with_accel:
586 * @action_group: the action group
587 * @action: the action to add
588 * @accelerator: the accelerator for the action, in
589 * the format understood by gtk_accelerator_parse(), or "" for no accelerator, or
590 * %NULL to use the stock accelerator
592 * Adds an action object to the action group and sets up the accelerator.
594 * If @accelerator is %NULL, attempts to use the accelerator associated
595 * with the stock_id of the action.
597 * Accel paths are set to
598 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
603 gtk_action_group_add_action_with_accel (GtkActionGroup *action_group,
605 const gchar *accelerator)
609 GdkModifierType accel_mods;
610 GtkStockItem stock_item;
614 if (!check_unique_action (action_group, gtk_action_get_name (action)))
617 g_object_get (action, "name", &name, "stock-id", &stock_id, NULL);
619 accel_path = g_strconcat ("<Actions>/",
620 action_group->private_data->name, "/", name, NULL);
624 if (accelerator[0] == 0)
628 gtk_accelerator_parse (accelerator, &accel_key, &accel_mods);
630 g_warning ("Unable to parse accelerator '%s' for action '%s'",
634 else if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
636 accel_key = stock_item.keyval;
637 accel_mods = stock_item.modifier;
641 gtk_accel_map_add_entry (accel_path, accel_key, accel_mods);
643 gtk_action_set_accel_path (action, accel_path);
644 gtk_action_group_add_action (action_group, action);
652 * gtk_action_group_remove_action:
653 * @action_group: the action group
656 * Removes an action object from the action group.
661 gtk_action_group_remove_action (GtkActionGroup *action_group,
664 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
665 g_return_if_fail (GTK_IS_ACTION (action));
666 g_return_if_fail (gtk_action_get_name (action) != NULL);
668 /* extra protection to make sure action->name is valid */
669 g_object_ref (action);
670 g_hash_table_remove (action_group->private_data->actions, gtk_action_get_name (action));
671 g_object_unref (action);
675 add_single_action (gpointer key,
679 GList **list = user_data;
681 *list = g_list_prepend (*list, value);
685 * gtk_action_group_list_actions:
686 * @action_group: the action group
688 * Lists the actions in the action group.
690 * Returns: an allocated list of the action objects in the action group
695 gtk_action_group_list_actions (GtkActionGroup *action_group)
697 GList *actions = NULL;
698 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
700 g_hash_table_foreach (action_group->private_data->actions, add_single_action, &actions);
702 return g_list_reverse (actions);
707 * gtk_action_group_add_actions:
708 * @action_group: the action group
709 * @entries: an array of action descriptions
710 * @n_entries: the number of entries
711 * @user_data: data to pass to the action callbacks
713 * This is a convenience function to create a number of actions and add them
714 * to the action group.
716 * The "activate" signals of the actions are connected to the callbacks and
717 * their accel paths are set to
718 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
723 gtk_action_group_add_actions (GtkActionGroup *action_group,
724 const GtkActionEntry *entries,
728 gtk_action_group_add_actions_full (action_group,
733 typedef struct _SharedData SharedData;
738 GDestroyNotify destroy;
742 shared_data_unref (gpointer data)
744 SharedData *shared_data = (SharedData *)data;
746 shared_data->ref_count--;
747 if (shared_data->ref_count == 0)
749 if (shared_data->destroy)
750 (*shared_data->destroy) (shared_data->data);
752 g_slice_free (SharedData, shared_data);
758 * gtk_action_group_add_actions_full:
759 * @action_group: the action group
760 * @entries: an array of action descriptions
761 * @n_entries: the number of entries
762 * @user_data: data to pass to the action callbacks
763 * @destroy: destroy notification callback for @user_data
765 * This variant of gtk_action_group_add_actions() adds a #GDestroyNotify
766 * callback for @user_data.
771 gtk_action_group_add_actions_full (GtkActionGroup *action_group,
772 const GtkActionEntry *entries,
775 GDestroyNotify destroy)
778 /* Keep this in sync with the other
779 * gtk_action_group_add_..._actions_full() functions.
782 SharedData *shared_data;
784 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
786 shared_data = g_slice_new0 (SharedData);
787 shared_data->ref_count = 1;
788 shared_data->data = user_data;
789 shared_data->destroy = destroy;
791 for (i = 0; i < n_entries; i++)
795 const gchar *tooltip;
797 if (!check_unique_action (action_group, entries[i].name))
800 label = gtk_action_group_translate_string (action_group, entries[i].label);
801 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
803 action = gtk_action_new (entries[i].name,
808 if (entries[i].stock_id)
810 g_object_set (action, "stock-id", entries[i].stock_id, NULL);
811 if (gtk_icon_theme_has_icon (gtk_icon_theme_get_default (),
812 entries[i].stock_id))
813 g_object_set (action, "icon-name", entries[i].stock_id, NULL);
816 if (entries[i].callback)
820 closure = g_cclosure_new (entries[i].callback, user_data, NULL);
821 g_closure_add_finalize_notifier (closure, shared_data,
822 (GClosureNotify)shared_data_unref);
823 shared_data->ref_count++;
825 g_signal_connect_closure (action, "activate", closure, FALSE);
828 gtk_action_group_add_action_with_accel (action_group,
830 entries[i].accelerator);
831 g_object_unref (action);
834 shared_data_unref (shared_data);
838 * gtk_action_group_add_toggle_actions:
839 * @action_group: the action group
840 * @entries: an array of toggle action descriptions
841 * @n_entries: the number of entries
842 * @user_data: data to pass to the action callbacks
844 * This is a convenience function to create a number of toggle actions and add them
845 * to the action group.
847 * The "activate" signals of the actions are connected to the callbacks and
848 * their accel paths are set to
849 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
854 gtk_action_group_add_toggle_actions (GtkActionGroup *action_group,
855 const GtkToggleActionEntry *entries,
859 gtk_action_group_add_toggle_actions_full (action_group,
866 * gtk_action_group_add_toggle_actions_full:
867 * @action_group: the action group
868 * @entries: an array of toggle action descriptions
869 * @n_entries: the number of entries
870 * @user_data: data to pass to the action callbacks
871 * @destroy: destroy notification callback for @user_data
873 * This variant of gtk_action_group_add_toggle_actions() adds a
874 * #GDestroyNotify callback for @user_data.
879 gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group,
880 const GtkToggleActionEntry *entries,
883 GDestroyNotify destroy)
885 /* Keep this in sync with the other
886 * gtk_action_group_add_..._actions_full() functions.
889 SharedData *shared_data;
891 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
893 shared_data = g_slice_new0 (SharedData);
894 shared_data->ref_count = 1;
895 shared_data->data = user_data;
896 shared_data->destroy = destroy;
898 for (i = 0; i < n_entries; i++)
900 GtkToggleAction *action;
902 const gchar *tooltip;
904 if (!check_unique_action (action_group, entries[i].name))
907 label = gtk_action_group_translate_string (action_group, entries[i].label);
908 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
910 action = gtk_toggle_action_new (entries[i].name,
915 if (entries[i].stock_id)
917 if (gtk_icon_factory_lookup_default (entries[i].stock_id))
918 g_object_set (action, "stock-id", entries[i].stock_id, NULL);
920 g_object_set (action, "icon-name", entries[i].stock_id, NULL);
923 gtk_toggle_action_set_active (action, entries[i].is_active);
925 if (entries[i].callback)
929 closure = g_cclosure_new (entries[i].callback, user_data, NULL);
930 g_closure_add_finalize_notifier (closure, shared_data,
931 (GClosureNotify)shared_data_unref);
932 shared_data->ref_count++;
934 g_signal_connect_closure (action, "activate", closure, FALSE);
937 gtk_action_group_add_action_with_accel (action_group,
939 entries[i].accelerator);
940 g_object_unref (action);
943 shared_data_unref (shared_data);
947 * gtk_action_group_add_radio_actions:
948 * @action_group: the action group
949 * @entries: an array of radio action descriptions
950 * @n_entries: the number of entries
951 * @value: the value of the action to activate initially, or -1 if
952 * no action should be activated
953 * @on_change: the callback to connect to the changed signal
954 * @user_data: data to pass to the action callbacks
956 * This is a convenience routine to create a group of radio actions and
957 * add them to the action group.
959 * The "changed" signal of the first radio action is connected to the
960 * @on_change callback and the accel paths of the actions are set to
961 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
966 gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
967 const GtkRadioActionEntry *entries,
973 gtk_action_group_add_radio_actions_full (action_group,
976 on_change, user_data, NULL);
980 * gtk_action_group_add_radio_actions_full:
981 * @action_group: the action group
982 * @entries: an array of radio action descriptions
983 * @n_entries: the number of entries
984 * @value: the value of the action to activate initially, or -1 if
985 * no action should be activated
986 * @on_change: the callback to connect to the changed signal
987 * @user_data: data to pass to the action callbacks
988 * @destroy: destroy notification callback for @user_data
990 * This variant of gtk_action_group_add_radio_actions() adds a
991 * #GDestroyNotify callback for @user_data.
996 gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
997 const GtkRadioActionEntry *entries,
1000 GCallback on_change,
1002 GDestroyNotify destroy)
1004 /* Keep this in sync with the other
1005 * gtk_action_group_add_..._actions_full() functions.
1008 GSList *group = NULL;
1009 GtkRadioAction *first_action = NULL;
1011 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1013 for (i = 0; i < n_entries; i++)
1015 GtkRadioAction *action;
1017 const gchar *tooltip;
1019 if (!check_unique_action (action_group, entries[i].name))
1022 label = gtk_action_group_translate_string (action_group, entries[i].label);
1023 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
1025 action = gtk_radio_action_new (entries[i].name,
1031 if (entries[i].stock_id)
1033 if (gtk_icon_factory_lookup_default (entries[i].stock_id))
1034 g_object_set (action, "stock-id", entries[i].stock_id, NULL);
1036 g_object_set (action, "icon-name", entries[i].stock_id, NULL);
1040 first_action = action;
1042 gtk_radio_action_set_group (action, group);
1043 group = gtk_radio_action_get_group (action);
1045 if (value == entries[i].value)
1046 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
1048 gtk_action_group_add_action_with_accel (action_group,
1049 GTK_ACTION (action),
1050 entries[i].accelerator);
1051 g_object_unref (action);
1054 if (on_change && first_action)
1055 g_signal_connect_data (first_action, "changed",
1056 on_change, user_data,
1057 (GClosureNotify)destroy, 0);
1061 * gtk_action_group_set_translate_func:
1062 * @action_group: a #GtkActionGroup
1063 * @func: a #GtkTranslateFunc
1064 * @data: data to be passed to @func and @notify
1065 * @notify: a #GtkDestroyNotify function to be called when @action_group is
1066 * destroyed and when the translation function is changed again
1068 * Sets a function to be used for translating the @label and @tooltip of
1069 * #GtkActionGroupEntry<!-- -->s added by gtk_action_group_add_actions().
1071 * If you're using gettext(), it is enough to set the translation domain
1072 * with gtk_action_group_set_translation_domain().
1077 gtk_action_group_set_translate_func (GtkActionGroup *action_group,
1078 GtkTranslateFunc func,
1080 GtkDestroyNotify notify)
1082 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1084 if (action_group->private_data->translate_notify)
1085 action_group->private_data->translate_notify (action_group->private_data->translate_data);
1087 action_group->private_data->translate_func = func;
1088 action_group->private_data->translate_data = data;
1089 action_group->private_data->translate_notify = notify;
1093 dgettext_swapped (const gchar *msgid,
1094 const gchar *domainname)
1096 /* Pass through dgettext if and only if msgid is nonempty. */
1097 if (msgid && *msgid)
1098 return dgettext (domainname, msgid);
1100 return (gchar*) msgid;
1104 * gtk_action_group_set_translation_domain:
1105 * @action_group: a #GtkActionGroup
1106 * @domain: the translation domain to use for dgettext() calls
1108 * Sets the translation domain and uses dgettext() for translating the
1109 * @label and @tooltip of #GtkActionEntry<!-- -->s added by
1110 * gtk_action_group_add_actions().
1112 * If you're not using gettext() for localization, see
1113 * gtk_action_group_set_translate_func().
1118 gtk_action_group_set_translation_domain (GtkActionGroup *action_group,
1119 const gchar *domain)
1121 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1123 gtk_action_group_set_translate_func (action_group,
1124 (GtkTranslateFunc)dgettext_swapped,
1131 * gtk_action_group_translate_string:
1132 * @action_group: a #GtkActionGroup
1135 * Translates a string using the specified translate_func(). This
1136 * is mainly intended for language bindings.
1138 * Returns: the translation of @string
1142 G_CONST_RETURN gchar *
1143 gtk_action_group_translate_string (GtkActionGroup *action_group,
1144 const gchar *string)
1146 GtkTranslateFunc translate_func;
1147 gpointer translate_data;
1149 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), string);
1154 translate_func = action_group->private_data->translate_func;
1155 translate_data = action_group->private_data->translate_data;
1158 return translate_func (string, translate_data);
1163 /* Protected for use by GtkAction */
1165 _gtk_action_group_emit_connect_proxy (GtkActionGroup *action_group,
1169 g_signal_emit (action_group, action_group_signals[CONNECT_PROXY], 0,
1174 _gtk_action_group_emit_disconnect_proxy (GtkActionGroup *action_group,
1178 g_signal_emit (action_group, action_group_signals[DISCONNECT_PROXY], 0,
1183 _gtk_action_group_emit_pre_activate (GtkActionGroup *action_group,
1186 g_signal_emit (action_group, action_group_signals[PRE_ACTIVATE], 0, action);
1190 _gtk_action_group_emit_post_activate (GtkActionGroup *action_group,
1193 g_signal_emit (action_group, action_group_signals[POST_ACTIVATE], 0, action);
1196 #define __GTK_ACTION_GROUP_C__
1197 #include "gtkaliasdef.c"