How do I validate/limit/filter the input to a Gtk::Entry?



I'm trying to translate a sample program from GTK FAQ
	6.15. How do I validate/limit/filter the input to a GtkEntry?
	http://www.gtk.org/faq/#AEN843
to GTKmm.

But it does not work and I don't know why. I've attached my program.
Could you help me, please?

Regards
Tometzky
-- 
...although Eating Honey was a very good thing to do, there was a
moment just before you began to eat it which was better than when you
were...
                                                      Winnie the Pooh
#include <gtkmm.h>

class AlphaUpperEntry : public Gtk::Entry
{
public:
	AlphaUpperEntry();
protected:
	virtual void insert_text_handler(Glib::ustring const& text,int* position);
	sigc::connection insert_text_connection;
};

AlphaUpperEntry::AlphaUpperEntry()
{
	insert_text_connection = signal_insert_text().connect(
		sigc::mem_fun(*this, &AlphaUpperEntry::insert_text_handler)
	);
}

void AlphaUpperEntry::insert_text_handler(Glib::ustring const& text, int* position)
{
	Glib::ustring result; result.reserve(text.size());
	
	for ( Glib::ustring::const_iterator it = text.begin(); it != text.end(); it++ ) {
		if ( Glib::Unicode::isalpha(*it) ) {
			result += Glib::Unicode::toupper(*it);
		}
	}
	
	if ( ! result.empty() ) {
		insert_text_connection.block();
		insert_text(result, result.size(), *position);
		insert_text_connection.unblock();
	}
	
	signal_insert_text().emission_stop();
}

int main(int argc, char* argv[])
{
	Gtk::Main kit(argc, argv);

	AlphaUpperEntry entry;
	
	Gtk::Window window;
	window.set_title("AlphaUpperEntry");
	window.add(entry);
	window.show_all();
	kit.run(window);
	
	return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]