1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_drawinglayer.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <drawinglayer/attribute/lineattribute.hxx>
32*cdf0e10cSrcweir #include <basegfx/color/bcolor.hxx>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir namespace drawinglayer
37*cdf0e10cSrcweir {
38*cdf0e10cSrcweir 	namespace attribute
39*cdf0e10cSrcweir 	{
40*cdf0e10cSrcweir 		class ImpLineAttribute
41*cdf0e10cSrcweir 		{
42*cdf0e10cSrcweir 		public:
43*cdf0e10cSrcweir 			// refcounter
44*cdf0e10cSrcweir 			sal_uInt32								mnRefCount;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir             // data definitions
47*cdf0e10cSrcweir 			basegfx::BColor							maColor;				// color
48*cdf0e10cSrcweir 			double									mfWidth;				// absolute line width
49*cdf0e10cSrcweir 			basegfx::B2DLineJoin					meLineJoin;				// type of LineJoin
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir 			ImpLineAttribute(
52*cdf0e10cSrcweir                 const basegfx::BColor& rColor,
53*cdf0e10cSrcweir 				double fWidth,
54*cdf0e10cSrcweir 				basegfx::B2DLineJoin aB2DLineJoin)
55*cdf0e10cSrcweir 			:	mnRefCount(0),
56*cdf0e10cSrcweir                 maColor(rColor),
57*cdf0e10cSrcweir                 mfWidth(fWidth),
58*cdf0e10cSrcweir                 meLineJoin(aB2DLineJoin)
59*cdf0e10cSrcweir 			{
60*cdf0e10cSrcweir 			}
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 			// data read access
63*cdf0e10cSrcweir 			const basegfx::BColor& getColor() const { return maColor; }
64*cdf0e10cSrcweir 			double getWidth() const { return mfWidth; }
65*cdf0e10cSrcweir 			basegfx::B2DLineJoin getLineJoin() const { return meLineJoin; }
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir 			bool operator==(const ImpLineAttribute& rCandidate) const
68*cdf0e10cSrcweir 			{
69*cdf0e10cSrcweir 				return (getColor() == rCandidate.getColor()
70*cdf0e10cSrcweir 					&& getWidth() == rCandidate.getWidth()
71*cdf0e10cSrcweir 					&& getLineJoin() == rCandidate.getLineJoin());
72*cdf0e10cSrcweir 			}
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir             static ImpLineAttribute* get_global_default()
75*cdf0e10cSrcweir             {
76*cdf0e10cSrcweir                 static ImpLineAttribute* pDefault = 0;
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir                 if(!pDefault)
79*cdf0e10cSrcweir                 {
80*cdf0e10cSrcweir                     pDefault = new ImpLineAttribute(
81*cdf0e10cSrcweir                         basegfx::BColor(),
82*cdf0e10cSrcweir                         0.0,
83*cdf0e10cSrcweir                         basegfx::B2DLINEJOIN_ROUND);
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
86*cdf0e10cSrcweir     			    pDefault->mnRefCount++;
87*cdf0e10cSrcweir                 }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir                 return pDefault;
90*cdf0e10cSrcweir             }
91*cdf0e10cSrcweir 		};
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir         LineAttribute::LineAttribute(
94*cdf0e10cSrcweir             const basegfx::BColor& rColor,
95*cdf0e10cSrcweir 			double fWidth,
96*cdf0e10cSrcweir 			basegfx::B2DLineJoin aB2DLineJoin)
97*cdf0e10cSrcweir 		:	mpLineAttribute(new ImpLineAttribute(
98*cdf0e10cSrcweir                 rColor, fWidth, aB2DLineJoin))
99*cdf0e10cSrcweir 		{
100*cdf0e10cSrcweir 		}
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 		LineAttribute::LineAttribute()
103*cdf0e10cSrcweir         :	mpLineAttribute(ImpLineAttribute::get_global_default())
104*cdf0e10cSrcweir 		{
105*cdf0e10cSrcweir 			mpLineAttribute->mnRefCount++;
106*cdf0e10cSrcweir 		}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir         LineAttribute::LineAttribute(const LineAttribute& rCandidate)
109*cdf0e10cSrcweir 		:	mpLineAttribute(rCandidate.mpLineAttribute)
110*cdf0e10cSrcweir 		{
111*cdf0e10cSrcweir 			mpLineAttribute->mnRefCount++;
112*cdf0e10cSrcweir 		}
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 		LineAttribute::~LineAttribute()
115*cdf0e10cSrcweir 		{
116*cdf0e10cSrcweir 			if(mpLineAttribute->mnRefCount)
117*cdf0e10cSrcweir 			{
118*cdf0e10cSrcweir 				mpLineAttribute->mnRefCount--;
119*cdf0e10cSrcweir 			}
120*cdf0e10cSrcweir 			else
121*cdf0e10cSrcweir 			{
122*cdf0e10cSrcweir 				delete mpLineAttribute;
123*cdf0e10cSrcweir 			}
124*cdf0e10cSrcweir 		}
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir         bool LineAttribute::isDefault() const
127*cdf0e10cSrcweir         {
128*cdf0e10cSrcweir             return mpLineAttribute == ImpLineAttribute::get_global_default();
129*cdf0e10cSrcweir         }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir         LineAttribute& LineAttribute::operator=(const LineAttribute& rCandidate)
132*cdf0e10cSrcweir 		{
133*cdf0e10cSrcweir 			if(rCandidate.mpLineAttribute != mpLineAttribute)
134*cdf0e10cSrcweir 			{
135*cdf0e10cSrcweir 				if(mpLineAttribute->mnRefCount)
136*cdf0e10cSrcweir 				{
137*cdf0e10cSrcweir 					mpLineAttribute->mnRefCount--;
138*cdf0e10cSrcweir 				}
139*cdf0e10cSrcweir 				else
140*cdf0e10cSrcweir 				{
141*cdf0e10cSrcweir 					delete mpLineAttribute;
142*cdf0e10cSrcweir 				}
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 				mpLineAttribute = rCandidate.mpLineAttribute;
145*cdf0e10cSrcweir 				mpLineAttribute->mnRefCount++;
146*cdf0e10cSrcweir 			}
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 			return *this;
149*cdf0e10cSrcweir 		}
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 		bool LineAttribute::operator==(const LineAttribute& rCandidate) const
152*cdf0e10cSrcweir 		{
153*cdf0e10cSrcweir 			if(rCandidate.mpLineAttribute == mpLineAttribute)
154*cdf0e10cSrcweir 			{
155*cdf0e10cSrcweir 				return true;
156*cdf0e10cSrcweir 			}
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
159*cdf0e10cSrcweir 			{
160*cdf0e10cSrcweir 				return false;
161*cdf0e10cSrcweir 			}
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir 			return (*rCandidate.mpLineAttribute == *mpLineAttribute);
164*cdf0e10cSrcweir 		}
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 		const basegfx::BColor& LineAttribute::getColor() const
167*cdf0e10cSrcweir 		{
168*cdf0e10cSrcweir 			return mpLineAttribute->getColor();
169*cdf0e10cSrcweir 		}
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 		double LineAttribute::getWidth() const
172*cdf0e10cSrcweir         {
173*cdf0e10cSrcweir             return mpLineAttribute->getWidth();
174*cdf0e10cSrcweir         }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir         basegfx::B2DLineJoin LineAttribute::getLineJoin() const
177*cdf0e10cSrcweir         {
178*cdf0e10cSrcweir             return mpLineAttribute->getLineJoin();
179*cdf0e10cSrcweir         }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     } // end of namespace attribute
182*cdf0e10cSrcweir } // end of namespace drawinglayer
183*cdf0e10cSrcweir 
184*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
185*cdf0e10cSrcweir // eof
186