Fix handling keys also used as accelerators in wxMSW wxComboBox
wxComboBox::MSWShouldPreProcessMessage() didn't take into account many keys that must be handled in wxComboBox even if they're used as accelerators, including plain (i.e. without Ctrl modifier) Delete, Home and End that are used by the embedded text control, if there is one. Fix this by reusing wxTextCtrl::MSWShouldPreProcessMessage() which already handled these keys correctly, by moving it to wxTextEntry, which can be used from both classes. Also add a check for wxCB_READONLY to prevent overriding the accelerators using the keys that the combobox doesn't need when there is no text control in it. Closes #19227.
This commit is contained in:
@@ -1072,4 +1072,74 @@ bool wxTextEntry::ClickDefaultButtonIfPossible()
|
||||
wxWindow::MSWGetDefaultButtonFor(GetEditableWindow()));
|
||||
}
|
||||
|
||||
bool wxTextEntry::MSWShouldPreProcessMessage(WXMSG* msg) const
|
||||
{
|
||||
// check for our special keys here: if we don't do it and the parent frame
|
||||
// uses them as accelerators, they wouldn't work at all, so we disable
|
||||
// usual preprocessing for them
|
||||
if ( msg->message == WM_KEYDOWN )
|
||||
{
|
||||
const WPARAM vkey = msg->wParam;
|
||||
if ( HIWORD(msg->lParam) & KF_ALTDOWN )
|
||||
{
|
||||
// Alt-Backspace is accelerator for "Undo"
|
||||
if ( vkey == VK_BACK )
|
||||
return false;
|
||||
}
|
||||
else // no Alt
|
||||
{
|
||||
// we want to process some Ctrl-foo and Shift-bar but no key
|
||||
// combinations without either Ctrl or Shift nor with both of them
|
||||
// pressed
|
||||
const int ctrl = wxIsCtrlDown(),
|
||||
shift = wxIsShiftDown();
|
||||
switch ( ctrl + shift )
|
||||
{
|
||||
default:
|
||||
wxFAIL_MSG( wxT("how many modifiers have we got?") );
|
||||
wxFALLTHROUGH;
|
||||
|
||||
case 0:
|
||||
switch ( vkey )
|
||||
{
|
||||
case VK_DELETE:
|
||||
case VK_HOME:
|
||||
case VK_END:
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
// either Ctrl or Shift pressed
|
||||
if ( ctrl )
|
||||
{
|
||||
switch ( vkey )
|
||||
{
|
||||
case 'A':
|
||||
case 'C':
|
||||
case 'V':
|
||||
case 'X':
|
||||
case VK_INSERT:
|
||||
case VK_DELETE:
|
||||
case VK_HOME:
|
||||
case VK_END:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else // Shift is pressed
|
||||
{
|
||||
if ( vkey == VK_INSERT || vkey == VK_DELETE )
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX
|
||||
|
||||
Reference in New Issue
Block a user