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/sdrlinestartendattribute.hxx>
26 #include <basegfx/polygon/b2dpolypolygon.hxx>
27 
28 //////////////////////////////////////////////////////////////////////////////
29 
30 namespace drawinglayer
31 {
32 	namespace attribute
33 	{
34 		class ImpSdrLineStartEndAttribute
35 		{
36 		public:
37 			// refcounter
38 			sal_uInt32								mnRefCount;
39 
40 			// line arrow definitions
41 			basegfx::B2DPolyPolygon					maStartPolyPolygon;		// start Line PolyPolygon
42 			basegfx::B2DPolyPolygon					maEndPolyPolygon;		// end Line PolyPolygon
43 			double									mfStartWidth;			// 1/100th mm
44 			double									mfEndWidth;				// 1/100th mm
45 
46 			// bitfield
47 			unsigned								mbStartActive : 1L;		// start of Line is active
48 			unsigned								mbEndActive : 1L;		// end of Line is active
49 			unsigned								mbStartCentered : 1L;	// Line is centered on line start point
50 			unsigned								mbEndCentered : 1L;		// Line is centered on line end point
51 
ImpSdrLineStartEndAttribute(const basegfx::B2DPolyPolygon & rStartPolyPolygon,const basegfx::B2DPolyPolygon & rEndPolyPolygon,double fStartWidth,double fEndWidth,bool bStartActive,bool bEndActive,bool bStartCentered,bool bEndCentered)52 			ImpSdrLineStartEndAttribute(
53 				const basegfx::B2DPolyPolygon& rStartPolyPolygon,
54                 const basegfx::B2DPolyPolygon& rEndPolyPolygon,
55 				double fStartWidth,
56                 double fEndWidth,
57                 bool bStartActive,
58                 bool bEndActive,
59                 bool bStartCentered,
60                 bool bEndCentered)
61 			:	mnRefCount(0),
62 		    	maStartPolyPolygon(rStartPolyPolygon),
63 			    maEndPolyPolygon(rEndPolyPolygon),
64 			    mfStartWidth(fStartWidth),
65 			    mfEndWidth(fEndWidth),
66 			    mbStartActive(bStartActive),
67 			    mbEndActive(bEndActive),
68 			    mbStartCentered(bStartCentered),
69 			    mbEndCentered(bEndCentered)
70 		    {
71 		    }
72 
73 			// data read access
getStartPolyPolygon() const74 			const basegfx::B2DPolyPolygon& getStartPolyPolygon() const { return maStartPolyPolygon; }
getEndPolyPolygon() const75 			const basegfx::B2DPolyPolygon& getEndPolyPolygon() const { return maEndPolyPolygon; }
getStartWidth() const76 			double getStartWidth() const { return mfStartWidth; }
getEndWidth() const77 			double getEndWidth() const { return mfEndWidth; }
isStartActive() const78 			bool isStartActive() const { return mbStartActive; }
isEndActive() const79 			bool isEndActive() const { return mbEndActive; }
isStartCentered() const80 			bool isStartCentered() const { return mbStartCentered; }
isEndCentered() const81 			bool isEndCentered() const { return mbEndCentered; }
82 
operator ==(const ImpSdrLineStartEndAttribute & rCandidate) const83             bool operator==(const ImpSdrLineStartEndAttribute& rCandidate) const
84             {
85 			    return (getStartPolyPolygon() == rCandidate.getStartPolyPolygon()
86 				    && getEndPolyPolygon() == rCandidate.getEndPolyPolygon()
87 				    && getStartWidth() == rCandidate.getStartWidth()
88 				    && getEndWidth() == rCandidate.getEndWidth()
89                     && isStartActive() == rCandidate.isStartActive()
90 				    && isEndActive() == rCandidate.isEndActive()
91 				    && isStartCentered() == rCandidate.isStartCentered()
92 				    && isEndCentered() == rCandidate.isEndCentered());
93             }
94 
get_global_default()95             static ImpSdrLineStartEndAttribute* get_global_default()
96             {
97                 static ImpSdrLineStartEndAttribute* pDefault = 0;
98 
99                 if(!pDefault)
100                 {
101                     pDefault = new ImpSdrLineStartEndAttribute(
102 			            basegfx::B2DPolyPolygon(),
103                         basegfx::B2DPolyPolygon(),
104 			            0.0,
105                         0.0,
106                         false,
107                         false,
108                         false,
109                         false);
110 
111                     // never delete; start with RefCount 1, not 0
112     			    pDefault->mnRefCount++;
113                 }
114 
115                 return pDefault;
116             }
117 		};
118 
SdrLineStartEndAttribute(const basegfx::B2DPolyPolygon & rStartPolyPolygon,const basegfx::B2DPolyPolygon & rEndPolyPolygon,double fStartWidth,double fEndWidth,bool bStartActive,bool bEndActive,bool bStartCentered,bool bEndCentered)119         SdrLineStartEndAttribute::SdrLineStartEndAttribute(
120 			const basegfx::B2DPolyPolygon& rStartPolyPolygon,
121             const basegfx::B2DPolyPolygon& rEndPolyPolygon,
122 			double fStartWidth,
123             double fEndWidth,
124             bool bStartActive,
125             bool bEndActive,
126             bool bStartCentered,
127             bool bEndCentered)
128 		:	mpSdrLineStartEndAttribute(new ImpSdrLineStartEndAttribute(
129                 rStartPolyPolygon, rEndPolyPolygon, fStartWidth, fEndWidth, bStartActive, bEndActive, bStartCentered, bEndCentered))
130 		{
131 		}
132 
SdrLineStartEndAttribute()133 		SdrLineStartEndAttribute::SdrLineStartEndAttribute()
134         :	mpSdrLineStartEndAttribute(ImpSdrLineStartEndAttribute::get_global_default())
135 		{
136 			mpSdrLineStartEndAttribute->mnRefCount++;
137 		}
138 
SdrLineStartEndAttribute(const SdrLineStartEndAttribute & rCandidate)139         SdrLineStartEndAttribute::SdrLineStartEndAttribute(const SdrLineStartEndAttribute& rCandidate)
140 		:	mpSdrLineStartEndAttribute(rCandidate.mpSdrLineStartEndAttribute)
141 		{
142 			mpSdrLineStartEndAttribute->mnRefCount++;
143 		}
144 
~SdrLineStartEndAttribute()145 		SdrLineStartEndAttribute::~SdrLineStartEndAttribute()
146 		{
147 			if(mpSdrLineStartEndAttribute->mnRefCount)
148 			{
149 				mpSdrLineStartEndAttribute->mnRefCount--;
150 			}
151 			else
152 			{
153 				delete mpSdrLineStartEndAttribute;
154 			}
155 		}
156 
isDefault() const157         bool SdrLineStartEndAttribute::isDefault() const
158         {
159             return mpSdrLineStartEndAttribute == ImpSdrLineStartEndAttribute::get_global_default();
160         }
161 
operator =(const SdrLineStartEndAttribute & rCandidate)162         SdrLineStartEndAttribute& SdrLineStartEndAttribute::operator=(const SdrLineStartEndAttribute& rCandidate)
163 		{
164 			if(rCandidate.mpSdrLineStartEndAttribute != mpSdrLineStartEndAttribute)
165 			{
166 				if(mpSdrLineStartEndAttribute->mnRefCount)
167 				{
168 					mpSdrLineStartEndAttribute->mnRefCount--;
169 				}
170 				else
171 				{
172 					delete mpSdrLineStartEndAttribute;
173 				}
174 
175 				mpSdrLineStartEndAttribute = rCandidate.mpSdrLineStartEndAttribute;
176 				mpSdrLineStartEndAttribute->mnRefCount++;
177 			}
178 
179 			return *this;
180 		}
181 
operator ==(const SdrLineStartEndAttribute & rCandidate) const182 		bool SdrLineStartEndAttribute::operator==(const SdrLineStartEndAttribute& rCandidate) const
183 		{
184 			if(rCandidate.mpSdrLineStartEndAttribute == mpSdrLineStartEndAttribute)
185 			{
186 				return true;
187 			}
188 
189 			if(rCandidate.isDefault() != isDefault())
190 			{
191 				return false;
192 			}
193 
194 			return (*rCandidate.mpSdrLineStartEndAttribute == *mpSdrLineStartEndAttribute);
195 		}
196 
getStartPolyPolygon() const197 		const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getStartPolyPolygon() const
198         {
199             return mpSdrLineStartEndAttribute->getStartPolyPolygon();
200         }
201 
getEndPolyPolygon() const202         const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getEndPolyPolygon() const
203         {
204             return mpSdrLineStartEndAttribute->getEndPolyPolygon();
205         }
206 
getStartWidth() const207         double SdrLineStartEndAttribute::getStartWidth() const
208         {
209             return mpSdrLineStartEndAttribute->getStartWidth();
210         }
211 
getEndWidth() const212         double SdrLineStartEndAttribute::getEndWidth() const
213         {
214             return mpSdrLineStartEndAttribute->getEndWidth();
215         }
216 
isStartActive() const217         bool SdrLineStartEndAttribute::isStartActive() const
218         {
219             return mpSdrLineStartEndAttribute->isStartActive();
220         }
221 
isEndActive() const222         bool SdrLineStartEndAttribute::isEndActive() const
223         {
224             return mpSdrLineStartEndAttribute->isEndActive();
225         }
226 
isStartCentered() const227         bool SdrLineStartEndAttribute::isStartCentered() const
228         {
229             return mpSdrLineStartEndAttribute->isStartCentered();
230         }
231 
isEndCentered() const232         bool SdrLineStartEndAttribute::isEndCentered() const
233         {
234             return mpSdrLineStartEndAttribute->isEndCentered();
235         }
236     } // end of namespace attribute
237 } // end of namespace drawinglayer
238 
239 //////////////////////////////////////////////////////////////////////////////
240 // eof
241