2 /* $Id: actiongroup.ccg,v 1.10 2006/05/16 20:36:24 murrayc Exp $ */
4 /* Copyright 2003 The gtkmm Development Team
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the 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 this library; if not, write to the Free
18 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <gtk/gtkactiongroup.h>
22 #include <gtkmm/accelmap.h>
28 void ActionGroup::add(const Glib::RefPtr<Action>& action)
30 gtk_action_group_add_action_with_accel(gobj(), Glib::unwrap(action),
31 0 /* accelerator=0 means use the stock accelerator if this is a stock item */ );
34 void ActionGroup::add(const Glib::RefPtr<Action>& action, const AccelKey& accel_key)
36 // We need to half-duplicate the gtk_action_group_add_action_with_accel() implementation, because we want to
37 // use AccelKey, not just the accelerator string format that is _one_ of the ways to create an AccelKey. murrayc.
39 //The AccelKey might have been constructed from key+mod or from an accelerator string,
40 //but it the end that just produces a key+mod.
41 guint key = accel_key.get_key();
42 Gdk::ModifierType mod = accel_key.get_mod();
45 // The AccelKey constructor can take an accel path, so I suppose we should not ignore it,
46 // but I can't imagine how it would be useful with the UIManager. murrayc.
47 Glib::ustring accel_path = accel_key.get_path();
48 if(accel_path.empty())
50 //Copied from the gtk_action_group_add_action_with_accel() implementation:
52 gchar* action_name = 0;
53 g_object_get(G_OBJECT(action->gobj()), "name", &action_name, static_cast<char*>(0));
56 accel_path = "<Actions>/" + get_name() + '/' + action_name;
61 AccelMap::add_entry(accel_path, key, mod);
63 action->set_accel_path(accel_path);
66 gtk_action_group_add_action(gobj(), action->gobj());
71 void ActionGroup::add(const Glib::RefPtr<Action>& action, const Action::SlotActivate& slot)
73 //This is meant to be similar to the gtk_action_group_add_actions() convenience method that is used from C.
74 //This also does the work of gtk_action_group_add_toggle_actions() and gtk_action_group_add_radio_actions_full(),
75 //because the extra stuff there is already done when the Action (or a derived type, such as ToggleAction) is create()ed.
77 action->signal_activate().connect(slot);
79 //We probably don't need to use translate_string(), because the label and tooltip will be regular translated strings in our C++ application code.
80 //But C needs it because gtk_action_group_add_actions() takes a static array of GtkActionEntrys whose fields
81 //can not be translated with gettext macros.
82 //But we should soon know if menus and toolbars are not translated in non-english locales. murrayc.
87 void ActionGroup::add(const Glib::RefPtr<Action>& action, const AccelKey& accel_key, const Action::SlotActivate& slot)
89 //This is meant to be similar to the gtk_action_group_add_actions() convenience method that is used from C.
90 //This also does the work of gtk_action_group_add_toggle_actions() and gtk_action_group_add_radio_actions_full(),
91 //because the extra stuff there is already done when the Action (or a derived type, such as ToggleAction) is create()ed.
93 action->signal_activate().connect(slot);
94 add(action, accel_key);
97 //Create the accel path (a kind of unique key):
98 Glib::ustring accel_path = "<Actions>/" + get_name() + "/" + action->get_name();
100 //Register the accel path:
101 Gtk::AccelMap::add_entry(accel_path, accel_key.get_key(), accel_key.get_mod());
103 //USe the accel path:
104 action->set_accel_path(accel_path);