Buttons

Buttons in maemomm use gtkmm button functions, providing additional features specific to the Hildon framework. Not considering the buttons already found in gtkmm, five types of button are provided in maemomm:

Button

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.

Button reference

Example

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

Figure 5.3. Button

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

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

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_clicked()
{
  std::cout << "Button clicked!" << std::endl;
}

CheckButton

A Hildon::CheckButton is the equivalent of a Gtk::CheckButton, in that the API is the same.

CheckButton reference

Example

This example shows a simple window that contains a Hildon::CheckButton. When the state is toggled, a line of output is sent to the terminal.

Figure 5.4. CheckButton

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

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

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_toggled()
{
  std::cout << "Button toggled: current state=" << checkbutton_.get_active() << std::endl;
}

PickerButton

A Hildon::PickerButton is a widget that, when clicked, displays a Hildon::PickerDialog much like a Gtk::ComboBox in gtkmm.

PickerButton reference

Example

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

Figure 5.5. PickerButton

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.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::TouchSelector touchselector;
};

#endif /* _MAEMOMM_EXAMPLEWINDOW_H */

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

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");

  Gtk::TreeModelColumnRecord columns;
  Gtk::TreeModelColumn<Glib::ustring> text_column;
  columns.add(text_column);
  Glib::RefPtr<Gtk::ListStore> list_store = Gtk::ListStore::create(columns);
  Glib::RefPtr<Hildon::TouchSelectorColumn> text_col = touchselector.append_text_column(list_store);
  g_object_set(text_col->gobj(), "text-column", 0, static_cast<char*>(0));
  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;
}

DateButton

A Hildon::DateButton is a widget that shows a text label and a date, and displays a Hildon::PickerDialog when clicked, enabling the user to select a date with a Hildon::DateSelector.

DateButton reference

Example

This example shows a simple window that contains a Hildon::DateButton. When a date is selected, the result appears as the value (subtitle) of the DateButton, and a line of output is sent to the terminal.

Figure 5.6. DateButton

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();

protected:
  // Signal handlers:
  void on_button_changed();

  // Child widgets:
  Gtk::VButtonBox buttonbox_;
  Hildon::DateButton datebutton_;
};

#endif /* _MAEMOMM_EXAMPLEWINDOW_H */

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

File: examplewindow.cc

#include "examplewindow.h"
#include <iostream>

ExampleWindow::ExampleWindow()
{
  set_title("Hildon::DateButton example");

  buttonbox_.pack_start(datebutton_);
  add(buttonbox_);

  datebutton_.signal_value_changed().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_changed));

  show_all();
}

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

TimeButton

A Hildon::TimeButton is a widget that shows a text label and a time. When clicked, Hildon::PickerDialog is displayed and the user can select a time with a Hildon::TimeSelector. It is possible to select the step size between minutes at construction time.

TimeButton reference

Example

This example shows a simple window that contains a Hildon::TimeButton. A time is selected in steps of five minutes, and the result appears as the value (subtitle) of the TimeButton. Selecting a new time sends a line of output to the terminal.

Figure 5.7. TimeButton

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

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

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_value_changed()
{
  std::cout << "Time changed! Selected time=" << timebutton_.get_hours() << ":" << timebutton_.get_minutes() << std::endl;
}