/* * Enhancing the main menu example of gtkmm-tutorial/unstable presented in * https://developer.gnome.org/gtkmm-tutorial/unstable/\ * sec-menus-examples.html.de#menu-example-main * to show an application menu as suggested in * https://wiki.gnome.org/ThreePointThree/Features/ApplicationMenu, * described in * https://wiki.gnome.org/HowDoI/ApplicationMenu * and realised using gtkmm in * https://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/\ * application/app_and_win_menus * * Started on 2014-11-10 * Current version: 2014-11-10 * Performed by: Jürgen Kleber (jkleber2701 t-online de) * * Original file downloaded on Sunday, 9th of November, 2014 from * https://git.gnome.org/browse/gtkmm-documentation/tree/examples/book/menus/\ * main_menu/examplewindow.cc */ #include "examplewindow.h" #include ExampleWindow::ExampleWindow() : Gtk::ApplicationWindow(), m_Box(Gtk::ORIENTATION_VERTICAL) { set_title("main menu example"); set_default_size(300, 100); add(m_Box); // put a MenuBar at the top of the box and other stuff below it. //Create actions for menus and toolbars: Glib::RefPtr refActionGroup = Gio::SimpleActionGroup::create(); //Edit menu: refActionGroup->add_action("copy", sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); refActionGroup->add_action("paste", sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); refActionGroup->add_action("something", sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); //Choices menus, to demonstrate Radio items, //using our convenience methods for string and int radio values: m_refChoice = refActionGroup->add_action_radio_string("choice", sigc::mem_fun(*this, &ExampleWindow::on_menu_choices), "a"); m_refChoiceOther = refActionGroup->add_action_radio_integer("choiceother", sigc::mem_fun(*this, &ExampleWindow::on_menu_choices_other), 1); m_refToggle = refActionGroup->add_action_bool("sometoggle", sigc::mem_fun(*this, &ExampleWindow::on_menu_toggle), false); //Help menu: refActionGroup->add_action("about", sigc::mem_fun(*this, &ExampleWindow::on_menu_others)); // Add a prefix to the actions declared in the .xml file insert_action_group("win", refActionGroup); //Create the toolbar and add it to a container widget: Gtk::Toolbar* toolbar = Gtk::manage(new Gtk::Toolbar()); Gtk::ToolButton* button = Gtk::manage(new Gtk::ToolButton()); button->set_icon_name("document-new"); // We can't do this until we can break the ToolButton ABI: // button->set_detailed_action_name("example.new"); gtk_actionable_set_detailed_action_name(GTK_ACTIONABLE(button->gobj()), "app.newstandard"); toolbar->add(*button); button = Gtk::manage(new Gtk::ToolButton()); button->set_icon_name("application-exit"); // We can't do this until we can break the ToolButton ABI: // button->set_detailed_action_name("example.quit"); gtk_actionable_set_detailed_action_name(GTK_ACTIONABLE(button->gobj()), "app.quit"); toolbar->add(*button); m_Box.pack_start(*toolbar, Gtk::PACK_SHRINK); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_menu_others() { std::cout << "A menu item was selected." << std::endl; } void ExampleWindow::on_menu_choices(const Glib::ustring& parameter) { //The radio action's state does not change automatically: m_refChoice->change_state(parameter); Glib::ustring message; if (parameter == "a") message = "Choice a was selected."; else message = "Choice b was selected"; std::cout << message << std::endl; } void ExampleWindow::on_menu_choices_other(int parameter) { //The radio action's state does not change automatically: m_refChoiceOther->change_state(parameter); Glib::ustring message; if (parameter == 1) message = "Choice 1 was selected."; else message = "Choice 2 was selected"; std::cout << message << std::endl; } void ExampleWindow::on_menu_toggle() { bool active = false; m_refToggle->get_state(active); //The toggle action's state does not change automatically: m_refToggle->change_state(!active); active = !active; Glib::ustring message; if (active) message = "Toggle is active."; else message = "Toggle is not active"; std::cout << message << std::endl; }