Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <com/sun/star/beans/PropertyState.hpp>
31 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
32 : : #include <com/sun/star/awt/Rectangle.hpp>
33 : : #include <osl/mutex.hxx>
34 : : #include <vcl/svapp.hxx>
35 : : #include <toolkit/helper/vclunohelper.hxx>
36 : : #include <comphelper/propertysetinfo.hxx>
37 : : #include <svl/itemprop.hxx>
38 : : #include <svtools/grfmgr.hxx>
39 : : #include <comphelper/servicehelper.hxx>
40 : : #include "graphic.hxx"
41 : : #include "renderer.hxx"
42 : :
43 : : #define UNOGRAPHIC_DEVICE 1
44 : : #define UNOGRAPHIC_DESTINATIONRECT 2
45 : : #define UNOGRAPHIC_RENDERDATA 3
46 : :
47 : : using namespace ::com::sun::star;
48 : :
49 : : namespace unographic {
50 : :
51 : : // ---------------------
52 : : // - GraphicRendererVCL -
53 : : // ---------------------
54 : :
55 : 0 : uno::Reference< uno::XInterface > SAL_CALL GraphicRendererVCL_CreateInstance( const uno::Reference< lang::XMultiServiceFactory >& )
56 : : {
57 [ # # ]: 0 : return (static_cast< ::cppu::OWeakObject* >(new GraphicRendererVCL ));
58 : : }
59 : :
60 : :
61 : 0 : GraphicRendererVCL::GraphicRendererVCL() :
62 : : ::comphelper::PropertySetHelper( createPropertySetInfo() ),
63 [ # # ][ # # ]: 0 : mpOutDev( NULL )
64 : : {
65 : 0 : }
66 : :
67 : : // ------------------------------------------------------------------------------
68 : :
69 : 0 : GraphicRendererVCL::~GraphicRendererVCL()
70 : 0 : throw()
71 : : {
72 [ # # ]: 0 : }
73 : :
74 : : // ------------------------------------------------------------------------------
75 : :
76 : 11 : ::rtl::OUString GraphicRendererVCL::getImplementationName_Static()
77 : : throw()
78 : : {
79 : 11 : return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.GraphicRendererVCL" ) );
80 : : }
81 : :
82 : : // ------------------------------------------------------------------------------
83 : :
84 : 0 : uno::Sequence< ::rtl::OUString > GraphicRendererVCL::getSupportedServiceNames_Static()
85 : : throw( )
86 : : {
87 : 0 : uno::Sequence< ::rtl::OUString > aSeq( 1 );
88 : :
89 [ # # ][ # # ]: 0 : aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicRendererVCL" ) );
90 : :
91 : 0 : return aSeq;
92 : : }
93 : :
94 : : // ------------------------------------------------------------------------------
95 : :
96 : 0 : uno::Any SAL_CALL GraphicRendererVCL::queryAggregation( const uno::Type & rType )
97 : : throw( uno::RuntimeException )
98 : : {
99 : 0 : uno::Any aAny;
100 : :
101 [ # # ][ # # ]: 0 : if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
102 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< lang::XServiceInfo >(this);
103 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
104 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< lang::XTypeProvider >(this);
105 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
106 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< beans::XPropertySet >(this);
107 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
108 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< beans::XPropertyState >(this);
109 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
110 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
111 [ # # ][ # # ]: 0 : else if( rType == ::getCppuType((const uno::Reference< graphic::XGraphicRenderer >*)0) )
112 [ # # ][ # # ]: 0 : aAny <<= uno::Reference< graphic::XGraphicRenderer >(this);
113 : : else
114 [ # # ][ # # ]: 0 : aAny <<= OWeakAggObject::queryAggregation( rType );
115 : :
116 : 0 : return aAny;
117 : : }
118 : :
119 : : // ------------------------------------------------------------------------------
120 : :
121 : 0 : uno::Any SAL_CALL GraphicRendererVCL::queryInterface( const uno::Type & rType )
122 : : throw( uno::RuntimeException )
123 : : {
124 : 0 : return OWeakAggObject::queryInterface( rType );
125 : : }
126 : :
127 : : // ------------------------------------------------------------------------------
128 : :
129 : 0 : void SAL_CALL GraphicRendererVCL::acquire()
130 : : throw()
131 : : {
132 : 0 : OWeakAggObject::acquire();
133 : 0 : }
134 : :
135 : : // ------------------------------------------------------------------------------
136 : :
137 : 0 : void SAL_CALL GraphicRendererVCL::release()
138 : : throw()
139 : : {
140 : 0 : OWeakAggObject::release();
141 : 0 : }
142 : :
143 : : // ------------------------------------------------------------------------------
144 : :
145 : 0 : ::rtl::OUString SAL_CALL GraphicRendererVCL::getImplementationName()
146 : : throw( uno::RuntimeException )
147 : : {
148 : 0 : return getImplementationName_Static();
149 : : }
150 : :
151 : : // ------------------------------------------------------------------------------
152 : :
153 : 0 : sal_Bool SAL_CALL GraphicRendererVCL::supportsService( const rtl::OUString& ServiceName )
154 : : throw( uno::RuntimeException )
155 : : {
156 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
157 : 0 : const ::rtl::OUString* pArray = aSNL.getConstArray();
158 : :
159 [ # # ]: 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
160 [ # # ]: 0 : if( pArray[i] == ServiceName )
161 : 0 : return true;
162 : :
163 [ # # ]: 0 : return false;
164 : : }
165 : :
166 : : // ------------------------------------------------------------------------------
167 : :
168 : 0 : uno::Sequence< rtl::OUString > SAL_CALL GraphicRendererVCL::getSupportedServiceNames()
169 : : throw( uno::RuntimeException )
170 : : {
171 : 0 : return getSupportedServiceNames_Static();
172 : : }
173 : :
174 : : // ------------------------------------------------------------------------------
175 : :
176 : 0 : uno::Sequence< uno::Type > SAL_CALL GraphicRendererVCL::getTypes()
177 : : throw( uno::RuntimeException )
178 : : {
179 : 0 : uno::Sequence< uno::Type > aTypes( 7 );
180 [ # # ]: 0 : uno::Type* pTypes = aTypes.getArray();
181 : :
182 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
183 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
184 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
185 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
186 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
187 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
188 [ # # ]: 0 : *pTypes++ = ::getCppuType((const uno::Reference< graphic::XGraphicRenderer>*)0);
189 : :
190 : 0 : return aTypes;
191 : : }
192 : :
193 : : namespace
194 : : {
195 : : class theGraphicRendererVCLUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theGraphicRendererVCLUnoTunnelId > {};
196 : : }
197 : :
198 : 0 : uno::Sequence< sal_Int8 > SAL_CALL GraphicRendererVCL::getImplementationId()
199 : : throw( uno::RuntimeException )
200 : : {
201 : 0 : return theGraphicRendererVCLUnoTunnelId::get().getSeq();
202 : : }
203 : :
204 : : // ------------------------------------------------------------------------------
205 : :
206 : 0 : ::comphelper::PropertySetInfo* GraphicRendererVCL::createPropertySetInfo()
207 : : {
208 [ # # ]: 0 : SolarMutexGuard aGuard;
209 : 0 : ::comphelper::PropertySetInfo* pRet = new ::comphelper::PropertySetInfo();
210 : :
211 : : static ::comphelper::PropertyMapEntry aEntries[] =
212 : : {
213 [ # # ]: 0 : { MAP_CHAR_LEN( "Device" ), UNOGRAPHIC_DEVICE, &::getCppuType( (const uno::Any*)(0)), 0, 0 },
214 [ # # ]: 0 : { MAP_CHAR_LEN( "DestinationRect" ), UNOGRAPHIC_DESTINATIONRECT, &::getCppuType( (const awt::Rectangle*)(0)), 0, 0 },
215 [ # # ]: 0 : { MAP_CHAR_LEN( "RenderData" ), UNOGRAPHIC_RENDERDATA, &::getCppuType( (const uno::Any*)(0)), 0, 0 },
216 : :
217 : : { 0,0,0,0,0,0 }
218 [ # # ][ # # ]: 0 : };
[ # # ]
219 : :
220 : 0 : pRet->acquire();
221 : 0 : pRet->add( aEntries );
222 : :
223 [ # # ]: 0 : return pRet;
224 : : }
225 : :
226 : : // ------------------------------------------------------------------------------
227 : :
228 : 0 : void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
229 : : throw( beans::UnknownPropertyException,
230 : : beans::PropertyVetoException,
231 : : lang::IllegalArgumentException,
232 : : lang::WrappedTargetException )
233 : : {
234 [ # # ]: 0 : SolarMutexGuard aGuard;
235 : :
236 [ # # ]: 0 : while( *ppEntries )
237 : : {
238 [ # # # # ]: 0 : switch( (*ppEntries)->mnHandle )
239 : : {
240 : : case( UNOGRAPHIC_DEVICE ):
241 : : {
242 : 0 : uno::Reference< awt::XDevice > xDevice;
243 : :
244 [ # # ][ # # ]: 0 : if( ( *pValues >>= xDevice ) && xDevice.is() )
[ # # ][ # # ]
245 : : {
246 [ # # ]: 0 : mxDevice = xDevice;
247 [ # # ]: 0 : mpOutDev = VCLUnoHelper::GetOutputDevice( xDevice );
248 : : }
249 : : else
250 : : {
251 : 0 : mxDevice.clear();
252 : 0 : mpOutDev = NULL;
253 : 0 : }
254 : : }
255 : 0 : break;
256 : :
257 : : case( UNOGRAPHIC_DESTINATIONRECT ):
258 : : {
259 : 0 : awt::Rectangle aAWTRect;
260 : :
261 [ # # ][ # # ]: 0 : if( *pValues >>= aAWTRect )
262 : : {
263 : : maDestRect = Rectangle( Point( aAWTRect.X, aAWTRect.Y ),
264 [ # # ]: 0 : Size( aAWTRect.Width, aAWTRect.Height ) );
265 : : }
266 : : }
267 : 0 : break;
268 : :
269 : : case( UNOGRAPHIC_RENDERDATA ):
270 : : {
271 : 0 : *pValues >>= maRenderData;
272 : : }
273 : 0 : break;
274 : : }
275 : :
276 : 0 : ++ppEntries;
277 : 0 : ++pValues;
278 [ # # ]: 0 : }
279 : 0 : }
280 : :
281 : : // ------------------------------------------------------------------------------
282 : :
283 : 0 : void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValues )
284 : : throw( beans::UnknownPropertyException, lang::WrappedTargetException )
285 : : {
286 [ # # ]: 0 : SolarMutexGuard aGuard;
287 : :
288 [ # # ]: 0 : while( *ppEntries )
289 : : {
290 [ # # # # ]: 0 : switch( (*ppEntries)->mnHandle )
291 : : {
292 : : case( UNOGRAPHIC_DEVICE ):
293 : : {
294 [ # # ]: 0 : if( mxDevice.is() )
295 [ # # ]: 0 : *pValues <<= mxDevice;
296 : : }
297 : 0 : break;
298 : :
299 : : case( UNOGRAPHIC_DESTINATIONRECT ):
300 : : {
301 : 0 : const awt::Rectangle aAWTRect( maDestRect.Left(), maDestRect.Top(),
302 [ # # ][ # # ]: 0 : maDestRect.GetWidth(), maDestRect.GetHeight() );
303 : :
304 [ # # ]: 0 : *pValues <<= aAWTRect;
305 : : }
306 : 0 : break;
307 : :
308 : : case( UNOGRAPHIC_RENDERDATA ):
309 : : {
310 [ # # ]: 0 : *pValues <<= maRenderData;
311 : : }
312 : 0 : break;
313 : : }
314 : :
315 : 0 : ++ppEntries;
316 : 0 : ++pValues;
317 [ # # ]: 0 : }
318 : 0 : }
319 : :
320 : : // ------------------------------------------------------------------------------
321 : :
322 : 0 : void SAL_CALL GraphicRendererVCL::render( const uno::Reference< graphic::XGraphic >& rxGraphic )
323 : : throw (uno::RuntimeException)
324 : : {
325 [ # # ][ # # ]: 0 : if( mpOutDev && mxDevice.is() && rxGraphic.is() )
[ # # ][ # # ]
326 : : {
327 [ # # ]: 0 : const uno::Reference< XInterface > xIFace( rxGraphic, uno::UNO_QUERY );
328 : 0 : const ::Graphic* pGraphic = ::unographic::Graphic::getImplementation( xIFace );
329 : :
330 [ # # ]: 0 : if( pGraphic )
331 : : {
332 [ # # ]: 0 : GraphicObject aGraphicObject( *pGraphic );
333 [ # # ][ # # ]: 0 : aGraphicObject.Draw( mpOutDev, maDestRect.TopLeft(), maDestRect.GetSize() );
[ # # ]
334 : 0 : }
335 : : }
336 : 0 : }
337 : :
338 : : }
339 : :
340 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|