1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svtools.hxx"
26
27 #include <com/sun/star/beans/PropertyState.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/awt/Rectangle.hpp>
30 #include <rtl/uuid.h>
31 #include <vos/mutex.hxx>
32 #include <vcl/svapp.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <comphelper/propertysetinfo.hxx>
35 #include <svl/itemprop.hxx>
36 #include <svtools/grfmgr.hxx>
37 #include "graphic.hxx"
38 #include "renderer.hxx"
39
40 #define UNOGRAPHIC_DEVICE 1
41 #define UNOGRAPHIC_DESTINATIONRECT 2
42 #define UNOGRAPHIC_RENDERDATA 3
43
44 using namespace ::com::sun::star;
45
46 namespace unographic {
47
48 // ---------------------
49 // - GraphicRendererVCL -
50 // ---------------------
51
GraphicRendererVCL_CreateInstance(const uno::Reference<lang::XMultiServiceFactory> &)52 uno::Reference< uno::XInterface > SAL_CALL GraphicRendererVCL_CreateInstance( const uno::Reference< lang::XMultiServiceFactory >& )
53 {
54 return SAL_STATIC_CAST( ::cppu::OWeakObject*, new GraphicRendererVCL );
55 }
56
57
GraphicRendererVCL()58 GraphicRendererVCL::GraphicRendererVCL() :
59 ::comphelper::PropertySetHelper( createPropertySetInfo() ),
60 mpOutDev( NULL )
61 {
62 }
63
64 // ------------------------------------------------------------------------------
65
~GraphicRendererVCL()66 GraphicRendererVCL::~GraphicRendererVCL()
67 throw()
68 {
69 }
70
71 // ------------------------------------------------------------------------------
72
getImplementationName_Static()73 ::rtl::OUString GraphicRendererVCL::getImplementationName_Static()
74 throw()
75 {
76 return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.GraphicRendererVCL" ) );
77 }
78
79 // ------------------------------------------------------------------------------
80
getSupportedServiceNames_Static()81 uno::Sequence< ::rtl::OUString > GraphicRendererVCL::getSupportedServiceNames_Static()
82 throw( )
83 {
84 uno::Sequence< ::rtl::OUString > aSeq( 1 );
85
86 aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.GraphicRendererVCL" ) );
87
88 return aSeq;
89 }
90
91 // ------------------------------------------------------------------------------
92
queryAggregation(const uno::Type & rType)93 uno::Any SAL_CALL GraphicRendererVCL::queryAggregation( const uno::Type & rType )
94 throw( uno::RuntimeException )
95 {
96 uno::Any aAny;
97
98 if( rType == ::getCppuType((const uno::Reference< lang::XServiceInfo >*)0) )
99 aAny <<= uno::Reference< lang::XServiceInfo >(this);
100 else if( rType == ::getCppuType((const uno::Reference< lang::XTypeProvider >*)0) )
101 aAny <<= uno::Reference< lang::XTypeProvider >(this);
102 else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
103 aAny <<= uno::Reference< beans::XPropertySet >(this);
104 else if( rType == ::getCppuType((const uno::Reference< beans::XPropertyState >*)0) )
105 aAny <<= uno::Reference< beans::XPropertyState >(this);
106 else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
107 aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
108 else if( rType == ::getCppuType((const uno::Reference< graphic::XGraphicRenderer >*)0) )
109 aAny <<= uno::Reference< graphic::XGraphicRenderer >(this);
110 else
111 aAny <<= OWeakAggObject::queryAggregation( rType );
112
113 return aAny;
114 }
115
116 // ------------------------------------------------------------------------------
117
queryInterface(const uno::Type & rType)118 uno::Any SAL_CALL GraphicRendererVCL::queryInterface( const uno::Type & rType )
119 throw( uno::RuntimeException )
120 {
121 return OWeakAggObject::queryInterface( rType );
122 }
123
124 // ------------------------------------------------------------------------------
125
acquire()126 void SAL_CALL GraphicRendererVCL::acquire()
127 throw()
128 {
129 OWeakAggObject::acquire();
130 }
131
132 // ------------------------------------------------------------------------------
133
release()134 void SAL_CALL GraphicRendererVCL::release()
135 throw()
136 {
137 OWeakAggObject::release();
138 }
139
140 // ------------------------------------------------------------------------------
141
getImplementationName()142 ::rtl::OUString SAL_CALL GraphicRendererVCL::getImplementationName()
143 throw( uno::RuntimeException )
144 {
145 return getImplementationName_Static();
146 }
147
148 // ------------------------------------------------------------------------------
149
supportsService(const rtl::OUString & ServiceName)150 sal_Bool SAL_CALL GraphicRendererVCL::supportsService( const rtl::OUString& ServiceName )
151 throw( uno::RuntimeException )
152 {
153 uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() );
154 const ::rtl::OUString* pArray = aSNL.getConstArray();
155
156 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
157 if( pArray[i] == ServiceName )
158 return true;
159
160 return false;
161 }
162
163 // ------------------------------------------------------------------------------
164
getSupportedServiceNames()165 uno::Sequence< rtl::OUString > SAL_CALL GraphicRendererVCL::getSupportedServiceNames()
166 throw( uno::RuntimeException )
167 {
168 return getSupportedServiceNames_Static();
169 }
170
171 // ------------------------------------------------------------------------------
172
getTypes()173 uno::Sequence< uno::Type > SAL_CALL GraphicRendererVCL::getTypes()
174 throw( uno::RuntimeException )
175 {
176 uno::Sequence< uno::Type > aTypes( 7 );
177 uno::Type* pTypes = aTypes.getArray();
178
179 *pTypes++ = ::getCppuType((const uno::Reference< uno::XAggregation>*)0);
180 *pTypes++ = ::getCppuType((const uno::Reference< lang::XServiceInfo>*)0);
181 *pTypes++ = ::getCppuType((const uno::Reference< lang::XTypeProvider>*)0);
182 *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertySet>*)0);
183 *pTypes++ = ::getCppuType((const uno::Reference< beans::XPropertyState>*)0);
184 *pTypes++ = ::getCppuType((const uno::Reference< beans::XMultiPropertySet>*)0);
185 *pTypes++ = ::getCppuType((const uno::Reference< graphic::XGraphicRenderer>*)0);
186
187 return aTypes;
188 }
189
190 // ------------------------------------------------------------------------------
191
getImplementationId()192 uno::Sequence< sal_Int8 > SAL_CALL GraphicRendererVCL::getImplementationId()
193 throw( uno::RuntimeException )
194 {
195 vos::OGuard aGuard( Application::GetSolarMutex() );
196 static uno::Sequence< sal_Int8 > aId;
197
198 if( aId.getLength() == 0 )
199 {
200 aId.realloc( 16 );
201 rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True );
202 }
203
204 return aId;
205 }
206
207 // ------------------------------------------------------------------------------
208
createPropertySetInfo()209 ::comphelper::PropertySetInfo* GraphicRendererVCL::createPropertySetInfo()
210 {
211 vos::OGuard aGuard( Application::GetSolarMutex() );
212 ::comphelper::PropertySetInfo* pRet = new ::comphelper::PropertySetInfo();
213
214 static ::comphelper::PropertyMapEntry aEntries[] =
215 {
216 { MAP_CHAR_LEN( "Device" ), UNOGRAPHIC_DEVICE, &::getCppuType( (const uno::Any*)(0)), 0, 0 },
217 { MAP_CHAR_LEN( "DestinationRect" ), UNOGRAPHIC_DESTINATIONRECT, &::getCppuType( (const awt::Rectangle*)(0)), 0, 0 },
218 { MAP_CHAR_LEN( "RenderData" ), UNOGRAPHIC_RENDERDATA, &::getCppuType( (const uno::Any*)(0)), 0, 0 },
219
220 { 0,0,0,0,0,0 }
221 };
222
223 pRet->acquire();
224 pRet->add( aEntries );
225
226 return pRet;
227 }
228
229 // ------------------------------------------------------------------------------
230
_setPropertyValues(const comphelper::PropertyMapEntry ** ppEntries,const uno::Any * pValues)231 void GraphicRendererVCL::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
232 throw( beans::UnknownPropertyException,
233 beans::PropertyVetoException,
234 lang::IllegalArgumentException,
235 lang::WrappedTargetException )
236 {
237 ::vos::OGuard aGuard( Application::GetSolarMutex() );
238
239 while( *ppEntries )
240 {
241 switch( (*ppEntries)->mnHandle )
242 {
243 case( UNOGRAPHIC_DEVICE ):
244 {
245 uno::Reference< awt::XDevice > xDevice;
246
247 if( ( *pValues >>= xDevice ) && xDevice.is() )
248 {
249 mxDevice = xDevice;
250 mpOutDev = VCLUnoHelper::GetOutputDevice( xDevice );
251 }
252 else
253 {
254 mxDevice.clear();
255 mpOutDev = NULL;
256 }
257 }
258 break;
259
260 case( UNOGRAPHIC_DESTINATIONRECT ):
261 {
262 awt::Rectangle aAWTRect;
263
264 if( *pValues >>= aAWTRect )
265 {
266 maDestRect = Rectangle( Point( aAWTRect.X, aAWTRect.Y ),
267 Size( aAWTRect.Width, aAWTRect.Height ) );
268 }
269 }
270 break;
271
272 case( UNOGRAPHIC_RENDERDATA ):
273 {
274 *pValues >>= maRenderData;
275 }
276 break;
277 }
278
279 ++ppEntries;
280 ++pValues;
281 }
282 }
283
284 // ------------------------------------------------------------------------------
285
_getPropertyValues(const comphelper::PropertyMapEntry ** ppEntries,uno::Any * pValues)286 void GraphicRendererVCL::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValues )
287 throw( beans::UnknownPropertyException, lang::WrappedTargetException )
288 {
289 ::vos::OGuard aGuard( Application::GetSolarMutex() );
290
291 while( *ppEntries )
292 {
293 switch( (*ppEntries)->mnHandle )
294 {
295 case( UNOGRAPHIC_DEVICE ):
296 {
297 if( mxDevice.is() )
298 *pValues <<= mxDevice;
299 }
300 break;
301
302 case( UNOGRAPHIC_DESTINATIONRECT ):
303 {
304 const awt::Rectangle aAWTRect( maDestRect.Left(), maDestRect.Top(),
305 maDestRect.GetWidth(), maDestRect.GetHeight() );
306
307 *pValues <<= aAWTRect;
308 }
309 break;
310
311 case( UNOGRAPHIC_RENDERDATA ):
312 {
313 *pValues <<= maRenderData;
314 }
315 break;
316 }
317
318 ++ppEntries;
319 ++pValues;
320 }
321 }
322
323 // ------------------------------------------------------------------------------
324
render(const uno::Reference<graphic::XGraphic> & rxGraphic)325 void SAL_CALL GraphicRendererVCL::render( const uno::Reference< graphic::XGraphic >& rxGraphic )
326 throw (uno::RuntimeException)
327 {
328 if( mpOutDev && mxDevice.is() && rxGraphic.is() )
329 {
330 const uno::Reference< XInterface > xIFace( rxGraphic, uno::UNO_QUERY );
331 const ::Graphic* pGraphic = ::unographic::Graphic::getImplementation( xIFace );
332
333 if( pGraphic )
334 {
335 GraphicObject aGraphicObject( *pGraphic );
336 aGraphicObject.Draw( mpOutDev, maDestRect.TopLeft(), maDestRect.GetSize() );
337 }
338 }
339 }
340
341 }
342