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/fillgradientattribute.hxx>
26 #include <basegfx/color/bcolor.hxx>
27 
28 //////////////////////////////////////////////////////////////////////////////
29 
30 namespace drawinglayer
31 {
32 	namespace attribute
33 	{
34 	    class ImpFillGradientAttribute
35 	    {
36         public:
37 		    // refcounter
38 		    sal_uInt32								mnRefCount;
39 
40             // data definitions
41 		    GradientStyle							meStyle;
42 		    double									mfBorder;
43 		    double									mfOffsetX;
44 		    double									mfOffsetY;
45 		    double									mfAngle;
46             basegfx::BColor							maStartColor;
47 		    basegfx::BColor							maEndColor;
48 		    sal_uInt16								mnSteps;
49 
ImpFillGradientAttribute(GradientStyle eStyle,double fBorder,double fOffsetX,double fOffsetY,double fAngle,const basegfx::BColor & rStartColor,const basegfx::BColor & rEndColor,sal_uInt16 nSteps)50 		    ImpFillGradientAttribute(
51 			    GradientStyle eStyle,
52                 double fBorder,
53                 double fOffsetX,
54                 double fOffsetY,
55                 double fAngle,
56 			    const basegfx::BColor& rStartColor,
57                 const basegfx::BColor& rEndColor,
58                 sal_uInt16 nSteps)
59 		    :	mnRefCount(0),
60 		        meStyle(eStyle),
61 		        mfBorder(fBorder),
62 		        mfOffsetX(fOffsetX),
63 		        mfOffsetY(fOffsetY),
64 		        mfAngle(fAngle),
65                 maStartColor(rStartColor),
66 		        maEndColor(rEndColor),
67 		        mnSteps(nSteps)
68             {
69             }
70 
71 		    // data read access
getStyle() const72 		    GradientStyle getStyle() const { return meStyle; }
getBorder() const73 		    double getBorder() const { return mfBorder; }
getOffsetX() const74 		    double getOffsetX() const { return mfOffsetX; }
getOffsetY() const75 		    double getOffsetY() const { return mfOffsetY; }
getAngle() const76 		    double getAngle() const { return mfAngle; }
getStartColor() const77 		    const basegfx::BColor& getStartColor() const { return maStartColor; }
getEndColor() const78 		    const basegfx::BColor& getEndColor() const { return maEndColor; }
getSteps() const79 		    sal_uInt16 getSteps() const { return mnSteps; }
80 
operator ==(const ImpFillGradientAttribute & rCandidate) const81 		    bool operator==(const ImpFillGradientAttribute& rCandidate) const
82             {
83 		        return (getStyle() == rCandidate.getStyle()
84 			        && getBorder() == rCandidate.getBorder()
85 			        && getOffsetX() == rCandidate.getOffsetX()
86 			        && getOffsetY() == rCandidate.getOffsetY()
87 			        && getAngle() == rCandidate.getAngle()
88                     && getStartColor() == rCandidate.getStartColor()
89 			        && getEndColor() == rCandidate.getEndColor()
90 			        && getSteps() == rCandidate.getSteps());
91             }
92 
get_global_default()93             static ImpFillGradientAttribute* get_global_default()
94             {
95                 static ImpFillGradientAttribute* pDefault = 0;
96 
97                 if(!pDefault)
98                 {
99                     pDefault = new ImpFillGradientAttribute(
100                         GRADIENTSTYLE_LINEAR,
101                         0.0, 0.0, 0.0, 0.0,
102                         basegfx::BColor(),
103                         basegfx::BColor(),
104                         0);
105 
106                     // never delete; start with RefCount 1, not 0
107     			    pDefault->mnRefCount++;
108                 }
109 
110                 return pDefault;
111             }
112 	    };
113 
FillGradientAttribute(GradientStyle eStyle,double fBorder,double fOffsetX,double fOffsetY,double fAngle,const basegfx::BColor & rStartColor,const basegfx::BColor & rEndColor,sal_uInt16 nSteps)114         FillGradientAttribute::FillGradientAttribute(
115 			GradientStyle eStyle,
116             double fBorder,
117             double fOffsetX,
118             double fOffsetY,
119             double fAngle,
120 			const basegfx::BColor& rStartColor,
121             const basegfx::BColor& rEndColor,
122             sal_uInt16 nSteps)
123         :	mpFillGradientAttribute(new ImpFillGradientAttribute(
124                 eStyle, fBorder, fOffsetX, fOffsetY, fAngle, rStartColor, rEndColor, nSteps))
125 		{
126 		}
127 
FillGradientAttribute()128 		FillGradientAttribute::FillGradientAttribute()
129         :	mpFillGradientAttribute(ImpFillGradientAttribute::get_global_default())
130 		{
131 			mpFillGradientAttribute->mnRefCount++;
132 		}
133 
FillGradientAttribute(const FillGradientAttribute & rCandidate)134 		FillGradientAttribute::FillGradientAttribute(const FillGradientAttribute& rCandidate)
135 		:	mpFillGradientAttribute(rCandidate.mpFillGradientAttribute)
136 		{
137 			mpFillGradientAttribute->mnRefCount++;
138 		}
139 
~FillGradientAttribute()140 		FillGradientAttribute::~FillGradientAttribute()
141 		{
142 			if(mpFillGradientAttribute->mnRefCount)
143 			{
144 				mpFillGradientAttribute->mnRefCount--;
145 			}
146 			else
147 			{
148 				delete mpFillGradientAttribute;
149 			}
150 		}
151 
isDefault() const152         bool FillGradientAttribute::isDefault() const
153         {
154             return mpFillGradientAttribute == ImpFillGradientAttribute::get_global_default();
155         }
156 
operator =(const FillGradientAttribute & rCandidate)157         FillGradientAttribute& FillGradientAttribute::operator=(const FillGradientAttribute& rCandidate)
158 		{
159 			if(rCandidate.mpFillGradientAttribute != mpFillGradientAttribute)
160 			{
161 				if(mpFillGradientAttribute->mnRefCount)
162 				{
163 					mpFillGradientAttribute->mnRefCount--;
164 				}
165 				else
166 				{
167 					delete mpFillGradientAttribute;
168 				}
169 
170 				mpFillGradientAttribute = rCandidate.mpFillGradientAttribute;
171 				mpFillGradientAttribute->mnRefCount++;
172 			}
173 
174 			return *this;
175 		}
176 
operator ==(const FillGradientAttribute & rCandidate) const177 		bool FillGradientAttribute::operator==(const FillGradientAttribute& rCandidate) const
178 		{
179 			if(rCandidate.mpFillGradientAttribute == mpFillGradientAttribute)
180 			{
181 				return true;
182 			}
183 
184 			if(rCandidate.isDefault() != isDefault())
185 			{
186 				return false;
187 			}
188 
189 			return (*rCandidate.mpFillGradientAttribute == *mpFillGradientAttribute);
190 		}
191 
getStartColor() const192 		const basegfx::BColor& FillGradientAttribute::getStartColor() const
193         {
194             return mpFillGradientAttribute->getStartColor();
195         }
196 
getEndColor() const197 		const basegfx::BColor& FillGradientAttribute::getEndColor() const
198         {
199             return mpFillGradientAttribute->getEndColor();
200         }
201 
getBorder() const202 		double FillGradientAttribute::getBorder() const
203         {
204             return mpFillGradientAttribute->getBorder();
205         }
206 
getOffsetX() const207 		double FillGradientAttribute::getOffsetX() const
208         {
209             return mpFillGradientAttribute->getOffsetX();
210         }
211 
getOffsetY() const212 		double FillGradientAttribute::getOffsetY() const
213         {
214             return mpFillGradientAttribute->getOffsetY();
215         }
216 
getAngle() const217 		double FillGradientAttribute::getAngle() const
218         {
219             return mpFillGradientAttribute->getAngle();
220         }
221 
getStyle() const222 		GradientStyle FillGradientAttribute::getStyle() const
223         {
224             return mpFillGradientAttribute->getStyle();
225         }
226 
getSteps() const227 		sal_uInt16 FillGradientAttribute::getSteps() const
228         {
229             return mpFillGradientAttribute->getSteps();
230         }
231 
232     } // end of namespace attribute
233 } // end of namespace drawinglayer
234 
235 //////////////////////////////////////////////////////////////////////////////
236 // eof
237