Browse Source

Fix NativeMenu layout direction on macOS, add extra check for Windows menu.

bruvzg 1 year ago
parent
commit
3459aaa9d1

+ 1 - 1
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);
 	MenuData *md = menus.get_or_null(p_rid);
 	ERR_FAIL_NULL(md);
 	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) {
 void NativeMenuMacOS::set_popup_open_callback(const RID &p_rid, const Callable &p_callback) {

+ 2 - 2
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.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA;
 	item.fType = MFT_STRING;
 	item.fType = MFT_STRING;
 	item.dwItemData = (ULONG_PTR)item_data;
 	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)) {
 	if (!InsertMenuItemW(md->menu, p_index, true, &item)) {
 		memdelete(item_data);
 		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.cbSize = sizeof(item);
 	item.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA;
 	item.fMask = MIIM_FTYPE | MIIM_STRING | MIIM_DATA;
 	if (GetMenuItemInfoW(md->menu, p_idx, true, &item)) {
 	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);
 		SetMenuItemInfoW(md->menu, p_idx, true, &item);
 	}
 	}
 }
 }

+ 1 - 1
scene/gui/popup_menu.cpp

@@ -92,7 +92,7 @@ RID PopupMenu::bind_global_menu() {
 
 
 	NativeMenu *nmenu = NativeMenu::get_singleton();
 	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)) {
 		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()));
 			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();
 			global_menu = nmenu->create_menu();