fix up file renaming code a little bit
[ArdourMidi.git] / gtk2_ardour / mtest.cc
blobb37b75c9b6f91e0edcc9e6d775fa59033ed52c75
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 Glib;
31 void
32 printit (string txt)
34 cout << "This is the " << txt << " item\n";
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)
40 Glib::RefPtr<Action> act;
42 act = Action::create (name, label);
43 group->add (act, sl);
44 AccelMap::add_entry (act->get_accel_path(), key, mods);
46 act->set_accel_group (accels);
48 cerr << "action " << name << " has path " << act->get_accel_path() << endl;
50 return act;
53 Glib::RefPtr<Action>
54 make_action (Glib::RefPtr<ActionGroup> group, string name, string label)
56 Glib::RefPtr<Action> act;
58 act = Action::create (name, label);
59 group->add (act);
61 cerr << "action " << name << " has path " << act->get_accel_path() << endl;
63 return act;
66 bool
67 lookup_entry (const ustring accel_path, Gtk::AccelKey& key)
69 GtkAccelKey gkey;
70 bool known = gtk_accel_map_lookup_entry (accel_path.c_str(), &gkey);
72 if (known) {
73 key = AccelKey (gkey.accel_key, Gdk::ModifierType (gkey.accel_mods));
74 } else {
75 key = AccelKey (GDK_VoidSymbol, Gdk::ModifierType (0));
78 return known;
81 RefPtr<ActionGroup>
82 copy_actions (const RefPtr<ActionGroup> src)
84 RefPtr<ActionGroup> grp = ActionGroup::create (src->get_name());
86 ListHandle<RefPtr<Action> > group_actions = src->get_actions();
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);
93 return grp;
96 int
97 main (int argc, char* argv[])
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;
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;
115 window.set_name ("Editor");
116 window.set_title ("Editor");
118 other_window.set_name ("Other");
119 other_window.set_title ("Other");
121 uimanager = UIManager::create();
122 other_uimanager = UIManager::create();
123 shared_uimanager = UIManager::create();
125 actions = ActionGroup::create("MyActions");
126 other_actions = ActionGroup::create("OtherActions");
127 shared_actions = ActionGroup::create("SharedActions");
129 uimanager->add_ui_from_file ("mtest.menus");
130 other_uimanager->add_ui_from_file ("mtest_other.menus");
132 // AccelMap::load ("mtest.bindings");
134 RefPtr<AccelGroup> accels = hidden.get_accel_group();
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));
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));
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);
145 act->connect_proxy (button);
146 act->connect_proxy (other_button);
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));
153 other_window.add_accel_group (accels);
154 // window.add_accel_group (accels);
156 Gtk::MenuBar* m;
158 m = dynamic_cast<MenuBar*>(other_uimanager->get_widget ("/OTop"));
160 other_vpacker.pack_start (*m);
161 other_vpacker.pack_start (other_button);
163 other_window.add (other_vpacker);
164 other_window.show_all ();
166 m = dynamic_cast<MenuBar*>(uimanager->get_widget ("/Top"));
168 vpacker.pack_start (*m);
169 vpacker.pack_start (button);
171 window.add (vpacker);
172 window.show_all ();
174 Settings::get_default()->property_gtk_can_change_accels() = true;
176 AccelMap::save ("mtest.bindings");
178 app.run ();
180 return 0;