22#include <com/sun/star/embed/EmbedStates.hpp>
23#include <com/sun/star/embed/EmbedVerbs.hpp>
24#include <com/sun/star/embed/EntryInitModes.hpp>
25#include <com/sun/star/embed/WrongStateException.hpp>
26#include <com/sun/star/embed/XStorage.hpp>
27#include <com/sun/star/embed/XTransactedObject.hpp>
28#include <com/sun/star/embed/ElementModes.hpp>
29#include <com/sun/star/embed/EmbedUpdateModes.hpp>
30#include <com/sun/star/embed/Aspects.hpp>
31#include <com/sun/star/embed/XOptimizedStorage.hpp>
32#include <com/sun/star/lang/XComponent.hpp>
33#include <com/sun/star/lang/DisposedException.hpp>
34#include <com/sun/star/container/XNameAccess.hpp>
35#include <com/sun/star/container/XNameContainer.hpp>
36#include <com/sun/star/io/TempFile.hpp>
37#include <com/sun/star/io/XSeekable.hpp>
38#include <com/sun/star/io/XTruncate.hpp>
39#include <com/sun/star/beans/XPropertySet.hpp>
40#include <com/sun/star/packages/WrongPasswordException.hpp>
41#include <com/sun/star/ucb/SimpleFileAccess.hpp>
42#include <com/sun/star/io/IOException.hpp>
47#include <osl/diagnose.h>
48#include <osl/thread.hxx>
62bool KillFile_Impl(
const OUString& aURL,
const uno::Reference< uno::XComponentContext >& xContext )
71 uno::Reference < ucb::XSimpleFileAccess3 > xAccess(
72 ucb::SimpleFileAccess::create( xContext ) );
74 xAccess->kill(
aURL );
77 catch(
const uno::Exception& )
87 SAL_WARN_IF( !xContext.is(),
"embeddedobj.ole",
"No factory is provided!" );
91 uno::Reference < io::XTempFile > xTempFile(
92 io::TempFile::create(xContext),
96 xTempFile->setRemoveFile(
false );
97 aResult = xTempFile->getUri();
99 catch (
const uno::Exception& )
103 if ( aResult.isEmpty() )
104 throw uno::RuntimeException(
"Cannot create tempfile.");
111 const uno::Reference< uno::XComponentContext >& xContext )
113 OSL_ENSURE( xInStream.is() && xContext.is(),
"Wrong parameters are provided!" );
117 if ( !aResult.isEmpty() )
120 uno::Reference < ucb::XSimpleFileAccess3 > xTempAccess(
121 ucb::SimpleFileAccess::create( xContext ) );
123 uno::Reference< io::XOutputStream > xTempOutStream = xTempAccess->openFileWrite( aResult );
124 if ( !xTempOutStream.is() )
125 throw io::IOException();
128 xTempOutStream->closeOutput();
129 xTempOutStream.clear();
131 catch(
const packages::WrongPasswordException& )
134 throw io::IOException();
136 catch(
const io::IOException& )
141 catch(
const uno::RuntimeException& )
146 catch(
const uno::Exception& )
158static OUString
GetNewFilledTempFile_Impl(
const uno::Reference< embed::XOptimizedStorage >& xParentStorage,
const OUString& aEntryName,
const uno::Reference< uno::XComponentContext >& xContext )
164 uno::Reference < io::XTempFile > xTempFile(
165 io::TempFile::create(xContext),
166 uno::UNO_SET_THROW );
168 xParentStorage->copyStreamElementData( aEntryName, xTempFile );
170 xTempFile->setRemoveFile(
false );
171 aResult = xTempFile->getUri();
173 catch(
const uno::RuntimeException& )
177 catch(
const uno::Exception& )
181 if ( aResult.isEmpty() )
182 throw io::IOException();
188static void SetStreamMediaType_Impl(
const uno::Reference< io::XStream >& xStream,
const OUString& aMediaType )
190 uno::Reference< beans::XPropertySet > xPropSet( xStream, uno::UNO_QUERY_THROW );
191 xPropSet->setPropertyValue(
"MediaType",
uno::Any( aMediaType ) );
197 uno::Reference< beans::XPropertySet > xPropSet(
xStream, uno::UNO_QUERY_THROW );
198 xPropSet->setPropertyValue(
"UseCommonStoragePasswordEncryption",
203void VerbExecutionController::StartControlExecution()
208 if ( !m_bVerbExecutionInProgress && !m_bWasEverActive )
210 m_bVerbExecutionInProgress =
true;
211 m_nVerbExecutionThreadIdentifier = osl::Thread::getCurrentIdentifier();
212 m_bChangedOnVerbExecution =
false;
217bool VerbExecutionController::EndControlExecution_WasModified()
221 bool bResult =
false;
222 if ( m_bVerbExecutionInProgress && m_nVerbExecutionThreadIdentifier == osl::Thread::getCurrentIdentifier() )
224 bResult = m_bChangedOnVerbExecution;
225 m_bVerbExecutionInProgress =
false;
232void VerbExecutionController::ModificationNotificationIsDone()
236 if ( m_bVerbExecutionInProgress && osl::Thread::getCurrentIdentifier() == m_nVerbExecutionThreadIdentifier )
237 m_bChangedOnVerbExecution =
true;
259 SAL_WARN_IF( !xInStream.is(),
"embeddedobj.ole",
"Wrong parameter is provided!" );
261 uno::Reference < io::XStream > xTempFile(
263 uno::UNO_QUERY_THROW );
265 uno::Reference< io::XOutputStream > xTempOutStream = xTempFile->getOutputStream();
266 if ( !xTempOutStream.is() )
267 throw io::IOException();
269 xTempOutStream->flush();
278 throw uno::RuntimeException();
280 uno::Reference< io::XInputStream > xInStream =
xStream->getInputStream();
281 if ( !xInStream.is() )
282 throw uno::RuntimeException();
284 uno::Reference< io::XSeekable > xSeek(
xStream, uno::UNO_QUERY_THROW );
287 uno::Sequence< sal_Int8 >
aData( 8 );
288 sal_Int32 nRead = xInStream->readBytes(
aData, 8 );
291 if ( ( nRead >= 2 &&
aData[0] ==
'B' &&
aData[1] ==
'M' )
299 sal_uInt32 nHeaderOffset = 0;
307 uno::Sequence< sal_Int8 > aHeadData( 4 );
308 nRead = xInStream->readBytes( aHeadData, 4 );
310 if ( nRead == 4 && aHeadData.getLength() == 4 )
311 nLen = ( ( (
static_cast<sal_uInt32
>(aHeadData[3]) * 0x100 +
static_cast<sal_uInt32
>(aHeadData[2]) ) * 0x100 ) +
static_cast<sal_uInt32
>(aHeadData[1]) ) * 0x100 +
static_cast<sal_uInt32
>(aHeadData[0]);
314 xInStream->skipBytes( nLen - 4 );
315 nHeaderOffset += nLen - 4;
319 else if ( nRead > 4 )
322 sal_uInt32 nSize = 0;
323 for ( sal_Int32 nInd = 3; nInd >= 0; nInd-- )
326 if ( nSize == xSeek->getLength() - 4 )
333 uno::Reference < io::XStream > xResult(
335 uno::UNO_QUERY_THROW );
336 uno::Reference < io::XSeekable > xResultSeek( xResult, uno::UNO_QUERY_THROW );
337 uno::Reference < io::XOutputStream > xResultOut = xResult->getOutputStream();
338 uno::Reference < io::XInputStream > xResultIn = xResult->getInputStream();
339 if ( !xResultOut.is() || !xResultIn.is() )
340 throw uno::RuntimeException();
342 xSeek->seek( nHeaderOffset );
344 xResultOut->closeOutput();
345 xResultSeek->seek( 0 );
351 return uno::Reference< io::XStream >();
356 const uno::Reference< io::XStream >& xCachedVisualRepresentation )
358 OSL_ENSURE( xTargetStream.is() && xCachedVisualRepresentation.is(),
"Invalid arguments!" );
360 if ( !xTargetStream.is() || !xCachedVisualRepresentation.is() )
361 throw uno::RuntimeException();
363 uno::Sequence< uno::Any > aArgs{
uno::Any(xTargetStream),
366 uno::Reference< container::XNameContainer > xNameContainer(
367 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
368 "com.sun.star.embed.OLESimpleStorage",
370 uno::UNO_QUERY_THROW );
372 uno::Reference< io::XSeekable > xCachedSeek( xCachedVisualRepresentation, uno::UNO_QUERY_THROW );
373 xCachedSeek->seek( 0 );
375 uno::Reference < io::XStream > xTempFile(
377 uno::UNO_QUERY_THROW );
379 uno::Reference< io::XSeekable > xTempSeek( xTempFile, uno::UNO_QUERY_THROW );
380 uno::Reference< io::XOutputStream > xTempOutStream = xTempFile->getOutputStream();
381 if ( !xTempOutStream.is() )
382 throw io::IOException();
386 uno::Reference< io::XInputStream > xInCacheStream = xCachedVisualRepresentation->getInputStream();
387 if ( !xInCacheStream.is() )
388 throw uno::RuntimeException();
391 uno::Sequence< sal_Int8 >
aData( 4 );
393 *
reinterpret_cast<sal_uInt32*
>(
pData) = 0xFFFFFFFF;
395 xTempOutStream->writeBytes(
aData );
398 uno::Sequence< sal_Int8 > aSigData( 2 );
399 xInCacheStream->readBytes( aSigData, 2 );
400 if ( aSigData.getLength() < 2 )
401 throw io::IOException();
403 if ( aSigData[0] ==
'B' && aSigData[1] ==
'M' )
413 xTempOutStream->writeBytes(
aData );
417 xTempOutStream->writeBytes(
aData );
421 xTempOutStream->writeBytes(
aData );
424 *
reinterpret_cast<sal_uInt32*
>(
pData) = 0xFFFFFFFF;
425 xTempOutStream->writeBytes(
aData );
429 xTempOutStream->writeBytes(
aData );
432 *
reinterpret_cast<sal_uInt32*
>(
pData) = 0x0;
433 xTempOutStream->writeBytes(
aData );
443 aSize.Width /= 0x100;
445 xTempOutStream->writeBytes(
aData );
451 aSize.Height /= 0x100;
453 xTempOutStream->writeBytes(
aData );
456 xTempOutStream->writeBytes(
aData );
459 xTempOutStream->writeBytes( aSigData );
465 sal_Int64
nLength = xTempSeek->getLength() - 40;
466 if ( nLength < 0 || nLength >= 0xFFFFFFFF )
468 SAL_WARN(
"embeddedobj.ole",
"Length is not acceptable!" );
471 for ( sal_Int32 nInd = 0; nInd < 4; nInd++ )
476 xTempSeek->seek( 36 );
477 xTempOutStream->writeBytes(
aData );
479 xTempOutStream->flush();
481 xTempSeek->seek( 0 );
482 if ( xCachedSeek.is() )
483 xCachedSeek->seek( 0 );
486 OUString aCacheName =
"\002OlePres000";
487 if ( xNameContainer->hasByName( aCacheName ) )
488 xNameContainer->replaceByName( aCacheName,
uno::Any( xTempFile ) );
490 xNameContainer->insertByName( aCacheName,
uno::Any( xTempFile ) );
492 uno::Reference< embed::XTransactedObject > xTransacted( xNameContainer, uno::UNO_QUERY_THROW );
493 xTransacted->commit();
499 OSL_ENSURE( xTargetStream.is(),
"Invalid argument!" );
500 if ( !xTargetStream.is() )
501 throw uno::RuntimeException();
503 uno::Sequence< uno::Any > aArgs{
uno::Any(xTargetStream),
505 uno::Reference< container::XNameContainer > xNameContainer(
506 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
507 "com.sun.star.embed.OLESimpleStorage",
509 uno::UNO_QUERY_THROW );
511 for (
sal_uInt8 nInd = 0; nInd < 10; nInd++ )
513 OUString aStreamName =
"\002OlePres00" + OUString::number( nInd );
514 if ( xNameContainer->hasByName( aStreamName ) )
515 xNameContainer->removeByName( aStreamName );
518 uno::Reference< embed::XTransactedObject > xTransacted( xNameContainer, uno::UNO_QUERY_THROW );
519 xTransacted->commit();
538 SAL_INFO(
"embeddedobj.ole",
"embeddedobj (mv76033) OleEmbeddedObject::HasVisualReplInStream, analyzing" );
540 uno::Reference< io::XInputStream >
xStream;
548 uno::Reference < ucb::XSimpleFileAccess3 > xTempAccess(
549 ucb::SimpleFileAccess::create(
m_xContext ) );
553 catch(
const uno::Exception& )
562 bool bExists =
false;
566 uno::Reference< container::XNameContainer > xNameContainer(
567 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
568 "com.sun.star.embed.OLESimpleStorage",
572 if ( xNameContainer.is() )
574 for (
sal_uInt8 nInd = 0; nInd < 10 && !bExists; nInd++ )
576 OUString aStreamName =
"\002OlePres00" + OUString::number( nInd );
579 bExists = xNameContainer->hasByName( aStreamName );
581 catch(
const uno::Exception& )
596 const uno::Reference< io::XStream >& xStream,
597 bool bAllowToRepair50 )
600 uno::Reference< io::XStream > xResult;
604 SAL_INFO(
"embeddedobj.ole",
"embeddedobj (mv76033) OleEmbeddedObject::TryToRetrieveCachedVisualRepresentation, retrieving" );
606 uno::Reference< container::XNameContainer > xNameContainer;
612 m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
613 "com.sun.star.embed.OLESimpleStorage",
617 catch(
const uno::Exception& )
620 if ( xNameContainer.is() )
622 for (
sal_uInt8 nInd = 0; nInd < 10; nInd++ )
624 OUString aStreamName =
"\002OlePres00" + OUString::number( nInd );
625 uno::Reference< io::XStream > xCachedCopyStream;
628 if ( ( xNameContainer->getByName( aStreamName ) >>= xCachedCopyStream ) && xCachedCopyStream.is() )
630 xResult = TryToGetAcceptableFormat_Impl( xCachedCopyStream );
635 catch(
const uno::Exception& )
641 aStreamName =
"\001Ole10Native";
644 if ( ( xNameContainer->getByName( aStreamName ) >>= xCachedCopyStream ) && xCachedCopyStream.is() )
646 xResult = TryToGetAcceptableFormat_Impl( xCachedCopyStream );
651 catch(
const uno::Exception& )
658 if ( bAllowToRepair50 && !xResult.is() )
660 OUString aOrigContName(
"Ole-Object" );
661 if ( xNameContainer->hasByName( aOrigContName ) )
663 uno::Reference< embed::XClassifiedObject > xClassified( xNameContainer, uno::UNO_QUERY_THROW );
664 if ( MimeConfigurationHelper::ClassIDsEqual( xClassified->getClassID(), MimeConfigurationHelper::GetSequenceClassID(
SO3_OUT_CLASSID ) ) )
669 uno::Reference< io::XOutputStream > xOutputStream =
xStream->getOutputStream();
670 uno::Reference< io::XTruncate > xTruncate( xOutputStream, uno::UNO_QUERY_THROW );
672 uno::Reference< io::XInputStream > xOrigInputStream;
673 if ( ( xNameContainer->getByName( aOrigContName ) >>= xOrigInputStream )
674 && xOrigInputStream.is() )
678 uno::Reference< io::XSeekable > xOrigSeekable( xOrigInputStream, uno::UNO_QUERY );
679 if ( xOrigSeekable.is() )
680 xOrigSeekable->seek( 0 );
682 uno::Reference< lang::XComponent > xNameContDisp( xNameContainer, uno::UNO_QUERY_THROW );
683 xNameContDisp->dispose();
685 xTruncate->truncate();
687 xOutputStream->flush();
689 if (
xStream == m_xObjectStream )
691 if ( !m_aTempURL.isEmpty() )
704 CreateOleComponentAndLoad_Impl();
705 m_aClassID = m_pOleComponent->GetCLSID();
707 catch(
const uno::Exception& )
714 xResult = TryToRetrieveCachedVisualRepresentation_Impl(
xStream );
720 catch(
const uno::Exception& )
730 const uno::Reference< io::XStream >& xNewObjectStream,
731 const OUString& aNewName )
739 uno::Reference<io::XSeekable> xNewSeekable(xNewObjectStream, uno::UNO_QUERY);
740 if (xNewSeekable.is() && xNewSeekable->getLength() == 0)
742 uno::Reference<io::XSeekable> xOldSeekable(
m_xObjectStream, uno::UNO_QUERY);
743 if (xOldSeekable.is() && xOldSeekable->getLength() > 0)
745 SAL_WARN(
"embeddedobj.ole",
"OleEmbeddedObject::SwitchOwnPersistence(stream version): "
746 "empty new stream, reusing old one");
747 uno::Reference<io::XInputStream> xInput =
m_xObjectStream->getInputStream();
748 uno::Reference<io::XOutputStream> xOutput = xNewObjectStream->getOutputStream();
749 xOldSeekable->seek(0);
751 xNewSeekable->seek(0);
756 uno::Reference< lang::XComponent > xComponent(
m_xObjectStream, uno::UNO_QUERY );
757 OSL_ENSURE( !
m_xObjectStream.is() || xComponent.is(),
"Wrong stream implementation!" );
758 if ( xComponent.is() )
759 xComponent->dispose();
761 catch (
const uno::Exception& )
772 const OUString& aNewName )
777 sal_Int32 nStreamMode =
m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
779 uno::Reference< io::XStream > xNewOwnStream = xNewParentStorage->openStreamElement( aNewName, nStreamMode );
781 uno::Reference<io::XSeekable> xNewSeekable (xNewOwnStream, uno::UNO_QUERY);
782 if (xNewSeekable.is() && xNewSeekable->getLength() == 0)
784 uno::Reference<io::XSeekable> xOldSeekable(
m_xObjectStream, uno::UNO_QUERY);
785 if (xOldSeekable.is() && xOldSeekable->getLength() > 0)
787 SAL_WARN(
"embeddedobj.ole",
"OleEmbeddedObject::SwitchOwnPersistence: empty new stream, reusing old one");
788 uno::Reference<io::XInputStream> xInput =
m_xObjectStream->getInputStream();
789 uno::Reference<io::XOutputStream> xOutput = xNewOwnStream->getOutputStream();
791 xNewSeekable->seek(0);
795 SAL_WARN_IF( !xNewOwnStream.is(),
"embeddedobj.ole",
"The method can not return empty reference!" );
802bool OleEmbeddedObject::SaveObject_Impl()
804 bool bResult =
false;
813 catch(
const uno::Exception& )
822bool OleEmbeddedObject::OnShowWindow_Impl(
bool bShow )
824 osl::ClearableMutexGuard aGuard(
m_aMutex);
826 bool bResult =
false;
829 SAL_WARN_IF(
m_nObjectState == embed::EmbedStates::LOADED,
"embeddedobj.ole",
"The object get OnShowWindow in loaded state!" );
843 else if ( !bShow &&
m_nObjectState == embed::EmbedStates::ACTIVE )
857 catch(
const uno::Exception& )
866void OleEmbeddedObject::OnIconChanged_Impl()
873void OleEmbeddedObject::OnViewChanged_Impl()
876 throw lang::DisposedException();
891 (MimeConfigurationHelper::ClassIDsEqual(
m_aClassID, MimeConfigurationHelper::GetSequenceClassID(0x852ee1c9, 0x9058, 0x44ba, 0x8c, 0x6c, 0x0c, 0x5f, 0xc6, 0x6b, 0xdb, 0x8d)) ||
892 MimeConfigurationHelper::ClassIDsEqual(
m_aClassID, MimeConfigurationHelper::GetSequenceClassID(0xcf1b4491, 0xbea3, 0x4c9f, 0xa7, 0x0f, 0x22, 0x1b, 0x1e, 0xca, 0xef, 0x3e)))
904void OleEmbeddedObject::OnClosed_Impl()
907 throw lang::DisposedException();
918OUString OleEmbeddedObject::CreateTempURLEmpty_Impl()
920 SAL_WARN_IF( !
m_aTempURL.isEmpty(),
"embeddedobj.ole",
"The object has already the temporary file!" );
927OUString OleEmbeddedObject::GetTempURL_Impl()
931 SAL_INFO(
"embeddedobj.ole",
"embeddedobj (mv76033) OleEmbeddedObject::GetTempURL_Impl, tempfile creation" );
934 uno::Reference< embed::XOptimizedStorage > xOptParStorage(
m_xParentStorage, uno::UNO_QUERY );
935 if ( xOptParStorage.is() )
942 uno::Reference< io::XInputStream > xInStream =
m_xObjectStream->getInputStream();
943 if ( !xInStream.is() )
944 throw io::IOException();
954void OleEmbeddedObject::CreateOleComponent_Impl(
969void OleEmbeddedObject::CreateOleComponentAndLoad_Impl(
975 throw uno::RuntimeException();
977 CreateOleComponent_Impl( pOleComponent );
984 throw uno::RuntimeException();
991void OleEmbeddedObject::CreateOleComponentFromClipboard_Impl(
OleComponent* pOleComponent )
996 throw uno::RuntimeException();
998 CreateOleComponent_Impl( pOleComponent );
1007uno::Reference< io::XOutputStream > OleEmbeddedObject::GetStreamForSaving()
1010 throw uno::RuntimeException();
1012 uno::Reference< io::XOutputStream > xOutStream =
m_xObjectStream->getOutputStream();
1013 if ( !xOutStream.is() )
1014 throw io::IOException();
1016 uno::Reference< io::XTruncate > xTruncate( xOutStream, uno::UNO_QUERY_THROW );
1017 xTruncate->truncate();
1023void OleEmbeddedObject::StoreObjectToStream( uno::Reference< io::XOutputStream >
const & xOutStream )
1031 throw uno::RuntimeException();
1034 uno::Reference < ucb::XSimpleFileAccess3 > xTempAccess(
1035 ucb::SimpleFileAccess::create(
m_xContext ) );
1037 uno::Reference< io::XInputStream > xTempInStream = xTempAccess->openFileRead(
m_aTempURL );
1038 SAL_WARN_IF( !xTempInStream.is(),
"embeddedobj.ole",
"The object's temporary file can not be reopened for reading!" );
1042 if ( !xTempInStream.is() )
1044 throw io::IOException();
1048 uno::Reference< io::XTruncate > xTrunc( xOutStream, uno::UNO_QUERY_THROW );
1059 const uno::Reference< embed::XStorage >& xStorage,
1060 const OUString& sEntName,
1061 const uno::Sequence< beans::PropertyValue >& lObjArgs,
1070 throw embed::WrongStateException(
"Can't store object without persistence!",
1075 throw embed::WrongStateException(
1076 "The object waits for saveCompleted() call!",
1081 bool bVisReplIsStored =
false;
1083 bool bTryOptimization =
false;
1085 uno::Reference< io::XStream > xCachedVisualRepresentation;
1086 for ( beans::PropertyValue
const & prop : lObjArgs )
1088 if ( prop.Name ==
"StoreVisualReplacement" )
1089 prop.Value >>= bStoreVis;
1090 else if ( prop.Name ==
"VisualReplacement" )
1091 prop.Value >>= xCachedVisualRepresentation;
1092 else if ( prop.Name ==
"CanTryOptimization" )
1093 prop.Value >>= bTryOptimization;
1098 xCachedVisualRepresentation.clear();
1101 throw io::IOException();
1104 bool bNeedLocalCache = xCachedVisualRepresentation.is();
1106 uno::Reference< io::XStream > xTargetStream;
1108 bool bStoreLoaded =
false;
1117 bool bOptimizedCopyingDone =
false;
1123 uno::Reference< embed::XOptimizedStorage > xSourceOptStor(
m_xParentStorage, uno::UNO_QUERY_THROW );
1124 uno::Reference< embed::XOptimizedStorage > xTargetOptStor( xStorage, uno::UNO_QUERY_THROW );
1125 xSourceOptStor->copyElementDirectlyTo(
m_aEntryName, xTargetOptStor, sEntName );
1126 bOptimizedCopyingDone =
true;
1128 catch(
const uno::Exception& )
1133 if ( !bOptimizedCopyingDone )
1144 bNeedLocalCache =
false;
1148 bStoreLoaded =
true;
1154 xStorage->openStreamElement( sEntName, embed::ElementModes::READWRITE );
1155 if ( !xTargetStream.is() )
1156 throw io::IOException();
1158 SetStreamMediaType_Impl( xTargetStream,
"application/vnd.sun.star.oleobject" );
1159 uno::Reference< io::XOutputStream > xOutStream = xTargetStream->getOutputStream();
1160 if ( !xOutStream.is() )
1161 throw io::IOException();
1163 StoreObjectToStream( xOutStream );
1164 bVisReplIsStored =
true;
1172 uno::Reference< io::XStream > xTmpCVRepresentation =
1176 if ( xTmpCVRepresentation.is() )
1178 xCachedVisualRepresentation = xTmpCVRepresentation;
1179 bNeedLocalCache =
false;
1186 throw io::IOException();
1189 if ( !xTargetStream.is() )
1192 xStorage->openStreamElement( sEntName, embed::ElementModes::READWRITE );
1193 if ( !xTargetStream.is() )
1194 throw io::IOException();
1199 if ( bStoreVis != bVisReplIsStored )
1203 if ( !xCachedVisualRepresentation.is() )
1206 SAL_WARN_IF( !xCachedVisualRepresentation.is(),
"embeddedobj.ole",
"No representation is available!" );
1213 uno::Reference< io::XSeekable > xCachedSeek( xCachedVisualRepresentation, uno::UNO_QUERY );
1214 if ( !xCachedSeek.is() )
1216 xCachedVisualRepresentation
1218 bNeedLocalCache =
false;
1227 if ( !xCachedVisualRepresentation.is() )
1244 if ( xCachedVisualRepresentation.is() )
1246 if ( bNeedLocalCache )
1257 uno::Reference< lang::XComponent > xComp( xTargetStream, uno::UNO_QUERY );
1262 }
catch(
const uno::Exception& )
1271 const uno::Reference< embed::XStorage >& xStorage,
1272 const OUString& sEntName,
1273 sal_Int32 nEntryConnectionMode,
1274 const uno::Sequence< beans::PropertyValue >& lArguments,
1275 const uno::Sequence< beans::PropertyValue >& lObjArgs )
1278 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1279 if ( xWrappedObject.is() )
1282 xWrappedObject->setPersistentEntry( xStorage, sEntName, nEntryConnectionMode, lArguments, lObjArgs );
1294 ::osl::MutexGuard aGuard(
m_aMutex );
1296 throw lang::DisposedException();
1298 if ( !xStorage.is() )
1299 throw lang::IllegalArgumentException(
"No parent storage is provided!",
1303 if ( sEntName.isEmpty() )
1304 throw lang::IllegalArgumentException(
"Empty element name is provided!",
1309 if ( (
m_nObjectState != -1 || nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
1310 && (
m_nObjectState == -1 || nEntryConnectionMode != embed::EntryInitModes::NO_INIT ) )
1318 throw embed::WrongStateException(
1319 "Can't change persistent representation of activated object!",
1325 if ( nEntryConnectionMode != embed::EntryInitModes::NO_INIT )
1326 throw embed::WrongStateException(
1327 "The object waits for saveCompleted() call!",
1332 uno::Reference< container::XNameAccess > xNameAccess( xStorage, uno::UNO_QUERY_THROW );
1335 bool bElExists = xNameAccess->hasByName( sEntName );
1338 for ( beans::PropertyValue
const & prop : lArguments )
1339 if ( prop.Name ==
"ReadOnly" )
1343 sal_Int32 nStorageMode =
m_bReadOnly ? embed::ElementModes::READ : embed::ElementModes::READWRITE;
1348 for ( beans::PropertyValue
const & prop : lObjArgs )
1349 if ( prop.Name ==
"StoreVisualReplacement" )
1353 if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT )
1359 CreateOleComponentFromClipboard_Impl();
1364 else if ( bElExists )
1371 CreateOleComponentAndLoad_Impl();
1374 catch(
const uno::Exception& )
1386 CreateOleComponent_Impl();
1394 if ( ( nStorageMode & embed::ElementModes::READWRITE ) != embed::ElementModes::READWRITE )
1395 throw io::IOException();
1397 if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
1403 else if ( nEntryConnectionMode == embed::EntryInitModes::TRUNCATE_INIT )
1406 CreateOleComponent_Impl();
1412 else if ( nEntryConnectionMode == embed::EntryInitModes::MEDIA_DESCRIPTOR_INIT )
1416 for ( beans::PropertyValue
const & prop : lArguments )
1417 if ( prop.Name ==
"URL" )
1418 prop.Value >>=
aURL;
1420 if (
aURL.isEmpty() )
1421 throw lang::IllegalArgumentException(
1422 "Empty URL is provided in the media descriptor!",
1426 CreateOleComponent_Impl();
1444 throw lang::IllegalArgumentException(
"Wrong connection mode is provided!",
1450 if ( nEntryConnectionMode == embed::EntryInitModes::DEFAULT_INIT && bElExists )
1457 else if ( nEntryConnectionMode == embed::EntryInitModes::NO_INIT )
1462 throw lang::IllegalArgumentException(
"Wrong connection mode is provided!",
1471 const OUString& sEntName,
1472 const uno::Sequence< beans::PropertyValue >& lArguments,
1473 const uno::Sequence< beans::PropertyValue >& lObjArgs )
1476 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1477 if ( xWrappedObject.is() )
1480 xWrappedObject->storeToEntry( xStorage, sEntName, lArguments, lObjArgs );
1485 ::osl::MutexGuard aGuard(
m_aMutex );
1487 throw lang::DisposedException();
1498 const OUString& sEntName,
1499 const uno::Sequence< beans::PropertyValue >& lArguments,
1500 const uno::Sequence< beans::PropertyValue >& lObjArgs )
1503 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1504 if ( xWrappedObject.is() )
1507 xWrappedObject->storeAsEntry( xStorage, sEntName, lArguments, lObjArgs );
1512 ::osl::MutexGuard aGuard(
m_aMutex );
1514 throw lang::DisposedException();
1527 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1528 if ( xWrappedObject.is() )
1531 xWrappedObject->saveCompleted( bUseNew );
1536 osl::ClearableMutexGuard aGuard(
m_aMutex);
1538 throw lang::DisposedException();
1543 throw embed::WrongStateException(
"Can't store object without persistence!",
1553 throw io::IOException();
1557 throw uno::RuntimeException();
1571 SAL_WARN_IF( !xComponent.is(),
"embeddedobj.ole",
"Wrong storage implementation!" );
1572 if ( xComponent.is() )
1573 xComponent->dispose();
1575 catch (
const uno::Exception& )
1601 catch(
const uno::Exception& )
1623 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1624 if ( xWrappedObject.is() )
1627 return xWrappedObject->hasEntry();
1631 ::osl::MutexGuard aGuard(
m_aMutex );
1633 throw lang::DisposedException();
1636 throw embed::WrongStateException(
1637 "The object waits for saveCompleted() call!",
1650 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1651 if ( xWrappedObject.is() )
1654 return xWrappedObject->getEntryName();
1658 ::osl::MutexGuard aGuard(
m_aMutex );
1660 throw lang::DisposedException();
1665 throw embed::WrongStateException(
"The object persistence is not initialized!",
1670 throw embed::WrongStateException(
1671 "The object waits for saveCompleted() call!",
1681 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1682 if ( xWrappedObject.is() )
1685 xWrappedObject->storeOwn();
1694 osl::ClearableMutexGuard aGuard(
m_aMutex);
1696 throw lang::DisposedException();
1703 throw embed::WrongStateException(
"Can't store object without persistence!",
1708 throw embed::WrongStateException(
1709 "The object waits for saveCompleted() call!",
1713 throw io::IOException();
1717 bool bStoreLoaded =
true;
1722 bStoreLoaded =
false;
1727 throw io::IOException();
1729 SetStreamMediaType_Impl(
m_xObjectStream,
"application/vnd.sun.star.oleobject" );
1730 uno::Reference< io::XOutputStream > xOutStream =
m_xObjectStream->getOutputStream();
1731 if ( !xOutStream.is() )
1732 throw io::IOException();
1735 StoreObjectToStream( GetStreamForSaving() );
1777 catch(
const uno::Exception& )
1795 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1796 if ( xWrappedObject.is() )
1799 return xWrappedObject->isReadonly();
1803 ::osl::MutexGuard aGuard(
m_aMutex );
1805 throw lang::DisposedException();
1810 throw embed::WrongStateException(
"The object persistence is not initialized!",
1815 throw embed::WrongStateException(
1816 "The object waits for saveCompleted() call!",
1824 const uno::Sequence< beans::PropertyValue >& lArguments,
1825 const uno::Sequence< beans::PropertyValue >& lObjArgs )
1828 uno::Reference< embed::XEmbedPersist > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1829 if ( xWrappedObject.is() )
1832 xWrappedObject->reload( lArguments, lObjArgs );
1839 ::osl::MutexGuard aGuard(
m_aMutex );
1841 throw lang::DisposedException();
1846 throw embed::WrongStateException(
"The object persistence is not initialized!",
1851 throw embed::WrongStateException(
1852 "The object waits for saveCompleted() call!",
1863 const OUString& sEntName )
1866 uno::Reference< embed::XLinkageSupport > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1867 if ( xWrappedObject.is() )
1870 xWrappedObject->breakLink( xStorage, sEntName );
1875 ::osl::MutexGuard aGuard(
m_aMutex );
1877 throw lang::DisposedException();
1879 if ( !xStorage.is() )
1880 throw lang::IllegalArgumentException(
"No parent storage is provided!",
1884 if ( sEntName.isEmpty() )
1885 throw lang::IllegalArgumentException(
"Empty element name is provided!",
1893 throw embed::WrongStateException(
1894 "The object is not a valid linked object!",
1899 throw io::IOException();
1902 throw embed::WrongStateException(
1903 "The object waits for saveCompleted() call!",
1918 catch (
const uno::Exception&)
1929 catch (
const uno::Exception&)
1939 CreateOleComponent_Impl(pNewOleComponent);
1951 if (nTargetState == embed::EmbedStates::RUNNING)
1965 throw io::IOException();
1973 uno::Reference< embed::XLinkageSupport > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1974 if ( xWrappedObject.is() )
1977 return xWrappedObject->isLink();
1981 ::osl::MutexGuard aGuard(
m_aMutex );
1983 throw lang::DisposedException();
1992 uno::Reference< embed::XLinkageSupport > xWrappedObject(
m_xWrappedObject, uno::UNO_QUERY );
1993 if ( xWrappedObject.is() )
1996 return xWrappedObject->getLinkURL();
2000 ::osl::MutexGuard aGuard(
m_aMutex );
2002 throw lang::DisposedException();
2005 throw embed::WrongStateException(
2006 "The object waits for saveCompleted() call!",
2010 throw embed::WrongStateException(
2011 "The object is not a link object!",
Reference< XComponentContext > m_xContext
css::uno::Reference< css::embed::XEmbeddedClient > m_xClientSite
css::uno::Reference< css::io::XStream > TryToGetAcceptableFormat_Impl(const css::uno::Reference< css::io::XStream > &xStream)
css::uno::Reference< css::io::XStream > m_xCachedVisualRepresentation
void StoreToLocation_Impl(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs, bool bSaveAs)
virtual css::awt::Size SAL_CALL getVisualAreaSize(sal_Int64 nAspect) override
css::uno::Reference< css::io::XStream > TryToRetrieveCachedVisualRepresentation_Impl(const css::uno::Reference< css::io::XStream > &xStream, bool bAllowRepair50=false) noexcept
virtual OUString SAL_CALL getLinkURL() override
css::uno::Reference< css::io::XStream > GetNewFilledTempStream_Impl(const css::uno::Reference< css::io::XInputStream > &xInStream)
virtual void SAL_CALL storeOwn() override
css::uno::Reference< css::util::XCloseListener > m_xClosePreventer
void RemoveVisualCache_Impl(const css::uno::Reference< css::io::XStream > &xTargetStream)
css::uno::Reference< css::embed::XStorage > m_xParentStorage
css::uno::Reference< css::io::XStream > m_xNewCachedVisRepl
virtual sal_Bool SAL_CALL hasEntry() override
void MakeEventListenerNotification_Impl(const OUString &aEventName)
css::uno::Reference< css::io::XStream > m_xNewObjectStream
virtual OUString SAL_CALL getEntryName() override
css::uno::Sequence< sal_Int8 > m_aClassID
virtual void SAL_CALL storeAsEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
bool m_bNewVisReplInStream
void SetVisReplInStream(bool bExists)
virtual sal_Bool SAL_CALL isReadonly() override
virtual sal_Bool SAL_CALL isLink() override
virtual void SAL_CALL setPersistentEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, sal_Int32 nEntryConnectionMode, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
void InsertVisualCache_Impl(const css::uno::Reference< css::io::XStream > &xTargetStream, const css::uno::Reference< css::io::XStream > &xCachedVisualRepresentation)
rtl::Reference< OleComponent > m_pOleComponent
bool m_bWaitSaveCompleted
bool m_bVisReplInitialized
void SwitchOwnPersistence(const css::uno::Reference< css::embed::XStorage > &xNewParentStorage, const css::uno::Reference< css::io::XStream > &xNewObjectStream, const OUString &aNewName)
friend class OleComponent
css::uno::Reference< css::uno::XComponentContext > m_xContext
VerbExecutionController m_aVerbExecutionController
virtual void SAL_CALL storeToEntry(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
css::uno::Reference< css::io::XStream > m_xObjectStream
virtual void SAL_CALL saveCompleted(sal_Bool bUseNew) override
css::uno::Reference< css::embed::XStorage > m_xNewParentStorage
virtual void SAL_CALL reload(const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Sequence< css::beans::PropertyValue > &lObjArgs) override
css::uno::Reference< css::embed::XEmbeddedObject > m_xWrappedObject
bool HasVisReplInStream()
virtual void SAL_CALL breakLink(const css::uno::Reference< css::embed::XStorage > &xStorage, const OUString &sEntName) override
bool m_bStreamReadOnly
If it is allowed to modify entries in the stream of the OLE storage.
void UnlockNotification()
::osl::Mutex m_aVerbExecutionMutex
sal_Int32 m_nNotificationLock
static void CopyInputToOutput(const css::uno::Reference< css::io::XInputStream > &xInput, const css::uno::Reference< css::io::XOutputStream > &xOutput)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
#define SAL_INFO(area, stream)
std::unique_ptr< sal_Int32[]> pData
constexpr OUStringLiteral aData
OUString GetNewTempFileURL_Impl(const uno::Reference< uno::XComponentContext > &xContext)
bool KillFile_Impl(const OUString &aURL, const uno::Reference< uno::XComponentContext > &xContext)
static void LetCommonStoragePassBeUsed_Impl(const uno::Reference< io::XStream > &xStream)
OUString GetNewFilledTempFile_Impl(const uno::Reference< io::XInputStream > &xInStream, const uno::Reference< uno::XComponentContext > &xContext)