Subversion Repositories eduke32

Rev

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