From 3459aaa9d15466292ee5fc7d2497b2d3894da0fe Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 15 Mar 2024 09:18:48 +0200 Subject: [PATCH] Fix NativeMenu layout direction on macOS, add extra check for Windows menu. --- platform/macos/native_menu_macos.mm | 2 +- platform/windows/native_menu_windows.cpp | 4 ++-- scene/gui/popup_menu.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/platform/macos/native_menu_macos.mm b/platform/macos/native_menu_macos.mm index f00527767c6..250b64dc046 100644 --- a/platform/macos/native_menu_macos.mm +++ b/platform/macos/native_menu_macos.mm @@ -271,7 +271,7 @@ void NativeMenuMacOS::set_interface_direction(const RID &p_rid, bool p_is_rtl) { MenuData *md = menus.get_or_null(p_rid); ERR_FAIL_NULL(md); - md->menu.userInterfaceLayoutDirection = p_is_rtl ? NSUserInterfaceLayoutDirectionLeftToRight : NSUserInterfaceLayoutDirectionRightToLeft; + md->menu.userInterfaceLayoutDirection = p_is_rtl ? NSUserInterfaceLayoutDirectionRightToLeft : NSUserInterfaceLayoutDirectionLeftToRight; } void NativeMenuMacOS::set_popup_open_callback(const RID &p_rid, const Callable &p_callback) { diff --git a/platform/windows/native_menu_windows.cpp b/platform/windows/native_menu_windows.cpp index eea30cab9ab..84e3611e914 100644 --- a/platform/windows/native_menu_windows.cpp +++ b/platform/windows/native_menu_windows.cpp @@ -289,7 +289,7 @@ int NativeMenuWindows::add_item(const RID &p_rid, const String &p_label, const C item.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA; item.fType = MFT_STRING; item.dwItemData = (ULONG_PTR)item_data; - item.dwTypeData = (LPWSTR)label.ptrw(); + item.dwTypeData = label.ptrw() ? (LPWSTR)label.ptrw() : L""; if (!InsertMenuItemW(md->menu, p_index, true, &item)) { memdelete(item_data); @@ -949,7 +949,7 @@ void NativeMenuWindows::set_item_text(const RID &p_rid, int p_idx, const String item.cbSize = sizeof(item); item.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA; if (GetMenuItemInfoW(md->menu, p_idx, true, &item)) { - item.dwTypeData = (LPWSTR)label.ptrw(); + item.dwTypeData = label.ptrw() ? (LPWSTR)label.ptrw() : L""; SetMenuItemInfoW(md->menu, p_idx, true, &item); } } diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 25d999851bf..56346f5edcc 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -92,7 +92,7 @@ RID PopupMenu::bind_global_menu() { NativeMenu *nmenu = NativeMenu::get_singleton(); - if (system_menu_id != NativeMenu::INVALID_MENU_ID) { + if (system_menu_id != NativeMenu::INVALID_MENU_ID && nmenu->has_system_menu(system_menu_id)) { if (system_menus.has(system_menu_id)) { WARN_PRINT(vformat("Attempting to bind PopupMenu to the system menu %s, but another menu is already bound to it. This menu: %s, current menu: %s", nmenu->get_system_menu_name(system_menu_id), get_description(), system_menus[system_menu_id]->get_description())); global_menu = nmenu->create_menu();