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"
35 #include "gtktoggleaction.h"
36 #include "gtkradioaction.h"
37 #include "gtkaccelmap.h"
38 #include "gtkmarshalers.h"
39 #include "gtkprivate.h"
43 #define GTK_ACTION_GROUP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_ACTION_GROUP, GtkActionGroupPrivate))
45 struct _GtkActionGroupPrivate
52 GtkTranslateFunc translate_func;
53 gpointer translate_data;
54 GtkDestroyNotify translate_notify;
74 static void gtk_action_group_init (GtkActionGroup *self);
75 static void gtk_action_group_class_init (GtkActionGroupClass *class);
76 static void gtk_action_group_finalize (GObject *object);
77 static void gtk_action_group_set_property (GObject *object,
81 static void gtk_action_group_get_property (GObject *object,
85 static GtkAction *gtk_action_group_real_get_action (GtkActionGroup *self,
90 gtk_action_group_get_type (void)
92 static GType type = 0;
96 static const GTypeInfo type_info =
98 sizeof (GtkActionGroupClass),
100 NULL, /* base_finalize */
101 (GClassInitFunc) gtk_action_group_class_init,
102 NULL, /* class_finalize */
103 NULL, /* class_data */
104 sizeof (GtkActionGroup),
106 (GInstanceInitFunc) gtk_action_group_init,
109 type = g_type_register_static (G_TYPE_OBJECT, I_("GtkActionGroup"),
116 static GObjectClass *parent_class = NULL;
117 static guint action_group_signals[LAST_SIGNAL] = { 0 };
120 gtk_action_group_class_init (GtkActionGroupClass *klass)
122 GObjectClass *gobject_class;
124 gobject_class = G_OBJECT_CLASS (klass);
125 parent_class = g_type_class_peek_parent (klass);
127 gobject_class->finalize = gtk_action_group_finalize;
128 gobject_class->set_property = gtk_action_group_set_property;
129 gobject_class->get_property = gtk_action_group_get_property;
130 klass->get_action = gtk_action_group_real_get_action;
132 g_object_class_install_property (gobject_class,
134 g_param_spec_string ("name",
136 P_("A name for the action group."),
138 GTK_PARAM_READWRITE | 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."),
145 GTK_PARAM_READWRITE));
146 g_object_class_install_property (gobject_class,
148 g_param_spec_boolean ("visible",
150 P_("Whether the action group is visible."),
152 GTK_PARAM_READWRITE));
155 * GtkActionGroup::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 (I_("connect_proxy"),
176 G_OBJECT_CLASS_TYPE (klass),
178 _gtk_marshal_VOID__OBJECT_OBJECT,
180 GTK_TYPE_ACTION, GTK_TYPE_WIDGET);
183 * GtkActionGroup::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 (I_("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 (I_("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 (I_("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, I_("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.
390 G_CONST_RETURN gchar *
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,
423 /* Minor optimization, the action_groups state only affects actions that are
424 * themselves sensitive */
425 if (gtk_action_get_sensitive (action))
426 g_object_notify (G_OBJECT (action), "sensitive");
430 * gtk_action_group_set_sensitive:
431 * @action_group: the action group
432 * @sensitive: new sensitivity
434 * Changes the sensitivity of @action_group
439 gtk_action_group_set_sensitive (GtkActionGroup *action_group,
442 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
444 sensitive = sensitive != FALSE;
446 if (action_group->private_data->sensitive != sensitive)
448 action_group->private_data->sensitive = sensitive;
449 g_hash_table_foreach (action_group->private_data->actions,
450 (GHFunc) cb_set_action_sensitivity, NULL);
452 g_object_notify (G_OBJECT (action_group), "sensitive");
457 * gtk_action_group_get_visible:
458 * @action_group: the action group
460 * Returns %TRUE if the group is visible. The constituent actions
461 * can only be logically visible (see gtk_action_is_visible()) if
462 * they are visible (see gtk_action_get_visible()) and their group
465 * Return value: %TRUE if the group is visible.
470 gtk_action_group_get_visible (GtkActionGroup *action_group)
472 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), FALSE);
474 return action_group->private_data->visible;
478 cb_set_action_visiblity (const gchar *name,
481 /* Minor optimization, the action_groups state only affects actions that are
482 * themselves sensitive */
483 if (gtk_action_get_visible (action))
484 g_object_notify (G_OBJECT (action), "visible");
488 * gtk_action_group_set_visible:
489 * @action_group: the action group
490 * @visible: new visiblity
492 * Changes the visible of @action_group.
497 gtk_action_group_set_visible (GtkActionGroup *action_group,
500 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
502 visible = visible != FALSE;
504 if (action_group->private_data->visible != visible)
506 action_group->private_data->visible = visible;
507 g_hash_table_foreach (action_group->private_data->actions,
508 (GHFunc) cb_set_action_visiblity, NULL);
510 g_object_notify (G_OBJECT (action_group), "visible");
515 * gtk_action_group_get_action:
516 * @action_group: the action group
517 * @action_name: the name of the action
519 * Looks up an action in the action group by name.
521 * Returns: the action, or %NULL if no action by that name exists
526 gtk_action_group_get_action (GtkActionGroup *action_group,
527 const gchar *action_name)
529 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
530 g_return_val_if_fail (GTK_ACTION_GROUP_GET_CLASS (action_group)->get_action != NULL, NULL);
532 return (* GTK_ACTION_GROUP_GET_CLASS (action_group)->get_action)
533 (action_group, action_name);
537 * gtk_action_group_add_action:
538 * @action_group: the action group
541 * Adds an action object to the action group. Note that this function
542 * does not set up the accel path of the action, which can lead to problems
543 * if a user tries to modify the accelerator of a menuitem associated with
544 * the action. Therefore you must either set the accel path yourself with
545 * gtk_action_set_accel_path(), or use
546 * <literal>gtk_action_group_add_action_with_accel (..., NULL)</literal>.
551 gtk_action_group_add_action (GtkActionGroup *action_group,
554 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
555 g_return_if_fail (GTK_IS_ACTION (action));
556 g_return_if_fail (gtk_action_get_name (action) != NULL);
558 g_hash_table_insert (action_group->private_data->actions,
559 g_strdup (gtk_action_get_name (action)),
560 g_object_ref (action));
561 g_object_set (action, I_("action-group"), action_group, NULL);
565 * gtk_action_group_add_action_with_accel:
566 * @action_group: the action group
567 * @action: the action to add
568 * @accelerator: the accelerator for the action, in
569 * the format understood by gtk_accelerator_parse(), or "" for no accelerator, or
570 * %NULL to use the stock accelerator
572 * Adds an action object to the action group and sets up the accelerator.
574 * If @accelerator is %NULL, attempts to use the accelerator associated
575 * with the stock_id of the action.
577 * Accel paths are set to
578 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
583 gtk_action_group_add_action_with_accel (GtkActionGroup *action_group,
585 const gchar *accelerator)
589 GdkModifierType accel_mods;
590 GtkStockItem stock_item;
594 g_object_get (action, "name", &name, "stock-id", &stock_id, NULL);
596 accel_path = g_strconcat ("<Actions>/",
597 action_group->private_data->name, "/", name, NULL);
601 if (accelerator[0] == 0)
605 gtk_accelerator_parse (accelerator, &accel_key, &accel_mods);
607 g_warning ("Unable to parse accelerator '%s' for action '%s'",
611 else if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
613 accel_key = stock_item.keyval;
614 accel_mods = stock_item.modifier;
618 gtk_accel_map_add_entry (accel_path, accel_key, accel_mods);
620 gtk_action_set_accel_path (action, accel_path);
621 gtk_action_group_add_action (action_group, action);
629 * gtk_action_group_remove_action:
630 * @action_group: the action group
633 * Removes an action object from the action group.
638 gtk_action_group_remove_action (GtkActionGroup *action_group,
641 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
642 g_return_if_fail (GTK_IS_ACTION (action));
643 g_return_if_fail (gtk_action_get_name (action) != NULL);
645 /* extra protection to make sure action->name is valid */
646 g_object_ref (action);
647 g_hash_table_remove (action_group->private_data->actions, gtk_action_get_name (action));
648 g_object_unref (action);
652 add_single_action (gpointer key,
656 GList **list = user_data;
658 *list = g_list_prepend (*list, value);
662 * gtk_action_group_list_actions:
663 * @action_group: the action group
665 * Lists the actions in the action group.
667 * Returns: an allocated list of the action objects in the action group
672 gtk_action_group_list_actions (GtkActionGroup *action_group)
674 GList *actions = NULL;
675 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), NULL);
677 g_hash_table_foreach (action_group->private_data->actions, add_single_action, &actions);
679 return g_list_reverse (actions);
684 * gtk_action_group_add_actions:
685 * @action_group: the action group
686 * @entries: an array of action descriptions
687 * @n_entries: the number of entries
688 * @user_data: data to pass to the action callbacks
690 * This is a convenience function to create a number of actions and add them
691 * to the action group.
693 * The "activate" signals of the actions are connected to the callbacks and
694 * their accel paths are set to
695 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
700 gtk_action_group_add_actions (GtkActionGroup *action_group,
701 const GtkActionEntry *entries,
705 gtk_action_group_add_actions_full (action_group,
710 typedef struct _SharedData SharedData;
715 GDestroyNotify destroy;
719 shared_data_unref (gpointer data)
721 SharedData *shared_data = (SharedData *)data;
723 shared_data->ref_count--;
724 if (shared_data->ref_count == 0)
726 if (shared_data->destroy)
727 (*shared_data->destroy) (shared_data->data);
729 g_slice_free (SharedData, shared_data);
735 * gtk_action_group_add_actions_full:
736 * @action_group: the action group
737 * @entries: an array of action descriptions
738 * @n_entries: the number of entries
739 * @user_data: data to pass to the action callbacks
740 * @destroy: destroy notification callback for @user_data
742 * This variant of gtk_action_group_add_actions() adds a #GDestroyNotify
743 * callback for @user_data.
748 gtk_action_group_add_actions_full (GtkActionGroup *action_group,
749 const GtkActionEntry *entries,
752 GDestroyNotify destroy)
755 /* Keep this in sync with the other
756 * gtk_action_group_add_..._actions_full() functions.
759 SharedData *shared_data;
761 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
763 shared_data = g_slice_new0 (SharedData);
764 shared_data->ref_count = 1;
765 shared_data->data = user_data;
766 shared_data->destroy = destroy;
768 for (i = 0; i < n_entries; i++)
772 const gchar *tooltip;
774 label = gtk_action_group_translate_string (action_group, entries[i].label);
775 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
777 action = gtk_action_new (entries[i].name,
780 entries[i].stock_id);
782 if (entries[i].callback)
786 closure = g_cclosure_new (entries[i].callback, user_data, NULL);
787 g_closure_add_finalize_notifier (closure, shared_data,
788 (GClosureNotify)shared_data_unref);
789 shared_data->ref_count++;
791 g_signal_connect_closure (action, "activate", closure, FALSE);
794 gtk_action_group_add_action_with_accel (action_group,
796 entries[i].accelerator);
797 g_object_unref (action);
800 shared_data_unref (shared_data);
804 * gtk_action_group_add_toggle_actions:
805 * @action_group: the action group
806 * @entries: an array of toggle action descriptions
807 * @n_entries: the number of entries
808 * @user_data: data to pass to the action callbacks
810 * This is a convenience function to create a number of toggle actions and add them
811 * to the action group.
813 * The "activate" signals of the actions are connected to the callbacks and
814 * their accel paths are set to
815 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
820 gtk_action_group_add_toggle_actions (GtkActionGroup *action_group,
821 const GtkToggleActionEntry *entries,
825 gtk_action_group_add_toggle_actions_full (action_group,
832 * gtk_action_group_add_toggle_actions_full:
833 * @action_group: the action group
834 * @entries: an array of toggle action descriptions
835 * @n_entries: the number of entries
836 * @user_data: data to pass to the action callbacks
837 * @destroy: destroy notification callback for @user_data
839 * This variant of gtk_action_group_add_toggle_actions() adds a
840 * #GDestroyNotify callback for @user_data.
845 gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group,
846 const GtkToggleActionEntry *entries,
849 GDestroyNotify destroy)
851 /* Keep this in sync with the other
852 * gtk_action_group_add_..._actions_full() functions.
855 SharedData *shared_data;
857 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
859 shared_data = g_slice_new0 (SharedData);
860 shared_data->ref_count = 1;
861 shared_data->data = user_data;
862 shared_data->destroy = destroy;
864 for (i = 0; i < n_entries; i++)
866 GtkToggleAction *action;
868 const gchar *tooltip;
870 label = gtk_action_group_translate_string (action_group, entries[i].label);
871 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
873 action = gtk_toggle_action_new (entries[i].name,
876 entries[i].stock_id);
878 gtk_toggle_action_set_active (action, entries[i].is_active);
880 if (entries[i].callback)
884 closure = g_cclosure_new (entries[i].callback, user_data, NULL);
885 g_closure_add_finalize_notifier (closure, shared_data,
886 (GClosureNotify)shared_data_unref);
887 shared_data->ref_count++;
889 g_signal_connect_closure (action, "activate", closure, FALSE);
892 gtk_action_group_add_action_with_accel (action_group,
894 entries[i].accelerator);
895 g_object_unref (action);
898 shared_data_unref (shared_data);
902 * gtk_action_group_add_radio_actions:
903 * @action_group: the action group
904 * @entries: an array of radio action descriptions
905 * @n_entries: the number of entries
906 * @value: the value of the action to activate initially, or -1 if
907 * no action should be activated
908 * @on_change: the callback to connect to the changed signal
909 * @user_data: data to pass to the action callbacks
911 * This is a convenience routine to create a group of radio actions and
912 * add them to the action group.
914 * The "changed" signal of the first radio action is connected to the
915 * @on_change callback and the accel paths of the actions are set to
916 * <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
921 gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
922 const GtkRadioActionEntry *entries,
928 gtk_action_group_add_radio_actions_full (action_group,
931 on_change, user_data, NULL);
935 * gtk_action_group_add_radio_actions_full:
936 * @action_group: the action group
937 * @entries: an array of radio action descriptions
938 * @n_entries: the number of entries
939 * @value: the value of the action to activate initially, or -1 if
940 * no action should be activated
941 * @on_change: the callback to connect to the changed signal
942 * @user_data: data to pass to the action callbacks
943 * @destroy: destroy notification callback for @user_data
945 * This variant of gtk_action_group_add_radio_actions() adds a
946 * #GDestroyNotify callback for @user_data.
951 gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
952 const GtkRadioActionEntry *entries,
957 GDestroyNotify destroy)
959 /* Keep this in sync with the other
960 * gtk_action_group_add_..._actions_full() functions.
963 GSList *group = NULL;
964 GtkRadioAction *first_action = NULL;
966 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
968 for (i = 0; i < n_entries; i++)
970 GtkRadioAction *action;
972 const gchar *tooltip;
974 label = gtk_action_group_translate_string (action_group, entries[i].label);
975 tooltip = gtk_action_group_translate_string (action_group, entries[i].tooltip);
977 action = gtk_radio_action_new (entries[i].name,
984 first_action = action;
986 gtk_radio_action_set_group (action, group);
987 group = gtk_radio_action_get_group (action);
989 if (value == entries[i].value)
990 gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
992 gtk_action_group_add_action_with_accel (action_group,
994 entries[i].accelerator);
995 g_object_unref (action);
998 if (on_change && first_action)
999 g_signal_connect_data (first_action, "changed",
1000 on_change, user_data,
1001 (GClosureNotify)destroy, 0);
1005 * gtk_action_group_set_translate_func:
1006 * @action_group: a #GtkActionGroup
1007 * @func: a #GtkTranslateFunc
1008 * @data: data to be passed to @func and @notify
1009 * @notify: a #GtkDestroyNotify function to be called when @action_group is
1010 * destroyed and when the translation function is changed again
1012 * Sets a function to be used for translating the @label and @tooltip of
1013 * #GtkActionGroupEntry<!-- -->s added by gtk_action_group_add_actions().
1015 * If you're using gettext(), it is enough to set the translation domain
1016 * with gtk_action_group_set_translation_domain().
1021 gtk_action_group_set_translate_func (GtkActionGroup *action_group,
1022 GtkTranslateFunc func,
1024 GtkDestroyNotify notify)
1026 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1028 if (action_group->private_data->translate_notify)
1029 action_group->private_data->translate_notify (action_group->private_data->translate_data);
1031 action_group->private_data->translate_func = func;
1032 action_group->private_data->translate_data = data;
1033 action_group->private_data->translate_notify = notify;
1037 dgettext_swapped (const gchar *msgid,
1038 const gchar *domainname)
1040 return dgettext (domainname, msgid);
1044 * gtk_action_group_set_translation_domain:
1045 * @action_group: a #GtkActionGroup
1046 * @domain: the translation domain to use for dgettext() calls
1048 * Sets the translation domain and uses dgettext() for translating the
1049 * @label and @tooltip of #GtkActionEntry<!-- -->s added by
1050 * gtk_action_group_add_actions().
1052 * If you're not using gettext() for localization, see
1053 * gtk_action_group_set_translate_func().
1058 gtk_action_group_set_translation_domain (GtkActionGroup *action_group,
1059 const gchar *domain)
1061 g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
1063 gtk_action_group_set_translate_func (action_group,
1064 (GtkTranslateFunc)dgettext_swapped,
1071 * gtk_action_group_translate_string:
1072 * @action_group: a #GtkActionGroup
1075 * Translates a string using the specified translate_func(). This
1076 * is mainly intended for language bindings.
1078 * Returns: the translation of @string
1082 G_CONST_RETURN gchar *
1083 gtk_action_group_translate_string (GtkActionGroup *action_group,
1084 const gchar *string)
1086 GtkTranslateFunc translate_func;
1087 gpointer translate_data;
1089 g_return_val_if_fail (GTK_IS_ACTION_GROUP (action_group), string);
1094 translate_func = action_group->private_data->translate_func;
1095 translate_data = action_group->private_data->translate_data;
1098 return translate_func (string, translate_data);
1103 /* Protected for use by GtkAction */
1105 _gtk_action_group_emit_connect_proxy (GtkActionGroup *action_group,
1109 g_signal_emit (action_group, action_group_signals[CONNECT_PROXY], 0,
1114 _gtk_action_group_emit_disconnect_proxy (GtkActionGroup *action_group,
1118 g_signal_emit (action_group, action_group_signals[DISCONNECT_PROXY], 0,
1123 _gtk_action_group_emit_pre_activate (GtkActionGroup *action_group,
1126 g_signal_emit (action_group, action_group_signals[PRE_ACTIVATE], 0, action);
1130 _gtk_action_group_emit_post_activate (GtkActionGroup *action_group,
1133 g_signal_emit (action_group, action_group_signals[POST_ACTIVATE], 0, action);
1136 #define __GTK_ACTION_GROUP_C__
1137 #include "gtkaliasdef.c"