/
gui_macosx.c
215 lines (171 loc) · 6.33 KB
1
2
3
4
5
6
7
8
/**
* 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.
*/
9
10
11
12
13
14
15
16
#if !SUPPORT_GUI_MACOSX
#error Something is wrong in the build system.
#endif
#include <Carbon/Carbon.h>
#undef true
#undef false
17
#define BUILDING_EXTERNAL_PLUGIN 1
18
#include "gui.h"
19
20
21
22
23
24
25
MOJOGUI_PLUGIN(macosx)
#if !GUI_STATIC_LINK_MACOSX
CREATE_MOJOGUI_ENTRY_POINT(macosx)
#endif
26
27
// (A lot of this is stolen from MojoPatch: http://icculus.org/mojopatch/ ...)
28
static uint8 MojoGui_macosx_priority(boolean istty)
29
{
30
// obviously this is the thing you want on Mac OS X.
31
32
33
return MOJOGUI_PRIORITY_TRY_FIRST;
} // MojoGui_macosx_priority
34
static boolean MojoGui_macosx_init(void)
35
{
36
37
38
39
40
41
42
43
44
45
46
// 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
47
48
49
50
51
// !!! 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.
52
53
} // MojoGui_macosx_init
54
static void MojoGui_macosx_deinit(void)
55
56
57
58
59
60
61
62
63
64
65
66
67
{
// 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),
68
kCFStringEncodingUTF8, 0);
69
70
71
CFStringRef msg = CFStringCreateWithBytes(NULL,
(const unsigned char *) str,
strlen(str),
72
kCFStringEncodingUTF8, 0);
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
93
static void MojoGui_macosx_msgbox(const char *title, const char *text)
94
95
96
97
{
do_msgbox(title, text, kAlertNoteAlert, NULL, NULL);
} // MojoGui_macosx_msgbox
98
99
100
static boolean do_prompt(const char *title, const char *text,
boolean yes, const char *yesstr, const char *nostr)
101
{
102
103
boolean retval = false;
OSStatus err = noErr;
104
AlertStdCFStringAlertParamRec params;
105
106
err = GetStandardAlertDefaultParams(¶ms, kStdCFStringAlertVersionOne);
107
108
109
110
if (err == noErr)
{
DialogItemIndex item;
CFStringRef yes, no;
111
const CFStringEncoding enc = kCFStringEncodingUTF8;
112
113
yes = CFStringCreateWithCString(NULL, yesstr, enc);
no = CFStringCreateWithCString(NULL, nostr, enc);
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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;
130
} // do_prompt
131
132
133
static boolean MojoGui_macosx_promptyn(const char *title, const char *text,
134
boolean defval)
135
{
136
return do_prompt(title, text, defval, entry->_("Yes"), entry->_("No"));
137
} // MojoGui_macosx_promptyn
138
139
140
static MojoGuiYNAN MojoGui_macosx_promptynan(const char *title,
141
142
const char *text,
boolean defval)
143
144
{
STUBBED("ynan");
145
return MojoGui_macosx_promptyn(title, text, defval); // !!! FIXME
146
147
148
} // MojoGui_macosx_promptynan
149
150
static boolean MojoGui_macosx_start(const char *title,
const MojoGuiSplash *splash)
151
{
152
return true; // !!! FIXME
153
} // MojoGui_macosx_start
154
155
156
static void MojoGui_macosx_stop(void)
157
158
{
// no-op.
159
160
161
} // MojoGui_macosx_stop
162
static int MojoGui_macosx_readme(const char *name, const uint8 *data,
163
164
size_t len, boolean can_back,
boolean can_fwd)
165
166
{
STUBBED("macosx readme");
167
return 1;
168
} // MojoGui_macosx_readme
169
170
171
static int MojoGui_macosx_options(MojoGuiSetupOptions *opts,
172
boolean can_back, boolean can_fwd)
173
174
175
{
// !!! FIXME: write me.
STUBBED("macosx options");
176
return 1;
177
178
} // MojoGui_macosx_options
179
180
181
static char *MojoGui_macosx_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
182
183
184
{
// !!! FIXME: write me.
STUBBED("macosx destination");
185
*command = 1;
186
187
return entry->xstrdup("/Applications");
} // MojoGui_macosx_destination
188
189
190
191
192
193
194
195
196
197
static boolean MojoGui_macosx_insertmedia(const char *medianame)
{
// !!! FIXME: "please insert '%s' ..."
// !!! FIXME: localization.
return do_prompt("Please insert", medianame, true,
entry->_("OK"), entry->_("Cancel"));
} // MojoGui_macosx_insertmedia
198
199
static int MojoGui_macosx_progress(const char *type, const char *component,
200
int percent, const char *item)
201
202
{
// !!! FIXME: write me.
203
STUBBED("macosx progress");
204
return 1;
205
} // MojoGui_macosx_progress
206
207
208
209
210
static void MojoGui_macosx_final(const char *msg)
{
// !!! FIXME: write me.
211
STUBBED("macosx final");
212
213
} // MojoGui_macosx_final
214
// end of gui_macosx.c ...