1cdf0e10cSrcweir /*************************************************************************
2cdf0e10cSrcweir  *
3cdf0e10cSrcweir  *  OpenOffice.org - a multi-platform office productivity suite
4cdf0e10cSrcweir  *
5cdf0e10cSrcweir  *  $RCSfile: sdrattribute.cxx,v $
6cdf0e10cSrcweir  *
7cdf0e10cSrcweir  *  $Revision: 1.5 $
8cdf0e10cSrcweir  *
9cdf0e10cSrcweir  *  last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $
10cdf0e10cSrcweir  *
11cdf0e10cSrcweir  *  The Contents of this file are made available subject to
12cdf0e10cSrcweir  *  the terms of GNU Lesser General Public License Version 2.1.
13cdf0e10cSrcweir  *
14cdf0e10cSrcweir  *
15cdf0e10cSrcweir  *    GNU Lesser General Public License Version 2.1
16cdf0e10cSrcweir  *    =============================================
17cdf0e10cSrcweir  *    Copyright 2005 by Sun Microsystems, Inc.
18cdf0e10cSrcweir  *    901 San Antonio Road, Palo Alto, CA 94303, USA
19cdf0e10cSrcweir  *
20cdf0e10cSrcweir  *    This library is free software; you can redistribute it and/or
21cdf0e10cSrcweir  *    modify it under the terms of the GNU Lesser General Public
22cdf0e10cSrcweir  *    License version 2.1, as published by the Free Software Foundation.
23cdf0e10cSrcweir  *
24cdf0e10cSrcweir  *    This library is distributed in the hope that it will be useful,
25cdf0e10cSrcweir  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
26cdf0e10cSrcweir  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27cdf0e10cSrcweir  *    Lesser General Public License for more details.
28cdf0e10cSrcweir  *
29cdf0e10cSrcweir  *    You should have received a copy of the GNU Lesser General Public
30cdf0e10cSrcweir  *    License along with this library; if not, write to the Free Software
31cdf0e10cSrcweir  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32cdf0e10cSrcweir  *    MA  02111-1307  USA
33cdf0e10cSrcweir  *
34cdf0e10cSrcweir  ************************************************************************/
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
37cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <drawinglayer/attribute/sdrlineattribute.hxx>
40cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
43cdf0e10cSrcweir 
44cdf0e10cSrcweir namespace drawinglayer
45cdf0e10cSrcweir {
46cdf0e10cSrcweir 	namespace attribute
47cdf0e10cSrcweir 	{
48cdf0e10cSrcweir 		class ImpSdrLineAttribute
49cdf0e10cSrcweir 		{
50cdf0e10cSrcweir 		public:
51cdf0e10cSrcweir 			// refcounter
52cdf0e10cSrcweir 			sal_uInt32								mnRefCount;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 			// line definitions
55cdf0e10cSrcweir 			basegfx::B2DLineJoin				    meJoin;				// B2DLINEJOIN_* defines
56cdf0e10cSrcweir 			double									mfWidth;			// 1/100th mm, 0.0==hair
57cdf0e10cSrcweir 			double									mfTransparence;		// [0.0 .. 1.0], 0.0==no transp.
58cdf0e10cSrcweir 			basegfx::BColor							maColor;			// color of line
59*5aaf853bSArmin Le Grand             com::sun::star::drawing::LineCap        meCap;              // BUTT, ROUND, or SQUARE
60cdf0e10cSrcweir 			::std::vector< double >					maDotDashArray;		// array of double which defines the dot-dash pattern
61cdf0e10cSrcweir 			double									mfFullDotDashLen;	// sum of maDotDashArray (for convenience)
62cdf0e10cSrcweir 
63cdf0e10cSrcweir             ImpSdrLineAttribute(
64cdf0e10cSrcweir 				basegfx::B2DLineJoin eJoin,
65cdf0e10cSrcweir                 double fWidth,
66cdf0e10cSrcweir                 double fTransparence,
67cdf0e10cSrcweir                 const basegfx::BColor& rColor,
68*5aaf853bSArmin Le Grand                 com::sun::star::drawing::LineCap eCap,
69cdf0e10cSrcweir 				const ::std::vector< double >& rDotDashArray,
70cdf0e10cSrcweir                 double fFullDotDashLen)
71cdf0e10cSrcweir 			:	mnRefCount(0),
72cdf0e10cSrcweir 		    	meJoin(eJoin),
73cdf0e10cSrcweir 			    mfWidth(fWidth),
74cdf0e10cSrcweir 			    mfTransparence(fTransparence),
75cdf0e10cSrcweir 			    maColor(rColor),
76*5aaf853bSArmin Le Grand                 meCap(eCap),
77cdf0e10cSrcweir 			    maDotDashArray(rDotDashArray),
78cdf0e10cSrcweir 			    mfFullDotDashLen(fFullDotDashLen)
79cdf0e10cSrcweir 		    {
80cdf0e10cSrcweir 		    }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir             ImpSdrLineAttribute(const basegfx::BColor& rColor)
83cdf0e10cSrcweir 			:	mnRefCount(0),
84cdf0e10cSrcweir 		    	meJoin(basegfx::B2DLINEJOIN_NONE),
85cdf0e10cSrcweir 			    mfWidth(0.0),
86cdf0e10cSrcweir 			    mfTransparence(0.0),
87cdf0e10cSrcweir 			    maColor(rColor),
88*5aaf853bSArmin Le Grand                 meCap(com::sun::star::drawing::LineCap_BUTT),
89cdf0e10cSrcweir 			    maDotDashArray(),
90cdf0e10cSrcweir 			    mfFullDotDashLen(0.0)
91cdf0e10cSrcweir             {
92cdf0e10cSrcweir             }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 			// data read access
95cdf0e10cSrcweir 			basegfx::B2DLineJoin getJoin() const { return meJoin; }
96cdf0e10cSrcweir 			double getWidth() const { return mfWidth; }
97cdf0e10cSrcweir 			double getTransparence() const { return mfTransparence; }
98cdf0e10cSrcweir 			const basegfx::BColor& getColor() const { return maColor; }
99*5aaf853bSArmin Le Grand             com::sun::star::drawing::LineCap getCap() const { return meCap; }
100cdf0e10cSrcweir 			const ::std::vector< double >& getDotDashArray() const { return maDotDashArray; }
101cdf0e10cSrcweir 			double getFullDotDashLen() const { return mfFullDotDashLen; }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             bool operator==(const ImpSdrLineAttribute& rCandidate) const
104cdf0e10cSrcweir 		    {
105cdf0e10cSrcweir 			    return (getJoin() == rCandidate.getJoin()
106cdf0e10cSrcweir 				    && getWidth() == rCandidate.getWidth()
107cdf0e10cSrcweir 				    && getTransparence() == rCandidate.getTransparence()
108cdf0e10cSrcweir 				    && getColor() == rCandidate.getColor()
109*5aaf853bSArmin Le Grand                     && getCap() == rCandidate.getCap()
110cdf0e10cSrcweir 				    && getDotDashArray() == rCandidate.getDotDashArray());
111cdf0e10cSrcweir 		    }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir             static ImpSdrLineAttribute* get_global_default()
114cdf0e10cSrcweir             {
115cdf0e10cSrcweir                 static ImpSdrLineAttribute* pDefault = 0;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir                 if(!pDefault)
118cdf0e10cSrcweir                 {
119cdf0e10cSrcweir                     pDefault = new ImpSdrLineAttribute(
120cdf0e10cSrcweir 			            basegfx::B2DLINEJOIN_ROUND,
121cdf0e10cSrcweir                         0.0,
122cdf0e10cSrcweir                         0.0,
123cdf0e10cSrcweir                         basegfx::BColor(),
124*5aaf853bSArmin Le Grand                         com::sun::star::drawing::LineCap_BUTT,
125cdf0e10cSrcweir 			            std::vector< double >(),
126cdf0e10cSrcweir                         0.0);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
129cdf0e10cSrcweir     			    pDefault->mnRefCount++;
130cdf0e10cSrcweir                 }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir                 return pDefault;
133cdf0e10cSrcweir             }
134cdf0e10cSrcweir 		};
135cdf0e10cSrcweir 
136cdf0e10cSrcweir         SdrLineAttribute::SdrLineAttribute(
137cdf0e10cSrcweir 			basegfx::B2DLineJoin eJoin,
138cdf0e10cSrcweir             double fWidth,
139cdf0e10cSrcweir             double fTransparence,
140cdf0e10cSrcweir             const basegfx::BColor& rColor,
141*5aaf853bSArmin Le Grand             com::sun::star::drawing::LineCap eCap,
142cdf0e10cSrcweir 			const ::std::vector< double >& rDotDashArray,
143cdf0e10cSrcweir             double fFullDotDashLen)
144*5aaf853bSArmin Le Grand 		:	mpSdrLineAttribute(
145*5aaf853bSArmin Le Grand                 new ImpSdrLineAttribute(
146*5aaf853bSArmin Le Grand                     eJoin,
147*5aaf853bSArmin Le Grand                     fWidth,
148*5aaf853bSArmin Le Grand                     fTransparence,
149*5aaf853bSArmin Le Grand                     rColor,
150*5aaf853bSArmin Le Grand                     eCap,
151*5aaf853bSArmin Le Grand                     rDotDashArray,
152*5aaf853bSArmin Le Grand                     fFullDotDashLen))
153cdf0e10cSrcweir 		{
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         SdrLineAttribute::SdrLineAttribute(
157cdf0e10cSrcweir             const basegfx::BColor& rColor)
158*5aaf853bSArmin Le Grand 		:	mpSdrLineAttribute(
159*5aaf853bSArmin Le Grand                 new ImpSdrLineAttribute(
160*5aaf853bSArmin Le Grand                     rColor))
161cdf0e10cSrcweir         {
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 		SdrLineAttribute::SdrLineAttribute()
165cdf0e10cSrcweir         :	mpSdrLineAttribute(ImpSdrLineAttribute::get_global_default())
166cdf0e10cSrcweir 		{
167cdf0e10cSrcweir 			mpSdrLineAttribute->mnRefCount++;
168cdf0e10cSrcweir 		}
169cdf0e10cSrcweir 
170cdf0e10cSrcweir         SdrLineAttribute::SdrLineAttribute(const SdrLineAttribute& rCandidate)
171cdf0e10cSrcweir 		:	mpSdrLineAttribute(rCandidate.mpSdrLineAttribute)
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			mpSdrLineAttribute->mnRefCount++;
174cdf0e10cSrcweir 		}
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 		SdrLineAttribute::~SdrLineAttribute()
177cdf0e10cSrcweir 		{
178cdf0e10cSrcweir 			if(mpSdrLineAttribute->mnRefCount)
179cdf0e10cSrcweir 			{
180cdf0e10cSrcweir 				mpSdrLineAttribute->mnRefCount--;
181cdf0e10cSrcweir 			}
182cdf0e10cSrcweir 			else
183cdf0e10cSrcweir 			{
184cdf0e10cSrcweir 				delete mpSdrLineAttribute;
185cdf0e10cSrcweir 			}
186cdf0e10cSrcweir 		}
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         bool SdrLineAttribute::isDefault() const
189cdf0e10cSrcweir         {
190cdf0e10cSrcweir             return mpSdrLineAttribute == ImpSdrLineAttribute::get_global_default();
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir         SdrLineAttribute& SdrLineAttribute::operator=(const SdrLineAttribute& rCandidate)
194cdf0e10cSrcweir 		{
195cdf0e10cSrcweir 			if(rCandidate.mpSdrLineAttribute != mpSdrLineAttribute)
196cdf0e10cSrcweir 			{
197cdf0e10cSrcweir 				if(mpSdrLineAttribute->mnRefCount)
198cdf0e10cSrcweir 				{
199cdf0e10cSrcweir 					mpSdrLineAttribute->mnRefCount--;
200cdf0e10cSrcweir 				}
201cdf0e10cSrcweir 				else
202cdf0e10cSrcweir 				{
203cdf0e10cSrcweir 					delete mpSdrLineAttribute;
204cdf0e10cSrcweir 				}
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 				mpSdrLineAttribute = rCandidate.mpSdrLineAttribute;
207cdf0e10cSrcweir 				mpSdrLineAttribute->mnRefCount++;
208cdf0e10cSrcweir 			}
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 			return *this;
211cdf0e10cSrcweir 		}
212cdf0e10cSrcweir 
213cdf0e10cSrcweir 		bool SdrLineAttribute::operator==(const SdrLineAttribute& rCandidate) const
214cdf0e10cSrcweir 		{
215cdf0e10cSrcweir 			if(rCandidate.mpSdrLineAttribute == mpSdrLineAttribute)
216cdf0e10cSrcweir 			{
217cdf0e10cSrcweir 				return true;
218cdf0e10cSrcweir 			}
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
221cdf0e10cSrcweir 			{
222cdf0e10cSrcweir 				return false;
223cdf0e10cSrcweir 			}
224cdf0e10cSrcweir 
225cdf0e10cSrcweir 			return (*rCandidate.mpSdrLineAttribute == *mpSdrLineAttribute);
226cdf0e10cSrcweir 		}
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 		basegfx::B2DLineJoin SdrLineAttribute::getJoin() const
229cdf0e10cSrcweir         {
230cdf0e10cSrcweir             return mpSdrLineAttribute->getJoin();
231cdf0e10cSrcweir         }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir 		double SdrLineAttribute::getWidth() const
234cdf0e10cSrcweir         {
235cdf0e10cSrcweir             return mpSdrLineAttribute->getWidth();
236cdf0e10cSrcweir         }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 		double SdrLineAttribute::getTransparence() const
239cdf0e10cSrcweir         {
240cdf0e10cSrcweir             return mpSdrLineAttribute->getTransparence();
241cdf0e10cSrcweir         }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 		const basegfx::BColor& SdrLineAttribute::getColor() const
244cdf0e10cSrcweir         {
245cdf0e10cSrcweir             return mpSdrLineAttribute->getColor();
246cdf0e10cSrcweir         }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 		const ::std::vector< double >& SdrLineAttribute::getDotDashArray() const
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             return mpSdrLineAttribute->getDotDashArray();
251cdf0e10cSrcweir         }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 		double SdrLineAttribute::getFullDotDashLen() const
254cdf0e10cSrcweir         {
255cdf0e10cSrcweir             return mpSdrLineAttribute->getFullDotDashLen();
256cdf0e10cSrcweir         }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir 		bool SdrLineAttribute::isDashed() const
259cdf0e10cSrcweir         {
260cdf0e10cSrcweir             return (0L != getDotDashArray().size());
261cdf0e10cSrcweir         }
262cdf0e10cSrcweir 
263*5aaf853bSArmin Le Grand         com::sun::star::drawing::LineCap SdrLineAttribute::getCap() const
264*5aaf853bSArmin Le Grand         {
265*5aaf853bSArmin Le Grand             return mpSdrLineAttribute->getCap();
266*5aaf853bSArmin Le Grand         }
267*5aaf853bSArmin Le Grand 
268cdf0e10cSrcweir     } // end of namespace attribute
269cdf0e10cSrcweir } // end of namespace drawinglayer
270cdf0e10cSrcweir 
271cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
272cdf0e10cSrcweir // eof
273