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/sdrfillattribute.hxx>
26 #include <basegfx/color/bcolor.hxx>
27 #include <drawinglayer/attribute/sdrfillgraphicattribute.hxx>
28 #include <drawinglayer/attribute/fillhatchattribute.hxx>
29 #include <drawinglayer/attribute/fillgradientattribute.hxx>
30 
31 //////////////////////////////////////////////////////////////////////////////
32 
33 namespace drawinglayer
34 {
35 	namespace attribute
36 	{
37 		class ImpSdrFillAttribute
38 		{
39 		public:
40 			// refcounter
41 			sal_uInt32							mnRefCount;
42 
43 			// fill definitions
44 			double								mfTransparence;		// [0.0 .. 1.0], 0.0==no transp.
45 			basegfx::BColor						maColor;			// fill color
46 			FillGradientAttribute				maGradient;			// fill gradient (if used)
47 			FillHatchAttribute					maHatch;			// fill hatch (if used)
48 			SdrFillGraphicAttribute				maFillGraphic;		// fill graphic (if used)
49 
50 		public:
ImpSdrFillAttribute(double fTransparence,const basegfx::BColor & rColor,const FillGradientAttribute & rGradient,const FillHatchAttribute & rHatch,const SdrFillGraphicAttribute & rFillGraphic)51 			ImpSdrFillAttribute(
52 				double fTransparence,
53                 const basegfx::BColor& rColor,
54                 const FillGradientAttribute& rGradient,
55 				const FillHatchAttribute& rHatch,
56                 const SdrFillGraphicAttribute& rFillGraphic)
57 			:	mnRefCount(0),
58 			    mfTransparence(fTransparence),
59 			    maColor(rColor),
60 			    maGradient(rGradient),
61 			    maHatch(rHatch),
62 			    maFillGraphic(rFillGraphic)
63             {
64             }
65 
66 			// data read access
getTransparence() const67 			double getTransparence() const { return mfTransparence;	}
getColor() const68 			const basegfx::BColor& getColor() const { return maColor; }
getGradient() const69 			const FillGradientAttribute& getGradient() const { return maGradient; }
getHatch() const70 			const FillHatchAttribute& getHatch() const { return maHatch; }
getFillGraphic() const71 			const SdrFillGraphicAttribute& getFillGraphic() const { return maFillGraphic; }
72 
73             // compare operator
operator ==(const ImpSdrFillAttribute & rCandidate) const74 			bool operator==(const ImpSdrFillAttribute& rCandidate) const
75             {
76                 return(getTransparence() == rCandidate.getTransparence()
77                     && getColor() == rCandidate.getColor()
78                     && getGradient() == rCandidate.getGradient()
79                     && getHatch() == rCandidate.getHatch()
80                     && getFillGraphic() == rCandidate.getFillGraphic());
81             }
82 
get_global_default()83             static ImpSdrFillAttribute* get_global_default()
84             {
85                 static ImpSdrFillAttribute* pDefault = 0;
86 
87                 if(!pDefault)
88                 {
89                     pDefault = new ImpSdrFillAttribute(
90 				        0.0,
91                         basegfx::BColor(),
92                         FillGradientAttribute(),
93 				        FillHatchAttribute(),
94                         SdrFillGraphicAttribute());
95 
96                     // never delete; start with RefCount 1, not 0
97     			    pDefault->mnRefCount++;
98                 }
99 
100                 return pDefault;
101             }
102 		};
103 
SdrFillAttribute(double fTransparence,const basegfx::BColor & rColor,const FillGradientAttribute & rGradient,const FillHatchAttribute & rHatch,const SdrFillGraphicAttribute & rFillGraphic)104         SdrFillAttribute::SdrFillAttribute(
105 			double fTransparence,
106             const basegfx::BColor& rColor,
107             const FillGradientAttribute& rGradient,
108 			const FillHatchAttribute& rHatch,
109             const SdrFillGraphicAttribute& rFillGraphic)
110 		:	mpSdrFillAttribute(
111                 new ImpSdrFillAttribute(
112                     fTransparence, rColor, rGradient, rHatch, rFillGraphic))
113 		{
114 		}
115 
SdrFillAttribute()116 		SdrFillAttribute::SdrFillAttribute()
117         :	mpSdrFillAttribute(ImpSdrFillAttribute::get_global_default())
118 		{
119 			mpSdrFillAttribute->mnRefCount++;
120 		}
121 
SdrFillAttribute(const SdrFillAttribute & rCandidate)122         SdrFillAttribute::SdrFillAttribute(const SdrFillAttribute& rCandidate)
123 		:	mpSdrFillAttribute(rCandidate.mpSdrFillAttribute)
124 		{
125 			mpSdrFillAttribute->mnRefCount++;
126 		}
127 
~SdrFillAttribute()128 		SdrFillAttribute::~SdrFillAttribute()
129 		{
130 			if(mpSdrFillAttribute->mnRefCount)
131 			{
132 				mpSdrFillAttribute->mnRefCount--;
133 			}
134 			else
135 			{
136 				delete mpSdrFillAttribute;
137 			}
138 		}
139 
isDefault() const140         bool SdrFillAttribute::isDefault() const
141         {
142             return mpSdrFillAttribute == ImpSdrFillAttribute::get_global_default();
143         }
144 
operator =(const SdrFillAttribute & rCandidate)145         SdrFillAttribute& SdrFillAttribute::operator=(const SdrFillAttribute& rCandidate)
146 		{
147 			if(rCandidate.mpSdrFillAttribute != mpSdrFillAttribute)
148 			{
149 				if(mpSdrFillAttribute->mnRefCount)
150 				{
151 					mpSdrFillAttribute->mnRefCount--;
152 				}
153 				else
154 				{
155 					delete mpSdrFillAttribute;
156 				}
157 
158 				mpSdrFillAttribute = rCandidate.mpSdrFillAttribute;
159 				mpSdrFillAttribute->mnRefCount++;
160 			}
161 
162 			return *this;
163 		}
164 
operator ==(const SdrFillAttribute & rCandidate) const165 		bool SdrFillAttribute::operator==(const SdrFillAttribute& rCandidate) const
166 		{
167 			if(rCandidate.mpSdrFillAttribute == mpSdrFillAttribute)
168 			{
169 				return true;
170 			}
171 
172 			if(rCandidate.isDefault() != isDefault())
173 			{
174 				return false;
175 			}
176 
177 			return (*rCandidate.mpSdrFillAttribute == *mpSdrFillAttribute);
178 		}
179 
getTransparence() const180 		double SdrFillAttribute::getTransparence() const
181         {
182             return mpSdrFillAttribute->getTransparence();
183         }
184 
getColor() const185 		const basegfx::BColor& SdrFillAttribute::getColor() const
186         {
187             return mpSdrFillAttribute->getColor();
188         }
189 
getGradient() const190 		const FillGradientAttribute& SdrFillAttribute::getGradient() const
191         {
192             return mpSdrFillAttribute->getGradient();
193         }
194 
getHatch() const195 		const FillHatchAttribute& SdrFillAttribute::getHatch() const
196         {
197             return mpSdrFillAttribute->getHatch();
198         }
199 
getFillGraphic() const200 		const SdrFillGraphicAttribute& SdrFillAttribute::getFillGraphic() const
201         {
202             return mpSdrFillAttribute->getFillGraphic();
203         }
204     } // end of namespace attribute
205 } // end of namespace drawinglayer
206 
207 //////////////////////////////////////////////////////////////////////////////
208 // eof
209