|
|
1.1 root 1: /*
2: Hatari - CreateFloppyController.m
3:
4: This file is distributed under the GNU Public License, version 2 or at
5: your option any later version. Read the file gpl.txt for details.
6:
7: Helper code used by the other Cocoa code files
8:
9: June 2006, Sébastien Molines - Created
10: */
11:
12: #import <Cocoa/Cocoa.h>
13: #import "Shared.h"
14: #import "AlertHooks.h"
15: #include "main.h"
16:
17: @implementation ModalWrapper
18:
19: // Runs an NSWindow modally
20: - (void)runModal:(NSWindow*)window
21: {
22: // Grab the window
23: modalWindow = window;
24:
25: // Set the window's delegate
26: [window setDelegate:self];
27:
28: // Change emulation and UI state
29: GuiOsx_PauseAndSwitchToCocoaUI();
30:
31: // Run it as modal
32: [NSApp runModalForWindow:window];
33:
34: // Restore emulation and UI state
35: GuiOsx_ResumeFromCocoaUI();
36: }
37:
38: // On closure of the NSWindow, end the modal session
39: - (void) windowWillClose:(NSNotification *)notification
40: {
41: NSWindow *windowAboutToClose = [notification object];
42:
43: // Is this our modal window?
44: if (windowAboutToClose == modalWindow)
45: {
46: // Stop the modal loop
47: [NSApp stopModal];
48: }
49: }
50:
51: @end
52:
53: /*-----------------------------------------------------------------------*/
54: /*
55: Helper function to write the contents of a path as an NSString to a string
56: */
57: void GuiOsx_ExportPathString(NSString* path, char* szTarget, size_t cchTarget)
58: {
59: NSCAssert((szTarget), @"Target buffer must not be null.");
60: NSCAssert((cchTarget > 0), @"Target buffer size must be greater than zero.");
61:
62: // Copy the string
63: strncpy(szTarget, [[path stringByExpandingTildeInPath] cString], cchTarget);
64:
65: // Make sure it is null terminated (as strncpy does not null-terminate if the buffer is too small)
66: szTarget[cchTarget - 1] = 0;
67: }
68:
69: /*-----------------------------------------------------------------------*/
70: /*
71: Pauses emulation and gets ready to use Cocoa UI
72: */
73: void GuiOsx_PauseAndSwitchToCocoaUI()
74: {
75: // Pause emulation
1.1.1.2 ! root 76: Main_PauseEmulation(FALSE);
1.1 root 77:
78: // Enable the alert hooks, so that any messages are shown in Cocoa alerts instead of SDL alerts
79: #ifdef ALERT_HOOKS
80: useAlertHooks = TRUE;
81: #endif
82: }
83:
84: /*-----------------------------------------------------------------------*/
85: /*
86: Switches back to emulation mode and resume emulation
87: */
88: void GuiOsx_ResumeFromCocoaUI()
89: {
90: // Disable the alert hooks, so that SDL handle messages
91: #ifdef ALERT_HOOKS
92: useAlertHooks = FALSE;
93: #endif
94:
95: // Resume emulation
96: Main_UnPauseEmulation();
97: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.