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