//------------------------------------------------------------------------------------------------
//
//	ImageWell
//	
//	Inherits From:	Control
//
//	Declared In:	ImageWell.h
//
//	Disclaimer
//
//		You may freely copy, distribute and reuse this software and its
//		associated documentation. I disclaim any warranty of any kind, 
//		expressed or implied, as to its fitness for any particular use.
//
//------------------------------------------------------------------------------------------------
#import "ImageWell.h"


@implementation ImageWell

//------------------------------------------------------------------------------------------------
//	Initialization and Freeing
//------------------------------------------------------------------------------------------------
- initFrame: (const NXRect*) frameRect
{ 
	[super initFrame:frameRect];
	[self setCell: [[ActionCell allocFromZone:[self zone]] init]];
    	[self registerForDraggedTypes:&NXFilenamePboardType count:1];
	return self;
}


- free
{
	if (image) [image free];
	return [super free];
}


//------------------------------------------------------------------------------------------------
//	Accessing Image
//------------------------------------------------------------------------------------------------
- image: anImage
{
	image = anImage;
	[self update];
	return self;
}


- image
{
	return image;
}


//------------------------------------------------------------------------------------------------
//	Drawing
//------------------------------------------------------------------------------------------------
- drawSelf: (const NXRect *)rects :(int)count
{
	NXSetColor ([[self window] backgroundColor]);
	NXRectFill (&bounds);
	[image composite:NX_SOVER toPoint:&bounds.origin];
	return self;
}


//------------------------------------------------------------------------------------------------
//	Dragging
//------------------------------------------------------------------------------------------------
- (NXDragOperation) draggingEntered:dragSource
{
	return NX_DragOperationGeneric;
}


- (BOOL) performDragOperation:dragSource
{
	id 	pasteboard = [dragSource draggingPasteboard];

	if ([NXImage canInitFromPasteboard: pasteboard] == NO) return NO;
	
	image = [[NXImage allocFromZone: [self zone]] initFromPasteboard: pasteboard];
	[[image setScalable: YES] setSize: &frame.size];
	return (image ? YES : NO);
}


- concludeDragOperation:dragSource
{
	[[self target] perform:[self action] with:self];
	[self display];
	return self;
}


@end