
/* written by Joe Freeman of NeXT Computer Inc.
 *	Version 2
 *	As with all my code, use at your own risk
 *
 *
 * MMFileCell.[hm]
 *	Cell used by the multi media text object to implement file attachments
 *
 * Notes:
 *	1)	This object generates attachments similar to mail.
 *		The format is identical ... see note in MMText for
 *		incompatible explanations
 *
 * Text objects expect the embeded graphic objects to implement
 *	highlight:inView:lit:
 *	drawSelf:inView:
 *	trackMouse:inRect:ofView:
 *	calcCellSize:
 *	readRichText:forView:
 *	writeRichText:forView:
 *
 */



/* Generated by Interface Builder */

#import "MMFileCell.h"
#import "MMText.h"			/* for the filename method */

#import <libc.h>			/* MAXPATHLEN */
#import	<stdio.h>
#import <strings.h>

#import <appkit/Application.h>
#import <appkit/Listener.h>
#import <appkit/Speaker.h>

#import	<appkit/NXImage.h>
#import <appkit/NXBitmapImageRep.h>
#import <appkit/NXEPSImageRep.h>
#import <appkit/tiff.h>			/* NX_TIFF_COMPRESSION_NONE */

#import	<dpsclient/dpsNeXT.h>		/* NX_COPY */
#import <streams/streams.h>


@implementation MMFileCell:MMCell


static char rcsstring[] = 
    "@(#)Object:MMFileCell.m Developer:Joe Freeman Version:2 July, 1991";

/* assume that we just want the image of the file and we save the pointer */
- initFromFile: (const char *)filename copy:(BOOL)flag
{
	char	*tiff;
	int 	length;
	int	okFlag;
	
	id	speaker = [NXApp appSpeaker];
	NXStream *stream;
	
	self = [super initFromFile: filename copy:flag];
	theImage = [NXImage findImageNamed: filename];
	if (!theImage){
		[speaker setSendPort: 
				NXPortFromName(NX_WORKSPACEREQUEST, NULL)];
		[speaker getFileIconFor:filename 
			TIFF: &tiff
			TIFFLength: &length
			ok: &okFlag];
		if (okFlag){
			stream = NXOpenMemory(tiff, length, NX_READONLY);
			theImage = [[NXImage alloc]
				initFromStream: stream ];
			NXCloseMemory(stream, NX_FREEBUFFER);
		}else{
			theImage = [[NXImage alloc] 
			initFromFile: "/usr/lib/nib/default_app_icon.tiff" ];
		}
		[theImage setName:filename];
	} else {
		/* reload image because value may have changed (doubtful)*/
		[theImage useFromFile:filename];
	}
	if (copyFlag){
		if (rindex(filename,'/'))
			strcpy(saveName,(char *)(rindex(filename,'/')+1));
		else
			strcpy(saveName,filename);
	} else {
		strcpy(saveName,filename);
	}
	
	return self;
}

- initFromFile: (const char *)filename requestedByView: aView; 
{
	[self initFromFile:filename copy:[aView copyAttachments]];
	return self;
}


@end
