// Robert Nicholson, Thu Feb 10 14:42:00 GMT 1994
// Copyright, 1994. All rights reserved.

#import "NibInfoMethods.h"
#import <string.h>

@implementation Object(NibInfoMethods)

// report header
- NIBINFOReportHeader:(const char *)pathname toStream:(NXStream *)s
{
	NXPrintf(s,"Header for nib %s\n",pathname);
	return self;
}

// report trailer
- NIBINFOReportTrailer:(const char *)pathname toStream:(NXStream *)s
{
	NXPrintf(s,"Trailer for nib %s\n",pathname);
	return self;
}

// header line for master object
- NIBINFOheaderForObject:anObject toStream:(NXStream *)s
{
	NXPrintf(s,"%s",[[anObject class] name]);
	if ([anObject respondsTo:@selector(NIBINFOinfoToStream:)]) {
		[anObject NIBINFOinfoToStream:s];
	}
	NXPrintf(s,"\n");
	return self;
}

// detail information for source of connection.
- NIBINFOdetailForSourceToStream:(NXStream *)s
{
	const char *sourceClassName;
	
	sourceClassName = [[self class] name];
	NXPrintf(s,"\t%s",sourceClassName ? sourceClassName : "NULL");
	return self;
}

// detail information for desintation of connection.
- NIBINFOdetailForDestToStream:(NXStream *)s
{
	const char *destClassName;
	
	destClassName = [[self class] name];
	NXPrintf(s,"->%s",destClassName ? destClassName : "NULL");
	return self;
}

// selector/outlet for connection
- NIBINFOselector:(const char *)selector toStream:(NXStream *)s
{
	char *slash=NULL;

	NXPrintf(s," ");
	slash = rindex(selector,'/');
	if (slash) {
		NXPrintf(s,"[%s]",slash+1);
	} else {
		NXPrintf(s,"[%s]",selector);
	}
	NXPrintf(s,"\n");
	return self;
}

#import <dbkit/DBModule.h>

// destintation information
- NIBINFOinfoToStream:(NXStream *)s
{
	const char *info=NULL;
	// Unfortunately we are unable to use dynamic binding on 
	// IB's Template classes.  eg. WindowTemplate, DBModuleTemplate
	// MenuTemplate. "Template" classes are substitutes for real classes during
	// edit mode. They are all Object subclasses.

	if (!strcmp([[self class] name],"DBModuleTemplate")) {
		char name[MAXPATHLEN+1];
		const char *database;
		const char *entity;

		database = (const char *)[[(DBModule *)self database] name];
		entity =(const char *)[[(DBModule *)self entity] name];
		sprintf(name,"%s->%s",database,entity);
		info = name;
	} else {
		if ([self respondsTo:@selector(title)]) {
			info=(const char *)[self perform:@selector(title)];
		}
	}
	if (info && *info) {
		NXPrintf(s,"(\"%s\") ",info);
	} else {
		NXPrintf(s,"(\"N/A\") ");
	}
	return self;
}

@end

// customized for View subclasses in order to print frame information.

@implementation View(NibInfoMethods)

- NIBINFOinfoToStream:(NXStream *)s
{
	[super NIBINFOinfoToStream:s];
	NXPrintf(s,"(%f %f %f %f)",NX_X(&frame),NX_Y(&frame),NX_WIDTH(&frame),NX_HEIGHT(&frame));
	return self;
}
	
@end
