make mixbus packaging work, to some degree
[ardour2.git] / gtk2_ardour / mtest.cc
blobe3f3855010f27f710ec110295a566c4eef2e24f2
1 /*
2 Copyright (C) 2000-2007 Paul Davis
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.
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.
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.
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>
27 using namespace Gtk;
28 using namespace std;
29 using namespace sigc;
30 using namespace Glib;
32 void
33 printit (string txt)
35 cout << "This is the " << txt << " item\n";
38 Glib::RefPtr<Action>
39 make_action (Glib::RefPtr<ActionGroup> group, string name, string label, RefPtr<AccelGroup> accels, slot<void> sl, guint key, Gdk::ModifierType mods)
41 Glib::RefPtr<Action> act;
43 act = Action::create (name, label);
44 group->add (act, sl);
45 AccelMap::add_entry (act->get_accel_path(), key, mods);
47 act->set_accel_group (accels);
49 cerr << "action " << name << " has path " << act->get_accel_path() << endl;
51 return act;
54 Glib::RefPtr<Action>
55 make_action (Glib::RefPtr<ActionGroup> group, string name, string label)
57 Glib::RefPtr<Action> act;
59 act = Action::create (name, label);
60 group->add (act);
62 cerr << "action " << name << " has path " << act->get_accel_path() << endl;
64 return act;
67 bool
68 lookup_entry (const ustring accel_path, Gtk::AccelKey& key)
70 GtkAccelKey gkey;
71 bool known = gtk_accel_map_lookup_entry (accel_path.c_str(), &gkey);
73 if (known) {
74 key = AccelKey (gkey.accel_key, Gdk::ModifierType (gkey.accel_mods));
75 } else {
76 key = AccelKey (GDK_VoidSymbol, Gdk::ModifierType (0));
79 return known;
82 RefPtr<ActionGroup>
83 copy_actions (const RefPtr<ActionGroup> src)
85 RefPtr<ActionGroup> grp = ActionGroup::create (src->get_name());
87 ListHandle<RefPtr<Action> > group_actions = src->get_actions();
89 for (ListHandle<RefPtr<Action> >::iterator a = group_actions.begin(); a != group_actions.end(); ++a) {
90 RefPtr<Action> act = Action::create ((*a)->get_name(), (*a)->property_label());
91 grp->add (act);
94 return grp;
97 int
98 main (int argc, char* argv[])
100 Main app (argc, argv);
101 Window hidden (WINDOW_TOPLEVEL);
102 Window window (WINDOW_TOPLEVEL);
103 Window other_window (WINDOW_TOPLEVEL);
104 Button button ("click me for baz");
105 Button other_button ("click me for baz");
106 VBox vpacker;
107 VBox other_vpacker;
109 Glib::RefPtr<ActionGroup> actions;
110 Glib::RefPtr<ActionGroup> other_actions;
111 Glib::RefPtr<ActionGroup> shared_actions;
112 Glib::RefPtr<UIManager> uimanager;
113 Glib::RefPtr<UIManager> other_uimanager;
114 Glib::RefPtr<UIManager> shared_uimanager;
116 window.set_name ("Editor");
117 window.set_title ("Editor");
119 other_window.set_name ("Other");
120 other_window.set_title ("Other");
122 uimanager = UIManager::create();
123 other_uimanager = UIManager::create();
124 shared_uimanager = UIManager::create();
126 actions = ActionGroup::create("MyActions");
127 other_actions = ActionGroup::create("OtherActions");
128 shared_actions = ActionGroup::create("SharedActions");
130 uimanager->add_ui_from_file ("mtest.menus");
131 other_uimanager->add_ui_from_file ("mtest_other.menus");
133 // AccelMap::load ("mtest.bindings");
135 RefPtr<AccelGroup> accels = hidden.get_accel_group();
137 make_action (actions, "TopMenu", "top");
138 make_action (actions, "Foo", "foo", accels, bind (sigc::ptr_fun (printit), "foo"), GDK_p, Gdk::ModifierType (0));
140 make_action (other_actions, "OTopMenu", "otop");
141 make_action (other_actions, "OFoo", "foo", accels, bind (sigc::ptr_fun (printit), "o-foo"), GDK_p, Gdk::ModifierType (0));
143 make_action (shared_actions, "Bar", "bar", accels, bind (sigc::ptr_fun (printit), "barshared"), GDK_p, Gdk::CONTROL_MASK);
144 RefPtr<Action> act = make_action (shared_actions, "Baz", "baz", accels, bind (sigc::ptr_fun (printit), "baz-shared"), GDK_p, Gdk::SHIFT_MASK);
146 act->connect_proxy (button);
147 act->connect_proxy (other_button);
149 uimanager->insert_action_group (copy_actions (actions));
150 uimanager->insert_action_group (copy_actions (shared_actions));
151 other_uimanager->insert_action_group (copy_actions (other_actions));
152 other_uimanager->insert_action_group (copy_actions (shared_actions));
154 other_window.add_accel_group (accels);
155 // window.add_accel_group (accels);
157 Gtk::MenuBar* m;
159 m = dynamic_cast<MenuBar*>(other_uimanager->get_widget ("/OTop"));
161 other_vpacker.pack_start (*m);
162 other_vpacker.pack_start (other_button);
164 other_window.add (other_vpacker);
165 other_window.show_all ();
167 m = dynamic_cast<MenuBar*>(uimanager->get_widget ("/Top"));
169 vpacker.pack_start (*m);
170 vpacker.pack_start (button);
172 window.add (vpacker);
173 window.show_all ();
175 Settings::get_default()->property_gtk_can_change_accels() = true;
177 AccelMap::save ("mtest.bindings");
179 app.run ();
181 return 0;