/*$Copyright:
 * Copyright (C) 1992.5.22. Recruit Co.,Ltd. 
 * Institute for Supercomputing Research
 * All rights reserved.
 * NewsBase  by ISR, Kazuto MIYAI, Gary ARAKAKI, Katsunori SUZUKI, Kok-meng Lue
 *
 * You may freely copy, distribute and reuse the code in this program under 
 * following conditions.
 * - to include this notice in the source code, if it is to be distributed 
 *   with source code.
 * - to add the file named "COPYING" within the code, which shall include 
 *   GNU GENERAL PUBLIC LICENSE(*).
 * - to display an acknowledgement in binary code as follows: "This product
 *   includes software developed by Recruit Co.,Ltd., ISR."
 * - to display a notice which shall state that the users may freely copy,
 *   distribute and reuse the code in this program under GNU GENERAL PUBLIC
 *   LICENSE(*)
 * - to indicate the way to access the copy of GNU GENERAL PUBLIC LICENSE(*)
 *
 *   (*)GNU GENERAL PUBLIC LICENSE is stored in the file named COPYING
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
$*/

#import "INXBrowserCellWithLinkedObject.h"
#import <appkit/Text.h>
#import <appkit/NXImage.h>
#import <dpsclient/psops.h>

#define		FIELD_LMARGIN		10
#define		MARGIN		2

@implementation INXBrowserCellWithLinkedObject

- init
{
    [super init];
    iNode = nil;
    iListnode = nil;
    activeFlag = YES;
    iImage = nil;

    return self;
}

- node
{
    return iNode;
}

- setNode:node
{
    iNode = node;
    return self;
}

- listnode
{
    return iListnode;
}

- setListnode:listnode
{
    /* listnode will be free in ITreeBrowser */
    iListnode = listnode;
    return self;
}

- setActive:(BOOL)flag
{
    activeFlag = flag;
    return self;
}

- (BOOL)active
{
    return activeFlag;
}

- toggleActive
{
    if (activeFlag == YES) {
	[self setActive:NO];
    } else {
	[self setActive:YES];
    }
    return self;
}

- free
{
    if (iListnode != nil) {    
        [iListnode free];
    }

    return ([super free]);
}

- setTextAttributes:textObj
{
    [super setTextAttributes:textObj];
    if (activeFlag == YES) {
	[textObj setTextGray:NX_BLACK];
    } else {
	[textObj setTextGray:NX_DKGRAY];
    }
    return textObj;
}

- setImage:image
{
    iImage = image;
    return self;
}

- drawInside:(const NXRect *)cellFrame inView:controlView
{
    NXCoord	baseX, baseY;
    NXPoint	imagePoint;
	
    // do normal stuff first
    [super drawInside:cellFrame inView:controlView];
    
    // draw image for cell
    baseX = NX_X(cellFrame);
    baseY = NX_Y(cellFrame);

    imagePoint.x = NX_WIDTH(cellFrame) - 15.0;
    imagePoint.y = NX_Y(cellFrame) + NX_HEIGHT(cellFrame) - 2.0;

    [iImage composite:NX_SOVER toPoint:&imagePoint];
    return self;
}

@end
