1*4bfbcde8SAndrew Rist /**************************************************************
2*4bfbcde8SAndrew Rist  *
3*4bfbcde8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*4bfbcde8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*4bfbcde8SAndrew Rist  * distributed with this work for additional information
6*4bfbcde8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*4bfbcde8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*4bfbcde8SAndrew Rist  * "License"); you may not use this file except in compliance
9*4bfbcde8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*4bfbcde8SAndrew Rist  *
11*4bfbcde8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*4bfbcde8SAndrew Rist  *
13*4bfbcde8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*4bfbcde8SAndrew Rist  * software distributed under the License is distributed on an
15*4bfbcde8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*4bfbcde8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*4bfbcde8SAndrew Rist  * specific language governing permissions and limitations
18*4bfbcde8SAndrew Rist  * under the License.
19*4bfbcde8SAndrew Rist  *
20*4bfbcde8SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <drawinglayer/attribute/sdrshadowattribute.hxx>
26cdf0e10cSrcweir #include <basegfx/vector/b2dvector.hxx>
27cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
30cdf0e10cSrcweir 
31cdf0e10cSrcweir namespace drawinglayer
32cdf0e10cSrcweir {
33cdf0e10cSrcweir 	namespace attribute
34cdf0e10cSrcweir 	{
35cdf0e10cSrcweir 		class ImpSdrShadowAttribute
36cdf0e10cSrcweir 		{
37cdf0e10cSrcweir 		public:
38cdf0e10cSrcweir 			// refcounter
39cdf0e10cSrcweir 			sal_uInt32								mnRefCount;
40cdf0e10cSrcweir 
41cdf0e10cSrcweir 			// shadow definitions
42cdf0e10cSrcweir 			basegfx::B2DVector					maOffset;					// shadow offset 1/100th mm
43cdf0e10cSrcweir 			double								mfTransparence;				// [0.0 .. 1.0], 0.0==no transp.
44cdf0e10cSrcweir 			basegfx::BColor						maColor;					// color of shadow
45cdf0e10cSrcweir 
ImpSdrShadowAttribute(const basegfx::B2DVector & rOffset,double fTransparence,const basegfx::BColor & rColor)46cdf0e10cSrcweir 			ImpSdrShadowAttribute(
47cdf0e10cSrcweir 				const basegfx::B2DVector& rOffset,
48cdf0e10cSrcweir                 double fTransparence,
49cdf0e10cSrcweir                 const basegfx::BColor& rColor)
50cdf0e10cSrcweir 			:	mnRefCount(0),
51cdf0e10cSrcweir 		    	maOffset(rOffset),
52cdf0e10cSrcweir 			    mfTransparence(fTransparence),
53cdf0e10cSrcweir 			    maColor(rColor)
54cdf0e10cSrcweir 		    {
55cdf0e10cSrcweir 		    }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 			// data read access
getOffset() const58cdf0e10cSrcweir 			const basegfx::B2DVector& getOffset() const { return maOffset; }
getTransparence() const59cdf0e10cSrcweir 			double getTransparence() const { return mfTransparence;	}
getColor() const60cdf0e10cSrcweir 			const basegfx::BColor& getColor() const { return maColor; }
61cdf0e10cSrcweir 
operator ==(const ImpSdrShadowAttribute & rCandidate) const62cdf0e10cSrcweir 			bool operator==(const ImpSdrShadowAttribute& rCandidate) const
63cdf0e10cSrcweir 		    {
64cdf0e10cSrcweir 			    return (getOffset() == rCandidate.getOffset()
65cdf0e10cSrcweir                     && getTransparence() == rCandidate.getTransparence()
66cdf0e10cSrcweir 				    && getColor() == rCandidate.getColor());
67cdf0e10cSrcweir 		    }
68cdf0e10cSrcweir 
get_global_default()69cdf0e10cSrcweir             static ImpSdrShadowAttribute* get_global_default()
70cdf0e10cSrcweir             {
71cdf0e10cSrcweir                 static ImpSdrShadowAttribute* pDefault = 0;
72cdf0e10cSrcweir 
73cdf0e10cSrcweir                 if(!pDefault)
74cdf0e10cSrcweir                 {
75cdf0e10cSrcweir                     pDefault = new ImpSdrShadowAttribute(
76cdf0e10cSrcweir                         basegfx::B2DVector(),
77cdf0e10cSrcweir                         0.0,
78cdf0e10cSrcweir                         basegfx::BColor());
79cdf0e10cSrcweir 
80cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
81cdf0e10cSrcweir     			    pDefault->mnRefCount++;
82cdf0e10cSrcweir                 }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir                 return pDefault;
85cdf0e10cSrcweir             }
86cdf0e10cSrcweir 		};
87cdf0e10cSrcweir 
SdrShadowAttribute(const basegfx::B2DVector & rOffset,double fTransparence,const basegfx::BColor & rColor)88cdf0e10cSrcweir         SdrShadowAttribute::SdrShadowAttribute(
89cdf0e10cSrcweir             const basegfx::B2DVector& rOffset,
90cdf0e10cSrcweir             double fTransparence,
91cdf0e10cSrcweir             const basegfx::BColor& rColor)
92cdf0e10cSrcweir 		:	mpSdrShadowAttribute(new ImpSdrShadowAttribute(
93cdf0e10cSrcweir                 rOffset, fTransparence, rColor))
94cdf0e10cSrcweir 		{
95cdf0e10cSrcweir 		}
96cdf0e10cSrcweir 
SdrShadowAttribute()97cdf0e10cSrcweir 		SdrShadowAttribute::SdrShadowAttribute()
98cdf0e10cSrcweir         :	mpSdrShadowAttribute(ImpSdrShadowAttribute::get_global_default())
99cdf0e10cSrcweir 		{
100cdf0e10cSrcweir 			mpSdrShadowAttribute->mnRefCount++;
101cdf0e10cSrcweir 		}
102cdf0e10cSrcweir 
SdrShadowAttribute(const SdrShadowAttribute & rCandidate)103cdf0e10cSrcweir         SdrShadowAttribute::SdrShadowAttribute(const SdrShadowAttribute& rCandidate)
104cdf0e10cSrcweir 		:	mpSdrShadowAttribute(rCandidate.mpSdrShadowAttribute)
105cdf0e10cSrcweir 		{
106cdf0e10cSrcweir 			mpSdrShadowAttribute->mnRefCount++;
107cdf0e10cSrcweir 		}
108cdf0e10cSrcweir 
~SdrShadowAttribute()109cdf0e10cSrcweir 		SdrShadowAttribute::~SdrShadowAttribute()
110cdf0e10cSrcweir 		{
111cdf0e10cSrcweir 			if(mpSdrShadowAttribute->mnRefCount)
112cdf0e10cSrcweir 			{
113cdf0e10cSrcweir 				mpSdrShadowAttribute->mnRefCount--;
114cdf0e10cSrcweir 			}
115cdf0e10cSrcweir 			else
116cdf0e10cSrcweir 			{
117cdf0e10cSrcweir 				delete mpSdrShadowAttribute;
118cdf0e10cSrcweir 			}
119cdf0e10cSrcweir 		}
120cdf0e10cSrcweir 
isDefault() const121cdf0e10cSrcweir         bool SdrShadowAttribute::isDefault() const
122cdf0e10cSrcweir         {
123cdf0e10cSrcweir             return mpSdrShadowAttribute == ImpSdrShadowAttribute::get_global_default();
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir 
operator =(const SdrShadowAttribute & rCandidate)126cdf0e10cSrcweir         SdrShadowAttribute& SdrShadowAttribute::operator=(const SdrShadowAttribute& rCandidate)
127cdf0e10cSrcweir 		{
128cdf0e10cSrcweir 			if(rCandidate.mpSdrShadowAttribute != mpSdrShadowAttribute)
129cdf0e10cSrcweir 			{
130cdf0e10cSrcweir 				if(mpSdrShadowAttribute->mnRefCount)
131cdf0e10cSrcweir 				{
132cdf0e10cSrcweir 					mpSdrShadowAttribute->mnRefCount--;
133cdf0e10cSrcweir 				}
134cdf0e10cSrcweir 				else
135cdf0e10cSrcweir 				{
136cdf0e10cSrcweir 					delete mpSdrShadowAttribute;
137cdf0e10cSrcweir 				}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 				mpSdrShadowAttribute = rCandidate.mpSdrShadowAttribute;
140cdf0e10cSrcweir 				mpSdrShadowAttribute->mnRefCount++;
141cdf0e10cSrcweir 			}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 			return *this;
144cdf0e10cSrcweir 		}
145cdf0e10cSrcweir 
operator ==(const SdrShadowAttribute & rCandidate) const146cdf0e10cSrcweir 		bool SdrShadowAttribute::operator==(const SdrShadowAttribute& rCandidate) const
147cdf0e10cSrcweir 		{
148cdf0e10cSrcweir 			if(rCandidate.mpSdrShadowAttribute == mpSdrShadowAttribute)
149cdf0e10cSrcweir 			{
150cdf0e10cSrcweir 				return true;
151cdf0e10cSrcweir 			}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
154cdf0e10cSrcweir 			{
155cdf0e10cSrcweir 				return false;
156cdf0e10cSrcweir 			}
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 			return (*rCandidate.mpSdrShadowAttribute == *mpSdrShadowAttribute);
159cdf0e10cSrcweir 		}
160cdf0e10cSrcweir 
getOffset() const161cdf0e10cSrcweir 		const basegfx::B2DVector& SdrShadowAttribute::getOffset() const
162cdf0e10cSrcweir         {
163cdf0e10cSrcweir             return mpSdrShadowAttribute->getOffset();
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir 
getTransparence() const166cdf0e10cSrcweir 		double SdrShadowAttribute::getTransparence() const
167cdf0e10cSrcweir         {
168cdf0e10cSrcweir             return mpSdrShadowAttribute->getTransparence();
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir 
getColor() const171cdf0e10cSrcweir 		const basegfx::BColor& SdrShadowAttribute::getColor() const
172cdf0e10cSrcweir         {
173cdf0e10cSrcweir             return mpSdrShadowAttribute->getColor();
174cdf0e10cSrcweir         }
175cdf0e10cSrcweir     } // end of namespace attribute
176cdf0e10cSrcweir } // end of namespace drawinglayer
177cdf0e10cSrcweir 
178cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
179cdf0e10cSrcweir // eof
180