Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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 <rtl/ref.hxx>
30 : #include <svl/itemprop.hxx>
31 : #include <svtools/grfmgr.hxx>
32 : #include <comphelper/servicehelper.hxx>
33 : #include "graphic.hxx"
34 : #include "renderer.hxx"
35 :
36 : #define UNOGRAPHIC_DEVICE 1
37 : #define UNOGRAPHIC_DESTINATIONRECT 2
38 : #define UNOGRAPHIC_RENDERDATA 3
39 :
40 : using namespace ::com::sun::star;
41 :
42 : namespace {
43 :
44 0 : GraphicRendererVCL::GraphicRendererVCL() :
45 : ::comphelper::PropertySetHelper( createPropertySetInfo() ),
46 0 : mpOutDev( NULL )
47 : {
48 0 : }
49 :
50 :
51 :
52 0 : GraphicRendererVCL::~GraphicRendererVCL()
53 0 : throw()
54 : {
55 0 : }
56 :
57 :
58 :
59 0 : uno::Any SAL_CALL GraphicRendererVCL::queryAggregation( const uno::Type & rType )
60 : throw( uno::RuntimeException, std::exception )
61 : {
62 0 : uno::Any aAny;
63 :
64 0 : if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
65 0 : aAny <<= uno::Reference< lang::XServiceInfo >(this);
66 0 : else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
67 0 : aAny <<= uno::Reference< lang::XTypeProvider >(this);
68 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
69 0 : aAny <<= uno::Reference< beans::XPropertySet >(this);
70 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
71 0 : aAny <<= uno::Reference< beans::XPropertyState >(this);
72 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
73 0 : aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
74 0 : else if( rType == ::getCppuType((const uno::Reference< graphic::XGraphicRenderer >*)0) )
75 0 : aAny <<= uno::Reference< graphic::XGraphicRenderer >(this);
76 : else
77 0 : aAny <<= OWeakAggObject::queryAggregation( rType );
78 :
79 0 : return aAny;
80 : }
81 :
82 :
83 :
84 0 : uno::Any SAL_CALL GraphicRendererVCL::queryInterface( const uno::Type & rType )
85 : throw( uno::RuntimeException, std::exception )
86 : {
87 0 : return OWeakAggObject::queryInterface( rType );
88 : }
89 :
90 :
91 :
92 0 : void SAL_CALL GraphicRendererVCL::acquire()
93 : throw()
94 : {
95 0 : OWeakAggObject::acquire();
96 0 : }
97 :
98 :
99 :
100 0 : void SAL_CALL GraphicRendererVCL::release()
101 : throw()
102 : {
103 0 : OWeakAggObject::release();
104 0 : }
105 :
106 :
107 :
108 0 : OUString SAL_CALL GraphicRendererVCL::getImplementationName()
109 : throw( uno::RuntimeException, std::exception )
110 : {
111 0 : return OUString( "com.sun.star.comp.graphic.GraphicRendererVCL" );
112 : }
113 :
114 0 : sal_Bool SAL_CALL GraphicRendererVCL::supportsService( const OUString& ServiceName )
115 : throw( uno::RuntimeException, std::exception )
116 : {
117 0 : return cppu::supportsService(this, ServiceName);
118 : }
119 :
120 :
121 :
122 0 : uno::Sequence< OUString > SAL_CALL GraphicRendererVCL::getSupportedServiceNames()
123 : throw( uno::RuntimeException, std::exception )
124 : {
125 0 : uno::Sequence< OUString > aSeq( 1 );
126 0 : aSeq.getArray()[ 0 ] = "com.sun.star.graphic.GraphicRendererVCL";
127 0 : return aSeq;
128 : }
129 :
130 :
131 :
132 0 : uno::Sequence< uno::Type > SAL_CALL GraphicRendererVCL::getTypes()
133 : throw( uno::RuntimeException, std::exception )
134 : {
135 0 : uno::Sequence< uno::Type > aTypes( 7 );
136 0 : uno::Type* pTypes = aTypes.getArray();
137 :
138 0 : *pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
139 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
140 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
141 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
142 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
143 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
144 0 : *pTypes++ = ::getCppuType((const uno::Reference< graphic::XGraphicRenderer>*)0);
145 :
146 0 : return aTypes;
147 : }
148 :
149 0 : uno::Sequence< sal_Int8 > SAL_CALL GraphicRendererVCL::getImplementationId()
150 : throw( uno::RuntimeException, std::exception )
151 : {
152 0 : return css::uno::Sequence<sal_Int8>();
153 : }
154 :
155 :
156 :
157 0 : ::comphelper::PropertySetInfo* GraphicRendererVCL::createPropertySetInfo()
158 : {
159 0 : SolarMutexGuard aGuard;
160 0 : ::comphelper::PropertySetInfo* pRet = new ::comphelper::PropertySetInfo();
161 :
162 : static ::comphelper::PropertyMapEntry const aEntries[] =
163 : {
164 0 : { OUString("Device"), UNOGRAPHIC_DEVICE, ::getCppuType( (const uno::Any*)(0)), 0, 0 },
165 0 : { OUString("DestinationRect"), UNOGRAPHIC_DESTINATIONRECT, ::getCppuType( (const awt::Rectangle*)(0)), 0, 0 },
166 0 : { OUString("RenderData"), UNOGRAPHIC_RENDERDATA, ::getCppuType( (const uno::Any*)(0)), 0, 0 },
167 : { OUString(), 0, css::uno::Type(), 0, 0 }
168 0 : };
169 :
170 0 : pRet->acquire();
171 0 : pRet->add( aEntries );
172 :
173 0 : return pRet;
174 : }
175 :
176 :
177 :
178 0 : void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
179 : throw( beans::UnknownPropertyException,
180 : beans::PropertyVetoException,
181 : lang::IllegalArgumentException,
182 : lang::WrappedTargetException )
183 : {
184 0 : SolarMutexGuard aGuard;
185 :
186 0 : while( *ppEntries )
187 : {
188 0 : switch( (*ppEntries)->mnHandle )
189 : {
190 : case( UNOGRAPHIC_DEVICE ):
191 : {
192 0 : uno::Reference< awt::XDevice > xDevice;
193 :
194 0 : if( ( *pValues >>= xDevice ) && xDevice.is() )
195 : {
196 0 : mxDevice = xDevice;
197 0 : mpOutDev = VCLUnoHelper::GetOutputDevice( xDevice );
198 : }
199 : else
200 : {
201 0 : mxDevice.clear();
202 0 : mpOutDev = NULL;
203 0 : }
204 : }
205 0 : break;
206 :
207 : case( UNOGRAPHIC_DESTINATIONRECT ):
208 : {
209 0 : awt::Rectangle aAWTRect;
210 :
211 0 : if( *pValues >>= aAWTRect )
212 : {
213 : maDestRect = Rectangle( Point( aAWTRect.X, aAWTRect.Y ),
214 0 : Size( aAWTRect.Width, aAWTRect.Height ) );
215 : }
216 : }
217 0 : break;
218 :
219 : case( UNOGRAPHIC_RENDERDATA ):
220 : {
221 0 : *pValues >>= maRenderData;
222 : }
223 0 : break;
224 : }
225 :
226 0 : ++ppEntries;
227 0 : ++pValues;
228 0 : }
229 0 : }
230 :
231 :
232 :
233 0 : void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValues )
234 : throw( beans::UnknownPropertyException, lang::WrappedTargetException )
235 : {
236 0 : SolarMutexGuard aGuard;
237 :
238 0 : while( *ppEntries )
239 : {
240 0 : switch( (*ppEntries)->mnHandle )
241 : {
242 : case( UNOGRAPHIC_DEVICE ):
243 : {
244 0 : if( mxDevice.is() )
245 0 : *pValues <<= mxDevice;
246 : }
247 0 : break;
248 :
249 : case( UNOGRAPHIC_DESTINATIONRECT ):
250 : {
251 0 : const awt::Rectangle aAWTRect( maDestRect.Left(), maDestRect.Top(),
252 0 : maDestRect.GetWidth(), maDestRect.GetHeight() );
253 :
254 0 : *pValues <<= aAWTRect;
255 : }
256 0 : break;
257 :
258 : case( UNOGRAPHIC_RENDERDATA ):
259 : {
260 0 : *pValues <<= maRenderData;
261 : }
262 0 : break;
263 : }
264 :
265 0 : ++ppEntries;
266 0 : ++pValues;
267 0 : }
268 0 : }
269 :
270 :
271 :
272 0 : void SAL_CALL GraphicRendererVCL::render( const uno::Reference< graphic::XGraphic >& rxGraphic )
273 : throw (uno::RuntimeException, std::exception)
274 : {
275 0 : if( mpOutDev && mxDevice.is() && rxGraphic.is() )
276 : {
277 0 : const uno::Reference< XInterface > xIFace( rxGraphic, uno::UNO_QUERY );
278 0 : const ::Graphic* pGraphic = ::unographic::Graphic::getImplementation( xIFace );
279 :
280 0 : if( pGraphic )
281 : {
282 0 : GraphicObject aGraphicObject( *pGraphic );
283 0 : aGraphicObject.Draw( mpOutDev, maDestRect.TopLeft(), maDestRect.GetSize() );
284 0 : }
285 : }
286 0 : }
287 :
288 : }
289 :
290 : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
291 0 : com_sun_star_comp_graphic_GraphicRendererVCL_get_implementation(
292 : css::uno::XComponentContext *,
293 : css::uno::Sequence<css::uno::Any> const &)
294 : {
295 0 : return cppu::acquire(new GraphicRendererVCL);
296 : }
297 :
298 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|