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