//
//  WebImageDocumentRepresentation.m
//  SimpleWebKit
//
//  Created by Nikolaus Schaller on 27.01.07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "WebImageDocumentRepresentation.h"
#import "Private.h"

@implementation _WebImageDocumentRepresentation

- (void) dealloc;
{
	[_image release];
	[super dealloc];
}

// methods from WebDocumentRepresentation protocol

- (void) setDataSource:(WebDataSource *) dataSource;
{
	[super setDataSource:dataSource];
	// well, we should know that...
	[[dataSource response] MIMEType];	// should be an image!
	// we should decide if we want to load into an <img> tag or into a full WebFrameView
}

- (void) finishedLoadingWithDataSource:(WebDataSource *) source;
{
	NSLog(@"WebImageDocumentRepresentation finishedLoadingWithDataSource");
	_image=[[NSImage alloc] initWithData:[source data]];
	// notify our delegate (an _WebImageDocumentView or the NSActionCell) about the new content
}

- (void) receivedData:(NSData *) data withDataSource:(WebDataSource *) source;
{
	// handle partial image data
#if 1
	NSLog(@"WebImageDocumentRepresentation receivedData");
#endif
	return; // not yet
}

- (NSString *) title;
{
	if(_image)
		{ // has been loaded
		NSString *file=[[[[_dataSource response] URL] path] lastPathComponent];
		NSSize size=[_image size];
		return [NSString stringWithFormat:@"%@ %ux&u Pixel", file, size.width, size.height];
		}
	return nil;	// no title yet
}

- (NSImage *) getImage; { return _image; }

@end

@interface _WebImageDocumentView : NSImageView <WebDocumentView>

@end

@implementation _WebImageDocumentView

- (void) dataSourceUpdated:(WebDataSource *) source;
{
}

- (void) layout;
{
}

- (void) setDataSource:(WebDataSource *) source;
{
}

- (void) setNeedsLayout:(BOOL) flag;
{
}

- (void) viewDidMoveToHostWindow;
{
}

- (void) viewWillMoveToHostWindow:(NSWindow *) win;
{
}

@end