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