src/video/cocoa/SDL_cocoamessagebox.m
changeset 6617 3a92812e0c91
child 6623 f4ae87f3ec15
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/video/cocoa/SDL_cocoamessagebox.m	Tue Oct 30 12:31:26 2012 -0700
     1.3 @@ -0,0 +1,72 @@
     1.4 +/*
     1.5 +  Simple DirectMedia Layer
     1.6 +  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
     1.7 +
     1.8 +  This software is provided 'as-is', without any express or implied
     1.9 +  warranty.  In no event will the authors be held liable for any damages
    1.10 +  arising from the use of this software.
    1.11 +
    1.12 +  Permission is granted to anyone to use this software for any purpose,
    1.13 +  including commercial applications, and to alter it and redistribute it
    1.14 +  freely, subject to the following restrictions:
    1.15 +
    1.16 +  1. The origin of this software must not be misrepresented; you must not
    1.17 +     claim that you wrote the original software. If you use this software
    1.18 +     in a product, an acknowledgment in the product documentation would be
    1.19 +     appreciated but is not required.
    1.20 +  2. Altered source versions must be plainly marked as such, and must not be
    1.21 +     misrepresented as being the original software.
    1.22 +  3. This notice may not be removed or altered from any source distribution.
    1.23 +*/
    1.24 +#include "SDL_config.h"
    1.25 +
    1.26 +#if SDL_VIDEO_DRIVER_COCOA
    1.27 +
    1.28 +#include "SDL.h"
    1.29 +#include "SDL_cocoavideo.h"
    1.30 +
    1.31 +
    1.32 +/* Display a Cocoa message box */
    1.33 +int
    1.34 +Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
    1.35 +{
    1.36 +    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.37 +
    1.38 +    NSAlert* alert = [[NSAlert alloc] init];
    1.39 +
    1.40 +    if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
    1.41 +        [alert setAlertStyle:NSCriticalAlertStyle];
    1.42 +    } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
    1.43 +        [alert setAlertStyle:NSWarningAlertStyle];
    1.44 +    } else {
    1.45 +        [alert setAlertStyle:NSInformationalAlertStyle];
    1.46 +    }
    1.47 +
    1.48 +    [alert setMessageText:[[NSString alloc] initWithUTF8String:messageboxdata->title]];
    1.49 +    [alert setInformativeText:[[NSString alloc] initWithUTF8String:messageboxdata->message]];
    1.50 +
    1.51 +    const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
    1.52 +    int i;
    1.53 +    for (i = 0; i < messageboxdata->numbuttons; ++i) {
    1.54 +        NSButton *button = [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]];
    1.55 +        if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
    1.56 +            [button setKeyEquivalent:@"\r"];
    1.57 +        } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
    1.58 +            [button setKeyEquivalent:@"\033"];
    1.59 +        } else {
    1.60 +            [button setKeyEquivalent:@""];
    1.61 +        }
    1.62 +    }
    1.63 +
    1.64 +    NSInteger clicked = [alert runModal];
    1.65 +    clicked -= NSAlertFirstButtonReturn;
    1.66 +    *buttonid = buttons[clicked].buttonid;
    1.67 +
    1.68 +    [pool release];
    1.69 +
    1.70 +    return 0;
    1.71 +}
    1.72 +
    1.73 +#endif /* SDL_VIDEO_DRIVER_COCOA */
    1.74 +
    1.75 +/* vi: set ts=4 sw=4 expandtab: */