maemomm provides several Button classes derived from Gtk::Button. These provide features specific to the Hildon framework. These classes are described in detail in the following sub-sections.
Hildon::Button is a clickable button, derived from Gtk::Button, providing both a title and a sub-title (referred to as the value).
Hildon::CheckButton contains a label and a checkbox that remains "pressed-in" when clicked, acting in a similar way to Gtk::CheckButton.
Hildon::PickerButton displays a single item selected from a list. Clicking on the button brings up a Hildon::PickerDialog, allowing selection of a different item. The value sub-title then indicates which item was selected. This behaviour is similar to Gtk::ComboBox in gtkmm.
Hildon::DateButton shows a text label and a date. When clicked it shows a Hildon::PickerDialog containing a Hildon::DateSelector. The value sub-title then indicates which date was selected.
Hildon::TimeButton is similar to Hildon::DateButton, using a time rather than a date, by displaying a Hildon::TimeSelector when clicked. The value sub-title then indicates which time was selected.
A Hildon::Button is the equivalent of a Gtk::Button. As it is derived from Gtk::Button, the API is the same, with some Hildon-specific additions.
The arrangement and size properties of a Hildon::Button are construct-time only. While a Button can contain any valid child widget, by default it contains two labels, a primary title and a secondary value, as opposed to the single label in a Gtk::Button.
This example shows a simple window that contains a Hildon::Button. When clicked, a line of output is sent to the terminal.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H
#include <hildonmm/window.h>
#include <hildonmm/button.h>
#include <gtkmm/buttonbox.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
//Signal handlers:
void on_button_clicked();
//Child widgets:
Gtk::HButtonBox box_;
Hildon::Button button_;
};
#endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h"
#include <iostream>
ExampleWindow::ExampleWindow() :
button_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
Hildon::BUTTON_ARRANGEMENT_VERTICAL,
"Click Me",
"Secondary (value) label")
{
set_title("Hildon::Button Example");
box_.add(button_);
add(box_);
button_.signal_clicked().connect(
sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
show_all_children();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_button_clicked()
{
std::cout << "Button clicked." << 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;
kit.run(window); //Shows the window and returns when it is closed.
return 0;
}
Hildon::CheckButton is similar to Gtk::CheckButton.
This example shows a simple window that contains a Hildon::CheckButton. When the button is toggled a line of output is sent to the terminal.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H
#include <hildonmm/window.h>
#include <hildonmm/button.h> // Needed for Hildon::BUTTON_ARRANGEMENT_*
#include <hildonmm/check-button.h>
#include <gtkmm/buttonbox.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
// Signal handlers:
void on_button_toggled();
// Child widgets:
Gtk::HButtonBox box_;
Hildon::CheckButton checkbutton_;
};
#endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h"
#include <iostream>
ExampleWindow::ExampleWindow() :
checkbutton_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH |
Gtk::Hildon::SIZE_FINGER_HEIGHT)
{
set_title("Hildon::CheckButton Example");
checkbutton_.set_label("Check Me");
box_.add(checkbutton_);
add(box_);
checkbutton_.signal_toggled().connect(
sigc::mem_fun(*this, &ExampleWindow::on_button_toggled));
show_all_children();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_button_toggled()
{
std::cout << "Button toggled: current state=" << checkbutton_.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;
kit.run(window); //Shows the window and returns when it is closed.
return 0;
}
A Hildon::PickerButton widget displays a specified Hildon::PickerDialog when clicked, much like a Gtk::ComboBox in gtkmm.
This example shows a simple window that contains a Hildon::PickerButton. When clicked, a continent is selected from a Hildon::PickerDialog and a line of output is sent to the terminal.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H
#include <hildonmm/window.h>
#include <hildonmm/picker-button.h>
#include <hildonmm/touch-selector-text.h>
#include <gtkmm.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
//Signal handlers:
void on_value_changed();
//Child widgets:
Gtk::HButtonBox box_;
Hildon::PickerButton pickerbutton_;
Hildon::TouchSelectorText touchselector_;
};
#endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h"
#include <iostream>
ExampleWindow::ExampleWindow() :
pickerbutton_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH |
Gtk::Hildon::SIZE_FINGER_HEIGHT, Hildon::BUTTON_ARRANGEMENT_VERTICAL)
{
set_title("Hildon::PickerButton Example");
touchselector_.append_text("Africa");
touchselector_.append_text("Antarctica");
touchselector_.append_text("Asia");
touchselector_.append_text("Australia");
touchselector_.append_text("Europe");
touchselector_.append_text("North America");
touchselector_.append_text("South America");
pickerbutton_.set_selector(touchselector_);
pickerbutton_.set_title("Select a Continent");
box_.add(pickerbutton_);
add(box_);
pickerbutton_.signal_value_changed().connect(
sigc::mem_fun(*this, &ExampleWindow::on_value_changed));
show_all_children();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_value_changed()
{
std::cout << "Selection changed. Current state=" <<
touchselector_.get_current_text() << std::endl;
}
File: main.cc
#include <hildonmm.h>
#include "examplewindow.h"
#include <iostream>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Hildon::init();
ExampleWindow window;
kit.run(window); //Shows the window and returns when it is closed.
return 0;
}
A Hildon::DateButton widget shows a text title and a date, and displays a Hildon::PickerDialog when clicked, enabling the user to select a date with a Hildon::DateSelector.
This example shows a simple window that contains a Hildon::DateButton. When a date is selected, the result appears as the value (sub-title) of the DateButton, and a line of output is sent to the terminal.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H
#include <gtkmm/buttonbox.h>
#include <hildonmm/window.h>
#include <hildonmm/date-button.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
// Signal handlers:
void on_button_changed();
// Child widgets:
Gtk::VButtonBox buttonbox_;
Hildon::DateButton datebutton_;
};
#endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h"
#include <iostream>
ExampleWindow::ExampleWindow()
{
set_title("Hildon::DateButton Example");
datebutton_.set_title("Select a Date");
buttonbox_.pack_start(datebutton_);
add(buttonbox_);
datebutton_.signal_value_changed().connect(
sigc::mem_fun(*this, &ExampleWindow::on_button_changed));
show_all_children();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_button_changed()
{
guint year = 0;
guint month = 0;
guint day = 0;
datebutton_.get_date(year, month, day);
std::cout << "Date chosen: year=" << year << ", month=" << month << ", day="
<< day << 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;
kit.run(window); //Shows the window and returns when it is closed.
return 0;
}
A Hildon::TimeButton widget shows a text title and a time. When clicked, Hildon::PickerDialog is displayed and the user can select a time with a Hildon::TimeSelector.
This example shows a simple window that contains a Hildon::TimeButton. The time may be selected in steps of five minutes and the result appears as the value (sub-title) of the TimeButton. Selecting a new time sends a line of output to the terminal.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H
#include <hildonmm/window.h>
#include <hildonmm/button.h> // Needed for Hildon::BUTTON_ARRANGEMENT_*
#include <hildonmm/time-button.h>
#include <gtkmm/buttonbox.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
// Signal handlers:
void on_button_value_changed();
// Child widgets:
Gtk::HButtonBox box_;
Hildon::TimeButton timebutton_;
};
#endif /* _MAEMOMM_EXAMPLEWINDOW_H */
File: examplewindow.cc
#include "examplewindow.h"
#include <iostream>
ExampleWindow::ExampleWindow() :
timebutton_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH |
Gtk::Hildon::SIZE_FINGER_HEIGHT, Hildon::BUTTON_ARRANGEMENT_VERTICAL, 5)
{
set_title("Hildon::TimeButton Example");
timebutton_.set_title("Select a Time");
timebutton_.set_time(12, 0);
box_.add(timebutton_);
add(box_);
timebutton_.signal_value_changed().connect(
sigc::mem_fun(*this, &ExampleWindow::on_button_value_changed));
show_all_children();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_button_value_changed()
{
std::cout << "Time changed. Selected time=" << timebutton_.get_hours()
<< ":" << timebutton_.get_minutes() << std::endl;
}
File: main.cc
#include <hildonmm.h>
#include "examplewindow.h"
#include <iostream>
int main(int argc, char *argv[])
{
Gtk::Main kit(argc, argv);
Hildon::init();
ExampleWindow window;
kit.run(window); //Shows the window and returns when it is closed.
return 0;
}