| 1 |
/* |
| 2 |
Simple DirectMedia Layer |
| 3 |
Copyright (C) 1997-2026 Sam Lantinga <[email protected]> |
| 4 |
|
| 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. |
| 8 |
|
| 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: |
| 12 |
|
| 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. |
| 20 |
*/ |
| 21 |
|
| 22 |
/* This file contains some macOS-specific support code */ |
| 23 |
|
| 24 |
#if defined(__APPLE__) |
| 25 |
#include <Cocoa/Cocoa.h> |
| 26 |
|
| 27 |
#if __GNUC__ >= 4 |
| 28 |
#define SDL2_PRIVATE __attribute__((visibility("hidden"))) |
| 29 |
#else |
| 30 |
#define SDL2_PRIVATE __private_extern__ |
| 31 |
#endif |
| 32 |
|
| 33 |
#ifndef MAC_OS_X_VERSION_10_12 |
| 34 |
#define NSAlertStyleCritical NSCriticalAlertStyle |
| 35 |
#endif |
| 36 |
|
| 37 |
SDL2_PRIVATE void SDL2Compat_NSLog(const char *prefix, const char *text) |
| 38 |
{ |
| 39 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; { |
| 40 |
NSString *nsText = [NSString stringWithUTF8String:text]; |
| 41 |
if (prefix && *prefix) { |
| 42 |
NSString *nsPrefix = [NSString stringWithUTF8String:prefix]; |
| 43 |
NSLog(@"%@%@", nsPrefix, nsText); |
| 44 |
} else { |
| 45 |
NSLog(@"%@", nsText); |
| 46 |
} |
| 47 |
} |
| 48 |
[pool drain]; |
| 49 |
} |
| 50 |
|
| 51 |
SDL2_PRIVATE void error_dialog(const char *errorMsg) |
| 52 |
{ |
| 53 |
NSAlert *alert; |
| 54 |
|
| 55 |
if (NSApp == nil) { |
| 56 |
ProcessSerialNumber psn = { 0, kCurrentProcess }; |
| 57 |
TransformProcessType(&psn, kProcessTransformToForegroundApplication); |
| 58 |
[NSApplication sharedApplication]; |
| 59 |
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; |
| 60 |
[NSApp finishLaunching]; |
| 61 |
} |
| 62 |
|
| 63 |
[NSApp activateIgnoringOtherApps:YES]; |
| 64 |
alert = [[[NSAlert alloc] init] autorelease]; |
| 65 |
alert.alertStyle = NSAlertStyleCritical; |
| 66 |
alert.messageText = @"Fatal error! Cannot continue!"; |
| 67 |
alert.informativeText = [NSString stringWithCString:errorMsg encoding:NSASCIIStringEncoding]; |
| 68 |
[alert runModal]; |
| 69 |
} |
| 70 |
#endif |
| 71 |
|
| 72 |
/* vi: set ts=4 sw=4 expandtab: */ |
| 73 |
|