//=============================================================================
//
//		Copyright (C) 1996 by Paul S. McCarthy and Eric Sunshine.
//				Written by Paul S. McCarthy and Eric Sunshine.
//							All Rights Reserved.
//
//		This notice may not be removed from this source code.
//
//		This object is included in the MiscKit by permission from the authors
//		and its use is governed by the MiscKit license, found in the file
//		"License.rtf" in the MiscKit distribution.	Please refer to that file
//		for a list of all applicable permissions and restrictions.
//		
//=============================================================================
//-----------------------------------------------------------------------------
// MiscTableConnector.M
//
//		A custom sublcass of the internal Interface Builder
//		IBControlConnector class that works for doubleTarget / doubleAction.
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// $Id: MiscTableConnector.M,v 1.2 96/04/23 02:32:48 sunshine Exp $
// $Log:		MiscTableConnector.M,v $
//	Revision 1.2  96/04/23	02:32:48  sunshine
//	Removed all of the NEXTSTEP 3.3 Foundation Kit specific code.  Now default
//	implementation only contains enough methods to reestablish connections at
//	nib load time.	This is necessary in order for these nibs to be loadable
//	on 3.2 machines (into applications, but *not* IB).
//	
//	Revision 1.1  96/04/20	01:34:26  zarnuk
//	Custom IB connector that handles target/action style pairs.
//-----------------------------------------------------------------------------
#import "MiscTableConnector.h"

@interface Object(MiscTableConnector)
- nibInstantiate;
@end

@implementation MiscTableConnector

//-----------------------------------------------------------------------------
// freeString:
//-----------------------------------------------------------------------------
- (void) freeString:(char*)str
	{
	if (str != 0)
		NXZoneFree( [self zone], str );
	}


//-----------------------------------------------------------------------------
// clone:into:
//-----------------------------------------------------------------------------
- (void) clone:(char const*)str into:(char**)p
	{
	[self freeString: *p];
	if (str != 0)
		{
		*p = (char*)NXZoneMalloc( [self zone], strlen(str) + 1 );
		strcpy( *p, str );
		}
	else
		{
		*p = 0;
		}
	}


//-----------------------------------------------------------------------------
// -free
//-----------------------------------------------------------------------------
- free
	{
	[self freeString:outletName];
	[self freeString:actionName];
	[self freeString:selectorName];
	return [super free];
	}


//-----------------------------------------------------------------------------
// -readString:into:
//-----------------------------------------------------------------------------
- (void) readString:(NXTypedStream*)stream into:(char**)var
	{
	char* s;
	NXReadType( stream, @encode(char*), &s );
	*var = 0;
	[self clone:s into:var];
	if (s != 0)
		free(s);
	}


//-----------------------------------------------------------------------------
// -read:
//-----------------------------------------------------------------------------
- read:(NXTypedStream*)stream
	{
	[super read:stream];
	[self readString:stream into:&outletName];
	[self readString:stream into:&actionName];
	[self readString:stream into:&selectorName];
	return self;
	}


//-----------------------------------------------------------------------------
// -establishConnection
//-----------------------------------------------------------------------------
- establishConnection
	{
	if (source != 0 && destination != 0 && outletName != 0)
		{
		object_setInstanceVariable( source, outletName, destination );
		if (actionName != 0 && selectorName != 0)
			{
			SEL aSel = sel_getUid( selectorName );
			if (aSel != 0)
				object_setInstanceVariable( source, actionName, aSel );
			}
		}
	return self;
	}

@end
