src/video/cocoa/SDL_cocoamessagebox.m
changeset 6848 478ecc8a58b3
parent 6836 b0ca1571caf3
child 6885 700f1b25f77f
equal deleted inserted replaced
6847:c0fa29d3fade 6848:478ecc8a58b3
    37 int
    37 int
    38 Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
    38 Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
    39 {
    39 {
    40     Cocoa_RegisterApp();
    40     Cocoa_RegisterApp();
    41 
    41 
    42     @autoreleasepool {
    42     NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    43         NSAlert* alert = [[NSAlert alloc] init];
       
    44 
    43 
    45         if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    44     NSAlert* alert = [[NSAlert alloc] init];
    46             [alert setAlertStyle:NSCriticalAlertStyle];
    45 
    47         } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    46     if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    48             [alert setAlertStyle:NSWarningAlertStyle];
    47         [alert setAlertStyle:NSCriticalAlertStyle];
       
    48     } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
       
    49         [alert setAlertStyle:NSWarningAlertStyle];
       
    50     } else {
       
    51         [alert setAlertStyle:NSInformationalAlertStyle];
       
    52     }
       
    53 
       
    54     [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
       
    55     [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
       
    56 
       
    57     const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
       
    58     int i;
       
    59     for (i = 0; i < messageboxdata->numbuttons; ++i) {
       
    60         NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
       
    61         if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
       
    62             [button setKeyEquivalent:@"\r"];
       
    63         } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
       
    64             [button setKeyEquivalent:@"\033"];
    49         } else {
    65         } else {
    50             [alert setAlertStyle:NSInformationalAlertStyle];
    66             [button setKeyEquivalent:@""];
    51         }
    67         }
       
    68     }
    52 
    69 
    53         [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
    70     NSInteger clicked = [alert runModal];
    54         [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
    71     clicked -= NSAlertFirstButtonReturn;
       
    72     *buttonid = buttons[clicked].buttonid;
       
    73     [alert release];
    55 
    74 
    56         const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    75     [pool release];
    57         int i;
       
    58         for (i = 0; i < messageboxdata->numbuttons; ++i) {
       
    59             NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
       
    60             if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
       
    61                 [button setKeyEquivalent:@"\r"];
       
    62             } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
       
    63                 [button setKeyEquivalent:@"\033"];
       
    64             } else {
       
    65                 [button setKeyEquivalent:@""];
       
    66             }
       
    67         }
       
    68 
       
    69         NSInteger clicked = [alert runModal];
       
    70         clicked -= NSAlertFirstButtonReturn;
       
    71         *buttonid = buttons[clicked].buttonid;
       
    72         [alert release];
       
    73     }
       
    74 
    76 
    75     return 0;
    77     return 0;
    76 }
    78 }
    77 
    79 
    78 #endif /* SDL_VIDEO_DRIVER_COCOA */
    80 #endif /* SDL_VIDEO_DRIVER_COCOA */