//
//	Copyright © 2005 Nemetschek North America 
//	All Rights Reserved.
//
// Created by Vladislav Stanev

#include "StdAfx.h"

using namespace VWFC::VWObjects;

VWPattern::VWPattern(InternalIndex fillIndex)
{
	// 0 if h is an object with no fill pattern 
	// [none is 0, white is 1, black is 2, and so on.
	// If the object is hatched, the number is negative, and valid values are not consecutive.

	fFillPatternIndex	= fillIndex;
	fbIsFillPattern		= true;
	fPenPatternIndex	= 0;
}

VWPattern::VWPattern(short penIndex)
{
	// 0 if h is an object with no pen pattern (e.g. group). 
	// [none is 0, white is 1, black is 2, and so on.]
	fPenPatternIndex	= penIndex;
	fbIsFillPattern		= false;
	fFillPatternIndex	= 0;
}

VWPattern::~VWPattern()
{
}

VWPattern::operator InternalIndex() const
{
	return fFillPatternIndex;
}

VWPattern::operator short() const
{
	return fPenPatternIndex;
}

Boolean VWPattern::IsNonePattern() const
{
	return fbIsFillPattern ? fFillPatternIndex == 0 : fPenPatternIndex == 0;
}

void VWPattern::SetNonePattern()
{
	if ( fbIsFillPattern )
		fFillPatternIndex	= 0;
	else
		fPenPatternIndex	= 0;
}

Boolean VWPattern::IsSolidPattern() const
{
	return fbIsFillPattern ? fFillPatternIndex == 1 : fPenPatternIndex == 1;
}

void VWPattern::SetSolidPattern()
{
	if ( fbIsFillPattern )
		fFillPatternIndex	= 1;
	else
		fPenPatternIndex	= 2;
}

Boolean VWPattern::IsHatchPattern() const
{
	// this applicable only for fill patterns
	VWFC_ASSERT( fbIsFillPattern );
	if ( ! fbIsFillPattern )
		return false;

	if ( fFillPatternIndex >= 0 )
		return false;
	if ( fFillPatternIndex == -2 )
		return true;

	InternalIndex	absIndex	= abs( fFillPatternIndex );

	MCObjectHandle	hObj		= ::GS_InternalIndexToHandle( gCBP, absIndex );
	if ( hObj == NULL )
		return false;

	short			type	= ::GS_GetObjectType( gCBP, hObj );
	return type == kHatchDefNode;
}

Boolean VWPattern::IsDashPattern() const
{
	// this applicable only for fill patterns
	VWFC_ASSERT( ! fbIsFillPattern );
	if ( fbIsFillPattern )
		return false;
	return fPenPatternIndex < 0;
}

Boolean VWPattern::IsGradientPattern() const
{
	// this applicable only for fill patterns
	VWFC_ASSERT( fbIsFillPattern );
	if ( ! fbIsFillPattern )
		return false;

	if ( fFillPatternIndex >= 0 )
		return false;
	if ( fFillPatternIndex == -2 )
		return true;

	InternalIndex	absIndex	= abs( fFillPatternIndex );

	MCObjectHandle	hObj		= ::GS_InternalIndexToHandle( gCBP, absIndex );
	if ( hObj == NULL )
		return false;

	short			type	= ::GS_GetObjectType( gCBP, hObj );
	return type == kGradientDefNode;
}

Boolean VWPattern::IsImagePattern() const
{
	// this applicable only for fill patterns
	VWFC_ASSERT( fbIsFillPattern );
	if ( ! fbIsFillPattern )
		return false;

	if ( fFillPatternIndex >= 0 )
		return false;
	if ( fFillPatternIndex == -2 )
		return true;

	InternalIndex	absIndex	= abs( fFillPatternIndex );

	MCObjectHandle	hObj		= ::GS_InternalIndexToHandle( gCBP, absIndex );
	if ( hObj == NULL )
		return false;

	short			type	= ::GS_GetObjectType( gCBP, hObj );
	return type == kImageDefNode;
}
