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 <com/sun/star/uno/XComponentContext.hpp>
25 #include <osl/mutex.hxx>
26 #include <vcl/svapp.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <comphelper/propertysetinfo.hxx>
29 #include <cppuhelper/supportsservice.hxx>
30 #include <rtl/ref.hxx>
31 #include <svl/itemprop.hxx>
32 #include <svtools/grfmgr.hxx>
33 #include <comphelper/servicehelper.hxx>
34 #include "graphic.hxx"
35 #include "renderer.hxx"
37 #define UNOGRAPHIC_DEVICE 1
38 #define UNOGRAPHIC_DESTINATIONRECT 2
39 #define UNOGRAPHIC_RENDERDATA 3
41 using namespace ::com::sun::star
;
45 GraphicRendererVCL::GraphicRendererVCL() :
46 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
53 GraphicRendererVCL::~GraphicRendererVCL()
60 uno::Any SAL_CALL
GraphicRendererVCL::queryAggregation( const uno::Type
& rType
)
61 throw( uno::RuntimeException
, std::exception
)
65 if( rType
== cppu::UnoType
<lang::XServiceInfo
>::get())
66 aAny
<<= uno::Reference
< lang::XServiceInfo
>(this);
67 else if( rType
== cppu::UnoType
<lang::XTypeProvider
>::get())
68 aAny
<<= uno::Reference
< lang::XTypeProvider
>(this);
69 else if( rType
== cppu::UnoType
<beans::XPropertySet
>::get())
70 aAny
<<= uno::Reference
< beans::XPropertySet
>(this);
71 else if( rType
== cppu::UnoType
<beans::XPropertyState
>::get())
72 aAny
<<= uno::Reference
< beans::XPropertyState
>(this);
73 else if( rType
== cppu::UnoType
<beans::XMultiPropertySet
>::get())
74 aAny
<<= uno::Reference
< beans::XMultiPropertySet
>(this);
75 else if( rType
== cppu::UnoType
<graphic::XGraphicRenderer
>::get())
76 aAny
<<= uno::Reference
< graphic::XGraphicRenderer
>(this);
78 aAny
<<= OWeakAggObject::queryAggregation( rType
);
85 uno::Any SAL_CALL
GraphicRendererVCL::queryInterface( const uno::Type
& rType
)
86 throw( uno::RuntimeException
, std::exception
)
88 return OWeakAggObject::queryInterface( rType
);
93 void SAL_CALL
GraphicRendererVCL::acquire()
96 OWeakAggObject::acquire();
101 void SAL_CALL
GraphicRendererVCL::release()
104 OWeakAggObject::release();
109 OUString SAL_CALL
GraphicRendererVCL::getImplementationName()
110 throw( uno::RuntimeException
, std::exception
)
112 return OUString( "com.sun.star.comp.graphic.GraphicRendererVCL" );
115 sal_Bool SAL_CALL
GraphicRendererVCL::supportsService( const OUString
& ServiceName
)
116 throw( uno::RuntimeException
, std::exception
)
118 return cppu::supportsService(this, ServiceName
);
123 uno::Sequence
< OUString
> SAL_CALL
GraphicRendererVCL::getSupportedServiceNames()
124 throw( uno::RuntimeException
, std::exception
)
126 uno::Sequence
< OUString
> aSeq( 1 );
127 aSeq
.getArray()[ 0 ] = "com.sun.star.graphic.GraphicRendererVCL";
133 uno::Sequence
< uno::Type
> SAL_CALL
GraphicRendererVCL::getTypes()
134 throw( uno::RuntimeException
, std::exception
)
136 uno::Sequence
< uno::Type
> aTypes( 7 );
137 uno::Type
* pTypes
= aTypes
.getArray();
139 *pTypes
++ = cppu::UnoType
<uno::XAggregation
>::get();
140 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
141 *pTypes
++ = cppu::UnoType
<lang::XTypeProvider
>::get();
142 *pTypes
++ = cppu::UnoType
<beans::XPropertySet
>::get();
143 *pTypes
++ = cppu::UnoType
<beans::XPropertyState
>::get();
144 *pTypes
++ = cppu::UnoType
<beans::XMultiPropertySet
>::get();
145 *pTypes
++ = cppu::UnoType
<graphic::XGraphicRenderer
>::get();
150 uno::Sequence
< sal_Int8
> SAL_CALL
GraphicRendererVCL::getImplementationId()
151 throw( uno::RuntimeException
, std::exception
)
153 return css::uno::Sequence
<sal_Int8
>();
158 ::comphelper::PropertySetInfo
* GraphicRendererVCL::createPropertySetInfo()
160 SolarMutexGuard aGuard
;
161 ::comphelper::PropertySetInfo
* pRet
= new ::comphelper::PropertySetInfo();
163 static ::comphelper::PropertyMapEntry
const aEntries
[] =
165 { OUString("Device"), UNOGRAPHIC_DEVICE
, cppu::UnoType
<uno::Any
>::get(), 0, 0 },
166 { OUString("DestinationRect"), UNOGRAPHIC_DESTINATIONRECT
, cppu::UnoType
<awt::Rectangle
>::get(), 0, 0 },
167 { OUString("RenderData"), UNOGRAPHIC_RENDERDATA
, cppu::UnoType
<uno::Any
>::get(), 0, 0 },
168 { OUString(), 0, css::uno::Type(), 0, 0 }
172 pRet
->add( aEntries
);
179 void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, const uno::Any
* pValues
)
180 throw( beans::UnknownPropertyException
,
181 beans::PropertyVetoException
,
182 lang::IllegalArgumentException
,
183 lang::WrappedTargetException
)
185 SolarMutexGuard aGuard
;
189 switch( (*ppEntries
)->mnHandle
)
191 case( UNOGRAPHIC_DEVICE
):
193 uno::Reference
< awt::XDevice
> xDevice
;
195 if( ( *pValues
>>= xDevice
) && xDevice
.is() )
198 mpOutDev
= VCLUnoHelper::GetOutputDevice( xDevice
);
208 case( UNOGRAPHIC_DESTINATIONRECT
):
210 awt::Rectangle aAWTRect
;
212 if( *pValues
>>= aAWTRect
)
214 maDestRect
= Rectangle( Point( aAWTRect
.X
, aAWTRect
.Y
),
215 Size( aAWTRect
.Width
, aAWTRect
.Height
) );
220 case( UNOGRAPHIC_RENDERDATA
):
222 *pValues
>>= maRenderData
;
234 void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry
** ppEntries
, uno::Any
* pValues
)
235 throw( beans::UnknownPropertyException
, lang::WrappedTargetException
)
237 SolarMutexGuard aGuard
;
241 switch( (*ppEntries
)->mnHandle
)
243 case( UNOGRAPHIC_DEVICE
):
246 *pValues
<<= mxDevice
;
250 case( UNOGRAPHIC_DESTINATIONRECT
):
252 const awt::Rectangle
aAWTRect( maDestRect
.Left(), maDestRect
.Top(),
253 maDestRect
.GetWidth(), maDestRect
.GetHeight() );
255 *pValues
<<= aAWTRect
;
259 case( UNOGRAPHIC_RENDERDATA
):
261 *pValues
<<= maRenderData
;
273 void SAL_CALL
GraphicRendererVCL::render( const uno::Reference
< graphic::XGraphic
>& rxGraphic
)
274 throw (uno::RuntimeException
, std::exception
)
276 if( mpOutDev
&& mxDevice
.is() && rxGraphic
.is() )
278 const uno::Reference
< XInterface
> xIFace( rxGraphic
, uno::UNO_QUERY
);
279 const ::Graphic
* pGraphic
= ::unographic::Graphic::getImplementation( xIFace
);
283 GraphicObject
aGraphicObject( *pGraphic
);
284 aGraphicObject
.Draw( mpOutDev
, maDestRect
.TopLeft(), maDestRect
.GetSize() );
291 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
292 com_sun_star_comp_graphic_GraphicRendererVCL_get_implementation(
293 css::uno::XComponentContext
*,
294 css::uno::Sequence
<css::uno::Any
> const &)
296 return cppu::acquire(new GraphicRendererVCL
);
299 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */