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 <rtl/uuid.h> 32*cdf0e10cSrcweir #include <vos/mutex.hxx> 33*cdf0e10cSrcweir #include <vcl/svapp.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/graphic/GraphicType.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphicTransformer.hpp> 36*cdf0e10cSrcweir #include <vcl/graph.hxx> 37*cdf0e10cSrcweir #include "graphic.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir using namespace com::sun::star; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir namespace unographic { 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // ------------------- 44*cdf0e10cSrcweir // - GraphicProvider - 45*cdf0e10cSrcweir // ------------------- 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir Graphic::Graphic() : 48*cdf0e10cSrcweir mpGraphic( NULL ) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir } 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir Graphic::~Graphic() 55*cdf0e10cSrcweir throw() 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir delete mpGraphic; 58*cdf0e10cSrcweir } 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir void Graphic::init( const ::Graphic& rGraphic ) 63*cdf0e10cSrcweir throw() 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir delete mpGraphic; 66*cdf0e10cSrcweir mpGraphic = new ::Graphic( rGraphic ); 67*cdf0e10cSrcweir ::unographic::GraphicDescriptor::init( *mpGraphic ); 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir uno::Any SAL_CALL Graphic::queryAggregation( const uno::Type& rType ) 73*cdf0e10cSrcweir throw( uno::RuntimeException ) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir uno::Any aAny; 76*cdf0e10cSrcweir if( rType == ::getCppuType((const uno::Reference< graphic::XGraphic >*)0) ) 77*cdf0e10cSrcweir aAny <<= uno::Reference< graphic::XGraphic >( this ); 78*cdf0e10cSrcweir else if( rType == ::getCppuType((const uno::Reference< awt::XBitmap >*)0) ) 79*cdf0e10cSrcweir aAny <<= uno::Reference< awt::XBitmap >( this ); 80*cdf0e10cSrcweir else if( rType == ::getCppuType((const uno::Reference< lang::XUnoTunnel >*)0) ) 81*cdf0e10cSrcweir aAny <<= uno::Reference< lang::XUnoTunnel >(this); 82*cdf0e10cSrcweir else 83*cdf0e10cSrcweir aAny <<= ::unographic::GraphicDescriptor::queryAggregation( rType ); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir return aAny ; 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir uno::Any SAL_CALL Graphic::queryInterface( const uno::Type & rType ) 91*cdf0e10cSrcweir throw( uno::RuntimeException ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir ::com::sun::star::uno::Any aReturn = ::unographic::GraphicDescriptor::queryInterface( rType ); 94*cdf0e10cSrcweir if ( !aReturn.hasValue() ) 95*cdf0e10cSrcweir aReturn = ::cppu::queryInterface ( rType, static_cast< graphic::XGraphicTransformer*>( this ) ); 96*cdf0e10cSrcweir return aReturn; 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir void SAL_CALL Graphic::acquire() 102*cdf0e10cSrcweir throw() 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir ::unographic::GraphicDescriptor::acquire(); 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir void SAL_CALL Graphic::release() throw() 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir ::unographic::GraphicDescriptor::release(); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId_Static() 117*cdf0e10cSrcweir throw(uno::RuntimeException) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir vos::OGuard aGuard( Application::GetSolarMutex() ); 120*cdf0e10cSrcweir static uno::Sequence< sal_Int8 > aId; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir if( aId.getLength() == 0 ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir aId.realloc( 16 ); 125*cdf0e10cSrcweir rtl_createUuid( reinterpret_cast< sal_uInt8* >( aId.getArray() ), 0, sal_True ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir return aId; 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir ::rtl::OUString Graphic::getImplementationName_Static() 134*cdf0e10cSrcweir throw() 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.graphic.Graphic" ) ); 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > Graphic::getSupportedServiceNames_Static() 142*cdf0e10cSrcweir throw() 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSeq( 1 ); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir aSeq.getArray()[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.graphic.Graphic" ) ); 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir return aSeq; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir ::rtl::OUString SAL_CALL Graphic::getImplementationName() 154*cdf0e10cSrcweir throw( uno::RuntimeException ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir return getImplementationName_Static(); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir sal_Bool SAL_CALL Graphic::supportsService( const ::rtl::OUString& rServiceName ) 162*cdf0e10cSrcweir throw( uno::RuntimeException ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir if( ::unographic::GraphicDescriptor::supportsService( rServiceName ) ) 165*cdf0e10cSrcweir return true; 166*cdf0e10cSrcweir else 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aSNL( getSupportedServiceNames() ); 169*cdf0e10cSrcweir const ::rtl::OUString* pArray = aSNL.getConstArray(); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir for( int i = 0; i < aSNL.getLength(); i++ ) 172*cdf0e10cSrcweir if( pArray[i] == rServiceName ) 173*cdf0e10cSrcweir return true; 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir return false; 176*cdf0e10cSrcweir } 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > SAL_CALL Graphic::getSupportedServiceNames() 182*cdf0e10cSrcweir throw( uno::RuntimeException ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aRet( ::unographic::GraphicDescriptor::getSupportedServiceNames() ); 185*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aNew( getSupportedServiceNames_Static() ); 186*cdf0e10cSrcweir sal_Int32 nOldCount = aRet.getLength(); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir aRet.realloc( nOldCount + aNew.getLength() ); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aNew.getLength(); ++i ) 191*cdf0e10cSrcweir aRet[ nOldCount++ ] = aNew[ i ]; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir return aRet; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir uno::Sequence< uno::Type > SAL_CALL Graphic::getTypes() 199*cdf0e10cSrcweir throw(uno::RuntimeException) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir uno::Sequence< uno::Type > aRet( ::unographic::GraphicDescriptor::getTypes() ); 202*cdf0e10cSrcweir sal_Int32 nOldCount = aRet.getLength(); 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir aRet.realloc( nOldCount + 2 ); 205*cdf0e10cSrcweir aRet[ nOldCount ] = ::getCppuType((const uno::Reference< graphic::XGraphic>*)0); 206*cdf0e10cSrcweir aRet[ nOldCount+1 ] = ::getCppuType((const uno::Reference< awt::XBitmap>*)0); 207*cdf0e10cSrcweir 208*cdf0e10cSrcweir return aRet; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir uno::Sequence< sal_Int8 > SAL_CALL Graphic::getImplementationId() 214*cdf0e10cSrcweir throw(uno::RuntimeException) 215*cdf0e10cSrcweir { 216*cdf0e10cSrcweir return getImplementationId_Static(); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir // ------------------------------------------------------------------------------ 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir ::sal_Int8 SAL_CALL Graphic::getType() 222*cdf0e10cSrcweir throw (uno::RuntimeException) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir ::sal_Int8 cRet = graphic::GraphicType::EMPTY; 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) ) 227*cdf0e10cSrcweir cRet = ( ( mpGraphic->GetType() == GRAPHIC_BITMAP ) ? graphic::GraphicType::PIXEL : graphic::GraphicType::VECTOR ); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir return cRet; 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir //---------------------------------------------------------------------- 233*cdf0e10cSrcweir // XBitmap 234*cdf0e10cSrcweir //---------------------------------------------------------------------- 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir awt::Size SAL_CALL Graphic::getSize( ) throw (uno::RuntimeException) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 239*cdf0e10cSrcweir 240*cdf0e10cSrcweir ::Size aVclSize; 241*cdf0e10cSrcweir if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) ) 242*cdf0e10cSrcweir aVclSize = mpGraphic->GetSizePixel(); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir return awt::Size( aVclSize.Width(), aVclSize.Height() ); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir //---------------------------------------------------------------------- 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getDIB( ) throw (uno::RuntimeException) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir SvMemoryStream aMem; 256*cdf0e10cSrcweir aMem << mpGraphic->GetBitmapEx().GetBitmap(); 257*cdf0e10cSrcweir return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() ); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir else 260*cdf0e10cSrcweir { 261*cdf0e10cSrcweir return uno::Sequence<sal_Int8>(); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir //---------------------------------------------------------------------- 266*cdf0e10cSrcweir 267*cdf0e10cSrcweir uno::Sequence< ::sal_Int8 > SAL_CALL Graphic::getMaskDIB( ) throw (uno::RuntimeException) 268*cdf0e10cSrcweir { 269*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir if( mpGraphic && ( mpGraphic->GetType() != GRAPHIC_NONE ) ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir SvMemoryStream aMem; 274*cdf0e10cSrcweir aMem << mpGraphic->GetBitmapEx().GetMask(); 275*cdf0e10cSrcweir return ::com::sun::star::uno::Sequence<sal_Int8>( (sal_Int8*) aMem.GetData(), aMem.Tell() ); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir else 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir return uno::Sequence<sal_Int8>(); 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir //---------------------------------------------------------------------- 284*cdf0e10cSrcweir const ::Graphic* Graphic::getImplementation( const uno::Reference< uno::XInterface >& rxIFace ) 285*cdf0e10cSrcweir throw() 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir uno::Reference< lang::XUnoTunnel > xTunnel( rxIFace, uno::UNO_QUERY ); 288*cdf0e10cSrcweir return( xTunnel.is() ? reinterpret_cast< ::Graphic* >( xTunnel->getSomething( getImplementationId_Static() ) ) : NULL ); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir //---------------------------------------------------------------------- 292*cdf0e10cSrcweir sal_Int64 SAL_CALL Graphic::getSomething( const uno::Sequence< sal_Int8 >& rId ) 293*cdf0e10cSrcweir throw( uno::RuntimeException ) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir return( ( rId.getLength() == 16 && 0 == rtl_compareMemory( getImplementationId().getConstArray(), rId.getConstArray(), 16 ) ) ? 296*cdf0e10cSrcweir reinterpret_cast< sal_Int64 >( mpGraphic ) : 297*cdf0e10cSrcweir 0 ); 298*cdf0e10cSrcweir } 299*cdf0e10cSrcweir 300*cdf0e10cSrcweir } 301