@@ -127,13 +127,13 @@ static void Cocoa_DeleteDevice(SDL_VideoDevice *device)
127127 device->SetWindowModal = Cocoa_SetWindowModal;
128128 device->SyncWindow = Cocoa_SyncWindow;
129129 device->CreateMenuBar = Cocoa_CreateMenuBar;
130+ device->SetWindowMenuBar = Cocoa_SetWindowMenuBar;
130131 device->CreateMenuItemAt = Cocoa_CreateMenuItemAt;
131- device->SetMenuItemChecked = Cocoa_SetMenuItemChecked;
132- device->UnSetMenuItemChecked = Cocoa_UnSetMenuItemChecked;
132+ device->SetMenuItemLabel = Cocoa_SetMenuItemLabel;
133133 device->GetMenuItemChecked = Cocoa_GetMenuItemChecked;
134+ device->SetMenuItemChecked = Cocoa_SetMenuItemChecked;
134135 device->GetMenuItemEnabled = Cocoa_GetMenuItemEnabled;
135- device->EnableMenuItem = Cocoa_EnableMenuItem;
136- device->DisableMenuItem = Cocoa_DisableMenuItem;
136+ device->SetMenuItemEnabled = Cocoa_SetMenuItemEnabled;
137137 device->DestroyMenuItem = Cocoa_DestroyMenuItem;
138138
139139#ifdef SDL_VIDEO_OPENGL_CGL
@@ -339,20 +339,6 @@ void SDL_NSLog(const char *prefix, const char *text)
339339 }
340340}
341341
342-
343-
344- @interface PlatformMenuData : NSObject {
345- @public
346- Uint16 user_event_type;
347- NSMenu *menu;
348- NSMenuItem *menu_item;
349- }
350-
351- - (void ) Cocoa_PlatformMenuData_MenuButtonClicked : (id )sender ;
352-
353- @end
354-
355-
356342@implementation PlatformMenuData
357343
358344- (void ) Cocoa_PlatformMenuData_MenuButtonClicked : (id )sender ;{
@@ -366,17 +352,10 @@ - (void) Cocoa_PlatformMenuData_MenuButtonClicked: (id)sender;{
366352
367353@end
368354
369-
370-
371-
372-
373-
374-
375355bool Cocoa_CreateMenuBar (SDL_MenuBar *menu_bar)
376356{
377357 PlatformMenuData* platform_menu =[PlatformMenuData new ];
378358 platform_menu->menu = [NSMenu new ];
379- [NSApp setMainMenu: platform_menu->menu];
380359
381360 NSMenuItem *appMenuItem = [NSMenuItem new ];
382361 NSMenu *appMenu = [NSMenu new ];
@@ -391,6 +370,19 @@ bool Cocoa_CreateMenuBar(SDL_MenuBar *menu_bar)
391370 return true ;
392371}
393372
373+ bool Cocoa_SetWindowMenuBar (SDL_MenuBar *menu_bar)
374+ {
375+ // We don't actually set the menubar until the window is in focus
376+ if (!menu_bar->window ->keyboard_focus ) {
377+ return true ;
378+ }
379+
380+ PlatformMenuData* platform_data = (__bridge PlatformMenuData*)menu_bar->common .item_common .platform_data ;
381+ [NSApp setMainMenu: platform_data->menu];
382+
383+ return true ;
384+ }
385+
394386bool Cocoa_CreateMenuItemAt (SDL_MenuItem *menu_item, size_t index, const char *name, Uint16 event_type)
395387{
396388 PlatformMenuData* platform_data = [PlatformMenuData new ];
@@ -400,7 +392,7 @@ bool Cocoa_CreateMenuItemAt(SDL_MenuItem *menu_item, size_t index, const char *n
400392 PlatformMenuData* parent_platform_data = (__bridge id _Nullable)(menu_item->common .parent ->common .platform_data );
401393 NSString * name_ns = [NSString stringWithUTF8String: name];
402394
403- if (menu_item->common .type == SDL_MENU ) {
395+ if (menu_item->common .type == SDL_MENUITEM_SUBMENU ) {
404396 platform_data->menu = [[NSMenu alloc ] initWithTitle: name_ns];
405397 [platform_data->menu setAutoenablesItems: false ];
406398 platform_data->menu_item = [NSMenuItem new ];
@@ -415,7 +407,7 @@ bool Cocoa_CreateMenuItemAt(SDL_MenuItem *menu_item, size_t index, const char *n
415407 [platform_data->menu_item setTarget: platform_data];
416408 [platform_data->menu_item setEnabled: true ];
417409
418- if ((menu_item->common .parent ->common .type == SDL_MENUBAR ) && (menu_item->common .type != SDL_MENU )) {
410+ if ((menu_item->common .parent ->common .type == SDL_MENUITEM_MENUBAR ) && (menu_item->common .type != SDL_MENUITEM_SUBMENU )) {
419411 NSMenu * app_menu = [[parent_platform_data->menu itemAtIndex: (NSInteger )0 ] submenu ];
420412 [app_menu addItem: platform_data->menu_item];
421413
@@ -426,20 +418,11 @@ bool Cocoa_CreateMenuItemAt(SDL_MenuItem *menu_item, size_t index, const char *n
426418 return true ;
427419}
428420
429-
430- bool Cocoa_SetMenuItemChecked (SDL_MenuItem *menu_item)
421+ bool Cocoa_SetMenuItemLabel (SDL_MenuItem *menu_item, const char *label)
431422{
423+ NSString * label_ns = [NSString stringWithUTF8String: label];
432424 PlatformMenuData* platform_data = (__bridge PlatformMenuData*)menu_item->common .platform_data ;
433- [platform_data->menu_item setState: NSControlStateValueOn ];
434- [platform_data->menu update ];
435- return true ;
436- }
437-
438- bool Cocoa_UnSetMenuItemChecked (SDL_MenuItem *menu_item)
439- {
440- PlatformMenuData* platform_data = (__bridge PlatformMenuData*)menu_item->common .platform_data ;
441- [platform_data->menu_item setState: NSControlStateValueOff ];
442- [platform_data->menu update ];
425+ [platform_data->menu_item setTitle: label_ns];
443426 return true ;
444427}
445428
@@ -451,25 +434,26 @@ bool Cocoa_GetMenuItemChecked(SDL_MenuItem *menu_item, bool *checked)
451434 return true ;
452435}
453436
454- bool Cocoa_GetMenuItemEnabled (SDL_MenuItem *menu_item, bool *enabled )
437+ bool Cocoa_SetMenuItemChecked (SDL_MenuItem *menu_item, bool checked )
455438{
439+ NSControlStateValue flag = checked ? NSControlStateValueOn : NSControlStateValueOff ;
456440 PlatformMenuData* platform_data = (__bridge PlatformMenuData*)menu_item->common .platform_data ;
457- *enabled = [platform_data->menu_item isEnabled ];
441+ [platform_data->menu_item setState: flag];
442+ [platform_data->menu update ];
458443 return true ;
459444}
460445
461- bool Cocoa_EnableMenuItem (SDL_MenuItem *menu_item)
446+ bool Cocoa_GetMenuItemEnabled (SDL_MenuItem *menu_item, bool *enabled )
462447{
463448 PlatformMenuData* platform_data = (__bridge PlatformMenuData*)menu_item->common .platform_data ;
464- [platform_data->menu_item setEnabled: true ];
465- [platform_data->menu update ];
449+ *enabled = [platform_data->menu_item isEnabled ];
466450 return true ;
467451}
468452
469- bool Cocoa_DisableMenuItem (SDL_MenuItem *menu_item)
453+ bool Cocoa_SetMenuItemEnabled (SDL_MenuItem *menu_item, bool enabled )
470454{
471455 PlatformMenuData* platform_data = (__bridge PlatformMenuData*)menu_item->common .platform_data ;
472- [platform_data->menu_item setEnabled: false ];
456+ [platform_data->menu_item setEnabled: enabled ];
473457 [platform_data->menu update ];
474458 return true ;
475459}
0 commit comments