Buttons

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.

Button

The Hildon::Button class is the equivalent of the Gtk::Button class from gtkmm. As it is derived from Gtk::Button, the API is the same, with some Hildon-specific additions.

The arrangement and size properties of 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 of Gtk::Button.

Button reference

Example

This example shows a simple window that contains a button. When the button is clicked, a line of output is sent to the terminal.

Button

Figure 4.3. Button


Source code

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;
}

CheckButton

The Hildon::CheckButton widget is similar to the Gtk::CheckButton widget.

CheckButton reference

Example

This example shows a simple window that contains a check button. When the button is toggled, a line of output is sent to the terminal.

CheckButton

Figure 4.4. CheckButton


Source code

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;
}

PickerButton

The Hildon::PickerButton widget displays a specified picker dialogue when it is clicked, much like a combo box in gtkmm.

PickerButton reference

Example

This example shows a simple window that contains a picker button. When it is clicked, a continent is selected from a picker dialogue and a line of output is sent to the terminal.

PickerButton

Figure 4.5. PickerButton


Source code

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;
}

DateButton

The Hildon::DateButton widget shows a text title and a date, and displays a picker dialogue when clicked, enabling the user to select a date with a date selector.

DateButton reference

Example

This example shows a simple window that contains a date button. When a date is selected, the result appears as the value (sub-title) of the date button, and a line of output is sent to the terminal.

DateButton

Figure 4.6. DateButton


Source code

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;
}

TimeButton

The Hildon::TimeButton widget shows a text title and a time. When it is clicked, a picker dialogue is displayed and the user can select a time with a time selector.

TimeButton reference

Example

This example shows a simple window that contains a time button. The time can be selected in steps of five minutes and the result appears as the value (sub-title) of the time button. Selecting a new time sends a line of output to the terminal.

TimeButton

Figure 4.7. TimeButton


Source code

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;
}