There are two widgets in maemomm for text entry, both of which are inherited from gtkmm equivalents, but with extra Hildon-specific additions.
Hildon::Entry represents a single-line text entry field. It is derived from Gtk::Entry and provides additional features specific to the Hildon framework. For example, at construction of a Hildon::Entry it is possible to set a size, for example either finger or thumb height.
Hildon::TextView represents a multi-line text entry box. It is derived from Gtk::TextView and also provides additional features specific to the Hildon framework. For example, placeholder text can be set, which is only shown when the widget is not focused and is empty, but is otherwise ignored.
A Hildon::Entry is a widget that shows a single-line text entry field, enabling the user to enter freeform text. You can set the placeholder text that is shown when the widget is not focused and is empty. A Hildon::Entry is derived from a Gtk::Entry.
This example shows a simple window that contains a Hildon::Entry, a Hildon::Button and a Gtk::Label. The Hildon::Entry has placeholder text set, which disappears when text is entered into the widget. When the Hildon::Button is clicked, or the Hildon::Entry is activated, the current text in the Hildon::Entry is sent to standard output.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H
#include <hildonmm/window.h>
#include <hildonmm/button.h>
#include <hildonmm/entry.h>
#include <gtkmm/table.h>
#include <gtkmm/label.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
// Signal handlers:
void on_button_clicked();
void on_entry_activated();
// Child widgets:
Gtk::Table table_;
Hildon::Button button_;
Gtk::Label label_;
Hildon::Entry entry_;
};
#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() :
table_(2, 2),
button_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
Hildon::BUTTON_ARRANGEMENT_VERTICAL,
"Click me!",
"to print text in entry"),
label_("Hildon::Entry example"),
entry_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT)
{
set_title("Hildon::Entry example");
table_.attach(button_, 0, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
table_.attach(label_, 0, 1, 1, 2);
table_.attach(entry_, 1, 2, 1, 2);
entry_.set_placeholder("This is placeholder text");
add(table_);
button_.signal_clicked().connect(sigc::mem_fun(*this, &ExampleWindow::on_button_clicked));
entry_.signal_activate().connect(sigc::mem_fun(*this, &ExampleWindow::on_entry_activated));
show_all();
}
ExampleWindow::~ExampleWindow()
{
}
void ExampleWindow::on_button_clicked()
{
std::cout << "Button clicked. Current entry text=\"" << entry_.get_text() << "\"." << std::endl;
}
void ExampleWindow::on_entry_activated()
{
std::cout << "Entry activated. Current text=\"" << entry_.get_text() << "\"." << std::endl;
}
Hildon::TextView is the multi-line equivalent to Hildon::Entry. As with Hildon::Entry, Hildon:TextView is derived from its gtkmm equivalent, in this case Gtk::TextView. The placeholder text functionality that exists in Hildon::Entry, where text can be shown by the widget when it is empty and the widget is not focused, is also present in Hildon::TextView.
| Note | |
|---|---|
Although Hildon::TextView is derived from Gtk::TextView, Gtk::TextView::get_buffer() and Gtk::TextView::set_buffer() must never be used to get/set the buffer in this widget. Hildon::TextView::get_buffer() and Hildon::TextView::set_buffer() must be used instead. |
This example shows a simple window that contains a Hildon::TextView, a Hildon::Button and a Gtk::Label. The Hildon::TextView has placeholder text set, which disappears when text is entered into the widget. Clicking the Hildon::Button , or activating the Hildon::Entry, sends the current text in the Hildon::TextView to standard output.
File: examplewindow.h
#ifndef _MAEMOMM_EXAMPLEWINDOW_H
#define _MAEMOMM_EXAMPLEWINDOW_H
#include <hildonmm/window.h>
#include <hildonmm/button.h>
#include <hildonmm/text-view.h>
#include <gtkmm/table.h>
#include <gtkmm/label.h>
class ExampleWindow : public Hildon::Window
{
public:
ExampleWindow();
virtual ~ExampleWindow();
private:
// Signal handlers:
void on_button_clicked();
// Child widgets:
Gtk::Table table_;
Hildon::Button button_;
Gtk::Label label_;
Hildon::TextView textview_;
};
#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() :
table_(2, 2, true),
button_(Gtk::Hildon::SIZE_HALFSCREEN_WIDTH | Gtk::Hildon::SIZE_FINGER_HEIGHT,
Hildon::BUTTON_ARRANGEMENT_VERTICAL,
"Click me!",
"to print text in textview"),
label_("Hildon::TextView example")
{
set_title("Hildon::TextView example");
table_.attach(button_, 0, 2, 0, 1, Gtk::SHRINK, Gtk::SHRINK);
table_.attach(label_, 0, 1, 1, 2);
table_.attach(textview_, 1, 2, 1, 2);
textview_.set_placeholder("This is placeholder text");
add(table_);
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. Current textview text=\"" << textview_.get_buffer()->get_text() << "\"." << std::endl;
}