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