1 /*************************************************************************
2  *
3  *  OpenOffice.org - a multi-platform office productivity suite
4  *
5  *  $RCSfile: sdrattribute3d.cxx,v $
6  *
7  *  $Revision: 1.5 $
8  *
9  *  last change: $Author: aw $ $Date: 2008-05-27 14:11:19 $
10  *
11  *  The Contents of this file are made available subject to
12  *  the terms of GNU Lesser General Public License Version 2.1.
13  *
14  *
15  *    GNU Lesser General Public License Version 2.1
16  *    =============================================
17  *    Copyright 2005 by Sun Microsystems, Inc.
18  *    901 San Antonio Road, Palo Alto, CA 94303, USA
19  *
20  *    This library is free software; you can redistribute it and/or
21  *    modify it under the terms of the GNU Lesser General Public
22  *    License version 2.1, as published by the Free Software Foundation.
23  *
24  *    This library is distributed in the hope that it will be useful,
25  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27  *    Lesser General Public License for more details.
28  *
29  *    You should have received a copy of the GNU Lesser General Public
30  *    License along with this library; if not, write to the Free Software
31  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32  *    MA  02111-1307  USA
33  *
34  ************************************************************************/
35 
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
38 
39 #include <drawinglayer/attribute/sdrsceneattribute3d.hxx>
40 
41 //////////////////////////////////////////////////////////////////////////////
42 
43 namespace drawinglayer
44 {
45 	namespace attribute
46 	{
47 		class ImpSdrSceneAttribute
48 		{
49 		public:
50 			// refcounter
51 			sal_uInt32								mnRefCount;
52 
53 			// 3D scene attribute definitions
54 			double										mfDistance;
55 			double										mfShadowSlant;
56 			::com::sun::star::drawing::ProjectionMode	maProjectionMode;
57 			::com::sun::star::drawing::ShadeMode		maShadeMode;
58 
59 			// bitfield
60 			unsigned									mbTwoSidedLighting : 1;
61 
62 		public:
63 			ImpSdrSceneAttribute(
64 				double fDistance,
65 				double fShadowSlant,
66 				::com::sun::star::drawing::ProjectionMode aProjectionMode,
67 				::com::sun::star::drawing::ShadeMode aShadeMode,
68 				bool bTwoSidedLighting)
69 			:	mnRefCount(0),
70 		    	mfDistance(fDistance),
71 			    mfShadowSlant(fShadowSlant),
72 			    maProjectionMode(aProjectionMode),
73 			    maShadeMode(aShadeMode),
74 			    mbTwoSidedLighting(bTwoSidedLighting)
75 		    {
76 		    }
77 
78 			// data read access
79 			double getDistance() const { return mfDistance; }
80 			double getShadowSlant() const { return mfShadowSlant; }
81 			::com::sun::star::drawing::ProjectionMode getProjectionMode() const { return maProjectionMode; }
82 			::com::sun::star::drawing::ShadeMode getShadeMode() const { return maShadeMode; }
83 			bool getTwoSidedLighting() const { return mbTwoSidedLighting; }
84 
85 			bool operator==(const ImpSdrSceneAttribute& rCandidate) const
86 		    {
87 			    return (getDistance() == rCandidate.getDistance()
88 				    && getShadowSlant() == rCandidate.getShadowSlant()
89 				    && getProjectionMode() == rCandidate.getProjectionMode()
90 				    && getShadeMode() == rCandidate.getShadeMode()
91 				    && getTwoSidedLighting() == rCandidate.getTwoSidedLighting());
92 		    }
93 
94             static ImpSdrSceneAttribute* get_global_default()
95             {
96                 static ImpSdrSceneAttribute* pDefault = 0;
97 
98                 if(!pDefault)
99                 {
100                     pDefault = new ImpSdrSceneAttribute(
101 			            0.0, 0.0,
102 			            ::com::sun::star::drawing::ProjectionMode_PARALLEL,
103 			            ::com::sun::star::drawing::ShadeMode_FLAT,
104 			            false);
105 
106                     // never delete; start with RefCount 1, not 0
107     			    pDefault->mnRefCount++;
108                 }
109 
110                 return pDefault;
111             }
112 		};
113 
114         SdrSceneAttribute::SdrSceneAttribute(
115 			double fDistance,
116 			double fShadowSlant,
117 			::com::sun::star::drawing::ProjectionMode aProjectionMode,
118 			::com::sun::star::drawing::ShadeMode aShadeMode,
119 			bool bTwoSidedLighting)
120 		:	mpSdrSceneAttribute(new ImpSdrSceneAttribute(
121                 fDistance, fShadowSlant, aProjectionMode, aShadeMode, bTwoSidedLighting))
122 		{
123 		}
124 
125 		SdrSceneAttribute::SdrSceneAttribute()
126         :	mpSdrSceneAttribute(ImpSdrSceneAttribute::get_global_default())
127 		{
128 			mpSdrSceneAttribute->mnRefCount++;
129 		}
130 
131         SdrSceneAttribute::SdrSceneAttribute(const SdrSceneAttribute& rCandidate)
132 		:	mpSdrSceneAttribute(rCandidate.mpSdrSceneAttribute)
133 		{
134 			mpSdrSceneAttribute->mnRefCount++;
135 		}
136 
137 		SdrSceneAttribute::~SdrSceneAttribute()
138 		{
139 			if(mpSdrSceneAttribute->mnRefCount)
140 			{
141 				mpSdrSceneAttribute->mnRefCount--;
142 			}
143 			else
144 			{
145 				delete mpSdrSceneAttribute;
146 			}
147 		}
148 
149         bool SdrSceneAttribute::isDefault() const
150         {
151             return mpSdrSceneAttribute == ImpSdrSceneAttribute::get_global_default();
152         }
153 
154         SdrSceneAttribute& SdrSceneAttribute::operator=(const SdrSceneAttribute& rCandidate)
155 		{
156 			if(rCandidate.mpSdrSceneAttribute != mpSdrSceneAttribute)
157 			{
158 				if(mpSdrSceneAttribute->mnRefCount)
159 				{
160 					mpSdrSceneAttribute->mnRefCount--;
161 				}
162 				else
163 				{
164 					delete mpSdrSceneAttribute;
165 				}
166 
167 				mpSdrSceneAttribute = rCandidate.mpSdrSceneAttribute;
168 				mpSdrSceneAttribute->mnRefCount++;
169 			}
170 
171 			return *this;
172 		}
173 
174 		bool SdrSceneAttribute::operator==(const SdrSceneAttribute& rCandidate) const
175 		{
176 			if(rCandidate.mpSdrSceneAttribute == mpSdrSceneAttribute)
177 			{
178 				return true;
179 			}
180 
181 			if(rCandidate.isDefault() != isDefault())
182 			{
183 				return false;
184 			}
185 
186 			return (*rCandidate.mpSdrSceneAttribute == *mpSdrSceneAttribute);
187 		}
188 
189 		double SdrSceneAttribute::getDistance() const
190         {
191             return mpSdrSceneAttribute->getDistance();
192         }
193 
194 		double SdrSceneAttribute::getShadowSlant() const
195         {
196             return mpSdrSceneAttribute->getShadowSlant();
197         }
198 
199 		::com::sun::star::drawing::ProjectionMode SdrSceneAttribute::getProjectionMode() const
200         {
201             return mpSdrSceneAttribute->getProjectionMode();
202         }
203 
204 		::com::sun::star::drawing::ShadeMode SdrSceneAttribute::getShadeMode() const
205         {
206             return mpSdrSceneAttribute->getShadeMode();
207         }
208 
209 		bool SdrSceneAttribute::getTwoSidedLighting() const
210         {
211             return mpSdrSceneAttribute->getTwoSidedLighting();
212         }
213 
214     } // end of namespace attribute
215 } // end of namespace drawinglayer
216 
217 //////////////////////////////////////////////////////////////////////////////
218 // eof
219