Editbox::EventActivated not called via mouse click [solved]

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Editbox::EventActivated not called via mouse click [solved]

Postby Rackle » Fri Jul 14, 2006 02:44

I'm subscribing to Editbox::EventActivated in order to receive a notification when an edit box gains the input focus in order to select the contents, allowing the user to quickly replace/delete that content:

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.
Last edited by Rackle on Fri Jul 14, 2006 10:50, edited 1 time in total.

User avatar
spannerman
Home away from home
Home away from home
Posts: 330
Joined: Wed Jan 12, 2005 12:06

Postby spannerman » Fri Jul 14, 2006 09:26

Are you sure the onActivated isnt getting called, but then the text selection is getting overwritten by the mouse click which would probably insert the caret at a position closest to the click?

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Fri Jul 14, 2006 10:13

Bah, I should have put a break point into onActivated() and figured out that was what is happening; onActivated() does get called when clicking.

I'm not sure how to solve this situation however.

Rackle
CEGUI Team (Retired)
Posts: 534
Joined: Mon Jan 16, 2006 11:59
Location: Montréal

Postby Rackle » Fri Jul 14, 2006 10:48

I just checked the Windows behavior and clicking into a field does not select its contents; that only happens when navigating via Tab or Shift+Tab. So I'll "fix" this problem by not providing that feature.

Cegui is selecting a word within the edit box when double-clicking and selecting the entire contents when triple clicking so that gives me all the mouse-clicking behavior I need.

User avatar
scriptkid
Home away from home
Home away from home
Posts: 1178
Joined: Wed Jan 12, 2005 12:06
Location: The Hague, The Netherlands
Contact:

Postby scriptkid » Fri Jul 14, 2006 13:30

Rackle wrote:I just checked the Windows behavior and clicking into a field does not select its contents; that only happens when navigating via Tab or Shift+Tab. So I'll "fix" this problem by not providing that feature.


I clicked a bit around, and it seems that comboboxes with an editable field do have the one-click-selects-all behaviour. For exampe your address bar, or the search box in VS. Confusing huh? :-)


Return to “Help”

Who is online

Users browsing this forum: No registered users and 14 guests