
/* 
	MiscInfoWindowManager.m
*/

// RCS identification information
static char *rcsID = "$Id:$";
static void __AvoidCompilerWarning(void) {if(!rcsID)__AvoidCompilerWarning();}

// Headers
#import <AppKit/AppKit.h>
#import "MiscAppManager.h"

#import "MiscInfoNibManager.h"

// Class Headers
#import "MiscInfoWindowManager.h"

// Module variables (static variables)
static Class _infoNibManagerClass = nil;


@implementation MiscInfoWindowManager

/*"
	MiscInfoWindowManager is a new class in need of a description. 
"*/


//-------------------------------------------------------------------
// Class initialization
//-------------------------------------------------------------------

+ (void) initialize
{
	if (self == [MiscInfoWindowManager class]) {
		[self setInfoNibManagerClass:[MiscInfoNibManager class]];
	}
}


//-------------------------------------------------------------------
// Our info manager
//-------------------------------------------------------------------

+ (MiscInfoWindowManager*) defaultInfoWindowManager
/*"
	Returns the current info window manager if one exists. If it doesn't
	it tries to use the info nib manager returned by #infoNibManagerClass
	to load and create the window manager. We return nil if for some
	reason we couldn't find nor load the info window manager.
"*/
{
	MiscInfoWindowManager* ourInfoWindowManager;
	
	// Try to find our existing info window manager.
	ourInfoWindowManager = 
		[MiscWindowManager windowManagerOfClass:[self class]];

	// If it doesn't exist then load it by loading our info nib 
	// manager.		
	if (ourInfoWindowManager == nil) {
		MiscInfoNibManager* infoNibManager;
		
		infoNibManager = [[[self infoNibManagerClass] alloc]
            initWithBundle:[NSBundle bundleForClass:[self class]]];

		// Should probably check whether the object created is
		// a subclass of MiscInfoNibManager I suppose.
		ourInfoWindowManager = [infoNibManager infoWindowManager];
	}
	
	return ourInfoWindowManager;
}
	
//-------------------------------------------------------------------
// Our info nib manager class
//-------------------------------------------------------------------

+ (Class) infoNibManagerClass
/*"
	Returns the info nib manager class that will be loaded to create
	a new instance of ourself. Our #defaultInfoWindowManager uses this
	method to allocate and initialize our info window manager if it
	doesn't already exist.
"*/
{
	return _infoNibManagerClass;
}


+ (void) setInfoNibManagerClass:(Class)newInfoNibManagerClass
{
	_infoNibManagerClass = newInfoNibManagerClass;
}


//-------------------------------------------------------------------
// Initialization/deallocation
//-------------------------------------------------------------------

- (void) dealloc
/*"
	Releases the UI objects I retained.
"*/
{
	[_applicationNameTF release];
	[_versionTF release];
	[_copyrightTF release];
	[super dealloc];
}


//-------------------------------------------------------------------
// Accessors
//-------------------------------------------------------------------

- (NSTextField*) applicationNameTF { return _applicationNameTF; }

- (void) setApplicationNameTF:(NSTextField*)newTextField
{
	[_applicationNameTF autorelease];
	_applicationNameTF = [newTextField retain];
}


- (NSTextField*) versionTF { return _versionTF; }

- (void) setVersionTF:(NSTextField*)newTextField
{
	[_versionTF autorelease];
	_versionTF = [newTextField retain];
}

- (NSTextField*) copyrightTF { return _copyrightTF; }

- (void) setCopyrightTF:(NSTextField*)newTextField
{
	[_copyrightTF autorelease];
	_copyrightTF = [newTextField retain];
}


//-------------------------------------------------------------------
// Updating the info panel 
//-------------------------------------------------------------------

- (void) updateInfo
/*"
	This method put values in all our textfields in the info panel.
	It is called from our #makeKeyConditionallyAndOrderFront: method.
"*/
{
	NSString* appName = [[NSProcessInfo processInfo] processName];
	
    [[self applicationNameTF] setStringValue:appName];
    [[self versionTF] setStringValue:[[NSApp delegate] appVersion]];
	// Not sure if I'll add copyright info into the MiscAppManager 
	// or not.
    [[self copyrightTF] setStringValue:@"Copyleft 1996, RightCopy"];
}


//-------------------------------------------------------------------
// Extensions
//-------------------------------------------------------------------

- (void) makeKeyConditionallyAndOrderFront:(id)sender
{
    [self updateInfo];
    [super makeKeyConditionallyAndOrderFront:sender];
}

@end

