X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Fmtest.cc;h=b37b75c9b6f91e0edcc9e6d775fa59033ed52c75;hb=129ace60e24aa7b5297563d389edbae1d70a3a80;hp=adc36c18f4a6734ff8f2f7097fceb3924a0f1e1f;hpb=cdc2d055f1ede3d9565dbf2b2d1abbf87a1f622c;p=ardour.git diff --git a/gtk2_ardour/mtest.cc b/gtk2_ardour/mtest.cc index adc36c18f4..b37b75c9b6 100644 --- a/gtk2_ardour/mtest.cc +++ b/gtk2_ardour/mtest.cc @@ -1,3 +1,22 @@ +/* + Copyright (C) 2000-2007 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #include #include #include @@ -7,26 +26,8 @@ using namespace Gtk; using namespace std; -using namespace sigc; using namespace Glib; -struct ActionBinding { - Glib::ustring name; - Glib::ustring label; - Gtk::Action::SlotActivate binding; - guint key; - Gdk::ModifierType mods; - - ActionBinding (Glib::ustring n, Glib::ustring l, Gtk::Action::SlotActivate b, - guint k = GDK_VoidSymbol, Gdk::ModifierType m = Gdk::ModifierType (0)) - : name (n), - label (l), - binding (b), - key (k), - mods (m) {} -}; - - void printit (string txt) { @@ -34,37 +35,7 @@ printit (string txt) } Glib::RefPtr -make_action (vector >& groups, string name, string label, slot sl, guint key, Gdk::ModifierType mods) -{ - Glib::RefPtr last; - - for (vector >::iterator g = groups.begin(); g != groups.end(); ++g) { - Glib::RefPtr act = Action::create (name, label); - (*g)->add (act, sl); - AccelMap::add_entry (act->get_accel_path(), key, mods); - last = act; - } - - return last; -} - -Glib::RefPtr -make_action (Glib::RefPtr group, Glib::RefPtr accel_group, string name, string label, slot sl, guint key, Gdk::ModifierType mods) -{ - Glib::RefPtr act; - - act = Action::create (name, label); - group->add (act, sl); - AccelMap::add_entry (act->get_accel_path(), key, mods); - act->set_accel_group (accel_group); - - cerr << "action " << name << " has path " << act->get_accel_path() << endl; - - return act; -} - -Glib::RefPtr -make_action (Glib::RefPtr group, string name, string label, slot sl, guint key, Gdk::ModifierType mods) +make_action (Glib::RefPtr group, string name, string label, RefPtr accels, slot sl, guint key, Gdk::ModifierType mods) { Glib::RefPtr act; @@ -72,18 +43,7 @@ make_action (Glib::RefPtr group, string name, string label, slotadd (act, sl); AccelMap::add_entry (act->get_accel_path(), key, mods); - cerr << "action " << name << " has path " << act->get_accel_path() << endl; - - return act; -} - -Glib::RefPtr -make_action (Glib::RefPtr group, string name, string label, slot sl) -{ - Glib::RefPtr act; - - act = Action::create (name, label); - group->add (act, sl); + act->set_accel_group (accels); cerr << "action " << name << " has path " << act->get_accel_path() << endl; @@ -103,12 +63,12 @@ make_action (Glib::RefPtr group, string name, string label) return act; } -bool +bool lookup_entry (const ustring accel_path, Gtk::AccelKey& key) { GtkAccelKey gkey; bool known = gtk_accel_map_lookup_entry (accel_path.c_str(), &gkey); - + if (known) { key = AccelKey (gkey.accel_key, Gdk::ModifierType (gkey.accel_mods)); } else { @@ -119,34 +79,25 @@ lookup_entry (const ustring accel_path, Gtk::AccelKey& key) } RefPtr -make_shared_action_group (ustring name, vector& actions) +copy_actions (const RefPtr src) { - RefPtr grp = ActionGroup::create (name); - - for (vector::iterator i = actions.begin(); i != actions.end(); ++i) { - RefPtr act = Action::create ((*i)->name, (*i)->label); - grp->add (act); - - if ((*i)->key != GDK_VoidSymbol) { - Gtk::AccelKey key; + RefPtr grp = ActionGroup::create (src->get_name()); - /* since this is a shared action, only add it once */ + ListHandle > group_actions = src->get_actions(); - if (!lookup_entry (act->get_accel_path(), key)) { - AccelMap::add_entry (act->get_accel_path(), (*i)->key, (*i)->mods); - cerr << "added accel map entry for " << act->get_accel_path() << endl; - } - } + for (ListHandle >::iterator a = group_actions.begin(); a != group_actions.end(); ++a) { + RefPtr act = Action::create ((*a)->get_name(), (*a)->property_label()); + grp->add (act); } return grp; } - int main (int argc, char* argv[]) { Main app (argc, argv); + Window hidden (WINDOW_TOPLEVEL); Window window (WINDOW_TOPLEVEL); Window other_window (WINDOW_TOPLEVEL); Button button ("click me for baz"); @@ -169,42 +120,38 @@ main (int argc, char* argv[]) uimanager = UIManager::create(); other_uimanager = UIManager::create(); + shared_uimanager = UIManager::create(); actions = ActionGroup::create("MyActions"); other_actions = ActionGroup::create("OtherActions"); + shared_actions = ActionGroup::create("SharedActions"); uimanager->add_ui_from_file ("mtest.menus"); other_uimanager->add_ui_from_file ("mtest_other.menus"); - + // AccelMap::load ("mtest.bindings"); - vector > all_groups; - all_groups.push_back (actions); - all_groups.push_back (other_actions); - + RefPtr accels = hidden.get_accel_group(); + make_action (actions, "TopMenu", "top"); - make_action (actions, "Foo", "foo", bind (sigc::ptr_fun (printit), "foo"), GDK_p, Gdk::ModifierType (0)); + make_action (actions, "Foo", "foo", accels, sigc::bind (sigc::ptr_fun (printit), "foo"), GDK_p, Gdk::ModifierType (0)); make_action (other_actions, "OTopMenu", "otop"); - make_action (other_actions, "OFoo", "foo", bind (sigc::ptr_fun (printit), "o-foo"), GDK_p, Gdk::ModifierType (0)); - - vector shared_actions; + make_action (other_actions, "OFoo", "foo", accels, sigc::bind (sigc::ptr_fun (printit), "o-foo"), GDK_p, Gdk::ModifierType (0)); - shared_actions.push_back (new ActionBinding ("Bar", "bar", bind (sigc::ptr_fun (printit), "barshared"), GDK_p, Gdk::CONTROL_MASK)); - shared_actions.push_back (new ActionBinding ("Baz", "baz", bind (sigc::ptr_fun (printit), "baz-shared"), GDK_p, Gdk::SHIFT_MASK)); + make_action (shared_actions, "Bar", "bar", accels, sigc::bind (sigc::ptr_fun (printit), "barshared"), GDK_p, Gdk::CONTROL_MASK); + RefPtr act = make_action (shared_actions, "Baz", "baz", accels, sigc::bind (sigc::ptr_fun (printit), "baz-shared"), GDK_p, Gdk::SHIFT_MASK); - RefPtr act = Action::create (shared_actions.back()->name, shared_actions.back()->label); - act->connect_proxy (button); act->connect_proxy (other_button); - uimanager->insert_action_group (actions); - uimanager->insert_action_group (make_shared_action_group ("shared", shared_actions)); - other_uimanager->insert_action_group (other_actions); - other_uimanager->insert_action_group (make_shared_action_group ("othershared", shared_actions)); + uimanager->insert_action_group (copy_actions (actions)); + uimanager->insert_action_group (copy_actions (shared_actions)); + other_uimanager->insert_action_group (copy_actions (other_actions)); + other_uimanager->insert_action_group (copy_actions (shared_actions)); - other_window.add_accel_group (other_uimanager->get_accel_group()); - window.add_accel_group (uimanager->get_accel_group()); + other_window.add_accel_group (accels); + // window.add_accel_group (accels); Gtk::MenuBar* m;