The Maemo Human Interface Guidelines recommend the use of Hildon::AppMenu
to create menus for Maemo applications, which provides a menu containing a number of entries as Gtk::Button
s, organised in columns if necessary. This menu can be attached to a Hildon::Program
instance, and made common to the whole application, or attached to a Hildon::Window
instance so that different menus can be used.
Note | |
---|---|
|
Hildon::AppMenu
is a class derived from Gtk::Window
, and can contain Gtk::Button
objects as well as groups of filter buttons (Gtk::ToggleButton
and Gtk::RadioButton
objects).
A Gtk::Button
is added to a Hildon::AppMenu
with the append()
, insert()
or prepend()
methods. A filter button is added with the add_filter()
method. A list of either the items
, that is normal Gtk::Button
s, or the filter
s, that is Gtk::ToggleButton
s and Gtk::RadioButton
s, can be retrieved with the get_items()
and get_filters
methods, respectively.
This example shows how to attach a Hildon::AppMenu
class, containing Gtk::Button
s, Gtk::RadioButton
s, and Gtk::ToggleButton
s objects, to a Hildon::Program
, object. Clicking any of the buttons sends output to the terminal.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H #define _MAEMOMM_EXAMPLEWINDOW_H #include <hildonmm/window.h> #include <hildonmm/app-menu.h> #include <gtkmm/button.h> #include <gtkmm/radiobutton.h> #include <gtkmm/togglebutton.h> #include <gtkmm/label.h> class ExampleWindow : public Hildon::Window { public: ExampleWindow(); virtual ~ExampleWindow(); private: // Signal handlers: void on_button1_clicked(); void on_button2_clicked(); void on_radio_toggled(); void on_toggle1_toggled(); void on_toggle2_toggled(); // Child widgets: Hildon::AppMenu menu_; Gtk::Button button1_; Gtk::Button button2_; Gtk::RadioButton radio1_; Gtk::RadioButton radio2_; Gtk::ToggleButton toggle1_; Gtk::ToggleButton toggle2_; Gtk::Label label_; }; #endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h" #include <hildonmm/program.h> #include <iostream> ExampleWindow::ExampleWindow() : button1_("Button 1"), button2_("Button 2"), radio1_("Radio 1"), radio2_("Radio 2"), toggle1_("Toggle 1"), toggle2_("Toggle 2"), label_("Hildon::AppMenu example. Click window title to display menu.") { set_title("Hildon::AppMenu Example"); // Setup radio buttons to be in one group. radio1_.set_active(); Gtk::RadioButton::Group radio_group = radio1_.get_group(); radio2_.set_group(radio_group); // Add buttons and filters to AppMenu. menu_.append(button1_); menu_.append(button2_); menu_.add_filter(radio1_); menu_.add_filter(radio2_); menu_.add_filter(toggle1_); menu_.add_filter(toggle2_); menu_.show_all(); Hildon::Program::get_instance()->set_common_app_menu(menu_); add(label_); // Connect signal handlers. button1_.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_button1_clicked)); button2_.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_button2_clicked)); radio1_.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_radio_toggled)); toggle1_.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_toggle1_toggled)); toggle2_.signal_clicked().connect( sigc::mem_fun(*this, &ExampleWindow::on_toggle1_toggled)); show_all_children(); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_button1_clicked() { std::cout << "Button 1 clicked" << std::endl; } void ExampleWindow::on_button2_clicked() { std::cout << "Button 2 clicked" << std::endl; } void ExampleWindow::on_radio_toggled() { std::cout << "Radio button toggled, current state: Radio 1=" << radio1_.get_active() << ", Radio 2=" << radio2_.get_active() << std::endl; } void ExampleWindow::on_toggle1_toggled() { std::cout << "Toggle 1 toggled, current state=" << toggle1_.get_active() << std::endl; } void ExampleWindow::on_toggle2_toggled() { std::cout << "Toggle 2 toggled, current state=" << toggle2_.get_active() << std::endl; }
File: main.cc
#include <hildonmm.h> #include "examplewindow.h" int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); Hildon::init(); ExampleWindow window; Hildon::Program::get_instance()->add_window(window); kit.run(window); //Shows the window and returns when it is closed. return 0; }