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