OSC: Changed gainVCA to gainfader as VCA is already used.
[ardour.git] / gtk2_ardour / mtest.cc
1 /*
2     Copyright (C) 2000-2007 Paul Davis
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <vector>
21 #include <iostream>
22 #include <gtkmm.h>
23 #include <gtkmm/accelmap.h>
24 #include <gdk/gdkkeysyms.h>
25 #include <gtk/gtkaccelmap.h>
26
27 using namespace Gtk;
28 using namespace std;
29 using namespace Glib;
30
31 void
32 printit (string txt)
33 {
34         cout << "This is the " << txt << " item\n";
35 }
36
37 Glib::RefPtr<Action>
38 make_action (Glib::RefPtr<ActionGroup> group, string name, string label, RefPtr<AccelGroup> accels, slot<void> sl, guint key, Gdk::ModifierType mods)
39 {
40         Glib::RefPtr<Action> act;
41
42         act = Action::create (name, label);
43         group->add (act, sl);
44         AccelMap::add_entry (act->get_accel_path(), key, mods);
45
46         act->set_accel_group (accels);
47
48         cerr << "action " << name << " has path " << act->get_accel_path() << endl;
49
50         return act;
51 }
52
53 Glib::RefPtr<Action>
54 make_action (Glib::RefPtr<ActionGroup> group, string name, string label)
55 {
56         Glib::RefPtr<Action> act;
57
58         act = Action::create (name, label);
59         group->add (act);
60
61         cerr << "action " << name << " has path " << act->get_accel_path() << endl;
62
63         return act;
64 }
65
66 bool
67 lookup_entry (const string accel_path, Gtk::AccelKey& key)
68 {
69         GtkAccelKey gkey;
70         bool known = gtk_accel_map_lookup_entry (accel_path.c_str(), &gkey);
71
72         if (known) {
73                 key = AccelKey (gkey.accel_key, Gdk::ModifierType (gkey.accel_mods));
74         } else {
75                 key = AccelKey (GDK_VoidSymbol, Gdk::ModifierType (0));
76         }
77
78         return known;
79 }
80
81 RefPtr<ActionGroup>
82 copy_actions (const RefPtr<ActionGroup> src)
83 {
84         RefPtr<ActionGroup> grp = ActionGroup::create (src->get_name());
85
86         ListHandle<RefPtr<Action> > group_actions = src->get_actions();
87
88         for (ListHandle<RefPtr<Action> >::iterator a = group_actions.begin(); a != group_actions.end(); ++a) {
89                 RefPtr<Action> act = Action::create ((*a)->get_name(), (*a)->property_label());
90                 grp->add (act);
91         }
92
93         return grp;
94 }
95
96 int
97 main (int argc, char* argv[])
98 {
99         Main app (argc, argv);
100         Window hidden (WINDOW_TOPLEVEL);
101         Window window (WINDOW_TOPLEVEL);
102         Window other_window (WINDOW_TOPLEVEL);
103         Button button ("click me for baz");
104         Button other_button ("click me for baz");
105         VBox   vpacker;
106         VBox   other_vpacker;
107
108         Glib::RefPtr<ActionGroup> actions;
109         Glib::RefPtr<ActionGroup> other_actions;
110         Glib::RefPtr<ActionGroup> shared_actions;
111         Glib::RefPtr<UIManager> uimanager;
112         Glib::RefPtr<UIManager> other_uimanager;
113         Glib::RefPtr<UIManager> shared_uimanager;
114
115         window.set_name ("Editor");
116         window.set_title ("Editor");
117
118         other_window.set_name ("Other");
119         other_window.set_title ("Other");
120
121         uimanager = UIManager::create();
122         other_uimanager = UIManager::create();
123         shared_uimanager = UIManager::create();
124
125         actions = ActionGroup::create("MyActions");
126         other_actions = ActionGroup::create("OtherActions");
127         shared_actions = ActionGroup::create("SharedActions");
128
129         uimanager->add_ui_from_file ("mtest.menus");
130         other_uimanager->add_ui_from_file ("mtest_other.menus");
131
132         // AccelMap::load ("mtest.bindings");
133
134         RefPtr<AccelGroup> accels = hidden.get_accel_group();
135
136         make_action (actions, "TopMenu", "top");
137         make_action (actions, "Foo", "foo", accels, sigc::bind (sigc::ptr_fun (printit), "foo"), GDK_p, Gdk::ModifierType (0));
138
139         make_action (other_actions, "OTopMenu", "otop");
140         make_action (other_actions, "OFoo", "foo", accels, sigc::bind (sigc::ptr_fun (printit), "o-foo"), GDK_p, Gdk::ModifierType (0));
141
142         make_action (shared_actions, "Bar", "bar", accels, sigc::bind (sigc::ptr_fun (printit), "barshared"), GDK_p, Gdk::CONTROL_MASK);
143         RefPtr<Action> act = make_action (shared_actions, "Baz", "baz", accels, sigc::bind (sigc::ptr_fun (printit), "baz-shared"), GDK_p, Gdk::SHIFT_MASK);
144
145         act->connect_proxy (button);
146         act->connect_proxy (other_button);
147
148         uimanager->insert_action_group (copy_actions (actions));
149         uimanager->insert_action_group (copy_actions (shared_actions));
150         other_uimanager->insert_action_group (copy_actions (other_actions));
151         other_uimanager->insert_action_group (copy_actions (shared_actions));
152
153         other_window.add_accel_group (accels);
154         // window.add_accel_group (accels);
155
156         Gtk::MenuBar* m;
157
158         m = dynamic_cast<MenuBar*>(other_uimanager->get_widget ("/OTop"));
159
160         other_vpacker.pack_start (*m);
161         other_vpacker.pack_start (other_button);
162
163         other_window.add (other_vpacker);
164         other_window.show_all ();
165
166         m = dynamic_cast<MenuBar*>(uimanager->get_widget ("/Top"));
167
168         vpacker.pack_start (*m);
169         vpacker.pack_start (button);
170
171         window.add (vpacker);
172         window.show_all ();
173
174         Settings::get_default()->property_gtk_can_change_accels() = true;
175
176         AccelMap::save ("mtest.bindings");
177
178         app.run ();
179
180         return 0;
181 }