1.1 --- a/src/video/cocoa/SDL_cocoamessagebox.m Mon Apr 22 18:14:26 2013 -0700
1.2 +++ b/src/video/cocoa/SDL_cocoamessagebox.m Mon Apr 22 18:14:32 2013 -0700
1.3 @@ -32,6 +32,29 @@
1.4 #include "SDL_messagebox.h"
1.5 #include "SDL_cocoavideo.h"
1.6
1.7 +@interface SDLMessageBoxPresenter : NSObject {
1.8 +@public
1.9 + NSInteger clicked;
1.10 +}
1.11 +@end
1.12 +
1.13 +@implementation SDLMessageBoxPresenter
1.14 +- (id)init
1.15 +{
1.16 + self = [super init];
1.17 + if (self) {
1.18 + clicked = -1;
1.19 + }
1.20 +
1.21 + return self;
1.22 +}
1.23 +
1.24 +- (void)showAlert:(NSAlert*)alert
1.25 +{
1.26 + clicked = [alert runModal];
1.27 +}
1.28 +@end
1.29 +
1.30
1.31 /* Display a Cocoa message box */
1.32 int
1.33 @@ -41,7 +64,7 @@
1.34
1.35 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
1.36
1.37 - NSAlert* alert = [[NSAlert alloc] init];
1.38 + NSAlert* alert = [[[NSAlert alloc] init] autorelease];
1.39
1.40 if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
1.41 [alert setAlertStyle:NSCriticalAlertStyle];
1.42 @@ -67,14 +90,27 @@
1.43 }
1.44 }
1.45
1.46 - NSInteger clicked = [alert runModal];
1.47 - clicked -= NSAlertFirstButtonReturn;
1.48 - *buttonid = buttons[clicked].buttonid;
1.49 - [alert release];
1.50 + SDLMessageBoxPresenter* presenter = [[[SDLMessageBoxPresenter alloc] init] autorelease];
1.51 +
1.52 + [presenter performSelectorOnMainThread:@selector(showAlert:)
1.53 + withObject:alert
1.54 + waitUntilDone:YES];
1.55 +
1.56 + int returnValue = 0;
1.57 + NSInteger clicked = presenter->clicked;
1.58 + if (clicked >= NSAlertFirstButtonReturn)
1.59 + {
1.60 + clicked -= NSAlertFirstButtonReturn;
1.61 + *buttonid = buttons[clicked].buttonid;
1.62 + }
1.63 + else
1.64 + {
1.65 + returnValue = SDL_SetError("Did not get a valid `clicked button' id: %d", clicked);
1.66 + }
1.67
1.68 [pool release];
1.69
1.70 - return 0;
1.71 + return returnValue;
1.72 }
1.73
1.74 #endif /* SDL_VIDEO_DRIVER_COCOA */