1 /*************************************************************************
2  *
3  *  OpenOffice.org - a multi-platform office productivity suite
4  *
5  *  $RCSfile: sdrattribute.cxx,v $
6  *
7  *  $Revision: 1.5 $
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/sdrlinestartendattribute.hxx>
40 #include <basegfx/polygon/b2dpolypolygon.hxx>
41 
42 //////////////////////////////////////////////////////////////////////////////
43 
44 namespace drawinglayer
45 {
46 	namespace attribute
47 	{
48 		class ImpSdrLineStartEndAttribute
49 		{
50 		public:
51 			// refcounter
52 			sal_uInt32								mnRefCount;
53 
54 			// line arrow definitions
55 			basegfx::B2DPolyPolygon					maStartPolyPolygon;		// start Line PolyPolygon
56 			basegfx::B2DPolyPolygon					maEndPolyPolygon;		// end Line PolyPolygon
57 			double									mfStartWidth;			// 1/100th mm
58 			double									mfEndWidth;				// 1/100th mm
59 
60 			// bitfield
61 			unsigned								mbStartActive : 1L;		// start of Line is active
62 			unsigned								mbEndActive : 1L;		// end of Line is active
63 			unsigned								mbStartCentered : 1L;	// Line is centered on line start point
64 			unsigned								mbEndCentered : 1L;		// Line is centered on line end point
65 
66 			ImpSdrLineStartEndAttribute(
67 				const basegfx::B2DPolyPolygon& rStartPolyPolygon,
68                 const basegfx::B2DPolyPolygon& rEndPolyPolygon,
69 				double fStartWidth,
70                 double fEndWidth,
71                 bool bStartActive,
72                 bool bEndActive,
73                 bool bStartCentered,
74                 bool bEndCentered)
75 			:	mnRefCount(0),
76 		    	maStartPolyPolygon(rStartPolyPolygon),
77 			    maEndPolyPolygon(rEndPolyPolygon),
78 			    mfStartWidth(fStartWidth),
79 			    mfEndWidth(fEndWidth),
80 			    mbStartActive(bStartActive),
81 			    mbEndActive(bEndActive),
82 			    mbStartCentered(bStartCentered),
83 			    mbEndCentered(bEndCentered)
84 		    {
85 		    }
86 
87 			// data read access
88 			const basegfx::B2DPolyPolygon& getStartPolyPolygon() const { return maStartPolyPolygon; }
89 			const basegfx::B2DPolyPolygon& getEndPolyPolygon() const { return maEndPolyPolygon; }
90 			double getStartWidth() const { return mfStartWidth; }
91 			double getEndWidth() const { return mfEndWidth; }
92 			bool isStartActive() const { return mbStartActive; }
93 			bool isEndActive() const { return mbEndActive; }
94 			bool isStartCentered() const { return mbStartCentered; }
95 			bool isEndCentered() const { return mbEndCentered; }
96 
97             bool operator==(const ImpSdrLineStartEndAttribute& rCandidate) const
98             {
99 			    return (getStartPolyPolygon() == rCandidate.getStartPolyPolygon()
100 				    && getEndPolyPolygon() == rCandidate.getEndPolyPolygon()
101 				    && getStartWidth() == rCandidate.getStartWidth()
102 				    && getEndWidth() == rCandidate.getEndWidth()
103                     && isStartActive() == rCandidate.isStartActive()
104 				    && isEndActive() == rCandidate.isEndActive()
105 				    && isStartCentered() == rCandidate.isStartCentered()
106 				    && isEndCentered() == rCandidate.isEndCentered());
107             }
108 
109             static ImpSdrLineStartEndAttribute* get_global_default()
110             {
111                 static ImpSdrLineStartEndAttribute* pDefault = 0;
112 
113                 if(!pDefault)
114                 {
115                     pDefault = new ImpSdrLineStartEndAttribute(
116 			            basegfx::B2DPolyPolygon(),
117                         basegfx::B2DPolyPolygon(),
118 			            0.0,
119                         0.0,
120                         false,
121                         false,
122                         false,
123                         false);
124 
125                     // never delete; start with RefCount 1, not 0
126     			    pDefault->mnRefCount++;
127                 }
128 
129                 return pDefault;
130             }
131 		};
132 
133         SdrLineStartEndAttribute::SdrLineStartEndAttribute(
134 			const basegfx::B2DPolyPolygon& rStartPolyPolygon,
135             const basegfx::B2DPolyPolygon& rEndPolyPolygon,
136 			double fStartWidth,
137             double fEndWidth,
138             bool bStartActive,
139             bool bEndActive,
140             bool bStartCentered,
141             bool bEndCentered)
142 		:	mpSdrLineStartEndAttribute(new ImpSdrLineStartEndAttribute(
143                 rStartPolyPolygon, rEndPolyPolygon, fStartWidth, fEndWidth, bStartActive, bEndActive, bStartCentered, bEndCentered))
144 		{
145 		}
146 
147 		SdrLineStartEndAttribute::SdrLineStartEndAttribute()
148         :	mpSdrLineStartEndAttribute(ImpSdrLineStartEndAttribute::get_global_default())
149 		{
150 			mpSdrLineStartEndAttribute->mnRefCount++;
151 		}
152 
153         SdrLineStartEndAttribute::SdrLineStartEndAttribute(const SdrLineStartEndAttribute& rCandidate)
154 		:	mpSdrLineStartEndAttribute(rCandidate.mpSdrLineStartEndAttribute)
155 		{
156 			mpSdrLineStartEndAttribute->mnRefCount++;
157 		}
158 
159 		SdrLineStartEndAttribute::~SdrLineStartEndAttribute()
160 		{
161 			if(mpSdrLineStartEndAttribute->mnRefCount)
162 			{
163 				mpSdrLineStartEndAttribute->mnRefCount--;
164 			}
165 			else
166 			{
167 				delete mpSdrLineStartEndAttribute;
168 			}
169 		}
170 
171         bool SdrLineStartEndAttribute::isDefault() const
172         {
173             return mpSdrLineStartEndAttribute == ImpSdrLineStartEndAttribute::get_global_default();
174         }
175 
176         SdrLineStartEndAttribute& SdrLineStartEndAttribute::operator=(const SdrLineStartEndAttribute& rCandidate)
177 		{
178 			if(rCandidate.mpSdrLineStartEndAttribute != mpSdrLineStartEndAttribute)
179 			{
180 				if(mpSdrLineStartEndAttribute->mnRefCount)
181 				{
182 					mpSdrLineStartEndAttribute->mnRefCount--;
183 				}
184 				else
185 				{
186 					delete mpSdrLineStartEndAttribute;
187 				}
188 
189 				mpSdrLineStartEndAttribute = rCandidate.mpSdrLineStartEndAttribute;
190 				mpSdrLineStartEndAttribute->mnRefCount++;
191 			}
192 
193 			return *this;
194 		}
195 
196 		bool SdrLineStartEndAttribute::operator==(const SdrLineStartEndAttribute& rCandidate) const
197 		{
198 			if(rCandidate.mpSdrLineStartEndAttribute == mpSdrLineStartEndAttribute)
199 			{
200 				return true;
201 			}
202 
203 			if(rCandidate.isDefault() != isDefault())
204 			{
205 				return false;
206 			}
207 
208 			return (*rCandidate.mpSdrLineStartEndAttribute == *mpSdrLineStartEndAttribute);
209 		}
210 
211 		const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getStartPolyPolygon() const
212         {
213             return mpSdrLineStartEndAttribute->getStartPolyPolygon();
214         }
215 
216         const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getEndPolyPolygon() const
217         {
218             return mpSdrLineStartEndAttribute->getEndPolyPolygon();
219         }
220 
221         double SdrLineStartEndAttribute::getStartWidth() const
222         {
223             return mpSdrLineStartEndAttribute->getStartWidth();
224         }
225 
226         double SdrLineStartEndAttribute::getEndWidth() const
227         {
228             return mpSdrLineStartEndAttribute->getEndWidth();
229         }
230 
231         bool SdrLineStartEndAttribute::isStartActive() const
232         {
233             return mpSdrLineStartEndAttribute->isStartActive();
234         }
235 
236         bool SdrLineStartEndAttribute::isEndActive() const
237         {
238             return mpSdrLineStartEndAttribute->isEndActive();
239         }
240 
241         bool SdrLineStartEndAttribute::isStartCentered() const
242         {
243             return mpSdrLineStartEndAttribute->isStartCentered();
244         }
245 
246         bool SdrLineStartEndAttribute::isEndCentered() const
247         {
248             return mpSdrLineStartEndAttribute->isEndCentered();
249         }
250     } // end of namespace attribute
251 } // end of namespace drawinglayer
252 
253 //////////////////////////////////////////////////////////////////////////////
254 // eof
255