author | Sam Lantinga |
Tue, 30 Oct 2012 19:26:30 -0700 | |
changeset 6623 | f4ae87f3ec15 |
parent 6617 | 3a92812e0c91 |
child 6624 | ad4892cb5be9 |
permissions | -rw-r--r-- |
slouken@6617 | 1 |
/* |
slouken@6617 | 2 |
Simple DirectMedia Layer |
slouken@6617 | 3 |
Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org> |
slouken@6617 | 4 |
|
slouken@6617 | 5 |
This software is provided 'as-is', without any express or implied |
slouken@6617 | 6 |
warranty. In no event will the authors be held liable for any damages |
slouken@6617 | 7 |
arising from the use of this software. |
slouken@6617 | 8 |
|
slouken@6617 | 9 |
Permission is granted to anyone to use this software for any purpose, |
slouken@6617 | 10 |
including commercial applications, and to alter it and redistribute it |
slouken@6617 | 11 |
freely, subject to the following restrictions: |
slouken@6617 | 12 |
|
slouken@6617 | 13 |
1. The origin of this software must not be misrepresented; you must not |
slouken@6617 | 14 |
claim that you wrote the original software. If you use this software |
slouken@6617 | 15 |
in a product, an acknowledgment in the product documentation would be |
slouken@6617 | 16 |
appreciated but is not required. |
slouken@6617 | 17 |
2. Altered source versions must be plainly marked as such, and must not be |
slouken@6617 | 18 |
misrepresented as being the original software. |
slouken@6617 | 19 |
3. This notice may not be removed or altered from any source distribution. |
slouken@6617 | 20 |
*/ |
slouken@6617 | 21 |
#include "SDL_config.h" |
slouken@6617 | 22 |
|
slouken@6617 | 23 |
#if SDL_VIDEO_DRIVER_COCOA |
slouken@6617 | 24 |
|
slouken@6623 | 25 |
#include "SDL_messagebox.h" |
slouken@6617 | 26 |
#include "SDL_cocoavideo.h" |
slouken@6617 | 27 |
|
slouken@6617 | 28 |
|
slouken@6617 | 29 |
/* Display a Cocoa message box */ |
slouken@6617 | 30 |
int |
slouken@6617 | 31 |
Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) |
slouken@6617 | 32 |
{ |
slouken@6617 | 33 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
slouken@6617 | 34 |
|
slouken@6617 | 35 |
NSAlert* alert = [[NSAlert alloc] init]; |
slouken@6617 | 36 |
|
slouken@6617 | 37 |
if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) { |
slouken@6617 | 38 |
[alert setAlertStyle:NSCriticalAlertStyle]; |
slouken@6617 | 39 |
} else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) { |
slouken@6617 | 40 |
[alert setAlertStyle:NSWarningAlertStyle]; |
slouken@6617 | 41 |
} else { |
slouken@6617 | 42 |
[alert setAlertStyle:NSInformationalAlertStyle]; |
slouken@6617 | 43 |
} |
slouken@6617 | 44 |
|
slouken@6617 | 45 |
[alert setMessageText:[[NSString alloc] initWithUTF8String:messageboxdata->title]]; |
slouken@6617 | 46 |
[alert setInformativeText:[[NSString alloc] initWithUTF8String:messageboxdata->message]]; |
slouken@6617 | 47 |
|
slouken@6617 | 48 |
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; |
slouken@6617 | 49 |
int i; |
slouken@6617 | 50 |
for (i = 0; i < messageboxdata->numbuttons; ++i) { |
slouken@6617 | 51 |
NSButton *button = [alert addButtonWithTitle:[[NSString alloc] initWithUTF8String:buttons[i].text]]; |
slouken@6617 | 52 |
if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) { |
slouken@6617 | 53 |
[button setKeyEquivalent:@"\r"]; |
slouken@6617 | 54 |
} else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) { |
slouken@6617 | 55 |
[button setKeyEquivalent:@"\033"]; |
slouken@6617 | 56 |
} else { |
slouken@6617 | 57 |
[button setKeyEquivalent:@""]; |
slouken@6617 | 58 |
} |
slouken@6617 | 59 |
} |
slouken@6617 | 60 |
|
slouken@6617 | 61 |
NSInteger clicked = [alert runModal]; |
slouken@6617 | 62 |
clicked -= NSAlertFirstButtonReturn; |
slouken@6617 | 63 |
*buttonid = buttons[clicked].buttonid; |
slouken@6617 | 64 |
|
slouken@6617 | 65 |
[pool release]; |
slouken@6617 | 66 |
|
slouken@6617 | 67 |
return 0; |
slouken@6617 | 68 |
} |
slouken@6617 | 69 |
|
slouken@6617 | 70 |
#endif /* SDL_VIDEO_DRIVER_COCOA */ |
slouken@6617 | 71 |
|
slouken@6617 | 72 |
/* vi: set ts=4 sw=4 expandtab: */ |