Antonio Coralles wrote:
Antonio
Coralles wrote:
I just was thinking about the most elegant
way of restricting the chars
a user can enter into a Gtk::Entry. At first i thought I should do that
by overriding on_changed() but then, after looking at the dokumentation
for Gtk::Editable the functions
virtual void insert_text_vfunc (const Glib::ustring& text,
int& position)
virtual void on_insert_text (const Glib::ustring& text, int*
position)
caught my attention. The problem is that these functions are
completeley
undocumented - especially I don't understand what i should do with
int&
/ int* position - what happens when i change the value of
position/*position ? Are these functions at least suitable for my
purpose ? Should i call [when overriding] the base class routines if i
want a char to be accepted and avoid that if i don't want that ?
Ok, after experimenting a bit I achieved what I wanted to do by
overriding insert_text_vfunc. text is the text which would be inserted
and position the position where inserting starts - which can be
modified through &. If I want the insertion to take place I call
the base class insert_text_vfunc. Eventually I can pass a modified
string to that method ...
So the question that remains is what on_insert_text is for and why does
it use int* instead of int& ?
Antonio
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
Hello Antonio,
I needed a Gtk::Entry object that behaved the same way, so I derived a
class I called "MaskedEntry." from Gtk::Entry. I added a gchar
pointer as a protected class variable, and as a formal paramter to the
contructor I passed a pointer to a gchar string containing all the
characters that I wanted to mask out of the entry. The constructor
makes a copy of this string with g_strdup. My class overrides the
"on_key_press_event" such that it uses gdk_keyval_to_unicode on the
event->keyval argument to convert it to a unicode value and then
uses strchr to see if that character is in the mask string. If it is
not, Gtk::Entry::on_key_press_event( event ) is called, passing the
original argument along to the framework. If, however, the character
does exist in the mask string, I put up a Gtk::MessageDialog informing
the user that the input character is not allowed as valid entry and
return without calling GtK::on_key_press_event.
Because all this happens before any characters are inserted into the
text of the entry, it is neat and clean.
--
Robert
L Caryl Jr
Fiscal
Systems, Inc.
256-772-8920 Ext. 108
This
email message may contain privileged or confidential information. If
you are not the recipient, you may not disclose, use, disseminate,
distribute, copy or rely on this message or attachment in any way. If
you received this email message in error, please return by forwarding
the message and its attachment to the sender and then delete the
message and its attachment from your computer. Fiscal Systems, Inc.
and its affiliates do not accept liability for any errors, omissions,
corruption or virus in the contents of this message or any
attachments that arise as a result of e-mail transmission.
|