
#pragma .h #import <AppKit/NSImage.h>
#pragma .h #import "IKIconObject.h"
#pragma .h #import "IKList.h"
#pragma .h 
#pragma .h #import <Foundation/NSString.h>
#pragma .h #import <AppKit/NSDragging.h>

#import <Foundation/NSArchiver.h>
#import <Foundation/NSUtilities.h>

#import <objc/objc-runtime.h>

#import "IKAnnouncer.h"
#import "IKfunctions.h"
#import "IKSuitcase.h"
#import "NSObject.LoadImage.h"

@implementation IKSuitcase: IKList
#pragma .h <IKEditableObject, IKDragAcceptingObject>
#pragma .h {
#pragma .h	NSString		* name,
#pragma .h					* classToHold;
#pragma .h	
#pragma .h	NSImage			*image,
#pragma .h					*miniImage,
#pragma .h					*acceptingDragImage,
#pragma .h 					*miniAcceptingDragImage;
#pragma .h	id				dragging;
#pragma .h	
#pragma .h	int				draggingSession;
#pragma .h	
#pragma .h	unsigned int	op;
#pragma .h }

static NSImage	* suitcase;
static NSImage	* openSuitcase;
static NSImage	* minisuitcase;
static NSImage	* miniopenSuitcase;


+ (void)initialize
{
    if (self == [IKSuitcase  class]) {
        IKInitIDpboardType();
        suitcase = [self loadImageFromBundle:@"IKSuitcase"];
        openSuitcase = [self loadImageFromBundle:@"IKOpenSuitcase"];
        minisuitcase = [self loadImageFromBundle:@"IKMiniSuitcase"];
        miniopenSuitcase = [self loadImageFromBundle:@"IKMiniOpenSuitcase"];
    }
}


- (NSImage *) getIBImage
{
    return suitcase;
}


- (NSString *) inspectorClassName
{
    return @"IKSuitcaseInspector";
}


- init
{
    return [self  init:@"IconKit"];
}


- init: (NSString *) theName  count: (unsigned) n
{
    if ((self = [super  initCount: n]) != nil) {
        name = [theName retain];
        image = nil;
        miniImage = nil;
        acceptingDragImage = nil;
        miniAcceptingDragImage = nil;
        dragging = nil;
        draggingSession = -1;
        [self setClassToHold:@""];
    }

    return self;
}


- init: (NSString *) theName
{
	return [self  init: theName  count: 0];
}


- initCount: (unsigned) n
{
	return [self  init:@""  count: n];
}


- (IKSuitcase *)copyWithZone: (NSZone *) zone
{
	IKSuitcase *copy = [super copyWithZone:zone];
	
	if (copy) {
		copy->name = [name copyWithZone:zone];
		copy->image = image;
		copy->miniImage = miniImage;
		copy->acceptingDragImage = acceptingDragImage;
		copy->miniAcceptingDragImage = miniAcceptingDragImage;
		copy->classToHold = classToHold ? [classToHold copyWithZone:zone] : nil;
	}
	return copy;
}


- (void)dealloc
{
	if (name)
		[name release];
	if (image && ![image name])
		[image release];
	if (miniImage && ![miniImage name])
		[miniImage release];
	if (acceptingDragImage && ![acceptingDragImage name])
		[acceptingDragImage release];
	if (miniAcceptingDragImage && ![miniAcceptingDragImage name])
		[miniAcceptingDragImage release];
	
	image = acceptingDragImage = miniAcceptingDragImage = miniImage = nil;
	name = nil;
	[super dealloc];	
}


- (id)initWithCoder:(NSCoder *)aDecoder
{
    [super initWithCoder:aDecoder];
	
	name = [aDecoder decodeObject];
	if(name)
		[name retain];
	classToHold = [aDecoder decodeObject];
	if(classToHold)
		[classToHold retain];

	image = (NSImage *)[aDecoder decodeObject];
	miniImage = (NSImage *)[aDecoder decodeObject];
	acceptingDragImage = (NSImage *)[aDecoder decodeObject];
	miniAcceptingDragImage = (NSImage *)[aDecoder decodeObject];

	users = [[IKAnnouncer alloc] initOwner: self];    
	return self;
}


- (void)encodeWithCoder:(NSCoder *)aCoder;
{
    [super encodeWithCoder:aCoder];
	
	[aCoder encodeObject:name];
	[aCoder encodeObject:classToHold];
	[aCoder encodeObject:image];
	[aCoder encodeObject:miniImage];
	[aCoder encodeObject:acceptingDragImage];
	[aCoder encodeObject:miniAcceptingDragImage];
}


- (NSImage *)image
{
	return	image ? image : suitcase;
}

- (NSImage *)miniImage
{
	return	miniImage ? miniImage : minisuitcase;
}

- (NSImage *)acceptingDragImage
{
	return	acceptingDragImage ? acceptingDragImage : openSuitcase;
}

- (NSImage *)miniAcceptingDragImage
{
	return	miniAcceptingDragImage ? miniAcceptingDragImage : miniopenSuitcase;
}


- (NSString *)name				{		return name;				}
- (BOOL) isEditable				{		return YES;					}
- (BOOL) isDraggable			{		return YES;					}
- (BOOL) isDragAccepting		{		return YES;					}
- (NSString *) classToHold		{		return classToHold;			}
- (void)setEditable:(BOOL)flag		{		
}
- setDragAccepting: (BOOL) flag	{		return self;				}


- (void)setName:(NSString *)theName
{
    if (name != nil)
        [name release];
    name = theName ? [theName copy] : nil;
    [users  announce: @selector(didChangeName:)];
}


- (void)setImage:(NSImage *)theImage
{
    image = theImage;
    [users  announce: @selector(didChangeImage:)];
}


- (void)setMiniImage:(NSImage *)theImage
{
    miniImage = theImage;
    [users  announce: @selector(didChangeMiniImage:)];
}


- (void)setAcceptingDragImage:(NSImage *)theImage
{
    acceptingDragImage = theImage;
    [users  announce: @selector(didChangeAcceptingDragImage:)];
}


- (void)setMiniAcceptingDragImage:(NSImage *)theImage
{
    miniAcceptingDragImage = theImage;
    [users  announce: @selector(didChangeMiniAcceptingDragImage:)];
}



- (void)setClassToHold: (NSString *) class
{
	if (classToHold) 
		[classToHold release];
	classToHold = class ? [classToHold retain] : nil;
}


- (unsigned int) draggingEntered: (id <NSDraggingInfo>) sender
{
    int n = [sender  draggingSequenceNumber];
    id  class;

    if (draggingSession != n) {
        draggingSession = n;
        class = classToHold ? objc_lookUpClass([classToHold cString]) : nil;
        dragging =
            classToHold == NULL ? NULL:
            [class  respondsTo: @selector(readFromPasteboard:)] ?
            [class  readFromPasteboard:  [sender draggingPasteboard]]:
            IKReadID ([sender  draggingPasteboard]);
        }

    return op = (dragging && (dragging != self) &&
                 [users  poll: @selector(list:willAdd:)  with: dragging]) ?

        NSDragOperationAll:
        NSDragOperationNone;
}


- (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
{
	[embeddedArray addObject:dragging];
	return YES;
}


- (unsigned int) draggingUpdated: (id <NSDraggingInfo>) sender
{
	return op;
}


- (void)draggingExited:(id <NSDraggingInfo>)sender
{
	return;
}


- (BOOL) prepareforDragOperation: (id <NSDraggingInfo>) sender
{
	return YES;
}


- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
	return;
}


@end
