//----------------------------------------------------------------------------------------------------
//
//	ClockInspector
//
//	Inherits From:		IBInspector
//
//	Declared In:		ClockInspector.h
//
//	Disclaimer
//
//		You may freely copy, distribute and reuse this software and its
//		associated documentation. I disclaim any warranty of any kind, 
//		expressed or implied, as to its fitness for any particular use.
//
//----------------------------------------------------------------------------------------------------
#import "ClockInspector.h"
#import "Clock.h"
#import "SoundWell.h"



@implementation ClockInspector

//----------------------------------------------------------------------------------------------------
//	Private Methods
//----------------------------------------------------------------------------------------------------
+ (const char*) _nib
{
	return "";
}


//----------------------------------------------------------------------------------------------------
//	Initialization and Freeing
//----------------------------------------------------------------------------------------------------
- init
{
    	char 	path[MAXPATHLEN+1];
    	id 		bundle;
		
    	[super init];
    	if (! (bundle = [NXBundle bundleForClass:[self class]])) return nil;
    	if (! ([bundle getPath: path forResource: [[self class] _nib] ofType:"nib"])) return nil;
       	[NXApp loadNibFile:path owner:self withNames:NO ]; 
    	return self;
}


//----------------------------------------------------------------------------------------------------
//	IB Inspector Methods
//----------------------------------------------------------------------------------------------------
- ok:sender
{
	[[NXApp activeDocument] touch];
    	return [super ok:sender];
}


- revert: sender
{
	[[self window] disableDisplay];
	sender = [[inspectButton target] itemList];
	
	switch ([[sender selectedCell] tag])
		{
		case 0:
			[inspectorView setContentView: [optionsWindow contentView]];
			[self revertOptions];
			break;
		case 1:
			[inspectorView setContentView: [timeAndDateWindow contentView]];
			[self revertTimeAndDate];
			break;
		case 2:
			[inspectorView setContentView: [displayWindow contentView]];
			[self revertDisplay];
			break;
		}
		
	[[self window] reenableDisplay];
	[inspectorView display];
	return [super revert: sender];
}


- (BOOL)wantsButtons
{
    	return NO;
}


//----------------------------------------------------------------------------------------------------
//	Reverting Attributes
//----------------------------------------------------------------------------------------------------
- revertOptions
{
	return self;
}


- revertTimeAndDate
{
	if ([object _displayMode] == 1)
		{
		[clockOrAlarmButton setTitle: "Alarm"]; 
		[[[clockOrAlarmButton target] itemList] selectCellWithTag: 1];
		}
	else
		{
		[clockOrAlarmButton setTitle: "Clock"]; 
		[[[clockOrAlarmButton target] itemList] selectCellWithTag: 0];
		}

	[self clockOrAlarm: clockOrAlarmButton];

	[alarmOptions setState: [object isAlarmEnabled] at: 0 :0];
	[alarmOptions setState: [object wantsAlarmIndicator] at: 1 :0];
	[alarmMode selectCellWithTag: [object  _alarmMode]];
	[alarmSound sound: [object alarmSound]];

	return self;
}


- revertDisplay
{
	return self;
}


- revertClockTimeAndDate
{
	[clock clockHour: [object clockHour]];
	[clock clockMinute: [object clockMinute]];
	[clock clockSecond: [object clockSecond]];
	[clock clockMonth: [object clockMonth]];
	[clock clockDay: [object clockDay]];
	[clock clockYear: [object clockYear]];
	[clock update];
	return self;
}


- revertAlarmTimeAndDate
{
	[clock alarmHour: [object alarmHour]];
	[clock alarmMinute: [object alarmMinute]];
	[clock alarmSecond: [object alarmSecond]];
	[clock alarmMonth: [object alarmMonth]];
	[clock alarmDay: [object alarmDay]];
	[clock alarmYear: [object alarmYear]];
	[clock update];
	return self;
}


//----------------------------------------------------------------------------------------------------
//	Setting Attributes
//----------------------------------------------------------------------------------------------------
- setClockOptions: sender
{
	return [self ok:nil];
}


- clockOrAlarm: sender
{
	alarmFlag = [[[[clockOrAlarmButton target] itemList] selectedCell] tag];

	if (alarmFlag)
		{
		[self revertAlarmTimeAndDate];
		[clock showAlarmTime: nil];
		[object showAlarmTime: nil];
		}
	else
		{
		[self revertClockTimeAndDate];
		[clock showClockTime: nil];
		[object showClockTime: nil];
		}

	[[NXApp activeDocument] redrawObject:object];
	return self;
}


- decrementHour: sender
{
	if (alarmFlag)
		{
		[object decrementAlarmHour:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object decrementClockHour:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok:nil];
}


- decrementMinute: sender
{
	if (alarmFlag)
		{
		[object decrementAlarmMinute:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object decrementClockMinute:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok:nil];
}


- decrementSecond: sender
{
	if (alarmFlag)
		{
		[object decrementAlarmSecond:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object decrementClockSecond:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}


- decrementMonth: sender
{
	if (alarmFlag)
		{
		[object decrementAlarmMonth:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object decrementClockMonth:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}


- decrementDay: sender
{
	if (alarmFlag)
		{
		[object decrementAlarmDay:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object decrementClockDay:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}


- decrementYear: sender
{
	if (alarmFlag)
		{
		[object decrementAlarmYear:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object decrementClockYear:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}



- incrementHour: sender
{
	if (alarmFlag)
		{
		[object incrementAlarmHour:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object incrementClockHour:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}


- incrementMinute: sender
{
	if (alarmFlag)
		{
		[object incrementAlarmMinute:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object incrementClockMinute:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}


- incrementSecond: sender
{
	if (alarmFlag)
		{
		[object incrementAlarmSecond:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object incrementClockSecond:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}


- incrementMonth: sender
{
	if (alarmFlag)
		{
		[object incrementAlarmMonth:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object incrementClockMonth:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}


- incrementDay: sender
{
	if (alarmFlag)
		{
		[object incrementAlarmDay:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object incrementClockDay:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}


- incrementYear: sender;
{
	if (alarmFlag)
		{
		[object incrementAlarmYear:nil];
		[self revertAlarmTimeAndDate];
		}
	else
		{
		[object incrementClockYear:nil];
		[self revertClockTimeAndDate];
		}
		
	return [self ok: nil];
}



- alarmOptions: sender
{
	[object enableAlarm: [[sender findCellWithTag: 0] state]];
	[object wantsAlarmIndicator: [[sender findCellWithTag: 1] state]];
	return [self ok: nil];
}


- alarmMode: sender
{
	[object _alarmMode: [[alarmMode selectedCell] tag]];
	return [self ok: nil];
}
	

- alarmSound: sender
{
	[object alarmSound: [alarmSound sound]];
	return [self ok: nil];
}


- playAlarmSound: sender
{
	[alarmSound play: nil];
	return self;
}


- imageOrColor: sender
{
	if ([[colorOrImage selectedCell] tag] == 1)
		[object backgroundColor: [backgroundColor color]];
	else
		[object backgroundImage: [backgroundImage image]];
	
	return [self ok:nil];
}


- setClockBackgroundColor: sender
{
	if ([[colorOrImage selectedCell] tag] == 1) [object backgroundColor: [sender color]];
	return [self ok:nil];
}
	
	
- setClockBackgroundImage: sender
{
	if ([[colorOrImage selectedCell] tag] == 0) 
		[object backgroundImage: [backgroundImage image]];
	return [self ok:nil];
}
	
	
@end