/*
 *    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 "CircularSliderInspector.h"
#import "CircularSlider.subproj/CircularSlider.h"

@implementation CircularSliderInspector

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

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

- ok:sender
{
    [(CircularSlider*)object display];
    return [super ok:sender];
}

- update
{
    if ([(CircularSlider*)object drawAsPieChart] == YES){
	[typeMatrix selectCellAt:0:1];
     }else{
	[typeMatrix selectCellAt:0:0];
     }

    [tagField setIntValue: (int)[(CircularSlider*)object tag]];
    [minValueField setFloatValue: (float)[(CircularSlider*)object minValue]];
    [maxValueField setFloatValue: (float)[(CircularSlider*)object maxValue]];
    [currentValueField setFloatValue: (float)[(CircularSlider*)object floatValue]];

    if ([(CircularSlider*)object isContinuous] == YES)
	[[optionMatrix cellAt:0:0] setState: 1];
    else
	[[optionMatrix cellAt:0:0] setState: 0];

    if ([(CircularSlider*)object isEnabled] == YES)
	[[optionMatrix cellAt:1:0] setState: 0];
    else
	[[optionMatrix cellAt:1:0] setState: 1];

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

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

    [optionMatrix display]; /* This is necessary to tell the matrix
			     * to update its contents (uuuuggggggggggggggg)
			     */
    [boarderMatrix display];
    return self;
}

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

- (BOOL)wantsButtons
{
    return NO;
}

- setType:sender
{
    switch ([[sender selectedCell] tag]){
	case 1: [(CircularSlider*)object setDrawAsPieChart: NO];
	    break;
	case 2: [(CircularSlider*)object setDrawAsPieChart: YES];
	    break;
    }
    [self touch:self];
    return [self ok:sender];
}

- setMaximum:sender
{
    [(CircularSlider*)object setMaxValue:(float)[sender floatValue]];
    [self touch:self];
    [self update];
    return [self ok:sender];
}

- setMinimum:sender
{
    [(CircularSlider*)object setMinValue:(float)[sender floatValue]];
    [self touch:self];
    [self update];
    return [self ok:sender];
}

- setCurrent:sender
{
    [(CircularSlider*)object setFloatValue:(float)[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)
		[(CircularSlider*)object setContinuous:YES];
	    else
		[(CircularSlider*)object setContinuous:NO];
	    break;
	case 2:  /* Disabled */
	    if (state)
		[(CircularSlider*)object setEnabled:NO];
	    else
		[(CircularSlider*)object setEnabled:YES];
	    break;
	case 3:  /* Hidden */
	    if (state){
		[(CircularSlider*)object setHidden:YES];   /* If an Object is Hidden it is also
							    * disabled 
							    */
		[[optionMatrix cellAt:1:0] setEnabled:NO];
	    }else{
		[(CircularSlider*)object setHidden:NO];
		[[optionMatrix cellAt:1:0] setEnabled:YES];
	    }
	    [optionMatrix display];
	    break;

    }    
    [self touch:self];
    return [self ok:sender];
}

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

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

@end
