change selection behaviour for track header context click
[ardour.git] / gtk2_ardour / mtest.cc
1 #include <vector>
2 #include <iostream>
3 #include <gtkmm.h>
4 #include <gtkmm/accelmap.h>
5 #include <gdk/gdkkeysyms.h>
6 #include <gtk/gtkaccelmap.h>
7
8 using namespace Gtk;
9 using namespace std;
10 using namespace sigc;
11 using namespace Glib;
12
13 void
14 printit (string txt)
15 {
16         cout << "This is the " << txt << " item\n";
17 }
18
19 Glib::RefPtr<Action>
20 make_action (Glib::RefPtr<ActionGroup> group, string name, string label, RefPtr<AccelGroup> accels, slot<void> sl, guint key, Gdk::ModifierType mods)
21 {
22         Glib::RefPtr<Action> act;
23
24         act = Action::create (name, label);
25         group->add (act, sl);
26         AccelMap::add_entry (act->get_accel_path(), key, mods);
27
28         act->set_accel_group (accels);
29
30         cerr << "action " << name << " has path " << act->get_accel_path() << endl;
31         
32         return act;
33 }
34
35 Glib::RefPtr<Action>
36 make_action (Glib::RefPtr<ActionGroup> group, string name, string label)
37 {
38         Glib::RefPtr<Action> act;
39
40         act = Action::create (name, label);
41         group->add (act);
42
43         cerr << "action " << name << " has path " << act->get_accel_path() << endl;
44
45         return act;
46 }
47
48 bool 
49 lookup_entry (const ustring accel_path, Gtk::AccelKey& key)
50 {
51         GtkAccelKey gkey;
52         bool known = gtk_accel_map_lookup_entry (accel_path.c_str(), &gkey);
53         
54         if (known) {
55                 key = AccelKey (gkey.accel_key, Gdk::ModifierType (gkey.accel_mods));
56         } else {
57                 key = AccelKey (GDK_VoidSymbol, Gdk::ModifierType (0));
58         }
59
60         return known;
61 }
62
63 RefPtr<ActionGroup>
64 copy_actions (const RefPtr<ActionGroup> src)
65 {
66         RefPtr<ActionGroup> grp = ActionGroup::create (src->get_name());
67         
68         ListHandle<RefPtr<Action> > group_actions = src->get_actions();
69         
70         for (ListHandle<RefPtr<Action> >::iterator a = group_actions.begin(); a != group_actions.end(); ++a) {
71                 RefPtr<Action> act = Action::create ((*a)->get_name(), (*a)->property_label());
72                 grp->add (act);
73         }
74
75         return grp;
76 }
77
78 int
79 main (int argc, char* argv[])
80 {
81         Main app (argc, argv);
82         Window hidden (WINDOW_TOPLEVEL);
83         Window window (WINDOW_TOPLEVEL);
84         Window other_window (WINDOW_TOPLEVEL);
85         Button button ("click me for baz");
86         Button other_button ("click me for baz");
87         VBox   vpacker;
88         VBox   other_vpacker;
89
90         Glib::RefPtr<ActionGroup> actions;
91         Glib::RefPtr<ActionGroup> other_actions;
92         Glib::RefPtr<ActionGroup> shared_actions;
93         Glib::RefPtr<UIManager> uimanager;
94         Glib::RefPtr<UIManager> other_uimanager;
95         Glib::RefPtr<UIManager> shared_uimanager;
96
97         window.set_name ("Editor");
98         window.set_title ("Editor");
99
100         other_window.set_name ("Other");
101         other_window.set_title ("Other");
102
103         uimanager = UIManager::create();
104         other_uimanager = UIManager::create();
105         shared_uimanager = UIManager::create();
106
107         actions = ActionGroup::create("MyActions");
108         other_actions = ActionGroup::create("OtherActions");
109         shared_actions = ActionGroup::create("SharedActions");
110
111         uimanager->add_ui_from_file ("mtest.menus");
112         other_uimanager->add_ui_from_file ("mtest_other.menus");
113         
114         // AccelMap::load ("mtest.bindings");
115
116         RefPtr<AccelGroup> accels = hidden.get_accel_group();
117
118         make_action (actions, "TopMenu", "top");
119         make_action (actions, "Foo", "foo", accels, bind (sigc::ptr_fun (printit), "foo"), GDK_p, Gdk::ModifierType (0));
120
121         make_action (other_actions, "OTopMenu", "otop");
122         make_action (other_actions, "OFoo", "foo", accels, bind (sigc::ptr_fun (printit), "o-foo"), GDK_p, Gdk::ModifierType (0));
123
124         make_action (shared_actions, "Bar", "bar", accels, bind (sigc::ptr_fun (printit), "barshared"), GDK_p, Gdk::CONTROL_MASK);
125         RefPtr<Action> act = make_action (shared_actions, "Baz", "baz", accels, bind (sigc::ptr_fun (printit), "baz-shared"), GDK_p, Gdk::SHIFT_MASK);
126         
127         act->connect_proxy (button);
128         act->connect_proxy (other_button);
129
130         uimanager->insert_action_group (copy_actions (actions));
131         uimanager->insert_action_group (copy_actions (shared_actions));
132         other_uimanager->insert_action_group (copy_actions (other_actions));
133         other_uimanager->insert_action_group (copy_actions (shared_actions));
134
135         other_window.add_accel_group (accels);
136         // window.add_accel_group (accels);
137
138         Gtk::MenuBar* m;
139
140         m = dynamic_cast<MenuBar*>(other_uimanager->get_widget ("/OTop"));
141
142         other_vpacker.pack_start (*m);
143         other_vpacker.pack_start (other_button);
144
145         other_window.add (other_vpacker);
146         other_window.show_all ();
147
148         m = dynamic_cast<MenuBar*>(uimanager->get_widget ("/Top"));
149
150         vpacker.pack_start (*m);
151         vpacker.pack_start (button);
152
153         window.add (vpacker);
154         window.show_all ();
155
156         Settings::get_default()->property_gtk_can_change_accels() = true;
157
158         AccelMap::save ("mtest.bindings");
159
160         app.run ();
161
162         return 0;
163 }