diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2024-03-16 13:12:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-16 13:12:53 +0100 |
commit | fe01776f05b1787b28b4a270d53037a3c25f4ca2 (patch) | |
tree | ec1b40606a343dfadf16ff08ae09d199df80c9e1 /platform/windows/native_menu_windows.cpp | |
parent | 68ad520da4365c866ceea42e0238b2ea24647289 (diff) | |
parent | ebb19c419804621bf2e5e08a0a77fb1d22eb1a6b (diff) | |
download | redot-engine-fe01776f05b1787b28b4a270d53037a3c25f4ca2.tar.gz |
Merge pull request #89540 from bruvzg/menu_fix_string_read
[NativeMenu] Fix changes lost due to incorrect rebase (menu goes under task bar, dark mode, item text get, docs) and check to ensure help menu is not using native menu on Windows.
Diffstat (limited to 'platform/windows/native_menu_windows.cpp')
-rw-r--r-- | platform/windows/native_menu_windows.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/platform/windows/native_menu_windows.cpp b/platform/windows/native_menu_windows.cpp index 13d1cc2a67..40a08f87df 100644 --- a/platform/windows/native_menu_windows.cpp +++ b/platform/windows/native_menu_windows.cpp @@ -141,7 +141,7 @@ RID NativeMenuWindows::create_menu() { ZeroMemory(&menu_info, sizeof(menu_info)); menu_info.cbSize = sizeof(menu_info); menu_info.fMask = MIM_STYLE; - menu_info.dwStyle = MNS_NOTIFYBYPOS | MNS_MODELESS; + menu_info.dwStyle = MNS_NOTIFYBYPOS; SetMenuInfo(md->menu, &menu_info); RID rid = menus.make_rid(md); @@ -189,7 +189,9 @@ void NativeMenuWindows::popup(const RID &p_rid, const Vector2i &p_position) { if (md->is_rtl) { flags |= TPM_LAYOUTRTL; } + SetForegroundWindow(hwnd); TrackPopupMenuEx(md->menu, flags, p_position.x, p_position.y, hwnd, nullptr); + PostMessage(hwnd, WM_NULL, 0, 0); } void NativeMenuWindows::set_interface_direction(const RID &p_rid, bool p_is_rtl) { @@ -556,9 +558,16 @@ int NativeMenuWindows::find_item_index_with_text(const RID &p_rid, const String ZeroMemory(&item, sizeof(item)); item.cbSize = sizeof(item); item.fMask = MIIM_STRING; + item.dwTypeData = nullptr; if (GetMenuItemInfoW(md->menu, i, true, &item)) { - if (String::utf16((const char16_t *)item.dwTypeData) == p_text) { - return i; + item.cch++; + Char16String str; + str.resize(item.cch); + item.dwTypeData = (LPWSTR)str.ptrw(); + if (GetMenuItemInfoW(md->menu, i, true, &item)) { + if (String::utf16((const char16_t *)str.get_data()) == p_text) { + return i; + } } } } @@ -700,8 +709,15 @@ String NativeMenuWindows::get_item_text(const RID &p_rid, int p_idx) const { ZeroMemory(&item, sizeof(item)); item.cbSize = sizeof(item); item.fMask = MIIM_STRING; + item.dwTypeData = nullptr; if (GetMenuItemInfoW(md->menu, p_idx, true, &item)) { - return String::utf16((const char16_t *)item.dwTypeData); + item.cch++; + Char16String str; + str.resize(item.cch); + item.dwTypeData = (LPWSTR)str.ptrw(); + if (GetMenuItemInfoW(md->menu, p_idx, true, &item)) { + return String::utf16((const char16_t *)str.get_data()); + } } return String(); } |