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

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

Window

Hildon::Window is a top-level window in the Hildon framework. You can attach a menu to the window, either with the set_app_menu() or the set_main_menu() methods, for use with Hildon::AppMenu or Gtk::Menu 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 gtk::Label.

Figure 4.1. Window

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: 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() :
  label_("Click the close button to quit.")
{
  set_title("Hildon::Window Example");

  add(label_);

  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

StackableWindow

A Hildon::StackableWindow is a stackable top-level window in the Hildon framework, derived from Hildon::Window. Every application has a default Hildon::WindowStack to which each window is pushed when the show() method is called. Although with the default stack you may use the show() and hide() methods from Gtk::Widget on each Hildon::StackableWindow, other Hildon::WindowStacks may be created, and individual Hildon::StackableWindows 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.

Figure 4.2. StackableWindow

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