
#include <iostream>
#include <gtkmm.h>

// compile with:
// g++ -g2 -O0 `pkg-config --cflags --libs gtkmm-2.4` test_ui_manager.cpp -o test_ui_manager


class TestWindow : public Gtk::Window
{
	public:

		enum action_t {
			action_quit
		};

		TestWindow()
		{
			Gtk::Box* vbox = Gtk::manage(new Gtk::VBox(false, 5));
			add(*vbox);

			Gtk::Label* label = Gtk::manage(new Gtk::Label("AAAAAAAAAAAAAAAA"));
			vbox->pack_start(*label, Gtk::PACK_SHRINK);

			show_all();

			Glib::ustring ui_info =
			"<menubar name='main_menubar'>"
			"	<menu action='file_menu'>"
			"		<menuitem action='action_quit' />"
			"	</menu>"
			"</menubar>";

			actiongroup_main = Gtk::ActionGroup::create("main_actions");

			actiongroup_main->add(Gtk::Action::create("file_menu", "_File"));

			Glib::RefPtr<Gtk::Action> action = Gtk::Action::create("action_quit", Gtk::Stock::QUIT);
			actiongroup_main->add(action, Gtk::AccelKey("<control>Q"),
					sigc::bind(sigc::bind(sigc::mem_fun(*this, &TestWindow::on_action_activated), action_quit), action));


			// create uimanager
			ui_manager = Gtk::UIManager::create();
			ui_manager->insert_action_group(actiongroup_main);

			try {
				ui_manager->add_ui_from_string(ui_info);
			}
			catch(Glib::Error& ex) {
				std::cerr << "UI Create failed: " << ex.what() << "\n";
			}

		}

		virtual ~TestWindow()
		{ }


	private:

		void on_action_activated(Glib::RefPtr<Gtk::Action> action, action_t action_type)
		{
			std::cerr << "TestWindow::on_action_activated()\n";
		}

		Glib::RefPtr<Gtk::UIManager> ui_manager;
		Glib::RefPtr<Gtk::ActionGroup> actiongroup_main;
};



int main(int argc, char *argv[])
{
    Gtk::Main m(&argc, &argv);

	TestWindow app;

    m.run(app);

    return 0;
}



