2006-07-01 01:40:18 +00:00
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
|
|
|
#include "baselayer.h"
|
|
|
|
|
2012-03-08 19:16:06 +00:00
|
|
|
static id nsapp;
|
|
|
|
|
2006-07-01 01:40:18 +00:00
|
|
|
@interface StartupWinController : NSWindowController
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
IBOutlet NSButton *alwaysShowButton;
|
|
|
|
IBOutlet NSButton *fullscreenButton;
|
|
|
|
IBOutlet NSTextView *messagesView;
|
|
|
|
IBOutlet NSTabView *tabView;
|
|
|
|
IBOutlet NSComboBox *videoModeCbox;
|
|
|
|
|
|
|
|
IBOutlet NSButton *cancelButton;
|
|
|
|
IBOutlet NSButton *startButton;
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)alwaysShowClicked:(id)sender;
|
|
|
|
- (IBAction)fullscreenClicked:(id)sender;
|
|
|
|
|
|
|
|
- (IBAction)cancel:(id)sender;
|
|
|
|
- (IBAction)start:(id)sender;
|
|
|
|
|
|
|
|
- (void)setupRunMode;
|
|
|
|
- (void)setupMessagesMode;
|
|
|
|
- (void)putsMessage:(NSString *)str;
|
|
|
|
- (void)setTitle:(NSString *)str;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation StartupWinController
|
|
|
|
|
|
|
|
- (IBAction)alwaysShowClicked:(id)sender
|
|
|
|
{
|
2014-10-19 00:44:23 +00:00
|
|
|
UNREFERENCED_PARAMETER(sender);
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)fullscreenClicked:(id)sender
|
|
|
|
{
|
2014-10-19 00:44:23 +00:00
|
|
|
UNREFERENCED_PARAMETER(sender);
|
2014-10-16 21:03:24 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
// XXX: recalculate the video modes list to take into account the fullscreen status
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)cancel:(id)sender
|
|
|
|
{
|
2014-10-19 00:44:23 +00:00
|
|
|
UNREFERENCED_PARAMETER(sender);
|
2014-10-16 21:03:24 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
[nsapp abortModal];
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)start:(id)sender
|
|
|
|
{
|
2014-10-19 00:44:23 +00:00
|
|
|
UNREFERENCED_PARAMETER(sender);
|
2014-10-16 21:03:24 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
// XXX: write the states of the form controls to their respective homes
|
|
|
|
[nsapp stopModal];
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupRunMode
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
// XXX: populate the lists and set everything up to represent the current options
|
|
|
|
|
|
|
|
// enable all the controls on the Configuration page
|
|
|
|
NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
|
|
|
|
NSControl *control;
|
2012-03-26 05:04:21 +00:00
|
|
|
while ((control = [enumerator nextObject]))
|
2012-03-08 19:16:47 +00:00
|
|
|
[control setEnabled:true];
|
|
|
|
|
|
|
|
[cancelButton setEnabled:true];
|
|
|
|
[startButton setEnabled:true];
|
|
|
|
|
|
|
|
[tabView selectTabViewItemAtIndex:0];
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupMessagesMode
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
[tabView selectTabViewItemAtIndex:1];
|
|
|
|
|
|
|
|
// disable all the controls on the Configuration page except "always show", so the
|
|
|
|
// user can enable it if they want to while waiting for something else to happen
|
|
|
|
NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator];
|
|
|
|
NSControl *control;
|
2012-03-26 05:04:21 +00:00
|
|
|
while ((control = [enumerator nextObject])) {
|
2012-03-08 19:16:47 +00:00
|
|
|
if (control == alwaysShowButton) continue;
|
|
|
|
[control setEnabled:false];
|
|
|
|
}
|
|
|
|
|
|
|
|
[cancelButton setEnabled:false];
|
|
|
|
[startButton setEnabled:false];
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)putsMessage:(NSString *)str
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
NSRange end;
|
|
|
|
NSTextStorage *text = [messagesView textStorage];
|
|
|
|
BOOL shouldAutoScroll;
|
|
|
|
|
|
|
|
shouldAutoScroll = ((int)NSMaxY([messagesView bounds]) == (int)NSMaxY([messagesView visibleRect]));
|
|
|
|
|
|
|
|
end.location = [text length];
|
|
|
|
end.length = 0;
|
|
|
|
|
|
|
|
[text beginEditing];
|
|
|
|
[messagesView replaceCharactersInRange:end withString:str];
|
|
|
|
[text endEditing];
|
|
|
|
|
|
|
|
if (shouldAutoScroll) {
|
|
|
|
end.location = [text length];
|
|
|
|
end.length = 0;
|
|
|
|
[messagesView scrollRangeToVisible:end];
|
|
|
|
}
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setTitle:(NSString *)str
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
[[self window] setTitle:str];
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
static StartupWinController *startwin = nil;
|
|
|
|
|
|
|
|
int startwin_open(void)
|
|
|
|
{
|
2012-03-08 19:16:06 +00:00
|
|
|
nsapp = [NSApplication sharedApplication];
|
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
if (startwin != nil) return 1;
|
|
|
|
|
|
|
|
startwin = [[StartupWinController alloc] initWithWindowNibName:@"startwin.editor"];
|
|
|
|
if (startwin == nil) return -1;
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
[startwin showWindow:nil];
|
|
|
|
[startwin setupMessagesMode];
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
return 0;
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_close(void)
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
if (startwin == nil) return 1;
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
[startwin close];
|
|
|
|
startwin = nil;
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
return 0;
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_puts(const char *s)
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
NSString *ns;
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
if (!s) return -1;
|
|
|
|
if (startwin == nil) return 1;
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2014-10-16 21:03:24 +00:00
|
|
|
ns = [[NSString alloc] initWithUTF8String:s];
|
2012-03-08 19:16:47 +00:00
|
|
|
[startwin putsMessage:ns];
|
|
|
|
[ns release];
|
2006-07-01 01:40:18 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
return 0;
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_settitle(const char *s)
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
NSString *ns;
|
|
|
|
|
|
|
|
if (!s) return -1;
|
|
|
|
if (startwin == nil) return 1;
|
|
|
|
|
2014-10-16 21:03:24 +00:00
|
|
|
ns = [[NSString alloc] initWithUTF8String:s];
|
2012-03-08 19:16:47 +00:00
|
|
|
[startwin setTitle:ns];
|
|
|
|
[ns release];
|
|
|
|
|
|
|
|
return 0;
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_idle(void *v)
|
|
|
|
{
|
2014-10-19 00:44:23 +00:00
|
|
|
UNREFERENCED_PARAMETER(v);
|
2014-10-16 21:03:24 +00:00
|
|
|
|
2012-03-08 19:16:47 +00:00
|
|
|
if (startwin) [[startwin window] displayIfNeeded];
|
|
|
|
return 0;
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int startwin_run(void)
|
|
|
|
{
|
2012-03-08 19:16:47 +00:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
if (startwin == nil) return 0;
|
|
|
|
|
|
|
|
[startwin setupRunMode];
|
|
|
|
|
|
|
|
switch ([nsapp runModalForWindow:[startwin window]]) {
|
2015-10-10 06:57:46 +00:00
|
|
|
#ifdef MAC_OS_X_VERSION_10_9
|
|
|
|
case NSModalResponseStop: retval = 1; break;
|
|
|
|
case NSModalResponseAbort: retval = 0; break;
|
|
|
|
#else
|
2012-03-08 19:16:47 +00:00
|
|
|
case NSRunStoppedResponse: retval = 1; break;
|
|
|
|
case NSRunAbortedResponse: retval = 0; break;
|
2015-10-10 06:57:46 +00:00
|
|
|
#endif
|
2012-03-08 19:16:47 +00:00
|
|
|
default: retval = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
[startwin setupMessagesMode];
|
|
|
|
|
|
|
|
return retval;
|
2006-07-01 01:40:18 +00:00
|
|
|
}
|