@@ -360,6 +360,7 @@ bool Cocoa_CreateMenuBar(SDL_MenuBar *menu_bar)
360360 app_menu->common .type = SDL_MENUITEM_SUBMENU;
361361 app_menu->common .enabled = true ;
362362 app_menu->common .parent = (SDL_MenuItem*)menu_bar;
363+ app_menu->common .menu_bar = menu_bar;
363364
364365 PlatformMenuData* app_menu_platform_data = [PlatformMenuData new ];
365366 app_menu->common .platform_data = (void *)CFBridgingRetain (app_menu_platform_data);
@@ -372,6 +373,7 @@ bool Cocoa_CreateMenuBar(SDL_MenuBar *menu_bar)
372373 [platform_menu->menu addItem: app_menu_platform_data->menu_item];
373374
374375 menu_bar->common .item_common .platform_data = (void *)CFBridgingRetain (platform_menu);
376+ menu_bar->app_menu = app_menu;
375377
376378 return true ;
377379}
@@ -398,6 +400,11 @@ bool Cocoa_SetWindowMenuBar(SDL_Window *window, SDL_MenuBar *menu_bar)
398400
399401bool Cocoa_CreateMenuItemAt (SDL_MenuItem *menu_item, size_t index, const char *name, Uint16 event_type)
400402{
403+ if ((menu_item->common .parent ->common .type == SDL_MENUITEM_MENUBAR) && (menu_item->common .type != SDL_MENUITEM_SUBMENU)) {
404+ SDL_SetError (" No top level Checkables or Buttons on this platform" );
405+ return false ;
406+ }
407+
401408 PlatformMenuData* platform_data = [PlatformMenuData new ];
402409 menu_item->common .platform_data = (void *)CFBridgingRetain (platform_data);
403410 platform_data->user_event_type = event_type;
@@ -420,14 +427,7 @@ bool Cocoa_CreateMenuItemAt(SDL_MenuItem *menu_item, size_t index, const char *n
420427 [platform_data->menu_item setAction: @selector (Cocoa_PlatformMenuData_MenuButtonClicked: )];
421428 [platform_data->menu_item setTarget: platform_data];
422429 [platform_data->menu_item setEnabled: true ];
423-
424- if ((menu_item->common .parent ->common .type == SDL_MENUITEM_MENUBAR) && (menu_item->common .type != SDL_MENUITEM_SUBMENU)) {
425- NSMenu * app_menu = [[parent_platform_data->menu itemAtIndex: (NSInteger )0 ] submenu ];
426- [app_menu addItem: platform_data->menu_item];
427-
428- } else {
429- [parent_platform_data->menu insertItem: platform_data->menu_item atIndex: (NSInteger )index];
430- }
430+ [parent_platform_data->menu insertItem: platform_data->menu_item atIndex: (NSInteger )index];
431431 }
432432 return true ;
433433}
0 commit comments