Table of Contents
This sections explains the additional widgets provided by the Maemo framework. Of course, most gtkmm widgets are also available.
Menus in maemomm use gtkmm menu functions, although the menu is then attached to the
Hildon::Program/Window and appears in the title bar. A Gtk::Menu can be created and attached
to the Hildon::Program
to be used as a common menu for all Hildon::Windows that don't have their own menu.
Another way is to use a Gtk::Menu in a Hildon::Window. In this way every application window
can have a different menu.
gtkmm menus can be created either manually or using Gtk::UIManager. The Gtk::UIManager is an action-based API used to create menus and toolbars using an XML description. We will first show the manual way and introduce you to Gtk::UIManager in the section Menus and Toolbars using Gtk::UIManager
// In constuctor of window set_menu(main);
This is the only line that differs from the equivalent gtkmm example program. It specifies what menu to use for the application.
This example creates a menu with a submenu. This submenu contains radio menu items and check menu item, all of which can be toggled. The last item in the menu (Close) is attached to a signal handler so that the application can also be closed from the menu.
This example also shows how to derive your own window class from Hildon::Window
:
File: examplewindow.h
#ifndef GTKMM_EXAMPLEWINDOW_H #define GTKMM_EXAMPLEWINDOW_H #include <hildonmm/window.h> class ExampleWindow : public Hildon::Window { public: ExampleWindow(); virtual ~ExampleWindow(); protected: //Signal handlers: virtual void on_menu_close(); Gtk::Menu m_main; Gtk::Menu m_sub_others; Gtk::MenuItem m_item_others; Gtk::RadioMenuItem::Group m_group; Gtk::RadioMenuItem m_item_radio1; Gtk::RadioMenuItem m_item_radio2; Gtk::CheckMenuItem m_item_check; Gtk::CheckMenuItem m_item_close; Gtk::SeparatorMenuItem m_item_separator; }; #endif //GTKMM_EXAMPLEWINDOW_H
File: examplewindow.cc
#include "examplewindow.h" #include <gtkmm.h> #include <iostream> ExampleWindow::ExampleWindow() : m_item_others("Others"), m_item_radio1(m_group, "Radio1"), m_item_radio2(m_group, "Radio2"), m_item_check("Check"), m_item_close("Close") { // Add menu items to right menus m_main.append(m_item_others); m_sub_others.append(m_item_radio1); m_sub_others.append(m_item_radio2); m_sub_others.append(m_item_separator); m_sub_others.append(m_item_check); m_main.append(m_item_close); // Add others submenu to the "Others" item m_item_others.set_submenu(m_sub_others); m_main.show_all(); //Show the main menu and all its child widgets. set_main_menu(m_main); // Attach the callback functions to the activate signal m_item_close.signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_menu_close) ); // Make all child widgets visible: show_all_children(); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_menu_close() { hide(); }
File: main.cc
#include <hildonmm.h> #include "examplewindow.h" #include <iostream> int main(int argc, char *argv[]) { // Initialize gtkmm: Gtk::Main kit(&argc, &argv); Hildon::init(); osso_context_t* osso_context = osso_initialize("example", "0.0.1", TRUE /* deprecated parameter */, 0 /* Use default Glib main loop context */); if(!osso_context) std::cerr << "osso_initialize() failed." << std::endl; Glib::set_application_name("Menu example"); // Create Window and set it to Program ExampleWindow window; Hildon::Program::get_instance()->add_window(window); // Add example label to window Gtk::Label label("Hildon::Menu example"); window.add(label); label.show(); // Begin the main application kit.run(window); osso_deinitialize(osso_context); return 0; }
The documentation for the standard gtkmm menu API can be found in the gtkmm tutorial.