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