33 |
|
#define DEBUG 0 |
34 |
|
#import <debug.h> |
35 |
|
|
36 |
+ |
#import "misc_macosx.h" |
37 |
|
#import "video_macosx.h" |
38 |
|
|
39 |
|
// |
43 |
|
- (id) init |
44 |
|
{ |
45 |
|
#ifdef ENABLE_MULTIPLE |
46 |
< |
emulators = [[NSMutableArray alloc] init]; |
46 |
> |
emulators = [NSMutableArray new]; |
47 |
|
#endif |
48 |
|
return [super init]; |
49 |
|
} |
67 |
|
|
68 |
|
- (void) sendEvent: (NSEvent *)event; |
69 |
|
{ |
70 |
< |
NSEventType type = [event type]; |
71 |
< |
|
72 |
< |
if ( type == NSKeyUp || type == NSKeyDown || type == NSFlagsChanged ) |
72 |
< |
[self dispatchKeyEvent: event |
73 |
< |
type: type]; |
70 |
> |
if ( [self isAnyEmulatorDisplayingSheets] || |
71 |
> |
[[thePrefsEditor window] isVisible] || ! [self isAnyEmulatorRunning] ) |
72 |
> |
[super sendEvent: event]; |
73 |
|
else |
74 |
< |
[self dispatchEvent: event |
75 |
< |
type: type]; |
74 |
> |
{ |
75 |
> |
NSEventType type = [event type]; |
76 |
> |
|
77 |
> |
if ( type == NSKeyUp || type == NSKeyDown || type == NSFlagsChanged ) |
78 |
> |
[self dispatchKeyEvent: event |
79 |
> |
type: type]; |
80 |
> |
else |
81 |
> |
[self dispatchEvent: event |
82 |
> |
type: type]; |
83 |
> |
} |
84 |
|
} |
85 |
|
|
86 |
|
// NSApplication methods which are invoked through delegation |
151 |
|
for ( tmp = 0; tmp < [emulators count], ++tmp ) |
152 |
|
{ |
153 |
|
theEmulator = [emulators objectAtIndex: tmp]; |
154 |
< |
if ( [ theEmulator isRunning ] && [[theEmulator window] isKeyWindow ] ) |
154 |
> |
view = [theEmulator screen]; |
155 |
> |
|
156 |
> |
if ( [ theEmulator isRunning ] && |
157 |
> |
( [[theEmulator window] isKeyWindow] || [view isFullScreen] ) ) |
158 |
|
break; |
159 |
|
} |
160 |
|
|
161 |
|
if ( tmp < [emulators count] ) // i.e. if we exited the for loop |
162 |
|
#else |
163 |
< |
if ( [theEmulator isRunning] && [[theEmulator window] isKeyWindow ] ) |
163 |
> |
view = [theEmulator screen]; |
164 |
> |
|
165 |
> |
if ( [theEmulator isRunning] && |
166 |
> |
( [[theEmulator window] isKeyWindow] || [view isFullScreen] ) ) |
167 |
|
#endif |
168 |
|
{ |
169 |
< |
view = [theEmulator screen]; |
157 |
< |
|
169 |
> |
D(NSLog(@"Got a key event - %d\n", [event keyCode])); |
170 |
|
switch ( type ) |
171 |
|
{ |
172 |
|
case NSKeyUp: |
193 |
|
- (void) dispatchEvent: (NSEvent *)event |
194 |
|
type: (NSEventType)type |
195 |
|
{ |
196 |
+ |
EmulatorView *view; |
197 |
+ |
BOOL fullScreen; |
198 |
+ |
|
199 |
|
#ifdef ENABLE_MULTIPLE |
200 |
|
// We need to work out what window's Emulator should receive these messages |
201 |
|
|
205 |
|
for ( tmp = 0; tmp < [emulators count], ++tmp ) |
206 |
|
{ |
207 |
|
theEmulator = [emulators objectAtIndex: tmp]; |
208 |
< |
if ( [ theEmulator isRunning ] && [[theEmulator window] isMainWindow ] ) |
208 |
> |
view = [theEmulator screen]; |
209 |
> |
fullScreen = [view isFullScreen]; |
210 |
> |
|
211 |
> |
if ( [theEmulator isRunning] && |
212 |
> |
( fullScreen || [[theEmulator window] isMainWindow] ) ) |
213 |
|
break; |
214 |
|
} |
215 |
|
|
216 |
|
if ( tmp < [emulators count] ) // i.e. if we exited the for loop |
217 |
|
#else |
218 |
< |
if ( FULLSCREEN || |
219 |
< |
( [theEmulator isRunning] && [[theEmulator window] isMainWindow ] ) ) |
218 |
> |
view = [theEmulator screen]; |
219 |
> |
fullScreen = [view isFullScreen]; |
220 |
> |
|
221 |
> |
if ( [theEmulator isRunning] && |
222 |
> |
( fullScreen || [[theEmulator window] isMainWindow] ) ) |
223 |
|
#endif |
224 |
|
{ |
225 |
< |
EmulatorView *view = [theEmulator screen]; |
204 |
< |
|
205 |
< |
// if ( [view mouseInView] ) |
206 |
< |
if ( [view mouseInView: event] || FULLSCREEN ) |
225 |
> |
if ( fullScreen || [view mouseInView: event] ) |
226 |
|
{ |
227 |
|
switch ( type ) |
228 |
|
{ |
234 |
|
break; |
235 |
|
case NSLeftMouseDragged: |
236 |
|
case NSMouseMoved: |
237 |
< |
[view processMouseMove: event]; |
237 |
> |
if ( fullScreen ) |
238 |
> |
[view fullscreenMouseMove]; |
239 |
> |
else |
240 |
> |
[view processMouseMove: event]; |
241 |
|
break; |
242 |
|
default: |
243 |
|
[super sendEvent: event]; // NSApplication default |
256 |
|
[super sendEvent: event]; |
257 |
|
} |
258 |
|
|
259 |
+ |
|
260 |
+ |
// Methods to display documentation: |
261 |
+ |
|
262 |
+ |
- (IBAction) HelpHowTo: (id)sender |
263 |
+ |
{ |
264 |
+ |
NSString *path = [[NSBundle mainBundle] pathForResource: @"HowTo" |
265 |
+ |
ofType: @"html"]; |
266 |
+ |
|
267 |
+ |
if ( ! path ) |
268 |
+ |
InfoSheet(@"Cannot find HowTo.html", [theEmulator window]); |
269 |
+ |
else |
270 |
+ |
if ( ! [[NSWorkspace sharedWorkspace] openFile: path |
271 |
+ |
withApplication: @"TextEdit"] ) |
272 |
+ |
InfoSheet(@"Cannot open HowTo.html with TextEdit", [theEmulator window]); |
273 |
+ |
} |
274 |
+ |
|
275 |
+ |
- (IBAction) HelpToDo: (id)sender |
276 |
+ |
{ |
277 |
+ |
NSString *path = [[NSBundle mainBundle] pathForResource: @"ToDo" |
278 |
+ |
ofType: @"html"]; |
279 |
+ |
|
280 |
+ |
if ( ! path ) |
281 |
+ |
InfoSheet(@"Cannot find ToDo.html", [theEmulator window]); |
282 |
+ |
else |
283 |
+ |
if ( ! [[NSWorkspace sharedWorkspace] openFile: path |
284 |
+ |
withApplication: @"TextEdit"] ) |
285 |
+ |
InfoSheet(@"Cannot open ToDo.html with TextEdit", [theEmulator window]); |
286 |
+ |
} |
287 |
+ |
|
288 |
+ |
- (IBAction) HelpVersions: (id)sender |
289 |
+ |
{ |
290 |
+ |
NSString *path = [[NSBundle mainBundle] pathForResource: @"Versions" |
291 |
+ |
ofType: @"html"]; |
292 |
+ |
|
293 |
+ |
if ( ! path ) |
294 |
+ |
InfoSheet(@"Cannot find Versions.html", [theEmulator window]); |
295 |
+ |
else |
296 |
+ |
if ( ! [[NSWorkspace sharedWorkspace] openFile: path |
297 |
+ |
withApplication: @"TextEdit"] ) |
298 |
+ |
InfoSheet(@"Cannot open Versions.html with TextEdit", |
299 |
+ |
[theEmulator window]); |
300 |
+ |
} |
301 |
+ |
|
302 |
+ |
|
303 |
+ |
// Menu items which for managing more than one window |
304 |
+ |
|
305 |
|
#ifdef ENABLE_MULTIPLE |
306 |
|
|
307 |
|
- (IBAction) NewEmulator: (id)sender |
345 |
|
|
346 |
|
#endif |
347 |
|
|
348 |
+ |
- (BOOL) isAnyEmulatorDisplayingSheets |
349 |
+ |
{ |
350 |
+ |
#ifdef ENABLE_MULTIPLE |
351 |
+ |
int tmp; |
352 |
+ |
|
353 |
+ |
for ( tmp = 0; tmp < [emulators count], ++tmp ) |
354 |
+ |
if ( [[[emulators objectAtIndex: tmp] window] attachedSheet] ) |
355 |
+ |
break; |
356 |
+ |
|
357 |
+ |
if ( tmp < [emulators count] ) // i.e. if we exited the for loop |
358 |
+ |
#else |
359 |
+ |
if ( [[theEmulator window] attachedSheet] ) |
360 |
+ |
#endif |
361 |
+ |
return TRUE; |
362 |
+ |
|
363 |
+ |
return FALSE; |
364 |
+ |
} |
365 |
+ |
|
366 |
|
- (BOOL) isAnyEmulatorRunning |
367 |
|
{ |
368 |
|
#ifdef ENABLE_MULTIPLE |