1*bfd08df8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*bfd08df8SAndrew Rist * distributed with this work for additional information 6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance 9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an 15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the 17*bfd08df8SAndrew Rist * specific language governing permissions and limitations 18*bfd08df8SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*bfd08df8SAndrew Rist *************************************************************/ 21*bfd08df8SAndrew Rist 22*bfd08df8SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <oleembobj.hxx> 28cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp> 29cdf0e10cSrcweir #include <com/sun/star/embed/EmbedVerbs.hpp> 30cdf0e10cSrcweir #include <com/sun/star/embed/EntryInitModes.hpp> 31cdf0e10cSrcweir #include <com/sun/star/embed/XStorage.hpp> 32cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 33cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 34cdf0e10cSrcweir #include <com/sun/star/embed/EmbedUpdateModes.hpp> 35cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp> 36cdf0e10cSrcweir #include <com/sun/star/embed/XOptimizedStorage.hpp> 37cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 38cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 39cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 40cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 41cdf0e10cSrcweir #include <com/sun/star/io/XSeekable.hpp> 42cdf0e10cSrcweir #include <com/sun/star/io/XTruncate.hpp> 43cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 44cdf0e10cSrcweir #include <com/sun/star/ucb/XSimpleFileAccess.hpp> 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include <rtl/logfile.hxx> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include <comphelper/storagehelper.hxx> 49cdf0e10cSrcweir #include <comphelper/mimeconfighelper.hxx> 50cdf0e10cSrcweir #include <comphelper/classids.hxx> 51cdf0e10cSrcweir 52cdf0e10cSrcweir 53cdf0e10cSrcweir #include <olecomponent.hxx> 54cdf0e10cSrcweir #include <closepreventer.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir using namespace ::com::sun::star; 57cdf0e10cSrcweir using namespace ::comphelper; 58cdf0e10cSrcweir 59cdf0e10cSrcweir //------------------------------------------------------------------------- 60cdf0e10cSrcweir sal_Bool KillFile_Impl( const ::rtl::OUString& aURL, const uno::Reference< lang::XMultiServiceFactory >& xFactory ) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir if ( !xFactory.is() ) 63cdf0e10cSrcweir return sal_False; 64cdf0e10cSrcweir 65cdf0e10cSrcweir sal_Bool bRet = sal_False; 66cdf0e10cSrcweir 67cdf0e10cSrcweir try 68cdf0e10cSrcweir { 69cdf0e10cSrcweir uno::Reference < ucb::XSimpleFileAccess > xAccess( 70cdf0e10cSrcweir xFactory->createInstance ( 71cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), 72cdf0e10cSrcweir uno::UNO_QUERY ); 73cdf0e10cSrcweir 74cdf0e10cSrcweir if ( xAccess.is() ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir xAccess->kill( aURL ); 77cdf0e10cSrcweir bRet = sal_True; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80cdf0e10cSrcweir catch( uno::Exception& ) 81cdf0e10cSrcweir { 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir return bRet; 85cdf0e10cSrcweir } 86cdf0e10cSrcweir 87cdf0e10cSrcweir //---------------------------------------------- 88cdf0e10cSrcweir ::rtl::OUString GetNewTempFileURL_Impl( const uno::Reference< lang::XMultiServiceFactory >& xFactory ) 89cdf0e10cSrcweir { 90cdf0e10cSrcweir OSL_ENSURE( xFactory.is(), "No factory is provided!\n" ); 91cdf0e10cSrcweir 92cdf0e10cSrcweir ::rtl::OUString aResult; 93cdf0e10cSrcweir 94cdf0e10cSrcweir uno::Reference < beans::XPropertySet > xTempFile( 95cdf0e10cSrcweir xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), 96cdf0e10cSrcweir uno::UNO_QUERY ); 97cdf0e10cSrcweir 98cdf0e10cSrcweir if ( !xTempFile.is() ) 99cdf0e10cSrcweir throw uno::RuntimeException(); // TODO 100cdf0e10cSrcweir 101cdf0e10cSrcweir try { 102cdf0e10cSrcweir xTempFile->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ), uno::makeAny( sal_False ) ); 103cdf0e10cSrcweir uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) ); 104cdf0e10cSrcweir aUrl >>= aResult; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir catch ( uno::Exception& ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir if ( !aResult.getLength() ) 111cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: can not create tempfile 112cdf0e10cSrcweir 113cdf0e10cSrcweir return aResult; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir //----------------------------------------------- 117cdf0e10cSrcweir ::rtl::OUString GetNewFilledTempFile_Impl( const uno::Reference< io::XInputStream >& xInStream, 118cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory >& xFactory ) 119cdf0e10cSrcweir throw ( io::IOException, 120cdf0e10cSrcweir uno::RuntimeException ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir OSL_ENSURE( xInStream.is() && xFactory.is(), "Wrong parameters are provided!\n" ); 123cdf0e10cSrcweir 124cdf0e10cSrcweir ::rtl::OUString aResult = GetNewTempFileURL_Impl( xFactory ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir if ( aResult.getLength() ) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir try { 129cdf0e10cSrcweir uno::Reference < ucb::XSimpleFileAccess > xTempAccess( 130cdf0e10cSrcweir xFactory->createInstance ( 131cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), 132cdf0e10cSrcweir uno::UNO_QUERY ); 133cdf0e10cSrcweir 134cdf0e10cSrcweir if ( !xTempAccess.is() ) 135cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 136cdf0e10cSrcweir 137cdf0e10cSrcweir uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aResult ); 138cdf0e10cSrcweir if ( xTempOutStream.is() ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir // copy stream contents to the file 141cdf0e10cSrcweir ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOutStream ); 142cdf0e10cSrcweir xTempOutStream->closeOutput(); 143cdf0e10cSrcweir xTempOutStream = uno::Reference< io::XOutputStream >(); 144cdf0e10cSrcweir } 145cdf0e10cSrcweir else 146cdf0e10cSrcweir throw io::IOException(); // TODO: 147cdf0e10cSrcweir } 148cdf0e10cSrcweir catch( packages::WrongPasswordException& ) 149cdf0e10cSrcweir { 150cdf0e10cSrcweir KillFile_Impl( aResult, xFactory ); 151cdf0e10cSrcweir throw io::IOException(); //TODO: 152cdf0e10cSrcweir } 153cdf0e10cSrcweir catch( io::IOException& ) 154cdf0e10cSrcweir { 155cdf0e10cSrcweir KillFile_Impl( aResult, xFactory ); 156cdf0e10cSrcweir throw; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir catch( uno::RuntimeException& ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir KillFile_Impl( aResult, xFactory ); 161cdf0e10cSrcweir throw; 162cdf0e10cSrcweir } 163cdf0e10cSrcweir catch( uno::Exception& ) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir KillFile_Impl( aResult, xFactory ); 166cdf0e10cSrcweir aResult = ::rtl::OUString(); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir } 169cdf0e10cSrcweir 170cdf0e10cSrcweir return aResult; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir #ifdef WNT 173cdf0e10cSrcweir ::rtl::OUString GetNewFilledTempFile_Impl( const uno::Reference< embed::XOptimizedStorage >& xParentStorage, const ::rtl::OUString& aEntryName, const uno::Reference< lang::XMultiServiceFactory >& xFactory ) 174cdf0e10cSrcweir throw( io::IOException, uno::RuntimeException ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir ::rtl::OUString aResult; 177cdf0e10cSrcweir 178cdf0e10cSrcweir try 179cdf0e10cSrcweir { 180cdf0e10cSrcweir uno::Reference < beans::XPropertySet > xTempFile( 181cdf0e10cSrcweir xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), 182cdf0e10cSrcweir uno::UNO_QUERY ); 183cdf0e10cSrcweir uno::Reference < io::XStream > xTempStream( xTempFile, uno::UNO_QUERY_THROW ); 184cdf0e10cSrcweir 185cdf0e10cSrcweir xParentStorage->copyStreamElementData( aEntryName, xTempStream ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir xTempFile->setPropertyValue( ::rtl::OUString::createFromAscii( "RemoveFile" ), uno::makeAny( sal_False ) ); 188cdf0e10cSrcweir uno::Any aUrl = xTempFile->getPropertyValue( ::rtl::OUString::createFromAscii( "Uri" ) ); 189cdf0e10cSrcweir aUrl >>= aResult; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir catch( uno::RuntimeException& ) 192cdf0e10cSrcweir { 193cdf0e10cSrcweir throw; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir catch( uno::Exception& ) 196cdf0e10cSrcweir { 197cdf0e10cSrcweir } 198cdf0e10cSrcweir 199cdf0e10cSrcweir if ( !aResult.getLength() ) 200cdf0e10cSrcweir throw io::IOException(); 201cdf0e10cSrcweir 202cdf0e10cSrcweir return aResult; 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir //------------------------------------------------------ 206cdf0e10cSrcweir void SetStreamMediaType_Impl( const uno::Reference< io::XStream >& xStream, const ::rtl::OUString& aMediaType ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xStream, uno::UNO_QUERY ); 209cdf0e10cSrcweir if ( !xPropSet.is() ) 210cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: all the storage streams must support XPropertySet 211cdf0e10cSrcweir 212cdf0e10cSrcweir xPropSet->setPropertyValue( ::rtl::OUString::createFromAscii( "MediaType" ), uno::makeAny( aMediaType ) ); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir #endif 215cdf0e10cSrcweir //------------------------------------------------------ 216cdf0e10cSrcweir void LetCommonStoragePassBeUsed_Impl( const uno::Reference< io::XStream >& xStream ) 217cdf0e10cSrcweir { 218cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xPropSet( xStream, uno::UNO_QUERY ); 219cdf0e10cSrcweir if ( !xPropSet.is() ) 220cdf0e10cSrcweir throw uno::RuntimeException(); // Only StorageStreams must be provided here, they must implement the interface 221cdf0e10cSrcweir 222cdf0e10cSrcweir xPropSet->setPropertyValue( ::rtl::OUString::createFromAscii( "UseCommonStoragePasswordEncryption" ), 223cdf0e10cSrcweir uno::makeAny( (sal_Bool)sal_True ) ); 224cdf0e10cSrcweir } 225cdf0e10cSrcweir #ifdef WNT 226cdf0e10cSrcweir //------------------------------------------------------ 227cdf0e10cSrcweir void VerbExecutionController::StartControlExecution() 228cdf0e10cSrcweir { 229cdf0e10cSrcweir osl::MutexGuard aGuard( m_aVerbExecutionMutex ); 230cdf0e10cSrcweir 231cdf0e10cSrcweir // the class is used to detect STAMPIT object, that can never be active 232cdf0e10cSrcweir if ( !m_bVerbExecutionInProgress && !m_bWasEverActive ) 233cdf0e10cSrcweir { 234cdf0e10cSrcweir m_bVerbExecutionInProgress = sal_True; 235cdf0e10cSrcweir m_nVerbExecutionThreadIdentifier = osl_getThreadIdentifier( NULL ); 236cdf0e10cSrcweir m_bChangedOnVerbExecution = sal_False; 237cdf0e10cSrcweir } 238cdf0e10cSrcweir } 239cdf0e10cSrcweir 240cdf0e10cSrcweir //------------------------------------------------------ 241cdf0e10cSrcweir sal_Bool VerbExecutionController::EndControlExecution_WasModified() 242cdf0e10cSrcweir { 243cdf0e10cSrcweir osl::MutexGuard aGuard( m_aVerbExecutionMutex ); 244cdf0e10cSrcweir 245cdf0e10cSrcweir sal_Bool bResult = sal_False; 246cdf0e10cSrcweir if ( m_bVerbExecutionInProgress && m_nVerbExecutionThreadIdentifier == osl_getThreadIdentifier( NULL ) ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir bResult = m_bChangedOnVerbExecution; 249cdf0e10cSrcweir m_bVerbExecutionInProgress = sal_False; 250cdf0e10cSrcweir } 251cdf0e10cSrcweir 252cdf0e10cSrcweir return bResult; 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir //------------------------------------------------------ 256cdf0e10cSrcweir void VerbExecutionController::ModificationNotificationIsDone() 257cdf0e10cSrcweir { 258cdf0e10cSrcweir osl::MutexGuard aGuard( m_aVerbExecutionMutex ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir if ( m_bVerbExecutionInProgress && osl_getThreadIdentifier( NULL ) == m_nVerbExecutionThreadIdentifier ) 261cdf0e10cSrcweir m_bChangedOnVerbExecution = sal_True; 262cdf0e10cSrcweir } 263cdf0e10cSrcweir #endif 264cdf0e10cSrcweir //----------------------------------------------- 265cdf0e10cSrcweir void VerbExecutionController::LockNotification() 266cdf0e10cSrcweir { 267cdf0e10cSrcweir osl::MutexGuard aGuard( m_aVerbExecutionMutex ); 268cdf0e10cSrcweir if ( m_nNotificationLock < SAL_MAX_INT32 ) 269cdf0e10cSrcweir m_nNotificationLock++; 270cdf0e10cSrcweir } 271cdf0e10cSrcweir 272cdf0e10cSrcweir //----------------------------------------------- 273cdf0e10cSrcweir void VerbExecutionController::UnlockNotification() 274cdf0e10cSrcweir { 275cdf0e10cSrcweir osl::MutexGuard aGuard( m_aVerbExecutionMutex ); 276cdf0e10cSrcweir if ( m_nNotificationLock > 0 ) 277cdf0e10cSrcweir m_nNotificationLock--; 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir //----------------------------------------------- 281cdf0e10cSrcweir uno::Reference< io::XStream > OleEmbeddedObject::GetNewFilledTempStream_Impl( const uno::Reference< io::XInputStream >& xInStream ) 282cdf0e10cSrcweir throw( io::IOException ) 283cdf0e10cSrcweir { 284cdf0e10cSrcweir OSL_ENSURE( xInStream.is(), "Wrong parameter is provided!\n" ); 285cdf0e10cSrcweir 286cdf0e10cSrcweir uno::Reference < io::XStream > xTempFile( 287cdf0e10cSrcweir m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), 288cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 289cdf0e10cSrcweir 290cdf0e10cSrcweir uno::Reference< io::XOutputStream > xTempOutStream = xTempFile->getOutputStream(); 291cdf0e10cSrcweir if ( xTempOutStream.is() ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xTempOutStream ); 294cdf0e10cSrcweir xTempOutStream->flush(); 295cdf0e10cSrcweir } 296cdf0e10cSrcweir else 297cdf0e10cSrcweir throw io::IOException(); // TODO: 298cdf0e10cSrcweir 299cdf0e10cSrcweir return xTempFile; 300cdf0e10cSrcweir } 301cdf0e10cSrcweir 302cdf0e10cSrcweir //------------------------------------------------------ 303cdf0e10cSrcweir uno::Reference< io::XStream > OleEmbeddedObject::TryToGetAcceptableFormat_Impl( const uno::Reference< io::XStream >& xStream ) 304cdf0e10cSrcweir throw ( uno::Exception ) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir // TODO/LATER: Actually this should be done by a centralized component ( may be a graphical filter ) 307cdf0e10cSrcweir if ( !m_xFactory.is() ) 308cdf0e10cSrcweir throw uno::RuntimeException(); 309cdf0e10cSrcweir 310cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = xStream->getInputStream(); 311cdf0e10cSrcweir if ( !xInStream.is() ) 312cdf0e10cSrcweir throw uno::RuntimeException(); 313cdf0e10cSrcweir 314cdf0e10cSrcweir uno::Reference< io::XSeekable > xSeek( xStream, uno::UNO_QUERY_THROW ); 315cdf0e10cSrcweir xSeek->seek( 0 ); 316cdf0e10cSrcweir 317cdf0e10cSrcweir uno::Sequence< sal_Int8 > aData( 8 ); 318cdf0e10cSrcweir sal_Int32 nRead = xInStream->readBytes( aData, 8 ); 319cdf0e10cSrcweir xSeek->seek( 0 ); 320cdf0e10cSrcweir 321cdf0e10cSrcweir if ( ( nRead >= 2 && aData[0] == 'B' && aData[1] == 'M' ) 322cdf0e10cSrcweir || ( nRead >= 4 && aData[0] == 1 && aData[1] == 0 && aData[2] == 9 && aData[3] == 0 ) ) 323cdf0e10cSrcweir { 324cdf0e10cSrcweir // it should be a bitmap or a Metafile 325cdf0e10cSrcweir return xStream; 326cdf0e10cSrcweir } 327cdf0e10cSrcweir 328cdf0e10cSrcweir // sal_Bool bSetSizeToRepl = sal_False; 329cdf0e10cSrcweir // awt::Size aSizeToSet; 330cdf0e10cSrcweir 331cdf0e10cSrcweir sal_uInt32 nHeaderOffset = 0; 332cdf0e10cSrcweir if ( ( nRead >= 8 && aData[0] == -1 && aData[1] == -1 && aData[2] == -1 && aData[3] == -1 ) 333cdf0e10cSrcweir && ( aData[4] == 2 || aData[4] == 3 || aData[4] == 14 ) && aData[5] == 0 && aData[6] == 0 && aData[7] == 0 ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir nHeaderOffset = 40; 336cdf0e10cSrcweir xSeek->seek( 8 ); 337cdf0e10cSrcweir 338cdf0e10cSrcweir // TargetDevice might be used in future, currently the cache has specified NULL 339cdf0e10cSrcweir uno::Sequence< sal_Int8 > aHeadData( 4 ); 340cdf0e10cSrcweir nRead = xInStream->readBytes( aHeadData, 4 ); 341cdf0e10cSrcweir sal_uInt32 nLen = 0; 342cdf0e10cSrcweir if ( nRead == 4 && aHeadData.getLength() == 4 ) 343cdf0e10cSrcweir nLen = ( ( ( (sal_uInt32)aHeadData[3] * 0x100 + (sal_uInt32)aHeadData[2] ) * 0x100 ) + (sal_uInt32)aHeadData[1] ) * 0x100 + (sal_uInt32)aHeadData[0]; 344cdf0e10cSrcweir if ( nLen > 4 ) 345cdf0e10cSrcweir { 346cdf0e10cSrcweir xInStream->skipBytes( nLen - 4 ); 347cdf0e10cSrcweir nHeaderOffset += nLen - 4; 348cdf0e10cSrcweir } 349cdf0e10cSrcweir 350cdf0e10cSrcweir // if ( aData[4] == 3 ) 351cdf0e10cSrcweir // { 352cdf0e10cSrcweir // try 353cdf0e10cSrcweir // { 354cdf0e10cSrcweir // 355cdf0e10cSrcweir // aSizeToSet = getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ); 356cdf0e10cSrcweir // aSizeToSet.Width /= 364; //2540; // let the size be in inches, as wmf requires 357cdf0e10cSrcweir // aSizeToSet.Height /= 364; //2540; // let the size be in inches, as wmf requires 358cdf0e10cSrcweir // bSetSizeToRepl = sal_True; 359cdf0e10cSrcweir // } 360cdf0e10cSrcweir // catch( uno::Exception& ) 361cdf0e10cSrcweir // {} 362cdf0e10cSrcweir // } 363cdf0e10cSrcweir } 364cdf0e10cSrcweir else if ( nRead > 4 ) 365cdf0e10cSrcweir { 366cdf0e10cSrcweir // check whether the first bytes represent the size 367cdf0e10cSrcweir sal_uInt32 nSize = 0; 368cdf0e10cSrcweir for ( sal_Int32 nInd = 3; nInd >= 0; nInd-- ) 369cdf0e10cSrcweir nSize = ( nSize << 8 ) + (sal_uInt8)aData[nInd]; 370cdf0e10cSrcweir 371cdf0e10cSrcweir if ( nSize == xSeek->getLength() - 4 ) 372cdf0e10cSrcweir nHeaderOffset = 4; 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir if ( nHeaderOffset ) 376cdf0e10cSrcweir { 377cdf0e10cSrcweir // this is either a bitmap or a metafile clipboard format, retrieve the pure stream 378cdf0e10cSrcweir uno::Reference < io::XStream > xResult( 379cdf0e10cSrcweir m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), 380cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 381cdf0e10cSrcweir uno::Reference < io::XSeekable > xResultSeek( xResult, uno::UNO_QUERY_THROW ); 382cdf0e10cSrcweir uno::Reference < io::XOutputStream > xResultOut = xResult->getOutputStream(); 383cdf0e10cSrcweir uno::Reference < io::XInputStream > xResultIn = xResult->getInputStream(); 384cdf0e10cSrcweir if ( !xResultOut.is() || !xResultIn.is() ) 385cdf0e10cSrcweir throw uno::RuntimeException(); 386cdf0e10cSrcweir 387cdf0e10cSrcweir // if it is windows metafile the size must be provided 388cdf0e10cSrcweir // the solution is not used currently 389cdf0e10cSrcweir // if ( bSetSizeToRepl && abs( aSizeToSet.Width ) < 0xFFFF && abs( aSizeToSet.Height ) < 0xFFFF ) 390cdf0e10cSrcweir // { 391cdf0e10cSrcweir // uno::Sequence< sal_Int8 > aHeader(22); 392cdf0e10cSrcweir // sal_uInt8* pBuffer = (sal_uInt8*)aHeader.getArray(); 393cdf0e10cSrcweir // 394cdf0e10cSrcweir // // write 0x9ac6cdd7L 395cdf0e10cSrcweir // pBuffer[0] = 0xd7; 396cdf0e10cSrcweir // pBuffer[1] = 0xcd; 397cdf0e10cSrcweir // pBuffer[2] = 0xc6; 398cdf0e10cSrcweir // pBuffer[3] = 0x9a; 399cdf0e10cSrcweir // 400cdf0e10cSrcweir // // following data seems to have no value 401cdf0e10cSrcweir // pBuffer[4] = 0; 402cdf0e10cSrcweir // pBuffer[5] = 0; 403cdf0e10cSrcweir // 404cdf0e10cSrcweir // // must be set to 0 405cdf0e10cSrcweir // pBuffer[6] = 0; 406cdf0e10cSrcweir // pBuffer[7] = 0; 407cdf0e10cSrcweir // pBuffer[8] = 0; 408cdf0e10cSrcweir // pBuffer[9] = 0; 409cdf0e10cSrcweir // 410cdf0e10cSrcweir // // width of the picture 411cdf0e10cSrcweir // pBuffer[10] = abs( aSizeToSet.Width ) % 0x100; 412cdf0e10cSrcweir // pBuffer[11] = ( abs( aSizeToSet.Width ) / 0x100 ) % 0x100; 413cdf0e10cSrcweir // 414cdf0e10cSrcweir // // height of the picture 415cdf0e10cSrcweir // pBuffer[12] = abs( aSizeToSet.Height ) % 0x100; 416cdf0e10cSrcweir // pBuffer[13] = ( abs( aSizeToSet.Height ) / 0x100 ) % 0x100; 417cdf0e10cSrcweir // 418cdf0e10cSrcweir // // write 2540 419cdf0e10cSrcweir // pBuffer[14] = 0x6c; //0xec; 420cdf0e10cSrcweir // pBuffer[15] = 0x01; //0x09; 421cdf0e10cSrcweir // 422cdf0e10cSrcweir // // fill with 0 423cdf0e10cSrcweir // for ( sal_Int32 nInd = 16; nInd < 22; nInd++ ) 424cdf0e10cSrcweir // pBuffer[nInd] = 0; 425cdf0e10cSrcweir // 426cdf0e10cSrcweir // xResultOut->writeBytes( aHeader ); 427cdf0e10cSrcweir // } 428cdf0e10cSrcweir 429cdf0e10cSrcweir xSeek->seek( nHeaderOffset ); // header size for these formats 430cdf0e10cSrcweir ::comphelper::OStorageHelper::CopyInputToOutput( xInStream, xResultOut ); 431cdf0e10cSrcweir xResultOut->closeOutput(); 432cdf0e10cSrcweir xResultSeek->seek( 0 ); 433cdf0e10cSrcweir xSeek->seek( 0 ); 434cdf0e10cSrcweir 435cdf0e10cSrcweir return xResult; 436cdf0e10cSrcweir } 437cdf0e10cSrcweir 438cdf0e10cSrcweir return uno::Reference< io::XStream >(); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir //------------------------------------------------------ 442cdf0e10cSrcweir void OleEmbeddedObject::InsertVisualCache_Impl( const uno::Reference< io::XStream >& xTargetStream, 443cdf0e10cSrcweir const uno::Reference< io::XStream >& xCachedVisualRepresentation ) 444cdf0e10cSrcweir throw ( uno::Exception ) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir OSL_ENSURE( xTargetStream.is() && xCachedVisualRepresentation.is(), "Invalid argumants!\n" ); 447cdf0e10cSrcweir 448cdf0e10cSrcweir if ( !xTargetStream.is() || !xCachedVisualRepresentation.is() ) 449cdf0e10cSrcweir throw uno::RuntimeException(); 450cdf0e10cSrcweir 451cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 452cdf0e10cSrcweir aArgs[0] <<= xTargetStream; 453cdf0e10cSrcweir aArgs[1] <<= (sal_Bool)sal_True; // do not create copy 454cdf0e10cSrcweir 455cdf0e10cSrcweir uno::Reference< container::XNameContainer > xNameContainer( 456cdf0e10cSrcweir m_xFactory->createInstanceWithArguments( 457cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLESimpleStorage" ), 458cdf0e10cSrcweir aArgs ), 459cdf0e10cSrcweir uno::UNO_QUERY ); 460cdf0e10cSrcweir 461cdf0e10cSrcweir if ( !xNameContainer.is() ) 462cdf0e10cSrcweir throw uno::RuntimeException(); 463cdf0e10cSrcweir 464cdf0e10cSrcweir uno::Reference< io::XSeekable > xCachedSeek( xCachedVisualRepresentation, uno::UNO_QUERY_THROW ); 465cdf0e10cSrcweir if ( xCachedSeek.is() ) 466cdf0e10cSrcweir xCachedSeek->seek( 0 ); 467cdf0e10cSrcweir 468cdf0e10cSrcweir uno::Reference < io::XStream > xTempFile( 469cdf0e10cSrcweir m_xFactory->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.io.TempFile" ) ), 470cdf0e10cSrcweir uno::UNO_QUERY_THROW ); 471cdf0e10cSrcweir 472cdf0e10cSrcweir uno::Reference< io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW ); 473cdf0e10cSrcweir uno::Reference< io::XOutputStream > xTempOutStream = xTempFile->getOutputStream(); 474cdf0e10cSrcweir if ( xTempOutStream.is() ) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir // the OlePres stream must have additional header 477cdf0e10cSrcweir // TODO/LATER: might need to be extended in future ( actually makes sence only for SO7 format ) 478cdf0e10cSrcweir uno::Reference< io::XInputStream > xInCacheStream = xCachedVisualRepresentation->getInputStream(); 479cdf0e10cSrcweir if ( !xInCacheStream.is() ) 480cdf0e10cSrcweir throw uno::RuntimeException(); 481cdf0e10cSrcweir 482cdf0e10cSrcweir // write 0xFFFFFFFF at the beginning 483cdf0e10cSrcweir uno::Sequence< sal_Int8 > aData( 4 ); 484cdf0e10cSrcweir *( (sal_uInt32*)aData.getArray() ) = 0xFFFFFFFF; 485cdf0e10cSrcweir 486cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 487cdf0e10cSrcweir 488cdf0e10cSrcweir // write clipboard format 489cdf0e10cSrcweir uno::Sequence< sal_Int8 > aSigData( 2 ); 490cdf0e10cSrcweir xInCacheStream->readBytes( aSigData, 2 ); 491cdf0e10cSrcweir if ( aSigData.getLength() < 2 ) 492cdf0e10cSrcweir throw io::IOException(); 493cdf0e10cSrcweir 494cdf0e10cSrcweir if ( aSigData[0] == 'B' && aSigData[1] == 'M' ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir // it's a bitmap 497cdf0e10cSrcweir aData[0] = 0x02; aData[1] = 0; aData[2] = 0; aData[3] = 0; 498cdf0e10cSrcweir } 499cdf0e10cSrcweir else 500cdf0e10cSrcweir { 501cdf0e10cSrcweir // treat it as a metafile 502cdf0e10cSrcweir aData[0] = 0x03; aData[1] = 0; aData[2] = 0; aData[3] = 0; 503cdf0e10cSrcweir } 504cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 505cdf0e10cSrcweir 506cdf0e10cSrcweir // write job related information 507cdf0e10cSrcweir aData[0] = 0x04; aData[1] = 0; aData[2] = 0; aData[3] = 0; 508cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 509cdf0e10cSrcweir 510cdf0e10cSrcweir // write aspect 511cdf0e10cSrcweir aData[0] = 0x01; aData[1] = 0; aData[2] = 0; aData[3] = 0; 512cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 513cdf0e10cSrcweir 514cdf0e10cSrcweir // write l-index 515cdf0e10cSrcweir *( (sal_uInt32*)aData.getArray() ) = 0xFFFFFFFF; 516cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 517cdf0e10cSrcweir 518cdf0e10cSrcweir // write adv. flags 519cdf0e10cSrcweir aData[0] = 0x02; aData[1] = 0; aData[2] = 0; aData[3] = 0; 520cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 521cdf0e10cSrcweir 522cdf0e10cSrcweir // write compression 523cdf0e10cSrcweir *( (sal_uInt32*)aData.getArray() ) = 0x0; 524cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 525cdf0e10cSrcweir 526cdf0e10cSrcweir // get the size 527cdf0e10cSrcweir awt::Size aSize = getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ); 528cdf0e10cSrcweir sal_Int32 nIndex = 0; 529cdf0e10cSrcweir 530cdf0e10cSrcweir // write width 531cdf0e10cSrcweir for ( nIndex = 0; nIndex < 4; nIndex++ ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir aData[nIndex] = (sal_Int8)( aSize.Width % 0x100 ); 534cdf0e10cSrcweir aSize.Width /= 0x100; 535cdf0e10cSrcweir } 536cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 537cdf0e10cSrcweir 538cdf0e10cSrcweir // write height 539cdf0e10cSrcweir for ( nIndex = 0; nIndex < 4; nIndex++ ) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir aData[nIndex] = (sal_Int8)( aSize.Height % 0x100 ); 542cdf0e10cSrcweir aSize.Height /= 0x100; 543cdf0e10cSrcweir } 544cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 545cdf0e10cSrcweir 546cdf0e10cSrcweir // write garbage, it will be overwritten by the size 547cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 548cdf0e10cSrcweir 549cdf0e10cSrcweir // write first bytes that was used to detect the type 550cdf0e10cSrcweir xTempOutStream->writeBytes( aSigData ); 551cdf0e10cSrcweir 552cdf0e10cSrcweir // write the rest of the stream 553cdf0e10cSrcweir ::comphelper::OStorageHelper::CopyInputToOutput( xInCacheStream, xTempOutStream ); 554cdf0e10cSrcweir 555cdf0e10cSrcweir // write the size of the stream 556cdf0e10cSrcweir sal_Int64 nLength = xTempSeek->getLength() - 40; 557cdf0e10cSrcweir if ( nLength < 0 || nLength >= 0xFFFFFFFF ) 558cdf0e10cSrcweir { 559cdf0e10cSrcweir OSL_ENSURE( sal_False, "Length is not acceptable!" ); 560cdf0e10cSrcweir return; 561cdf0e10cSrcweir } 562cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < 4; nInd++ ) 563cdf0e10cSrcweir { 564cdf0e10cSrcweir aData[nInd] = (sal_Int8)( ( (sal_uInt64) nLength ) % 0x100 ); 565cdf0e10cSrcweir nLength /= 0x100; 566cdf0e10cSrcweir } 567cdf0e10cSrcweir xTempSeek->seek( 36 ); 568cdf0e10cSrcweir xTempOutStream->writeBytes( aData ); 569cdf0e10cSrcweir 570cdf0e10cSrcweir xTempOutStream->flush(); 571cdf0e10cSrcweir 572cdf0e10cSrcweir xTempSeek->seek( 0 ); 573cdf0e10cSrcweir if ( xCachedSeek.is() ) 574cdf0e10cSrcweir xCachedSeek->seek( 0 ); 575cdf0e10cSrcweir } 576cdf0e10cSrcweir else 577cdf0e10cSrcweir throw io::IOException(); // TODO: 578cdf0e10cSrcweir 579cdf0e10cSrcweir // insert the result file as replacement image 580cdf0e10cSrcweir ::rtl::OUString aCacheName = ::rtl::OUString::createFromAscii( "\002OlePres000" ); 581cdf0e10cSrcweir if ( xNameContainer->hasByName( aCacheName ) ) 582cdf0e10cSrcweir xNameContainer->replaceByName( aCacheName, uno::makeAny( xTempFile ) ); 583cdf0e10cSrcweir else 584cdf0e10cSrcweir xNameContainer->insertByName( aCacheName, uno::makeAny( xTempFile ) ); 585cdf0e10cSrcweir 586cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransacted( xNameContainer, uno::UNO_QUERY ); 587cdf0e10cSrcweir if ( !xTransacted.is() ) 588cdf0e10cSrcweir throw uno::RuntimeException(); 589cdf0e10cSrcweir 590cdf0e10cSrcweir xTransacted->commit(); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir //------------------------------------------------------ 594cdf0e10cSrcweir void OleEmbeddedObject::RemoveVisualCache_Impl( const uno::Reference< io::XStream >& xTargetStream ) 595cdf0e10cSrcweir throw ( uno::Exception ) 596cdf0e10cSrcweir { 597cdf0e10cSrcweir OSL_ENSURE( xTargetStream.is(), "Invalid argumant!\n" ); 598cdf0e10cSrcweir if ( !xTargetStream.is() ) 599cdf0e10cSrcweir throw uno::RuntimeException(); 600cdf0e10cSrcweir 601cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 602cdf0e10cSrcweir aArgs[0] <<= xTargetStream; 603cdf0e10cSrcweir aArgs[1] <<= (sal_Bool)sal_True; // do not create copy 604cdf0e10cSrcweir uno::Reference< container::XNameContainer > xNameContainer( 605cdf0e10cSrcweir m_xFactory->createInstanceWithArguments( 606cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLESimpleStorage" ), 607cdf0e10cSrcweir aArgs ), 608cdf0e10cSrcweir uno::UNO_QUERY ); 609cdf0e10cSrcweir 610cdf0e10cSrcweir if ( !xNameContainer.is() ) 611cdf0e10cSrcweir throw uno::RuntimeException(); 612cdf0e10cSrcweir 613cdf0e10cSrcweir for ( sal_uInt8 nInd = 0; nInd < 10; nInd++ ) 614cdf0e10cSrcweir { 615cdf0e10cSrcweir ::rtl::OUString aStreamName = ::rtl::OUString::createFromAscii( "\002OlePres00" ); 616cdf0e10cSrcweir aStreamName += ::rtl::OUString::valueOf( (sal_Int32)nInd ); 617cdf0e10cSrcweir if ( xNameContainer->hasByName( aStreamName ) ) 618cdf0e10cSrcweir xNameContainer->removeByName( aStreamName ); 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir uno::Reference< embed::XTransactedObject > xTransacted( xNameContainer, uno::UNO_QUERY ); 622cdf0e10cSrcweir if ( !xTransacted.is() ) 623cdf0e10cSrcweir throw uno::RuntimeException(); 624cdf0e10cSrcweir 625cdf0e10cSrcweir xTransacted->commit(); 626cdf0e10cSrcweir } 627cdf0e10cSrcweir 628cdf0e10cSrcweir //------------------------------------------------------ 629cdf0e10cSrcweir void OleEmbeddedObject::SetVisReplInStream( sal_Bool bExists ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir m_bVisReplInitialized = sal_True; 632cdf0e10cSrcweir m_bVisReplInStream = bExists; 633cdf0e10cSrcweir } 634cdf0e10cSrcweir 635cdf0e10cSrcweir //------------------------------------------------------ 636cdf0e10cSrcweir sal_Bool OleEmbeddedObject::HasVisReplInStream() 637cdf0e10cSrcweir { 638cdf0e10cSrcweir if ( !m_bVisReplInitialized ) 639cdf0e10cSrcweir { 640cdf0e10cSrcweir if ( m_xCachedVisualRepresentation.is() ) 641cdf0e10cSrcweir SetVisReplInStream( sal_True ); 642cdf0e10cSrcweir else 643cdf0e10cSrcweir { 644cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::HasVisualReplInStream, analizing" ); 645cdf0e10cSrcweir 646cdf0e10cSrcweir uno::Reference< io::XInputStream > xStream; 647cdf0e10cSrcweir 648cdf0e10cSrcweir OSL_ENSURE( !m_pOleComponent || m_aTempURL.getLength(), "The temporary file must exist if there is a component!\n" ); 649cdf0e10cSrcweir if ( m_aTempURL.getLength() ) 650cdf0e10cSrcweir { 651cdf0e10cSrcweir try 652cdf0e10cSrcweir { 653cdf0e10cSrcweir // open temporary file for reading 654cdf0e10cSrcweir uno::Reference < ucb::XSimpleFileAccess > xTempAccess( 655cdf0e10cSrcweir m_xFactory->createInstance ( 656cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), 657cdf0e10cSrcweir uno::UNO_QUERY ); 658cdf0e10cSrcweir 659cdf0e10cSrcweir if ( !xTempAccess.is() ) 660cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 661cdf0e10cSrcweir 662cdf0e10cSrcweir xStream = xTempAccess->openFileRead( m_aTempURL ); 663cdf0e10cSrcweir } 664cdf0e10cSrcweir catch( uno::Exception& ) 665cdf0e10cSrcweir {} 666cdf0e10cSrcweir } 667cdf0e10cSrcweir 668cdf0e10cSrcweir if ( !xStream.is() ) 669cdf0e10cSrcweir xStream = m_xObjectStream->getInputStream(); 670cdf0e10cSrcweir 671cdf0e10cSrcweir if ( xStream.is() ) 672cdf0e10cSrcweir { 673cdf0e10cSrcweir sal_Bool bExists = sal_False; 674cdf0e10cSrcweir 675cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 676cdf0e10cSrcweir aArgs[0] <<= xStream; 677cdf0e10cSrcweir aArgs[1] <<= (sal_Bool)sal_True; // do not create copy 678cdf0e10cSrcweir uno::Reference< container::XNameContainer > xNameContainer( 679cdf0e10cSrcweir m_xFactory->createInstanceWithArguments( 680cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLESimpleStorage" ), 681cdf0e10cSrcweir aArgs ), 682cdf0e10cSrcweir uno::UNO_QUERY ); 683cdf0e10cSrcweir 684cdf0e10cSrcweir if ( xNameContainer.is() ) 685cdf0e10cSrcweir { 686cdf0e10cSrcweir for ( sal_uInt8 nInd = 0; nInd < 10 && !bExists; nInd++ ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir ::rtl::OUString aStreamName = ::rtl::OUString::createFromAscii( "\002OlePres00" ); 689cdf0e10cSrcweir aStreamName += ::rtl::OUString::valueOf( (sal_Int32)nInd ); 690cdf0e10cSrcweir try 691cdf0e10cSrcweir { 692cdf0e10cSrcweir bExists = xNameContainer->hasByName( aStreamName ); 693cdf0e10cSrcweir } 694cdf0e10cSrcweir catch( uno::Exception& ) 695cdf0e10cSrcweir {} 696cdf0e10cSrcweir } 697cdf0e10cSrcweir } 698cdf0e10cSrcweir 699cdf0e10cSrcweir SetVisReplInStream( bExists ); 700cdf0e10cSrcweir } 701cdf0e10cSrcweir } 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir return m_bVisReplInStream; 705cdf0e10cSrcweir } 706cdf0e10cSrcweir 707cdf0e10cSrcweir //------------------------------------------------------ 708cdf0e10cSrcweir uno::Reference< io::XStream > OleEmbeddedObject::TryToRetrieveCachedVisualRepresentation_Impl( 709cdf0e10cSrcweir const uno::Reference< io::XStream >& xStream, 710cdf0e10cSrcweir sal_Bool bAllowToRepair50 ) 711cdf0e10cSrcweir throw () 712cdf0e10cSrcweir { 713cdf0e10cSrcweir uno::Reference< io::XStream > xResult; 714cdf0e10cSrcweir 715cdf0e10cSrcweir if ( xStream.is() ) 716cdf0e10cSrcweir { 717cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::TryToRetrieveCachedVisualRepresentation, retrieving" ); 718cdf0e10cSrcweir 719cdf0e10cSrcweir uno::Reference< container::XNameContainer > xNameContainer; 720cdf0e10cSrcweir uno::Sequence< uno::Any > aArgs( 2 ); 721cdf0e10cSrcweir aArgs[0] <<= xStream; 722cdf0e10cSrcweir aArgs[1] <<= (sal_Bool)sal_True; // do not create copy 723cdf0e10cSrcweir try 724cdf0e10cSrcweir { 725cdf0e10cSrcweir xNameContainer = uno::Reference< container::XNameContainer >( 726cdf0e10cSrcweir m_xFactory->createInstanceWithArguments( 727cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.embed.OLESimpleStorage" ), 728cdf0e10cSrcweir aArgs ), 729cdf0e10cSrcweir uno::UNO_QUERY ); 730cdf0e10cSrcweir } 731cdf0e10cSrcweir catch( uno::Exception& ) 732cdf0e10cSrcweir {} 733cdf0e10cSrcweir 734cdf0e10cSrcweir if ( xNameContainer.is() ) 735cdf0e10cSrcweir { 736cdf0e10cSrcweir for ( sal_uInt8 nInd = 0; nInd < 10; nInd++ ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir ::rtl::OUString aStreamName = ::rtl::OUString::createFromAscii( "\002OlePres00" ); 739cdf0e10cSrcweir aStreamName += ::rtl::OUString::valueOf( (sal_Int32)nInd ); 740cdf0e10cSrcweir uno::Reference< io::XStream > xCachedCopyStream; 741cdf0e10cSrcweir try 742cdf0e10cSrcweir { 743cdf0e10cSrcweir if ( ( xNameContainer->getByName( aStreamName ) >>= xCachedCopyStream ) && xCachedCopyStream.is() ) 744cdf0e10cSrcweir { 745cdf0e10cSrcweir xResult = TryToGetAcceptableFormat_Impl( xCachedCopyStream ); 746cdf0e10cSrcweir if ( xResult.is() ) 747cdf0e10cSrcweir break; 748cdf0e10cSrcweir } 749cdf0e10cSrcweir } 750cdf0e10cSrcweir catch( uno::Exception& ) 751cdf0e10cSrcweir {} 752cdf0e10cSrcweir 753cdf0e10cSrcweir if ( nInd == 0 ) 754cdf0e10cSrcweir { 755cdf0e10cSrcweir // to be compatible with the old versions Ole10Native is checked after OlePress000 756cdf0e10cSrcweir aStreamName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\001Ole10Native" ) ); 757cdf0e10cSrcweir try 758cdf0e10cSrcweir { 759cdf0e10cSrcweir if ( ( xNameContainer->getByName( aStreamName ) >>= xCachedCopyStream ) && xCachedCopyStream.is() ) 760cdf0e10cSrcweir { 761cdf0e10cSrcweir xResult = TryToGetAcceptableFormat_Impl( xCachedCopyStream ); 762cdf0e10cSrcweir if ( xResult.is() ) 763cdf0e10cSrcweir break; 764cdf0e10cSrcweir } 765cdf0e10cSrcweir } 766cdf0e10cSrcweir catch( uno::Exception& ) 767cdf0e10cSrcweir {} 768cdf0e10cSrcweir } 769cdf0e10cSrcweir } 770cdf0e10cSrcweir 771cdf0e10cSrcweir try 772cdf0e10cSrcweir { 773cdf0e10cSrcweir if ( bAllowToRepair50 && !xResult.is() ) 774cdf0e10cSrcweir { 775cdf0e10cSrcweir ::rtl::OUString aOrigContName( RTL_CONSTASCII_USTRINGPARAM( "Ole-Object" ) ); 776cdf0e10cSrcweir if ( xNameContainer->hasByName( aOrigContName ) ) 777cdf0e10cSrcweir { 778cdf0e10cSrcweir uno::Reference< embed::XClassifiedObject > xClassified( xNameContainer, uno::UNO_QUERY_THROW ); 779cdf0e10cSrcweir uno::Sequence< sal_Int8 > aClassID; 780cdf0e10cSrcweir if ( MimeConfigurationHelper::ClassIDsEqual( xClassified->getClassID(), MimeConfigurationHelper::GetSequenceClassID( SO3_OUT_CLASSID ) ) ) 781cdf0e10cSrcweir { 782cdf0e10cSrcweir // this is an OLE object wrongly stored in 5.0 format 783cdf0e10cSrcweir // this object must be repaired since SO7 has done it 784cdf0e10cSrcweir 785cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutputStream = xStream->getOutputStream(); 786cdf0e10cSrcweir uno::Reference< io::XTruncate > xTruncate( xOutputStream, uno::UNO_QUERY_THROW ); 787cdf0e10cSrcweir 788cdf0e10cSrcweir uno::Reference< io::XInputStream > xOrigInputStream; 789cdf0e10cSrcweir if ( ( xNameContainer->getByName( aOrigContName ) >>= xOrigInputStream ) 790cdf0e10cSrcweir && xOrigInputStream.is() ) 791cdf0e10cSrcweir { 792cdf0e10cSrcweir // the provided input stream must be based on temporary medium and must be independent 793cdf0e10cSrcweir // from the stream the storage is based on 794cdf0e10cSrcweir uno::Reference< io::XSeekable > xOrigSeekable( xOrigInputStream, uno::UNO_QUERY ); 795cdf0e10cSrcweir if ( xOrigSeekable.is() ) 796cdf0e10cSrcweir xOrigSeekable->seek( 0 ); 797cdf0e10cSrcweir 798cdf0e10cSrcweir uno::Reference< lang::XComponent > xNameContDisp( xNameContainer, uno::UNO_QUERY_THROW ); 799cdf0e10cSrcweir xNameContDisp->dispose(); // free the original stream 800cdf0e10cSrcweir 801cdf0e10cSrcweir xTruncate->truncate(); 802cdf0e10cSrcweir ::comphelper::OStorageHelper::CopyInputToOutput( xOrigInputStream, xOutputStream ); 803cdf0e10cSrcweir xOutputStream->flush(); 804cdf0e10cSrcweir 805cdf0e10cSrcweir if ( xStream == m_xObjectStream ) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir if ( m_aTempURL.getLength() ) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir // this is the own stream, so the temporary URL must be cleaned if it exists 810cdf0e10cSrcweir KillFile_Impl( m_aTempURL, m_xFactory ); 811cdf0e10cSrcweir m_aTempURL = ::rtl::OUString(); 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir #ifdef WNT 815cdf0e10cSrcweir // retry to create the component after recovering 816cdf0e10cSrcweir GetRidOfComponent(); 817cdf0e10cSrcweir 818cdf0e10cSrcweir try 819cdf0e10cSrcweir { 820cdf0e10cSrcweir CreateOleComponentAndLoad_Impl( NULL ); 821cdf0e10cSrcweir m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction 822cdf0e10cSrcweir } 823cdf0e10cSrcweir catch( uno::Exception& ) 824cdf0e10cSrcweir { 825cdf0e10cSrcweir GetRidOfComponent(); 826cdf0e10cSrcweir } 827cdf0e10cSrcweir #endif 828cdf0e10cSrcweir } 829cdf0e10cSrcweir 830cdf0e10cSrcweir xResult = TryToRetrieveCachedVisualRepresentation_Impl( xStream, sal_False ); 831cdf0e10cSrcweir } 832cdf0e10cSrcweir } 833cdf0e10cSrcweir } 834cdf0e10cSrcweir } 835cdf0e10cSrcweir } 836cdf0e10cSrcweir catch( uno::Exception& ) 837cdf0e10cSrcweir {} 838cdf0e10cSrcweir } 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir return xResult; 842cdf0e10cSrcweir } 843cdf0e10cSrcweir 844cdf0e10cSrcweir //------------------------------------------------------ 845cdf0e10cSrcweir void OleEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage, 846cdf0e10cSrcweir const uno::Reference< io::XStream >& xNewObjectStream, 847cdf0e10cSrcweir const ::rtl::OUString& aNewName ) 848cdf0e10cSrcweir { 849cdf0e10cSrcweir if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) ) 850cdf0e10cSrcweir { 851cdf0e10cSrcweir OSL_ENSURE( xNewObjectStream == m_xObjectStream, "The streams must be the same!\n" ); 852cdf0e10cSrcweir return; 853cdf0e10cSrcweir } 854cdf0e10cSrcweir 855cdf0e10cSrcweir try { 856cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent( m_xObjectStream, uno::UNO_QUERY ); 857cdf0e10cSrcweir OSL_ENSURE( !m_xObjectStream.is() || xComponent.is(), "Wrong stream implementation!" ); 858cdf0e10cSrcweir if ( xComponent.is() ) 859cdf0e10cSrcweir xComponent->dispose(); 860cdf0e10cSrcweir } 861cdf0e10cSrcweir catch ( uno::Exception& ) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir } 864cdf0e10cSrcweir 865cdf0e10cSrcweir m_xObjectStream = xNewObjectStream; 866cdf0e10cSrcweir m_xParentStorage = xNewParentStorage; 867cdf0e10cSrcweir m_aEntryName = aNewName; 868cdf0e10cSrcweir } 869cdf0e10cSrcweir 870cdf0e10cSrcweir //------------------------------------------------------ 871cdf0e10cSrcweir void OleEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStorage >& xNewParentStorage, 872cdf0e10cSrcweir const ::rtl::OUString& aNewName ) 873cdf0e10cSrcweir { 874cdf0e10cSrcweir if ( xNewParentStorage == m_xParentStorage && aNewName.equals( m_aEntryName ) ) 875cdf0e10cSrcweir return; 876cdf0e10cSrcweir 877cdf0e10cSrcweir sal_Int32 nStreamMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE; 878cdf0e10cSrcweir 879cdf0e10cSrcweir uno::Reference< io::XStream > xNewOwnStream = xNewParentStorage->openStreamElement( aNewName, nStreamMode ); 880cdf0e10cSrcweir OSL_ENSURE( xNewOwnStream.is(), "The method can not return empty reference!" ); 881cdf0e10cSrcweir 882cdf0e10cSrcweir SwitchOwnPersistence( xNewParentStorage, xNewOwnStream, aNewName ); 883cdf0e10cSrcweir } 884cdf0e10cSrcweir 885cdf0e10cSrcweir #ifdef WNT 886cdf0e10cSrcweir //---------------------------------------------- 887cdf0e10cSrcweir sal_Bool OleEmbeddedObject::SaveObject_Impl() 888cdf0e10cSrcweir { 889cdf0e10cSrcweir sal_Bool bResult = sal_False; 890cdf0e10cSrcweir 891cdf0e10cSrcweir if ( m_xClientSite.is() ) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir try 894cdf0e10cSrcweir { 895cdf0e10cSrcweir m_xClientSite->saveObject(); 896cdf0e10cSrcweir bResult = sal_True; 897cdf0e10cSrcweir } 898cdf0e10cSrcweir catch( uno::Exception& ) 899cdf0e10cSrcweir { 900cdf0e10cSrcweir } 901cdf0e10cSrcweir } 902cdf0e10cSrcweir 903cdf0e10cSrcweir return bResult; 904cdf0e10cSrcweir } 905cdf0e10cSrcweir 906cdf0e10cSrcweir //---------------------------------------------- 907cdf0e10cSrcweir sal_Bool OleEmbeddedObject::OnShowWindow_Impl( sal_Bool bShow ) 908cdf0e10cSrcweir { 909cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 910cdf0e10cSrcweir 911cdf0e10cSrcweir sal_Bool bResult = sal_False; 912cdf0e10cSrcweir 913cdf0e10cSrcweir OSL_ENSURE( m_nObjectState != -1, "The object has no persistence!\n" ); 914cdf0e10cSrcweir OSL_ENSURE( m_nObjectState != embed::EmbedStates::LOADED, "The object get OnShowWindow in loaded state!\n" ); 915cdf0e10cSrcweir if ( m_nObjectState == -1 || m_nObjectState == embed::EmbedStates::LOADED ) 916cdf0e10cSrcweir return sal_False; 917cdf0e10cSrcweir 918cdf0e10cSrcweir // the object is either activated or deactivated 919cdf0e10cSrcweir sal_Int32 nOldState = m_nObjectState; 920cdf0e10cSrcweir if ( bShow && m_nObjectState == embed::EmbedStates::RUNNING ) 921cdf0e10cSrcweir { 922cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::ACTIVE; 923cdf0e10cSrcweir m_aVerbExecutionController.ObjectIsActive(); 924cdf0e10cSrcweir 925cdf0e10cSrcweir aGuard.clear(); 926cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ); 927cdf0e10cSrcweir } 928cdf0e10cSrcweir else if ( !bShow && m_nObjectState == embed::EmbedStates::ACTIVE ) 929cdf0e10cSrcweir { 930cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 931cdf0e10cSrcweir aGuard.clear(); 932cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ); 933cdf0e10cSrcweir } 934cdf0e10cSrcweir 935cdf0e10cSrcweir if ( m_xClientSite.is() ) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir try 938cdf0e10cSrcweir { 939cdf0e10cSrcweir m_xClientSite->visibilityChanged( bShow ); 940cdf0e10cSrcweir bResult = sal_True; 941cdf0e10cSrcweir } 942cdf0e10cSrcweir catch( uno::Exception& ) 943cdf0e10cSrcweir { 944cdf0e10cSrcweir } 945cdf0e10cSrcweir } 946cdf0e10cSrcweir 947cdf0e10cSrcweir return bResult; 948cdf0e10cSrcweir } 949cdf0e10cSrcweir 950cdf0e10cSrcweir //------------------------------------------------------ 951cdf0e10cSrcweir void OleEmbeddedObject::OnIconChanged_Impl() 952cdf0e10cSrcweir { 953cdf0e10cSrcweir // TODO/LATER: currently this notification seems to be impossible 954cdf0e10cSrcweir // MakeEventListenerNotification_Impl( ::rtl::OUString::createFromAscii( "OnIconChanged" ) ); 955cdf0e10cSrcweir } 956cdf0e10cSrcweir 957cdf0e10cSrcweir //------------------------------------------------------ 958cdf0e10cSrcweir void OleEmbeddedObject::OnViewChanged_Impl() 959cdf0e10cSrcweir { 960cdf0e10cSrcweir if ( m_bDisposed ) 961cdf0e10cSrcweir throw lang::DisposedException(); 962cdf0e10cSrcweir 963cdf0e10cSrcweir // For performance reasons the notification currently is ignored, STAMPIT object is the exception, 964cdf0e10cSrcweir // it can never be active and never call SaveObject, so it is the only way to detect that it is changed 965cdf0e10cSrcweir 966cdf0e10cSrcweir // ==== the STAMPIT related solution ============================= 967cdf0e10cSrcweir // the following variable is used to detect whether the object was modified during verb execution 968cdf0e10cSrcweir m_aVerbExecutionController.ModificationNotificationIsDone(); 969cdf0e10cSrcweir 970cdf0e10cSrcweir // The following things are controlled by VerbExecutionController: 971cdf0e10cSrcweir // - if the verb execution is in progress and the view is changed the object will be stored 972cdf0e10cSrcweir // after the execution, so there is no need to send the notification. 973cdf0e10cSrcweir // - the STAMPIT object can never be active. 974cdf0e10cSrcweir if ( m_aVerbExecutionController.CanDoNotification() 975cdf0e10cSrcweir && m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE ) 976cdf0e10cSrcweir { 977cdf0e10cSrcweir OSL_ENSURE( MimeConfigurationHelper::ClassIDsEqual( m_aClassID, MimeConfigurationHelper::GetSequenceClassID( 0x852ee1c9, 0x9058, 0x44ba, 0x8c,0x6c,0x0c,0x5f,0xc6,0x6b,0xdb,0x8d ) ) 978cdf0e10cSrcweir || MimeConfigurationHelper::ClassIDsEqual( m_aClassID, MimeConfigurationHelper::GetSequenceClassID( 0xcf1b4491, 0xbea3, 0x4c9f, 0xa7,0x0f,0x22,0x1b,0x1e,0xca,0xef,0x3e ) ), 979cdf0e10cSrcweir "Expected to be triggered for STAMPIT only! Please contact developers!\n" ); 980cdf0e10cSrcweir 981cdf0e10cSrcweir // The view is changed while the object is in running state, save the new object 982cdf0e10cSrcweir m_xCachedVisualRepresentation = uno::Reference< io::XStream >(); 983cdf0e10cSrcweir SaveObject_Impl(); 984cdf0e10cSrcweir MakeEventListenerNotification_Impl( ::rtl::OUString::createFromAscii( "OnVisAreaChanged" ) ); 985cdf0e10cSrcweir } 986cdf0e10cSrcweir // =============================================================== 987cdf0e10cSrcweir } 988cdf0e10cSrcweir 989cdf0e10cSrcweir //------------------------------------------------------ 990cdf0e10cSrcweir void OleEmbeddedObject::OnClosed_Impl() 991cdf0e10cSrcweir { 992cdf0e10cSrcweir if ( m_bDisposed ) 993cdf0e10cSrcweir throw lang::DisposedException(); 994cdf0e10cSrcweir 995cdf0e10cSrcweir if ( m_nObjectState != embed::EmbedStates::LOADED ) 996cdf0e10cSrcweir { 997cdf0e10cSrcweir sal_Int32 nOldState = m_nObjectState; 998cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::LOADED; 999cdf0e10cSrcweir StateChangeNotification_Impl( sal_False, nOldState, m_nObjectState ); 1000cdf0e10cSrcweir } 1001cdf0e10cSrcweir } 1002cdf0e10cSrcweir 1003cdf0e10cSrcweir //------------------------------------------------------ 1004cdf0e10cSrcweir ::rtl::OUString OleEmbeddedObject::CreateTempURLEmpty_Impl() 1005cdf0e10cSrcweir { 1006cdf0e10cSrcweir OSL_ENSURE( !m_aTempURL.getLength(), "The object has already the temporary file!" ); 1007cdf0e10cSrcweir m_aTempURL = GetNewTempFileURL_Impl( m_xFactory ); 1008cdf0e10cSrcweir 1009cdf0e10cSrcweir return m_aTempURL; 1010cdf0e10cSrcweir } 1011cdf0e10cSrcweir 1012cdf0e10cSrcweir //------------------------------------------------------ 1013cdf0e10cSrcweir ::rtl::OUString OleEmbeddedObject::GetTempURL_Impl() 1014cdf0e10cSrcweir { 1015cdf0e10cSrcweir if ( !m_aTempURL.getLength() ) 1016cdf0e10cSrcweir { 1017cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::GetTempURL_Impl, tempfile creation" ); 1018cdf0e10cSrcweir 1019cdf0e10cSrcweir // if there is no temporary file, it will be created from the own entry 1020cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xOptParStorage( m_xParentStorage, uno::UNO_QUERY ); 1021cdf0e10cSrcweir if ( xOptParStorage.is() ) 1022cdf0e10cSrcweir { 1023cdf0e10cSrcweir m_aTempURL = GetNewFilledTempFile_Impl( xOptParStorage, m_aEntryName, m_xFactory ); 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir else if ( m_xObjectStream.is() ) 1026cdf0e10cSrcweir { 1027cdf0e10cSrcweir // load object from the stream 1028cdf0e10cSrcweir uno::Reference< io::XInputStream > xInStream = m_xObjectStream->getInputStream(); 1029cdf0e10cSrcweir if ( !xInStream.is() ) 1030cdf0e10cSrcweir throw io::IOException(); // TODO: access denied 1031cdf0e10cSrcweir 1032cdf0e10cSrcweir m_aTempURL = GetNewFilledTempFile_Impl( xInStream, m_xFactory ); 1033cdf0e10cSrcweir } 1034cdf0e10cSrcweir } 1035cdf0e10cSrcweir 1036cdf0e10cSrcweir return m_aTempURL; 1037cdf0e10cSrcweir } 1038cdf0e10cSrcweir 1039cdf0e10cSrcweir //------------------------------------------------------ 1040cdf0e10cSrcweir void OleEmbeddedObject::CreateOleComponent_Impl( OleComponent* pOleComponent ) 1041cdf0e10cSrcweir { 1042cdf0e10cSrcweir if ( !m_pOleComponent ) 1043cdf0e10cSrcweir { 1044cdf0e10cSrcweir m_pOleComponent = pOleComponent ? pOleComponent : new OleComponent( m_xFactory, this ); 1045cdf0e10cSrcweir m_pOleComponent->acquire(); // TODO: needs holder? 1046cdf0e10cSrcweir 1047cdf0e10cSrcweir if ( !m_xClosePreventer.is() ) 1048cdf0e10cSrcweir m_xClosePreventer = uno::Reference< util::XCloseListener >( 1049cdf0e10cSrcweir static_cast< ::cppu::OWeakObject* >( new OClosePreventer ), 1050cdf0e10cSrcweir uno::UNO_QUERY ); 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir m_pOleComponent->addCloseListener( m_xClosePreventer ); 1053cdf0e10cSrcweir } 1054cdf0e10cSrcweir } 1055cdf0e10cSrcweir 1056cdf0e10cSrcweir //------------------------------------------------------ 1057cdf0e10cSrcweir void OleEmbeddedObject::CreateOleComponentAndLoad_Impl( OleComponent* pOleComponent ) 1058cdf0e10cSrcweir { 1059cdf0e10cSrcweir if ( !m_pOleComponent ) 1060cdf0e10cSrcweir { 1061cdf0e10cSrcweir if ( !m_xObjectStream.is() ) 1062cdf0e10cSrcweir throw uno::RuntimeException(); 1063cdf0e10cSrcweir 1064cdf0e10cSrcweir CreateOleComponent_Impl( pOleComponent ); 1065cdf0e10cSrcweir 1066cdf0e10cSrcweir // after the loading the object can appear as a link 1067cdf0e10cSrcweir // will be detected later by olecomponent 1068cdf0e10cSrcweir 1069cdf0e10cSrcweir GetTempURL_Impl(); 1070cdf0e10cSrcweir if ( !m_aTempURL.getLength() ) 1071cdf0e10cSrcweir throw uno::RuntimeException(); // TODO 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir m_pOleComponent->LoadEmbeddedObject( m_aTempURL ); 1074cdf0e10cSrcweir } 1075cdf0e10cSrcweir } 1076cdf0e10cSrcweir 1077cdf0e10cSrcweir //------------------------------------------------------ 1078cdf0e10cSrcweir void OleEmbeddedObject::CreateOleComponentFromClipboard_Impl( OleComponent* pOleComponent ) 1079cdf0e10cSrcweir { 1080cdf0e10cSrcweir if ( !m_pOleComponent ) 1081cdf0e10cSrcweir { 1082cdf0e10cSrcweir if ( !m_xObjectStream.is() ) 1083cdf0e10cSrcweir throw uno::RuntimeException(); 1084cdf0e10cSrcweir 1085cdf0e10cSrcweir CreateOleComponent_Impl( pOleComponent ); 1086cdf0e10cSrcweir 1087cdf0e10cSrcweir // after the loading the object can appear as a link 1088cdf0e10cSrcweir // will be detected later by olecomponent 1089cdf0e10cSrcweir m_pOleComponent->CreateObjectFromClipboard(); 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir } 1092cdf0e10cSrcweir 1093cdf0e10cSrcweir //------------------------------------------------------ 1094cdf0e10cSrcweir uno::Reference< io::XOutputStream > OleEmbeddedObject::GetStreamForSaving() 1095cdf0e10cSrcweir { 1096cdf0e10cSrcweir if ( !m_xObjectStream.is() ) 1097cdf0e10cSrcweir throw uno::RuntimeException(); //TODO: 1098cdf0e10cSrcweir 1099cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream(); 1100cdf0e10cSrcweir if ( !xOutStream.is() ) 1101cdf0e10cSrcweir throw io::IOException(); //TODO: access denied 1102cdf0e10cSrcweir 1103cdf0e10cSrcweir uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY ); 1104cdf0e10cSrcweir if ( !xTruncate.is() ) 1105cdf0e10cSrcweir throw uno::RuntimeException(); //TODO: 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir xTruncate->truncate(); 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir return xOutStream; 1110cdf0e10cSrcweir } 1111cdf0e10cSrcweir 1112cdf0e10cSrcweir //---------------------------------------------- 1113cdf0e10cSrcweir void OleEmbeddedObject::StoreObjectToStream( uno::Reference< io::XOutputStream > xOutStream ) 1114cdf0e10cSrcweir throw ( uno::Exception ) 1115cdf0e10cSrcweir { 1116cdf0e10cSrcweir // this method should be used only on windows 1117cdf0e10cSrcweir if ( m_pOleComponent ) 1118cdf0e10cSrcweir m_pOleComponent->StoreOwnTmpIfNecessary(); 1119cdf0e10cSrcweir 1120cdf0e10cSrcweir // now all the changes should be in temporary location 1121cdf0e10cSrcweir if ( !m_aTempURL ) 1122cdf0e10cSrcweir throw uno::RuntimeException(); 1123cdf0e10cSrcweir 1124cdf0e10cSrcweir // open temporary file for reading 1125cdf0e10cSrcweir uno::Reference < ucb::XSimpleFileAccess > xTempAccess( 1126cdf0e10cSrcweir m_xFactory->createInstance ( 1127cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "com.sun.star.ucb.SimpleFileAccess" ) ), 1128cdf0e10cSrcweir uno::UNO_QUERY ); 1129cdf0e10cSrcweir 1130cdf0e10cSrcweir if ( !xTempAccess.is() ) 1131cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: 1132cdf0e10cSrcweir 1133cdf0e10cSrcweir uno::Reference< io::XInputStream > xTempInStream = xTempAccess->openFileRead( m_aTempURL ); 1134cdf0e10cSrcweir OSL_ENSURE( xTempInStream.is(), "The object's temporary file can not be reopened for reading!\n" ); 1135cdf0e10cSrcweir 1136cdf0e10cSrcweir // TODO: use bStoreVisReplace 1137cdf0e10cSrcweir 1138cdf0e10cSrcweir if ( xTempInStream.is() ) 1139cdf0e10cSrcweir { 1140cdf0e10cSrcweir // write all the contents to XOutStream 1141cdf0e10cSrcweir uno::Reference< io::XTruncate > xTrunc( xOutStream, uno::UNO_QUERY ); 1142cdf0e10cSrcweir if ( !xTrunc.is() ) 1143cdf0e10cSrcweir throw uno::RuntimeException(); //TODO: 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir xTrunc->truncate(); 1146cdf0e10cSrcweir 1147cdf0e10cSrcweir ::comphelper::OStorageHelper::CopyInputToOutput( xTempInStream, xOutStream ); 1148cdf0e10cSrcweir } 1149cdf0e10cSrcweir else 1150cdf0e10cSrcweir throw io::IOException(); // TODO: 1151cdf0e10cSrcweir 1152cdf0e10cSrcweir // TODO: should the view replacement be in the stream ??? 1153cdf0e10cSrcweir // probably it must be specified on storing 1154cdf0e10cSrcweir } 1155cdf0e10cSrcweir #endif 1156cdf0e10cSrcweir //------------------------------------------------------ 1157cdf0e10cSrcweir void OleEmbeddedObject::StoreToLocation_Impl( 1158cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 1159cdf0e10cSrcweir const ::rtl::OUString& sEntName, 1160cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& /*lArguments*/, 1161cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs, 1162cdf0e10cSrcweir sal_Bool bSaveAs ) 1163cdf0e10cSrcweir throw ( uno::Exception ) 1164cdf0e10cSrcweir { 1165cdf0e10cSrcweir // TODO: use lObjArgs 1166cdf0e10cSrcweir // TODO: exchange StoreVisualReplacement by SO file format version? 1167cdf0e10cSrcweir 1168cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1169cdf0e10cSrcweir { 1170cdf0e10cSrcweir // the object is still not loaded 1171cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), 1172cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1173cdf0e10cSrcweir } 1174cdf0e10cSrcweir 1175cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1176cdf0e10cSrcweir throw embed::WrongStateException( 1177cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1178cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1179cdf0e10cSrcweir 1180cdf0e10cSrcweir OSL_ENSURE( m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" ); 1181cdf0e10cSrcweir 1182cdf0e10cSrcweir sal_Bool bVisReplIsStored = sal_False; 1183cdf0e10cSrcweir 1184cdf0e10cSrcweir sal_Bool bTryOptimization = sal_False; 1185cdf0e10cSrcweir sal_Bool bStoreVis = m_bStoreVisRepl; 1186cdf0e10cSrcweir uno::Reference< io::XStream > xCachedVisualRepresentation; 1187cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < lObjArgs.getLength(); nInd++ ) 1188cdf0e10cSrcweir { 1189cdf0e10cSrcweir if ( lObjArgs[nInd].Name.equalsAscii( "StoreVisualReplacement" ) ) 1190cdf0e10cSrcweir lObjArgs[nInd].Value >>= bStoreVis; 1191cdf0e10cSrcweir else if ( lObjArgs[nInd].Name.equalsAscii( "VisualReplacement" ) ) 1192cdf0e10cSrcweir lObjArgs[nInd].Value >>= xCachedVisualRepresentation; 1193cdf0e10cSrcweir else if ( lObjArgs[nInd].Name.equalsAscii( "CanTryOptimization" ) ) 1194cdf0e10cSrcweir lObjArgs[nInd].Value >>= bTryOptimization; 1195cdf0e10cSrcweir } 1196cdf0e10cSrcweir 1197cdf0e10cSrcweir // ignore visual representation provided from outside if it should not be stored 1198cdf0e10cSrcweir if ( !bStoreVis ) 1199cdf0e10cSrcweir xCachedVisualRepresentation = uno::Reference< io::XStream >(); 1200cdf0e10cSrcweir 1201cdf0e10cSrcweir if ( bStoreVis && !HasVisReplInStream() && !xCachedVisualRepresentation.is() ) 1202cdf0e10cSrcweir throw io::IOException(); // TODO: there is no cached visual representation and nothing is provided from outside 1203cdf0e10cSrcweir 1204cdf0e10cSrcweir // if the representation is provided from outside it should be copied to a local stream 1205cdf0e10cSrcweir sal_Bool bNeedLocalCache = xCachedVisualRepresentation.is(); 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir uno::Reference< io::XStream > xTargetStream; 1208cdf0e10cSrcweir 1209cdf0e10cSrcweir sal_Bool bStoreLoaded = sal_False; 1210cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::LOADED 1211cdf0e10cSrcweir #ifdef WNT 1212cdf0e10cSrcweir // if the object was NOT modified after storing it can be just copied 1213cdf0e10cSrcweir // as if it was in loaded state 1214cdf0e10cSrcweir || ( m_pOleComponent && !m_pOleComponent->IsDirty() ) 1215cdf0e10cSrcweir #endif 1216cdf0e10cSrcweir ) 1217cdf0e10cSrcweir { 1218cdf0e10cSrcweir sal_Bool bOptimizedCopyingDone = sal_False; 1219cdf0e10cSrcweir 1220cdf0e10cSrcweir if ( bTryOptimization && bStoreVis == HasVisReplInStream() ) 1221cdf0e10cSrcweir { 1222cdf0e10cSrcweir try 1223cdf0e10cSrcweir { 1224cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xSourceOptStor( m_xParentStorage, uno::UNO_QUERY_THROW ); 1225cdf0e10cSrcweir uno::Reference< embed::XOptimizedStorage > xTargetOptStor( xStorage, uno::UNO_QUERY_THROW ); 1226cdf0e10cSrcweir xSourceOptStor->copyElementDirectlyTo( m_aEntryName, xTargetOptStor, sEntName ); 1227cdf0e10cSrcweir bOptimizedCopyingDone = sal_True; 1228cdf0e10cSrcweir } 1229cdf0e10cSrcweir catch( uno::Exception& ) 1230cdf0e10cSrcweir { 1231cdf0e10cSrcweir } 1232cdf0e10cSrcweir } 1233cdf0e10cSrcweir 1234cdf0e10cSrcweir if ( !bOptimizedCopyingDone ) 1235cdf0e10cSrcweir { 1236cdf0e10cSrcweir // if optimized copying fails a normal one should be tried 1237cdf0e10cSrcweir m_xParentStorage->copyElementTo( m_aEntryName, xStorage, sEntName ); 1238cdf0e10cSrcweir } 1239cdf0e10cSrcweir 1240cdf0e10cSrcweir // the locally retrieved representation is always preferable 1241cdf0e10cSrcweir // since the object is in loaded state the representation is unchanged 1242cdf0e10cSrcweir if ( m_xCachedVisualRepresentation.is() ) 1243cdf0e10cSrcweir { 1244cdf0e10cSrcweir xCachedVisualRepresentation = m_xCachedVisualRepresentation; 1245cdf0e10cSrcweir bNeedLocalCache = sal_False; 1246cdf0e10cSrcweir } 1247cdf0e10cSrcweir 1248cdf0e10cSrcweir bVisReplIsStored = HasVisReplInStream(); 1249cdf0e10cSrcweir bStoreLoaded = sal_True; 1250cdf0e10cSrcweir } 1251cdf0e10cSrcweir #ifdef WNT 1252cdf0e10cSrcweir else if ( m_pOleComponent ) 1253cdf0e10cSrcweir { 1254cdf0e10cSrcweir xTargetStream = 1255cdf0e10cSrcweir xStorage->openStreamElement( sEntName, embed::ElementModes::READWRITE ); 1256cdf0e10cSrcweir if ( !xTargetStream.is() ) 1257cdf0e10cSrcweir throw io::IOException(); //TODO: access denied 1258cdf0e10cSrcweir 1259cdf0e10cSrcweir SetStreamMediaType_Impl( xTargetStream, ::rtl::OUString::createFromAscii( "application/vnd.sun.star.oleobject" ) ); 1260cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutStream = xTargetStream->getOutputStream(); 1261cdf0e10cSrcweir if ( !xOutStream.is() ) 1262cdf0e10cSrcweir throw io::IOException(); //TODO: access denied 1263cdf0e10cSrcweir 1264cdf0e10cSrcweir StoreObjectToStream( xOutStream ); 1265cdf0e10cSrcweir bVisReplIsStored = sal_True; 1266cdf0e10cSrcweir 1267cdf0e10cSrcweir if ( bSaveAs ) 1268cdf0e10cSrcweir { 1269cdf0e10cSrcweir // no need to do it on StoreTo since in this case the replacement is in the stream 1270cdf0e10cSrcweir // and there is no need to cache it even if it is thrown away because the object 1271cdf0e10cSrcweir // is not changed by StoreTo action 1272cdf0e10cSrcweir 1273cdf0e10cSrcweir uno::Reference< io::XStream > xTmpCVRepresentation = 1274cdf0e10cSrcweir TryToRetrieveCachedVisualRepresentation_Impl( xTargetStream ); 1275cdf0e10cSrcweir 1276cdf0e10cSrcweir // the locally retrieved representation is always preferable 1277cdf0e10cSrcweir if ( xTmpCVRepresentation.is() ) 1278cdf0e10cSrcweir { 1279cdf0e10cSrcweir xCachedVisualRepresentation = xTmpCVRepresentation; 1280cdf0e10cSrcweir bNeedLocalCache = sal_False; 1281cdf0e10cSrcweir } 1282cdf0e10cSrcweir } 1283cdf0e10cSrcweir } 1284cdf0e10cSrcweir #endif 1285cdf0e10cSrcweir else 1286cdf0e10cSrcweir { 1287cdf0e10cSrcweir throw io::IOException(); // TODO 1288cdf0e10cSrcweir } 1289cdf0e10cSrcweir 1290cdf0e10cSrcweir if ( !xTargetStream.is() ) 1291cdf0e10cSrcweir { 1292cdf0e10cSrcweir xTargetStream = 1293cdf0e10cSrcweir xStorage->openStreamElement( sEntName, embed::ElementModes::READWRITE ); 1294cdf0e10cSrcweir if ( !xTargetStream.is() ) 1295cdf0e10cSrcweir throw io::IOException(); //TODO: access denied 1296cdf0e10cSrcweir } 1297cdf0e10cSrcweir 1298cdf0e10cSrcweir LetCommonStoragePassBeUsed_Impl( xTargetStream ); 1299cdf0e10cSrcweir 1300cdf0e10cSrcweir if ( bStoreVis != bVisReplIsStored ) 1301cdf0e10cSrcweir { 1302cdf0e10cSrcweir if ( bStoreVis ) 1303cdf0e10cSrcweir { 1304cdf0e10cSrcweir if ( !xCachedVisualRepresentation.is() ) 1305cdf0e10cSrcweir xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( xTargetStream ); 1306cdf0e10cSrcweir 1307cdf0e10cSrcweir OSL_ENSURE( xCachedVisualRepresentation.is(), "No representation is available!" ); 1308cdf0e10cSrcweir 1309cdf0e10cSrcweir // the following copying will be done in case it is SaveAs anyway 1310cdf0e10cSrcweir // if it is not SaveAs the seekable access is not required currently 1311cdf0e10cSrcweir // TODO/LATER: may be required in future 1312cdf0e10cSrcweir if ( bSaveAs ) 1313cdf0e10cSrcweir { 1314cdf0e10cSrcweir uno::Reference< io::XSeekable > xCachedSeek( xCachedVisualRepresentation, uno::UNO_QUERY ); 1315cdf0e10cSrcweir if ( !xCachedSeek.is() ) 1316cdf0e10cSrcweir { 1317cdf0e10cSrcweir xCachedVisualRepresentation 1318cdf0e10cSrcweir = GetNewFilledTempStream_Impl( xCachedVisualRepresentation->getInputStream() ); 1319cdf0e10cSrcweir bNeedLocalCache = sal_False; 1320cdf0e10cSrcweir } 1321cdf0e10cSrcweir } 1322cdf0e10cSrcweir 1323cdf0e10cSrcweir InsertVisualCache_Impl( xTargetStream, xCachedVisualRepresentation ); 1324cdf0e10cSrcweir } 1325cdf0e10cSrcweir else 1326cdf0e10cSrcweir { 1327cdf0e10cSrcweir // the removed representation could be cached by this method 1328cdf0e10cSrcweir if ( !xCachedVisualRepresentation.is() ) 1329cdf0e10cSrcweir xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( xTargetStream ); 1330cdf0e10cSrcweir 1331cdf0e10cSrcweir RemoveVisualCache_Impl( xTargetStream ); 1332cdf0e10cSrcweir } 1333cdf0e10cSrcweir } 1334cdf0e10cSrcweir 1335cdf0e10cSrcweir if ( bSaveAs ) 1336cdf0e10cSrcweir { 1337cdf0e10cSrcweir m_bWaitSaveCompleted = sal_True; 1338cdf0e10cSrcweir m_xNewObjectStream = xTargetStream; 1339cdf0e10cSrcweir m_xNewParentStorage = xStorage; 1340cdf0e10cSrcweir m_aNewEntryName = sEntName; 1341cdf0e10cSrcweir m_bNewVisReplInStream = bStoreVis; 1342cdf0e10cSrcweir m_bStoreLoaded = bStoreLoaded; 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir if ( xCachedVisualRepresentation.is() ) 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir if ( bNeedLocalCache ) 1347cdf0e10cSrcweir m_xNewCachedVisRepl = GetNewFilledTempStream_Impl( xCachedVisualRepresentation->getInputStream() ); 1348cdf0e10cSrcweir else 1349cdf0e10cSrcweir m_xNewCachedVisRepl = xCachedVisualRepresentation; 1350cdf0e10cSrcweir } 1351cdf0e10cSrcweir 1352cdf0e10cSrcweir // TODO: register listeners for storages above, in case they are disposed 1353cdf0e10cSrcweir // an exception will be thrown on saveCompleted( true ) 1354cdf0e10cSrcweir } 1355cdf0e10cSrcweir else 1356cdf0e10cSrcweir { 1357cdf0e10cSrcweir uno::Reference< lang::XComponent > xComp( xTargetStream, uno::UNO_QUERY ); 1358cdf0e10cSrcweir if ( xComp.is() ) 1359cdf0e10cSrcweir { 1360cdf0e10cSrcweir try { 1361cdf0e10cSrcweir xComp->dispose(); 1362cdf0e10cSrcweir } catch( uno::Exception& ) 1363cdf0e10cSrcweir { 1364cdf0e10cSrcweir } 1365cdf0e10cSrcweir } 1366cdf0e10cSrcweir } 1367cdf0e10cSrcweir } 1368cdf0e10cSrcweir 1369cdf0e10cSrcweir //------------------------------------------------------ 1370cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::setPersistentEntry( 1371cdf0e10cSrcweir const uno::Reference< embed::XStorage >& xStorage, 1372cdf0e10cSrcweir const ::rtl::OUString& sEntName, 1373cdf0e10cSrcweir sal_Int32 nEntryConnectionMode, 1374cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 1375cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 1376cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 1377cdf0e10cSrcweir embed::WrongStateException, 1378cdf0e10cSrcweir io::IOException, 1379cdf0e10cSrcweir uno::Exception, 1380cdf0e10cSrcweir uno::RuntimeException ) 1381cdf0e10cSrcweir { 1382cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::setPersistentEntry" ); 1383cdf0e10cSrcweir 1384cdf0e10cSrcweir // begin wrapping related part ==================== 1385cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1386cdf0e10cSrcweir if ( xWrappedObject.is() ) 1387cdf0e10cSrcweir { 1388cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1389cdf0e10cSrcweir xWrappedObject->setPersistentEntry( xStorage, sEntName, nEntryConnectionMode, lArguments, lObjArgs ); 1390cdf0e10cSrcweir return; 1391cdf0e10cSrcweir } 1392cdf0e10cSrcweir // end wrapping related part ==================== 1393cdf0e10cSrcweir 1394cdf0e10cSrcweir // TODO: use lObjArgs 1395cdf0e10cSrcweir 1396cdf0e10cSrcweir // the type of the object must be already set 1397cdf0e10cSrcweir // a kind of typedetection should be done in the factory; 1398cdf0e10cSrcweir // the only exception is object initialized from a stream, 1399cdf0e10cSrcweir // the class ID will be detected from the stream 1400cdf0e10cSrcweir 1401cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1402cdf0e10cSrcweir if ( m_bDisposed ) 1403cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1404cdf0e10cSrcweir 1405cdf0e10cSrcweir if ( !xStorage.is() ) 1406cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 1407cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 1408cdf0e10cSrcweir 1 ); 1409cdf0e10cSrcweir 1410cdf0e10cSrcweir if ( !sEntName.getLength() ) 1411cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 1412cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 1413cdf0e10cSrcweir 2 ); 1414cdf0e10cSrcweir 1415cdf0e10cSrcweir // May be LOADED should be forbidden here ??? 1416cdf0e10cSrcweir if ( ( m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT ) 1417cdf0e10cSrcweir && ( m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) ) 1418cdf0e10cSrcweir { 1419cdf0e10cSrcweir // if the object is not loaded 1420cdf0e10cSrcweir // it can not get persistant representation without initialization 1421cdf0e10cSrcweir 1422cdf0e10cSrcweir // if the object is loaded 1423cdf0e10cSrcweir // it can switch persistant representation only without initialization 1424cdf0e10cSrcweir 1425cdf0e10cSrcweir throw embed::WrongStateException( 1426cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Can't change persistant representation of activated object!\n" ), 1427cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1428cdf0e10cSrcweir } 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1431cdf0e10cSrcweir { 1432cdf0e10cSrcweir if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT ) 1433cdf0e10cSrcweir saveCompleted( ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) ) ); 1434cdf0e10cSrcweir else 1435cdf0e10cSrcweir throw embed::WrongStateException( 1436cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1437cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1438cdf0e10cSrcweir } 1439cdf0e10cSrcweir 1440cdf0e10cSrcweir uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY ); 1441cdf0e10cSrcweir if ( !xNameAccess.is() ) 1442cdf0e10cSrcweir throw uno::RuntimeException(); //TODO 1443cdf0e10cSrcweir 1444cdf0e10cSrcweir // detect entry existence 1445cdf0e10cSrcweir sal_Bool bElExists = xNameAccess->hasByName( sEntName ); 1446cdf0e10cSrcweir 1447cdf0e10cSrcweir m_bReadOnly = sal_False; 1448cdf0e10cSrcweir sal_Int32 nInd = 0; 1449cdf0e10cSrcweir for ( nInd = 0; nInd < lArguments.getLength(); nInd++ ) 1450cdf0e10cSrcweir if ( lArguments[nInd].Name.equalsAscii( "ReadOnly" ) ) 1451cdf0e10cSrcweir lArguments[nInd].Value >>= m_bReadOnly; 1452cdf0e10cSrcweir 1453cdf0e10cSrcweir #ifdef WNT 1454cdf0e10cSrcweir sal_Int32 nStorageMode = m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE; 1455cdf0e10cSrcweir #endif 1456cdf0e10cSrcweir 1457cdf0e10cSrcweir SwitchOwnPersistence( xStorage, sEntName ); 1458cdf0e10cSrcweir 1459cdf0e10cSrcweir for ( nInd = 0; nInd < lObjArgs.getLength(); nInd++ ) 1460cdf0e10cSrcweir if ( lObjArgs[nInd].Name.equalsAscii( "StoreVisualReplacement" ) ) 1461cdf0e10cSrcweir lObjArgs[nInd].Value >>= m_bStoreVisRepl; 1462cdf0e10cSrcweir 1463cdf0e10cSrcweir #ifdef WNT 1464cdf0e10cSrcweir if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT ) 1465cdf0e10cSrcweir { 1466cdf0e10cSrcweir if ( m_bFromClipboard ) 1467cdf0e10cSrcweir { 1468cdf0e10cSrcweir // the object should be initialized from clipboard 1469cdf0e10cSrcweir // inpossibility to initialize the object means error here 1470cdf0e10cSrcweir CreateOleComponentFromClipboard_Impl( NULL ); 1471cdf0e10cSrcweir m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction 1472cdf0e10cSrcweir m_pOleComponent->RunObject(); 1473cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 1474cdf0e10cSrcweir } 1475cdf0e10cSrcweir else if ( bElExists ) 1476cdf0e10cSrcweir { 1477cdf0e10cSrcweir // load object from the stream 1478cdf0e10cSrcweir // after the loading the object can appear as a link 1479cdf0e10cSrcweir // will be detected by olecomponent 1480cdf0e10cSrcweir try 1481cdf0e10cSrcweir { 1482cdf0e10cSrcweir CreateOleComponentAndLoad_Impl( NULL ); 1483cdf0e10cSrcweir m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction 1484cdf0e10cSrcweir } 1485cdf0e10cSrcweir catch( uno::Exception& ) 1486cdf0e10cSrcweir { 1487cdf0e10cSrcweir // TODO/LATER: detect classID of the object if possible 1488cdf0e10cSrcweir // means that the object inprocess server could not be successfuly instantiated 1489cdf0e10cSrcweir GetRidOfComponent(); 1490cdf0e10cSrcweir } 1491cdf0e10cSrcweir 1492cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::LOADED; 1493cdf0e10cSrcweir } 1494cdf0e10cSrcweir else 1495cdf0e10cSrcweir { 1496cdf0e10cSrcweir // create a new object 1497cdf0e10cSrcweir CreateOleComponent_Impl(); 1498cdf0e10cSrcweir m_pOleComponent->CreateNewEmbeddedObject( m_aClassID ); 1499cdf0e10cSrcweir m_pOleComponent->RunObject(); 1500cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 1501cdf0e10cSrcweir } 1502cdf0e10cSrcweir } 1503cdf0e10cSrcweir else 1504cdf0e10cSrcweir { 1505cdf0e10cSrcweir if ( ( nStorageMode & embed::ElementModes::READWRITE ) != embed::ElementModes::READWRITE ) 1506cdf0e10cSrcweir throw io::IOException(); 1507cdf0e10cSrcweir 1508cdf0e10cSrcweir if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT ) 1509cdf0e10cSrcweir { 1510cdf0e10cSrcweir // the document just already changed its stream to store to; 1511cdf0e10cSrcweir // the links to OLE documents switch their persistence in the same way 1512cdf0e10cSrcweir // as normal embedded objects 1513cdf0e10cSrcweir } 1514cdf0e10cSrcweir else if ( nEntryConnectionMode == embed::EntryInitModes::TRUNCATE_INIT ) 1515cdf0e10cSrcweir { 1516cdf0e10cSrcweir // create a new object, that will be stored in specified stream 1517cdf0e10cSrcweir CreateOleComponent_Impl(); 1518cdf0e10cSrcweir 1519cdf0e10cSrcweir m_pOleComponent->CreateNewEmbeddedObject( m_aClassID ); 1520cdf0e10cSrcweir m_pOleComponent->RunObject(); 1521cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 1522cdf0e10cSrcweir } 1523cdf0e10cSrcweir else if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT ) 1524cdf0e10cSrcweir { 1525cdf0e10cSrcweir // use URL ( may be content or stream later ) from MediaDescriptor to initialize object 1526cdf0e10cSrcweir ::rtl::OUString aURL; 1527cdf0e10cSrcweir for ( sal_Int32 nInd = 0; nInd < lArguments.getLength(); nInd++ ) 1528cdf0e10cSrcweir if ( lArguments[nInd].Name.equalsAscii( "URL" ) ) 1529cdf0e10cSrcweir lArguments[nInd].Value >>= aURL; 1530cdf0e10cSrcweir 1531cdf0e10cSrcweir if ( !aURL.getLength() ) 1532cdf0e10cSrcweir throw lang::IllegalArgumentException( 1533cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "Empty URL is provided in the media descriptor!\n" ), 1534cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 1535cdf0e10cSrcweir 4 ); 1536cdf0e10cSrcweir 1537cdf0e10cSrcweir CreateOleComponent_Impl(); 1538cdf0e10cSrcweir 1539cdf0e10cSrcweir // TODO: the m_bIsLink value must be set already 1540cdf0e10cSrcweir if ( !m_bIsLink ) 1541cdf0e10cSrcweir m_pOleComponent->CreateObjectFromFile( aURL ); 1542cdf0e10cSrcweir else 1543cdf0e10cSrcweir m_pOleComponent->CreateLinkFromFile( aURL ); 1544cdf0e10cSrcweir 1545cdf0e10cSrcweir m_pOleComponent->RunObject(); 1546cdf0e10cSrcweir m_aClassID = m_pOleComponent->GetCLSID(); // was not set during consruction 1547cdf0e10cSrcweir 1548cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::RUNNING; 1549cdf0e10cSrcweir } 1550cdf0e10cSrcweir //else if ( nEntryConnectionMode == embed::EntryInitModes::TRANSFERABLE_INIT ) 1551cdf0e10cSrcweir //{ 1552cdf0e10cSrcweir //TODO: 1553cdf0e10cSrcweir //} 1554cdf0e10cSrcweir else 1555cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong connection mode is provided!\n" ), 1556cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 1557cdf0e10cSrcweir 3 ); 1558cdf0e10cSrcweir } 1559cdf0e10cSrcweir #else 1560cdf0e10cSrcweir // On unix the ole object can not do anything except storing itself somewere 1561cdf0e10cSrcweir if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT && bElExists ) 1562cdf0e10cSrcweir { 1563cdf0e10cSrcweir // TODO/LATER: detect classID of the object 1564cdf0e10cSrcweir // can be a real problem for the links 1565cdf0e10cSrcweir 1566cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::LOADED; 1567cdf0e10cSrcweir } 1568cdf0e10cSrcweir else if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT ) 1569cdf0e10cSrcweir { 1570cdf0e10cSrcweir // do nothing, the object has already switched it's persistence 1571cdf0e10cSrcweir } 1572cdf0e10cSrcweir else 1573cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Wrong connection mode is provided!\n" ), 1574cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 1575cdf0e10cSrcweir 3 ); 1576cdf0e10cSrcweir 1577cdf0e10cSrcweir #endif 1578cdf0e10cSrcweir } 1579cdf0e10cSrcweir 1580cdf0e10cSrcweir //------------------------------------------------------ 1581cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::storeToEntry( const uno::Reference< embed::XStorage >& xStorage, 1582cdf0e10cSrcweir const ::rtl::OUString& sEntName, 1583cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 1584cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 1585cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 1586cdf0e10cSrcweir embed::WrongStateException, 1587cdf0e10cSrcweir io::IOException, 1588cdf0e10cSrcweir uno::Exception, 1589cdf0e10cSrcweir uno::RuntimeException ) 1590cdf0e10cSrcweir { 1591cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::storeToEntry" ); 1592cdf0e10cSrcweir 1593cdf0e10cSrcweir // begin wrapping related part ==================== 1594cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1595cdf0e10cSrcweir if ( xWrappedObject.is() ) 1596cdf0e10cSrcweir { 1597cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1598cdf0e10cSrcweir xWrappedObject->storeToEntry( xStorage, sEntName, lArguments, lObjArgs ); 1599cdf0e10cSrcweir return; 1600cdf0e10cSrcweir } 1601cdf0e10cSrcweir // end wrapping related part ==================== 1602cdf0e10cSrcweir 1603cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1604cdf0e10cSrcweir if ( m_bDisposed ) 1605cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1606cdf0e10cSrcweir 1607cdf0e10cSrcweir VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController ); 1608cdf0e10cSrcweir 1609cdf0e10cSrcweir StoreToLocation_Impl( xStorage, sEntName, lArguments, lObjArgs, sal_False ); 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir // TODO: should the listener notification be done? 1612cdf0e10cSrcweir } 1613cdf0e10cSrcweir 1614cdf0e10cSrcweir //------------------------------------------------------ 1615cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::storeAsEntry( const uno::Reference< embed::XStorage >& xStorage, 1616cdf0e10cSrcweir const ::rtl::OUString& sEntName, 1617cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 1618cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 1619cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 1620cdf0e10cSrcweir embed::WrongStateException, 1621cdf0e10cSrcweir io::IOException, 1622cdf0e10cSrcweir uno::Exception, 1623cdf0e10cSrcweir uno::RuntimeException ) 1624cdf0e10cSrcweir { 1625cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::storeAsEntry" ); 1626cdf0e10cSrcweir 1627cdf0e10cSrcweir // begin wrapping related part ==================== 1628cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1629cdf0e10cSrcweir if ( xWrappedObject.is() ) 1630cdf0e10cSrcweir { 1631cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1632cdf0e10cSrcweir xWrappedObject->storeAsEntry( xStorage, sEntName, lArguments, lObjArgs ); 1633cdf0e10cSrcweir return; 1634cdf0e10cSrcweir } 1635cdf0e10cSrcweir // end wrapping related part ==================== 1636cdf0e10cSrcweir 1637cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1638cdf0e10cSrcweir if ( m_bDisposed ) 1639cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1640cdf0e10cSrcweir 1641cdf0e10cSrcweir VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController ); 1642cdf0e10cSrcweir 1643cdf0e10cSrcweir StoreToLocation_Impl( xStorage, sEntName, lArguments, lObjArgs, sal_True ); 1644cdf0e10cSrcweir 1645cdf0e10cSrcweir // TODO: should the listener notification be done here or in saveCompleted? 1646cdf0e10cSrcweir } 1647cdf0e10cSrcweir 1648cdf0e10cSrcweir //------------------------------------------------------ 1649cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::saveCompleted( sal_Bool bUseNew ) 1650cdf0e10cSrcweir throw ( embed::WrongStateException, 1651cdf0e10cSrcweir uno::Exception, 1652cdf0e10cSrcweir uno::RuntimeException ) 1653cdf0e10cSrcweir { 1654cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::saveCompleted" ); 1655cdf0e10cSrcweir 1656cdf0e10cSrcweir // begin wrapping related part ==================== 1657cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1658cdf0e10cSrcweir if ( xWrappedObject.is() ) 1659cdf0e10cSrcweir { 1660cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1661cdf0e10cSrcweir xWrappedObject->saveCompleted( bUseNew ); 1662cdf0e10cSrcweir return; 1663cdf0e10cSrcweir } 1664cdf0e10cSrcweir // end wrapping related part ==================== 1665cdf0e10cSrcweir 1666cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 1667cdf0e10cSrcweir if ( m_bDisposed ) 1668cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1669cdf0e10cSrcweir 1670cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1671cdf0e10cSrcweir { 1672cdf0e10cSrcweir // the object is still not loaded 1673cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), 1674cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1675cdf0e10cSrcweir } 1676cdf0e10cSrcweir 1677cdf0e10cSrcweir // it is allowed to call saveCompleted( false ) for nonstored objects 1678cdf0e10cSrcweir if ( !m_bWaitSaveCompleted && !bUseNew ) 1679cdf0e10cSrcweir return; 1680cdf0e10cSrcweir 1681cdf0e10cSrcweir OSL_ENSURE( m_bWaitSaveCompleted, "Unexpected saveCompleted() call!\n" ); 1682cdf0e10cSrcweir if ( !m_bWaitSaveCompleted ) 1683cdf0e10cSrcweir throw io::IOException(); // TODO: illegal call 1684cdf0e10cSrcweir 1685cdf0e10cSrcweir OSL_ENSURE( m_xNewObjectStream.is() && m_xNewParentStorage.is() , "Internal object information is broken!\n" ); 1686cdf0e10cSrcweir if ( !m_xNewObjectStream.is() || !m_xNewParentStorage.is() ) 1687cdf0e10cSrcweir throw uno::RuntimeException(); // TODO: broken internal information 1688cdf0e10cSrcweir 1689cdf0e10cSrcweir if ( bUseNew ) 1690cdf0e10cSrcweir { 1691cdf0e10cSrcweir SwitchOwnPersistence( m_xNewParentStorage, m_xNewObjectStream, m_aNewEntryName ); 1692cdf0e10cSrcweir m_bStoreVisRepl = m_bNewVisReplInStream; 1693cdf0e10cSrcweir SetVisReplInStream( m_bNewVisReplInStream ); 1694cdf0e10cSrcweir m_xCachedVisualRepresentation = m_xNewCachedVisRepl; 1695cdf0e10cSrcweir } 1696cdf0e10cSrcweir else 1697cdf0e10cSrcweir { 1698cdf0e10cSrcweir // close remembered stream 1699cdf0e10cSrcweir try { 1700cdf0e10cSrcweir uno::Reference< lang::XComponent > xComponent( m_xNewObjectStream, uno::UNO_QUERY ); 1701cdf0e10cSrcweir OSL_ENSURE( xComponent.is(), "Wrong storage implementation!" ); 1702cdf0e10cSrcweir if ( xComponent.is() ) 1703cdf0e10cSrcweir xComponent->dispose(); 1704cdf0e10cSrcweir } 1705cdf0e10cSrcweir catch ( uno::Exception& ) 1706cdf0e10cSrcweir { 1707cdf0e10cSrcweir } 1708cdf0e10cSrcweir } 1709cdf0e10cSrcweir 1710cdf0e10cSrcweir sal_Bool bStoreLoaded = m_bStoreLoaded; 1711cdf0e10cSrcweir 1712cdf0e10cSrcweir m_xNewObjectStream = uno::Reference< io::XStream >(); 1713cdf0e10cSrcweir m_xNewParentStorage = uno::Reference< embed::XStorage >(); 1714cdf0e10cSrcweir m_aNewEntryName = ::rtl::OUString(); 1715cdf0e10cSrcweir m_bWaitSaveCompleted = sal_False; 1716cdf0e10cSrcweir m_bNewVisReplInStream = sal_False; 1717cdf0e10cSrcweir m_xNewCachedVisRepl = uno::Reference< io::XStream >(); 1718cdf0e10cSrcweir m_bStoreLoaded = sal_False; 1719cdf0e10cSrcweir 1720cdf0e10cSrcweir if ( bUseNew && m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE && !bStoreLoaded 1721cdf0e10cSrcweir && m_nObjectState != embed::EmbedStates::LOADED ) 1722cdf0e10cSrcweir { 1723cdf0e10cSrcweir // the object replacement image should be updated, so the cached size as well 1724cdf0e10cSrcweir m_bHasCachedSize = sal_False; 1725cdf0e10cSrcweir try 1726cdf0e10cSrcweir { 1727cdf0e10cSrcweir // the call will cache the size in case of success 1728cdf0e10cSrcweir // probably it might need to be done earlier, while the object is in active state 1729cdf0e10cSrcweir getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ); 1730cdf0e10cSrcweir } 1731cdf0e10cSrcweir catch( uno::Exception& ) 1732cdf0e10cSrcweir {} 1733cdf0e10cSrcweir } 1734cdf0e10cSrcweir 1735cdf0e10cSrcweir aGuard.clear(); 1736cdf0e10cSrcweir if ( bUseNew ) 1737cdf0e10cSrcweir { 1738cdf0e10cSrcweir MakeEventListenerNotification_Impl( ::rtl::OUString::createFromAscii( "OnSaveAsDone" ) ); 1739cdf0e10cSrcweir 1740cdf0e10cSrcweir // the object can be changed only on windows 1741cdf0e10cSrcweir // the notification should be done only if the object is not in loaded state 1742cdf0e10cSrcweir if ( m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE && !bStoreLoaded ) 1743cdf0e10cSrcweir { 1744cdf0e10cSrcweir MakeEventListenerNotification_Impl( ::rtl::OUString::createFromAscii( "OnVisAreaChanged" ) ); 1745cdf0e10cSrcweir } 1746cdf0e10cSrcweir } 1747cdf0e10cSrcweir } 1748cdf0e10cSrcweir 1749cdf0e10cSrcweir //------------------------------------------------------ 1750cdf0e10cSrcweir sal_Bool SAL_CALL OleEmbeddedObject::hasEntry() 1751cdf0e10cSrcweir throw ( embed::WrongStateException, 1752cdf0e10cSrcweir uno::RuntimeException ) 1753cdf0e10cSrcweir { 1754cdf0e10cSrcweir // begin wrapping related part ==================== 1755cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1756cdf0e10cSrcweir if ( xWrappedObject.is() ) 1757cdf0e10cSrcweir { 1758cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1759cdf0e10cSrcweir return xWrappedObject->hasEntry(); 1760cdf0e10cSrcweir } 1761cdf0e10cSrcweir // end wrapping related part ==================== 1762cdf0e10cSrcweir 1763cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1764cdf0e10cSrcweir if ( m_bDisposed ) 1765cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1766cdf0e10cSrcweir 1767cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1768cdf0e10cSrcweir throw embed::WrongStateException( 1769cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1770cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1771cdf0e10cSrcweir 1772cdf0e10cSrcweir if ( m_xObjectStream.is() ) 1773cdf0e10cSrcweir return sal_True; 1774cdf0e10cSrcweir 1775cdf0e10cSrcweir return sal_False; 1776cdf0e10cSrcweir } 1777cdf0e10cSrcweir 1778cdf0e10cSrcweir //------------------------------------------------------ 1779cdf0e10cSrcweir ::rtl::OUString SAL_CALL OleEmbeddedObject::getEntryName() 1780cdf0e10cSrcweir throw ( embed::WrongStateException, 1781cdf0e10cSrcweir uno::RuntimeException ) 1782cdf0e10cSrcweir { 1783cdf0e10cSrcweir // begin wrapping related part ==================== 1784cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1785cdf0e10cSrcweir if ( xWrappedObject.is() ) 1786cdf0e10cSrcweir { 1787cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1788cdf0e10cSrcweir return xWrappedObject->getEntryName(); 1789cdf0e10cSrcweir } 1790cdf0e10cSrcweir // end wrapping related part ==================== 1791cdf0e10cSrcweir 1792cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1793cdf0e10cSrcweir if ( m_bDisposed ) 1794cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1795cdf0e10cSrcweir 1796cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1797cdf0e10cSrcweir { 1798cdf0e10cSrcweir // the object is still not loaded 1799cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), 1800cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1801cdf0e10cSrcweir } 1802cdf0e10cSrcweir 1803cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1804cdf0e10cSrcweir throw embed::WrongStateException( 1805cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1806cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1807cdf0e10cSrcweir 1808cdf0e10cSrcweir return m_aEntryName; 1809cdf0e10cSrcweir } 1810cdf0e10cSrcweir 1811cdf0e10cSrcweir 1812cdf0e10cSrcweir //------------------------------------------------------ 1813cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::storeOwn() 1814cdf0e10cSrcweir throw ( embed::WrongStateException, 1815cdf0e10cSrcweir io::IOException, 1816cdf0e10cSrcweir uno::Exception, 1817cdf0e10cSrcweir uno::RuntimeException ) 1818cdf0e10cSrcweir { 1819cdf0e10cSrcweir RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OleEmbeddedObject::storeOwn" ); 1820cdf0e10cSrcweir 1821cdf0e10cSrcweir // begin wrapping related part ==================== 1822cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1823cdf0e10cSrcweir if ( xWrappedObject.is() ) 1824cdf0e10cSrcweir { 1825cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1826cdf0e10cSrcweir xWrappedObject->storeOwn(); 1827cdf0e10cSrcweir return; 1828cdf0e10cSrcweir } 1829cdf0e10cSrcweir // end wrapping related part ==================== 1830cdf0e10cSrcweir 1831cdf0e10cSrcweir // during switching from Activated to Running and from Running to Loaded states the object will 1832cdf0e10cSrcweir // ask container to store the object, the container has to make decision 1833cdf0e10cSrcweir // to do so or not 1834cdf0e10cSrcweir 1835cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 1836cdf0e10cSrcweir if ( m_bDisposed ) 1837cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1838cdf0e10cSrcweir 1839cdf0e10cSrcweir VerbExecutionControllerGuard aVerbGuard( m_aVerbExecutionController ); 1840cdf0e10cSrcweir 1841cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1842cdf0e10cSrcweir { 1843cdf0e10cSrcweir // the object is still not loaded 1844cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "Can't store object without persistence!\n" ), 1845cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1846cdf0e10cSrcweir } 1847cdf0e10cSrcweir 1848cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1849cdf0e10cSrcweir throw embed::WrongStateException( 1850cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1851cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1852cdf0e10cSrcweir 1853cdf0e10cSrcweir if ( m_bReadOnly ) 1854cdf0e10cSrcweir throw io::IOException(); // TODO: access denied 1855cdf0e10cSrcweir 1856cdf0e10cSrcweir LetCommonStoragePassBeUsed_Impl( m_xObjectStream ); 1857cdf0e10cSrcweir 1858cdf0e10cSrcweir sal_Bool bStoreLoaded = sal_True; 1859cdf0e10cSrcweir 1860cdf0e10cSrcweir #ifdef WNT 1861cdf0e10cSrcweir if ( m_nObjectState != embed::EmbedStates::LOADED && m_pOleComponent && m_pOleComponent->IsDirty() ) 1862cdf0e10cSrcweir { 1863cdf0e10cSrcweir bStoreLoaded = sal_False; 1864cdf0e10cSrcweir 1865cdf0e10cSrcweir OSL_ENSURE( m_xParentStorage.is() && m_xObjectStream.is(), "The object has no valid persistence!\n" ); 1866cdf0e10cSrcweir 1867cdf0e10cSrcweir if ( !m_xObjectStream.is() ) 1868cdf0e10cSrcweir throw io::IOException(); //TODO: access denied 1869cdf0e10cSrcweir 1870cdf0e10cSrcweir SetStreamMediaType_Impl( m_xObjectStream, ::rtl::OUString::createFromAscii( "application/vnd.sun.star.oleobject" ) ); 1871cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutStream = m_xObjectStream->getOutputStream(); 1872cdf0e10cSrcweir if ( !xOutStream.is() ) 1873cdf0e10cSrcweir throw io::IOException(); //TODO: access denied 1874cdf0e10cSrcweir 1875cdf0e10cSrcweir if ( m_bIsLink ) 1876cdf0e10cSrcweir { 1877cdf0e10cSrcweir // just let the link store itself 1878cdf0e10cSrcweir // in case visual repersentation must be stored also 1879cdf0e10cSrcweir // the procedure should be the same as for embedded objects 1880cdf0e10cSrcweir 1881cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutStream = GetStreamForSaving(); 1882cdf0e10cSrcweir 1883cdf0e10cSrcweir // should the component detect that it is a link??? 1884cdf0e10cSrcweir StoreObjectToStream( xOutStream ); 1885cdf0e10cSrcweir } 1886cdf0e10cSrcweir else 1887cdf0e10cSrcweir { 1888cdf0e10cSrcweir uno::Reference< io::XOutputStream > xOutStream = GetStreamForSaving(); 1889cdf0e10cSrcweir StoreObjectToStream( xOutStream ); 1890cdf0e10cSrcweir } 1891cdf0e10cSrcweir 1892cdf0e10cSrcweir // the replacement is changed probably, and it must be in the object stream 1893cdf0e10cSrcweir if ( !m_pOleComponent->IsWorkaroundActive() ) 1894cdf0e10cSrcweir m_xCachedVisualRepresentation = uno::Reference< io::XStream >(); 1895cdf0e10cSrcweir SetVisReplInStream( sal_True ); 1896cdf0e10cSrcweir } 1897cdf0e10cSrcweir #endif 1898cdf0e10cSrcweir 1899cdf0e10cSrcweir if ( m_bStoreVisRepl != HasVisReplInStream() ) 1900cdf0e10cSrcweir { 1901cdf0e10cSrcweir if ( m_bStoreVisRepl ) 1902cdf0e10cSrcweir { 1903cdf0e10cSrcweir // the m_xCachedVisualRepresentation must be set or it should be already stored 1904cdf0e10cSrcweir if ( m_xCachedVisualRepresentation.is() ) 1905cdf0e10cSrcweir InsertVisualCache_Impl( m_xObjectStream, m_xCachedVisualRepresentation ); 1906cdf0e10cSrcweir else 1907cdf0e10cSrcweir { 1908cdf0e10cSrcweir m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream ); 1909cdf0e10cSrcweir OSL_ENSURE( m_xCachedVisualRepresentation.is(), "No representation is available!" ); 1910cdf0e10cSrcweir } 1911cdf0e10cSrcweir } 1912cdf0e10cSrcweir else 1913cdf0e10cSrcweir { 1914cdf0e10cSrcweir if ( !m_xCachedVisualRepresentation.is() ) 1915cdf0e10cSrcweir m_xCachedVisualRepresentation = TryToRetrieveCachedVisualRepresentation_Impl( m_xObjectStream ); 1916cdf0e10cSrcweir RemoveVisualCache_Impl( m_xObjectStream ); 1917cdf0e10cSrcweir } 1918cdf0e10cSrcweir 1919cdf0e10cSrcweir SetVisReplInStream( m_bStoreVisRepl ); 1920cdf0e10cSrcweir } 1921cdf0e10cSrcweir 1922cdf0e10cSrcweir if ( m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE && !bStoreLoaded ) 1923cdf0e10cSrcweir { 1924cdf0e10cSrcweir // the object replacement image should be updated, so the cached size as well 1925cdf0e10cSrcweir m_bHasCachedSize = sal_False; 1926cdf0e10cSrcweir try 1927cdf0e10cSrcweir { 1928cdf0e10cSrcweir // the call will cache the size in case of success 1929cdf0e10cSrcweir // probably it might need to be done earlier, while the object is in active state 1930cdf0e10cSrcweir getVisualAreaSize( embed::Aspects::MSOLE_CONTENT ); 1931cdf0e10cSrcweir } 1932cdf0e10cSrcweir catch( uno::Exception& ) 1933cdf0e10cSrcweir {} 1934cdf0e10cSrcweir } 1935cdf0e10cSrcweir 1936cdf0e10cSrcweir aGuard.clear(); 1937cdf0e10cSrcweir 1938cdf0e10cSrcweir MakeEventListenerNotification_Impl( ::rtl::OUString::createFromAscii( "OnSaveDone" ) ); 1939cdf0e10cSrcweir 1940cdf0e10cSrcweir // the object can be changed only on Windows 1941cdf0e10cSrcweir // the notification should be done only if the object is not in loaded state 1942cdf0e10cSrcweir if ( m_pOleComponent && m_nUpdateMode == embed::EmbedUpdateModes::ALWAYS_UPDATE && !bStoreLoaded ) 1943cdf0e10cSrcweir MakeEventListenerNotification_Impl( ::rtl::OUString::createFromAscii( "OnVisAreaChanged" ) ); 1944cdf0e10cSrcweir } 1945cdf0e10cSrcweir 1946cdf0e10cSrcweir //------------------------------------------------------ 1947cdf0e10cSrcweir sal_Bool SAL_CALL OleEmbeddedObject::isReadonly() 1948cdf0e10cSrcweir throw ( embed::WrongStateException, 1949cdf0e10cSrcweir uno::RuntimeException ) 1950cdf0e10cSrcweir { 1951cdf0e10cSrcweir // begin wrapping related part ==================== 1952cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1953cdf0e10cSrcweir if ( xWrappedObject.is() ) 1954cdf0e10cSrcweir { 1955cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1956cdf0e10cSrcweir return xWrappedObject->isReadonly(); 1957cdf0e10cSrcweir } 1958cdf0e10cSrcweir // end wrapping related part ==================== 1959cdf0e10cSrcweir 1960cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 1961cdf0e10cSrcweir if ( m_bDisposed ) 1962cdf0e10cSrcweir throw lang::DisposedException(); // TODO 1963cdf0e10cSrcweir 1964cdf0e10cSrcweir if ( m_nObjectState == -1 ) 1965cdf0e10cSrcweir { 1966cdf0e10cSrcweir // the object is still not loaded 1967cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), 1968cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1969cdf0e10cSrcweir } 1970cdf0e10cSrcweir 1971cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 1972cdf0e10cSrcweir throw embed::WrongStateException( 1973cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 1974cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 1975cdf0e10cSrcweir 1976cdf0e10cSrcweir return m_bReadOnly; 1977cdf0e10cSrcweir } 1978cdf0e10cSrcweir 1979cdf0e10cSrcweir //------------------------------------------------------ 1980cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::reload( 1981cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lArguments, 1982cdf0e10cSrcweir const uno::Sequence< beans::PropertyValue >& lObjArgs ) 1983cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 1984cdf0e10cSrcweir embed::WrongStateException, 1985cdf0e10cSrcweir io::IOException, 1986cdf0e10cSrcweir uno::Exception, 1987cdf0e10cSrcweir uno::RuntimeException ) 1988cdf0e10cSrcweir { 1989cdf0e10cSrcweir // begin wrapping related part ==================== 1990cdf0e10cSrcweir uno::Reference< embed::XEmbedPersist > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 1991cdf0e10cSrcweir if ( xWrappedObject.is() ) 1992cdf0e10cSrcweir { 1993cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 1994cdf0e10cSrcweir xWrappedObject->reload( lArguments, lObjArgs ); 1995cdf0e10cSrcweir return; 1996cdf0e10cSrcweir } 1997cdf0e10cSrcweir // end wrapping related part ==================== 1998cdf0e10cSrcweir 1999cdf0e10cSrcweir // TODO: use lObjArgs 2000cdf0e10cSrcweir 2001cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 2002cdf0e10cSrcweir if ( m_bDisposed ) 2003cdf0e10cSrcweir throw lang::DisposedException(); // TODO 2004cdf0e10cSrcweir 2005cdf0e10cSrcweir if ( m_nObjectState == -1 ) 2006cdf0e10cSrcweir { 2007cdf0e10cSrcweir // the object is still not loaded 2008cdf0e10cSrcweir throw embed::WrongStateException( ::rtl::OUString::createFromAscii( "The object persistence is not initialized!\n" ), 2009cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 2010cdf0e10cSrcweir } 2011cdf0e10cSrcweir 2012cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 2013cdf0e10cSrcweir throw embed::WrongStateException( 2014cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 2015cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 2016cdf0e10cSrcweir 2017cdf0e10cSrcweir // TODO: 2018cdf0e10cSrcweir // throw away current document 2019cdf0e10cSrcweir // load new document from current storage 2020cdf0e10cSrcweir // use meaningfull part of lArguments 2021cdf0e10cSrcweir } 2022cdf0e10cSrcweir 2023cdf0e10cSrcweir //------------------------------------------------------ 2024cdf0e10cSrcweir void SAL_CALL OleEmbeddedObject::breakLink( const uno::Reference< embed::XStorage >& xStorage, 2025cdf0e10cSrcweir const ::rtl::OUString& sEntName ) 2026cdf0e10cSrcweir throw ( lang::IllegalArgumentException, 2027cdf0e10cSrcweir embed::WrongStateException, 2028cdf0e10cSrcweir io::IOException, 2029cdf0e10cSrcweir uno::Exception, 2030cdf0e10cSrcweir uno::RuntimeException ) 2031cdf0e10cSrcweir { 2032cdf0e10cSrcweir // begin wrapping related part ==================== 2033cdf0e10cSrcweir uno::Reference< embed::XLinkageSupport > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 2034cdf0e10cSrcweir if ( xWrappedObject.is() ) 2035cdf0e10cSrcweir { 2036cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 2037cdf0e10cSrcweir xWrappedObject->breakLink( xStorage, sEntName ); 2038cdf0e10cSrcweir return; 2039cdf0e10cSrcweir } 2040cdf0e10cSrcweir // end wrapping related part ==================== 2041cdf0e10cSrcweir 2042cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 2043cdf0e10cSrcweir if ( m_bDisposed ) 2044cdf0e10cSrcweir throw lang::DisposedException(); // TODO 2045cdf0e10cSrcweir 2046cdf0e10cSrcweir if ( !xStorage.is() ) 2047cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "No parent storage is provided!\n" ), 2048cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 2049cdf0e10cSrcweir 1 ); 2050cdf0e10cSrcweir 2051cdf0e10cSrcweir if ( !sEntName.getLength() ) 2052cdf0e10cSrcweir throw lang::IllegalArgumentException( ::rtl::OUString::createFromAscii( "Empty element name is provided!\n" ), 2053cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ), 2054cdf0e10cSrcweir 2 ); 2055cdf0e10cSrcweir 2056cdf0e10cSrcweir // TODO: The object must be at least in Running state; 2057cdf0e10cSrcweir if ( !m_bIsLink || m_nObjectState == -1 || !m_pOleComponent ) 2058cdf0e10cSrcweir { 2059cdf0e10cSrcweir // it must be a linked initialized object 2060cdf0e10cSrcweir throw embed::WrongStateException( 2061cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object is not a valid linked object!\n" ), 2062cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 2063cdf0e10cSrcweir } 2064cdf0e10cSrcweir 2065cdf0e10cSrcweir if ( m_bReadOnly ) 2066cdf0e10cSrcweir throw io::IOException(); // TODO: Access denied 2067cdf0e10cSrcweir 2068cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 2069cdf0e10cSrcweir throw embed::WrongStateException( 2070cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 2071cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 2072cdf0e10cSrcweir 2073cdf0e10cSrcweir 2074cdf0e10cSrcweir #ifdef WNT 2075cdf0e10cSrcweir if ( m_pOleComponent ) 2076cdf0e10cSrcweir { 2077cdf0e10cSrcweir // TODO: create an object based on the link 2078cdf0e10cSrcweir 2079cdf0e10cSrcweir // disconnect the old temporary URL 2080cdf0e10cSrcweir ::rtl::OUString aOldTempURL = m_aTempURL; 2081cdf0e10cSrcweir m_aTempURL = ::rtl::OUString(); 2082cdf0e10cSrcweir 2083cdf0e10cSrcweir OleComponent* pNewOleComponent = new OleComponent( m_xFactory, this ); 2084cdf0e10cSrcweir try { 2085cdf0e10cSrcweir pNewOleComponent->InitEmbeddedCopyOfLink( m_pOleComponent ); 2086cdf0e10cSrcweir } 2087cdf0e10cSrcweir catch ( uno::Exception& ) 2088cdf0e10cSrcweir { 2089cdf0e10cSrcweir delete pNewOleComponent; 2090cdf0e10cSrcweir if ( m_aTempURL ) 2091cdf0e10cSrcweir KillFile_Impl( m_aTempURL, m_xFactory ); 2092cdf0e10cSrcweir m_aTempURL = aOldTempURL; 2093cdf0e10cSrcweir throw; 2094cdf0e10cSrcweir } 2095cdf0e10cSrcweir 2096cdf0e10cSrcweir try { 2097cdf0e10cSrcweir GetRidOfComponent(); 2098cdf0e10cSrcweir } 2099cdf0e10cSrcweir catch( uno::Exception& ) 2100cdf0e10cSrcweir { 2101cdf0e10cSrcweir delete pNewOleComponent; 2102cdf0e10cSrcweir if ( m_aTempURL ) 2103cdf0e10cSrcweir KillFile_Impl( m_aTempURL, m_xFactory ); 2104cdf0e10cSrcweir m_aTempURL = aOldTempURL; 2105cdf0e10cSrcweir throw; 2106cdf0e10cSrcweir } 2107cdf0e10cSrcweir 2108cdf0e10cSrcweir KillFile_Impl( aOldTempURL, m_xFactory ); 2109cdf0e10cSrcweir 2110cdf0e10cSrcweir CreateOleComponent_Impl( pNewOleComponent ); 2111cdf0e10cSrcweir 2112cdf0e10cSrcweir if ( m_xParentStorage != xStorage || !m_aEntryName.equals( sEntName ) ) 2113cdf0e10cSrcweir SwitchOwnPersistence( xStorage, sEntName ); 2114cdf0e10cSrcweir 2115cdf0e10cSrcweir if ( m_nObjectState != embed::EmbedStates::LOADED ) 2116cdf0e10cSrcweir { 2117cdf0e10cSrcweir // TODO: should we activate the new object if the link was activated? 2118cdf0e10cSrcweir 2119cdf0e10cSrcweir sal_Int32 nTargetState = m_nObjectState; 2120cdf0e10cSrcweir m_nObjectState = embed::EmbedStates::LOADED; 2121cdf0e10cSrcweir 2122cdf0e10cSrcweir if ( m_nObjectState == embed::EmbedStates::RUNNING ) 2123cdf0e10cSrcweir m_pOleComponent->RunObject(); // the object already was in running state, the server must be installed 2124cdf0e10cSrcweir else // m_nObjectState == embed::EmbedStates::ACTIVE 2125cdf0e10cSrcweir { 2126cdf0e10cSrcweir m_pOleComponent->RunObject(); // the object already was in running state, the server must be installed 2127cdf0e10cSrcweir m_pOleComponent->ExecuteVerb( embed::EmbedVerbs::MS_OLEVERB_OPEN ); 2128cdf0e10cSrcweir } 2129cdf0e10cSrcweir 2130cdf0e10cSrcweir m_nObjectState = nTargetState; 2131cdf0e10cSrcweir } 2132cdf0e10cSrcweir 2133cdf0e10cSrcweir m_bIsLink = sal_False; 2134cdf0e10cSrcweir m_aLinkURL = ::rtl::OUString(); 2135cdf0e10cSrcweir } 2136cdf0e10cSrcweir else 2137cdf0e10cSrcweir #endif 2138cdf0e10cSrcweir { 2139cdf0e10cSrcweir throw io::IOException(); //TODO: 2140cdf0e10cSrcweir } 2141cdf0e10cSrcweir } 2142cdf0e10cSrcweir 2143cdf0e10cSrcweir //------------------------------------------------------ 2144cdf0e10cSrcweir sal_Bool SAL_CALL OleEmbeddedObject::isLink() 2145cdf0e10cSrcweir throw ( embed::WrongStateException, 2146cdf0e10cSrcweir uno::RuntimeException ) 2147cdf0e10cSrcweir { 2148cdf0e10cSrcweir // begin wrapping related part ==================== 2149cdf0e10cSrcweir uno::Reference< embed::XLinkageSupport > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 2150cdf0e10cSrcweir if ( xWrappedObject.is() ) 2151cdf0e10cSrcweir { 2152cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 2153cdf0e10cSrcweir return xWrappedObject->isLink(); 2154cdf0e10cSrcweir } 2155cdf0e10cSrcweir // end wrapping related part ==================== 2156cdf0e10cSrcweir 2157cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 2158cdf0e10cSrcweir if ( m_bDisposed ) 2159cdf0e10cSrcweir throw lang::DisposedException(); // TODO 2160cdf0e10cSrcweir 2161cdf0e10cSrcweir return m_bIsLink; 2162cdf0e10cSrcweir } 2163cdf0e10cSrcweir 2164cdf0e10cSrcweir //------------------------------------------------------ 2165cdf0e10cSrcweir ::rtl::OUString SAL_CALL OleEmbeddedObject::getLinkURL() 2166cdf0e10cSrcweir throw ( embed::WrongStateException, 2167cdf0e10cSrcweir uno::Exception, 2168cdf0e10cSrcweir uno::RuntimeException ) 2169cdf0e10cSrcweir { 2170cdf0e10cSrcweir // begin wrapping related part ==================== 2171cdf0e10cSrcweir uno::Reference< embed::XLinkageSupport > xWrappedObject( m_xWrappedObject, uno::UNO_QUERY ); 2172cdf0e10cSrcweir if ( xWrappedObject.is() ) 2173cdf0e10cSrcweir { 2174cdf0e10cSrcweir // the object was converted to OOo embedded object, the current implementation is now only a wrapper 2175cdf0e10cSrcweir return xWrappedObject->getLinkURL(); 2176cdf0e10cSrcweir } 2177cdf0e10cSrcweir // end wrapping related part ==================== 2178cdf0e10cSrcweir 2179cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 2180cdf0e10cSrcweir if ( m_bDisposed ) 2181cdf0e10cSrcweir throw lang::DisposedException(); // TODO 2182cdf0e10cSrcweir 2183cdf0e10cSrcweir if ( m_bWaitSaveCompleted ) 2184cdf0e10cSrcweir throw embed::WrongStateException( 2185cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object waits for saveCompleted() call!\n" ), 2186cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 2187cdf0e10cSrcweir 2188cdf0e10cSrcweir if ( !m_bIsLink ) 2189cdf0e10cSrcweir throw embed::WrongStateException( 2190cdf0e10cSrcweir ::rtl::OUString::createFromAscii( "The object is not a link object!\n" ), 2191cdf0e10cSrcweir uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) ); 2192cdf0e10cSrcweir 2193cdf0e10cSrcweir // TODO: probably the link URL can be retrieved from OLE 2194cdf0e10cSrcweir 2195cdf0e10cSrcweir return m_aLinkURL; 2196cdf0e10cSrcweir } 2197cdf0e10cSrcweir 2198