Provide ttext_ with a text_changed event to be able to grab...

...the text of a textbox after it got changed by keystrokes.
This commit is contained in:
Jörg Hinrichs 2009-07-14 19:16:52 +00:00
parent 5a03201363
commit 6093d40a23
2 changed files with 23 additions and 3 deletions

View file

@ -203,6 +203,10 @@ void ttext_::key_press(tevent_handler& /*event*/,
handle_key_default(handled, key, modifier, unicode);
}
if(text_changed_callback_) {
text_changed_callback_(this, this->text());
}
}
void ttext_::set_maximum_length(const size_t maximum_length)

View file

@ -38,9 +38,8 @@ public:
state_(ENABLED),
text_(),
selection_start_(0),
selection_length_(0),
key_press_callback_()
{
selection_length_(0),
key_press_callback_() {
}
/** Inherited from tevent_executor. */
@ -101,6 +100,13 @@ public:
key_press_callback_ = cb;
}
/** Set the text_changed callback. */
void set_text_changed_callback(
boost::function< void (ttext_* textbox, const std::string text) > cb)
{
text_changed_callback_ = cb;
}
protected:
/**
@ -409,6 +415,16 @@ protected:
* - The unicode for the pressed key.
*/
boost::function< bool (twidget*, SDLKey, SDLMod, Uint16) > key_press_callback_;
/**
* Text changed callback.
*
* This callback is called in key_press after the key_press event has been
* handled by the control. The parameters to the function are:
* - The widget invoking the callback
* - The new text of the textbox.
*/
boost::function< void (ttext_* textbox, const std::string text) > text_changed_callback_;
};
} // namespace gui2