
/* Generated by Interface Builder */

#import "IFolderDockCell.h"
#import "IFolderMatrix.h"

#import <appkit/NXImage.h>
#import <dpsclient/dpsNeXT.h>
#import <dpsclient/wraps.h>
#import <string.h>

@implementation IFolderDockCell

- initIconCell:(const char *)iconName
{
    [super initIconCell:iconName];
    iCurrentImage = NULL;
    return self;
}

- setCurrentImage:currentImage
{
    iCurrentImage = currentImage;
    return self;
}

- currentImage
{
    return (iCurrentImage);
}

- drawInside:(const NXRect *)cellFrame inView:controlView
{
    NXRect	iconFrame;
    NXPoint	iconOrigin;
    
    // do normal stuff
    [super drawInside:cellFrame inView:controlView];
    
    // if cell has current image, draw ghost of it
    // current image is set when dragging icon come across over this cell
    if (iCurrentImage != NULL) {
	iconFrame = *cellFrame;
	[self getIconRect:&iconFrame];
	iconOrigin = iconFrame.origin;
	if ([controlView isFlipped] == YES) {
	    // control view is Matrix, so usually control view's coordinate
	    // is Flipped. 
	    iconOrigin.y = iconFrame.origin.y + iconFrame.size.height;
	}
	[iCurrentImage composite:NX_SOVER toPoint:&(iconOrigin)];
	PSsetalpha(0.5);
	PSsetgray(NX_LTGRAY);
	PScompositerect(iconFrame.origin.x, iconFrame.origin.y, 
			iconFrame.size.width, iconFrame.size.height,
			NX_SOVER);
    }
        
    return self;
}

- (BOOL)windowEntered:dragSource controlView:cView
{
    id		image;

    if ((image =[dragSource image]) == [NXImage findImageNamed:CLOSEDFOLDER]
    		&& (strcmp([[self image] name], BLANKICON) == 0)) {
	// dragged window is newsgroup folder and this cell has no folder
	iCurrentImage = image;
	[[cView window] disableFlushWindow];
	[cView drawCell:self];
	[[cView window] reenableFlushWindow];
	return YES;
    } else {
	// dragged icon may be file's one to post
	return ([super windowEntered:dragSource controlView:cView]);
    }
}
	
- (BOOL)windowExited:dragSource controlView:cView
{
    id		image;
    
    if ((image =[dragSource image]) == [NXImage findImageNamed:CLOSEDFOLDER]
    		&& (strcmp([[self image] name], BLANKICON) == 0)) {
	// dragged window is newsgroup folder and this cell has no folder
	iCurrentImage = NULL;
	[[cView window] disableFlushWindow];
	[cView drawCell:self];
	[[cView window] reenableFlushWindow];
	return YES;
    } else {
	// dragged icon may be file's one to post
	return ([super windowExited:dragSource controlView:cView]);
    }
}

- (BOOL)windowDropped:dragSource controlView:cView
{
    id		image;
    
    if ((image =[dragSource image]) == [NXImage findImageNamed:CLOSEDFOLDER]) {
    	if (strcmp([[self image] name], BLANKICON) == 0) {
	    // dragged window is newsgroup folder and this cell has no folder
	    iCurrentImage = NULL;
	    [self setImage:image];
	    [self setTitle:[dragSource title]];
	    [cView drawCell:self];
	    return YES;
	} else if (strcmp([[self image] name], BLANKICON) != 0) {
	    // folder has already another image, so dragged newsfolder
	    // icon will be refused
	    return NO;
	}
    } else {
	return ([super windowDropped:dragSource controlView:cView]);
    }
    return YES;		// dummy statement for fool compiler
}

@end
