/*
 * AppController.j
 *
 * Created by __Me__ on __Date__.
 * Copyright 2008 __MyCompanyName__. All rights reserved.
 */

@import <Foundation/CPObject.j>

PhotoCellDragType = @"PhotoCellDragType";

@implementation PhotoCell : CPView
{
    CPImage         image;
    CPImageView     imageView;
    CPView          highlightView;
    
    CPString        imagePath @accessors;
}

- (void)setRepresentedObject:(CPObject)anObject
{
    if(!imageView)
    {
        imageView = [[CPImageView alloc] initWithFrame:CGRectMakeCopy([self bounds])];
        [imageView setAutoresizingMask:CPViewWidthSizable | CPViewHeightSizable];
        [imageView setImageScaling:CPScaleProportionally];
        [imageView setHasShadow:YES];
        [self addSubview:imageView];
    }
    
    imagePath = anObject;
    
    [image setDelegate:nil];
    
    image = [[CPImage alloc] initWithContentsOfFile:imagePath];
    [image setDelegate:self];
    
    if([image loadStatus] == CPImageLoadStatusCompleted)
        [imageView setImage:image];
    else
        [imageView setImage:nil];
}

- (void)imageDidLoad:(CPImage)anImage
{
    [imageView setImage:anImage];
}

- (void)setSelected:(BOOL)flag
{
    if(!highlightView)
    {
        highlightView = [[CPView alloc] initWithFrame:CGRectCreateCopy([self bounds])];
        [highlightView setBackgroundColor:[CPColor colorWithCalibratedWhite:0.8 alpha:0.6]];
    }

    if(flag)
    {
        [highlightView setFrame:CGRectInset([imageView imageRect], -10.0, -10.0)];
        [self addSubview:highlightView positioned:CPWindowBelow relativeTo:imageView];
    }
    else
        [highlightView removeFromSuperview];
}


@end