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/awt/Rectangle.hpp>
22 #include <com/sun/star/awt/XDevice.hpp>
23 #include <com/sun/star/graphic/XGraphic.hpp>
24 #include <com/sun/star/graphic/XGraphicRenderer.hpp>
25 #include <com/sun/star/lang/XServiceInfo.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <tools/gen.hxx>
28 #include <vcl/svapp.hxx>
29 #include <toolkit/helper/vclunohelper.hxx>
30 #include <comphelper/propertysethelper.hxx>
31 #include <comphelper/propertysetinfo.hxx>
32 #include <cppuhelper/supportsservice.hxx>
33 #include <rtl/ref.hxx>
34 #include <vcl/GraphicObject.hxx>
35 #include <vcl/outdev.hxx>
37 #define UNOGRAPHIC_DEVICE 1
38 #define UNOGRAPHIC_DESTINATIONRECT 2
39 #define UNOGRAPHIC_RENDERDATA 3
41 using namespace ::com::sun::star
;
45 class GraphicRendererVCL
: public ::cppu::OWeakObject
,
46 public css::lang::XServiceInfo
,
47 public css::lang::XTypeProvider
,
48 public ::comphelper::PropertySetHelper
,
49 public css::graphic::XGraphicRenderer
51 static rtl::Reference
<::comphelper::PropertySetInfo
> createPropertySetInfo();
58 virtual css::uno::Any SAL_CALL
queryInterface( const css::uno::Type
& rType
) override
;
59 virtual void SAL_CALL
acquire() noexcept override
;
60 virtual void SAL_CALL
release() noexcept override
;
63 virtual OUString SAL_CALL
getImplementationName() override
;
64 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
65 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
68 virtual css::uno::Sequence
< css::uno::Type
> SAL_CALL
getTypes( ) override
;
69 virtual css::uno::Sequence
< sal_Int8
> SAL_CALL
getImplementationId( ) override
;
72 virtual void _setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const css::uno::Any
* pValues
) override
;
73 virtual void _getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, css::uno::Any
* pValue
) override
;
76 virtual void SAL_CALL
render( const css::uno::Reference
< css::graphic::XGraphic
>& Graphic
) override
;
80 css::uno::Reference
< css::awt::XDevice
> mxDevice
;
82 VclPtr
<OutputDevice
> mpOutDev
;
83 tools::Rectangle maDestRect
;
84 css::uno::Any maRenderData
;
87 GraphicRendererVCL::GraphicRendererVCL() :
88 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
93 uno::Any SAL_CALL
GraphicRendererVCL::queryInterface( const uno::Type
& rType
)
97 if( rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
98 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
99 else if( rType
== cppu::UnoType
<lang::XTypeProvider
>::get())
100 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
101 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
102 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
103 else if( rType
== cppu::UnoType
<beans::XPropertyState
>::get())
104 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
105 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
106 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
107 else if( rType
== cppu::UnoType
<graphic::XGraphicRenderer
>::get())
108 aAny
<<= uno::Reference
< graphic::XGraphicRenderer
>(this);
110 aAny
= OWeakObject::queryInterface( rType
);
116 void SAL_CALL
GraphicRendererVCL::acquire()
119 OWeakObject::acquire();
123 void SAL_CALL
GraphicRendererVCL::release()
126 OWeakObject::release();
130 OUString SAL_CALL
GraphicRendererVCL::getImplementationName()
132 return u
"com.sun.star.comp.graphic.GraphicRendererVCL"_ustr
;
135 sal_Bool SAL_CALL
GraphicRendererVCL::supportsService( const OUString
& ServiceName
)
137 return cppu::supportsService(this, ServiceName
);
141 uno::Sequence
< OUString
> SAL_CALL
GraphicRendererVCL::getSupportedServiceNames()
143 return { u
"com.sun.star.graphic.GraphicRendererVCL"_ustr
};
147 uno::Sequence
< uno::Type
> SAL_CALL
GraphicRendererVCL::getTypes()
149 static const uno::Sequence
< uno::Type
> aTypes
{
150 cppu::UnoType
<lang::XServiceInfo
>::get(),
151 cppu::UnoType
<lang::XTypeProvider
>::get(),
152 cppu::UnoType
<beans::XPropertySet
>::get(),
153 cppu::UnoType
<beans::XPropertyState
>::get(),
154 cppu::UnoType
<beans::XMultiPropertySet
>::get(),
155 cppu::UnoType
<graphic::XGraphicRenderer
>::get() };
159 uno::Sequence
< sal_Int8
> SAL_CALL
GraphicRendererVCL::getImplementationId()
161 return css::uno::Sequence
<sal_Int8
>();
165 rtl::Reference
<::comphelper::PropertySetInfo
> GraphicRendererVCL::createPropertySetInfo()
167 static ::comphelper::PropertyMapEntry
const aEntries
[] =
169 { u
"Device"_ustr
, UNOGRAPHIC_DEVICE
, cppu::UnoType
<uno::Any
>::get(), 0, 0 },
170 { u
"DestinationRect"_ustr
, UNOGRAPHIC_DESTINATIONRECT
, cppu::UnoType
<awt::Rectangle
>::get(), 0, 0 },
171 { u
"RenderData"_ustr
, UNOGRAPHIC_RENDERDATA
, cppu::UnoType
<uno::Any
>::get(), 0, 0 },
174 return rtl::Reference
<::comphelper::PropertySetInfo
>( new ::comphelper::PropertySetInfo(aEntries
) );
178 void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
180 SolarMutexGuard aGuard
;
184 switch( (*ppEntries
)->mnHandle
)
186 case UNOGRAPHIC_DEVICE
:
188 uno::Reference
< awt::XDevice
> xDevice
;
190 if( ( *pValues
>>= xDevice
) && xDevice
.is() )
193 mpOutDev
= VCLUnoHelper::GetOutputDevice( xDevice
);
203 case UNOGRAPHIC_DESTINATIONRECT
:
205 awt::Rectangle aAWTRect
;
207 if( *pValues
>>= aAWTRect
)
209 maDestRect
= tools::Rectangle( Point( aAWTRect
.X
, aAWTRect
.Y
),
210 Size( aAWTRect
.Width
, aAWTRect
.Height
) );
215 case UNOGRAPHIC_RENDERDATA
:
217 maRenderData
= *pValues
;
228 void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValues
)
230 SolarMutexGuard aGuard
;
234 switch( (*ppEntries
)->mnHandle
)
236 case UNOGRAPHIC_DEVICE
:
239 *pValues
<<= mxDevice
;
243 case UNOGRAPHIC_DESTINATIONRECT
:
245 const awt::Rectangle
aAWTRect( maDestRect
.Left(), maDestRect
.Top(),
246 maDestRect
.GetWidth(), maDestRect
.GetHeight() );
248 *pValues
<<= aAWTRect
;
252 case UNOGRAPHIC_RENDERDATA
:
254 *pValues
= maRenderData
;
264 void SAL_CALL
GraphicRendererVCL::render( const uno::Reference
< graphic::XGraphic
>& rxGraphic
)
266 if( mpOutDev
&& mxDevice
.is() && rxGraphic
.is() )
268 Graphic
aGraphic(rxGraphic
);
269 if (!aGraphic
.IsNone())
271 GraphicObject
aGraphicObject(std::move(aGraphic
));
272 aGraphicObject
.Draw(*mpOutDev
, maDestRect
.TopLeft(), maDestRect
.GetSize());
279 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
280 com_sun_star_comp_graphic_GraphicRendererVCL_get_implementation(
281 css::uno::XComponentContext
*,
282 css::uno::Sequence
<css::uno::Any
> const &)
284 return cppu::acquire(new GraphicRendererVCL
);
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */