Caption

A Hildon::Caption is a simple container widget which contains a label, one Gtk::Widget and an optional icon (usually a Gtk::Image). It is often used to group widgets together in input dialogs, in which case you should also use a Gtk::SizeGroup to ensure that the widgets are arranged appropriately.

Caption Reference

Example

This example shows a simple window with a group of Hildon::Entry widgets inside Hildon::Caption containers.

Figure 4.21. Caption

Caption

Source Code

File: examplewindow.h

#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H

#include <hildonmm/window.h>
#include <hildonmm/entry.h>
#include <hildonmm/caption.h>
#include <gtkmm.h>

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

private:
  //Signal handlers:
  void on_activate();
 
  // Child widgets:
  Gtk::VBox box_;

  Hildon::Entry entry_name_;
  Hildon::Entry entry_street_;
  Hildon::Entry entry_position_;

  Gtk::Image icon1_;
  Gtk::Image icon2_;
  Gtk::Image icon3_;

  Glib::RefPtr<Gtk::SizeGroup> group_;
};

#endif /* _MAEMOMM_EXAMPLEWINDOW_H */

File: main.cc

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

int main(int argc, char *argv[])
{
  // Initialize gtkmm:
  Gtk::Main kit(&argc, &argv);
  Hildon::init();
  
  // Create Window and set it to Program
  ExampleWindow window;
  Hildon::Program::get_instance()->add_window(window);

  // Begin the main application
  kit.run(window);

  return 0;
}

File: examplewindow.cc

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

ExampleWindow::ExampleWindow() :
  box_(false, 6), //TODO: See https://bugs.maemo.org/show_bug.cgi?id=4464 for correct spacing.
  entry_name_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH |
    Gtk::Hildon::SIZE_FINGER_HEIGHT),
  entry_street_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH |
    Gtk::Hildon::SIZE_FINGER_HEIGHT),
  entry_position_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH |
    Gtk::Hildon::SIZE_FINGER_HEIGHT),
  icon1_(Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON),
  icon2_(Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON),
  icon3_(Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON)
{
  set_title("Hildon::Caption Example");

  // A silly test:
  entry_name_.set_placeholder("Mr. Example");
  group_ = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_VERTICAL);
  
  // Create the captions:
  Hildon::Caption* caption_name = Gtk::manage(
    new Hildon::Caption(group_, "Name", entry_name_, icon1_));
  caption_name->signal_activate().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_activate));

  Hildon::Caption* caption_street = Gtk::manage(
    new Hildon::Caption(group_, "Street", entry_street_, icon2_));
  caption_street->signal_activate().connect(sigc::mem_fun(*this,
    &ExampleWindow::on_activate));
  
  Hildon::Caption* caption_position = Gtk::manage(
    new Hildon::Caption(group_, "Position", entry_position_, icon3_));
  caption_position->signal_activate().connect(
    sigc::mem_fun(*this, &ExampleWindow::on_activate));

  box_.pack_start(*caption_name, Gtk::PACK_SHRINK);
  box_.pack_start(*caption_street, Gtk::PACK_SHRINK);
  box_.pack_start(*caption_position, Gtk::PACK_SHRINK);
  add(box_);  
  
  // Make all child widgets visible,
  // so they will be visible when this window is shown:
  show_all_children();
}

ExampleWindow::~ExampleWindow()
{
}

void ExampleWindow::on_activate()
{
  std::cout << "Caption activated." << std::endl;
}