xref: /trunk/main/drawinglayer/source/attribute/fillgradientattribute.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  *  OpenOffice.org - a multi-platform office productivity suite
4  *
5  *  $RCSfile: fillattribute.cxx,v $
6  *
7  *  $Revision: 1.4 $
8  *
9  *  last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $
10  *
11  *  The Contents of this file are made available subject to
12  *  the terms of GNU Lesser General Public License Version 2.1.
13  *
14  *
15  *    GNU Lesser General Public License Version 2.1
16  *    =============================================
17  *    Copyright 2005 by Sun Microsystems, Inc.
18  *    901 San Antonio Road, Palo Alto, CA 94303, USA
19  *
20  *    This library is free software; you can redistribute it and/or
21  *    modify it under the terms of the GNU Lesser General Public
22  *    License version 2.1, as published by the Free Software Foundation.
23  *
24  *    This library is distributed in the hope that it will be useful,
25  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27  *    Lesser General Public License for more details.
28  *
29  *    You should have received a copy of the GNU Lesser General Public
30  *    License along with this library; if not, write to the Free Software
31  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32  *    MA  02111-1307  USA
33  *
34  ************************************************************************/
35 
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
38 
39 #include <drawinglayer/attribute/fillgradientattribute.hxx>
40 #include <basegfx/color/bcolor.hxx>
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace drawinglayer
45 {
46     namespace attribute
47     {
48         class ImpFillGradientAttribute
49         {
50         public:
51             // refcounter
52             sal_uInt32                              mnRefCount;
53 
54             // data definitions
55             GradientStyle                           meStyle;
56             double                                  mfBorder;
57             double                                  mfOffsetX;
58             double                                  mfOffsetY;
59             double                                  mfAngle;
60             basegfx::BColor                         maStartColor;
61             basegfx::BColor                         maEndColor;
62             sal_uInt16                              mnSteps;
63 
64             ImpFillGradientAttribute(
65                 GradientStyle eStyle,
66                 double fBorder,
67                 double fOffsetX,
68                 double fOffsetY,
69                 double fAngle,
70                 const basegfx::BColor& rStartColor,
71                 const basegfx::BColor& rEndColor,
72                 sal_uInt16 nSteps)
73             :   mnRefCount(0),
74                 meStyle(eStyle),
75                 mfBorder(fBorder),
76                 mfOffsetX(fOffsetX),
77                 mfOffsetY(fOffsetY),
78                 mfAngle(fAngle),
79                 maStartColor(rStartColor),
80                 maEndColor(rEndColor),
81                 mnSteps(nSteps)
82             {
83             }
84 
85             // data read access
86             GradientStyle getStyle() const { return meStyle; }
87             double getBorder() const { return mfBorder; }
88             double getOffsetX() const { return mfOffsetX; }
89             double getOffsetY() const { return mfOffsetY; }
90             double getAngle() const { return mfAngle; }
91             const basegfx::BColor& getStartColor() const { return maStartColor; }
92             const basegfx::BColor& getEndColor() const { return maEndColor; }
93             sal_uInt16 getSteps() const { return mnSteps; }
94 
95             bool operator==(const ImpFillGradientAttribute& rCandidate) const
96             {
97                 return (getStyle() == rCandidate.getStyle()
98                     && getBorder() == rCandidate.getBorder()
99                     && getOffsetX() == rCandidate.getOffsetX()
100                     && getOffsetY() == rCandidate.getOffsetY()
101                     && getAngle() == rCandidate.getAngle()
102                     && getStartColor() == rCandidate.getStartColor()
103                     && getEndColor() == rCandidate.getEndColor()
104                     && getSteps() == rCandidate.getSteps());
105             }
106 
107             static ImpFillGradientAttribute* get_global_default()
108             {
109                 static ImpFillGradientAttribute* pDefault = 0;
110 
111                 if(!pDefault)
112                 {
113                     pDefault = new ImpFillGradientAttribute(
114                         GRADIENTSTYLE_LINEAR,
115                         0.0, 0.0, 0.0, 0.0,
116                         basegfx::BColor(),
117                         basegfx::BColor(),
118                         0);
119 
120                     // never delete; start with RefCount 1, not 0
121                     pDefault->mnRefCount++;
122                 }
123 
124                 return pDefault;
125             }
126         };
127 
128         FillGradientAttribute::FillGradientAttribute(
129             GradientStyle eStyle,
130             double fBorder,
131             double fOffsetX,
132             double fOffsetY,
133             double fAngle,
134             const basegfx::BColor& rStartColor,
135             const basegfx::BColor& rEndColor,
136             sal_uInt16 nSteps)
137         :   mpFillGradientAttribute(new ImpFillGradientAttribute(
138                 eStyle, fBorder, fOffsetX, fOffsetY, fAngle, rStartColor, rEndColor, nSteps))
139         {
140         }
141 
142         FillGradientAttribute::FillGradientAttribute()
143         :   mpFillGradientAttribute(ImpFillGradientAttribute::get_global_default())
144         {
145             mpFillGradientAttribute->mnRefCount++;
146         }
147 
148         FillGradientAttribute::FillGradientAttribute(const FillGradientAttribute& rCandidate)
149         :   mpFillGradientAttribute(rCandidate.mpFillGradientAttribute)
150         {
151             mpFillGradientAttribute->mnRefCount++;
152         }
153 
154         FillGradientAttribute::~FillGradientAttribute()
155         {
156             if(mpFillGradientAttribute->mnRefCount)
157             {
158                 mpFillGradientAttribute->mnRefCount--;
159             }
160             else
161             {
162                 delete mpFillGradientAttribute;
163             }
164         }
165 
166         bool FillGradientAttribute::isDefault() const
167         {
168             return mpFillGradientAttribute == ImpFillGradientAttribute::get_global_default();
169         }
170 
171         FillGradientAttribute& FillGradientAttribute::operator=(const FillGradientAttribute& rCandidate)
172         {
173             if(rCandidate.mpFillGradientAttribute != mpFillGradientAttribute)
174             {
175                 if(mpFillGradientAttribute->mnRefCount)
176                 {
177                     mpFillGradientAttribute->mnRefCount--;
178                 }
179                 else
180                 {
181                     delete mpFillGradientAttribute;
182                 }
183 
184                 mpFillGradientAttribute = rCandidate.mpFillGradientAttribute;
185                 mpFillGradientAttribute->mnRefCount++;
186             }
187 
188             return *this;
189         }
190 
191         bool FillGradientAttribute::operator==(const FillGradientAttribute& rCandidate) const
192         {
193             if(rCandidate.mpFillGradientAttribute == mpFillGradientAttribute)
194             {
195                 return true;
196             }
197 
198             if(rCandidate.isDefault() != isDefault())
199             {
200                 return false;
201             }
202 
203             return (*rCandidate.mpFillGradientAttribute == *mpFillGradientAttribute);
204         }
205 
206         const basegfx::BColor& FillGradientAttribute::getStartColor() const
207         {
208             return mpFillGradientAttribute->getStartColor();
209         }
210 
211         const basegfx::BColor& FillGradientAttribute::getEndColor() const
212         {
213             return mpFillGradientAttribute->getEndColor();
214         }
215 
216         double FillGradientAttribute::getBorder() const
217         {
218             return mpFillGradientAttribute->getBorder();
219         }
220 
221         double FillGradientAttribute::getOffsetX() const
222         {
223             return mpFillGradientAttribute->getOffsetX();
224         }
225 
226         double FillGradientAttribute::getOffsetY() const
227         {
228             return mpFillGradientAttribute->getOffsetY();
229         }
230 
231         double FillGradientAttribute::getAngle() const
232         {
233             return mpFillGradientAttribute->getAngle();
234         }
235 
236         GradientStyle FillGradientAttribute::getStyle() const
237         {
238             return mpFillGradientAttribute->getStyle();
239         }
240 
241         sal_uInt16 FillGradientAttribute::getSteps() const
242         {
243             return mpFillGradientAttribute->getSteps();
244         }
245 
246     } // end of namespace attribute
247 } // end of namespace drawinglayer
248 
249 //////////////////////////////////////////////////////////////////////////////
250 // eof
251