/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 * 
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: sdrallattribute.cxx,v $
 *
 * $Revision: 1.2 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#include "precompiled_svx.hxx"
#include <svx/sdr/attribute/sdrallattribute.hxx>
#include <drawinglayer/attribute/sdrattribute.hxx>
#include <drawinglayer/attribute/fillattribute.hxx>
#include <svx/sdr/attribute/sdrtextattribute.hxx>

//////////////////////////////////////////////////////////////////////////////
// pointer compare define
#define pointerOrContentEqual(p, q) ((p == q) || (p && q && *p == *q))

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
	namespace attribute
	{
		SdrShadowTextAttribute::SdrShadowTextAttribute(SdrShadowAttribute* pShadow, SdrTextAttribute* pTextAttribute)
		:	mpShadow(pShadow),
			mpTextAttribute(pTextAttribute)
		{
		}

		SdrShadowTextAttribute::SdrShadowTextAttribute(const SdrShadowTextAttribute& rCandidate)
		:	mpShadow(0L),
			mpTextAttribute(0L)
		{
			if(!(*this == rCandidate))
			{
				*this = rCandidate;
			}
		}

		SdrShadowTextAttribute::~SdrShadowTextAttribute()
		{
			delete mpShadow;
			delete mpTextAttribute;
		}

		SdrShadowTextAttribute& SdrShadowTextAttribute::operator=(const SdrShadowTextAttribute& rCandidate)
		{
			// handle mpShadow
			{
				// delete local mpShadow if necessary
				if(mpShadow && ((!rCandidate.mpShadow) || (!(*mpShadow == *rCandidate.mpShadow))))
				{
					delete mpShadow;
					mpShadow = 0L;
				}
				
				// copy mpShadow if necessary
				if(!mpShadow && rCandidate.mpShadow)
				{
					mpShadow = new SdrShadowAttribute(*rCandidate.mpShadow);
				}
			}

			// handle mpTextAttribute
			{
				// delete local mpTextAttribute if necessary
				if(mpTextAttribute && ((!rCandidate.mpTextAttribute) || (!(*mpTextAttribute == *rCandidate.mpTextAttribute))))
				{
					delete mpTextAttribute;
					mpTextAttribute = 0L;
				}
				
				// copy mpTextAttribute if necessary
				if(!mpTextAttribute && rCandidate.mpTextAttribute)
				{
					mpTextAttribute = new SdrTextAttribute(*rCandidate.mpTextAttribute);
				}
			}

			return *this;
		}

		bool SdrShadowTextAttribute::operator==(const SdrShadowTextAttribute& rCandidate) const
		{
			// handle mpShadow
			if(!pointerOrContentEqual(mpShadow, rCandidate.mpShadow))
				return false;

			// handle mpTextAttribute
			if(!pointerOrContentEqual(mpTextAttribute, rCandidate.mpTextAttribute))
				return false;

			return true;
		}
	} // end of namespace attribute
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
	namespace attribute
	{
		SdrFillTextAttribute::SdrFillTextAttribute(SdrFillAttribute* pFill, FillGradientAttribute* pFillFloatTransGradient, SdrTextAttribute* pTextAttribute)
		:	mpFill(pFill),
			mpFillFloatTransGradient(pFillFloatTransGradient),
			mpTextAttribute(pTextAttribute)
		{
		}

		SdrFillTextAttribute::SdrFillTextAttribute(const SdrFillTextAttribute& rCandidate)
		:	mpFill(0),
			mpFillFloatTransGradient(0),
			mpTextAttribute(0)
		{
			if(!(*this == rCandidate))
			{
				*this = rCandidate;
			}
		}

		SdrFillTextAttribute::~SdrFillTextAttribute()
		{
			delete mpFill;
			delete mpFillFloatTransGradient;
			delete mpTextAttribute;
		}

		SdrFillTextAttribute& SdrFillTextAttribute::operator=(const SdrFillTextAttribute& rCandidate)
		{
			// handle mpFill
			{
				// delete local mpFill if necessary
				if(mpFill && ((!rCandidate.mpFill) || (!(*mpFill == *rCandidate.mpFill))))
				{
					delete mpFill;
					mpFill = 0L;
				}
				
				// copy mpFill if necessary
				if(!mpFill && rCandidate.mpFill)
				{
					mpFill = new attribute::SdrFillAttribute(*rCandidate.mpFill);
				}
			}

			// handle mpFillFloatTransGradient
			{
				// delete local mpFillFloatTransGradient if necessary
				if(mpFillFloatTransGradient && ((!rCandidate.mpFillFloatTransGradient) || (!(*mpFillFloatTransGradient == *rCandidate.mpFillFloatTransGradient))))
				{
					delete mpFillFloatTransGradient;
					mpFillFloatTransGradient = 0L;
				}
				
				// copy mpFillFloatTransGradient if necessary
				if(!mpFillFloatTransGradient && rCandidate.mpFillFloatTransGradient)
				{
					mpFillFloatTransGradient = new FillGradientAttribute(*rCandidate.mpFillFloatTransGradient);
				}
			}

			// handle mpTextAttribute
			{
				// delete local mpTextAttribute if necessary
				if(mpTextAttribute && ((!rCandidate.mpTextAttribute) || (!(*mpTextAttribute == *rCandidate.mpTextAttribute))))
				{
					delete mpTextAttribute;
					mpTextAttribute = 0L;
				}
				
				// copy mpTextAttribute if necessary
				if(!mpTextAttribute && rCandidate.mpTextAttribute)
				{
					mpTextAttribute = new SdrTextAttribute(*rCandidate.mpTextAttribute);
				}
			}

			return *this;
		}

		bool SdrFillTextAttribute::operator==(const SdrFillTextAttribute& rCandidate) const
		{
			// handle mpFill
			if(!pointerOrContentEqual(mpFill, rCandidate.mpFill))
				return false;

			// handle mpFillFloatTransGradient
			if(!pointerOrContentEqual(mpFillFloatTransGradient, rCandidate.mpFillFloatTransGradient))
				return false;

			// handle mpTextAttribute
			if(!pointerOrContentEqual(mpTextAttribute, rCandidate.mpTextAttribute))
				return false;

			return true;
		}
	} // end of namespace attribute
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
	namespace attribute
	{
		SdrLineShadowTextAttribute::SdrLineShadowTextAttribute(
			SdrLineAttribute* pLine, SdrLineStartEndAttribute* pLineStartEnd, 
			SdrShadowAttribute* pShadow, SdrTextAttribute* pTextAttribute)
		:	SdrShadowTextAttribute(pShadow, pTextAttribute),
			mpLine(pLine),
			mpLineStartEnd(pLineStartEnd)
		{
		}

		SdrLineShadowTextAttribute::SdrLineShadowTextAttribute(const SdrLineShadowTextAttribute& rCandidate)
		:	SdrShadowTextAttribute(0L, 0L),
			mpLine(0L),
			mpLineStartEnd(0L)
		{
			if(!(*this == rCandidate))
			{
				*this = rCandidate;
			}
		}

		SdrLineShadowTextAttribute::~SdrLineShadowTextAttribute()
		{
			delete mpLine;
			delete mpLineStartEnd;
		}

		SdrLineShadowTextAttribute& SdrLineShadowTextAttribute::operator=(const SdrLineShadowTextAttribute& rCandidate)
		{
			// call parent
			SdrShadowTextAttribute::operator=(rCandidate);
	
			// handle mpLine
			{
				// delete local mpLine if necessary
				if(mpLine && ((!rCandidate.mpLine) || (!(*mpLine == *rCandidate.mpLine))))
				{
					delete mpLine;
					mpLine = 0L;
				}
				
				// copy mpLine if necessary
				if(!mpLine && rCandidate.mpLine)
				{
					mpLine = new SdrLineAttribute(*rCandidate.mpLine);
				}
			}

			// handle mpLineStartEnd
			{
				// delete local mpLineStartEnd if necessary
				if(mpLineStartEnd && ((!rCandidate.mpLineStartEnd) || (!(*mpLineStartEnd == *rCandidate.mpLineStartEnd))))
				{
					delete mpLineStartEnd;
					mpLineStartEnd = 0L;
				}
				
				// copy mpLineStartEnd if necessary
				if(!mpLineStartEnd && rCandidate.mpLineStartEnd)
				{
					mpLineStartEnd = new SdrLineStartEndAttribute(*rCandidate.mpLineStartEnd);
				}
			}

			return *this;
		}

		bool SdrLineShadowTextAttribute::operator==(const SdrLineShadowTextAttribute& rCandidate) const
		{
			// call parent
			if(!(SdrShadowTextAttribute::operator==(rCandidate)))
				return false;

			// handle mpLine
			if(!pointerOrContentEqual(mpLine, rCandidate.mpLine))
				return false;

			// handle mpLineStartEnd
			if(!pointerOrContentEqual(mpLineStartEnd, rCandidate.mpLineStartEnd))
				return false;

			return true;
		}
	} // end of namespace attribute
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////

namespace drawinglayer
{
	namespace attribute
	{
		SdrLineFillShadowTextAttribute::SdrLineFillShadowTextAttribute(
			SdrLineAttribute* pLine, attribute::SdrFillAttribute* pFill, SdrLineStartEndAttribute* pLineStartEnd, 
			SdrShadowAttribute* pShadow, FillGradientAttribute* pFillFloatTransGradient, SdrTextAttribute* pTextAttribute)
		:	SdrLineShadowTextAttribute(pLine, pLineStartEnd, pShadow, pTextAttribute),
			mpFill(pFill),
			mpFillFloatTransGradient(pFillFloatTransGradient)
		{
		}

		SdrLineFillShadowTextAttribute::SdrLineFillShadowTextAttribute(const SdrLineFillShadowTextAttribute& rCandidate)
		:	SdrLineShadowTextAttribute(0L, 0L, 0L, 0L),
			mpFill(0L),
			mpFillFloatTransGradient(0L)
		{
			if(!(*this == rCandidate))
			{
				*this = rCandidate;
			}
		}

		SdrLineFillShadowTextAttribute::~SdrLineFillShadowTextAttribute()
		{
			delete mpFill;
			delete mpFillFloatTransGradient;
		}

		SdrLineFillShadowTextAttribute& SdrLineFillShadowTextAttribute::operator=(const SdrLineFillShadowTextAttribute& rCandidate)
		{
			// call parent
			SdrLineShadowTextAttribute::operator=(rCandidate);
	
			// handle mpFill
			{
				// delete local mpFill if necessary
				if(mpFill && ((!rCandidate.mpFill) || (!(*mpFill == *rCandidate.mpFill))))
				{
					delete mpFill;
					mpFill = 0L;
				}
				
				// copy mpFill if necessary
				if(!mpFill && rCandidate.mpFill)
				{
					mpFill = new attribute::SdrFillAttribute(*rCandidate.mpFill);
				}
			}

			// handle mpFillFloatTransGradient
			{
				// delete local mpFillFloatTransGradient if necessary
				if(mpFillFloatTransGradient && ((!rCandidate.mpFillFloatTransGradient) || (!(*mpFillFloatTransGradient == *rCandidate.mpFillFloatTransGradient))))
				{
					delete mpFillFloatTransGradient;
					mpFillFloatTransGradient = 0L;
				}
				
				// copy mpFillFloatTransGradient if necessary
				if(!mpFillFloatTransGradient && rCandidate.mpFillFloatTransGradient)
				{
					mpFillFloatTransGradient = new FillGradientAttribute(*rCandidate.mpFillFloatTransGradient);
				}
			}

			return *this;
		}

		bool SdrLineFillShadowTextAttribute::operator==(const SdrLineFillShadowTextAttribute& rCandidate) const
		{
			// call parent
			if(!(SdrLineShadowTextAttribute::operator==(rCandidate)))
				return false;

			// handle mpFill
			if(!pointerOrContentEqual(mpFill, rCandidate.mpFill))
				return false;

			// handle mpFillFloatTransGradient
			if(!pointerOrContentEqual(mpFillFloatTransGradient, rCandidate.mpFillFloatTransGradient))
				return false;

			return true;
		}
	} // end of namespace attribute
} // end of namespace drawinglayer

//////////////////////////////////////////////////////////////////////////////
// eof
