author | Sam Lantinga |
Fri, 15 Feb 2013 08:47:44 -0800 | |
changeset 6885 | 700f1b25f77f |
parent 6848 | 478ecc8a58b3 |
child 7088 | 664d8532219b |
permissions | -rw-r--r-- |
slouken@6617 | 1 |
/* |
slouken@6617 | 2 |
Simple DirectMedia Layer |
slouken@6885 | 3 |
Copyright (C) 1997-2013 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 |
|
icculus@6624 | 25 |
#if defined(__APPLE__) && defined(__POWERPC__) |
icculus@6624 | 26 |
#include <altivec.h> |
icculus@6624 | 27 |
#undef bool |
icculus@6624 | 28 |
#undef vector |
icculus@6626 | 29 |
#undef pixel |
icculus@6624 | 30 |
#endif |
icculus@6624 | 31 |
|
slouken@6623 | 32 |
#include "SDL_messagebox.h" |
slouken@6617 | 33 |
#include "SDL_cocoavideo.h" |
slouken@6617 | 34 |
|
slouken@6617 | 35 |
|
slouken@6617 | 36 |
/* Display a Cocoa message box */ |
slouken@6617 | 37 |
int |
slouken@6617 | 38 |
Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid) |
slouken@6617 | 39 |
{ |
icculus@6639 | 40 |
Cocoa_RegisterApp(); |
icculus@6639 | 41 |
|
slouken@6848 | 42 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
slouken@6848 | 43 |
|
slouken@6848 | 44 |
NSAlert* alert = [[NSAlert alloc] init]; |
slouken@6617 | 45 |
|
slouken@6848 | 46 |
if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) { |
slouken@6848 | 47 |
[alert setAlertStyle:NSCriticalAlertStyle]; |
slouken@6848 | 48 |
} else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) { |
slouken@6848 | 49 |
[alert setAlertStyle:NSWarningAlertStyle]; |
slouken@6848 | 50 |
} else { |
slouken@6848 | 51 |
[alert setAlertStyle:NSInformationalAlertStyle]; |
slouken@6848 | 52 |
} |
slouken@6617 | 53 |
|
slouken@6848 | 54 |
[alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]]; |
slouken@6848 | 55 |
[alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]]; |
slouken@6617 | 56 |
|
slouken@6848 | 57 |
const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons; |
slouken@6848 | 58 |
int i; |
slouken@6848 | 59 |
for (i = 0; i < messageboxdata->numbuttons; ++i) { |
slouken@6848 | 60 |
NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]]; |
slouken@6848 | 61 |
if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) { |
slouken@6848 | 62 |
[button setKeyEquivalent:@"\r"]; |
slouken@6848 | 63 |
} else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) { |
slouken@6848 | 64 |
[button setKeyEquivalent:@"\033"]; |
slouken@6848 | 65 |
} else { |
slouken@6848 | 66 |
[button setKeyEquivalent:@""]; |
slouken@6617 | 67 |
} |
slouken@6848 | 68 |
} |
alexey@6832 | 69 |
|
slouken@6848 | 70 |
NSInteger clicked = [alert runModal]; |
slouken@6848 | 71 |
clicked -= NSAlertFirstButtonReturn; |
slouken@6848 | 72 |
*buttonid = buttons[clicked].buttonid; |
slouken@6848 | 73 |
[alert release]; |
slouken@6848 | 74 |
|
slouken@6848 | 75 |
[pool release]; |
slouken@6617 | 76 |
|
slouken@6617 | 77 |
return 0; |
slouken@6617 | 78 |
} |
slouken@6617 | 79 |
|
slouken@6617 | 80 |
#endif /* SDL_VIDEO_DRIVER_COCOA */ |
slouken@6617 | 81 |
|
slouken@6617 | 82 |
/* vi: set ts=4 sw=4 expandtab: */ |