Table of Contents
There are specific APIs for Menus and Toolbars, but you should usually deal with them together, using the UIManager, which allows you to define actions which you can then arrange in menu and toolbars. You can then handle activation of the action instead of responding to the menu and toolbar items separately. And you can enable or disable both the menu and toolbar item just by changing action.
First, you should create the actions and add them to an ActionGroup. The arguments to Action::create() specify the action's name and how it will appear in menus and toolbars. Use stock items where possible so that you don't need to specify the label, accelerator, icon, and tooltips, and soyou can use pre-existing translations.
You can specify a signal handler when calling ActionGroup::add(). This signal handler will be called when the action is activated via either the menu item or the toolbar.
Note that you must specify actions for sub menus as well as menu items.
For instance:
m_refActionGroup = Gtk::ActionGroup::create(); m_refActionGroup->add( Gtk::Action::create("MenuFile", "_File") ); m_refActionGroup->add( Gtk::Action::create("New", Gtk::Stock::NEW), sigc::mem_fun(*this, &ExampleWindow::on_action_file_new) ); m_refActionGroup->add( Gtk::Action::create("ExportData", "Export Data"), sigc::mem_fun(*this, &ExampleWindow::on_action_file_open) ); m_refActionGroup->add( Gtk::Action::create("Quit", Gtk::Stock::QUIT), sigc::mem_fun(*this, &ExampleWindow::on_action_file_quit) );