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.
This example shows a simple window with a group of Gtk::Entry
widgets inside Hildon::Caption
containers.
File: examplewindow.h
#ifndef GTKMM_EXAMPLEWINDOW_H #define GTKMM_EXAMPLEWINDOW_H #include <hildonmm/window.h> #include <hildonmm/caption.h> #include <gtkmm.h> class ExampleWindow : public Hildon::Window { public: ExampleWindow(); virtual ~ExampleWindow(); protected: //Signal handlers: void on_menu_quit(); void on_activate(); //Child widgets: Gtk::Menu m_main; Gtk::MenuItem m_item_quit; Gtk::VBox m_box; Gtk::Entry m_entry_name; Gtk::Entry m_entry_street; Gtk::Entry m_entry_position; Gtk::Image m_icon1; Gtk::Image m_icon2; Gtk::Image m_icon3; Glib::RefPtr<Gtk::SizeGroup> m_group; }; #endif //GTKMM_EXAMPLEWINDOW_H
File: examplewindow.cc
#include "examplewindow.h" #include <gtkmm.h> #include <iostream> ExampleWindow::ExampleWindow() : m_item_quit("Quit"), m_box(3), m_icon1(Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON), m_icon2(Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON), m_icon3(Gtk::Stock::NEW, Gtk::ICON_SIZE_BUTTON) { // Add menu items to the main menu: m_main.append(m_item_quit); m_main.show_all(); set_main_menu(m_main); //Connect signal handlers: m_item_quit.signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_menu_quit) ); // Set some silly test m_entry_name.set_text("Mr. Example"); m_group = Gtk::SizeGroup::create(Gtk::SIZE_GROUP_VERTICAL); // Create the captions Hildon::Caption* caption_name = Gtk::manage(new Hildon::Caption( m_group, "Name", m_entry_name, m_icon1)); caption_name->signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_activate)); Hildon::Caption* caption_street = Gtk::manage(new Hildon::Caption( m_group, "Street", m_entry_street, m_icon2)); caption_street->signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_activate)); Hildon::Caption* caption_position = Gtk::manage(new Hildon::Caption( m_group, "Position", m_entry_position, m_icon3)); caption_position->signal_activate().connect( sigc::mem_fun(*this, &ExampleWindow::on_activate)); m_box.pack_start(*caption_name); m_box.pack_start(*caption_street); m_box.pack_start(*caption_position); add(m_box); //Make all child widgets visible, //so they will be visible when this window is shown: show_all_children(); } ExampleWindow::~ExampleWindow() { } void ExampleWindow::on_menu_quit() { hide(); } void ExampleWindow::on_activate() { std::cout << "Caption activated" << std::endl; }
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(); osso_context_t* osso_context = osso_initialize("example", "0.0.1", TRUE /* deprecated parameter */, 0 /* Use default Glib main loop context */); if(!osso_context) std::cerr << "osso_initialize() failed." << std::endl; Glib::set_application_name("Caption example"); // Create Window and set it to Program ExampleWindow window; Hildon::Program::get_instance()->add_window(window); // Begin the main application kit.run(window); osso_deinitialize(osso_context); return 0; }