showAlert: legacy OS compatibility fix

This commit is contained in:
Joshua Root
2025-01-03 03:40:34 +11:00
committed by Sam Lantinga
parent 123b967a99
commit ed0eb7714a
+20 -1
View File
@@ -33,6 +33,9 @@
NSWindow *nswindow; NSWindow *nswindow;
} }
- (id)initWithParentWindow:(SDL_Window *)window; - (id)initWithParentWindow:(SDL_Window *)window;
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
- (void)alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
#endif
@end @end
@implementation SDLMessageBoxPresenter @implementation SDLMessageBoxPresenter
@@ -56,16 +59,32 @@
- (void)showAlert:(NSAlert*)alert - (void)showAlert:(NSAlert*)alert
{ {
if (nswindow) { if (nswindow) {
[alert beginSheetModalForWindow:nswindow #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1090
if ([alert respondsToSelector:@selector(beginSheetModalForWindow:completionHandler:)]) {
[alert beginSheetModalForWindow:nswindow
completionHandler:^(NSModalResponse returnCode) { completionHandler:^(NSModalResponse returnCode) {
[NSApp stopModalWithCode:returnCode]; [NSApp stopModalWithCode:returnCode];
}]; }];
} else
#endif
{
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
[alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
#endif
}
clicked = [NSApp runModalForWindow:nswindow]; clicked = [NSApp runModalForWindow:nswindow];
nswindow = nil; nswindow = nil;
} else { } else {
clicked = [alert runModal]; clicked = [alert runModal];
} }
} }
#if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
{
[NSApp stopModalWithCode:returnCode];
}
#endif
@end @end