1.1 --- a/src/video/cocoa/SDL_cocoamessagebox.m Sun Jul 14 11:57:45 2013 -0700
1.2 +++ b/src/video/cocoa/SDL_cocoamessagebox.m Sun Jul 14 11:58:57 2013 -0700
1.3 @@ -29,21 +29,33 @@
1.4 #undef pixel
1.5 #endif
1.6
1.7 +#include "SDL_events.h"
1.8 +#include "SDL_timer.h"
1.9 #include "SDL_messagebox.h"
1.10 #include "SDL_cocoavideo.h"
1.11
1.12 @interface SDLMessageBoxPresenter : NSObject {
1.13 @public
1.14 NSInteger clicked;
1.15 + NSWindow *nswindow;
1.16 }
1.17 +- (id) initWithParentWindow:(SDL_Window *)window;
1.18 +- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
1.19 @end
1.20
1.21 @implementation SDLMessageBoxPresenter
1.22 -- (id)init
1.23 +- (id) initWithParentWindow:(SDL_Window *)window
1.24 {
1.25 self = [super init];
1.26 if (self) {
1.27 clicked = -1;
1.28 +
1.29 + /* Retain the NSWindow because we'll show the alert later on the main thread */
1.30 + if (window) {
1.31 + nswindow = [((SDL_WindowData *) window->driverdata)->nswindow retain];
1.32 + } else {
1.33 + nswindow = NULL;
1.34 + }
1.35 }
1.36
1.37 return self;
1.38 @@ -51,8 +63,23 @@
1.39
1.40 - (void)showAlert:(NSAlert*)alert
1.41 {
1.42 - clicked = [alert runModal];
1.43 + if (nswindow) {
1.44 + [alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
1.45 + while (clicked < 0) {
1.46 + SDL_PumpEvents();
1.47 + SDL_Delay(100);
1.48 + }
1.49 + [nswindow release];
1.50 + } else {
1.51 + clicked = [alert runModal];
1.52 + }
1.53 }
1.54 +
1.55 +- (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
1.56 +{
1.57 + clicked = returnCode;
1.58 +}
1.59 +
1.60 @end
1.61
1.62
1.63 @@ -90,7 +117,7 @@
1.64 }
1.65 }
1.66
1.67 - SDLMessageBoxPresenter* presenter = [[[SDLMessageBoxPresenter alloc] init] autorelease];
1.68 + SDLMessageBoxPresenter* presenter = [[[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window] autorelease];
1.69
1.70 [presenter performSelectorOnMainThread:@selector(showAlert:)
1.71 withObject:alert