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 #include "precompiled_svx.hxx"
29 
30 #include <svx/sdr/attribute/sdrformtextoutlineattribute.hxx>
31 #include <drawinglayer/attribute/lineattribute.hxx>
32 #include <drawinglayer/attribute/strokeattribute.hxx>
33 
34 //////////////////////////////////////////////////////////////////////////////
35 
36 namespace drawinglayer
37 {
38 	namespace attribute
39 	{
40         class ImpSdrFormTextOutlineAttribute
41         {
42 		public:
43 			// refcounter
44 			sal_uInt32							mnRefCount;
45 
46             // one set of attributes for FormText (FontWork) outline visualisation
47 		    LineAttribute                       maLineAttribute;
48 		    StrokeAttribute                     maStrokeAttribute;
49 		    sal_uInt8                           mnTransparence;
50 
51 			ImpSdrFormTextOutlineAttribute(
52                 const LineAttribute& rLineAttribute,
53                 const StrokeAttribute& rStrokeAttribute,
54                 sal_uInt8 nTransparence)
55 			:	mnRefCount(0),
56 				maLineAttribute(rLineAttribute),
57 				maStrokeAttribute(rStrokeAttribute),
58 				mnTransparence(nTransparence)
59 			{
60 			}
61 
62 			// data read access
63             const LineAttribute& getLineAttribute() const { return maLineAttribute; }
64             const StrokeAttribute& getStrokeAttribute() const { return maStrokeAttribute; }
65             sal_uInt8 getTransparence() const { return mnTransparence; }
66 
67 			// compare operator
68 			bool operator==(const ImpSdrFormTextOutlineAttribute& rCandidate) const
69 			{
70 				return (getLineAttribute() == rCandidate.getLineAttribute()
71 					&& getStrokeAttribute() == rCandidate.getStrokeAttribute()
72 					&& getTransparence() == rCandidate.getTransparence());
73 			}
74 
75 			static ImpSdrFormTextOutlineAttribute* get_global_default()
76             {
77                 static ImpSdrFormTextOutlineAttribute* pDefault = 0;
78 
79                 if(!pDefault)
80                 {
81                     pDefault = new ImpSdrFormTextOutlineAttribute(
82 						LineAttribute(),
83 						StrokeAttribute(),
84 						0);
85 
86                     // never delete; start with RefCount 1, not 0
87     			    pDefault->mnRefCount++;
88                 }
89 
90                 return pDefault;
91             }
92         };
93 
94         SdrFormTextOutlineAttribute::SdrFormTextOutlineAttribute(
95 			const LineAttribute& rLineAttribute,
96             const StrokeAttribute& rStrokeAttribute,
97             sal_uInt8 nTransparence)
98 		:	mpSdrFormTextOutlineAttribute(new ImpSdrFormTextOutlineAttribute(
99 				rLineAttribute, rStrokeAttribute, nTransparence))
100 		{
101 		}
102 
103 		SdrFormTextOutlineAttribute::SdrFormTextOutlineAttribute()
104         :	mpSdrFormTextOutlineAttribute(ImpSdrFormTextOutlineAttribute::get_global_default())
105 		{
106 			mpSdrFormTextOutlineAttribute->mnRefCount++;
107 		}
108 
109         SdrFormTextOutlineAttribute::SdrFormTextOutlineAttribute(const SdrFormTextOutlineAttribute& rCandidate)
110 		:	mpSdrFormTextOutlineAttribute(rCandidate.mpSdrFormTextOutlineAttribute)
111 		{
112 			mpSdrFormTextOutlineAttribute->mnRefCount++;
113 		}
114 
115 		SdrFormTextOutlineAttribute::~SdrFormTextOutlineAttribute()
116 		{
117 			if(mpSdrFormTextOutlineAttribute->mnRefCount)
118 			{
119 				mpSdrFormTextOutlineAttribute->mnRefCount--;
120 			}
121 			else
122 			{
123 				delete mpSdrFormTextOutlineAttribute;
124 			}
125 		}
126 
127         bool SdrFormTextOutlineAttribute::isDefault() const
128         {
129             return mpSdrFormTextOutlineAttribute == ImpSdrFormTextOutlineAttribute::get_global_default();
130         }
131 
132         SdrFormTextOutlineAttribute& SdrFormTextOutlineAttribute::operator=(const SdrFormTextOutlineAttribute& rCandidate)
133 		{
134 			if(rCandidate.mpSdrFormTextOutlineAttribute != mpSdrFormTextOutlineAttribute)
135 			{
136 				if(mpSdrFormTextOutlineAttribute->mnRefCount)
137 				{
138 					mpSdrFormTextOutlineAttribute->mnRefCount--;
139 				}
140 				else
141 				{
142 					delete mpSdrFormTextOutlineAttribute;
143 				}
144 
145 				mpSdrFormTextOutlineAttribute = rCandidate.mpSdrFormTextOutlineAttribute;
146 				mpSdrFormTextOutlineAttribute->mnRefCount++;
147 			}
148 
149 			return *this;
150 		}
151 
152 		bool SdrFormTextOutlineAttribute::operator==(const SdrFormTextOutlineAttribute& rCandidate) const
153 		{
154 			if(rCandidate.mpSdrFormTextOutlineAttribute == mpSdrFormTextOutlineAttribute)
155 			{
156 				return true;
157 			}
158 
159 			if(rCandidate.isDefault() != isDefault())
160 			{
161 				return false;
162 			}
163 
164 			return (*rCandidate.mpSdrFormTextOutlineAttribute == *mpSdrFormTextOutlineAttribute);
165 		}
166 
167         const LineAttribute& SdrFormTextOutlineAttribute::getLineAttribute() const
168 		{
169 			return mpSdrFormTextOutlineAttribute->getLineAttribute();
170 		}
171 
172 		const StrokeAttribute& SdrFormTextOutlineAttribute::getStrokeAttribute() const
173 		{
174 			return mpSdrFormTextOutlineAttribute->getStrokeAttribute();
175 		}
176 
177 		sal_uInt8 SdrFormTextOutlineAttribute::getTransparence() const
178 		{
179 			return mpSdrFormTextOutlineAttribute->getTransparence();
180 		}
181 	} // end of namespace attribute
182 } // end of namespace drawinglayer
183 
184 //////////////////////////////////////////////////////////////////////////////
185 // eof
186