/
gui.h
302 lines (253 loc) · 8.65 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
17
18
19
20
#ifndef _INCL_GUI_H_
#define _INCL_GUI_H_
#include "universal.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum
{
MOJOGUI_PRIORITY_NEVER_TRY = 0,
21
MOJOGUI_PRIORITY_USER_REQUESTED,
22
23
MOJOGUI_PRIORITY_TRY_FIRST,
MOJOGUI_PRIORITY_TRY_NORMAL,
24
MOJOGUI_PRIORITY_TRY_LAST,
25
MOJOGUI_PRIORITY_TRY_ABSOLUTELY_LAST,
26
MOJOGUI_PRIORITY_TOTAL
27
28
} MojoGuiPluginPriority;
29
30
31
32
33
34
35
36
37
38
39
typedef enum
{
MOJOGUI_NO,
MOJOGUI_YES,
MOJOGUI_ALWAYS,
MOJOGUI_NEVER
} MojoGuiYNAN;
40
41
42
/*
* Abstract GUI interfaces.
*/
43
44
45
46
47
typedef struct MojoGuiSetupOptions MojoGuiSetupOptions;
struct MojoGuiSetupOptions
{
const char *description;
48
const char *tooltip;
49
50
51
boolean value;
boolean is_group_parent;
uint64 size;
52
int opaque; // GUI drivers shouldn't touch this.
53
void *guiopaque; // For GUI drivers. App won't touch or free this.
54
55
56
57
MojoGuiSetupOptions *next_sibling;
MojoGuiSetupOptions *child;
};
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
typedef enum
{
MOJOGUI_SPLASH_NONE,
MOJOGUI_SPLASH_TOP,
MOJOGUI_SPLASH_LEFT,
MOJOGUI_SPLASH_RIGHT,
MOJOGUI_SPLASH_BOTTOM,
MOJOGUI_SPLASH_BACKGROUND,
} MojoGuiSplashPos;
typedef struct MojoGuiSplash MojoGuiSplash;
struct MojoGuiSplash
{
const uint8 *rgba; // framebuffer.
uint32 w; // width in pixels.
uint32 h; // height in pixels.
MojoGuiSplashPos position; // where to put the splash.
};
79
80
81
82
#define MOJOGUI_ENTRY_POINT MojoSetup_Gui_GetInterface
#define MOJOGUI_ENTRY_POINT_STR DEFINE_TO_STR(MOJOGUI_ENTRY_POINT)
// Increment this value when MojoGui's structure changes.
83
#define MOJOGUI_INTERFACE_REVISION 6
84
85
86
typedef struct MojoGui MojoGui;
struct MojoGui
87
{
88
uint8 (*priority)(boolean istty);
89
90
91
92
const char* (*name)(void);
boolean (*init)(void);
void (*deinit)(void);
void (*msgbox)(const char *title, const char *text);
93
94
boolean (*promptyn)(const char *title, const char *text, boolean def);
MojoGuiYNAN (*promptynan)(const char *title, const char *text, boolean def);
95
boolean (*start)(const char *title, const MojoGuiSplash *splash);
96
void (*stop)(void);
97
int (*readme)(const char *name, const uint8 *data, size_t len,
98
boolean can_back, boolean can_fwd);
99
int (*options)(MojoGuiSetupOptions *opts,
100
boolean can_back, boolean can_fwd);
101
102
char * (*destination)(const char **recommendations, int recnum,
int *command, boolean can_back, boolean can_fwd);
103
104
int (*productkey)(const char *desc, const char *fmt, char *buf,
const int buflen, boolean can_back, boolean can_fwd);
105
boolean (*insertmedia)(const char *medianame);
106
void (*progressitem)(void);
107
boolean (*progress)(const char *type, const char *component,
108
int percent, const char *item, boolean can_cancel);
109
void (*final)(const char *msg);
110
111
};
112
113
typedef const MojoGui* (*MojoGuiEntryPoint)(int revision,
const MojoSetupEntryPoints *e);
114
115
116
117
#if !BUILDING_EXTERNAL_PLUGIN
extern const MojoGui *GGui;
const MojoGui *MojoGui_initGuiPlugin(void);
118
119
120
void MojoGui_deinitGuiPlugin(void);
#else
121
122
__EXPORT__ const MojoGui *MOJOGUI_ENTRY_POINT(int revision,
const MojoSetupEntryPoints *e);
123
124
125
126
127
128
/*
* We do this as a macro so we only have to update one place, and it
* enforces some details in the plugins. Without effort, plugins don't
* support anything but the latest version of the interface.
*/
129
#define MOJOGUI_PLUGIN(module) \
130
static const MojoSetupEntryPoints *entry = NULL; \
131
static uint8 MojoGui_##module##_priority(boolean istty); \
132
133
134
135
static const char* MojoGui_##module##_name(void) { return #module; } \
static boolean MojoGui_##module##_init(void); \
static void MojoGui_##module##_deinit(void); \
static void MojoGui_##module##_msgbox(const char *title, const char *text); \
136
137
static boolean MojoGui_##module##_promptyn(const char *t1, const char *t2, \
boolean d); \
138
static MojoGuiYNAN MojoGui_##module##_promptynan(const char *t1, \
139
const char *t2, boolean d); \
140
141
static boolean MojoGui_##module##_start(const char *t, \
const MojoGuiSplash *splash); \
142
static void MojoGui_##module##_stop(void); \
143
static int MojoGui_##module##_readme(const char *name, const uint8 *data, \
144
145
size_t len, boolean can_back, \
boolean can_fwd); \
146
static int MojoGui_##module##_options(MojoGuiSetupOptions *opts, \
147
boolean can_back, boolean can_fwd); \
148
149
static char *MojoGui_##module##_destination(const char **r, int recnum, \
int *command, boolean can_back, boolean can_fwd); \
150
151
152
static int MojoGui_##module##_productkey(const char *desc, const char *fmt, \
char *buf, const int buflen, boolean can_back, \
boolean can_fwd); \
153
static boolean MojoGui_##module##_insertmedia(const char *medianame); \
154
static void MojoGui_##module##_progressitem(void); \
155
static boolean MojoGui_##module##_progress(const char *typ, const char *comp, \
156
157
int percent, const char *item, \
boolean can_cancel); \
158
static void MojoGui_##module##_final(const char *msg); \
159
const MojoGui *MojoGuiPlugin_##module(int rev, const MojoSetupEntryPoints *e) \
160
{ \
161
162
163
164
165
166
167
168
if (rev == MOJOGUI_INTERFACE_REVISION) { \
static const MojoGui retval = { \
MojoGui_##module##_priority, \
MojoGui_##module##_name, \
MojoGui_##module##_init, \
MojoGui_##module##_deinit, \
MojoGui_##module##_msgbox, \
MojoGui_##module##_promptyn, \
169
MojoGui_##module##_promptynan, \
170
171
172
MojoGui_##module##_start, \
MojoGui_##module##_stop, \
MojoGui_##module##_readme, \
173
MojoGui_##module##_options, \
174
MojoGui_##module##_destination, \
175
MojoGui_##module##_productkey, \
176
MojoGui_##module##_insertmedia, \
177
MojoGui_##module##_progressitem, \
178
MojoGui_##module##_progress, \
179
MojoGui_##module##_final, \
180
181
}; \
entry = e; \
182
183
184
return &retval; \
} \
return NULL; \
185
186
} \
187
#define CREATE_MOJOGUI_ENTRY_POINT(module) \
188
const MojoGui *MOJOGUI_ENTRY_POINT(int rev, const MojoSetupEntryPoints *e) \
189
{ \
190
return MojoGuiPlugin_##module(rev, e); \
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
// Redefine things that need to go through the plugin entry point interface,
// so plugins calling into the MojoSetup core can use the same code as the
// rest of the app.
#ifdef _
#undef _
#endif
#define _(x) entry->translate(x)
#ifdef xmalloc
#undef xmalloc
#endif
#define xmalloc(x) entry->xmalloc(x)
#ifdef xrealloc
#undef xrealloc
#endif
#define xrealloc(x,y) entry->xrealloc(x,y)
#ifdef xstrdup
#undef xstrdup
#endif
#define xstrdup(x) entry->xstrdup(x)
#ifdef xstrncpy
#undef xstrncpy
#endif
#define xstrncpy(x,y,z) entry->xstrcpy(x,y,z)
#ifdef logWarning
#undef logWarning
#endif
#define logWarning entry->logWarning
#ifdef logError
#undef logError
#endif
#define logError entry->logError
#ifdef logInfo
#undef logInfo
#endif
#define logInfo entry->logInfo
#ifdef logDebug
#undef logDebug
#endif
#define logDebug entry->logDebug
#ifdef format
#undef format
#endif
#define format entry->format
#ifdef numstr
#undef numstr
#endif
#define numstr(x) entry->numstr(x)
#ifdef ticks
#undef ticks
#endif
#define ticks() entry->ticks()
258
259
260
261
262
#ifdef utf8codepoint
#undef utf8codepoint
#endif
#define utf8codepoint(x) entry->utf8codepoint(x)
263
264
265
266
267
268
269
270
271
272
#ifdef utf8len
#undef utf8len
#endif
#define utf8len(x) entry->utf8len(x)
#ifdef splitText
#undef splitText
#endif
#define splitText(w,x,y,z) entry->splitText(w,x,y,z)
273
274
275
#ifdef isValidProductKey
#undef isValidProductKey
#endif
276
#define isValidProductKey(x,y) entry->isValidProductKey(x,y)
277
278
#endif
279
280
281
282
/*
* make some decisions about which GUI plugins to build...
283
284
* We list them all here, but some are built, some aren't. Some are DLLs,
* some aren't...
285
286
*/
287
const MojoGui *MojoGuiPlugin_stdio(int rev, const MojoSetupEntryPoints *e);
288
const MojoGui *MojoGuiPlugin_ncurses(int rev, const MojoSetupEntryPoints *e);
289
const MojoGui *MojoGuiPlugin_gtkplus2(int rev, const MojoSetupEntryPoints *e);
290
const MojoGui *MojoGuiPlugin_www(int rev, const MojoSetupEntryPoints *e);
291
const MojoGui *MojoGuiPlugin_cocoa(int rev, const MojoSetupEntryPoints *e);
292
293
// !!! FIXME: Qt? KDE? Gnome? Console? wxWidgets?
294
295
296
297
298
299
300
#ifdef __cplusplus
}
#endif
#endif
301
// end of gui.h ...