1 |
asvitkine |
1.1 |
/* |
2 |
asvitkine |
1.6 |
* $Id: prefs_macosx.mm,v 1.5 2010/07/27 02:55:09 asvitkine Exp $ |
3 |
asvitkine |
1.1 |
* |
4 |
|
|
* prefs_macosx.mm - Enables access to SheepShaver preferences while |
5 |
|
|
* SheepShaver is running (on Mac OS X). |
6 |
|
|
* |
7 |
|
|
* Copyright (C) 2007 Alexei Svitkine |
8 |
|
|
* |
9 |
|
|
* This program is free software; you can redistribute it and/or modify |
10 |
|
|
* it under the terms of the GNU General Public License as published by |
11 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
12 |
|
|
* (at your option) any later version. |
13 |
|
|
* |
14 |
|
|
* This program is distributed in the hope that it will be useful, |
15 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 |
|
|
* GNU General Public License for more details. |
18 |
|
|
* |
19 |
|
|
* You should have received a copy of the GNU General Public License |
20 |
|
|
* along with this program; if not, write to the Free Software |
21 |
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "sysdeps.h" |
26 |
|
|
|
27 |
asvitkine |
1.5 |
// The _UINT64 define is needed to guard against a typedef mismatch with Snow Leopard headers. |
28 |
|
|
#define _UINT64 |
29 |
|
|
|
30 |
asvitkine |
1.1 |
#include <Cocoa/Cocoa.h> |
31 |
asvitkine |
1.2 |
#include "VMSettingsController.h" |
32 |
asvitkine |
1.1 |
|
33 |
asvitkine |
1.6 |
|
34 |
asvitkine |
1.1 |
@interface SheepShaverMain : NSObject |
35 |
asvitkine |
1.6 |
{ |
36 |
asvitkine |
1.1 |
NSArray *nibObjects; |
37 |
|
|
NSWindow *prefsWindow; |
38 |
asvitkine |
1.6 |
} |
39 |
asvitkine |
1.1 |
@end |
40 |
|
|
|
41 |
|
|
@implementation SheepShaverMain |
42 |
|
|
|
43 |
|
|
|
44 |
|
|
- (NSArray*) loadPrefsNibFile |
45 |
|
|
{ |
46 |
asvitkine |
1.2 |
NSNib *nib = [[NSNib alloc] initWithNibNamed:@"VMSettingsWindow" bundle:nil]; |
47 |
asvitkine |
1.1 |
NSArray *objects = nil; |
48 |
|
|
|
49 |
asvitkine |
1.2 |
if (![nib instantiateNibWithOwner:[VMSettingsController sharedInstance] topLevelObjects:&objects]) { |
50 |
asvitkine |
1.1 |
NSLog(@"Could not load Prefs NIB file!\n"); |
51 |
|
|
return nil; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
NSLog(@"%d objects loaded\n", [objects count]); |
55 |
|
|
|
56 |
|
|
// Release the raw nib data. |
57 |
|
|
[nib release]; |
58 |
|
|
|
59 |
|
|
// Release the top-level objects so that they are just owned by the array. |
60 |
|
|
[objects makeObjectsPerformSelector:@selector(release)]; |
61 |
|
|
|
62 |
|
|
prefsWindow = nil; |
63 |
|
|
for (int i = 0; i < [objects count]; i++) { |
64 |
|
|
NSObject *object = [objects objectAtIndex:i]; |
65 |
|
|
NSLog(@"Got %@", object); |
66 |
|
|
|
67 |
|
|
if ([object isKindOfClass:[NSWindow class]]) { |
68 |
|
|
prefsWindow = (NSWindow *) object; |
69 |
|
|
break; |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
if (prefsWindow == nil) { |
74 |
|
|
NSLog(@"Could not find NSWindow in Prefs NIB file!\n"); |
75 |
|
|
return nil; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
return objects; |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
- (void) openPreferences:(id)sender |
83 |
|
|
{ |
84 |
asvitkine |
1.3 |
NSAutoreleasePool *pool; |
85 |
|
|
|
86 |
asvitkine |
1.1 |
if (nibObjects == nil) { |
87 |
|
|
nibObjects = [self loadPrefsNibFile]; |
88 |
|
|
if (nibObjects == nil) |
89 |
|
|
return; |
90 |
|
|
[nibObjects retain]; |
91 |
|
|
} |
92 |
|
|
|
93 |
asvitkine |
1.3 |
pool = [[NSAutoreleasePool alloc] init]; |
94 |
asvitkine |
1.2 |
[[VMSettingsController sharedInstance] setupGUI]; |
95 |
asvitkine |
1.1 |
[NSApp runModalForWindow:prefsWindow]; |
96 |
asvitkine |
1.3 |
[pool release]; |
97 |
asvitkine |
1.1 |
} |
98 |
|
|
|
99 |
|
|
@end |
100 |
|
|
|
101 |
|
|
/* |
102 |
|
|
* Initialization |
103 |
|
|
*/ |
104 |
|
|
|
105 |
|
|
void prefs_init(void) |
106 |
|
|
{ |
107 |
asvitkine |
1.4 |
NSAutoreleasePool *pool; |
108 |
asvitkine |
1.1 |
NSMenu *appMenu; |
109 |
|
|
NSMenuItem *menuItem; |
110 |
|
|
|
111 |
asvitkine |
1.4 |
pool = [[NSAutoreleasePool alloc] init]; |
112 |
|
|
|
113 |
asvitkine |
1.1 |
appMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu]; |
114 |
|
|
menuItem = [[NSMenuItem alloc] initWithTitle:@"Preferences..." action:@selector(openPreferences:) keyEquivalent:@","]; |
115 |
|
|
[appMenu insertItem:menuItem atIndex:2]; |
116 |
|
|
[appMenu insertItem:[NSMenuItem separatorItem] atIndex:3]; |
117 |
|
|
[menuItem release]; |
118 |
|
|
|
119 |
|
|
[NSApp setDelegate:[[SheepShaverMain alloc] init]]; |
120 |
asvitkine |
1.4 |
|
121 |
|
|
[pool release]; |
122 |
asvitkine |
1.1 |
} |
123 |
|
|
|
124 |
|
|
|
125 |
|
|
/* |
126 |
|
|
* Deinitialization |
127 |
|
|
*/ |
128 |
|
|
|
129 |
|
|
void prefs_exit(void) |
130 |
|
|
{ |
131 |
|
|
} |