ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/MacOSX/prefs_macosx.mm
Revision: 1.2
Committed: 2009-08-18T18:22:01Z (14 years, 10 months ago) by asvitkine
Branch: MAIN
Changes since 1.1: +5 -5 lines
Log Message:
load the VMSettingsWindow nib for prefs window in SheepShaver

File Contents

# User Rev Content
1 asvitkine 1.1 /*
2 asvitkine 1.2 * $Id: prefs_macosx.mm,v 1.1 2007/07/28 15:46:17 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     #include <Cocoa/Cocoa.h>
28 asvitkine 1.2 #include "VMSettingsController.h"
29 asvitkine 1.1
30     @interface SheepShaverMain : NSObject
31     NSArray *nibObjects;
32     NSWindow *prefsWindow;
33     @end
34    
35     @implementation SheepShaverMain
36    
37    
38     - (NSArray*) loadPrefsNibFile
39     {
40 asvitkine 1.2 NSNib *nib = [[NSNib alloc] initWithNibNamed:@"VMSettingsWindow" bundle:nil];
41 asvitkine 1.1 NSArray *objects = nil;
42    
43 asvitkine 1.2 if (![nib instantiateNibWithOwner:[VMSettingsController sharedInstance] topLevelObjects:&objects]) {
44 asvitkine 1.1 NSLog(@"Could not load Prefs NIB file!\n");
45     return nil;
46     }
47    
48     NSLog(@"%d objects loaded\n", [objects count]);
49    
50     // Release the raw nib data.
51     [nib release];
52    
53     // Release the top-level objects so that they are just owned by the array.
54     [objects makeObjectsPerformSelector:@selector(release)];
55    
56     prefsWindow = nil;
57     for (int i = 0; i < [objects count]; i++) {
58     NSObject *object = [objects objectAtIndex:i];
59     NSLog(@"Got %@", object);
60    
61     if ([object isKindOfClass:[NSWindow class]]) {
62     prefsWindow = (NSWindow *) object;
63     break;
64     }
65     }
66    
67     if (prefsWindow == nil) {
68     NSLog(@"Could not find NSWindow in Prefs NIB file!\n");
69     return nil;
70     }
71    
72     return objects;
73     }
74    
75    
76     - (void) openPreferences:(id)sender
77     {
78     if (nibObjects == nil) {
79     nibObjects = [self loadPrefsNibFile];
80     if (nibObjects == nil)
81     return;
82     [nibObjects retain];
83     }
84    
85 asvitkine 1.2 [[VMSettingsController sharedInstance] setupGUI];
86 asvitkine 1.1 [NSApp runModalForWindow:prefsWindow];
87     }
88    
89     @end
90    
91     /*
92     * Initialization
93     */
94    
95     void prefs_init(void)
96     {
97     NSMenu *appMenu;
98     NSMenuItem *menuItem;
99    
100     appMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu];
101     menuItem = [[NSMenuItem alloc] initWithTitle:@"Preferences..." action:@selector(openPreferences:) keyEquivalent:@","];
102     [appMenu insertItem:menuItem atIndex:2];
103     [appMenu insertItem:[NSMenuItem separatorItem] atIndex:3];
104     [menuItem release];
105    
106     [NSApp setDelegate:[[SheepShaverMain alloc] init]];
107     }
108    
109    
110     /*
111     * Deinitialization
112     */
113    
114     void prefs_exit(void)
115     {
116     }