Merged revisions 6293,6296-6306,6308 via svnmerge from
[ardour.git] / libs / gtkmm2 / gtk / src / actiongroup.ccg
1 // -*- c++ -*-
2 /* $Id: actiongroup.ccg,v 1.10 2006/05/16 20:36:24 murrayc Exp $ */
3
4 /* Copyright 2003 The gtkmm Development Team
5  *
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.
10  *
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.
15  *
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.
19  */
20
21 #include <gtk/gtkactiongroup.h>
22 #include <gtkmm/accelmap.h>
23
24
25 namespace Gtk
26 {
27
28 void ActionGroup::add(const Glib::RefPtr<Action>& action)
29 {
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 */ );
32 }
33
34 void ActionGroup::add(const Glib::RefPtr<Action>& action, const AccelKey& accel_key)
35 {
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.
38
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();
43   if(key)
44   {
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())
49     {
50       //Copied from the gtk_action_group_add_action_with_accel() implementation:
51
52       gchar* action_name = 0;
53       g_object_get(G_OBJECT(action->gobj()), "name", &action_name, static_cast<char*>(0));
54       if(action_name)
55       {
56         accel_path =  "<Actions>/" + get_name() + '/' + action_name;
57         g_free(action_name);
58       }
59     }
60
61     AccelMap::add_entry(accel_path, key, mod);
62
63     action->set_accel_path(accel_path);
64   }
65
66   gtk_action_group_add_action(gobj(), action->gobj());
67 }
68
69   
70
71 void ActionGroup::add(const Glib::RefPtr<Action>& action, const Action::SlotActivate& slot)
72 {
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.
76   
77   action->signal_activate().connect(slot);
78   
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.
83   
84   add(action);
85 }
86
87 void ActionGroup::add(const Glib::RefPtr<Action>& action, const AccelKey& accel_key, const Action::SlotActivate& slot)
88 {
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.
92
93   action->signal_activate().connect(slot);
94   add(action, accel_key);
95
96   /*
97   //Create the accel path (a kind of unique key):
98   Glib::ustring accel_path = "<Actions>/" + get_name() + "/" + action->get_name();
99
100   //Register the accel path:
101   Gtk::AccelMap::add_entry(accel_path, accel_key.get_key(), accel_key.get_mod());
102
103   //USe the accel path:
104   action->set_accel_path(accel_path);
105   */
106 }  
107
108
109 } // namespace Gtk
110