Skip to content

Latest commit

 

History

History
800 lines (693 loc) · 31.8 KB

gui_cocoa.m

File metadata and controls

800 lines (693 loc) · 31.8 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;
May 10, 2009
May 10, 2009
68
69
70
71
72
73
74
IBOutlet NSMenuItem *WindowMenuItem;
IBOutlet NSMenuItem *HideOthersMenuItem;
IBOutlet NSMenuItem *ShowAllMenuItem;
IBOutlet NSMenuItem *ServicesMenuItem;
IBOutlet NSMenuItem *MinimizeMenuItem;
IBOutlet NSMenuItem *ZoomMenuItem;
IBOutlet NSMenuItem *BringAllToFrontMenuItem;
Jun 15, 2009
Jun 15, 2009
75
IBOutlet NSView *OptionsView;
76
77
ClickValue clickValue;
boolean canForward;
May 7, 2009
May 7, 2009
78
boolean needToBreakEventLoop;
May 7, 2009
May 7, 2009
79
boolean finalPage;
May 7, 2009
May 7, 2009
80
MojoGuiYNAN answerYNAN;
Jun 15, 2009
Jun 15, 2009
81
MojoGuiSetupOptions *mojoOpts;
May 7, 2009
May 7, 2009
83
- (void)awakeFromNib;
84
85
86
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
- (void)prepareWidgets:(const char*)winTitle;
- (void)unprepareWidgets;
May 7, 2009
May 7, 2009
87
88
89
90
91
92
93
- (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;
94
95
96
97
- (IBAction)backClicked:(NSButton *)sender;
- (IBAction)cancelClicked:(NSButton *)sender;
- (IBAction)nextClicked:(NSButton *)sender;
- (IBAction)browseClicked:(NSButton *)sender;
May 7, 2009
May 7, 2009
98
- (IBAction)menuQuit:(NSMenuItem *)sender;
May 7, 2009
May 7, 2009
99
- (int)doPage:(NSString *)pageId title:(const char *)_title canBack:(boolean)canBack canFwd:(boolean)canFwd canCancel:(boolean)canCancel canFwdAtStart:(boolean)canFwdAtStart shouldBlock:(BOOL)shouldBlock;
100
- (int)doReadme:(const char *)title text:(NSString *)text canBack:(boolean)canBack canFwd:(boolean)canFwd;
Jun 15, 2009
Jun 15, 2009
101
102
103
104
- (void)setOptionTreeSensitivity:(MojoGuiSetupOptions *)opts enabled:(boolean)val;
- (void)optionToggled:(id)toggle;
- (NSView *)newOptionLevel:(NSView *)box;
- (void)buildOptions:(MojoGuiSetupOptions *)opts view:(NSView *)box sensitive:(boolean)sensitive;
105
106
107
108
109
110
111
112
- (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
113
114
115
116
117
- (void)awakeFromNib
{
clickValue = CLICK_NONE;
canForward = false;
answerYNAN = MOJOGUI_NO;
May 7, 2009
May 7, 2009
118
needToBreakEventLoop = false;
May 7, 2009
May 7, 2009
119
finalPage = false;
Jun 15, 2009
Jun 15, 2009
120
mojoOpts = nil;
May 7, 2009
May 7, 2009
121
122
} // awakeFromNib
123
124
125
126
127
128
129
130
- (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#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;
145
146
147
[BackButton setTitle:[NSString stringWithUTF8String:_("Back")]];
[NextButton setTitle:[NSString stringWithUTF8String:_("Next")]];
[CancelButton setTitle:[NSString stringWithUTF8String:_("Cancel")]];
May 7, 2009
May 7, 2009
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
[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
167
May 10, 2009
May 10, 2009
168
169
170
171
172
173
174
175
[WindowMenuItem setTitle:[NSString stringWithUTF8String:_("Window")]];
[HideOthersMenuItem setTitle:[NSString stringWithUTF8String:_("Hide Others")]];
[ShowAllMenuItem setTitle:[NSString stringWithUTF8String:_("Show All")]];
[ServicesMenuItem setTitle:[NSString stringWithUTF8String:_("Services")]];
[MinimizeMenuItem setTitle:[NSString stringWithUTF8String:_("Minimize")]];
[ZoomMenuItem setTitle:[NSString stringWithUTF8String:_("Zoom")]];
[BringAllToFrontMenuItem setTitle:[NSString stringWithUTF8String:_("Bring All to Front")]];
May 7, 2009
May 7, 2009
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
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);
196
197
198
199
200
201
202
203
204
205
[MainWindow setTitle:[NSString stringWithUTF8String:winTitle]];
[MainWindow center];
[MainWindow makeKeyAndOrderFront:self];
} // prepareWidgets
- (void)unprepareWidgets
{
[MainWindow orderOut:self];
} // unprepareWidgets
May 7, 2009
May 7, 2009
206
207
208
209
210
211
212
213
214
215
216
217
218
- (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
219
220
221
222
223
224
225
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
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
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
252
253
254
255
256
if (needToBreakEventLoop)
{
needToBreakEventLoop = false;
[self fireCustomEvent:CUSTOMEVENT_RUNQUEUE data1:0 data2:0 atStart:NO];
} // if
May 7, 2009
May 7, 2009
257
258
259
260
261
262
263
264
265
266
} // 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
267
268
269
270
271
if (needToBreakEventLoop)
{
needToBreakEventLoop = false;
[self fireCustomEvent:CUSTOMEVENT_RUNQUEUE data1:0 data2:0 atStart:NO];
} // if
May 7, 2009
May 7, 2009
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
} // 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
292
293
294
295
296
if (needToBreakEventLoop)
{
needToBreakEventLoop = false;
[self fireCustomEvent:CUSTOMEVENT_RUNQUEUE data1:0 data2:0 atStart:NO];
} // if
May 7, 2009
May 7, 2009
297
298
299
300
301
302
303
} // doInsertMedia
- (MojoGuiYNAN)getAnswerYNAN
{
return answerYNAN;
} // getAnswerYNAN
304
305
306
307
308
309
310
311
312
313
- (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
314
[self doPromptYN:title text:text];
315
316
free(title);
free(text);
May 7, 2009
May 7, 2009
317
if (answerYNAN == MOJOGUI_YES)
318
319
320
321
322
323
324
325
326
327
328
329
330
331
{
clickValue = CLICK_CANCEL;
[NSApp stop:self];
} // if
} // cancelClicked
- (IBAction)nextClicked:(NSButton *)sender
{
clickValue = CLICK_NEXT;
[NSApp stop:self];
} // nextClicked
- (IBAction)browseClicked:(NSButton *)sender
{
May 10, 2009
May 10, 2009
332
333
334
335
336
337
338
339
340
NSOpenPanel *panel = [NSOpenPanel openPanel];
[panel setTitle:[NSString stringWithUTF8String:_("Destination")]];
[panel setAllowsMultipleSelection:NO];
[panel setCanCreateDirectories:YES];
[panel setCanChooseDirectories:YES];
[panel setCanChooseFiles:NO];
if ([panel runModal] == NSOKButton)
[DestinationCombo setStringValue:[panel filename]];
} // browseClicked
341
May 7, 2009
May 7, 2009
342
343
344
345
- (IBAction)menuQuit:(NSMenuItem *)sender
{
if (finalPage) // make this work like you clicked "finished".
[self nextClicked:nil];
May 7, 2009
May 7, 2009
346
else if ([CancelButton isEnabled]) // make this work like you clicked "cancel".
May 7, 2009
May 7, 2009
347
348
349
[self cancelClicked:nil];
} // menuQuit
May 7, 2009
May 7, 2009
350
- (int)doPage:(NSString *)pageId title:(const char *)_title canBack:(boolean)canBack canFwd:(boolean)canFwd canCancel:(boolean)canCancel canFwdAtStart:(boolean)canFwdAtStart shouldBlock:(BOOL)shouldBlock
351
352
353
354
355
356
357
358
{
[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
359
360
361
362
363
364
365
if (shouldBlock == NO)
[self fireCustomEvent:CUSTOMEVENT_RUNQUEUE data1:0 data2:0 atStart:NO];
else
{
[NSApp run];
assert(clickValue < CLICK_NONE);
} // else
366
return (int) clickValue;
May 7, 2009
May 7, 2009
367
} // doPage
368
369
370
371
372
373
- (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
374
return [self doPage:@"Readme" title:title canBack:canBack canFwd:canFwd canCancel:true canFwdAtStart:canFwd shouldBlock:YES];
375
376
} // doReadme
Jun 15, 2009
Jun 15, 2009
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
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
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
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
- (void)setOptionTreeSensitivity:(MojoGuiSetupOptions *)opts enabled:(boolean)val
{
if (opts != nil)
{
[((id) opts->guiopaque) setEnabled:(val ? YES : NO)];
[self setOptionTreeSensitivity:opts->next_sibling enabled:val];
[self setOptionTreeSensitivity:opts->child enabled:(val && opts->value)];
} // if
} // setOptionTreeSensitivity
- (MojoGuiSetupOptions *)findMojoOption:(id)obj opt:(MojoGuiSetupOptions *)opt
{
// !!! FIXME: this is not ideal. How can we attach this pointer to
// !!! FIXME: the objects themselves so we don't have to walk a tree
// !!! FIXME: to find it on each action? The objects are controls
// !!! FIXME: and cells (distinct classes), and I don't control the
// !!! FIXME: creation of all of them (radio buttons).
// !!! FIXME: Alternately, let's just hold a hashtable to map
// !!! FIXME: objects to options without walking this tree.
if (opt == nil)
return nil;
MojoGuiSetupOptions *i;
for (i = opt; i != nil; i = i->next_sibling)
{
if (i->guiopaque == ((void *) obj))
return i;
MojoGuiSetupOptions *rc = [self findMojoOption:obj opt:i->child];
if (rc != nil)
return rc;
} // for
return [self findMojoOption:obj opt:opt->child];
} // findMojoOption
- (void)optionToggled:(id)toggle
{
MojoGuiSetupOptions *opts = [self findMojoOption:toggle opt:mojoOpts];
assert(opts != nil);
// !!! FIXME: cast is wrong. use a selector?
const boolean enabled = ([((NSControl*)toggle) isEnabled] == YES);
opts->value = enabled;
[self setOptionTreeSensitivity:opts->child enabled:enabled];
} // optionToggled
- (NSView *)newOptionLevel:(NSView *)box
{
NSRect frame = NSMakeRect(10, 10, 10, 10);
NSView *widget = [[NSView alloc] initWithFrame:frame];
[box addSubview:widget positioned:NSWindowBelow relativeTo:nil];
[widget release]; // (box) owns it now.
return widget;
} // newOptionLevel
// !!! FIXME: most of this mess is cut, pasted, and Cocoaized from the
// !!! FIXME: GTK+ GUI. Can we abstract this in the high level and just
// !!! FIXME: implement the target-specific bits in the plugins?
- (void)buildOptions:(MojoGuiSetupOptions *)opts view:(NSView *)box sensitive:(boolean)sensitive
{
NSRect frame = NSMakeRect(10, 10, 10, 10);
if (opts != nil)
{
if (opts->is_group_parent)
{
MojoGuiSetupOptions *kids = opts->child;
NSView *childbox = nil;
//GtkWidget *alignment = gtk_alignment_new(0.0, 0.5, 0, 0);
//gtk_widget_show(alignment);
// !!! FIXME: disable line wrap?
// !!! FIXME: resize on superview resize?
NSTextField *widget = [[NSTextField alloc] initWithFrame:frame];
[widget setStringValue:[NSString stringWithUTF8String:opts->description]];
[widget setEnabled:(sensitive ? YES : NO)];
[widget setEditable:NO];
[widget setSelectable:NO];
[widget setBordered:NO];
[widget setBezeled:NO];
[widget setAlignment:NSLeftTextAlignment];
[widget sizeToFit];
if (opts->tooltip != nil)
[widget setToolTip:[NSString stringWithUTF8String:opts->tooltip]];
[box addSubview:widget positioned:NSWindowBelow relativeTo:nil];
[widget release]; // (box) owns it now.
//!!! FIXME[box sizeToFit];
childbox = [self newOptionLevel:box];
NSButtonCell *prototype = [[NSButtonCell alloc] init];
[prototype setButtonType:NSRadioButton];
[prototype setAllowsMixedState:NO];
NSMatrix *matrix = [[NSMatrix alloc] initWithFrame:frame mode:NSRadioModeMatrix prototype:(NSCell *)prototype numberOfRows:0 numberOfColumns:1];
int row = 0;
while (kids)
{
[matrix addRow];
NSButtonCell *cell = (NSButtonCell *) [matrix cellAtRow:row column:0];
kids->guiopaque = cell;
[cell setTitle:[NSString stringWithUTF8String:kids->description]];
[matrix setState:(kids->value ? NSOnState : NSOffState) atRow:row column:0];
[cell setEnabled:(kids->value ? YES : NO)];
[cell setTarget:self];
[cell setAction:@selector(optionToggled:)];
if (kids->tooltip != nil)
[matrix setToolTip:[NSString stringWithUTF8String:kids->tooltip] forCell:cell];
if (kids->child != nil)
[self buildOptions:kids->child view:[self newOptionLevel:childbox] sensitive:sensitive];
kids = kids->next_sibling;
row++;
} // while
[matrix sizeToCells];
[childbox addSubview:matrix positioned:NSWindowBelow relativeTo:nil];
[matrix release]; // childbox owns it now.
//!!! FIXME: [childbox sizeToFit];
//!!! FIXME: [[childbox superview] sizeToFit];
} // if
else
{
NSButton *widget = [[NSButton alloc] initWithFrame:frame];
opts->guiopaque = widget;
[widget setAllowsMixedState:NO];
[widget setTitle:[NSString stringWithUTF8String:opts->description]];
[widget setState:(opts->value ? NSOnState : NSOffState)];
[widget setEnabled:(sensitive ? YES : NO)];
[widget setTarget:self];
[widget setAction:@selector(optionToggled:)];
[box addSubview:widget positioned:NSWindowBelow relativeTo:nil];
[widget release]; // (box) owns it now.
//!!!FIXME:[box sizeToFit];
if (opts->tooltip != nil)
[widget setToolTip:[NSString stringWithUTF8String:opts->tooltip]];
if (opts->child != nil)
[self buildOptions:opts->child view:[self newOptionLevel:box] sensitive:((sensitive) && (opts->value))];
} // else
[self buildOptions:opts->next_sibling view:box sensitive:sensitive];
} // if
//!!! FIXME:[box sizeToFit];
} // buildOptions
524
525
- (int)doOptions:(MojoGuiSetupOptions *)opts canBack:(boolean)canBack canFwd:(boolean)canFwd
{
Jun 15, 2009
Jun 15, 2009
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
// add all the option widgets to the page's view.
[self buildOptions:opts view:OptionsView sensitive:true];
// run the page.
mojoOpts = opts;
int retval = [self doPage:@"Options" title:_("Options") canBack:canBack canFwd:canFwd canCancel:true canFwdAtStart:canFwd shouldBlock:YES];
mojoOpts = nil;
// we're done, so nuke everything from the view.
NSArray *array = [[OptionsView subviews] copy];
NSEnumerator *enumerator = [array objectEnumerator];
NSView *obj;
while ((obj = (NSView *) [enumerator nextObject]) != nil)
[obj removeFromSuperviewWithoutNeedingDisplay];
[OptionsView setNeedsDisplay:YES];
[enumerator release];
[array release];
return retval;
545
546
547
548
549
} // doOptions
- (char *)doDestination:(const char **)recommends recnum:(int)recnum command:(int *)command canBack:(boolean)canBack canFwd:(boolean)canFwd
{
const boolean fwdAtStart = ( (recnum > 0) && (*(recommends[0])) );
May 7, 2009
May 7, 2009
550
551
552
553
554
555
556
557
558
559
560
int i;
[DestinationCombo removeAllItems];
for (i = 0; i < recnum; i++)
[DestinationCombo addItemWithObjectValue:[NSString stringWithUTF8String:recommends[i]]];
if (recnum > 0)
[DestinationCombo setStringValue:[NSString stringWithUTF8String:recommends[0]]];
else
[DestinationCombo setStringValue:@""];
May 7, 2009
May 7, 2009
561
*command = [self doPage:@"Destination" title:_("Destination") canBack:canBack canFwd:canFwd canCancel:true canFwdAtStart:fwdAtStart shouldBlock:YES];
May 7, 2009
May 7, 2009
562
563
564
565
char *retval = xstrdup([[DestinationCombo stringValue] UTF8String]);
[DestinationCombo removeAllItems];
[DestinationCombo setStringValue:@""];
return retval;
566
567
568
569
570
} // 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
571
return [self doPage:@"ProductKey" title:desc canBack:canBack canFwd:canFwd canCancel:true canFwdAtStart:canFwd shouldBlock:YES];
572
573
574
575
} // 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
576
577
578
579
580
581
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
582
return [self doPage:@"Progress" title:type canBack:false canFwd:false canCancel:canCancel canFwdAtStart:false shouldBlock:NO];
583
584
585
586
} // doProgress
- (void)doFinal:(const char *)msg
{
May 7, 2009
May 7, 2009
587
finalPage = true;
588
589
[FinalText setStringValue:[NSString stringWithUTF8String:msg]];
[NextButton setTitle:[NSString stringWithUTF8String:_("Finish")]];
May 7, 2009
May 7, 2009
590
[self doPage:@"Final" title:_("Finish") canBack:false canFwd:true canCancel:false canFwdAtStart:true shouldBlock:YES];
591
592
593
} // doFinal
@end // implementation MojoSetupController
May 7, 2009
May 7, 2009
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
// 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
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
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
May 12, 2009
May 12, 2009
631
GAutoreleasePool = [[NSAutoreleasePool alloc] init];
632
633
634
635
// !!! 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
636
637
638
// For NSApp to be our subclass, instead of default NSApplication.
[MojoSetupApplication sharedApplication];
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
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
659
static void MojoGui_cocoa_msgbox(const char *title, const char *text)
660
{
May 12, 2009
May 12, 2009
661
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
May 7, 2009
May 7, 2009
662
[[NSApp delegate] fireCustomEvent:CUSTOMEVENT_MSGBOX data1:(NSInteger)title data2:(NSInteger)text atStart:YES];
May 12, 2009
May 12, 2009
663
[pool release];
664
665
666
} // MojoGui_cocoa_msgbox
May 7, 2009
May 7, 2009
667
static boolean MojoGui_cocoa_promptyn(const char *title, const char *text,
668
669
boolean defval)
{
May 12, 2009
May 12, 2009
670
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
May 7, 2009
May 7, 2009
671
672
[[NSApp delegate] fireCustomEvent:CUSTOMEVENT_PROMPTYN data1:(NSInteger)title data2:(NSInteger)text atStart:YES];
const MojoGuiYNAN ynan = [[NSApp delegate] getAnswerYNAN];
May 12, 2009
May 12, 2009
673
[pool release];
May 7, 2009
May 7, 2009
674
675
assert((ynan == MOJOGUI_YES) || (ynan == MOJOGUI_NO));
return (ynan == MOJOGUI_YES);
676
677
678
679
680
681
682
} // MojoGui_cocoa_promptyn
static MojoGuiYNAN MojoGui_cocoa_promptynan(const char *title,
const char *text,
boolean defval)
{
May 12, 2009
May 12, 2009
683
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
May 7, 2009
May 7, 2009
684
[[NSApp delegate] fireCustomEvent:CUSTOMEVENT_PROMPTYNAN data1:(NSInteger)title data2:(NSInteger)text atStart:YES];
May 12, 2009
May 12, 2009
685
686
687
const MojoGuiYNAN retval = [[NSApp delegate] getAnswerYNAN];
[pool release];
return retval;
688
689
690
691
692
693
694
} // MojoGui_cocoa_promptynan
static boolean MojoGui_cocoa_start(const char *title,
const MojoGuiSplash *splash)
{
printf("start\n");
May 12, 2009
May 12, 2009
695
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
696
697
// !!! FIXME: deal with (splash).
[[NSApp delegate] prepareWidgets:title];
May 12, 2009
May 12, 2009
698
[pool release];
699
700
701
702
703
704
705
return true;
} // MojoGui_cocoa_start
static void MojoGui_cocoa_stop(void)
{
printf("stop\n");
May 12, 2009
May 12, 2009
706
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
707
[[NSApp delegate] unprepareWidgets];
May 12, 2009
May 12, 2009
708
[pool release];
709
710
711
712
713
714
715
716
} // 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");
May 12, 2009
May 12, 2009
717
718
719
720
721
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *str = [[[NSString alloc] initWithBytes:data length:len encoding:NSUTF8StringEncoding] autorelease];
const int retval = [[NSApp delegate] doReadme:name text:str canBack:can_back canFwd:can_fwd];
[pool release];
return retval;
722
723
724
725
726
727
728
} // MojoGui_cocoa_readme
static int MojoGui_cocoa_options(MojoGuiSetupOptions *opts,
boolean can_back, boolean can_fwd)
{
printf("options\n");
May 12, 2009
May 12, 2009
729
730
731
732
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const int retval = [[NSApp delegate] doOptions:opts canBack:can_back canFwd:can_fwd];
[pool release];
return retval;
733
734
735
736
737
738
739
740
} // MojoGui_cocoa_options
static char *MojoGui_cocoa_destination(const char **recommends, int recnum,
int *command, boolean can_back,
boolean can_fwd)
{
printf("destination\n");
May 12, 2009
May 12, 2009
741
742
743
744
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
char *retval = [[NSApp delegate] doDestination:recommends recnum:recnum command:command canBack:can_back canFwd:can_fwd];
[pool release];
return retval;
745
746
747
748
749
750
751
752
} // 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");
May 12, 2009
May 12, 2009
753
754
755
756
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const int retval = [[NSApp delegate] doProductKey:desc fmt:fmt buf:buf buflen:buflen canBack:can_back canFwd:can_fwd];
[pool release];
return retval;
757
758
759
760
761
762
} // MojoGui_cocoa_productkey
static boolean MojoGui_cocoa_insertmedia(const char *medianame)
{
printf("insertmedia\n");
May 12, 2009
May 12, 2009
763
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
May 7, 2009
May 7, 2009
764
765
766
[[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));
May 12, 2009
May 12, 2009
767
[pool release];
May 7, 2009
May 7, 2009
768
return (ynan == MOJOGUI_YES);
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
} // 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");
May 12, 2009
May 12, 2009
784
785
786
787
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
const int retval = [[NSApp delegate] doProgress:type component:component percent:percent item:item canCancel:can_cancel];
[pool release];
return retval;
788
789
790
791
792
793
} // MojoGui_cocoa_progress
static void MojoGui_cocoa_final(const char *msg)
{
printf("final\n");
May 12, 2009
May 12, 2009
794
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
795
[[NSApp delegate] doFinal:msg];
May 12, 2009
May 12, 2009
796
[pool release];
797
798
799
} // MojoGui_cocoa_final
// end of gui_cocoa.m ...