Code: Select all
Editbox* editbox = static_cast<Editbox*>(WindowManager::getSingleton().getWindow(widget));
editbox->subscribeEvent(Editbox::EventActivated, Event::Subscriber(&EditboxWidget::onActivated, this));
editbox->subscribeEvent(Editbox::EventDeactivated, Event::Subscriber(&EditboxWidget::onDeactivated, this));
bool EditboxWidget::onActivated(const CEGUI::EventArgs& e)
{
// Select the entire contents of the edit box when it is activated (given input focus)
Editbox* editbox = static_cast<Editbox*>(WindowManager::getSingleton().getWindow(m_widget));
editbox->setSelection(0, editbox->getText().length());
return true;
}
bool EditboxWidget::onDeactivated(const CEGUI::EventArgs& e)
{
// Unselect the contents of the edit box when it is deactivated (lost input focus)
Editbox* editbox = static_cast<Editbox*>(WindowManager::getSingleton().getWindow(m_widget));
editbox->setSelection(0, 0);
return true;
}
It works well when I tab through the widgets (that code is nearly ready for release) but when I click within the edit box this event is not activated.
It seems to me that clicking within the edit box gives it the input focus, so it should trigger the onActivated event. The workaround would be to subscribe to Editbox::EventMouseClick and if the edit box does not have the input focus then call activate() which should trigger the onActivated event. But that seems far fetched.
