Skip to content

Latest commit

 

History

History
565 lines (483 loc) · 21.4 KB

gui_cocoa.m

File metadata and controls

565 lines (483 loc) · 21.4 KB
 
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
/**
* 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_COCOA
#error Something is wrong in the build system.
#endif
#import <Cocoa/Cocoa.h>
#undef true
#undef false
#define BUILDING_EXTERNAL_PLUGIN 1
#include "gui.h"
MOJOGUI_PLUGIN(cocoa)
#if !GUI_STATIC_LINK_COCOA
CREATE_MOJOGUI_ENTRY_POINT(cocoa)
#endif
typedef enum
{
CLICK_BACK=-1,
CLICK_CANCEL,
CLICK_NEXT,
CLICK_NONE
} ClickValue;
May 7, 2009
May 7, 2009
34
// This nasty hack is because we appear to need to be under
May 7, 2009
May 7, 2009
35
// -[NSApp run] when calling things like NSRunAlertPanel().
May 7, 2009
May 7, 2009
36
37
38
39
// So we push a custom event, call -[NSApp run], catch it, do
// the panel, then call -[NSApp stop]. Yuck.
typedef enum
{
May 7, 2009
May 7, 2009
40
CUSTOMEVENT_BASEVALUE=3234,
May 7, 2009
May 7, 2009
41
42
43
44
45
46
47
48
CUSTOMEVENT_RUNQUEUE,
CUSTOMEVENT_MSGBOX,
CUSTOMEVENT_PROMPTYN,
CUSTOMEVENT_PROMPTYNAN,
CUSTOMEVENT_INSERTMEDIA,
} CustomEvent;
49
50
51
52
53
54
55
56
static NSAutoreleasePool *GAutoreleasePool = nil;
@interface MojoSetupController : NSView
{
IBOutlet NSButton *BackButton;
IBOutlet NSButton *CancelButton;
IBOutlet NSComboBox *DestinationCombo;
IBOutlet NSTextField *FinalText;
May 7, 2009
May 7, 2009
57
58
59
60
61
IBOutlet NSWindow *MainWindow;
IBOutlet NSButton *NextButton;
IBOutlet NSProgressIndicator *ProgressBar;
IBOutlet NSTextField *ProgressComponentLabel;
IBOutlet NSTextField *ProgressItemLabel;
62
63
64
IBOutlet NSTextView *ReadmeText;
IBOutlet NSTabView *TabView;
IBOutlet NSTextField *TitleLabel;
May 7, 2009
May 7, 2009
65
IBOutlet NSMenuItem *QuitMenuItem;
May 7, 2009
May 7, 2009
66
67
IBOutlet NSMenuItem *AboutMenuItem;
IBOutlet NSMenuItem *HideMenuItem;
68
69
ClickValue clickValue;
boolean canForward;
May 7, 2009
May 7, 2009
70
boolean needToBreakEventLoop;
May 7, 2009
May 7, 2009
71
boolean finalPage;
May 7, 2009
May 7, 2009
72
MojoGuiYNAN answerYNAN;
May 7, 2009
May 7, 2009
74
- (void)awakeFromNib;
75
76
77
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void)prepareWidgets:(const char*)winTitle;
- (void)unprepareWidgets;
May 7, 2009
May 7, 2009
78
79
80
81
82
83
84
- (void)fireCustomEvent:(CustomEvent)eventType data1:(NSInteger)data1 data2:(NSInteger)data2 atStart:(BOOL)atStart;
- (void)doCustomEvent:(NSEvent *)event;
- (void)doMsgBox:(const char *)title text:(const char *)text;
- (void)doPromptYN:(const char *)title text:(const char *)text;
- (void)doPromptYNAN:(const char *)title text:(const char *)text;
- (void)doInsertMedia:(const char *)medianame;
- (MojoGuiYNAN)getAnswerYNAN;
85
86
87
88
- (IBAction)backClicked:(NSButton *)sender;
- (IBAction)cancelClicked:(NSButton *)sender;
- (IBAction)nextClicked:(NSButton *)sender;
- (IBAction)browseClicked:(NSButton *)sender;
May 7, 2009
May 7, 2009
89
- (IBAction)menuQuit:(NSMenuItem *)sender;
May 7, 2009
May 7, 2009
90
- (int)doPage:(NSString *)pageId title:(const char *)_title canBack:(boolean)canBack canFwd:(boolean)canFwd canCancel:(boolean)canCancel canFwdAtStart:(boolean)canFwdAtStart shouldBlock:(BOOL)shouldBlock;
91
92
93
94
95
96
97
98
99
- (int)doReadme:(const char *)title text:(NSString *)text canBack:(boolean)canBack canFwd:(boolean)canFwd;
- (int)doOptions:(MojoGuiSetupOptions *)opts canBack:(boolean)canBack canFwd:(boolean)canFwd;
- (char *)doDestination:(const char **)recommends recnum:(int)recnum command:(int *)command canBack:(boolean)canBack canFwd:(boolean)canFwd;
- (int)doProductKey:(const char *)desc fmt:(const char *)fmt buf:(char *)buf buflen:(const int)buflen canBack:(boolean)canBack canFwd:(boolean)canFwd;
- (int)doProgress:(const char *)type component:(const char *)component percent:(int)percent item:(const char *)item canCancel:(boolean)canCancel;
- (void)doFinal:(const char *)msg;
@end // interface MojoSetupController
@implementation MojoSetupController
May 7, 2009
May 7, 2009
100
101
102
103
104
- (void)awakeFromNib
{
clickValue = CLICK_NONE;
canForward = false;
answerYNAN = MOJOGUI_NO;
May 7, 2009
May 7, 2009
105
needToBreakEventLoop = false;
May 7, 2009
May 7, 2009
106
finalPage = false;
May 7, 2009
May 7, 2009
107
108
} // awakeFromNib
109
110
111
112
113
114
115
116
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
printf("didfinishlaunching\n");
[NSApp stop:self]; // break out of NSApp::run()
} // applicationDidFinishLaunching
- (void)prepareWidgets:(const char*)winTitle
{
May 7, 2009
May 7, 2009
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#if 1
[BackButton setTitle:[NSString stringWithUTF8String:_("Back")]];
[NextButton setTitle:[NSString stringWithUTF8String:_("Next")]];
[CancelButton setTitle:[NSString stringWithUTF8String:_("Cancel")]];
#else
// !!! FIXME: there's probably a better way to do this.
// Set the correct localization for the buttons, then resize them so
// the new text fits perfectly. After that, we need to reposition
// them so they don't look scattered.
NSRect frameBack = [BackButton frame];
NSRect frameNext = [NextButton frame];
NSRect frameCancel = [CancelButton frame];
const float startX = frameCancel.origin.x + frameCancel.size.width;
const float spacing = (frameBack.origin.x + frameBack.size.width) - frameNext.origin.x;
131
132
133
[BackButton setTitle:[NSString stringWithUTF8String:_("Back")]];
[NextButton setTitle:[NSString stringWithUTF8String:_("Next")]];
[CancelButton setTitle:[NSString stringWithUTF8String:_("Cancel")]];
May 7, 2009
May 7, 2009
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
[BackButton sizeToFit];
[NextButton sizeToFit];
[CancelButton sizeToFit];
frameBack = [BackButton frame];
frameNext = [NextButton frame];
frameCancel = [CancelButton frame];
frameCancel.origin.x = startX - frameCancel.size.width;
frameNext.origin.x = (frameCancel.origin.x - frameNext.size.width) - spacing;
frameBack.origin.x = (frameNext.origin.x - frameBack.size.width) - spacing;
[CancelButton setFrame:frameCancel];
[CancelButton setNeedsDisplay:YES];
[NextButton setFrame:frameNext];
[NextButton setNeedsDisplay:YES];
[BackButton setFrame:frameBack];
[BackButton setNeedsDisplay:YES];
#endif
[ProgressBar setUsesThreadedAnimation:YES]; // we don't pump fast enough.
[ProgressBar startAnimation:self];
May 7, 2009
May 7, 2009
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
NSString *appName;
appName = (NSString *) [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
if (appName == nil)
appName = [[NSProcessInfo processInfo] processName];
const char *utf8AppName = [appName UTF8String];
char *text;
text = format(_("About %0"), utf8AppName);
[AboutMenuItem setTitle:[NSString stringWithUTF8String:text]];
free(text);
text = format(_("Hide %0"), utf8AppName);
[HideMenuItem setTitle:[NSString stringWithUTF8String:text]];
free(text);
text = format(_("Quit %0"), utf8AppName);
[QuitMenuItem setTitle:[NSString stringWithUTF8String:text]];
free(text);
174
175
176
177
178
179
180
181
182
183
[MainWindow setTitle:[NSString stringWithUTF8String:winTitle]];
[MainWindow center];
[MainWindow makeKeyAndOrderFront:self];
} // prepareWidgets
- (void)unprepareWidgets
{
[MainWindow orderOut:self];
} // unprepareWidgets
May 7, 2009
May 7, 2009
184
185
186
187
188
189
190
191
192
193
194
195
196
- (void)fireCustomEvent:(CustomEvent)eventType data1:(NSInteger)data1 data2:(NSInteger)data2 atStart:(BOOL)atStart
{
NSEvent *event = [NSEvent otherEventWithType:NSApplicationDefined location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:0 context:nil subtype:(short)eventType data1:data1 data2:data2];
[NSApp postEvent:event atStart:atStart];
[NSApp run]; // event handler _must_ call -[NSApp stop], or you block here forever.
} // fireCustomEvent
- (void)doCustomEvent:(NSEvent*)event
{
printf("custom event!\n");
switch ((CustomEvent) [event subtype])
{
case CUSTOMEVENT_RUNQUEUE:
May 7, 2009
May 7, 2009
197
198
199
200
201
202
203
if ([NSApp modalWindow] != nil)
{
// If we're in a modal thing, so don't break the event loop.
// Just make a note to break it later.
needToBreakEventLoop = true;
return;
} // if
May 7, 2009
May 7, 2009
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
break; // we just need the -[NSApp stop] call.
case CUSTOMEVENT_MSGBOX:
[self doMsgBox:(const char *)[event data1] text:(const char *)[event data2]];
break;
case CUSTOMEVENT_PROMPTYN:
[self doPromptYN:(const char *)[event data1] text:(const char *)[event data2]];
break;
case CUSTOMEVENT_PROMPTYNAN:
[self doPromptYNAN:(const char *)[event data1] text:(const char *)[event data2]];
break;
case CUSTOMEVENT_INSERTMEDIA:
[self doInsertMedia:(const char *)[event data1]];
break;
default:
return; // let it go without breaking the event loop.
} // switch
[NSApp stop:self]; // break the event loop.
} // doCustomEvent
- (void)doMsgBox:(const char *)title text:(const char *)text
{
NSString *titlestr = [NSString stringWithUTF8String:title];
NSString *textstr = [NSString stringWithUTF8String:text];
NSString *okstr = [NSString stringWithUTF8String:_("OK")];
NSRunInformationalAlertPanel(titlestr, textstr, okstr, nil, nil);
May 7, 2009
May 7, 2009
230
231
232
233
234
if (needToBreakEventLoop)
{
needToBreakEventLoop = false;
[self fireCustomEvent:CUSTOMEVENT_RUNQUEUE data1:0 data2:0 atStart:NO];
} // if
May 7, 2009
May 7, 2009
235
236
237
238
239
240
241
242
243
244
} // doMsgBox
- (void)doPromptYN:(const char *)title text:(const char *)text
{
NSString *titlestr = [NSString stringWithUTF8String:title];
NSString *textstr = [NSString stringWithUTF8String:text];
NSString *yesstr = [NSString stringWithUTF8String:_("Yes")];
NSString *nostr = [NSString stringWithUTF8String:_("No")];
const NSInteger rc = NSRunAlertPanel(titlestr, textstr, yesstr, nostr, nil);
answerYNAN = ((rc == NSAlertDefaultReturn) ? MOJOGUI_YES : MOJOGUI_NO);
May 7, 2009
May 7, 2009
245
246
247
248
249
if (needToBreakEventLoop)
{
needToBreakEventLoop = false;
[self fireCustomEvent:CUSTOMEVENT_RUNQUEUE data1:0 data2:0 atStart:NO];
} // if
May 7, 2009
May 7, 2009
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
} // doPromptYN
- (void)doPromptYNAN:(const char *)title text:(const char *)text
{
// !!! FIXME
[self doPromptYN:title text:text];
} // doPromptYN
- (void)doInsertMedia:(const char *)medianame
{
NSString *title = [NSString stringWithUTF8String:_("Media change")];
char *fmt = xstrdup(_("Please insert '%0'"));
char *_text = format(fmt, medianame);
NSString *text = [NSString stringWithUTF8String:_text];
free(_text);
free(fmt);
NSString *okstr = [NSString stringWithUTF8String:_("OK")];
NSString *cancelstr = [NSString stringWithUTF8String:_("Cancel")];
const NSInteger rc = NSRunAlertPanel(title, text, okstr, cancelstr, nil);
answerYNAN = ((rc == NSAlertDefaultReturn) ? MOJOGUI_YES : MOJOGUI_NO);
May 7, 2009
May 7, 2009
270
271
272
273
274
if (needToBreakEventLoop)
{
needToBreakEventLoop = false;
[self fireCustomEvent:CUSTOMEVENT_RUNQUEUE data1:0 data2:0 atStart:NO];
} // if
May 7, 2009
May 7, 2009
275
276
277
278
279
280
281
} // doInsertMedia
- (MojoGuiYNAN)getAnswerYNAN
{
return answerYNAN;
} // getAnswerYNAN
282
283
284
285
286
287
288
289
290
291
- (IBAction)backClicked:(NSButton *)sender
{
clickValue = CLICK_BACK;
[NSApp stop:self];
} // backClicked
- (IBAction)cancelClicked:(NSButton *)sender
{
char *title = xstrdup(_("Cancel installation"));
char *text = xstrdup(_("Are you sure you want to cancel installation?"));
May 7, 2009
May 7, 2009
292
[self doPromptYN:title text:text];
293
294
free(title);
free(text);
May 7, 2009
May 7, 2009
295
if (answerYNAN == MOJOGUI_YES)
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
{
clickValue = CLICK_CANCEL;
[NSApp stop:self];
} // if
} // cancelClicked
- (IBAction)nextClicked:(NSButton *)sender
{
clickValue = CLICK_NEXT;
[NSApp stop:self];
} // nextClicked
- (IBAction)browseClicked:(NSButton *)sender
{
// !!! FIXME: write me!
STUBBED("browseClicked");
} // nextClicked
May 7, 2009
May 7, 2009
314
315
316
317
- (IBAction)menuQuit:(NSMenuItem *)sender
{
if (finalPage) // make this work like you clicked "finished".
[self nextClicked:nil];
May 7, 2009
May 7, 2009
318
else if ([CancelButton isEnabled]) // make this work like you clicked "cancel".
May 7, 2009
May 7, 2009
319
320
321
[self cancelClicked:nil];
} // menuQuit
May 7, 2009
May 7, 2009
322
- (int)doPage:(NSString *)pageId title:(const char *)_title canBack:(boolean)canBack canFwd:(boolean)canFwd canCancel:(boolean)canCancel canFwdAtStart:(boolean)canFwdAtStart shouldBlock:(BOOL)shouldBlock
323
324
325
326
327
328
329
330
{
[TitleLabel setStringValue:[NSString stringWithUTF8String:_title]];
clickValue = CLICK_NONE;
canForward = canFwd;
[BackButton setEnabled:canBack ? YES : NO];
[NextButton setEnabled:canFwdAtStart ? YES : NO];
[CancelButton setEnabled:canCancel ? YES : NO];
[TabView selectTabViewItemWithIdentifier:pageId];
May 7, 2009
May 7, 2009
331
332
333
334
335
336
337
if (shouldBlock == NO)
[self fireCustomEvent:CUSTOMEVENT_RUNQUEUE data1:0 data2:0 atStart:NO];
else
{
[NSApp run];
assert(clickValue < CLICK_NONE);
} // else
338
return (int) clickValue;
May 7, 2009
May 7, 2009
339
} // doPage
340
341
342
343
344
345
- (int)doReadme:(const char *)title text:(NSString *)text canBack:(boolean)canBack canFwd:(boolean)canFwd
{
NSRange range = {0, 1}; // reset scrolling to start of text.
[ReadmeText setString:text];
[ReadmeText scrollRangeToVisible:range];
May 7, 2009
May 7, 2009
346
return [self doPage:@"Readme" title:title canBack:canBack canFwd:canFwd canCancel:true canFwdAtStart:canFwd shouldBlock:YES];
347
348
349
350
351
} // doReadme
- (int)doOptions:(MojoGuiSetupOptions *)opts canBack:(boolean)canBack canFwd:(boolean)canFwd
{
// !!! FIXME: write me!
May 7, 2009
May 7, 2009
352
return [self doPage:@"Options" title:_("Options") canBack:canBack canFwd:canFwd canCancel:true canFwdAtStart:canFwd shouldBlock:YES];
353
354
355
356
357
358
} // doOptions
- (char *)doDestination:(const char **)recommends recnum:(int)recnum command:(int *)command canBack:(boolean)canBack canFwd:(boolean)canFwd
{
// !!! FIXME: write me!
const boolean fwdAtStart = ( (recnum > 0) && (*(recommends[0])) );
May 7, 2009
May 7, 2009
359
*command = [self doPage:@"Destination" title:_("Destination") canBack:canBack canFwd:canFwd canCancel:true canFwdAtStart:fwdAtStart shouldBlock:YES];
360
361
362
363
364
365
return xstrdup("/Applications");
} // doDestination
- (int)doProductKey:(const char *)desc fmt:(const char *)fmt buf:(char *)buf buflen:(const int)buflen canBack:(boolean)canBack canFwd:(boolean)canFwd
{
// !!! FIXME: write me!
May 7, 2009
May 7, 2009
366
return [self doPage:@"ProductKey" title:desc canBack:canBack canFwd:canFwd canCancel:true canFwdAtStart:canFwd shouldBlock:YES];
367
368
369
370
} // doProductKey
- (int)doProgress:(const char *)type component:(const char *)component percent:(int)percent item:(const char *)item canCancel:(boolean)canCancel
{
May 7, 2009
May 7, 2009
371
372
373
374
375
376
const BOOL indeterminate = (percent < 0) ? YES : NO;
[ProgressComponentLabel setStringValue:[NSString stringWithUTF8String:component]];
[ProgressItemLabel setStringValue:[NSString stringWithUTF8String:item]];
[ProgressBar setIndeterminate:indeterminate];
if (!indeterminate)
[ProgressBar setDoubleValue:(double)percent];
May 7, 2009
May 7, 2009
377
return [self doPage:@"Progress" title:type canBack:false canFwd:false canCancel:canCancel canFwdAtStart:false shouldBlock:NO];
378
379
380
381
} // doProgress
- (void)doFinal:(const char *)msg
{
May 7, 2009
May 7, 2009
382
finalPage = true;
383
384
[FinalText setStringValue:[NSString stringWithUTF8String:msg]];
[NextButton setTitle:[NSString stringWithUTF8String:_("Finish")]];
May 7, 2009
May 7, 2009
385
[self doPage:@"Final" title:_("Finish") canBack:false canFwd:true canCancel:false canFwdAtStart:true shouldBlock:YES];
386
387
388
} // doFinal
@end // implementation MojoSetupController
May 7, 2009
May 7, 2009
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
// Override [NSApplication sendEvent], so we can catch custom events.
@interface MojoSetupApplication : NSApplication
{
}
- (void)sendEvent:(NSEvent *)event;
@end // interface MojoSetupApplication
@implementation MojoSetupApplication
- (void)sendEvent:(NSEvent *)event
{
if ([event type] == NSApplicationDefined)
[((MojoSetupController *)[self delegate]) doCustomEvent:event];
[super sendEvent:event];
} // sendEvent
@end // implementation MojoSetupApplication
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
static uint8 MojoGui_cocoa_priority(boolean istty)
{
// obviously this is the thing you want on Mac OS X.
return MOJOGUI_PRIORITY_TRY_FIRST;
} // MojoGui_cocoa_priority
static boolean MojoGui_cocoa_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
GAutoreleasePool = [[NSAutoreleasePool alloc] init];
// !!! 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.
May 7, 2009
May 7, 2009
431
432
433
// For NSApp to be our subclass, instead of default NSApplication.
[MojoSetupApplication sharedApplication];
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
if ([NSBundle loadNibNamed:@"MojoSetup" owner:NSApp] == NO)
return false;
// Force NSApp initialization stuff. MojoSetupController is set, in the
// .nib, to be NSApp's delegate. Its applicationDidFinishLaunching calls
// [NSApp stop] to break event loop right away so we can continue.
[NSApp run];
return true; // always succeeds.
} // MojoGui_cocoa_init
static void MojoGui_cocoa_deinit(void)
{
[GAutoreleasePool release];
GAutoreleasePool = nil;
// !!! FIXME: destroy nib and NSApp?
} // MojoGui_cocoa_deinit
May 7, 2009
May 7, 2009
454
static void MojoGui_cocoa_msgbox(const char *title, const char *text)
455
{
May 7, 2009
May 7, 2009
456
[[NSApp delegate] fireCustomEvent:CUSTOMEVENT_MSGBOX data1:(NSInteger)title data2:(NSInteger)text atStart:YES];
457
458
459
} // MojoGui_cocoa_msgbox
May 7, 2009
May 7, 2009
460
static boolean MojoGui_cocoa_promptyn(const char *title, const char *text,
461
462
boolean defval)
{
May 7, 2009
May 7, 2009
463
464
465
466
[[NSApp delegate] fireCustomEvent:CUSTOMEVENT_PROMPTYN data1:(NSInteger)title data2:(NSInteger)text atStart:YES];
const MojoGuiYNAN ynan = [[NSApp delegate] getAnswerYNAN];
assert((ynan == MOJOGUI_YES) || (ynan == MOJOGUI_NO));
return (ynan == MOJOGUI_YES);
467
468
469
470
471
472
473
} // MojoGui_cocoa_promptyn
static MojoGuiYNAN MojoGui_cocoa_promptynan(const char *title,
const char *text,
boolean defval)
{
May 7, 2009
May 7, 2009
474
475
[[NSApp delegate] fireCustomEvent:CUSTOMEVENT_PROMPTYNAN data1:(NSInteger)title data2:(NSInteger)text atStart:YES];
return [[NSApp delegate] getAnswerYNAN];
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
} // MojoGui_cocoa_promptynan
static boolean MojoGui_cocoa_start(const char *title,
const MojoGuiSplash *splash)
{
printf("start\n");
// !!! FIXME: deal with (splash).
[[NSApp delegate] prepareWidgets:title];
return true;
} // MojoGui_cocoa_start
static void MojoGui_cocoa_stop(void)
{
printf("stop\n");
[[NSApp delegate] unprepareWidgets];
} // MojoGui_cocoa_stop
static int MojoGui_cocoa_readme(const char *name, const uint8 *data,
size_t len, boolean can_back,
boolean can_fwd)
{
printf("readme\n");
NSString *str = [[NSString alloc] initWithBytes:data length:len encoding:NSUTF8StringEncoding];
return [[NSApp delegate] doReadme:name text:str canBack:can_back canFwd:can_fwd];
} // MojoGui_cocoa_readme
static int MojoGui_cocoa_options(MojoGuiSetupOptions *opts,
boolean can_back, boolean can_fwd)
{
printf("options\n");
return [[NSApp delegate] doOptions:opts canBack:can_back canFwd:can_fwd];
} // MojoGui_cocoa_options
static char *MojoGui_cocoa_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
{
printf("destination\n");
return [[NSApp delegate] doDestination:recommends recnum:recnum command:command canBack:can_back canFwd:can_fwd];
} // MojoGui_cocoa_destination
static int MojoGui_cocoa_productkey(const char *desc, const char *fmt,
char *buf, const int buflen,
boolean can_back, boolean can_fwd)
{
printf("productkey\n");
return [[NSApp delegate] doProductKey:desc fmt:fmt buf:buf buflen:buflen canBack:can_back canFwd:can_fwd];
} // MojoGui_cocoa_productkey
static boolean MojoGui_cocoa_insertmedia(const char *medianame)
{
printf("insertmedia\n");
May 7, 2009
May 7, 2009
535
536
537
538
[[NSApp delegate] fireCustomEvent:CUSTOMEVENT_INSERTMEDIA data1:(NSInteger)medianame data2:0 atStart:YES];
const MojoGuiYNAN ynan = [[NSApp delegate] getAnswerYNAN];
assert((ynan == MOJOGUI_YES) || (ynan == MOJOGUI_NO));
return (ynan == MOJOGUI_YES);
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
} // MojoGui_cocoa_insertmedia
static void MojoGui_cocoa_progressitem(void)
{
printf("progressitem\n");
// no-op in this UI target.
} // MojoGui_cocoa_progressitem
static int MojoGui_cocoa_progress(const char *type, const char *component,
int percent, const char *item,
boolean can_cancel)
{
printf("progress\n");
return [[NSApp delegate] doProgress:type component:component percent:percent item:item canCancel:can_cancel];
} // MojoGui_cocoa_progress
static void MojoGui_cocoa_final(const char *msg)
{
printf("final\n");
[[NSApp delegate] doFinal:msg];
} // MojoGui_cocoa_final
// end of gui_cocoa.m ...