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