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.
This commit is contained in:
Martín Capello 2024-11-11 17:43:21 -03:00 committed by David Capello
parent 8a8a324651
commit 9ca6368088

View File

@ -153,12 +153,22 @@ bool ButtonBase::onProcessMessage(Message* msg)
}
break;
case kCheckWidget: {
// Fire onClick() event
onClick();
return true;
}
case kCheckWidget:
KeyMessage* keymsg = static_cast<KeyMessage*>(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;