Ensure that Enter key presses are never stolen from wxButton in wxMSW.
This commit fixes the following bug: when an in-place editor control containing an embedded button was used in wxDataViewCtrl, pressing Enter on the button would close the editor, accepting changes, instead as (generic) wxDataViewCtrl intercepts WXK_RETURN in its EVT_CHAR_HOOK handler. To prevent this from happening, wxButton now handles EVT_CHAR_HOOK itself and never lets the parent window intercept it if it's for WXK_RETURN. To ensure that normal wxEVT_KEY_DOWN and wxEVT_CHAR are still generated in this case, wxButton handler calls the new wxKeyEvent::DoAllowNextEvent() method that was added to allow suppressing EVT_CHAR_HOOK only, without affecting the subsequent events. DoAllowNextEvent() is currently only used in wxMSW but support for it was also added to wxGTK and (both) wxOSX ports. See #9102. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69984 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -62,6 +62,10 @@
|
||||
// macros
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
BEGIN_EVENT_TABLE(wxButton, wxButtonBase)
|
||||
EVT_CHAR_HOOK(wxButton::OnCharHook)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// ============================================================================
|
||||
// implementation
|
||||
// ============================================================================
|
||||
@@ -370,6 +374,25 @@ void wxButton::Command(wxCommandEvent & event)
|
||||
// event/message handlers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxButton::OnCharHook(wxKeyEvent& event)
|
||||
{
|
||||
// We want to ensure that the button always processes Enter key events
|
||||
// itself, even if it's inside some control that normally takes over them
|
||||
// (this happens when the button is part of an in-place editor control for
|
||||
// example).
|
||||
if ( event.GetKeyCode() == WXK_RETURN )
|
||||
{
|
||||
// We should ensure that subsequent key events are still generated even
|
||||
// if we did handle EVT_CHAR_HOOK (normally this would suppress their
|
||||
// generation).
|
||||
event.DoAllowNextEvent();
|
||||
}
|
||||
else
|
||||
{
|
||||
event.Skip();
|
||||
}
|
||||
}
|
||||
|
||||
bool wxButton::MSWCommand(WXUINT param, WXWORD WXUNUSED(id))
|
||||
{
|
||||
bool processed = false;
|
||||
|
Reference in New Issue
Block a user