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