src/video/cocoa/SDL_cocoamessagebox.m
changeset 6848 478ecc8a58b3
parent 6836 b0ca1571caf3
child 6885 700f1b25f77f
     1.1 --- a/src/video/cocoa/SDL_cocoamessagebox.m	Mon Feb 11 17:25:58 2013 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoamessagebox.m	Mon Feb 11 17:39:52 2013 -0800
     1.3 @@ -39,38 +39,40 @@
     1.4  {
     1.5      Cocoa_RegisterApp();
     1.6  
     1.7 -    @autoreleasepool {
     1.8 -        NSAlert* alert = [[NSAlert alloc] init];
     1.9 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.10  
    1.11 -        if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    1.12 -            [alert setAlertStyle:NSCriticalAlertStyle];
    1.13 -        } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    1.14 -            [alert setAlertStyle:NSWarningAlertStyle];
    1.15 +    NSAlert* alert = [[NSAlert alloc] init];
    1.16 +
    1.17 +    if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    1.18 +        [alert setAlertStyle:NSCriticalAlertStyle];
    1.19 +    } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    1.20 +        [alert setAlertStyle:NSWarningAlertStyle];
    1.21 +    } else {
    1.22 +        [alert setAlertStyle:NSInformationalAlertStyle];
    1.23 +    }
    1.24 +
    1.25 +    [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    1.26 +    [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    1.27 +
    1.28 +    const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    1.29 +    int i;
    1.30 +    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    1.31 +        NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
    1.32 +        if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    1.33 +            [button setKeyEquivalent:@"\r"];
    1.34 +        } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    1.35 +            [button setKeyEquivalent:@"\033"];
    1.36          } else {
    1.37 -            [alert setAlertStyle:NSInformationalAlertStyle];
    1.38 +            [button setKeyEquivalent:@""];
    1.39          }
    1.40 +    }
    1.41  
    1.42 -        [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    1.43 -        [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    1.44 +    NSInteger clicked = [alert runModal];
    1.45 +    clicked -= NSAlertFirstButtonReturn;
    1.46 +    *buttonid = buttons[clicked].buttonid;
    1.47 +    [alert release];
    1.48  
    1.49 -        const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    1.50 -        int i;
    1.51 -        for (i = 0; i < messageboxdata->numbuttons; ++i) {
    1.52 -            NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
    1.53 -            if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    1.54 -                [button setKeyEquivalent:@"\r"];
    1.55 -            } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    1.56 -                [button setKeyEquivalent:@"\033"];
    1.57 -            } else {
    1.58 -                [button setKeyEquivalent:@""];
    1.59 -            }
    1.60 -        }
    1.61 -
    1.62 -        NSInteger clicked = [alert runModal];
    1.63 -        clicked -= NSAlertFirstButtonReturn;
    1.64 -        *buttonid = buttons[clicked].buttonid;
    1.65 -        [alert release];
    1.66 -    }
    1.67 +    [pool release];
    1.68  
    1.69      return 0;
    1.70  }