21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_COCOA
30 @interface SDLMessageBoxPresenter : NSObject {
36 - (
void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(
void *)contextInfo;
39 @implementation SDLMessageBoxPresenter
57 - (
void)showAlert:(NSAlert*)alert
60 #ifdef MAC_OS_X_VERSION_10_9
61 if ([alert respondsToSelector:
@selector(beginSheetModalForWindow:completionHandler:)]) {
62 [alert beginSheetModalForWindow:nswindow completionHandler:^(NSModalResponse returnCode) {
68 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1090
69 [alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
80 clicked = [alert runModal];
84 - (
void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(
void *)contextInfo
99 NSAlert* alert = [[[NSAlert alloc] init] autorelease];
102 [alert setAlertStyle:NSAlertStyleCritical];
104 [alert setAlertStyle:NSAlertStyleWarning];
106 [alert setAlertStyle:NSAlertStyleInformational];
109 [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
110 [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
115 NSButton *
button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
117 [button setKeyEquivalent:@"\r"];
119 [button setKeyEquivalent:@"\033"];
121 [button setKeyEquivalent:@""];
125 SDLMessageBoxPresenter* presenter = [[[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window] autorelease];
127 [presenter performSelectorOnMainThread:@selector(showAlert:)
132 NSInteger clicked = presenter->clicked;
133 if (clicked >= NSAlertFirstButtonReturn) {
134 clicked -= NSAlertFirstButtonReturn;
135 *buttonid = buttons[clicked].
buttonid;
137 returnValue =
SDL_SetError(
"Did not get a valid `clicked button' id: %ld", (
long)clicked);