/
gui_macosx.c
221 lines (175 loc) · 6.45 KB
/
gui_macosx.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/**
* MojoSetup; a portable, flexible installation application.
*
* Please see the file LICENSE.txt in the source's root directory.
*
* This file written by Ryan C. Gordon.
*/
#if !SUPPORT_GUI_MACOSX
#error Something is wrong in the build system.
#endif
#include <Carbon/Carbon.h>
#undef true
#undef false
#define BUILDING_EXTERNAL_PLUGIN 1
#include "gui.h"
MOJOGUI_PLUGIN(macosx)
#if !GUI_STATIC_LINK_MACOSX
CREATE_MOJOGUI_ENTRY_POINT(macosx)
#endif
// (A lot of this is stolen from MojoPatch: http://icculus.org/mojopatch/ ...)
static uint8 MojoGui_macosx_priority(boolean istty)
{
// obviously this is the thing you want on Mac OS X.
return MOJOGUI_PRIORITY_TRY_FIRST;
} // MojoGui_macosx_priority
static boolean MojoGui_macosx_init(void)
{
// This lets a stdio app become a GUI app. Otherwise, you won't get
// GUI events from the system and other things will fail to work.
// Putting the app in an application bundle does the same thing.
// TransformProcessType() is a 10.3+ API. SetFrontProcess() is 10.0+.
if (TransformProcessType != NULL) // check it as a weak symbol.
{
ProcessSerialNumber psn = { 0, kCurrentProcess };
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
SetFrontProcess(&psn);
} // if
// !!! FIXME: make sure we have access to the desktop...may be ssh'd in
// !!! FIXME: as another user that doesn't have the Finder loaded or
// !!! FIXME: something.
return true; // always succeeds.
} // MojoGui_macosx_init
static void MojoGui_macosx_deinit(void)
{
// no-op
} // MojoGui_macosx_deinit
static int do_msgbox(const char *_title, const char *str, AlertType alert_type,
AlertStdCFStringAlertParamRec *param,
DialogItemIndex *idx)
{
int retval = 0;
DialogItemIndex val = 0;
CFStringRef title = CFStringCreateWithBytes(NULL,
(const unsigned char *) _title,
strlen(_title),
kCFStringEncodingUTF8, 0);
CFStringRef msg = CFStringCreateWithBytes(NULL,
(const unsigned char *) str,
strlen(str),
kCFStringEncodingUTF8, 0);
if ((msg != NULL) && (title != NULL))
{
DialogRef dlg = NULL;
if (CreateStandardAlert(alert_type, title, msg, param, &dlg) == noErr)
{
RunStandardAlert(dlg, NULL, (idx) ? idx : &val);
retval = 1;
} /* if */
} /* if */
if (msg != NULL)
CFRelease(msg);
if (title != NULL)
CFRelease(title);
return(retval);
} // do_msgbox
static void MojoGui_macosx_msgbox(const char *title, const char *text)
{
do_msgbox(title, text, kAlertNoteAlert, NULL, NULL);
} // MojoGui_macosx_msgbox
static boolean do_prompt(const char *title, const char *text,
boolean yes, const char *yesstr, const char *nostr)
{
boolean retval = false;
OSStatus err = noErr;
AlertStdCFStringAlertParamRec params;
err = GetStandardAlertDefaultParams(¶ms, kStdCFStringAlertVersionOne);
if (err == noErr)
{
DialogItemIndex item;
CFStringRef yes, no;
const CFStringEncoding enc = kCFStringEncodingUTF8;
yes = CFStringCreateWithCString(NULL, yesstr, enc);
no = CFStringCreateWithCString(NULL, nostr, enc);
params.movable = TRUE;
params.helpButton = FALSE;
params.defaultText = yes;
params.cancelText = no;
params.defaultButton = (yes) ? kAlertStdAlertOKButton :
kAlertStdAlertCancelButton;
params.cancelButton = kAlertStdAlertCancelButton;
if (do_msgbox(title, text, kAlertCautionAlert, ¶ms, &item))
retval = (item == kAlertStdAlertOKButton);
CFRelease(yes);
CFRelease(no);
} // if
return retval;
} // do_prompt
static boolean MojoGui_macosx_promptyn(const char *title, const char *text,
boolean defval)
{
return do_prompt(title, text, defval, _("Yes"), _("No"));
} // MojoGui_macosx_promptyn
static MojoGuiYNAN MojoGui_macosx_promptynan(const char *title,
const char *text,
boolean defval)
{
STUBBED("ynan");
return MojoGui_macosx_promptyn(title, text, defval); // !!! FIXME
} // MojoGui_macosx_promptynan
static boolean MojoGui_macosx_start(const char *title,
const MojoGuiSplash *splash)
{
return true; // !!! FIXME
} // MojoGui_macosx_start
static void MojoGui_macosx_stop(void)
{
// no-op.
} // MojoGui_macosx_stop
static int MojoGui_macosx_readme(const char *name, const uint8 *data,
size_t len, boolean can_back,
boolean can_fwd)
{
STUBBED("macosx readme");
return 1;
} // MojoGui_macosx_readme
static int MojoGui_macosx_options(MojoGuiSetupOptions *opts,
boolean can_back, boolean can_fwd)
{
// !!! FIXME: write me.
STUBBED("macosx options");
return 1;
} // MojoGui_macosx_options
static char *MojoGui_macosx_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
{
// !!! FIXME: write me.
STUBBED("macosx destination");
*command = 1;
return xstrdup("/Applications");
} // MojoGui_macosx_destination
static boolean MojoGui_macosx_insertmedia(const char *medianame)
{
// !!! FIXME: "please insert '%s' ..."
// !!! FIXME: localization.
return do_prompt("Please insert", medianame, true, _("OK"), _("Cancel"));
} // MojoGui_macosx_insertmedia
static void MojoGui_macosx_progressitem(void)
{
STUBBED("macosx progressitem");
} // MojoGui_macosx_progressitem
static int MojoGui_macosx_progress(const char *type, const char *component,
int percent, const char *item,
boolean can_cancel)
{
// !!! FIXME: write me.
STUBBED("macosx progress");
return 1;
} // MojoGui_macosx_progress
static void MojoGui_macosx_final(const char *msg)
{
// !!! FIXME: write me.
STUBBED("macosx final");
} // MojoGui_macosx_final
// end of gui_macosx.c ...