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/geometry/viewinformation2d.hxx>
32*cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrix.hxx>
33*cdf0e10cSrcweir #include <basegfx/range/b2drange.hxx>
34*cdf0e10cSrcweir #include <osl/mutex.hxx>
35*cdf0e10cSrcweir #include <basegfx/tools/canvastools.hxx>
36*cdf0e10cSrcweir #include <com/sun/star/geometry/AffineMatrix2D.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/geometry/RealRectangle2D.hpp>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace com::sun::star;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace drawinglayer
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir 	namespace geometry
48*cdf0e10cSrcweir 	{
49*cdf0e10cSrcweir 		class ImpViewInformation2D
50*cdf0e10cSrcweir 		{
51*cdf0e10cSrcweir 		private:
52*cdf0e10cSrcweir 			// ViewInformation2D implementation can change refcount, so we have only
53*cdf0e10cSrcweir 			// two memory regions for pairs of ViewInformation2D/ImpViewInformation2D
54*cdf0e10cSrcweir 			friend class ::drawinglayer::geometry::ViewInformation2D;
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir 			// the refcounter. 0 means exclusively used
57*cdf0e10cSrcweir 			sal_uInt32									mnRefCount;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 		protected:
60*cdf0e10cSrcweir             // the object transformation
61*cdf0e10cSrcweir 			basegfx::B2DHomMatrix						maObjectTransformation;
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir             // the view transformation
64*cdf0e10cSrcweir 			basegfx::B2DHomMatrix						maViewTransformation;
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir             // the ObjectToView and it's inverse, both on demand from ObjectTransformation
67*cdf0e10cSrcweir             // and ViewTransformation
68*cdf0e10cSrcweir 			basegfx::B2DHomMatrix						maObjectToViewTransformation;
69*cdf0e10cSrcweir 			basegfx::B2DHomMatrix						maInverseObjectToViewTransformation;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir             // the visible range and the on-demand one in ViewCoordinates
72*cdf0e10cSrcweir 			basegfx::B2DRange							maViewport;
73*cdf0e10cSrcweir 			basegfx::B2DRange							maDiscreteViewport;
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 			// the DrawPage which is target of visualisation. This is needed e.g. for
76*cdf0e10cSrcweir 			// the view-dependent decomposition of PageNumber TextFields.
77*cdf0e10cSrcweir             // This parameter is buffered here, but mainly resides in mxExtendedInformation,
78*cdf0e10cSrcweir             // so it will be interpreted, but held there. It will also not be added
79*cdf0e10cSrcweir             // to mxExtendedInformation in impFillViewInformationFromContent (it's there already)
80*cdf0e10cSrcweir 			uno::Reference< drawing::XDrawPage >		mxVisualizedPage;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 			// the point in time
83*cdf0e10cSrcweir 			double										mfViewTime;
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir             // bitfield
86*cdf0e10cSrcweir             bool                                        mbReducedDisplayQuality : 1;
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir 			// the complete PropertyValue representation (if already created)
89*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue >		mxViewInformation;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 			// the extra PropertyValues; not represented by ViewTransformation,
92*cdf0e10cSrcweir 			// Viewport, VisualizedPage or ViewTime
93*cdf0e10cSrcweir 			uno::Sequence< beans::PropertyValue >		mxExtendedInformation;
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 			// the local UNO API strings
96*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyObjectTransformation()
97*cdf0e10cSrcweir 			{
98*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("ObjectTransformation"));
99*cdf0e10cSrcweir 				return s_sNameProperty;
100*cdf0e10cSrcweir 			}
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyViewTransformation()
103*cdf0e10cSrcweir 			{
104*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("ViewTransformation"));
105*cdf0e10cSrcweir 				return s_sNameProperty;
106*cdf0e10cSrcweir 			}
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyViewport()
109*cdf0e10cSrcweir 			{
110*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Viewport"));
111*cdf0e10cSrcweir 				return s_sNameProperty;
112*cdf0e10cSrcweir 			}
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyTime()
115*cdf0e10cSrcweir 			{
116*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("Time"));
117*cdf0e10cSrcweir 				return s_sNameProperty;
118*cdf0e10cSrcweir 			}
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyVisualizedPage()
121*cdf0e10cSrcweir 			{
122*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("VisualizedPage"));
123*cdf0e10cSrcweir 				return s_sNameProperty;
124*cdf0e10cSrcweir 			}
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 			const ::rtl::OUString& getNamePropertyReducedDisplayQuality()
127*cdf0e10cSrcweir 			{
128*cdf0e10cSrcweir 				static ::rtl::OUString s_sNameProperty(RTL_CONSTASCII_USTRINGPARAM("ReducedDisplayQuality"));
129*cdf0e10cSrcweir 				return s_sNameProperty;
130*cdf0e10cSrcweir 			}
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 			void impInterpretPropertyValues(const uno::Sequence< beans::PropertyValue >& rViewParameters)
133*cdf0e10cSrcweir 			{
134*cdf0e10cSrcweir 				if(rViewParameters.hasElements())
135*cdf0e10cSrcweir 				{
136*cdf0e10cSrcweir 					const sal_Int32 nCount(rViewParameters.getLength());
137*cdf0e10cSrcweir 					sal_Int32 nExtendedInsert(0);
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 					// prepare extended information for filtering. Maximum size is nCount
140*cdf0e10cSrcweir 					mxExtendedInformation.realloc(nCount);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 					for(sal_Int32 a(0); a < nCount; a++)
143*cdf0e10cSrcweir 					{
144*cdf0e10cSrcweir 						const beans::PropertyValue& rProp = rViewParameters[a];
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 						if(rProp.Name == getNamePropertyReducedDisplayQuality())
147*cdf0e10cSrcweir 						{
148*cdf0e10cSrcweir                             // extra information; add to filtered information
149*cdf0e10cSrcweir 							mxExtendedInformation[nExtendedInsert++] = rProp;
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir                             // for performance reasons, also cache content locally
152*cdf0e10cSrcweir                             sal_Bool bSalBool(false);
153*cdf0e10cSrcweir 							rProp.Value >>= bSalBool;
154*cdf0e10cSrcweir                             mbReducedDisplayQuality = bSalBool;
155*cdf0e10cSrcweir 						}
156*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyObjectTransformation())
157*cdf0e10cSrcweir 						{
158*cdf0e10cSrcweir 							com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D;
159*cdf0e10cSrcweir 							rProp.Value >>= aAffineMatrix2D;
160*cdf0e10cSrcweir 							basegfx::unotools::homMatrixFromAffineMatrix(maObjectTransformation, aAffineMatrix2D);
161*cdf0e10cSrcweir 						}
162*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyViewTransformation())
163*cdf0e10cSrcweir 						{
164*cdf0e10cSrcweir 							com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D;
165*cdf0e10cSrcweir 							rProp.Value >>= aAffineMatrix2D;
166*cdf0e10cSrcweir 							basegfx::unotools::homMatrixFromAffineMatrix(maViewTransformation, aAffineMatrix2D);
167*cdf0e10cSrcweir 						}
168*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyViewport())
169*cdf0e10cSrcweir 						{
170*cdf0e10cSrcweir 							com::sun::star::geometry::RealRectangle2D aViewport;
171*cdf0e10cSrcweir 							rProp.Value >>= aViewport;
172*cdf0e10cSrcweir 							maViewport = basegfx::unotools::b2DRectangleFromRealRectangle2D(aViewport);
173*cdf0e10cSrcweir 						}
174*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyTime())
175*cdf0e10cSrcweir 						{
176*cdf0e10cSrcweir 							rProp.Value >>= mfViewTime;
177*cdf0e10cSrcweir 						}
178*cdf0e10cSrcweir 						else if(rProp.Name == getNamePropertyVisualizedPage())
179*cdf0e10cSrcweir 						{
180*cdf0e10cSrcweir 							rProp.Value >>= mxVisualizedPage;
181*cdf0e10cSrcweir 						}
182*cdf0e10cSrcweir 						else
183*cdf0e10cSrcweir 						{
184*cdf0e10cSrcweir 							// extra information; add to filtered information
185*cdf0e10cSrcweir 							mxExtendedInformation[nExtendedInsert++] = rProp;
186*cdf0e10cSrcweir 						}
187*cdf0e10cSrcweir 					}
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 					// extra information size is now known; realloc to final size
190*cdf0e10cSrcweir 					mxExtendedInformation.realloc(nExtendedInsert);
191*cdf0e10cSrcweir 				}
192*cdf0e10cSrcweir 			}
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 			void impFillViewInformationFromContent()
195*cdf0e10cSrcweir 			{
196*cdf0e10cSrcweir 				uno::Sequence< beans::PropertyValue > xRetval;
197*cdf0e10cSrcweir 				const bool bObjectTransformationUsed(!maObjectTransformation.isIdentity());
198*cdf0e10cSrcweir 				const bool bViewTransformationUsed(!maViewTransformation.isIdentity());
199*cdf0e10cSrcweir 				const bool bViewportUsed(!maViewport.isEmpty());
200*cdf0e10cSrcweir 				const bool bTimeUsed(0.0 < mfViewTime);
201*cdf0e10cSrcweir 				const bool bVisualizedPageUsed(mxVisualizedPage.is());
202*cdf0e10cSrcweir                 const bool bReducedDisplayQualityUsed(true == mbReducedDisplayQuality);
203*cdf0e10cSrcweir 				const bool bExtraInformation(mxExtendedInformation.hasElements());
204*cdf0e10cSrcweir 				sal_uInt32 nIndex(0);
205*cdf0e10cSrcweir 				const sal_uInt32 nCount(
206*cdf0e10cSrcweir 					(bObjectTransformationUsed ? 1 : 0) +
207*cdf0e10cSrcweir 					(bViewTransformationUsed ? 1 : 0) +
208*cdf0e10cSrcweir 					(bViewportUsed ? 1 : 0) +
209*cdf0e10cSrcweir 					(bTimeUsed ? 1 : 0) +
210*cdf0e10cSrcweir 					(bVisualizedPageUsed ? 1 : 0) +
211*cdf0e10cSrcweir                     (bReducedDisplayQualityUsed ? 1 : 0) +
212*cdf0e10cSrcweir 					(bExtraInformation ? mxExtendedInformation.getLength() : 0));
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 				mxViewInformation.realloc(nCount);
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 				if(bObjectTransformationUsed)
217*cdf0e10cSrcweir 				{
218*cdf0e10cSrcweir 					com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D;
219*cdf0e10cSrcweir 					basegfx::unotools::affineMatrixFromHomMatrix(aAffineMatrix2D, maObjectTransformation);
220*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyObjectTransformation();
221*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= aAffineMatrix2D;
222*cdf0e10cSrcweir 					nIndex++;
223*cdf0e10cSrcweir 				}
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 				if(bViewTransformationUsed)
226*cdf0e10cSrcweir 				{
227*cdf0e10cSrcweir 					com::sun::star::geometry::AffineMatrix2D aAffineMatrix2D;
228*cdf0e10cSrcweir 					basegfx::unotools::affineMatrixFromHomMatrix(aAffineMatrix2D, maViewTransformation);
229*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyViewTransformation();
230*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= aAffineMatrix2D;
231*cdf0e10cSrcweir 					nIndex++;
232*cdf0e10cSrcweir 				}
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 				if(bViewportUsed)
235*cdf0e10cSrcweir 				{
236*cdf0e10cSrcweir 					const com::sun::star::geometry::RealRectangle2D aViewport(basegfx::unotools::rectangle2DFromB2DRectangle(maViewport));
237*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyViewport();
238*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= aViewport;
239*cdf0e10cSrcweir 					nIndex++;
240*cdf0e10cSrcweir 				}
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 				if(bTimeUsed)
243*cdf0e10cSrcweir 				{
244*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyTime();
245*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= mfViewTime;
246*cdf0e10cSrcweir 					nIndex++;
247*cdf0e10cSrcweir 				}
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 				if(bVisualizedPageUsed)
250*cdf0e10cSrcweir 				{
251*cdf0e10cSrcweir 					mxViewInformation[nIndex].Name = getNamePropertyVisualizedPage();
252*cdf0e10cSrcweir 					mxViewInformation[nIndex].Value <<= mxVisualizedPage;
253*cdf0e10cSrcweir 					nIndex++;
254*cdf0e10cSrcweir 				}
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 				if(bExtraInformation)
257*cdf0e10cSrcweir 				{
258*cdf0e10cSrcweir 					const sal_Int32 nExtra(mxExtendedInformation.getLength());
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir 					for(sal_Int32 a(0); a < nExtra; a++)
261*cdf0e10cSrcweir 					{
262*cdf0e10cSrcweir 						mxViewInformation[nIndex++] = mxExtendedInformation[a];
263*cdf0e10cSrcweir 					}
264*cdf0e10cSrcweir 				}
265*cdf0e10cSrcweir 			}
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 		public:
268*cdf0e10cSrcweir 			ImpViewInformation2D(
269*cdf0e10cSrcweir 				const basegfx::B2DHomMatrix& rObjectTransformation,
270*cdf0e10cSrcweir 				const basegfx::B2DHomMatrix& rViewTransformation,
271*cdf0e10cSrcweir 				const basegfx::B2DRange& rViewport,
272*cdf0e10cSrcweir 				const uno::Reference< drawing::XDrawPage >& rxDrawPage,
273*cdf0e10cSrcweir 				double fViewTime,
274*cdf0e10cSrcweir 				const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
275*cdf0e10cSrcweir 			:	mnRefCount(0),
276*cdf0e10cSrcweir 				maObjectTransformation(rObjectTransformation),
277*cdf0e10cSrcweir 				maViewTransformation(rViewTransformation),
278*cdf0e10cSrcweir                 maObjectToViewTransformation(),
279*cdf0e10cSrcweir                 maInverseObjectToViewTransformation(),
280*cdf0e10cSrcweir 				maViewport(rViewport),
281*cdf0e10cSrcweir 				maDiscreteViewport(),
282*cdf0e10cSrcweir 				mxVisualizedPage(rxDrawPage),
283*cdf0e10cSrcweir 				mfViewTime(fViewTime),
284*cdf0e10cSrcweir                 mbReducedDisplayQuality(false),
285*cdf0e10cSrcweir 				mxViewInformation(),
286*cdf0e10cSrcweir 				mxExtendedInformation()
287*cdf0e10cSrcweir 			{
288*cdf0e10cSrcweir 				impInterpretPropertyValues(rExtendedParameters);
289*cdf0e10cSrcweir 			}
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 			ImpViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
292*cdf0e10cSrcweir 			:	mnRefCount(0),
293*cdf0e10cSrcweir 				maObjectTransformation(),
294*cdf0e10cSrcweir 				maViewTransformation(),
295*cdf0e10cSrcweir                 maObjectToViewTransformation(),
296*cdf0e10cSrcweir                 maInverseObjectToViewTransformation(),
297*cdf0e10cSrcweir 				maViewport(),
298*cdf0e10cSrcweir 				maDiscreteViewport(),
299*cdf0e10cSrcweir 				mxVisualizedPage(),
300*cdf0e10cSrcweir 				mfViewTime(),
301*cdf0e10cSrcweir                 mbReducedDisplayQuality(false),
302*cdf0e10cSrcweir 				mxViewInformation(rViewParameters),
303*cdf0e10cSrcweir 				mxExtendedInformation()
304*cdf0e10cSrcweir 			{
305*cdf0e10cSrcweir 				impInterpretPropertyValues(rViewParameters);
306*cdf0e10cSrcweir 			}
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir 			ImpViewInformation2D()
309*cdf0e10cSrcweir 			:	mnRefCount(0),
310*cdf0e10cSrcweir 				maObjectTransformation(),
311*cdf0e10cSrcweir 				maViewTransformation(),
312*cdf0e10cSrcweir                 maObjectToViewTransformation(),
313*cdf0e10cSrcweir                 maInverseObjectToViewTransformation(),
314*cdf0e10cSrcweir 				maViewport(),
315*cdf0e10cSrcweir 				maDiscreteViewport(),
316*cdf0e10cSrcweir 				mxVisualizedPage(),
317*cdf0e10cSrcweir 				mfViewTime(),
318*cdf0e10cSrcweir                 mbReducedDisplayQuality(false),
319*cdf0e10cSrcweir 				mxViewInformation(),
320*cdf0e10cSrcweir 				mxExtendedInformation()
321*cdf0e10cSrcweir 			{
322*cdf0e10cSrcweir 			}
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& getObjectTransformation() const
325*cdf0e10cSrcweir             {
326*cdf0e10cSrcweir                 return maObjectTransformation;
327*cdf0e10cSrcweir             }
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& getViewTransformation() const
330*cdf0e10cSrcweir             {
331*cdf0e10cSrcweir                 return maViewTransformation;
332*cdf0e10cSrcweir             }
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 			const basegfx::B2DRange& getViewport() const
335*cdf0e10cSrcweir             {
336*cdf0e10cSrcweir                 return maViewport;
337*cdf0e10cSrcweir             }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir 			const basegfx::B2DRange& getDiscreteViewport() const
340*cdf0e10cSrcweir 			{
341*cdf0e10cSrcweir 			    ::osl::Mutex m_mutex;
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 				if(maDiscreteViewport.isEmpty() && !maViewport.isEmpty())
344*cdf0e10cSrcweir 				{
345*cdf0e10cSrcweir 					basegfx::B2DRange aDiscreteViewport(maViewport);
346*cdf0e10cSrcweir 					aDiscreteViewport.transform(getViewTransformation());
347*cdf0e10cSrcweir 					const_cast< ImpViewInformation2D* >(this)->maDiscreteViewport = aDiscreteViewport;
348*cdf0e10cSrcweir 				}
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir 				return maDiscreteViewport;
351*cdf0e10cSrcweir 			}
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir     		const basegfx::B2DHomMatrix& getObjectToViewTransformation() const
354*cdf0e10cSrcweir             {
355*cdf0e10cSrcweir 			    ::osl::Mutex m_mutex;
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 				if(maObjectToViewTransformation.isIdentity() &&
358*cdf0e10cSrcweir                     (!maObjectTransformation.isIdentity() || !maViewTransformation.isIdentity()))
359*cdf0e10cSrcweir 				{
360*cdf0e10cSrcweir     				basegfx::B2DHomMatrix aObjectToView(maViewTransformation * maObjectTransformation);
361*cdf0e10cSrcweir 					const_cast< ImpViewInformation2D* >(this)->maObjectToViewTransformation = aObjectToView;
362*cdf0e10cSrcweir 				}
363*cdf0e10cSrcweir 
364*cdf0e10cSrcweir 				return maObjectToViewTransformation;
365*cdf0e10cSrcweir             }
366*cdf0e10cSrcweir 
367*cdf0e10cSrcweir     		const basegfx::B2DHomMatrix& getInverseObjectToViewTransformation() const
368*cdf0e10cSrcweir             {
369*cdf0e10cSrcweir 			    ::osl::Mutex m_mutex;
370*cdf0e10cSrcweir 
371*cdf0e10cSrcweir 				if(maInverseObjectToViewTransformation.isIdentity() &&
372*cdf0e10cSrcweir                     (!maObjectTransformation.isIdentity() || !maViewTransformation.isIdentity()))
373*cdf0e10cSrcweir 				{
374*cdf0e10cSrcweir     				basegfx::B2DHomMatrix aInverseObjectToView(maViewTransformation * maObjectTransformation);
375*cdf0e10cSrcweir                     aInverseObjectToView.invert();
376*cdf0e10cSrcweir 					const_cast< ImpViewInformation2D* >(this)->maInverseObjectToViewTransformation = aInverseObjectToView;
377*cdf0e10cSrcweir 				}
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir 				return maInverseObjectToViewTransformation;
380*cdf0e10cSrcweir             }
381*cdf0e10cSrcweir 
382*cdf0e10cSrcweir 			double getViewTime() const
383*cdf0e10cSrcweir             {
384*cdf0e10cSrcweir                 return mfViewTime;
385*cdf0e10cSrcweir             }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 			const uno::Reference< drawing::XDrawPage >& getVisualizedPage() const
388*cdf0e10cSrcweir 			{
389*cdf0e10cSrcweir 				return mxVisualizedPage;
390*cdf0e10cSrcweir 			}
391*cdf0e10cSrcweir 
392*cdf0e10cSrcweir             bool getReducedDisplayQuality() const
393*cdf0e10cSrcweir             {
394*cdf0e10cSrcweir                 return mbReducedDisplayQuality;
395*cdf0e10cSrcweir             }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 			const uno::Sequence< beans::PropertyValue >& getViewInformationSequence() const
398*cdf0e10cSrcweir 			{
399*cdf0e10cSrcweir 				if(!mxViewInformation.hasElements())
400*cdf0e10cSrcweir 				{
401*cdf0e10cSrcweir 					const_cast< ImpViewInformation2D* >(this)->impFillViewInformationFromContent();
402*cdf0e10cSrcweir 				}
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir 				return mxViewInformation;
405*cdf0e10cSrcweir 			}
406*cdf0e10cSrcweir 
407*cdf0e10cSrcweir 			const uno::Sequence< beans::PropertyValue >& getExtendedInformationSequence() const
408*cdf0e10cSrcweir 			{
409*cdf0e10cSrcweir 				return mxExtendedInformation;
410*cdf0e10cSrcweir 			}
411*cdf0e10cSrcweir 
412*cdf0e10cSrcweir 			bool operator==(const ImpViewInformation2D& rCandidate) const
413*cdf0e10cSrcweir 			{
414*cdf0e10cSrcweir 				return (maObjectTransformation == rCandidate.maObjectTransformation
415*cdf0e10cSrcweir                     && maViewTransformation == rCandidate.maViewTransformation
416*cdf0e10cSrcweir 					&& maViewport == rCandidate.maViewport
417*cdf0e10cSrcweir 					&& mxVisualizedPage == rCandidate.mxVisualizedPage
418*cdf0e10cSrcweir 					&& mfViewTime == rCandidate.mfViewTime
419*cdf0e10cSrcweir 					&& mxExtendedInformation == rCandidate.mxExtendedInformation);
420*cdf0e10cSrcweir 			}
421*cdf0e10cSrcweir 
422*cdf0e10cSrcweir 			static ImpViewInformation2D* get_global_default()
423*cdf0e10cSrcweir             {
424*cdf0e10cSrcweir                 static ImpViewInformation2D* pDefault = 0;
425*cdf0e10cSrcweir 
426*cdf0e10cSrcweir                 if(!pDefault)
427*cdf0e10cSrcweir                 {
428*cdf0e10cSrcweir                     pDefault = new ImpViewInformation2D();
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir                     // never delete; start with RefCount 1, not 0
431*cdf0e10cSrcweir     			    pDefault->mnRefCount++;
432*cdf0e10cSrcweir                 }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir                 return pDefault;
435*cdf0e10cSrcweir             }
436*cdf0e10cSrcweir 		};
437*cdf0e10cSrcweir 	} // end of anonymous namespace
438*cdf0e10cSrcweir } // end of namespace drawinglayer
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir namespace drawinglayer
443*cdf0e10cSrcweir {
444*cdf0e10cSrcweir 	namespace geometry
445*cdf0e10cSrcweir 	{
446*cdf0e10cSrcweir 		ViewInformation2D::ViewInformation2D(
447*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rObjectTransformation,
448*cdf0e10cSrcweir 			const basegfx::B2DHomMatrix& rViewTransformation,
449*cdf0e10cSrcweir 			const basegfx::B2DRange& rViewport,
450*cdf0e10cSrcweir 			const uno::Reference< drawing::XDrawPage >& rxDrawPage,
451*cdf0e10cSrcweir 			double fViewTime,
452*cdf0e10cSrcweir 			const uno::Sequence< beans::PropertyValue >& rExtendedParameters)
453*cdf0e10cSrcweir 		:	mpViewInformation2D(new ImpViewInformation2D(
454*cdf0e10cSrcweir                 rObjectTransformation,
455*cdf0e10cSrcweir                 rViewTransformation,
456*cdf0e10cSrcweir                 rViewport,
457*cdf0e10cSrcweir                 rxDrawPage,
458*cdf0e10cSrcweir                 fViewTime,
459*cdf0e10cSrcweir                 rExtendedParameters))
460*cdf0e10cSrcweir 		{
461*cdf0e10cSrcweir 		}
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir 		ViewInformation2D::ViewInformation2D(const uno::Sequence< beans::PropertyValue >& rViewParameters)
464*cdf0e10cSrcweir 		:	mpViewInformation2D(new ImpViewInformation2D(rViewParameters))
465*cdf0e10cSrcweir 		{
466*cdf0e10cSrcweir 		}
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir 		ViewInformation2D::ViewInformation2D()
469*cdf0e10cSrcweir         :	mpViewInformation2D(ImpViewInformation2D::get_global_default())
470*cdf0e10cSrcweir 		{
471*cdf0e10cSrcweir 			mpViewInformation2D->mnRefCount++;
472*cdf0e10cSrcweir 		}
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir 		ViewInformation2D::ViewInformation2D(const ViewInformation2D& rCandidate)
475*cdf0e10cSrcweir 		:	mpViewInformation2D(rCandidate.mpViewInformation2D)
476*cdf0e10cSrcweir 		{
477*cdf0e10cSrcweir 		    ::osl::Mutex m_mutex;
478*cdf0e10cSrcweir 			mpViewInformation2D->mnRefCount++;
479*cdf0e10cSrcweir 		}
480*cdf0e10cSrcweir 
481*cdf0e10cSrcweir 		ViewInformation2D::~ViewInformation2D()
482*cdf0e10cSrcweir 		{
483*cdf0e10cSrcweir 		    ::osl::Mutex m_mutex;
484*cdf0e10cSrcweir 
485*cdf0e10cSrcweir 			if(mpViewInformation2D->mnRefCount)
486*cdf0e10cSrcweir 			{
487*cdf0e10cSrcweir 				mpViewInformation2D->mnRefCount--;
488*cdf0e10cSrcweir 			}
489*cdf0e10cSrcweir 			else
490*cdf0e10cSrcweir 			{
491*cdf0e10cSrcweir 				delete mpViewInformation2D;
492*cdf0e10cSrcweir 			}
493*cdf0e10cSrcweir 		}
494*cdf0e10cSrcweir 
495*cdf0e10cSrcweir         bool ViewInformation2D::isDefault() const
496*cdf0e10cSrcweir         {
497*cdf0e10cSrcweir             return mpViewInformation2D == ImpViewInformation2D::get_global_default();
498*cdf0e10cSrcweir         }
499*cdf0e10cSrcweir 
500*cdf0e10cSrcweir 		ViewInformation2D& ViewInformation2D::operator=(const ViewInformation2D& rCandidate)
501*cdf0e10cSrcweir 		{
502*cdf0e10cSrcweir 		    ::osl::Mutex m_mutex;
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir 			if(mpViewInformation2D->mnRefCount)
505*cdf0e10cSrcweir 			{
506*cdf0e10cSrcweir 				mpViewInformation2D->mnRefCount--;
507*cdf0e10cSrcweir 			}
508*cdf0e10cSrcweir 			else
509*cdf0e10cSrcweir 			{
510*cdf0e10cSrcweir 				delete mpViewInformation2D;
511*cdf0e10cSrcweir 			}
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 			mpViewInformation2D = rCandidate.mpViewInformation2D;
514*cdf0e10cSrcweir 			mpViewInformation2D->mnRefCount++;
515*cdf0e10cSrcweir 
516*cdf0e10cSrcweir 			return *this;
517*cdf0e10cSrcweir 		}
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir 		bool ViewInformation2D::operator==(const ViewInformation2D& rCandidate) const
520*cdf0e10cSrcweir 		{
521*cdf0e10cSrcweir 			if(rCandidate.mpViewInformation2D == mpViewInformation2D)
522*cdf0e10cSrcweir 			{
523*cdf0e10cSrcweir 				return true;
524*cdf0e10cSrcweir 			}
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir 			if(rCandidate.isDefault() != isDefault())
527*cdf0e10cSrcweir 			{
528*cdf0e10cSrcweir 				return false;
529*cdf0e10cSrcweir 			}
530*cdf0e10cSrcweir 
531*cdf0e10cSrcweir 			return (*rCandidate.mpViewInformation2D == *mpViewInformation2D);
532*cdf0e10cSrcweir 		}
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir 		const basegfx::B2DHomMatrix& ViewInformation2D::getObjectTransformation() const
535*cdf0e10cSrcweir         {
536*cdf0e10cSrcweir 			return mpViewInformation2D->getObjectTransformation();
537*cdf0e10cSrcweir         }
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir 		const basegfx::B2DHomMatrix& ViewInformation2D::getViewTransformation() const
540*cdf0e10cSrcweir 		{
541*cdf0e10cSrcweir 			return mpViewInformation2D->getViewTransformation();
542*cdf0e10cSrcweir 		}
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir 		const basegfx::B2DRange& ViewInformation2D::getViewport() const
545*cdf0e10cSrcweir 		{
546*cdf0e10cSrcweir 			return mpViewInformation2D->getViewport();
547*cdf0e10cSrcweir 		}
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir 		double ViewInformation2D::getViewTime() const
550*cdf0e10cSrcweir 		{
551*cdf0e10cSrcweir 			return mpViewInformation2D->getViewTime();
552*cdf0e10cSrcweir 		}
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir 		const uno::Reference< drawing::XDrawPage >& ViewInformation2D::getVisualizedPage() const
555*cdf0e10cSrcweir 		{
556*cdf0e10cSrcweir 			return mpViewInformation2D->getVisualizedPage();
557*cdf0e10cSrcweir 		}
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir 		const basegfx::B2DHomMatrix& ViewInformation2D::getObjectToViewTransformation() const
560*cdf0e10cSrcweir         {
561*cdf0e10cSrcweir 			return mpViewInformation2D->getObjectToViewTransformation();
562*cdf0e10cSrcweir         }
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir 		const basegfx::B2DHomMatrix& ViewInformation2D::getInverseObjectToViewTransformation() const
565*cdf0e10cSrcweir         {
566*cdf0e10cSrcweir 			return mpViewInformation2D->getInverseObjectToViewTransformation();
567*cdf0e10cSrcweir         }
568*cdf0e10cSrcweir 
569*cdf0e10cSrcweir         const basegfx::B2DRange& ViewInformation2D::getDiscreteViewport() const
570*cdf0e10cSrcweir 		{
571*cdf0e10cSrcweir 			return mpViewInformation2D->getDiscreteViewport();
572*cdf0e10cSrcweir 		}
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir         bool ViewInformation2D::getReducedDisplayQuality() const
575*cdf0e10cSrcweir         {
576*cdf0e10cSrcweir             return mpViewInformation2D->getReducedDisplayQuality();
577*cdf0e10cSrcweir         }
578*cdf0e10cSrcweir 
579*cdf0e10cSrcweir 		const uno::Sequence< beans::PropertyValue >& ViewInformation2D::getViewInformationSequence() const
580*cdf0e10cSrcweir 		{
581*cdf0e10cSrcweir 			return mpViewInformation2D->getViewInformationSequence();
582*cdf0e10cSrcweir 		}
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir 		const uno::Sequence< beans::PropertyValue >& ViewInformation2D::getExtendedInformationSequence() const
585*cdf0e10cSrcweir 		{
586*cdf0e10cSrcweir 			return mpViewInformation2D->getExtendedInformationSequence();
587*cdf0e10cSrcweir 		}
588*cdf0e10cSrcweir 	} // end of namespace geometry
589*cdf0e10cSrcweir } // end of namespace drawinglayer
590*cdf0e10cSrcweir 
591*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
592*cdf0e10cSrcweir // eof
593