
#pragma .h #import <AppKit/AppKit.h>
#pragma .h #import <apps/InterfaceBuilder.h>

#import <IconKit/IKCell.h>

#import "IKCellInspector.h"

@implementation IKCellInspector : IBInspector 
#pragma .h <IBInspectors>
#pragma .h {
#pragma .h 	id
#pragma .h 		look,
#pragma .h 		tag,
#pragma .h 		container,
#pragma .h 		options,
#pragma .h 		layout;
#pragma .h }

#define TITLE				0
#define ICON				1
#define MINIICON			2

#define TAG					0

#define NOCONTAINER			0
#define UNLOCKED			1
#define LOCKED				2
#define REALLYLOCKED		3

#define DRAGGABLE			0
#define DRAGACCEPTING		1
#define EDITABLE			2

#define LEFTSINGLE			0
#define LEFTMULTIPLE		1
#define SINGLE				2
#define MULTIPLE			3




- init
{
    [super init];
    [NSBundle loadNibNamed:@"IKCellInspector" owner:self];
    return self;
}




/*

Reset the various options as needed.  Only changes to the image and title require redrawing.  This code doubtless leaks memory, since it doesn't free the images when it resets them, but it seems rather unsafe to start freeing named images.

*/


- updateLook: sender
{
	NSString * title = [[look cellWithTag:TITLE] stringValue],
                 * icon = [[look cellWithTag:ICON] stringValue],
		 * miniIcon = [[look cellWithTag:MINIICON] stringValue];
	
	[[self object] setTitle:title];
        [[self object] setImage: icon ? [NSImage imageNamed:icon] : nil];
        [[self object] setMiniImage: miniIcon ? [NSImage imageNamed:miniIcon] : nil];
	[self  ok: sender];
	
	return self;
}


- updateContainer: sender
{
    [[self object]  setShelfMode: [[sender  selectedCell]  tag]];
    [self  ok: sender];
	
    return self;
}


- updateOptions: sender
{
    [[self object]  setEditable: [[sender cellWithTag:EDITABLE]  state]];
    [[self object]  setDraggable: [[sender cellWithTag:DRAGGABLE]  state]];
    [[self object]  setDragAccepting: [[sender cellWithTag:DRAGACCEPTING] state]];
    [self  ok: sender];

    return self;
}


- updateLayout: sender
{
    switch([sender  selectedTag]) {
        case LEFTSINGLE:
            [[self object] setMultipleLines:NO];
            [[self object] setAlignment:NSLeftTextAlignment];
            break;
        case LEFTMULTIPLE:
            [[self object] setMultipleLines:YES];
            [[self object] setAlignment:NSLeftTextAlignment];
            break;
        case SINGLE:
            [[self object] setMultipleLines:NO];
            [[self object] setAlignment:NSCenterTextAlignment];
            break;
        case MULTIPLE:
            [[self object] setMultipleLines:YES];
            [[self object] setAlignment:NSCenterTextAlignment];
            break;
            }
    [self  ok: sender];

    return self;
}


- updateTag: sender
{
    [[self object]  setTag: [[sender cellWithTag:TAG]  intValue]];
    [self  ok: sender];

    return self;
}


- (void)ok:(id)sender
{
    [self  touch: self];
    [super  ok: sender];
}


- (void)revert:(id)sender
{
	NSString *title = [[self object] title],
                 *icon = [(NSImage *)[[self object] image] name],
                 *miniIcon = [[[self object] miniImage] name];
	int    	 i;
	
    [[look cellWithTag:TITLE] setStringValue:title ? title : @""];
    [[look cellWithTag:ICON] setStringValue:icon ? icon : @""];
    [[look cellWithTag:MINIICON] setStringValue:miniIcon ? miniIcon : @""];
	
    [[tag cellWithTag:TAG]  setIntValue: [[self object] tag]];

    [[options cellWithTag:EDITABLE]  setIntValue: [[self object] isEditable]];
    [[options cellWithTag:DRAGGABLE]  setIntValue: [[self object] isDraggable]];
    [[options cellWithTag:DRAGACCEPTING]  setIntValue: [[self object] isDragAccepting]];
	
    if([[self object] alignment] == NSCenterTextAlignment) {
        if([[self object]  isMultipleLines]) {
            [layout selectCellWithTag:MULTIPLE];
        } else {
            [layout selectCellWithTag:SINGLE];
        }
    } else if([[self object] alignment] == NSLeftTextAlignment) {
        if([[self object]  isMultipleLines]) {
            [layout selectCellWithTag:LEFTMULTIPLE];
        } else {
            [layout selectCellWithTag:LEFTSINGLE];
        }
    }
    for(i = 0; i < [[container itemArray] count]; i++) {
        if([[[container itemArray] objectAtIndex:i] tag] == [[self object] shelfMode]) {
            [container selectItemAtIndex:i];
            break;
        }
    }
    [super revert: sender];
}


- (BOOL) wantsButtons
{
    return NO;
}


@end
