1*4bfbcde8SAndrew Rist /**************************************************************
2*4bfbcde8SAndrew Rist  *
3*4bfbcde8SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*4bfbcde8SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*4bfbcde8SAndrew Rist  * distributed with this work for additional information
6*4bfbcde8SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*4bfbcde8SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*4bfbcde8SAndrew Rist  * "License"); you may not use this file except in compliance
9*4bfbcde8SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*4bfbcde8SAndrew Rist  *
11*4bfbcde8SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*4bfbcde8SAndrew Rist  *
13*4bfbcde8SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*4bfbcde8SAndrew Rist  * software distributed under the License is distributed on an
15*4bfbcde8SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*4bfbcde8SAndrew Rist  * KIND, either express or implied.  See the License for the
17*4bfbcde8SAndrew Rist  * specific language governing permissions and limitations
18*4bfbcde8SAndrew Rist  * under the License.
19*4bfbcde8SAndrew Rist  *
20*4bfbcde8SAndrew Rist  *************************************************************/
21cdf0e10cSrcweir 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlinestartendattribute.hxx>
26cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygon.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace drawinglayer
31cdf0e10cSrcweir {
32cdf0e10cSrcweir 	namespace attribute
33cdf0e10cSrcweir 	{
34cdf0e10cSrcweir 		class ImpSdrLineStartEndAttribute
35cdf0e10cSrcweir 		{
36cdf0e10cSrcweir 		public:
37cdf0e10cSrcweir 			// refcounter
38cdf0e10cSrcweir 			sal_uInt32								mnRefCount;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir 			// line arrow definitions
41cdf0e10cSrcweir 			basegfx::B2DPolyPolygon					maStartPolyPolygon;		// start Line PolyPolygon
42cdf0e10cSrcweir 			basegfx::B2DPolyPolygon					maEndPolyPolygon;		// end Line PolyPolygon
43cdf0e10cSrcweir 			double									mfStartWidth;			// 1/100th mm
44cdf0e10cSrcweir 			double									mfEndWidth;				// 1/100th mm
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 			// bitfield
47cdf0e10cSrcweir 			unsigned								mbStartActive : 1L;		// start of Line is active
48cdf0e10cSrcweir 			unsigned								mbEndActive : 1L;		// end of Line is active
49cdf0e10cSrcweir 			unsigned								mbStartCentered : 1L;	// Line is centered on line start point
50cdf0e10cSrcweir 			unsigned								mbEndCentered : 1L;		// Line is centered on line end point
51cdf0e10cSrcweir 
ImpSdrLineStartEndAttribute(const basegfx::B2DPolyPolygon & rStartPolyPolygon,const basegfx::B2DPolyPolygon & rEndPolyPolygon,double fStartWidth,double fEndWidth,bool bStartActive,bool bEndActive,bool bStartCentered,bool bEndCentered)52cdf0e10cSrcweir 			ImpSdrLineStartEndAttribute(
53cdf0e10cSrcweir 				const basegfx::B2DPolyPolygon& rStartPolyPolygon,
54cdf0e10cSrcweir                 const basegfx::B2DPolyPolygon& rEndPolyPolygon,
55cdf0e10cSrcweir 				double fStartWidth,
56cdf0e10cSrcweir                 double fEndWidth,
57cdf0e10cSrcweir                 bool bStartActive,
58cdf0e10cSrcweir                 bool bEndActive,
59cdf0e10cSrcweir                 bool bStartCentered,
60cdf0e10cSrcweir                 bool bEndCentered)
61cdf0e10cSrcweir 			:	mnRefCount(0),
62cdf0e10cSrcweir 		    	maStartPolyPolygon(rStartPolyPolygon),
63cdf0e10cSrcweir 			    maEndPolyPolygon(rEndPolyPolygon),
64cdf0e10cSrcweir 			    mfStartWidth(fStartWidth),
65cdf0e10cSrcweir 			    mfEndWidth(fEndWidth),
66cdf0e10cSrcweir 			    mbStartActive(bStartActive),
67cdf0e10cSrcweir 			    mbEndActive(bEndActive),
68cdf0e10cSrcweir 			    mbStartCentered(bStartCentered),
69cdf0e10cSrcweir 			    mbEndCentered(bEndCentered)
70cdf0e10cSrcweir 		    {
71cdf0e10cSrcweir 		    }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 			// data read access
getStartPolyPolygon() const74cdf0e10cSrcweir 			const basegfx::B2DPolyPolygon& getStartPolyPolygon() const { return maStartPolyPolygon; }
getEndPolyPolygon() const75cdf0e10cSrcweir 			const basegfx::B2DPolyPolygon& getEndPolyPolygon() const { return maEndPolyPolygon; }
getStartWidth() const76cdf0e10cSrcweir 			double getStartWidth() const { return mfStartWidth; }
getEndWidth() const77cdf0e10cSrcweir 			double getEndWidth() const { return mfEndWidth; }
isStartActive() const78cdf0e10cSrcweir 			bool isStartActive() const { return mbStartActive; }
isEndActive() const79cdf0e10cSrcweir 			bool isEndActive() const { return mbEndActive; }
isStartCentered() const80cdf0e10cSrcweir 			bool isStartCentered() const { return mbStartCentered; }
isEndCentered() const81cdf0e10cSrcweir 			bool isEndCentered() const { return mbEndCentered; }
82cdf0e10cSrcweir 
operator ==(const ImpSdrLineStartEndAttribute & rCandidate) const83cdf0e10cSrcweir             bool operator==(const ImpSdrLineStartEndAttribute& rCandidate) const
84cdf0e10cSrcweir             {
85cdf0e10cSrcweir 			    return (getStartPolyPolygon() == rCandidate.getStartPolyPolygon()
86cdf0e10cSrcweir 				    && getEndPolyPolygon() == rCandidate.getEndPolyPolygon()
87cdf0e10cSrcweir 				    && getStartWidth() == rCandidate.getStartWidth()
88cdf0e10cSrcweir 				    && getEndWidth() == rCandidate.getEndWidth()
89cdf0e10cSrcweir                     && isStartActive() == rCandidate.isStartActive()
90cdf0e10cSrcweir 				    && isEndActive() == rCandidate.isEndActive()
91cdf0e10cSrcweir 				    && isStartCentered() == rCandidate.isStartCentered()
92cdf0e10cSrcweir 				    && isEndCentered() == rCandidate.isEndCentered());
93cdf0e10cSrcweir             }
94cdf0e10cSrcweir 
get_global_default()95cdf0e10cSrcweir             static ImpSdrLineStartEndAttribute* get_global_default()
96cdf0e10cSrcweir             {
97cdf0e10cSrcweir                 static ImpSdrLineStartEndAttribute* pDefault = 0;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir                 if(!pDefault)
100cdf0e10cSrcweir                 {
101cdf0e10cSrcweir                     pDefault = new ImpSdrLineStartEndAttribute(
102cdf0e10cSrcweir 			            basegfx::B2DPolyPolygon(),
103cdf0e10cSrcweir                         basegfx::B2DPolyPolygon(),
104cdf0e10cSrcweir 			            0.0,
105cdf0e10cSrcweir                         0.0,
106cdf0e10cSrcweir                         false,
107cdf0e10cSrcweir                         false,
108cdf0e10cSrcweir                         false,
109cdf0e10cSrcweir                         false);
110cdf0e10cSrcweir 
111cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
112cdf0e10cSrcweir     			    pDefault->mnRefCount++;
113cdf0e10cSrcweir                 }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir                 return pDefault;
116cdf0e10cSrcweir             }
117cdf0e10cSrcweir 		};
118cdf0e10cSrcweir 
SdrLineStartEndAttribute(const basegfx::B2DPolyPolygon & rStartPolyPolygon,const basegfx::B2DPolyPolygon & rEndPolyPolygon,double fStartWidth,double fEndWidth,bool bStartActive,bool bEndActive,bool bStartCentered,bool bEndCentered)119cdf0e10cSrcweir         SdrLineStartEndAttribute::SdrLineStartEndAttribute(
120cdf0e10cSrcweir 			const basegfx::B2DPolyPolygon& rStartPolyPolygon,
121cdf0e10cSrcweir             const basegfx::B2DPolyPolygon& rEndPolyPolygon,
122cdf0e10cSrcweir 			double fStartWidth,
123cdf0e10cSrcweir             double fEndWidth,
124cdf0e10cSrcweir             bool bStartActive,
125cdf0e10cSrcweir             bool bEndActive,
126cdf0e10cSrcweir             bool bStartCentered,
127cdf0e10cSrcweir             bool bEndCentered)
128cdf0e10cSrcweir 		:	mpSdrLineStartEndAttribute(new ImpSdrLineStartEndAttribute(
129cdf0e10cSrcweir                 rStartPolyPolygon, rEndPolyPolygon, fStartWidth, fEndWidth, bStartActive, bEndActive, bStartCentered, bEndCentered))
130cdf0e10cSrcweir 		{
131cdf0e10cSrcweir 		}
132cdf0e10cSrcweir 
SdrLineStartEndAttribute()133cdf0e10cSrcweir 		SdrLineStartEndAttribute::SdrLineStartEndAttribute()
134cdf0e10cSrcweir         :	mpSdrLineStartEndAttribute(ImpSdrLineStartEndAttribute::get_global_default())
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir 			mpSdrLineStartEndAttribute->mnRefCount++;
137cdf0e10cSrcweir 		}
138cdf0e10cSrcweir 
SdrLineStartEndAttribute(const SdrLineStartEndAttribute & rCandidate)139cdf0e10cSrcweir         SdrLineStartEndAttribute::SdrLineStartEndAttribute(const SdrLineStartEndAttribute& rCandidate)
140cdf0e10cSrcweir 		:	mpSdrLineStartEndAttribute(rCandidate.mpSdrLineStartEndAttribute)
141cdf0e10cSrcweir 		{
142cdf0e10cSrcweir 			mpSdrLineStartEndAttribute->mnRefCount++;
143cdf0e10cSrcweir 		}
144cdf0e10cSrcweir 
~SdrLineStartEndAttribute()145cdf0e10cSrcweir 		SdrLineStartEndAttribute::~SdrLineStartEndAttribute()
146cdf0e10cSrcweir 		{
147cdf0e10cSrcweir 			if(mpSdrLineStartEndAttribute->mnRefCount)
148cdf0e10cSrcweir 			{
149cdf0e10cSrcweir 				mpSdrLineStartEndAttribute->mnRefCount--;
150cdf0e10cSrcweir 			}
151cdf0e10cSrcweir 			else
152cdf0e10cSrcweir 			{
153cdf0e10cSrcweir 				delete mpSdrLineStartEndAttribute;
154cdf0e10cSrcweir 			}
155cdf0e10cSrcweir 		}
156cdf0e10cSrcweir 
isDefault() const157cdf0e10cSrcweir         bool SdrLineStartEndAttribute::isDefault() const
158cdf0e10cSrcweir         {
159cdf0e10cSrcweir             return mpSdrLineStartEndAttribute == ImpSdrLineStartEndAttribute::get_global_default();
160cdf0e10cSrcweir         }
161cdf0e10cSrcweir 
operator =(const SdrLineStartEndAttribute & rCandidate)162cdf0e10cSrcweir         SdrLineStartEndAttribute& SdrLineStartEndAttribute::operator=(const SdrLineStartEndAttribute& rCandidate)
163cdf0e10cSrcweir 		{
164cdf0e10cSrcweir 			if(rCandidate.mpSdrLineStartEndAttribute != mpSdrLineStartEndAttribute)
165cdf0e10cSrcweir 			{
166cdf0e10cSrcweir 				if(mpSdrLineStartEndAttribute->mnRefCount)
167cdf0e10cSrcweir 				{
168cdf0e10cSrcweir 					mpSdrLineStartEndAttribute->mnRefCount--;
169cdf0e10cSrcweir 				}
170cdf0e10cSrcweir 				else
171cdf0e10cSrcweir 				{
172cdf0e10cSrcweir 					delete mpSdrLineStartEndAttribute;
173cdf0e10cSrcweir 				}
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 				mpSdrLineStartEndAttribute = rCandidate.mpSdrLineStartEndAttribute;
176cdf0e10cSrcweir 				mpSdrLineStartEndAttribute->mnRefCount++;
177cdf0e10cSrcweir 			}
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 			return *this;
180cdf0e10cSrcweir 		}
181cdf0e10cSrcweir 
operator ==(const SdrLineStartEndAttribute & rCandidate) const182cdf0e10cSrcweir 		bool SdrLineStartEndAttribute::operator==(const SdrLineStartEndAttribute& rCandidate) const
183cdf0e10cSrcweir 		{
184cdf0e10cSrcweir 			if(rCandidate.mpSdrLineStartEndAttribute == mpSdrLineStartEndAttribute)
185cdf0e10cSrcweir 			{
186cdf0e10cSrcweir 				return true;
187cdf0e10cSrcweir 			}
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
190cdf0e10cSrcweir 			{
191cdf0e10cSrcweir 				return false;
192cdf0e10cSrcweir 			}
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 			return (*rCandidate.mpSdrLineStartEndAttribute == *mpSdrLineStartEndAttribute);
195cdf0e10cSrcweir 		}
196cdf0e10cSrcweir 
getStartPolyPolygon() const197cdf0e10cSrcweir 		const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getStartPolyPolygon() const
198cdf0e10cSrcweir         {
199cdf0e10cSrcweir             return mpSdrLineStartEndAttribute->getStartPolyPolygon();
200cdf0e10cSrcweir         }
201cdf0e10cSrcweir 
getEndPolyPolygon() const202cdf0e10cSrcweir         const basegfx::B2DPolyPolygon& SdrLineStartEndAttribute::getEndPolyPolygon() const
203cdf0e10cSrcweir         {
204cdf0e10cSrcweir             return mpSdrLineStartEndAttribute->getEndPolyPolygon();
205cdf0e10cSrcweir         }
206cdf0e10cSrcweir 
getStartWidth() const207cdf0e10cSrcweir         double SdrLineStartEndAttribute::getStartWidth() const
208cdf0e10cSrcweir         {
209cdf0e10cSrcweir             return mpSdrLineStartEndAttribute->getStartWidth();
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir 
getEndWidth() const212cdf0e10cSrcweir         double SdrLineStartEndAttribute::getEndWidth() const
213cdf0e10cSrcweir         {
214cdf0e10cSrcweir             return mpSdrLineStartEndAttribute->getEndWidth();
215cdf0e10cSrcweir         }
216cdf0e10cSrcweir 
isStartActive() const217cdf0e10cSrcweir         bool SdrLineStartEndAttribute::isStartActive() const
218cdf0e10cSrcweir         {
219cdf0e10cSrcweir             return mpSdrLineStartEndAttribute->isStartActive();
220cdf0e10cSrcweir         }
221cdf0e10cSrcweir 
isEndActive() const222cdf0e10cSrcweir         bool SdrLineStartEndAttribute::isEndActive() const
223cdf0e10cSrcweir         {
224cdf0e10cSrcweir             return mpSdrLineStartEndAttribute->isEndActive();
225cdf0e10cSrcweir         }
226cdf0e10cSrcweir 
isStartCentered() const227cdf0e10cSrcweir         bool SdrLineStartEndAttribute::isStartCentered() const
228cdf0e10cSrcweir         {
229cdf0e10cSrcweir             return mpSdrLineStartEndAttribute->isStartCentered();
230cdf0e10cSrcweir         }
231cdf0e10cSrcweir 
isEndCentered() const232cdf0e10cSrcweir         bool SdrLineStartEndAttribute::isEndCentered() const
233cdf0e10cSrcweir         {
234cdf0e10cSrcweir             return mpSdrLineStartEndAttribute->isEndCentered();
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir     } // end of namespace attribute
237cdf0e10cSrcweir } // end of namespace drawinglayer
238cdf0e10cSrcweir 
239cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
240cdf0e10cSrcweir // eof
241