1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/beans/PropertyState.hpp>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <com/sun/star/awt/Rectangle.hpp>
24 #include <osl/mutex.hxx>
25 #include <vcl/svapp.hxx>
26 #include <toolkit/helper/vclunohelper.hxx>
27 #include <comphelper/propertysetinfo.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <svl/itemprop.hxx>
30 #include <svtools/grfmgr.hxx>
31 #include <comphelper/servicehelper.hxx>
32 #include "graphic.hxx"
33 #include "renderer.hxx"
35 #define UNOGRAPHIC_DEVICE 1
36 #define UNOGRAPHIC_DESTINATIONRECT 2
37 #define UNOGRAPHIC_RENDERDATA 3
39 using namespace ::com::sun::star
;
41 namespace unographic
{
43 // ---------------------
44 // - GraphicRendererVCL -
45 // ---------------------
47 uno::Reference
< uno::XInterface
> SAL_CALL
GraphicRendererVCL_CreateInstance( const uno::Reference
< lang::XMultiServiceFactory
>& )
49 return (static_cast< ::cppu::OWeakObject
* >(new GraphicRendererVCL
));
53 GraphicRendererVCL::GraphicRendererVCL() :
54 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
59 // ------------------------------------------------------------------------------
61 GraphicRendererVCL::~GraphicRendererVCL()
66 // ------------------------------------------------------------------------------
68 OUString
GraphicRendererVCL::getImplementationName_Static()
71 return OUString( "com.sun.star.comp.graphic.GraphicRendererVCL" );
74 // ------------------------------------------------------------------------------
76 uno::Sequence
< OUString
> GraphicRendererVCL::getSupportedServiceNames_Static()
79 uno::Sequence
< OUString
> aSeq( 1 );
81 aSeq
.getArray()[ 0 ] = "com.sun.star.graphic.GraphicRendererVCL";
86 // ------------------------------------------------------------------------------
88 uno::Any SAL_CALL
GraphicRendererVCL::queryAggregation( const uno::Type
& rType
)
89 throw( uno::RuntimeException
)
93 if( rType
== ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0) )
94 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
95 else if( rType
== ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0) )
96 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
97 else if( rType
== ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0) )
98 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
99 else if( rType
== ::getCppuType((const uno::Reference
< beans::XPropertyState
>*)0) )
100 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
101 else if( rType
== ::getCppuType((const uno::Reference
< beans::XMultiPropertySet
>*)0) )
102 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
103 else if( rType
== ::getCppuType((const uno::Reference
< graphic::XGraphicRenderer
>*)0) )
104 aAny
<<= uno::Reference
< graphic::XGraphicRenderer
>(this);
106 aAny
<<= OWeakAggObject::queryAggregation( rType
);
111 // ------------------------------------------------------------------------------
113 uno::Any SAL_CALL
GraphicRendererVCL::queryInterface( const uno::Type
& rType
)
114 throw( uno::RuntimeException
)
116 return OWeakAggObject::queryInterface( rType
);
119 // ------------------------------------------------------------------------------
121 void SAL_CALL
GraphicRendererVCL::acquire()
124 OWeakAggObject::acquire();
127 // ------------------------------------------------------------------------------
129 void SAL_CALL
GraphicRendererVCL::release()
132 OWeakAggObject::release();
135 // ------------------------------------------------------------------------------
137 OUString SAL_CALL
GraphicRendererVCL::getImplementationName()
138 throw( uno::RuntimeException
)
140 return getImplementationName_Static();
143 sal_Bool SAL_CALL
GraphicRendererVCL::supportsService( const OUString
& ServiceName
)
144 throw( uno::RuntimeException
)
146 return cppu::supportsService(this, ServiceName
);
149 // ------------------------------------------------------------------------------
151 uno::Sequence
< OUString
> SAL_CALL
GraphicRendererVCL::getSupportedServiceNames()
152 throw( uno::RuntimeException
)
154 return getSupportedServiceNames_Static();
157 // ------------------------------------------------------------------------------
159 uno::Sequence
< uno::Type
> SAL_CALL
GraphicRendererVCL::getTypes()
160 throw( uno::RuntimeException
)
162 uno::Sequence
< uno::Type
> aTypes( 7 );
163 uno::Type
* pTypes
= aTypes
.getArray();
165 *pTypes
++ = ::getCppuType((const uno::Reference
< uno::XAggregation
>*)0);
166 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XServiceInfo
>*)0);
167 *pTypes
++ = ::getCppuType((const uno::Reference
< lang::XTypeProvider
>*)0);
168 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XPropertySet
>*)0);
169 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XPropertyState
>*)0);
170 *pTypes
++ = ::getCppuType((const uno::Reference
< beans::XMultiPropertySet
>*)0);
171 *pTypes
++ = ::getCppuType((const uno::Reference
< graphic::XGraphicRenderer
>*)0);
178 class theGraphicRendererVCLUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theGraphicRendererVCLUnoTunnelId
> {};
181 uno::Sequence
< sal_Int8
> SAL_CALL
GraphicRendererVCL::getImplementationId()
182 throw( uno::RuntimeException
)
184 return theGraphicRendererVCLUnoTunnelId::get().getSeq();
187 // ------------------------------------------------------------------------------
189 ::comphelper::PropertySetInfo
* GraphicRendererVCL::createPropertySetInfo()
191 SolarMutexGuard aGuard
;
192 ::comphelper::PropertySetInfo
* pRet
= new ::comphelper::PropertySetInfo();
194 static ::comphelper::PropertyMapEntry aEntries
[] =
196 { MAP_CHAR_LEN( "Device" ), UNOGRAPHIC_DEVICE
, &::getCppuType( (const uno::Any
*)(0)), 0, 0 },
197 { MAP_CHAR_LEN( "DestinationRect" ), UNOGRAPHIC_DESTINATIONRECT
, &::getCppuType( (const awt::Rectangle
*)(0)), 0, 0 },
198 { MAP_CHAR_LEN( "RenderData" ), UNOGRAPHIC_RENDERDATA
, &::getCppuType( (const uno::Any
*)(0)), 0, 0 },
204 pRet
->add( aEntries
);
209 // ------------------------------------------------------------------------------
211 void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
212 throw( beans::UnknownPropertyException
,
213 beans::PropertyVetoException
,
214 lang::IllegalArgumentException
,
215 lang::WrappedTargetException
)
217 SolarMutexGuard aGuard
;
221 switch( (*ppEntries
)->mnHandle
)
223 case( UNOGRAPHIC_DEVICE
):
225 uno::Reference
< awt::XDevice
> xDevice
;
227 if( ( *pValues
>>= xDevice
) && xDevice
.is() )
230 mpOutDev
= VCLUnoHelper::GetOutputDevice( xDevice
);
240 case( UNOGRAPHIC_DESTINATIONRECT
):
242 awt::Rectangle aAWTRect
;
244 if( *pValues
>>= aAWTRect
)
246 maDestRect
= Rectangle( Point( aAWTRect
.X
, aAWTRect
.Y
),
247 Size( aAWTRect
.Width
, aAWTRect
.Height
) );
252 case( UNOGRAPHIC_RENDERDATA
):
254 *pValues
>>= maRenderData
;
264 // ------------------------------------------------------------------------------
266 void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValues
)
267 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
)
269 SolarMutexGuard aGuard
;
273 switch( (*ppEntries
)->mnHandle
)
275 case( UNOGRAPHIC_DEVICE
):
278 *pValues
<<= mxDevice
;
282 case( UNOGRAPHIC_DESTINATIONRECT
):
284 const awt::Rectangle
aAWTRect( maDestRect
.Left(), maDestRect
.Top(),
285 maDestRect
.GetWidth(), maDestRect
.GetHeight() );
287 *pValues
<<= aAWTRect
;
291 case( UNOGRAPHIC_RENDERDATA
):
293 *pValues
<<= maRenderData
;
303 // ------------------------------------------------------------------------------
305 void SAL_CALL
GraphicRendererVCL::render( const uno::Reference
< graphic::XGraphic
>& rxGraphic
)
306 throw (uno::RuntimeException
)
308 if( mpOutDev
&& mxDevice
.is() && rxGraphic
.is() )
310 const uno::Reference
< XInterface
> xIFace( rxGraphic
, uno::UNO_QUERY
);
311 const ::Graphic
* pGraphic
= ::unographic::Graphic::getImplementation( xIFace
);
315 GraphicObject
aGraphicObject( *pGraphic
);
316 aGraphicObject
.Draw( mpOutDev
, maDestRect
.TopLeft(), maDestRect
.GetSize() );
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */