2005-11-17 16:31:37 -05:00
|
|
|
#include <vector>
|
2005-11-13 07:15:05 -05:00
|
|
|
#include <iostream>
|
|
|
|
#include <gtkmm.h>
|
|
|
|
#include <gtkmm/accelmap.h>
|
2005-11-17 16:31:37 -05:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
#include <gtk/gtkaccelmap.h>
|
2005-11-13 07:15:05 -05:00
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace std;
|
|
|
|
using namespace sigc;
|
2005-11-17 16:31:37 -05:00
|
|
|
using namespace Glib;
|
|
|
|
|
2005-11-13 07:15:05 -05:00
|
|
|
void
|
|
|
|
printit (string txt)
|
|
|
|
{
|
|
|
|
cout << "This is the " << txt << " item\n";
|
|
|
|
}
|
|
|
|
|
2005-11-17 16:31:37 -05:00
|
|
|
Glib::RefPtr<Action>
|
2005-11-22 00:10:12 -05:00
|
|
|
make_action (Glib::RefPtr<ActionGroup> group, string name, string label, RefPtr<AccelGroup> accels, slot<void> sl, guint key, Gdk::ModifierType mods)
|
2005-11-13 07:15:05 -05:00
|
|
|
{
|
|
|
|
Glib::RefPtr<Action> act;
|
|
|
|
|
|
|
|
act = Action::create (name, label);
|
|
|
|
group->add (act, sl);
|
|
|
|
AccelMap::add_entry (act->get_accel_path(), key, mods);
|
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
act->set_accel_group (accels);
|
2005-11-13 07:15:05 -05:00
|
|
|
|
|
|
|
cerr << "action " << name << " has path " << act->get_accel_path() << endl;
|
|
|
|
|
|
|
|
return act;
|
|
|
|
}
|
|
|
|
|
|
|
|
Glib::RefPtr<Action>
|
|
|
|
make_action (Glib::RefPtr<ActionGroup> group, string name, string label)
|
|
|
|
{
|
|
|
|
Glib::RefPtr<Action> act;
|
|
|
|
|
|
|
|
act = Action::create (name, label);
|
|
|
|
group->add (act);
|
|
|
|
|
|
|
|
cerr << "action " << name << " has path " << act->get_accel_path() << endl;
|
|
|
|
|
|
|
|
return act;
|
|
|
|
}
|
|
|
|
|
2005-11-17 16:31:37 -05:00
|
|
|
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 {
|
|
|
|
key = AccelKey (GDK_VoidSymbol, Gdk::ModifierType (0));
|
|
|
|
}
|
|
|
|
|
|
|
|
return known;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<ActionGroup>
|
2005-11-22 00:10:12 -05:00
|
|
|
copy_actions (const RefPtr<ActionGroup> src)
|
2005-11-17 16:31:37 -05:00
|
|
|
{
|
2005-11-22 00:10:12 -05:00
|
|
|
RefPtr<ActionGroup> grp = ActionGroup::create (src->get_name());
|
|
|
|
|
|
|
|
ListHandle<RefPtr<Action> > group_actions = src->get_actions();
|
|
|
|
|
|
|
|
for (ListHandle<RefPtr<Action> >::iterator a = group_actions.begin(); a != group_actions.end(); ++a) {
|
|
|
|
RefPtr<Action> act = Action::create ((*a)->get_name(), (*a)->property_label());
|
2005-11-17 16:31:37 -05:00
|
|
|
grp->add (act);
|
|
|
|
}
|
|
|
|
|
|
|
|
return grp;
|
|
|
|
}
|
|
|
|
|
2005-11-13 07:15:05 -05:00
|
|
|
int
|
|
|
|
main (int argc, char* argv[])
|
|
|
|
{
|
|
|
|
Main app (argc, argv);
|
2005-11-22 00:10:12 -05:00
|
|
|
Window hidden (WINDOW_TOPLEVEL);
|
2005-11-13 07:15:05 -05:00
|
|
|
Window window (WINDOW_TOPLEVEL);
|
|
|
|
Window other_window (WINDOW_TOPLEVEL);
|
|
|
|
Button button ("click me for baz");
|
|
|
|
Button other_button ("click me for baz");
|
|
|
|
VBox vpacker;
|
|
|
|
VBox other_vpacker;
|
|
|
|
|
|
|
|
Glib::RefPtr<ActionGroup> actions;
|
|
|
|
Glib::RefPtr<ActionGroup> other_actions;
|
2005-11-17 16:31:37 -05:00
|
|
|
Glib::RefPtr<ActionGroup> shared_actions;
|
2005-11-13 07:15:05 -05:00
|
|
|
Glib::RefPtr<UIManager> uimanager;
|
|
|
|
Glib::RefPtr<UIManager> other_uimanager;
|
|
|
|
Glib::RefPtr<UIManager> shared_uimanager;
|
|
|
|
|
|
|
|
window.set_name ("Editor");
|
|
|
|
window.set_title ("Editor");
|
|
|
|
|
|
|
|
other_window.set_name ("Other");
|
|
|
|
other_window.set_title ("Other");
|
|
|
|
|
|
|
|
uimanager = UIManager::create();
|
|
|
|
other_uimanager = UIManager::create();
|
2005-11-22 00:10:12 -05:00
|
|
|
shared_uimanager = UIManager::create();
|
2005-11-13 07:15:05 -05:00
|
|
|
|
|
|
|
actions = ActionGroup::create("MyActions");
|
|
|
|
other_actions = ActionGroup::create("OtherActions");
|
2005-11-22 00:10:12 -05:00
|
|
|
shared_actions = ActionGroup::create("SharedActions");
|
2005-11-13 07:15:05 -05:00
|
|
|
|
|
|
|
uimanager->add_ui_from_file ("mtest.menus");
|
|
|
|
other_uimanager->add_ui_from_file ("mtest_other.menus");
|
|
|
|
|
2005-11-17 16:31:37 -05:00
|
|
|
// AccelMap::load ("mtest.bindings");
|
2005-11-13 07:15:05 -05:00
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
RefPtr<AccelGroup> accels = hidden.get_accel_group();
|
|
|
|
|
2005-11-13 07:15:05 -05:00
|
|
|
make_action (actions, "TopMenu", "top");
|
2005-11-22 00:10:12 -05:00
|
|
|
make_action (actions, "Foo", "foo", accels, bind (sigc::ptr_fun (printit), "foo"), GDK_p, Gdk::ModifierType (0));
|
2005-11-17 16:31:37 -05:00
|
|
|
|
2005-11-13 07:15:05 -05:00
|
|
|
make_action (other_actions, "OTopMenu", "otop");
|
2005-11-22 00:10:12 -05:00
|
|
|
make_action (other_actions, "OFoo", "foo", accels, bind (sigc::ptr_fun (printit), "o-foo"), GDK_p, Gdk::ModifierType (0));
|
2005-11-17 16:31:37 -05:00
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
make_action (shared_actions, "Bar", "bar", accels, bind (sigc::ptr_fun (printit), "barshared"), GDK_p, Gdk::CONTROL_MASK);
|
|
|
|
RefPtr<Action> act = make_action (shared_actions, "Baz", "baz", accels, bind (sigc::ptr_fun (printit), "baz-shared"), GDK_p, Gdk::SHIFT_MASK);
|
2005-11-13 07:15:05 -05:00
|
|
|
|
2005-11-17 16:31:37 -05:00
|
|
|
act->connect_proxy (button);
|
|
|
|
act->connect_proxy (other_button);
|
2005-11-13 07:15:05 -05:00
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
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));
|
2005-11-13 07:15:05 -05:00
|
|
|
|
2005-11-22 00:10:12 -05:00
|
|
|
other_window.add_accel_group (accels);
|
|
|
|
window.add_accel_group (accels);
|
2005-11-13 07:15:05 -05:00
|
|
|
|
|
|
|
Gtk::MenuBar* m;
|
|
|
|
|
|
|
|
m = dynamic_cast<MenuBar*>(other_uimanager->get_widget ("/OTop"));
|
|
|
|
|
|
|
|
other_vpacker.pack_start (*m);
|
|
|
|
other_vpacker.pack_start (other_button);
|
|
|
|
|
|
|
|
other_window.add (other_vpacker);
|
|
|
|
other_window.show_all ();
|
|
|
|
|
|
|
|
m = dynamic_cast<MenuBar*>(uimanager->get_widget ("/Top"));
|
|
|
|
|
|
|
|
vpacker.pack_start (*m);
|
|
|
|
vpacker.pack_start (button);
|
|
|
|
|
|
|
|
window.add (vpacker);
|
|
|
|
window.show_all ();
|
|
|
|
|
|
|
|
Settings::get_default()->property_gtk_can_change_accels() = true;
|
|
|
|
|
2005-11-17 16:31:37 -05:00
|
|
|
AccelMap::save ("mtest.bindings");
|
2005-11-13 07:15:05 -05:00
|
|
|
|
|
|
|
app.run ();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|