1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: renderer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_goodies.hxx"
34 #ifndef _COM_SUN_STAR_BEANS_PROPERTYSTATE_HDL_
35 #include <com/sun/star/beans/PropertyState.hpp>
37 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HDL_
38 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #ifndef _COM_SUN_STAR_AWT_RECTANGLE_HDL_
41 #include <com/sun/star/awt/Rectangle.hpp>
44 #include <vos/mutex.hxx>
45 #ifndef _SV_SVAPP_HXX_
46 #include <vcl/svapp.hxx>
49 #include <toolkit/helper/vclunohelper.hxx>
50 #include <comphelper/propertysetinfo.hxx>
51 #include <svtools/itemprop.hxx>
53 #include "graphic.hxx"
54 #include "renderer.hxx"
56 #define UNOGRAPHIC_DEVICE 1
57 #define UNOGRAPHIC_DESTINATIONRECT 2
58 #define UNOGRAPHIC_RENDERDATA 3
60 using namespace ::com::sun::star
;
62 namespace unographic
{
64 // ---------------------
65 // - GraphicRendererVCL -
66 // ---------------------
68 GraphicRendererVCL::GraphicRendererVCL() :
69 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
74 // ------------------------------------------------------------------------------
76 GraphicRendererVCL::~GraphicRendererVCL()
81 // ------------------------------------------------------------------------------
83 ::rtl::OUString
GraphicRendererVCL::getImplementationName_Static()
86 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.GraphicRendererVCL" ) );
89 // ------------------------------------------------------------------------------
91 uno::Sequence
< ::rtl::OUString
> GraphicRendererVCL::getSupportedServiceNames_Static()
94 uno::Sequence
< ::rtl::OUString
> aSeq( 1 );
96 aSeq
.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicRendererVCL" ) );
101 // ------------------------------------------------------------------------------
103 uno::Any SAL_CALL
GraphicRendererVCL::queryAggregation( const uno::Type
& rType
)
104 throw( uno::RuntimeException
)
108 if( rType
== ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0) )
109 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
110 else if( rType
== ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0) )
111 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
112 else if( rType
== ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0) )
113 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
114 else if( rType
== ::getCppuType((const uno::Reference
< beans::XPropertyState
>*)0) )
115 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
116 else if( rType
== ::getCppuType((const uno::Reference
< beans::XMultiPropertySet
>*)0) )
117 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
118 else if( rType
== ::getCppuType((const uno::Reference
< graphic::XGraphicRenderer
>*)0) )
119 aAny
<<= uno::Reference
< graphic::XGraphicRenderer
>(this);
121 aAny
<<= OWeakAggObject::queryAggregation( rType
);
126 // ------------------------------------------------------------------------------
128 uno::Any SAL_CALL
GraphicRendererVCL::queryInterface( const uno::Type
& rType
)
129 throw( uno::RuntimeException
)
131 return OWeakAggObject::queryInterface( rType
);
134 // ------------------------------------------------------------------------------
136 void SAL_CALL
GraphicRendererVCL::acquire()
139 OWeakAggObject::acquire();
142 // ------------------------------------------------------------------------------
144 void SAL_CALL
GraphicRendererVCL::release()
147 OWeakAggObject::release();
150 // ------------------------------------------------------------------------------
152 ::rtl::OUString SAL_CALL
GraphicRendererVCL::getImplementationName()
153 throw( uno::RuntimeException
)
155 return getImplementationName_Static();
158 // ------------------------------------------------------------------------------
160 sal_Bool SAL_CALL
GraphicRendererVCL::supportsService( const rtl::OUString
& ServiceName
)
161 throw( uno::RuntimeException
)
163 uno::Sequence
< ::rtl::OUString
> aSNL( getSupportedServiceNames() );
164 const ::rtl::OUString
* pArray
= aSNL
.getConstArray();
166 for( sal_Int32 i
= 0; i
< aSNL
.getLength(); i
++ )
167 if( pArray
[i
] == ServiceName
)
173 // ------------------------------------------------------------------------------
175 uno::Sequence
< rtl::OUString
> SAL_CALL
GraphicRendererVCL::getSupportedServiceNames()
176 throw( uno::RuntimeException
)
178 return getSupportedServiceNames_Static();
181 // ------------------------------------------------------------------------------
183 uno::Sequence
< uno::Type
> SAL_CALL
GraphicRendererVCL::getTypes()
184 throw( uno::RuntimeException
)
186 uno::Sequence
< uno::Type
> aTypes( 7 );
187 uno::Type
* pTypes
= aTypes
.getArray();
189 *pTypes
++ = ::getCppuType((const uno::Reference
< uno::XAggregation
>*)0);
190 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0);
191 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0);
192 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0);
193 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XPropertyState
>*)0);
194 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XMultiPropertySet
>*)0);
195 *pTypes
++ = ::getCppuType((const uno::Reference
< graphic::XGraphicRenderer
>*)0);
200 // ------------------------------------------------------------------------------
202 uno::Sequence
< sal_Int8
> SAL_CALL
GraphicRendererVCL::getImplementationId()
203 throw( uno::RuntimeException
)
205 vos::OGuard
aGuard( Application::GetSolarMutex() );
206 static uno::Sequence
< sal_Int8
> aId
;
208 if( aId
.getLength() == 0 )
211 rtl_createUuid( reinterpret_cast< sal_uInt8
* >( aId
.getArray() ), 0, sal_True
);
217 // ------------------------------------------------------------------------------
219 ::comphelper::PropertySetInfo
* GraphicRendererVCL::createPropertySetInfo()
221 vos::OGuard
aGuard( Application::GetSolarMutex() );
222 ::comphelper::PropertySetInfo
* pRet
= new ::comphelper::PropertySetInfo();
224 static ::comphelper::PropertyMapEntry aEntries
[] =
226 { MAP_CHAR_LEN( "Device" ), UNOGRAPHIC_DEVICE
, &::getCppuType( (const uno::Any
*)(0)), 0, 0 },
227 { MAP_CHAR_LEN( "DestinationRect" ), UNOGRAPHIC_DESTINATIONRECT
, &::getCppuType( (const awt::Rectangle
*)(0)), 0, 0 },
228 { MAP_CHAR_LEN( "RenderData" ), UNOGRAPHIC_RENDERDATA
, &::getCppuType( (const uno::Any
*)(0)), 0, 0 },
234 pRet
->add( aEntries
);
239 // ------------------------------------------------------------------------------
241 void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
242 throw( beans::UnknownPropertyException
,
243 beans::PropertyVetoException
,
244 lang::IllegalArgumentException
,
245 lang::WrappedTargetException
)
247 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
251 switch( (*ppEntries
)->mnHandle
)
253 case( UNOGRAPHIC_DEVICE
):
255 uno::Reference
< awt::XDevice
> xDevice
;
257 if( ( *pValues
>>= xDevice
) && xDevice
.is() )
260 mpOutDev
= VCLUnoHelper::GetOutputDevice( xDevice
);
270 case( UNOGRAPHIC_DESTINATIONRECT
):
272 awt::Rectangle aAWTRect
;
274 if( *pValues
>>= aAWTRect
)
276 maDestRect
= Rectangle( Point( aAWTRect
.X
, aAWTRect
.Y
),
277 Size( aAWTRect
.Width
, aAWTRect
.Height
) );
282 case( UNOGRAPHIC_RENDERDATA
):
284 *pValues
>>= maRenderData
;
294 // ------------------------------------------------------------------------------
296 void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValues
)
297 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
)
299 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
303 switch( (*ppEntries
)->mnHandle
)
305 case( UNOGRAPHIC_DEVICE
):
308 *pValues
<<= mxDevice
;
312 case( UNOGRAPHIC_DESTINATIONRECT
):
314 const awt::Rectangle
aAWTRect( maDestRect
.Left(), maDestRect
.Top(),
315 maDestRect
.GetWidth(), maDestRect
.GetHeight() );
317 *pValues
<<= aAWTRect
;
321 case( UNOGRAPHIC_RENDERDATA
):
323 *pValues
<<= maRenderData
;
333 // ------------------------------------------------------------------------------
335 void SAL_CALL
GraphicRendererVCL::render( const uno::Reference
< graphic::XGraphic
>& rxGraphic
)
336 throw (uno::RuntimeException
)
338 if( mpOutDev
&& mxDevice
.is() && rxGraphic
.is() )
340 const uno::Reference
< XInterface
> xIFace( rxGraphic
, uno::UNO_QUERY
);
341 const ::Graphic
* pGraphic
= ::unographic::Graphic::getImplementation( xIFace
);
345 GraphicObject
aGraphicObject( *pGraphic
);
346 aGraphicObject
.Draw( mpOutDev
, maDestRect
.TopLeft(), maDestRect
.GetSize() );