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/.
34 #include "gtkactiongroup.h"
36 #include "gtktoggleaction.h"
37 #include "gtkradioaction.h"
38 #include "gtkaccelmap.h"
39 #include "gtkmarshalers.h"
42 #define GTK_ACTION_GROUP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION_GROUP, GtkActionGroupPrivate))
44 struct _GtkActionGroupPrivate
51 GtkTranslateFunc translate_func;
52 gpointer translate_data;
53 GtkDestroyNotify translate_notify;
73 static void gtk_action_group_init (GtkActionGroup *self);
74 static void gtk_action_group_class_init (GtkActionGroupClass *class);
75 static void gtk_action_group_finalize (GObject *object);
76 static void gtk_action_group_set_property (GObject *object,
80 static void gtk_action_group_get_property (GObject *object,
84 static GtkAction *gtk_action_group_real_get_action (GtkActionGroup *self,
89 gtk_action_group_get_type (void)
91 static GType type = 0;
95 static const GTypeInfo type_info =
97 sizeof (GtkActionGroupClass),
99 NULL, /* base_finalize */
100 (GClassInitFunc) gtk_action_group_class_init,
101 NULL, /* class_finalize */
102 NULL, /* class_data */
103 sizeof (GtkActionGroup),
105 (GInstanceInitFunc) gtk_action_group_init,
108 type = g_type_register_static (G_TYPE_OBJECT, "GtkActionGroup",
115 static GObjectClass *parent_class = NULL;
116 static guint action_group_signals[LAST_SIGNAL] = { 0 };
119 gtk_action_group_class_init (GtkActionGroupClass *klass)
121 GObjectClass *gobject_class;
123 gobject_class = G_OBJECT_CLASS (klass);
124 parent_class = g_type_class_peek_parent (klass);
126 gobject_class->finalize = gtk_action_group_finalize;
127 gobject_class->set_property = gtk_action_group_set_property;
128 gobject_class->get_property = gtk_action_group_get_property;
129 klass->get_action = gtk_action_group_real_get_action;
131 g_object_class_install_property (gobject_class,
133 g_param_spec_string ("name",
135 P_("A name for the action group."),
138 G_PARAM_CONSTRUCT_ONLY));
139 g_object_class_install_property (gobject_class,
141 g_param_spec_boolean ("sensitive",
143 P_("Whether the action group is enabled."),
146 g_object_class_install_property (gobject_class,
148 g_param_spec_boolean ("visible",
150 P_("Whether the action group is visible."),
155 * GtkGroupAction::connect-proxy:
156 * @action_group: the group
157 * @action: the action
160 * The connect_proxy signal is emitted after connecting a proxy to
161 * an action in the group. Note that the proxy may have been connected
162 * to a different action before.
164 * This is intended for simple customizations for which a custom action
165 * class would be too clumsy, e.g. showing tooltips for menuitems in the
168 * #GtkUIManager proxies the signal and provides global notification
169 * just before any action is connected to a proxy, which is probably more
174 action_group_signals[CONNECT_PROXY] =
175 g_signal_new ("connect_proxy",
176 G_OBJECT_CLASS_TYPE (klass),
178 _gtk_marshal_VOID__OBJECT_OBJECT,
180 GTK_TYPE_ACTION, GTK_TYPE_WIDGET);
183 * GtkAction::disconnect-proxy:
184 * @action_group: the group
185 * @action: the action
188 * The disconnect_proxy signal is emitted after disconnecting a proxy
189 * from an action in the group.
191 * #GtkUIManager proxies the signal and provides global notification
192 * just before any action is connected to a proxy, which is probably more
197 action_group_signals[DISCONNECT_PROXY] =
198 g_signal_new ("disconnect_proxy",
199 G_OBJECT_CLASS_TYPE (klass),
201 _gtk_marshal_VOID__OBJECT_OBJECT,
203 GTK_TYPE_ACTION, GTK_TYPE_WIDGET);
206 * GtkActionGroup::pre-activate:
207 * @action_group: the group
208 * @action: the action
210 * The pre_activate signal is emitted just before the @action in the
211 * @action_group is activated
213 * This is intended for #GtkUIManager to proxy the signal and provide global
214 * notification just before any action is activated.
218 action_group_signals[PRE_ACTIVATE] =
219 g_signal_new ("pre_activate",
220 G_OBJECT_CLASS_TYPE (klass),
222 _gtk_marshal_VOID__OBJECT,
227 * GtkActionGroup::post-activate:
228 * @action_group: the group
229 * @action: the action
231 * The post_activate signal is emitted just after the @action in the
232 * @action_group is activated
234 * This is intended for #GtkUIManager to proxy the signal and provide global
235 * notification just after any action is activated.
239 action_group_signals[POST_ACTIVATE] =
240 g_signal_new ("post_activate",
241 G_OBJECT_CLASS_TYPE (klass),
243 _gtk_marshal_VOID__OBJECT,
247 g_type_class_add_private (gobject_class, sizeof (GtkActionGroupPrivate));
252 remove_action (GtkAction *action)
254 g_object_set (action, "action_group", NULL, NULL);
255 g_object_unref (action);
259 gtk_action_group_init (GtkActionGroup *self)
261 self->private_data = GTK_ACTION_GROUP_GET_PRIVATE (self);
262 self->private_data->name = NULL;
263 self->private_data->sensitive = TRUE;
264 self->private_data->visible = TRUE;
265 self->private_data->actions = g_hash_table_new_full (g_str_hash, g_str_equal,
266 (GDestroyNotify) g_free,
267 (GDestroyNotify) remove_action);
268 self->private_data->translate_func = NULL;
269 self->private_data->translate_data = NULL;
270 self->private_data->translate_notify = NULL;
274 * gtk_action_group_new:
275 * @name: the name of the action group.
277 * Creates a new #GtkActionGroup object. The name of the action group
278 * is used when associating <link linkend="Action-Accel">keybindings</link>
281 * Returns: the new #GtkActionGroup
286 gtk_action_group_new (const gchar *name)
288 GtkActionGroup *self;
290 self = g_object_new (GTK_TYPE_ACTION_GROUP, NULL);
291 self->private_data->name = g_strdup (name);
297 gtk_action_group_finalize (GObject *object)
299 GtkActionGroup *self;
301 self = GTK_ACTION_GROUP (object);
303 g_free (self->private_data->name);
304 self->private_data->name = NULL;
306 g_hash_table_destroy (self->private_data->actions);
307 self->private_data->actions = NULL;
309 if (self->private_data->translate_notify)
310 self->private_data->translate_notify (self->private_data->translate_data);
312 if (parent_class->finalize)
313 (* parent_class->finalize) (object);
317 gtk_action_group_set_property (GObject *object,
322 GtkActionGroup *self;
325 self = GTK_ACTION_GROUP (object);
330 tmp = self->private_data->name;
331 self->private_data->name = g_value_dup_string (value);
335 gtk_action_group_set_sensitive (self, g_value_get_boolean (value));
338 gtk_action_group_set_visible (self, g_value_get_boolean (value));
341 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
347 gtk_action_group_get_property (GObject *object,
352 GtkActionGroup *self;
354 self = GTK_ACTION_GROUP (object);
359 g_value_set_string (value, self->private_data->name);
362 g_value_set_boolean (value, self->private_data->sensitive);
365 g_value_set_boolean (value, self->private_data->visible);
368 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
374 gtk_action_group_real_get_action (GtkActionGroup *self,
375 const gchar *action_name)
377 return g_hash_table_lookup (self->private_data->actions, action_name);
381 * gtk_action_group_get_name:
382 * @action_group: the action group
384 * Gets the name of the action group.
386 * Returns: the name of the action group.
391 gtk_action_group_get_name (GtkActionGroup *action_group)
393 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
395 return action_group->private_data->name;
399 * gtk_action_group_get_sensitive:
400 * @action_group: the action group
402 * Returns %TRUE if the group is sensitive. The constituent actions
403 * can only be logically sensitive (see gtk_action_is_sensitive()) if
404 * they are sensitive (see gtk_action_get_sensitive()) and their group
407 * Return value: %TRUE if the group is sensitive.
412 gtk_action_group_get_sensitive (GtkActionGroup *action_group)
414 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), FALSE);
416 return action_group->private_data->sensitive;
420 cb_set_action_sensitivity (const gchar *name, GtkAction *action)
422 /* Minor optimization, the action_groups state only effects actions that are
423 * themselves sensitive */
424 if (gtk_action_get_sensitive (action))
425 g_object_notify (G_OBJECT (action), "sensitive");
429 * gtk_action_group_set_sensitive:
430 * @action_group: the action group
431 * @sensitive: new sensitivity
433 * Changes the sensitivity of @action_group
438 gtk_action_group_set_sensitive (GtkActionGroup *action_group, gboolean sensitive)
440 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
442 if (action_group->private_data->sensitive ^ sensitive)
444 action_group->private_data->sensitive = sensitive;
445 g_hash_table_foreach (action_group->private_data->actions,
446 (GHFunc) cb_set_action_sensitivity, NULL);
451 * gtk_action_group_get_visible:
452 * @action_group: the action group
454 * Returns %TRUE if the group is visible. The constituent actions
455 * can only be logically visible (see gtk_action_is_visible()) if
456 * they are visible (see gtk_action_get_visible()) and their group
459 * Return value: %TRUE if the group is sensitive.
464 gtk_action_group_get_visible (GtkActionGroup *action_group)
466 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), FALSE);
468 return action_group->private_data->visible;
472 cb_set_action_visiblity (const gchar *name, GtkAction *action)
474 /* Minor optimization, the action_groups state only effects actions that are
475 * themselves sensitive */
476 if (gtk_action_get_visible (action))
477 g_object_notify (G_OBJECT (action), "visible");
481 * gtk_action_group_set_visible:
482 * @action_group: the action group
483 * @visible: new visiblity
485 * Changes the visible of @action_group.
490 gtk_action_group_set_visible (GtkActionGroup *action_group, gboolean visible)
492 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
494 if (action_group->private_data->visible ^ visible)
496 action_group->private_data->visible = visible;
497 g_hash_table_foreach (action_group->private_data->actions,
498 (GHFunc) cb_set_action_visiblity, NULL);
503 * gtk_action_group_get_action:
504 * @action_group: the action group
505 * @action_name: the name of the action
507 * Looks up an action in the action group by name.
509 * Returns: the action, or %NULL if no action by that name exists
514 gtk_action_group_get_action (GtkActionGroup *action_group,
515 const gchar *action_name)
517 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
518 g_return_val_if_fail (GTK_ACTION_GROUP_GET_CLASS (action_group)->get_action != NULL, NULL);
520 return (* GTK_ACTION_GROUP_GET_CLASS (action_group)->get_action)
521 (action_group, action_name);
525 * gtk_action_group_add_action:
526 * @action_group: the action group
529 * Adds an action object to the action group. Note that this function
530 * does not set up the accel path of the action, which can lead to problems
531 * if a user tries to modify the accelerator of a menuitem associated with
532 * the action. Therefore you must either set the accel path yourself with
533 * gtk_action_set_accel_path(), or use
534 * <literal>gtk_action_group_add_action_with_accel (..., NULL)</literal>.
539 gtk_action_group_add_action (GtkActionGroup *action_group,
542 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
543 g_return_if_fail (GTK_IS_ACTION (action));
544 g_return_if_fail (gtk_action_get_name (action) != NULL);
546 g_hash_table_insert (action_group->private_data->actions,
547 g_strdup (gtk_action_get_name (action)),
548 g_object_ref (action));
549 g_object_set (G_OBJECT (action), "action_group", action_group, NULL);
553 * gtk_action_group_add_action_with_accel:
554 * @action_group: the action group
555 * @action: the action to add
556 * @accelerator: the accelerator for the action, in
557 * the format understood by gtk_accelerator_parse(), or "" for no accelerator, or
558 * %NULL to use the stock accelerator
560 * Adds an action object to the action group and sets up the accelerator.
562 * If @accelerator is %NULL, attempts to use the accelerator associated
563 * with the stock_id of the action.
565 * Accel paths are set to
566 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
571 gtk_action_group_add_action_with_accel (GtkActionGroup *action_group,
573 const gchar *accelerator)
577 GdkModifierType accel_mods;
578 GtkStockItem stock_item;
582 g_object_get (action, "name", &name, "stock_id", &stock_id, NULL);
584 accel_path = g_strconcat ("<Actions>/",
585 action_group->private_data->name, "/", name, NULL);
589 if (accelerator[0] == 0)
593 gtk_accelerator_parse (accelerator, &accel_key, &accel_mods);
595 g_warning ("Unable to parse accelerator '%s' for action '%s'",
599 else if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
601 accel_key = stock_item.keyval;
602 accel_mods = stock_item.modifier;
606 gtk_accel_map_add_entry (accel_path, accel_key, accel_mods);
608 gtk_action_set_accel_path (action, accel_path);
609 gtk_action_group_add_action (action_group, action);
617 * gtk_action_group_remove_action:
618 * @action_group: the action group
621 * Removes an action object from the action group.
626 gtk_action_group_remove_action (GtkActionGroup *action_group,
629 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
630 g_return_if_fail (GTK_IS_ACTION (action));
631 g_return_if_fail (gtk_action_get_name (action) != NULL);
633 /* extra protection to make sure action->name is valid */
634 g_object_ref (action);
635 g_hash_table_remove (action_group->private_data->actions, gtk_action_get_name (action));
636 g_object_unref (action);
640 add_single_action (gpointer key,
644 GList **list = user_data;
646 *list = g_list_prepend (*list, value);
650 * gtk_action_group_list_actions:
651 * @action_group: the action group
653 * Lists the actions in the action group.
655 * Returns: an allocated list of the action objects in the action group
660 gtk_action_group_list_actions (GtkActionGroup *action_group)
662 GList *actions = NULL;
663 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
665 g_hash_table_foreach (action_group->private_data->actions, add_single_action, &actions);
667 return g_list_reverse (actions);
672 * gtk_action_group_add_actions:
673 * @action_group: the action group
674 * @entries: an array of action descriptions
675 * @n_entries: the number of entries
676 * @user_data: data to pass to the action callbacks
678 * This is a convenience function to create a number of actions and add them
679 * to the action group.
681 * The "activate" signals of the actions are connected to the callbacks and
682 * their accel paths are set to
683 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
688 gtk_action_group_add_actions (GtkActionGroup *action_group,
689 const GtkActionEntry *entries,
693 gtk_action_group_add_actions_full (action_group,
698 typedef struct _SharedData SharedData;
703 GDestroyNotify destroy;
707 shared_data_unref (gpointer data)
709 SharedData *shared_data = (SharedData *)data;
711 shared_data->ref_count--;
712 if (shared_data->ref_count == 0)
714 if (shared_data->destroy)
715 (*shared_data->destroy) (shared_data->data);
717 g_free (shared_data);
723 * gtk_action_group_add_actions_full:
724 * @action_group: the action group
725 * @entries: an array of action descriptions
726 * @n_entries: the number of entries
727 * @user_data: data to pass to the action callbacks
728 * @destroy: destroy notification callback for @user_data
730 * This variant of gtk_action_group_add_actions() adds a #GDestroyNotify
731 * callback for @user_data.
736 gtk_action_group_add_actions_full (GtkActionGroup *action_group,
737 const GtkActionEntry *entries,
740 GDestroyNotify destroy)
743 /* Keep this in sync with the other
744 * gtk_action_group_add_..._actions_full() functions.
747 GtkTranslateFunc translate_func;
748 gpointer translate_data;
749 SharedData *shared_data;
751 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
753 translate_func = action_group->private_data->translate_func;
754 translate_data = action_group->private_data->translate_data;
756 shared_data = g_new0 (SharedData, 1);
757 shared_data->ref_count = 1;
758 shared_data->data = user_data;
759 shared_data->destroy = destroy;
761 for (i = 0; i < n_entries; i++)
765 const gchar *tooltip;
769 label = translate_func (entries[i].label, translate_data);
770 tooltip = translate_func (entries[i].tooltip, translate_data);
774 label = entries[i].label;
775 tooltip = entries[i].tooltip;
778 action = gtk_action_new (entries[i].name,
781 entries[i].stock_id);
783 if (entries[i].callback)
787 closure = g_cclosure_new (entries[i].callback, user_data, NULL);
788 g_closure_add_finalize_notifier (closure, shared_data,
789 (GClosureNotify)shared_data_unref);
790 shared_data->ref_count++;
792 g_signal_connect_closure (action, "activate", closure, FALSE);
795 gtk_action_group_add_action_with_accel (action_group,
797 entries[i].accelerator);
798 g_object_unref (action);
801 shared_data_unref (shared_data);
805 * gtk_action_group_add_toggle_actions:
806 * @action_group: the action group
807 * @entries: an array of toggle action descriptions
808 * @n_entries: the number of entries
809 * @user_data: data to pass to the action callbacks
811 * This is a convenience function to create a number of toggle actions and add them
812 * to the action group.
814 * The "activate" signals of the actions are connected to the callbacks and
815 * their accel paths are set to
816 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
821 gtk_action_group_add_toggle_actions (GtkActionGroup *action_group,
822 const GtkToggleActionEntry *entries,
826 gtk_action_group_add_toggle_actions_full (action_group,
833 * gtk_action_group_add_toggle_actions_full:
834 * @action_group: the action group
835 * @entries: an array of toggle action descriptions
836 * @n_entries: the number of entries
837 * @user_data: data to pass to the action callbacks
838 * @destroy: destroy notification callback for @user_data
840 * This variant of gtk_action_group_add_toggle_actions() adds a
841 * #GDestroyNotify callback for @user_data.
846 gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group,
847 const GtkToggleActionEntry *entries,
850 GDestroyNotify destroy)
852 /* Keep this in sync with the other
853 * gtk_action_group_add_..._actions_full() functions.
856 GtkTranslateFunc translate_func;
857 gpointer translate_data;
858 SharedData *shared_data;
860 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
862 translate_func = action_group->private_data->translate_func;
863 translate_data = action_group->private_data->translate_data;
865 shared_data = g_new0 (SharedData, 1);
866 shared_data->ref_count = 1;
867 shared_data->data = user_data;
868 shared_data->destroy = destroy;
870 for (i = 0; i < n_entries; i++)
872 GtkToggleAction *action;
874 const gchar *tooltip;
878 label = translate_func (entries[i].label, translate_data);
879 tooltip = translate_func (entries[i].tooltip, translate_data);
883 label = entries[i].label;
884 tooltip = entries[i].tooltip;
887 action = gtk_toggle_action_new (entries[i].name,
890 entries[i].stock_id);
892 gtk_toggle_action_set_active (action, entries[i].is_active);
894 if (entries[i].callback)
898 closure = g_cclosure_new (entries[i].callback, user_data, NULL);
899 g_closure_add_finalize_notifier (closure, shared_data,
900 (GClosureNotify)shared_data_unref);
901 shared_data->ref_count++;
903 g_signal_connect_closure (action, "activate", closure, FALSE);
906 gtk_action_group_add_action_with_accel (action_group,
908 entries[i].accelerator);
909 g_object_unref (action);
912 shared_data_unref (shared_data);
916 * gtk_action_group_add_radio_actions:
917 * @action_group: the action group
918 * @entries: an array of radio action descriptions
919 * @n_entries: the number of entries
920 * @value: the value of the action to activate initially, or -1 if
921 * no action should be activated
922 * @on_change: the callback to connect to the changed signal
923 * @user_data: data to pass to the action callbacks
925 * This is a convenience routine to create a group of radio actions and
926 * add them to the action group.
928 * The "changed" signal of the first radio action is connected to the
929 * @on_change callback and the accel paths of the actions are set to
930 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
935 gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
936 const GtkRadioActionEntry *entries,
942 gtk_action_group_add_radio_actions_full (action_group,
945 on_change, user_data, NULL);
949 * gtk_action_group_add_radio_actions_full:
950 * @action_group: the action group
951 * @entries: an array of radio action descriptions
952 * @n_entries: the number of entries
953 * @value: the value of the action to activate initially, or -1 if
954 * no action should be activated
955 * @on_change: the callback to connect to the changed signal
956 * @user_data: data to pass to the action callbacks
957 * @destroy: destroy notification callback for @user_data
959 * This variant of gtk_action_group_add_radio_actions() adds a
960 * #GDestroyNotify callback for @user_data.
965 gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
966 const GtkRadioActionEntry *entries,
971 GDestroyNotify destroy)
973 /* Keep this in sync with the other
974 * gtk_action_group_add_..._actions_full() functions.
977 GtkTranslateFunc translate_func;
978 gpointer translate_data;
979 GSList *group = NULL;
980 GtkRadioAction *first_action = NULL;
982 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
984 translate_func = action_group->private_data->translate_func;
985 translate_data = action_group->private_data->translate_data;
987 for (i = 0; i < n_entries; i++)
989 GtkRadioAction *action;
991 const gchar *tooltip;
995 label = translate_func (entries[i].label, translate_data);
996 tooltip = translate_func (entries[i].tooltip, translate_data);
1000 label = entries[i].label;
1001 tooltip = entries[i].tooltip;
1004 action = gtk_radio_action_new (entries[i].name,
1007 entries[i].stock_id,
1011 first_action = action;
1013 gtk_radio_action_set_group (action, group);
1014 group = gtk_radio_action_get_group (action);
1016 if (value == entries[i].value)
1017 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
1019 gtk_action_group_add_action_with_accel (action_group,
1020 GTK_ACTION (action),
1021 entries[i].accelerator);
1022 g_object_unref (action);
1025 if (on_change && first_action)
1026 g_signal_connect_data (first_action, "changed",
1027 on_change, user_data,
1028 (GClosureNotify)destroy, 0);
1032 * gtk_action_group_set_translate_func:
1033 * @action_group: a #GtkActionGroup
1034 * @func: a #GtkTranslateFunc
1035 * @data: data to be passed to @func and @notify
1036 * @notify: a #GtkDestroyNotify function to be called when @action_group is
1037 * destroyed and when the translation function is changed again
1039 * Sets a function to be used for translating the @label and @tooltip of
1040 * #GtkActionGroupEntry<!-- -->s added by gtk_action_group_add_actions().
1042 * If you're using gettext(), it is enough to set the translation domain
1043 * with gtk_action_group_set_translation_domain().
1048 gtk_action_group_set_translate_func (GtkActionGroup *action_group,
1049 GtkTranslateFunc func,
1051 GtkDestroyNotify notify)
1053 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1055 if (action_group->private_data->translate_notify)
1056 action_group->private_data->translate_notify (action_group->private_data->translate_data);
1058 action_group->private_data->translate_func = func;
1059 action_group->private_data->translate_data = data;
1060 action_group->private_data->translate_notify = notify;
1064 dgettext_swapped (const gchar *msgid,
1065 const gchar *domainname)
1067 return dgettext (domainname, msgid);
1071 * gtk_action_group_set_translation_domain:
1072 * @action_group: a #GtkActionGroup
1073 * @domain: the translation domain to use for dgettext() calls
1075 * Sets the translation domain and uses dgettext() for translating the
1076 * @label and @tooltip of #GtkActionEntry<!-- -->s added by
1077 * gtk_action_group_add_actions().
1079 * If you're not using gettext() for localization, see
1080 * gtk_action_group_set_translate_func().
1085 gtk_action_group_set_translation_domain (GtkActionGroup *action_group,
1086 const gchar *domain)
1088 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1090 gtk_action_group_set_translate_func (action_group,
1091 (GtkTranslateFunc)dgettext_swapped,
1096 /* Protected for use by GtkAction */
1098 _gtk_action_group_emit_connect_proxy (GtkActionGroup *action_group,
1102 g_signal_emit (action_group, action_group_signals[CONNECT_PROXY], 0,
1107 _gtk_action_group_emit_disconnect_proxy (GtkActionGroup *action_group,
1111 g_signal_emit (action_group, action_group_signals[DISCONNECT_PROXY], 0,
1116 _gtk_action_group_emit_pre_activate (GtkActionGroup *action_group,
1119 g_signal_emit (action_group, action_group_signals[PRE_ACTIVATE], 0, action);
1123 _gtk_action_group_emit_post_activate (GtkActionGroup *action_group,
1126 g_signal_emit (action_group, action_group_signals[POST_ACTIVATE], 0, action);