/*
 *    Filename:	CircularSliderInspector.m 
 *    Created :	Thu Oct 22 00:46:47 1992 
 *    Author  :	Vince DeMarco
 *		<vince@whatnxt.cuc.ab.ca>
 *    LastEditDate was "Sun Nov 15 21:05:03 1992"
 */


#import "MiscCSInspector.h"
#import "MiscCircularSlider.h"

@implementation MiscCircularSliderInspector

- init
{
    char buf[MAXPATHLEN + 1];
    id bundle = [NXBundle bundleForClass:[MiscCircularSlider class]];

    [bundle getPath:buf forResource:"MiscCSInspector" ofType:"nib"];
    [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
    return self;
}

- ok:sender
{
    [object display];
    return [super ok:sender];
}

- update
{
	[typeMatrix selectCellWithTag:[object sliderStyle]];
	[tagField setIntValue:[object tag]];
	[widthField setFloatValue:[object sliderPathWidth]];
	[minValueField setFloatValue:[(Slider *)object minValue]];
	[maxValueField setFloatValue:[(Slider *)object maxValue]];
	[currentValueField setFloatValue:[object floatValue]];
	[[optionMatrix cellAt:0:0] setState:[object isContinuous]];
	[[optionMatrix cellAt:1:0] setState:![object isEnabled]];

    if ([object hidden] == YES) {
		[[optionMatrix cellAt:2:0] setState: 1]; /* If hidden it is disabled */
		[[optionMatrix cellAt:1:0] setEnabled:NO];
	} else {
		[[optionMatrix cellAt:2:0] setState: 0];
		[[optionMatrix cellAt:1:0] setEnabled:YES];
	}

    if ([object isBezeled] == YES) {
		[[borderMatrix cellAt:0:0] setState:0];
		[[borderMatrix cellAt:0:1] setState:0];
		[[borderMatrix cellAt:0:2] setState:1];
	} else if ([object isBordered] == YES) {
	    [[borderMatrix cellAt:0:0] setState:0];
		[[borderMatrix cellAt:0:1] setState:1];
	    [[borderMatrix cellAt:0:2] setState:0];
	} else {
	    [[borderMatrix cellAt:0:0] setState:1];
	    [[borderMatrix cellAt:0:1] setState:0];
	    [[borderMatrix cellAt:0:2] setState:0];
	}

	[optionMatrix display];
	[borderMatrix display];
	return self;
}

- revert:sender
{
	[self update];
	return [super revert:sender];
}

- (BOOL)wantsButtons
{
	return NO;
}

- setType:sender
{
	[object setSliderStyle:[[sender selectedCell] tag]];
	[self touch:self];
	return [self ok:sender];
}

- setMaximum:sender
{
	[object setMaxValue:[sender floatValue]];
	[self touch:self]; [self update];
	return [self ok:sender];
}

- setMinimum:sender
{
	[object setMinValue:[sender floatValue]];
	[self touch:self]; [self update];
	return [self ok:sender];
}

- setCurrent:sender
{
	[object setFloatValue:[sender floatValue]];
	[self touch:self]; [self update];
	return [self ok:sender];
}

- setOptions:sender
{
	int state = [[sender selectedCell] state];
	switch ([[sender selectedCell] tag]){
	case 1: /* Cont */
		if (state)
			[object setContinuous:YES];
		else
			[object setContinuous:NO];
		break;
	case 2:  /* Disabled */
		if (state)
			[object setEnabled:NO];
		else
			[object setEnabled:YES];
		break;
	case 3:  /* Hidden */
		if (state){
			[object setHidden:YES]; /* If Hidden it is also disabled */
			[object setEnabled:NO];
			[[optionMatrix cellAt:1:0] setEnabled:NO];
			[[optionMatrix cellAt:1:0] setState:YES];
		} else {
			[object setHidden:NO];
			[[optionMatrix cellAt:1:0] setEnabled:YES];
	    }
		[optionMatrix display];
		break;
	}    
	[self touch:self];
	return [self ok:sender];
}

- setBorder:sender
{
	switch ([[sender selectedCell] tag]){
	case 1: /* NONE */
			[object setBezeled:NO];
			[object setBordered:NO];
		break;
	case 2: /* Bordered */
			[object setBezeled:NO];
			[object setBordered:YES];
		break;
	case 3: /* Bezeled */
			[object setBordered:NO];
			[object setBezeled:YES];
		break;
	}
	[self touch:self];
	return [self ok:sender];
}

- setTag:sender
{
	[(Cell *)object setTag:[sender intValue]];
	[self touch:self];
	return [self ok:sender];
}

- changeWidth:sender
{
	[object setSliderPathWidth:[sender floatValue]];
	[self touch:self];
	return [self ok:sender];
}

@end
