1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
/* ComboboxText Example
*
* This example creates a combobox with a single list of text strings.
* It uses the convenience class Gtk::ComboBoxText which replaces the
* deprecated Gtk::OptionMenu. A more advanced combobox example can be
* found in the <tests/combobox> subdirectory which shows you how to
* add images and use the new combobox grid mode.
*/
#include "comboboxtext.hh"
#include <gfc/gtk/box.hh>
#include <gfc/gtk/treemodel.hh>
#include <iostream>
Window::Window()
: Gtk::WidgetSignals(this)
{
set_title("ComboBoxEntry Example");
set_border_width(10);
Gtk::VBox *vbox = new Gtk::VBox;
add(*vbox);
// Gtk::ComboBoxEntry
combobox = new Gtk::ComboBoxText;
for (int i = 0; i < 6; i++)
{
String s = String::format("Item Number %i", i);
combobox->append_text(s);
}
combobox->set_active(0);
vbox->add(*combobox);
vbox->show_all();
}
Window::~Window()
{
}
bool
Window::on_delete_event(const Gdk::EventAny&)
{
Gtk::TreeIter iter;
if (combobox->get_active_iter(iter))
{
String text;
combobox->get_model()->get_value(iter, 0, text);
std::cout << "You selected: " << text << std::endl;
}
return false;
}
int main (int argc, char *argv[])
{
using namespace Main;
init(&argc, &argv);
Window window;
window.sig_destroy().connect(sigc::ptr_fun(&GFC::Main::quit));
window.show();
run();
return 0;
}
|