Debian Codegraph @

code/sys/sys_osx.m

raw
1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4
5 This file is part of Quake III Arena source code.
6
7 Quake III Arena source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
11
12 Quake III Arena source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Quake III Arena source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
21 */
22
23 #ifndef __APPLE__
24 #error This file is for Mac OS X only. You probably should not compile it.
25 #endif
26
27 // Please note that this file is just some Mac-specific bits. Most of the
28 // Mac OS X code is shared with other Unix platforms in sys_unix.c ...
29
30 #include "../qcommon/q_shared.h"
31 #include "../qcommon/qcommon.h"
32 #include "sys_local.h"
33
34 #import <Carbon/Carbon.h>
35 #import <Cocoa/Cocoa.h>
36
37 /*
38 ==============
39 Sys_Dialog
40
41 Display an OS X dialog box
42 ==============
43 */
44 dialogResult_t Sys_Dialog( dialogType_t type, const char *message, const char *title )
45 {
46 dialogResult_t result = DR_OK;
47 NSAlert *alert = [NSAlert new];
48
49 [alert setMessageText: [NSString stringWithUTF8String: title]];
50 [alert setInformativeText: [NSString stringWithUTF8String: message]];
51
52 if( type == DT_ERROR )
53 [alert setAlertStyle: NSAlertStyleCritical];
54 else
55 [alert setAlertStyle: NSAlertStyleWarning];
56
57 switch( type )
58 {
59 default:
60 [alert runModal];
61 result = DR_OK;
62 break;
63
64 case DT_YES_NO:
65 [alert addButtonWithTitle: @"Yes"];
66 [alert addButtonWithTitle: @"No"];
67 switch( [alert runModal] )
68 {
69 default:
70 case NSAlertFirstButtonReturn: result = DR_YES; break;
71 case NSAlertSecondButtonReturn: result = DR_NO; break;
72 }
73 break;
74
75 case DT_OK_CANCEL:
76 [alert addButtonWithTitle: @"OK"];
77 [alert addButtonWithTitle: @"Cancel"];
78
79 switch( [alert runModal] )
80 {
81 default:
82 case NSAlertFirstButtonReturn: result = DR_OK; break;
83 case NSAlertSecondButtonReturn: result = DR_CANCEL; break;
84 }
85 break;
86 }
87
88 [alert release];
89
90 return result;
91 }
92
93 /*
94 =================
95 Sys_StripAppBundle
96
97 Discovers if passed dir is suffixed with the directory structure of a Mac OS X
98 .app bundle. If it is, the .app directory structure is stripped off the end and
99 the result is returned. If not, dir is returned untouched.
100 =================
101 */
102 char *Sys_StripAppBundle( char *dir )
103 {
104 static char cwd[MAX_OSPATH];
105
106 Q_strncpyz(cwd, dir, sizeof(cwd));
107 if(strcmp(Sys_Basename(cwd), "MacOS"))
108 return dir;
109 Q_strncpyz(cwd, Sys_Dirname(cwd), sizeof(cwd));
110 if(strcmp(Sys_Basename(cwd), "Contents"))
111 return dir;
112 Q_strncpyz(cwd, Sys_Dirname(cwd), sizeof(cwd));
113 if(!strstr(Sys_Basename(cwd), ".app"))
114 return dir;
115 Q_strncpyz(cwd, Sys_Dirname(cwd), sizeof(cwd));
116 return cwd;
117 }