
#import "MiscArrowButton.subproj/MiscArrowButton.h"
#import "ABInspector.h"

@implementation ABInspector

// Load the Inspector

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

    [bundle getPath: buf forResource: "MiscABInspector" ofType:"nib"];

    [NXApp loadNibFile:buf owner:self withNames:NO fromZone:[self zone]];
		   
    return self;
}


// This method sets all the values in the inspector by getting
// the relevant info from the object. This is called when the
// inspector first appears, so the object's attributes are
// correctly displayed in the inspector.

- revert: sender
{	
	// set all the options
	
    if ([object isBordered])
		[ [optionMatrix cellAt: 0 : 0] setState: 1];
	else
		[ [optionMatrix cellAt: 0 : 0] setState: 0];	

    if ([object isTransparent])
		[ [optionMatrix cellAt: 1 : 0] setState: 1];
	else
		[ [optionMatrix cellAt: 1 : 0] setState: 0];	

    if ([object isContinuous])
		[ [optionMatrix cellAt: 2 : 0] setState: 1];
	else
		[ [optionMatrix cellAt: 2 : 0] setState: 0];	

    if ([object isEnabled])
		[ [optionMatrix cellAt: 3 : 0] setState: 0];
	else
		[ [optionMatrix cellAt: 3 : 0] setState: 1];	

    if ([object state])
		[ [optionMatrix cellAt: 4 : 0] setState: 1];
	else
		[ [optionMatrix cellAt: 4 : 0] setState: 0];	

	// set the title, altTitle, and sound in the inspector
	
	[tagField setIntValue: [object tag] ];
	[titleField setStringValue: [object title] ];
	[altTitleField setStringValue: [object altTitle] ];
	[soundField setStringValue: [ [object sound] name] ];
	
	[optionMatrix display];

	[alignButton setState: [object arrowAlignment] ];
		
	return [super revert: sender];
}



// One of the checkbox buttons was clicked, so change the corresponding
// attribute of the object being inspected.

- optionsChanged:sender
{
  id  cell = [sender selectedCell];
  BOOL  state = [cell state];
  
  	switch ([cell tag])
	{
	  case 0:		// bordered
	  	if (state)
			[object setBordered: YES];
		else
			[object setBordered: NO];
		break;

	  case 1:		// transparent
	  	if (state)
			[object setTransparent: YES];
		else
			[object setTransparent: NO];
		break;

	  case 2:		// continuous
	  	if (state)
			[object setContinuous: YES];
		else
			[object setContinuous: NO];
		break;

	  case 3:		// disabled
	  	if (state)
			[object setEnabled: NO];
		else
			[object setEnabled: YES];
		break;

	  case 4:		// selected
			[object setState: state];
		break;
	 }
		
    return [self ok: sender];
}



- tagChanged: sender
{
  	[object setTag: [sender intValue] ];
	
    return [self ok: sender];
}



- titleChanged: sender
{
	[object setTitle: [sender stringValue] ];
	return [self ok: sender];
}



- altTitleChanged: sender
{
	[object setAltTitle: [sender stringValue] ];
	return [self ok: sender];
}		



- soundChanged: sender
{
	[object setSound: [Sound findSoundFor: [sender stringValue] ] ];
    return [self ok: sender];
}



- alignmentChanged: sender
{
	[object setArrowAlignment: [sender state] ];
	return [self ok: sender];
}



- (BOOL)wantsButtons
{
	return NO;
}


@end
