Fixed bug 2374 - Update copyright for 2014...
Is it that time already??
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org>
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
21 #include "../../SDL_internal.h"
23 #if SDL_VIDEO_DRIVER_COCOA
25 #if defined(__APPLE__) && defined(__POWERPC__) && !defined(__APPLE_ALTIVEC__)
32 #include "SDL_events.h"
33 #include "SDL_timer.h"
34 #include "SDL_messagebox.h"
35 #include "SDL_cocoavideo.h"
37 @interface SDLMessageBoxPresenter : NSObject {
42 - (id) initWithParentWindow:(SDL_Window *)window;
43 - (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
46 @implementation SDLMessageBoxPresenter
47 - (id) initWithParentWindow:(SDL_Window *)window
53 /* Retain the NSWindow because we'll show the alert later on the main thread */
55 nswindow = [((SDL_WindowData *) window->driverdata)->nswindow retain];
64 - (void)showAlert:(NSAlert*)alert
67 [alert beginSheetModalForWindow:nswindow modalDelegate:self didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:) contextInfo:nil];
74 clicked = [alert runModal];
78 - (void) alertDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
86 /* Display a Cocoa message box */
88 Cocoa_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
92 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
94 NSAlert* alert = [[[NSAlert alloc] init] autorelease];
96 if (messageboxdata->flags & SDL_MESSAGEBOX_ERROR) {
97 [alert setAlertStyle:NSCriticalAlertStyle];
98 } else if (messageboxdata->flags & SDL_MESSAGEBOX_WARNING) {
99 [alert setAlertStyle:NSWarningAlertStyle];
101 [alert setAlertStyle:NSInformationalAlertStyle];
104 [alert setMessageText:[NSString stringWithUTF8String:messageboxdata->title]];
105 [alert setInformativeText:[NSString stringWithUTF8String:messageboxdata->message]];
107 const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
109 for (i = 0; i < messageboxdata->numbuttons; ++i) {
110 NSButton *button = [alert addButtonWithTitle:[NSString stringWithUTF8String:buttons[i].text]];
111 if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
112 [button setKeyEquivalent:@"\r"];
113 } else if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
114 [button setKeyEquivalent:@"\033"];
116 [button setKeyEquivalent:@""];
120 SDLMessageBoxPresenter* presenter = [[[SDLMessageBoxPresenter alloc] initWithParentWindow:messageboxdata->window] autorelease];
122 [presenter performSelectorOnMainThread:@selector(showAlert:)
127 NSInteger clicked = presenter->clicked;
128 if (clicked >= NSAlertFirstButtonReturn)
130 clicked -= NSAlertFirstButtonReturn;
131 *buttonid = buttons[clicked].buttonid;
135 returnValue = SDL_SetError("Did not get a valid `clicked button' id: %d", clicked);
143 #endif /* SDL_VIDEO_DRIVER_COCOA */
145 /* vi: set ts=4 sw=4 expandtab: */