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