ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/SheepShaver/src/MacOSX/prefs_macosx.mm
Revision: 1.3
Committed: 2010-01-02T19:24:24Z (14 years, 6 months ago) by asvitkine
Branch: MAIN
Changes since 1.2: +5 -1 lines
Log Message:
[ Tim Douglas <timdoug@gmail.com> ]
use an auto release pool around modal prefs dialog on Mac OS X

File Contents

# User Rev Content
1 asvitkine 1.1 /*
2 asvitkine 1.3 * $Id: prefs_macosx.mm,v 1.2 2009/08/18 18:22:01 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 asvitkine 1.3 NSAutoreleasePool *pool;
79    
80 asvitkine 1.1 if (nibObjects == nil) {
81     nibObjects = [self loadPrefsNibFile];
82     if (nibObjects == nil)
83     return;
84     [nibObjects retain];
85     }
86    
87 asvitkine 1.3 pool = [[NSAutoreleasePool alloc] init];
88 asvitkine 1.2 [[VMSettingsController sharedInstance] setupGUI];
89 asvitkine 1.1 [NSApp runModalForWindow:prefsWindow];
90 asvitkine 1.3 [pool release];
91 asvitkine 1.1 }
92    
93     @end
94    
95     /*
96     * Initialization
97     */
98    
99     void prefs_init(void)
100     {
101     NSMenu *appMenu;
102     NSMenuItem *menuItem;
103    
104     appMenu = [[[NSApp mainMenu] itemAtIndex:0] submenu];
105     menuItem = [[NSMenuItem alloc] initWithTitle:@"Preferences..." action:@selector(openPreferences:) keyEquivalent:@","];
106     [appMenu insertItem:menuItem atIndex:2];
107     [appMenu insertItem:[NSMenuItem separatorItem] atIndex:3];
108     [menuItem release];
109    
110     [NSApp setDelegate:[[SheepShaverMain alloc] init]];
111     }
112    
113    
114     /*
115     * Deinitialization
116     */
117    
118     void prefs_exit(void)
119     {
120     }