ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/MacOSX/prefs_macosx.mm
Revision: 1.6
Committed: 2010-08-22T19:33:25Z (13 years, 8 months ago) by asvitkine
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +4 -1 lines
Log Message:
add braces around @interface declaration to compile with clang

File Contents

# Content
1 /*
2 * $Id: prefs_macosx.mm,v 1.5 2010/07/27 02:55:09 asvitkine Exp $
3 *
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 // The _UINT64 define is needed to guard against a typedef mismatch with Snow Leopard headers.
28 #define _UINT64
29
30 #include <Cocoa/Cocoa.h>
31 #include "VMSettingsController.h"
32
33
34 @interface SheepShaverMain : NSObject
35 {
36 NSArray *nibObjects;
37 NSWindow *prefsWindow;
38 }
39 @end
40
41 @implementation SheepShaverMain
42
43
44 - (NSArray*) loadPrefsNibFile
45 {
46 NSNib *nib = [[NSNib alloc] initWithNibNamed:@"VMSettingsWindow" bundle:nil];
47 NSArray *objects = nil;
48
49 if (![nib instantiateNibWithOwner:[VMSettingsController sharedInstance] topLevelObjects:&objects]) {
50 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 NSAutoreleasePool *pool;
85
86 if (nibObjects == nil) {
87 nibObjects = [self loadPrefsNibFile];
88 if (nibObjects == nil)
89 return;
90 [nibObjects retain];
91 }
92
93 pool = [[NSAutoreleasePool alloc] init];
94 [[VMSettingsController sharedInstance] setupGUI];
95 [NSApp runModalForWindow:prefsWindow];
96 [pool release];
97 }
98
99 @end
100
101 /*
102 * Initialization
103 */
104
105 void prefs_init(void)
106 {
107 NSAutoreleasePool *pool;
108 NSMenu *appMenu;
109 NSMenuItem *menuItem;
110
111 pool = [[NSAutoreleasePool alloc] init];
112
113 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
121 [pool release];
122 }
123
124
125 /*
126 * Deinitialization
127 */
128
129 void prefs_exit(void)
130 {
131 }