Rev 4644 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
194 | terminx | 1 | #import <Cocoa/Cocoa.h> |
2 | |||
3 | #include "baselayer.h" |
||
4 | |||
2429 | helixhorne | 5 | static id nsapp; |
6 | |||
194 | terminx | 7 | @interface StartupWinController : NSWindowController |
8 | { |
||
2431 | helixhorne | 9 | IBOutlet NSButton *alwaysShowButton; |
10 | IBOutlet NSButton *fullscreenButton; |
||
11 | IBOutlet NSTextView *messagesView; |
||
12 | IBOutlet NSTabView *tabView; |
||
13 | IBOutlet NSComboBox *videoModeCbox; |
||
14 | |||
15 | IBOutlet NSButton *cancelButton; |
||
16 | IBOutlet NSButton *startButton; |
||
194 | terminx | 17 | } |
18 | |||
19 | - (IBAction)alwaysShowClicked:(id)sender; |
||
20 | - (IBAction)fullscreenClicked:(id)sender; |
||
21 | |||
22 | - (IBAction)cancel:(id)sender; |
||
23 | - (IBAction)start:(id)sender; |
||
24 | |||
25 | - (void)setupRunMode; |
||
26 | - (void)setupMessagesMode; |
||
27 | - (void)putsMessage:(NSString *)str; |
||
28 | - (void)setTitle:(NSString *)str; |
||
29 | @end |
||
30 | |||
31 | @implementation StartupWinController |
||
32 | |||
33 | - (IBAction)alwaysShowClicked:(id)sender |
||
34 | { |
||
4647 | hendricks2 | 35 | UNREFERENCED_PARAMETER(sender); |
194 | terminx | 36 | } |
37 | |||
38 | - (IBAction)fullscreenClicked:(id)sender |
||
39 | { |
||
4647 | hendricks2 | 40 | UNREFERENCED_PARAMETER(sender); |
4644 | hendricks2 | 41 | |
2431 | helixhorne | 42 | // XXX: recalculate the video modes list to take into account the fullscreen status |
194 | terminx | 43 | } |
44 | |||
45 | - (IBAction)cancel:(id)sender |
||
46 | { |
||
4647 | hendricks2 | 47 | UNREFERENCED_PARAMETER(sender); |
4644 | hendricks2 | 48 | |
2431 | helixhorne | 49 | [nsapp abortModal]; |
194 | terminx | 50 | } |
51 | |||
52 | - (IBAction)start:(id)sender |
||
53 | { |
||
4647 | hendricks2 | 54 | UNREFERENCED_PARAMETER(sender); |
4644 | hendricks2 | 55 | |
2431 | helixhorne | 56 | // XXX: write the states of the form controls to their respective homes |
57 | [nsapp stopModal]; |
||
194 | terminx | 58 | } |
59 | |||
60 | - (void)setupRunMode |
||
61 | { |
||
2431 | helixhorne | 62 | // XXX: populate the lists and set everything up to represent the current options |
194 | terminx | 63 | |
2431 | helixhorne | 64 | // enable all the controls on the Configuration page |
65 | NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator]; |
||
66 | NSControl *control; |
||
2537 | hendricks2 | 67 | while ((control = [enumerator nextObject])) |
2431 | helixhorne | 68 | [control setEnabled:true]; |
194 | terminx | 69 | |
2431 | helixhorne | 70 | [cancelButton setEnabled:true]; |
71 | [startButton setEnabled:true]; |
||
72 | |||
73 | [tabView selectTabViewItemAtIndex:0]; |
||
194 | terminx | 74 | } |
75 | |||
76 | - (void)setupMessagesMode |
||
77 | { |
||
2431 | helixhorne | 78 | [tabView selectTabViewItemAtIndex:1]; |
194 | terminx | 79 | |
2431 | helixhorne | 80 | // disable all the controls on the Configuration page except "always show", so the |
81 | // user can enable it if they want to while waiting for something else to happen |
||
82 | NSEnumerator *enumerator = [[[[tabView tabViewItemAtIndex:0] view] subviews] objectEnumerator]; |
||
83 | NSControl *control; |
||
2537 | hendricks2 | 84 | while ((control = [enumerator nextObject])) { |
2431 | helixhorne | 85 | if (control == alwaysShowButton) continue; |
86 | [control setEnabled:false]; |
||
87 | } |
||
194 | terminx | 88 | |
2431 | helixhorne | 89 | [cancelButton setEnabled:false]; |
90 | [startButton setEnabled:false]; |
||
194 | terminx | 91 | } |
92 | |||
93 | - (void)putsMessage:(NSString *)str |
||
94 | { |
||
2431 | helixhorne | 95 | NSRange end; |
96 | NSTextStorage *text = [messagesView textStorage]; |
||
97 | BOOL shouldAutoScroll; |
||
194 | terminx | 98 | |
2431 | helixhorne | 99 | shouldAutoScroll = ((int)NSMaxY([messagesView bounds]) == (int)NSMaxY([messagesView visibleRect])); |
194 | terminx | 100 | |
2431 | helixhorne | 101 | end.location = [text length]; |
102 | end.length = 0; |
||
194 | terminx | 103 | |
2431 | helixhorne | 104 | [text beginEditing]; |
105 | [messagesView replaceCharactersInRange:end withString:str]; |
||
106 | [text endEditing]; |
||
107 | |||
108 | if (shouldAutoScroll) { |
||
109 | end.location = [text length]; |
||
110 | end.length = 0; |
||
111 | [messagesView scrollRangeToVisible:end]; |
||
112 | } |
||
194 | terminx | 113 | } |
114 | |||
115 | - (void)setTitle:(NSString *)str |
||
116 | { |
||
2431 | helixhorne | 117 | [[self window] setTitle:str]; |
194 | terminx | 118 | } |
119 | |||
120 | @end |
||
121 | |||
122 | static StartupWinController *startwin = nil; |
||
123 | |||
124 | int startwin_open(void) |
||
125 | { |
||
2429 | helixhorne | 126 | nsapp = [NSApplication sharedApplication]; |
127 | |||
2431 | helixhorne | 128 | if (startwin != nil) return 1; |
194 | terminx | 129 | |
2431 | helixhorne | 130 | startwin = [[StartupWinController alloc] initWithWindowNibName:@"startwin.editor"]; |
131 | if (startwin == nil) return -1; |
||
194 | terminx | 132 | |
2431 | helixhorne | 133 | [startwin showWindow:nil]; |
134 | [startwin setupMessagesMode]; |
||
135 | |||
136 | return 0; |
||
194 | terminx | 137 | } |
138 | |||
139 | int startwin_close(void) |
||
140 | { |
||
2431 | helixhorne | 141 | if (startwin == nil) return 1; |
194 | terminx | 142 | |
2431 | helixhorne | 143 | [startwin close]; |
144 | startwin = nil; |
||
194 | terminx | 145 | |
2431 | helixhorne | 146 | return 0; |
194 | terminx | 147 | } |
148 | |||
149 | int startwin_puts(const char *s) |
||
150 | { |
||
2431 | helixhorne | 151 | NSString *ns; |
194 | terminx | 152 | |
2431 | helixhorne | 153 | if (!s) return -1; |
154 | if (startwin == nil) return 1; |
||
194 | terminx | 155 | |
4644 | hendricks2 | 156 | ns = [[NSString alloc] initWithUTF8String:s]; |
2431 | helixhorne | 157 | [startwin putsMessage:ns]; |
158 | [ns release]; |
||
194 | terminx | 159 | |
2431 | helixhorne | 160 | return 0; |
194 | terminx | 161 | } |
162 | |||
163 | int startwin_settitle(const char *s) |
||
164 | { |
||
2431 | helixhorne | 165 | NSString *ns; |
194 | terminx | 166 | |
2431 | helixhorne | 167 | if (!s) return -1; |
168 | if (startwin == nil) return 1; |
||
169 | |||
4644 | hendricks2 | 170 | ns = [[NSString alloc] initWithUTF8String:s]; |
2431 | helixhorne | 171 | [startwin setTitle:ns]; |
172 | [ns release]; |
||
173 | |||
174 | return 0; |
||
194 | terminx | 175 | } |
176 | |||
177 | int startwin_idle(void *v) |
||
178 | { |
||
4647 | hendricks2 | 179 | UNREFERENCED_PARAMETER(v); |
4644 | hendricks2 | 180 | |
2431 | helixhorne | 181 | if (startwin) [[startwin window] displayIfNeeded]; |
182 | return 0; |
||
194 | terminx | 183 | } |
184 | |||
185 | int startwin_run(void) |
||
186 | { |
||
2431 | helixhorne | 187 | int retval; |
188 | |||
189 | if (startwin == nil) return 0; |
||
190 | |||
191 | [startwin setupRunMode]; |
||
192 | |||
193 | switch ([nsapp runModalForWindow:[startwin window]]) { |
||
194 | case NSRunStoppedResponse: retval = 1; break; |
||
195 | case NSRunAbortedResponse: retval = 0; break; |
||
196 | default: retval = -1; |
||
197 | } |
||
198 | |||
199 | [startwin setupMessagesMode]; |
||
200 | |||
201 | return retval; |
||
194 | terminx | 202 | } |