Skip to content

Latest commit

 

History

History
215 lines (171 loc) · 6.33 KB

gui_macosx.c

File metadata and controls

215 lines (171 loc) · 6.33 KB
 
May 12, 2007
May 12, 2007
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.
*/
Dec 9, 2006
Dec 9, 2006
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
Dec 1, 2006
Dec 1, 2006
17
#define BUILDING_EXTERNAL_PLUGIN 1
May 8, 2007
May 8, 2007
18
#include "gui.h"
Dec 1, 2006
Dec 1, 2006
19
Dec 7, 2006
Dec 7, 2006
20
21
22
23
24
25
MOJOGUI_PLUGIN(macosx)
#if !GUI_STATIC_LINK_MACOSX
CREATE_MOJOGUI_ENTRY_POINT(macosx)
#endif
Dec 2, 2006
Dec 2, 2006
26
27
// (A lot of this is stolen from MojoPatch: http://icculus.org/mojopatch/ ...)
Nov 21, 2007
Nov 21, 2007
28
static uint8 MojoGui_macosx_priority(boolean istty)
Dec 1, 2006
Dec 1, 2006
29
{
May 18, 2007
May 18, 2007
30
// obviously this is the thing you want on Mac OS X.
Dec 1, 2006
Dec 1, 2006
31
32
33
return MOJOGUI_PRIORITY_TRY_FIRST;
} // MojoGui_macosx_priority
Dec 7, 2006
Dec 7, 2006
34
static boolean MojoGui_macosx_init(void)
Dec 1, 2006
Dec 1, 2006
35
{
Dec 12, 2006
Dec 12, 2006
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
May 18, 2007
May 18, 2007
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.
Dec 1, 2006
Dec 1, 2006
52
53
} // MojoGui_macosx_init
Dec 7, 2006
Dec 7, 2006
54
static void MojoGui_macosx_deinit(void)
Dec 1, 2006
Dec 1, 2006
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),
Dec 6, 2006
Dec 6, 2006
68
kCFStringEncodingUTF8, 0);
Dec 1, 2006
Dec 1, 2006
69
70
71
CFStringRef msg = CFStringCreateWithBytes(NULL,
(const unsigned char *) str,
strlen(str),
Dec 6, 2006
Dec 6, 2006
72
kCFStringEncodingUTF8, 0);
Dec 1, 2006
Dec 1, 2006
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
Dec 7, 2006
Dec 7, 2006
93
static void MojoGui_macosx_msgbox(const char *title, const char *text)
Dec 1, 2006
Dec 1, 2006
94
95
96
97
{
do_msgbox(title, text, kAlertNoteAlert, NULL, NULL);
} // MojoGui_macosx_msgbox
Dec 6, 2006
Dec 6, 2006
98
Apr 21, 2007
Apr 21, 2007
99
100
static boolean do_prompt(const char *title, const char *text,
boolean yes, const char *yesstr, const char *nostr)
Dec 1, 2006
Dec 1, 2006
101
{
Dec 6, 2006
Dec 6, 2006
102
103
boolean retval = false;
OSStatus err = noErr;
Dec 1, 2006
Dec 1, 2006
104
AlertStdCFStringAlertParamRec params;
Dec 6, 2006
Dec 6, 2006
105
Dec 1, 2006
Dec 1, 2006
106
err = GetStandardAlertDefaultParams(&params, kStdCFStringAlertVersionOne);
Dec 6, 2006
Dec 6, 2006
107
108
109
110
if (err == noErr)
{
DialogItemIndex item;
CFStringRef yes, no;
Dec 7, 2006
Dec 7, 2006
111
const CFStringEncoding enc = kCFStringEncodingUTF8;
Apr 21, 2007
Apr 21, 2007
112
113
yes = CFStringCreateWithCString(NULL, yesstr, enc);
no = CFStringCreateWithCString(NULL, nostr, enc);
Dec 6, 2006
Dec 6, 2006
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, &params, &item))
retval = (item == kAlertStdAlertOKButton);
CFRelease(yes);
CFRelease(no);
} // if
return retval;
Jul 2, 2007
Jul 2, 2007
130
} // do_prompt
Dec 1, 2006
Dec 1, 2006
131
132
Sep 20, 2007
Sep 20, 2007
133
static boolean MojoGui_macosx_promptyn(const char *title, const char *text,
Jul 2, 2007
Jul 2, 2007
134
boolean defval)
Dec 1, 2006
Dec 1, 2006
135
{
Jul 2, 2007
Jul 2, 2007
136
return do_prompt(title, text, defval, entry->_("Yes"), entry->_("No"));
Apr 21, 2007
Apr 21, 2007
137
} // MojoGui_macosx_promptyn
Dec 1, 2006
Dec 1, 2006
138
Dec 20, 2006
Dec 20, 2006
139
May 17, 2007
May 17, 2007
140
static MojoGuiYNAN MojoGui_macosx_promptynan(const char *title,
Jul 2, 2007
Jul 2, 2007
141
142
const char *text,
boolean defval)
May 17, 2007
May 17, 2007
143
144
{
STUBBED("ynan");
Jul 2, 2007
Jul 2, 2007
145
return MojoGui_macosx_promptyn(title, text, defval); // !!! FIXME
May 17, 2007
May 17, 2007
146
147
148
} // MojoGui_macosx_promptynan
Nov 24, 2007
Nov 24, 2007
149
150
static boolean MojoGui_macosx_start(const char *title,
const MojoGuiSplash *splash)
Dec 12, 2006
Dec 12, 2006
151
{
Apr 21, 2007
Apr 21, 2007
152
return true; // !!! FIXME
Dec 20, 2006
Dec 20, 2006
153
} // MojoGui_macosx_start
Dec 12, 2006
Dec 12, 2006
154
155
Dec 20, 2006
Dec 20, 2006
156
static void MojoGui_macosx_stop(void)
Dec 12, 2006
Dec 12, 2006
157
158
{
// no-op.
Dec 20, 2006
Dec 20, 2006
159
160
161
} // MojoGui_macosx_stop
May 10, 2007
May 10, 2007
162
static int MojoGui_macosx_readme(const char *name, const uint8 *data,
May 10, 2007
May 10, 2007
163
164
size_t len, boolean can_back,
boolean can_fwd)
Dec 20, 2006
Dec 20, 2006
165
166
{
STUBBED("macosx readme");
May 10, 2007
May 10, 2007
167
return 1;
Dec 20, 2006
Dec 20, 2006
168
} // MojoGui_macosx_readme
Dec 12, 2006
Dec 12, 2006
169
Dec 27, 2006
Dec 27, 2006
170
May 10, 2007
May 10, 2007
171
static int MojoGui_macosx_options(MojoGuiSetupOptions *opts,
May 10, 2007
May 10, 2007
172
boolean can_back, boolean can_fwd)
Dec 27, 2006
Dec 27, 2006
173
174
175
{
// !!! FIXME: write me.
STUBBED("macosx options");
May 10, 2007
May 10, 2007
176
return 1;
Dec 27, 2006
Dec 27, 2006
177
178
} // MojoGui_macosx_options
May 10, 2007
May 10, 2007
179
180
181
static char *MojoGui_macosx_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
Dec 28, 2006
Dec 28, 2006
182
183
184
{
// !!! FIXME: write me.
STUBBED("macosx destination");
May 10, 2007
May 10, 2007
185
*command = 1;
Dec 28, 2006
Dec 28, 2006
186
187
return entry->xstrdup("/Applications");
} // MojoGui_macosx_destination
Dec 27, 2006
Dec 27, 2006
188
Apr 21, 2007
Apr 21, 2007
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
May 12, 2007
May 12, 2007
198
May 10, 2007
May 10, 2007
199
static int MojoGui_macosx_progress(const char *type, const char *component,
May 7, 2007
May 7, 2007
200
int percent, const char *item)
Apr 22, 2007
Apr 22, 2007
201
202
{
// !!! FIXME: write me.
Sep 20, 2007
Sep 20, 2007
203
STUBBED("macosx progress");
May 10, 2007
May 10, 2007
204
return 1;
May 7, 2007
May 7, 2007
205
} // MojoGui_macosx_progress
Apr 22, 2007
Apr 22, 2007
206
May 12, 2007
May 12, 2007
207
208
209
210
static void MojoGui_macosx_final(const char *msg)
{
// !!! FIXME: write me.
Sep 20, 2007
Sep 20, 2007
211
STUBBED("macosx final");
May 12, 2007
May 12, 2007
212
213
} // MojoGui_macosx_final
Dec 1, 2006
Dec 1, 2006
214
// end of gui_macosx.c ...