Chapter 4. Widgets

Table of Contents

This section explains the additional widgets provided by the Maemo framework. Of course, most gtkmm widgets are also available.

Windows

Window classes in maemomm are derived from Gtk::Window, with extra features specific to the Hildon framework. For example, you can set a Gtk::Menu for a window with the set_main_menu() method.

Window

The Hildon::Window widget is a top-level window in the Hildon framework. You can attach a menu to a window, either with the set_app_menu() or the set_main_menu() methods, for use with Hildon::AppMenu or Gtk::Menu classes respectively. The Maemo Human Interface Guidelines recommend that you use only Hildon::AppMenu in Maemo 5.

Window reference

Example

This example shows a simple window with a title, containing a label.

Window

Figure 4.1. Window


Source code

File: examplewindow.h

#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H

#include <hildonmm/window.h>
#include <gtkmm/label.h>

class ExampleWindow : public Hildon::Window
{
public:
  ExampleWindow();
  virtual ~ExampleWindow();

private:
  // Child widgets.
  Gtk::Label label_;
};

#endif /* _MAEMOMM_EXAMPLEWINDOW_H */

File: examplewindow.cc

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


ExampleWindow::ExampleWindow() :
  label_("Click the close button to quit.")
{
  set_title("Hildon::Window Example");

  add(label_);

  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

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

StackableWindow

The Hildon::StackableWindow widget is a stackable top-level window in the Hildon framework, derived from the Hildon::Window class. Every application has a default Hildon::WindowStack object to which each window is pushed when the show() method is called. Although with the default stack you can use the show() and hide() methods from the Gtk::Widget class on each stackable window, other window stacks can be created, and individual stackable windows must be pushed and popped onto these user-created stacks with push() and pop() respectively.

StackableWindow reference

Example

This example shows a stack of three windows with different titles. As each window is closed, the next window on the stack is made visible.

StackableWindow

Figure 4.2. StackableWindow


Source code

File: examplewindow.h

#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H

#include <hildonmm/stackable-window.h>
#include <gtkmm/buttonbox.h>
#include <hildonmm/button.h>

class ExampleWindow : public Hildon::StackableWindow
{
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 <hildonmm/stackable-window.h>
#include <hildonmm/window-stack.h>
#include <iostream>

ExampleWindow::ExampleWindow() :
  button_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
    Hildon::BUTTON_ARRANGEMENT_VERTICAL,
    "Click Me",
    "To show a new StackableWindow")
{
  set_title("Hildon::StackableWindow Example");

  button_.signal_clicked().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));

  box_.add(button_);
  add(box_);

  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_button_clicked()
{
  Hildon::StackableWindow* stackable = new Hildon::StackableWindow;
  stackable->set_title("Hildon::StackableWindow Example");
  Gtk::Label* stackable_label = Gtk::manage(
    new Gtk::Label("This is a stackable window, above the root window."));
  stackable->add(*stackable_label);
  stackable_label->show();
  stackable->show_all();
  
  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;
}