xref: /trunk/main/drawinglayer/source/attribute/fillhatchattribute.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/fillhatchattribute.hxx>
40 #include <basegfx/color/bcolor.hxx>
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace drawinglayer
45 {
46     namespace attribute
47     {
48         class ImpFillHatchAttribute
49         {
50         public:
51             // refcounter
52             sal_uInt32                              mnRefCount;
53 
54             // data definitions
55             HatchStyle                              meStyle;
56             double                                  mfDistance;
57             double                                  mfAngle;
58             basegfx::BColor                         maColor;
59 
60             // bitfield
61             unsigned                                mbFillBackground : 1;
62 
63             ImpFillHatchAttribute(
64                 HatchStyle eStyle,
65                 double fDistance,
66                 double fAngle,
67                 const basegfx::BColor& rColor,
68                 bool bFillBackground)
69             :   mnRefCount(0),
70                 meStyle(eStyle),
71                 mfDistance(fDistance),
72                 mfAngle(fAngle),
73                 maColor(rColor),
74                 mbFillBackground(bFillBackground)
75             {
76             }
77 
78             // data read access
79             HatchStyle getStyle() const { return meStyle; }
80             double getDistance() const { return mfDistance; }
81             double getAngle() const { return mfAngle; }
82             const basegfx::BColor& getColor() const { return maColor; }
83             bool isFillBackground() const { return mbFillBackground; }
84 
85             bool operator==(const ImpFillHatchAttribute& rCandidate) const
86             {
87                 return (getStyle() == rCandidate.getStyle()
88                     && getDistance() == rCandidate.getDistance()
89                     && getAngle() == rCandidate.getAngle()
90                     && getColor() == rCandidate.getColor()
91                     && isFillBackground()  == rCandidate.isFillBackground());
92             }
93 
94             static ImpFillHatchAttribute* get_global_default()
95             {
96                 static ImpFillHatchAttribute* pDefault = 0;
97 
98                 if(!pDefault)
99                 {
100                     pDefault = new ImpFillHatchAttribute(
101                         HATCHSTYLE_SINGLE,
102                         0.0, 0.0,
103                         basegfx::BColor(),
104                         false);
105 
106                     // never delete; start with RefCount 1, not 0
107                     pDefault->mnRefCount++;
108                 }
109 
110                 return pDefault;
111             }
112         };
113 
114         FillHatchAttribute::FillHatchAttribute(
115             HatchStyle eStyle,
116             double fDistance,
117             double fAngle,
118             const basegfx::BColor& rColor,
119             bool bFillBackground)
120         :   mpFillHatchAttribute(new ImpFillHatchAttribute(
121                 eStyle, fDistance, fAngle, rColor, bFillBackground))
122         {
123         }
124 
125         FillHatchAttribute::FillHatchAttribute()
126         :   mpFillHatchAttribute(ImpFillHatchAttribute::get_global_default())
127         {
128             mpFillHatchAttribute->mnRefCount++;
129         }
130 
131         FillHatchAttribute::FillHatchAttribute(const FillHatchAttribute& rCandidate)
132         :   mpFillHatchAttribute(rCandidate.mpFillHatchAttribute)
133         {
134             mpFillHatchAttribute->mnRefCount++;
135         }
136 
137         FillHatchAttribute::~FillHatchAttribute()
138         {
139             if(mpFillHatchAttribute->mnRefCount)
140             {
141                 mpFillHatchAttribute->mnRefCount--;
142             }
143             else
144             {
145                 delete mpFillHatchAttribute;
146             }
147         }
148 
149         bool FillHatchAttribute::isDefault() const
150         {
151             return mpFillHatchAttribute == ImpFillHatchAttribute::get_global_default();
152         }
153 
154         FillHatchAttribute& FillHatchAttribute::operator=(const FillHatchAttribute& rCandidate)
155         {
156             if(rCandidate.mpFillHatchAttribute != mpFillHatchAttribute)
157             {
158                 if(mpFillHatchAttribute->mnRefCount)
159                 {
160                     mpFillHatchAttribute->mnRefCount--;
161                 }
162                 else
163                 {
164                     delete mpFillHatchAttribute;
165                 }
166 
167                 mpFillHatchAttribute = rCandidate.mpFillHatchAttribute;
168                 mpFillHatchAttribute->mnRefCount++;
169             }
170 
171             return *this;
172         }
173 
174         bool FillHatchAttribute::operator==(const FillHatchAttribute& rCandidate) const
175         {
176             if(rCandidate.mpFillHatchAttribute == mpFillHatchAttribute)
177             {
178                 return true;
179             }
180 
181             if(rCandidate.isDefault() != isDefault())
182             {
183                 return false;
184             }
185 
186             return (*rCandidate.mpFillHatchAttribute == *mpFillHatchAttribute);
187         }
188 
189         // data read access
190         HatchStyle FillHatchAttribute::getStyle() const
191         {
192             return mpFillHatchAttribute->getStyle();
193         }
194 
195         double FillHatchAttribute::getDistance() const
196         {
197             return mpFillHatchAttribute->getDistance();
198         }
199 
200         double FillHatchAttribute::getAngle() const
201         {
202             return mpFillHatchAttribute->getAngle();
203         }
204 
205         const basegfx::BColor& FillHatchAttribute::getColor() const
206         {
207             return mpFillHatchAttribute->getColor();
208         }
209 
210         bool FillHatchAttribute::isFillBackground() const
211         {
212             return mpFillHatchAttribute->isFillBackground();
213         }
214 
215     } // end of namespace attribute
216 } // end of namespace drawinglayer
217 
218 //////////////////////////////////////////////////////////////////////////////
219 // eof
220