Interface Kit: Fix missing Alt key in menu shortcuts

The shortcut detection was working, just not the display of the
modifiers in the menu. I've added back the necessary code to fix
this in BMenuItem.

BWindow does the heavy lifting of preparing the keys and
modifiers. I have changes _FindShortcut() used by BMenuItem to
send the prepared modifiers back to BMenuItem.

Set the parameters raw in the constructor, they will get fixed
up in Install().

I also make sure to use the prepped version of the key and mods
in BWindow::AddShortcut() to remove the old one. This is a minor
update that eliminates an edge failure case of malformed input.

Fixes #19395 a regression from hrev58589.

Change-Id: I4333f89149ff843f92dbffbd53d58ffc2def6760
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8943
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: John Scipione <[email protected]>
This commit is contained in:
John Scipione
2025-02-07 17:00:56 +00:00
committed by waddlesplash
parent 2c7072f33c
commit 5ee786c31f
3 changed files with 23 additions and 9 deletions
+1 -1
View File
@@ -316,7 +316,7 @@ private:
BPoint AlertPosition(const BRect& frame);
virtual BMessage* ConvertToMessage(void* raw, int32 code);
void _AddShortcut(uint32 key, uint32 modifiers,
void _AddShortcut(uint32* _key, uint32* _modifiers,
BMenuItem* item);
BHandler* _DetermineTarget(BMessage* message,
BHandler* target);
+12 -4
View File
@@ -275,11 +275,13 @@ BMenuItem::SetShortcut(char shortcut, uint32 modifiers)
if (fShortcutChar != 0 && fWindow != NULL)
fWindow->RemoveShortcut(fShortcutChar, fModifiers);
fShortcutChar = shortcut;
fModifiers = (fShortcutChar != 0 ? modifiers : 0);
uint32 key = (uint32)fShortcutChar;
if (fShortcutChar != 0 && fWindow != NULL)
fWindow->_AddShortcut(fShortcutChar, fModifiers, this);
fWindow->_AddShortcut(&key, &modifiers, this);
fShortcutChar = (char)key;
fModifiers = (fShortcutChar != 0 ? modifiers : 0);
if (fSuper != NULL) {
fSuper->InvalidateLayout();
@@ -566,8 +568,14 @@ BMenuItem::Install(BWindow* window)
fWindow = window;
uint32 key = (uint32)fShortcutChar;
uint32 modifiers = fModifiers;
if (fShortcutChar != 0 && fWindow != NULL)
fWindow->_AddShortcut(fShortcutChar, fModifiers, this);
fWindow->_AddShortcut(&key, &modifiers, this);
fShortcutChar = (char)key;
fModifiers = (fShortcutChar != 0 ? modifiers : 0);
if (!Messenger().IsValid())
SetTarget(fWindow);
+10 -4
View File
@@ -99,6 +99,8 @@ public:
bool Matches(uint32 key, uint32 modifiers) const;
uint32 Key() const { return fKey; };
uint32 Modifiers() const { return fModifiers; };
BMenuItem* MenuItem() const { return fMenuItem; }
BMessage* Message() const { return fMessage; }
BHandler* Target() const { return fTarget; }
@@ -1684,14 +1686,18 @@ BWindow::PulseRate() const
//! \brief Used by BMenuItem to add its shortcut to the window.
void
BWindow::_AddShortcut(uint32 key, uint32 modifiers, BMenuItem* item)
BWindow::_AddShortcut(uint32* _key, uint32* _modifiers, BMenuItem* item)
{
Shortcut* shortcut = new(std::nothrow) Shortcut(key, modifiers, item);
Shortcut* shortcut = new(std::nothrow) Shortcut(*_key, *_modifiers, item);
if (shortcut == NULL)
return;
// removes the shortcut if it already exists!
RemoveShortcut(key, modifiers);
RemoveShortcut(shortcut->Key(), shortcut->Modifiers());
// pass the prepared key and modifiers back to caller
*_key = shortcut->Key();
*_modifiers = shortcut->Modifiers();
fShortcuts.AddItem(shortcut);
}
@@ -1715,7 +1721,7 @@ BWindow::AddShortcut(uint32 key, uint32 modifiers, BMessage* message, BHandler*
return;
// removes the shortcut if it already exists!
RemoveShortcut(key, modifiers);
RemoveShortcut(shortcut->Key(), shortcut->Modifiers());
fShortcuts.AddItem(shortcut);
}