1/* 2 PrefsController.m 3 4 Preferences window controller class 5 6 Copyright (C) 2001 Dusk to Dawn Computing, Inc. 7 8 Author: Jeff Teunissen <deek@d2dc.net> 9 Date: 11 Nov 2001 10 11 This program is free software; you can redistribute it and/or 12 modify it under the terms of the GNU General Public License as 13 published by the Free Software Foundation; either version 2 of 14 the License, or (at your option) any later version. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 20 See the GNU General Public License for more details. 21 22 You should have received a copy of the GNU General Public 23 License along with this program; if not, write to: 24 25 Free Software Foundation, Inc. 26 59 Temple Place - Suite 330 27 Boston, MA 02111-1307, USA 28*/ 29static const char rcsid[] = 30 "$Id: PrefsController.m,v 1.5 2002/06/08 09:26:13 deek Exp $"; 31 32#ifdef HAVE_CONFIG_H 33# include "Config.h" 34#endif 35 36#import <Foundation/NSDebug.h> 37 38#import <AppKit/NSApplication.h> 39#import <AppKit/NSNibLoading.h> 40 41#import <PrefsModule/PrefsModule.h> 42 43#import "PrefsController.h" 44 45@implementation PrefsController 46 47static PrefsController *sharedInstance = nil; 48static NSMutableArray *prefsViews = nil; 49static id <PrefsModule> currentModule = nil; 50 51+ (PrefsController *) sharedPrefsController 52{ 53 return (sharedInstance ? sharedInstance : [[self alloc] init]); 54} 55 56- (id) init 57{ 58 if (sharedInstance) { 59 [self dealloc]; 60 } else { 61 self = [super init]; 62 prefsViews = [[[NSMutableArray alloc] initWithCapacity: 5] retain]; 63 } 64 sharedInstance = self; 65 return sharedInstance; 66} 67 68/* 69 awakeFromNib 70 71 Initialize stuff that can't be set in the nib/gorm file. 72*/ 73- (void) awakeFromNib 74{ 75 // Let the systen keep track of where it belongs 76 [window setFrameAutosaveName: @"Preferences"]; 77 [window setFrameUsingName: @"Preferences"]; 78 79 if (iconList) // stop processing if we already have an icon list 80 return; 81 82 /* What is the matrix? :) */ 83 iconList = [[NSMatrix alloc] initWithFrame: NSMakeRect (0, 0, 64*30, 64)]; 84 [iconList setCellClass: [NSButtonCell class]]; 85 [iconList setCellSize: NSMakeSize (64, 64)]; 86 [iconList setMode: NSRadioModeMatrix]; 87 88 [iconScrollView setDocumentView: iconList]; 89 [iconScrollView setHasHorizontalScroller: YES]; 90 [iconScrollView setHasVerticalScroller: NO]; 91} 92 93- (void) dealloc 94{ 95 NSDebugLog (@"PrefsController -dealloc"); 96 97 [prefsViews release]; 98 [super dealloc]; 99} 100 101- (void) windowWillClose: (NSNotification *) aNotification 102{ 103} 104 105- (BOOL) registerPrefsModule: (id <PrefsModule>) aPrefsModule; 106{ 107 NSButtonCell *button = [[NSButtonCell alloc] init]; 108 109 if (!aPrefsModule) 110 return NO; 111 112 if (! [prefsViews containsObject: aPrefsModule]) { 113 [prefsViews addObject: aPrefsModule]; 114 } 115 116 [button setTitle: [aPrefsModule buttonCaption]]; 117 [button setFont: [NSFont systemFontOfSize: 9]]; 118 [button setImage: [aPrefsModule buttonImage]]; 119 [button setImagePosition: NSImageOnly]; 120 [button setHighlightsBy: NSChangeBackgroundCellMask]; 121 [button setShowsStateBy: NSChangeBackgroundCellMask]; 122 [button setTarget: aPrefsModule]; 123 [button setAction: [aPrefsModule buttonAction]]; 124 125 [iconList addColumnWithCells: [NSArray arrayWithObject: button]]; 126 [iconList sizeToCells]; 127 128 [aPrefsModule autorelease]; 129 return YES; 130} 131 132- (BOOL) setCurrentModule: (id <PrefsModule>) aPrefsModule; 133{ 134 if (!aPrefsModule || ![aPrefsModule view]) 135 return NO; 136 137 currentModule = aPrefsModule; 138 [prefsViewBox setContentView: [currentModule view]]; 139 [window setTitle: [currentModule buttonCaption]]; 140 return YES; 141} 142 143- (id) window; 144{ 145 return window; 146} 147 148- (id) currentModule; 149{ 150 return currentModule; 151} 152@end 153