From 9ca6368088b876543ff60b85bb1569bdc26a976b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Capello?= Date: Mon, 11 Nov 2024 17:43:21 -0300 Subject: [PATCH] Fix button's kKeyUpMessage handling Now the checkbox button skips the kKeyUpMessage when the key being depressed is not the space key and is not the associated mnemonic key. Before this change, for instance, if a checkbox received the focus by using the Tab key, the kKeyUpMessage (of the Tab key) was intercepted by the checkbox and triggered the onClick() event. --- src/ui/button.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ui/button.cpp b/src/ui/button.cpp index f7222a4b7..808aab5a6 100644 --- a/src/ui/button.cpp +++ b/src/ui/button.cpp @@ -153,12 +153,22 @@ bool ButtonBase::onProcessMessage(Message* msg) } break; - case kCheckWidget: { - // Fire onClick() event - onClick(); - return true; - } - + case kCheckWidget: + KeyMessage* keymsg = static_cast(msg); + KeyScancode scancode = keymsg->scancode(); + const bool mnemonicPressed = + (mnemonic() && + (!mnemonicRequiresModifiers() || + msg->altPressed() || + msg->cmdPressed()) && + isMnemonicPressed(keymsg)); + // Fire the onClick() event only if the user pressed space or + // Alt+the underscored letter of the checkbox label. + if (scancode == kKeySpace || mnemonicPressed) { + onClick(); + return true; + } + break; } } break;