1*5900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5900e8ecSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5900e8ecSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5900e8ecSAndrew Rist  * distributed with this work for additional information
6*5900e8ecSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5900e8ecSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5900e8ecSAndrew Rist  * "License"); you may not use this file except in compliance
9*5900e8ecSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5900e8ecSAndrew Rist  *
11*5900e8ecSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5900e8ecSAndrew Rist  *
13*5900e8ecSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5900e8ecSAndrew Rist  * software distributed under the License is distributed on an
15*5900e8ecSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5900e8ecSAndrew Rist  * KIND, either express or implied.  See the License for the
17*5900e8ecSAndrew Rist  * specific language governing permissions and limitations
18*5900e8ecSAndrew Rist  * under the License.
19*5900e8ecSAndrew Rist  *
20*5900e8ecSAndrew Rist  *************************************************************/
21*5900e8ecSAndrew Rist 
22*5900e8ecSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyState.hpp>
28cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
29cdf0e10cSrcweir #include <com/sun/star/awt/Rectangle.hpp>
30cdf0e10cSrcweir #include <rtl/uuid.h>
31cdf0e10cSrcweir #include <vos/mutex.hxx>
32cdf0e10cSrcweir #include <vcl/svapp.hxx>
33cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
34cdf0e10cSrcweir #include <comphelper/propertysetinfo.hxx>
35cdf0e10cSrcweir #include <svl/itemprop.hxx>
36cdf0e10cSrcweir #include <svtools/grfmgr.hxx>
37cdf0e10cSrcweir #include "graphic.hxx"
38cdf0e10cSrcweir #include "renderer.hxx"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #define UNOGRAPHIC_DEVICE 			1
41cdf0e10cSrcweir #define UNOGRAPHIC_DESTINATIONRECT	2
42cdf0e10cSrcweir #define UNOGRAPHIC_RENDERDATA		3
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace ::com::sun::star;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace unographic {
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // ---------------------
49cdf0e10cSrcweir // - GraphicRendererVCL -
50cdf0e10cSrcweir // ---------------------
51cdf0e10cSrcweir 
GraphicRendererVCL_CreateInstance(const uno::Reference<lang::XMultiServiceFactory> &)52cdf0e10cSrcweir uno::Reference< uno::XInterface > SAL_CALL GraphicRendererVCL_CreateInstance( const uno::Reference< lang::XMultiServiceFactory >& )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	return SAL_STATIC_CAST( ::cppu::OWeakObject*, new GraphicRendererVCL );
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 
GraphicRendererVCL()58cdf0e10cSrcweir GraphicRendererVCL::GraphicRendererVCL() :
59cdf0e10cSrcweir 	::comphelper::PropertySetHelper( createPropertySetInfo() ),
60cdf0e10cSrcweir 	mpOutDev( NULL )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir // ------------------------------------------------------------------------------
65cdf0e10cSrcweir 
~GraphicRendererVCL()66cdf0e10cSrcweir GraphicRendererVCL::~GraphicRendererVCL()
67cdf0e10cSrcweir 	throw()
68cdf0e10cSrcweir {
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir // ------------------------------------------------------------------------------
72cdf0e10cSrcweir 
getImplementationName_Static()73cdf0e10cSrcweir ::rtl::OUString GraphicRendererVCL::getImplementationName_Static()
74cdf0e10cSrcweir 	throw()
75cdf0e10cSrcweir {
76cdf0e10cSrcweir 	return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.GraphicRendererVCL" ) );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir // ------------------------------------------------------------------------------
80cdf0e10cSrcweir 
getSupportedServiceNames_Static()81cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > GraphicRendererVCL::getSupportedServiceNames_Static()
82cdf0e10cSrcweir 	throw(	)
83cdf0e10cSrcweir {
84cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aSeq( 1 );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicRendererVCL" ) );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	return aSeq;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir // ------------------------------------------------------------------------------
92cdf0e10cSrcweir 
queryAggregation(const uno::Type & rType)93cdf0e10cSrcweir uno::Any SAL_CALL GraphicRendererVCL::queryAggregation( const uno::Type & rType )
94cdf0e10cSrcweir 	throw( uno::RuntimeException )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	uno::Any aAny;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 	if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
99cdf0e10cSrcweir 		aAny <<= uno::Reference< lang::XServiceInfo >(this);
100cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
101cdf0e10cSrcweir 		aAny <<= uno::Reference< lang::XTypeProvider >(this);
102cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
103cdf0e10cSrcweir 		aAny <<= uno::Reference< beans::XPropertySet >(this);
104cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
105cdf0e10cSrcweir 		aAny <<= uno::Reference< beans::XPropertyState >(this);
106cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
107cdf0e10cSrcweir 		aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
108cdf0e10cSrcweir 	else if( rType == ::getCppuType((const uno::Reference< graphic::XGraphicRenderer >*)0) )
109cdf0e10cSrcweir 		aAny <<= uno::Reference< graphic::XGraphicRenderer >(this);
110cdf0e10cSrcweir 	else
111cdf0e10cSrcweir 		aAny <<= OWeakAggObject::queryAggregation( rType );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	return aAny;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir // ------------------------------------------------------------------------------
117cdf0e10cSrcweir 
queryInterface(const uno::Type & rType)118cdf0e10cSrcweir uno::Any SAL_CALL GraphicRendererVCL::queryInterface( const uno::Type & rType )
119cdf0e10cSrcweir 	throw( uno::RuntimeException )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	return OWeakAggObject::queryInterface( rType );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir // ------------------------------------------------------------------------------
125cdf0e10cSrcweir 
acquire()126cdf0e10cSrcweir void SAL_CALL GraphicRendererVCL::acquire()
127cdf0e10cSrcweir 	throw()
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	OWeakAggObject::acquire();
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir // ------------------------------------------------------------------------------
133cdf0e10cSrcweir 
release()134cdf0e10cSrcweir void SAL_CALL GraphicRendererVCL::release()
135cdf0e10cSrcweir 	throw()
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	OWeakAggObject::release();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir // ------------------------------------------------------------------------------
141cdf0e10cSrcweir 
getImplementationName()142cdf0e10cSrcweir ::rtl::OUString SAL_CALL GraphicRendererVCL::getImplementationName()
143cdf0e10cSrcweir 	throw( uno::RuntimeException )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir 	return getImplementationName_Static();
146cdf0e10cSrcweir }
147cdf0e10cSrcweir 
148cdf0e10cSrcweir // ------------------------------------------------------------------------------
149cdf0e10cSrcweir 
supportsService(const rtl::OUString & ServiceName)150cdf0e10cSrcweir sal_Bool SAL_CALL GraphicRendererVCL::supportsService( const rtl::OUString& ServiceName )
151cdf0e10cSrcweir 	throw( uno::RuntimeException )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString >	aSNL( getSupportedServiceNames() );
154cdf0e10cSrcweir     const ::rtl::OUString*				pArray = aSNL.getConstArray();
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
157cdf0e10cSrcweir         if( pArray[i] == ServiceName )
158cdf0e10cSrcweir             return true;
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     return false;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir // ------------------------------------------------------------------------------
164cdf0e10cSrcweir 
getSupportedServiceNames()165cdf0e10cSrcweir uno::Sequence< rtl::OUString > SAL_CALL GraphicRendererVCL::getSupportedServiceNames()
166cdf0e10cSrcweir 	throw( uno::RuntimeException )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir // ------------------------------------------------------------------------------
172cdf0e10cSrcweir 
getTypes()173cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL GraphicRendererVCL::getTypes()
174cdf0e10cSrcweir 	throw( uno::RuntimeException )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir 	uno::Sequence< uno::Type >	aTypes( 7 );
177cdf0e10cSrcweir 	uno::Type* 					pTypes = aTypes.getArray();
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
180cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
181cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
182cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
183cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
184cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
185cdf0e10cSrcweir 	*pTypes++ = ::getCppuType((const uno::Reference< graphic::XGraphicRenderer>*)0);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 	return aTypes;
188cdf0e10cSrcweir }
189cdf0e10cSrcweir 
190cdf0e10cSrcweir // ------------------------------------------------------------------------------
191cdf0e10cSrcweir 
getImplementationId()192cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL GraphicRendererVCL::getImplementationId()
193cdf0e10cSrcweir 	throw( uno::RuntimeException )
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	vos::OGuard 						aGuard( Application::GetSolarMutex() );
196cdf0e10cSrcweir 	static uno::Sequence< sal_Int8 >	aId;
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	if( aId.getLength() == 0 )
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir 		aId.realloc( 16 );
201cdf0e10cSrcweir 		rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	return aId;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir 
207cdf0e10cSrcweir // ------------------------------------------------------------------------------
208cdf0e10cSrcweir 
createPropertySetInfo()209cdf0e10cSrcweir ::comphelper::PropertySetInfo* GraphicRendererVCL::createPropertySetInfo()
210cdf0e10cSrcweir {
211cdf0e10cSrcweir 	vos::OGuard 					aGuard( Application::GetSolarMutex() );
212cdf0e10cSrcweir 	::comphelper::PropertySetInfo*	pRet = new ::comphelper::PropertySetInfo();
213cdf0e10cSrcweir 
214cdf0e10cSrcweir 	static ::comphelper::PropertyMapEntry aEntries[] =
215cdf0e10cSrcweir 	{
216cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "Device" ), UNOGRAPHIC_DEVICE, &::getCppuType( (const uno::Any*)(0)), 0, 0 },
217cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "DestinationRect" ), UNOGRAPHIC_DESTINATIONRECT, &::getCppuType( (const awt::Rectangle*)(0)), 0, 0 },
218cdf0e10cSrcweir 		{ MAP_CHAR_LEN( "RenderData" ), UNOGRAPHIC_RENDERDATA,	&::getCppuType( (const uno::Any*)(0)), 0, 0 },
219cdf0e10cSrcweir 
220cdf0e10cSrcweir 		{ 0,0,0,0,0,0 }
221cdf0e10cSrcweir 	};
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	pRet->acquire();
224cdf0e10cSrcweir 	pRet->add( aEntries );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 	return pRet;
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir // ------------------------------------------------------------------------------
230cdf0e10cSrcweir 
_setPropertyValues(const comphelper::PropertyMapEntry ** ppEntries,const uno::Any * pValues)231cdf0e10cSrcweir void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
232cdf0e10cSrcweir 	throw( beans::UnknownPropertyException,
233cdf0e10cSrcweir 		   beans::PropertyVetoException,
234cdf0e10cSrcweir 		   lang::IllegalArgumentException,
235cdf0e10cSrcweir 	   	   lang::WrappedTargetException )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir 	while( *ppEntries )
240cdf0e10cSrcweir 	{
241cdf0e10cSrcweir 		switch( (*ppEntries)->mnHandle )
242cdf0e10cSrcweir 		{
243cdf0e10cSrcweir 			case( UNOGRAPHIC_DEVICE ):
244cdf0e10cSrcweir 			{
245cdf0e10cSrcweir 				uno::Reference< awt::XDevice > xDevice;
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 				if( ( *pValues >>= xDevice ) && xDevice.is() )
248cdf0e10cSrcweir 				{
249cdf0e10cSrcweir 					mxDevice = xDevice;
250cdf0e10cSrcweir 					mpOutDev = VCLUnoHelper::GetOutputDevice( xDevice );
251cdf0e10cSrcweir 				}
252cdf0e10cSrcweir 				else
253cdf0e10cSrcweir 				{
254cdf0e10cSrcweir 					mxDevice.clear();
255cdf0e10cSrcweir 					mpOutDev = NULL;
256cdf0e10cSrcweir 				}
257cdf0e10cSrcweir 			}
258cdf0e10cSrcweir 			break;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 			case( UNOGRAPHIC_DESTINATIONRECT ):
261cdf0e10cSrcweir 			{
262cdf0e10cSrcweir 				awt::Rectangle aAWTRect;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir 				if( *pValues >>= aAWTRect )
265cdf0e10cSrcweir 				{
266cdf0e10cSrcweir 					maDestRect = Rectangle( Point( aAWTRect.X, aAWTRect.Y ),
267cdf0e10cSrcweir 											Size( aAWTRect.Width, aAWTRect.Height ) );
268cdf0e10cSrcweir 				}
269cdf0e10cSrcweir 			}
270cdf0e10cSrcweir 			break;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 			case( UNOGRAPHIC_RENDERDATA ):
273cdf0e10cSrcweir 			{
274cdf0e10cSrcweir 				*pValues >>= maRenderData;
275cdf0e10cSrcweir 			}
276cdf0e10cSrcweir 			break;
277cdf0e10cSrcweir 		}
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 		++ppEntries;
280cdf0e10cSrcweir 		++pValues;
281cdf0e10cSrcweir 	}
282cdf0e10cSrcweir }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir // ------------------------------------------------------------------------------
285cdf0e10cSrcweir 
_getPropertyValues(const comphelper::PropertyMapEntry ** ppEntries,uno::Any * pValues)286cdf0e10cSrcweir void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValues )
287cdf0e10cSrcweir 	throw( beans::UnknownPropertyException, lang::WrappedTargetException )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir 	::vos::OGuard aGuard( Application::GetSolarMutex() );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 	while( *ppEntries )
292cdf0e10cSrcweir 	{
293cdf0e10cSrcweir 		switch( (*ppEntries)->mnHandle )
294cdf0e10cSrcweir 		{
295cdf0e10cSrcweir 			case( UNOGRAPHIC_DEVICE ):
296cdf0e10cSrcweir 			{
297cdf0e10cSrcweir 				if( mxDevice.is() )
298cdf0e10cSrcweir 					*pValues <<= mxDevice;
299cdf0e10cSrcweir 			}
300cdf0e10cSrcweir 			break;
301cdf0e10cSrcweir 
302cdf0e10cSrcweir 			case( UNOGRAPHIC_DESTINATIONRECT ):
303cdf0e10cSrcweir 			{
304cdf0e10cSrcweir 				const awt::Rectangle aAWTRect( maDestRect.Left(), maDestRect.Top(),
305cdf0e10cSrcweir 											   maDestRect.GetWidth(), maDestRect.GetHeight() );
306cdf0e10cSrcweir 
307cdf0e10cSrcweir 				*pValues <<= aAWTRect;
308cdf0e10cSrcweir 			}
309cdf0e10cSrcweir 			break;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 			case( UNOGRAPHIC_RENDERDATA ):
312cdf0e10cSrcweir 			{
313cdf0e10cSrcweir 				*pValues <<= maRenderData;
314cdf0e10cSrcweir 			}
315cdf0e10cSrcweir 			break;
316cdf0e10cSrcweir 		}
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 		++ppEntries;
319cdf0e10cSrcweir 		++pValues;
320cdf0e10cSrcweir 	}
321cdf0e10cSrcweir }
322cdf0e10cSrcweir 
323cdf0e10cSrcweir // ------------------------------------------------------------------------------
324cdf0e10cSrcweir 
render(const uno::Reference<graphic::XGraphic> & rxGraphic)325cdf0e10cSrcweir void SAL_CALL GraphicRendererVCL::render( const uno::Reference< graphic::XGraphic >& rxGraphic )
326cdf0e10cSrcweir 	throw (uno::RuntimeException)
327cdf0e10cSrcweir {
328cdf0e10cSrcweir 	if( mpOutDev && mxDevice.is() && rxGraphic.is() )
329cdf0e10cSrcweir 	{
330cdf0e10cSrcweir 		const uno::Reference< XInterface > 	xIFace( rxGraphic, uno::UNO_QUERY );
331cdf0e10cSrcweir 		const ::Graphic* 					pGraphic = ::unographic::Graphic::getImplementation( xIFace );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 		if( pGraphic )
334cdf0e10cSrcweir 		{
335cdf0e10cSrcweir 			GraphicObject aGraphicObject( *pGraphic );
336cdf0e10cSrcweir 			aGraphicObject.Draw( mpOutDev, maDestRect.TopLeft(), maDestRect.GetSize() );
337cdf0e10cSrcweir 		}
338cdf0e10cSrcweir 	}
339cdf0e10cSrcweir }
340cdf0e10cSrcweir 
341cdf0e10cSrcweir }
342