Subversion Repositories eduke32

Rev

Rev 854 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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