
/*
	Copyright 1993  Jeremy Slade.

	You are free to use all or any parts of the Locus project
	however you wish, just give credit where credit is due.
	The author (Jeremy Slade) shall not be held responsible
	for any damages that result out of use or misuse of any
	part of this project.

*/

/*
	Project: Locus

	File: Activator.h

	Description: See Activator.h
	
	Original Author: Jeremy Slade

	Revision History:
		Created
			V.101	JGS	Tue Mar  9 18:44:28 GMT-0700 1993

*/


#import "Activator.h"

#import "ActivatorBar.h"
#import "Globals.h"


@implementation Activator : Object


// -------------------------------------------------------------------------
//   Creating, Initializing
// -------------------------------------------------------------------------


+ initialize
{
	[self setVersion:Activator_VERSION];
	return ( self );
}



- init
{
	[super init];
	
	// Set default colors
	fillColor = NX_COLORWHITE;
	borderColor = NX_COLORBLACK;
	
	// Create the bars...
	topBar = [[ActivatorBar allocFromZone:[self zone]] initAt:ABAR_TOP];
	bottomBar = [[ActivatorBar allocFromZone:[self zone]] initAt:ABAR_BOTTOM];
	leftBar = [[ActivatorBar allocFromZone:[self zone]] initAt:ABAR_LEFT];
	rightBar = [[ActivatorBar allocFromZone:[self zone]] initAt:ABAR_RIGHT];
	[topBar setDelegate:self];
	[leftBar setDelegate:self];
	[rightBar setDelegate:self];
	[bottomBar setDelegate:self];
	
	[self setBar:ACT_NONE on:NO];
	return ( self );
}



- free
{
	[self hide:self];
	[topBar free];
	[bottomBar free];
	[leftBar free];
	[rightBar free];
	return ( [super free] );
}
	


// -------------------------------------------------------------------------
//   Setting the Delegate
// -------------------------------------------------------------------------


- setDelegate:anObj
{
	delegate = anObj;
	return ( self );
}



- delegate
{
	return ( self );
}



// -------------------------------------------------------------------------
//   Controlling the Bars
// -------------------------------------------------------------------------


- setBar:(int)mask on:(BOOL)flag
/*
	Turn on the bar(s) corresponding to mask.  If mask is ACT_NONE, turn off all bars.
*/
{
	int newMask = barMask;
	
	if ( mask == ACT_NONE ) { // hide all bars
		newMask = ACT_NONE;
	} else {
		if ( mask & ACT_TOP ) {
			if ( flag ) newMask |= ACT_TOP;
				else newMask &= ~ACT_TOP;
		}
		if ( mask & ACT_LEFT ) {
			if ( flag ) newMask |= ACT_LEFT;
				else newMask &= ~ACT_LEFT;
		}
		if ( mask & ACT_RIGHT ) {
			if ( flag ) newMask |= ACT_RIGHT;
				else newMask &= ~ACT_RIGHT;
		}
		if ( mask & ACT_BOTTOM ) {
			if ( flag ) newMask |= ACT_BOTTOM;
				else newMask &= ~ACT_BOTTOM;
		}
	}
	
	// Set the bar positions according to mask
	barMask = newMask;
	[topBar setPosition:((barMask & ACT_TOP) ? ABAR_TOP : ABAR_NONE)];
	[leftBar setPosition:((barMask & ACT_LEFT) ? ABAR_LEFT : ABAR_NONE)];
	[rightBar setPosition:((barMask & ACT_RIGHT) ? ABAR_RIGHT : ABAR_NONE)];
	[bottomBar setPosition:
		((barMask & ACT_BOTTOM) ? ABAR_BOTTOM : ABAR_NONE)];
	
	[self show:self];
	return ( self );
}



- (int)barMask
{
	return ( barMask );
}



- (BOOL)isBarOn:(int)mask
/*
	This method returns YES if the bar(s) corresponding to mask is turned on (visible), or NO if it is not.
*/
{
	return ( (barMask & mask) ? YES : NO );
}



- show:sender
/*
	Show all the bars.  Since each individual bar knows if it is supposed to be on screen or now, telling it to show itself will do the right thing regardless.
*/
{
	[topBar show:sender];
	[leftBar show:sender];
	[rightBar show:sender];
	[bottomBar show:sender];
	return ( self );
}



- hide:sender
/*
	Hide all of the activator bars.
*/
{
	[topBar hide:sender];
	[leftBar hide:sender];
	[rightBar hide:sender];
	[bottomBar hide:sender];
	return ( self );
}



- setColor:(NXColor)color
/*
	Set the fill color of all the activator bars.
*/
{
	fillColor = color;
	[topBar setColor:color];
	[leftBar setColor:color];
	[rightBar setColor:color];
	[bottomBar setColor:color];
	return ( self );
}



-(NXColor)color
{
	return ( fillColor );
}



- setBorderColor:(NXColor)color
/*
	Set the border color of all the activator bars.
*/
{
	borderColor = color;
	[topBar setBorderColor:color];
	[leftBar setBorderColor:color];
	[rightBar setBorderColor:color];
	[bottomBar setBorderColor:color];
	return ( self );
}



-(NXColor)borderColor
{
	return ( borderColor );
}



- setFloating:(BOOL)flag
/*
	Sets the floatActivator global to flag.  The Activator Bars check this flag to determine which window tier to display in.  Calling setBar:on: indirectly results in having a setPosition: message sent to each of the bars, causing them to place themselves in the proper tier.
*/
{
	floatActivator = flag;
	[self setBar:barMask on:YES];
	return ( self );
}



- (BOOL)isFloating
{
	return ( floatActivator );
}



// -------------------------------------------------------------------------
//   Activation
// -------------------------------------------------------------------------


- barHit:sender
/*
	This method is called by one of the Activator Bars when it is clicked in.  We simply inform our delegate that we were hit.
*/
{
	if ( [delegate respondsTo:@selector(activatorHit:)] )
		[delegate activatorHit:self];
	return ( self );
}



// -------------------------------------------------------------------------
//   Enabling Dragging
// -------------------------------------------------------------------------


- setDraggingEnabled:(BOOL)flag
/*
	When dragging into the Activator is enabled, the Activator bars can each act as dragging destinations for the NXDraggingProtocol for the types defined by dragInTypes -- currently only handles NXFilenamePboardTypes.  When dragging is disabled, the bars are unregistered so they won't respond as dragging destinations.
*/
{
	if ( flag == YES ) {
		[leftBar registerForDraggedTypes:dragInTypes count:DRAGINTYPES];
		[topBar registerForDraggedTypes:dragInTypes count:DRAGINTYPES];
		[rightBar registerForDraggedTypes:dragInTypes count:DRAGINTYPES];
		[bottomBar registerForDraggedTypes:dragInTypes count:DRAGINTYPES];
	} else {
		[leftBar unregisterDraggedTypes];
		[topBar unregisterDraggedTypes];
		[rightBar unregisterDraggedTypes];
		[bottomBar unregisterDraggedTypes];
	}
	return ( self );
}



@end
