20#include <com/sun/star/container/XChild.hpp>
21#include <com/sun/star/embed/XEmbeddedObject.hpp>
22#include <com/sun/star/embed/XEmbedPersist.hpp>
23#include <com/sun/star/embed/XLinkageSupport.hpp>
24#include <com/sun/star/embed/EmbedMisc.hpp>
25#include <com/sun/star/embed/EmbedStates.hpp>
26#include <com/sun/star/util/XModifiable.hpp>
27#include <com/sun/star/chart2/XChartDocument.hpp>
58#include <libxml/xmlwriter.h>
59#include <osl/diagnose.h>
72 std::deque<SwOLEObj *> m_OleObjects;
73 sal_Int32 m_nLRU_InitSize;
74 static uno::Sequence< OUString > GetPropertyNames();
81 virtual void Notify(
const uno::Sequence<
82 OUString>& aPropertyNames )
override;
99 virtual void SAL_CALL
changingState(
const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
override;
100 virtual void SAL_CALL
stateChanged(
const lang::EventObject& aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState )
override;
101 virtual void SAL_CALL
disposing(
const lang::EventObject& aEvent )
override;
119 if (
mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
125 else if (
mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
130 else if(
mpObj && nNewState == embed::EmbedStates::RUNNING)
159 explicit SwEmbedObjectLink(
SwOLENode* pNode);
161 virtual void Closed()
override;
162 virtual ::sfx2::SvBaseLink::UpdateResult
DataChanged(
163 const OUString& rMimeType,
const css::uno::Any & rValue )
override;
168SwEmbedObjectLink::SwEmbedObjectLink(
SwOLENode* pNode)
172 SetSynchron(
false );
178 if (!m_pOleNode->UpdateLinkURL_Impl())
181 uno::Reference<embed::XEmbeddedObject> xObject = m_pOleNode->GetOLEObj().GetOleRef();
182 OSL_ENSURE( xObject.is(),
"The object must exist always!" );
190 sal_Int32
nState = xObject->getCurrentState();
191 if ( nState != embed::EmbedStates::LOADED )
194 xObject->changeState( embed::EmbedStates::LOADED );
195 xObject->changeState( nState );
198 catch (
const uno::Exception&)
204 m_pOleNode->GetNewReplacement();
205 m_pOleNode->SetChanged();
210void SwEmbedObjectLink::Closed()
212 m_pOleNode->BreakFileLink_Impl();
213 SvBaseLink::Closed();
232 uno::Reference<embed::XCommonEmbedPersist> xPersObj(xObject, uno::UNO_QUERY);
238 xPersObj->reload(uno::Sequence<beans::PropertyValue>(), uno::Sequence<beans::PropertyValue>());
240 catch (
const uno::Exception&)
260 mbOLESizeInvalid( false ),
261 mpObjectLink( nullptr )
267 const OUString &rString,
272 maOLEObj( rString, nAspect ),
273 mbOLESizeInvalid( false ),
274 mpObjectLink( nullptr )
306 OSL_ENSURE(
false,
"Why are we creating a DocShell here?" );
313 xChild->setParent(
p->GetModel() );
320 xChild->setParent(
nullptr );
321 OSL_FAIL(
"InsertObject failed" );
336 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwOLENode"));
337 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
338 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"index"),
339 BAD_CAST(OString::number(sal_Int32(
GetIndex())).getStr()));
343 (void)xmlTextWriterEndElement(pWriter);
355#if OSL_DEBUG_LEVEL > 0
357 OSL_ENSURE(
p,
"No document!" );
361 OSL_ENSURE( !pCnt || &rCnt == pCnt,
"The helper is assigned to unexpected container!" );
369 xChild->setParent(
nullptr );
387 bool bKeepObjectToTempStorage =
true;
392 uno::Reference< chart2::XChartDocument > xChart( xIP->getComponent(), UNO_QUERY );
393 if (xChart.is() && !xChart->hasInternalDataProvider())
395 bKeepObjectToTempStorage =
false;
409 catch (
const uno::Exception&)
424 OSL_ENSURE( pGrfColl,
"SwNodes::MakeOLENode: Formatpointer is 0." );
427 new SwOLENode( rWhere, xObj, pGrfColl,
nullptr );
436 xChild->setParent( pDocSh->
GetModel() );
445 OSL_ENSURE( pGrfColl,
"SwNodes::MakeOLENode: Formatpointer is 0." );
448 new SwOLENode( rWhere, rName, nAspect, pGrfColl, pAutoAttr );
457 xChild->setParent( pDocSh->
GetModel() );
465 MapMode aMapMode( MapUnit::MapTwip );
477 pPersistShell =
new SwDocShell( rDoc, SfxObjectCreateMode::INTERNAL );
514 const SwNode* pAnchorNd =
this;
525 }
while( pAnchorNd->
GetIndex() < nEndExtraIdx );
551 return !
p->GetEmbeddedObjectContainer().HasEmbeddedObject(
maOLEObj.
m_aName );
565 bool bResult =
false;
569 OUString aNewLinkURL;
571 if ( !aNewLinkURL.equalsIgnoreAsciiCase(
maLinkURL ) )
577 uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObj, uno::UNO_QUERY );
578 OSL_ENSURE( xPersObj.is(),
"The object must exist!" );
583 sal_Int32 nCurState = xObj->getCurrentState();
584 if ( nCurState != embed::EmbedStates::LOADED )
585 xObj->changeState( embed::EmbedStates::LOADED );
589 "URL", aNewLinkURL) };
590 xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
595 if ( nCurState != embed::EmbedStates::LOADED )
596 xObj->changeState( nCurState );
598 catch (
const uno::Exception&)
620 uno::Reference< embed::XStorage > xStorage = pPers->
GetStorage();
621 if ( !xStorage.is() )
626 uno::Reference< embed::XLinkageSupport > xLinkSupport(
maOLEObj.
GetOleRef(), uno::UNO_QUERY_THROW );
631 catch( uno::Exception& )
656 bool bIFrame =
false;
659 uno::Reference<embed::XLinkageSupport> xLinkSupport(xObject, uno::UNO_QUERY);
662 if (xLinkSupport->isLink())
663 aLinkURL = xLinkSupport->getLinkURL();
672 uno::Reference<beans::XPropertySet> xSet(xObject->getComponent(), uno::UNO_QUERY);
674 xSet->getPropertyValue(
"FrameURL") >>= aLinkURL;
679 if (!aLinkURL.isEmpty())
681 SwEmbedObjectLink* pEmbedObjectLink =
nullptr;
684 pEmbedObjectLink =
new SwEmbedObjectLink(
this);
693 if (pEmbedObjectLink)
694 pEmbedObjectLink->Connect();
697 catch( uno::Exception& )
705 bool bIsChart(
false );
707 const uno::Reference< embed::XEmbeddedObject > xEmbObj =
723 if(
nullptr == pFrame)
740 if(rShell.VisArea().Overlaps(aFrameArea) &&
OUTDEV_WINDOW == rShell.GetOut()->GetOutDevType())
743 rShell.GetWin()->Invalidate(aFrameArea.
SVRect());
748namespace {
class DeflateThread; }
766 std::shared_ptr<comphelper::ThreadTaskTag>
mpTag;
811 :
comphelper::ThreadTask(rDeflateData.mpTag), mrDeflateData(rDeflateData)
816 virtual void doWork()
override
828 catch (
const uno::Exception&)
835 delete &mrDeflateData;
845 m_pOLENode( nullptr ),
847 m_nGraphicVersion( 0 )
858 m_pOLENode( nullptr ),
860 m_nGraphicVersion( 0 )
889#if OSL_DEBUG_LEVEL > 0
891 OSL_ENSURE(
p,
"No document!" );
895 OSL_ENSURE( !pCnt || &rCnt == pCnt,
"The helper is assigned to unexpected container!" );
903 xChild->setParent(
nullptr );
918 catch ( uno::Exception& )
945 OSL_ENSURE(
false,
"Why are we creating a DocShell here??" );
946 p =
new SwDocShell( rDoc, SfxObjectCreateMode::INTERNAL );
952 if ( xChild.is() && xChild->getParent() !=
p->GetModel() )
954 xChild->setParent(
p->GetModel() );
955 if (!
p->GetEmbeddedObjectContainer().InsertEmbeddedObject(
m_xOLERef.
GetObject(), aObjName ) )
957 OSL_FAIL(
"InsertObject failed" );
959 xChild->setParent(
nullptr );
1002 auto pFlyFrame =
static_cast<SwFlyFrame*
>(pUpper);
1003 const SwFrame* pAnchor = pFlyFrame->GetAnchorFrame();
1017 assert(
p &&
"No SvPersist present");
1020 uno::Reference < embed::XEmbeddedObject > xObj =
p->GetEmbeddedObjectContainer().GetEmbeddedObject(
m_aName, &
sDocumentBaseURL);
1021 OSL_ENSURE( !
m_xOLERef.
is(),
"Calling GetOleRef() recursively is not permitted" );
1052 else if (
m_xOLERef->getCurrentState() == embed::EmbedStates::RUNNING )
1082 : m_rManager(const_cast<
SwDoc&>(rDoc).GetDocumentSettingManager())
1099 sal_Int32
nState = xObj.is() ? xObj->getCurrentState() : embed::EmbedStates::LOADED;
1100 bool bIsActive = (
nState != embed::EmbedStates::LOADED &&
nState != embed::EmbedStates::RUNNING );
1101 sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1103 if( nState != embed::EmbedStates::LOADED && !pDoc->
IsInDtor() && !bIsActive &&
1104 embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1105 embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) )
1114 uno::Reference < util::XModifiable > xMod( xObj->getComponent(), uno::UNO_QUERY );
1115 if( xMod.is() && xMod->isModified() )
1117 uno::Reference < embed::XEmbedPersist > xPers( xObj, uno::UNO_QUERY );
1118 assert(xPers.is() &&
"Modified object without persistence in cache!");
1125 xObj->changeState( embed::EmbedStates::LOADED );
1127 catch (
const uno::Exception&)
1142 uno::Reference< embed::XEmbeddedObject > xEmbObj =
GetOleRef();
1143 if ( !xEmbObj.is() )
1148 return SwResId(STR_MATH_FORMULA);
1196 const uno::Reference< frame::XModel > aXModel(
m_xOLERef->getComponent(), uno::UNO_QUERY);
1201 static bool bAsynchronousLoadingAllowed =
false;
1204 !bAsynchronousLoadingAllowed)
1219 std::unique_ptr<DeflateThread> pNew(
new DeflateThread(*
m_pDeflateData) );
1253 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwOLEObj"));
1254 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
1258 (void)xmlTextWriterEndElement(pWriter);
1261SwOLELRUCache::SwOLELRUCache()
1263 , m_nLRU_InitSize( 20 )
1265 EnableNotification( GetPropertyNames() );
1269uno::Sequence< OUString > SwOLELRUCache::GetPropertyNames()
1280void SwOLELRUCache::ImplCommit()
1284void SwOLELRUCache::Load()
1288 const Any*
pValues = aValues.getConstArray();
1289 OSL_ENSURE( aValues.getLength() == aNames.getLength(),
"GetProperties failed" );
1290 if (aValues.getLength() != aNames.getLength() || !
pValues->hasValue())
1296 if (nVal < m_nLRU_InitSize)
1300 sal_Int32
nCount = m_OleObjects.size();
1304 while( nCount > nVal )
1314 m_nLRU_InitSize = nVal;
1317void SwOLELRUCache::InsertObj(
SwOLEObj& rObj )
1320 if (
auto const it = std::find(m_OleObjects.begin(), m_OleObjects.end(), pObj);
1321 it != m_OleObjects.end())
1323 if (it == m_OleObjects.begin())
1326 m_OleObjects.erase(it);
1331 sal_Int32
nCount = m_OleObjects.size();
1333 while (nPos >= 0 && nCount >= m_nLRU_InitSize)
1335 pObj = m_OleObjects[
nPos-- ];
1339 m_OleObjects.push_front(&rObj);
1342void SwOLELRUCache::RemoveObj(
SwOLEObj& rObj )
1344 auto const it = std::find(m_OleObjects.begin(), m_OleObjects.end(), &rObj);
1345 if (it != m_OleObjects.end())
1347 m_OleObjects.erase(it);
1349 if (m_OleObjects.empty())
const PropertyValue * pValues
constexpr OUStringLiteral sDocumentBaseURL
static drawinglayer::primitive2d::Primitive2DContainer tryToGetChartContentAsPrimitive2DSequence(const css::uno::Reference< css::frame::XModel > &rXModel, basegfx::B2DRange &rRange)
Holder for local data for a parallel-executed task to load a chart model.
drawinglayer::primitive2d::Primitive2DContainer maPrimitive2DSequence
DeflateData(uno::Reference< frame::XModel > xXModel)
std::atomic< bool > mbKilled
std::shared_ptr< comphelper::ThreadTaskTag > mpTag
basegfx::B2DRange maRange
const drawinglayer::primitive2d::Primitive2DContainer & getSequence() const
uno::Reference< frame::XModel > maXModel
const basegfx::B2DRange & getRange() const
virtual sfx2::LinkManager & GetLinkManager()=0
PurgeGuard(const SwDoc &rDoc)
~PurgeGuard() COVERITY_NOEXCEPT_FALSE
::sw::DocumentSettingManager & m_rManager
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual OUString getDocumentBaseURL() const override
css::uno::Reference< css::embed::XStorage > const & GetStorage()
static sal_uInt16 IsChart(const SvGlobalName &rName)
static sal_uInt16 IsMath(const SvGlobalName &rName)
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
const SwAttrSet * GetpSwAttrSet() const
virtual bool ResetAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0)
const SwGrfFormatColl * GetDfltGrfFormatColl() const
void SetOLEPrtNotifyPending(bool bSet=true)
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
void SetTmpDocShell(SfxObjectShellLock rLock)
in case during copying of embedded object a new shell is created, it should be set here and cleaned l...
SfxObjectShell * GetPersist() const
::sw::DocumentSettingManager & GetDocumentSettingManager()
SwDocShell * GetDocShell()
general base class for all free-flowing frames
const SwRect & getFrameArea() const
Base class of the Writer layout elements.
bool IsProtected() const
Is the Frame or rather the Section in which it lies protected?
SwLayoutFrame * GetUpper()
Layout frame for SwNoTextNode, i.e. graphics and OLE nodes (including charts).
void SetContour(const tools::PolyPolygon *pPoly, bool bAutomatic=false)
bool HasAutomaticContour() const
OUString GetTitle() const
const tools::PolyPolygon * HasContour() const
void SetTitle(const OUString &rTitle)
void SetDescription(const OUString &rDescription)
Base class of the Writer document model elements.
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
SwNodeOffset GetIndex() const
SwNodes & GetNodes()
Node is in which nodes-array/doc?
SwSectionNode * FindSectionNode()
Search section node, in which it is.
const SwStartNode * StartOfSectionNode() const
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
SwOLENode * MakeOLENode(SwNode &rWhere, const svt::EmbeddedObjectRef &, SwGrfFormatColl *pColl)
in ndole.cxx
SwDoc & GetDoc()
Which Doc contains the nodes-array?
virtual void SAL_CALL disposing(const lang::EventObject &aEvent) override
virtual void SAL_CALL stateChanged(const lang::EventObject &aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState) override
SwOLEListener_Impl(SwOLEObj *pObj)
virtual void SAL_CALL changingState(const lang::EventObject &aEvent, ::sal_Int32 nOldState, ::sal_Int32 nNewState) override
SwOLENode(SwNode &rWhere, const svt::EmbeddedObjectRef &, SwGrfFormatColl *pGrfColl, SwAttrSet const *pAutoAttr)
sfx2::SvBaseLink * mpObjectLink
bool IsOLEObjectDeleted() const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Dumps the node structure to the given destination (file nodes.xml in the current directory by default...
virtual Size GetTwipSize() const override
OUString GetDescription() const
Remove OLE-object from "memory".
bool UpdateLinkURL_Impl()
sal_Int64 GetAspect() const
const SwOLEObj & GetOLEObj() const
virtual bool SavePersistentData() override
OLE object is transported into UNDO area.
virtual bool RestorePersistentData() override
Loading an OLE object that has been moved to the Undo Area.
void DisconnectFileLink_Impl()
bool IsInGlobalDocSection() const
void SetChartTableName(const OUString &rNm)
void SetOLESizeInvalid(bool b)
const Graphic * GetGraphic()
void BreakFileLink_Impl()
const OUString & GetChartTableName() const
OUString msChartTableName
with chart objects: name of referenced table.
void CheckFileLink_Impl()
void SetAspect(sal_Int64 nAspect)
virtual ~SwOLENode() override
virtual SwContentNode * MakeCopy(SwDoc &, SwNode &rWhere, bool bNewFrames) const override
Is in ndcopy.cxx.
svt::EmbeddedObjectRef m_xOLERef
Either ref or name are known.
~SwOLEObj() COVERITY_NOEXCEPT_FALSE
void SetNode(SwOLENode *pNode)
drawinglayer::primitive2d::Primitive2DContainer const & tryToGetChartContentAsPrimitive2DSequence(basegfx::B2DRange &rRange, bool bSynchron)
sal_uInt32 m_nGraphicVersion
svt::EmbeddedObjectRef & GetObject()
std::unique_ptr< DeflateData > m_pDeflateData
bool IsOleRef() const
To avoid unnecessary loading of object.
css::uno::Reference< css::embed::XEmbeddedObject > const & GetOleRef()
void dumpAsXml(xmlTextWriterPtr pWriter) const
OUString GetDescription()
drawinglayer::primitive2d::Primitive2DContainer m_aPrimitive2DSequence
SwOLEObj(const SwOLEObj &rObj)=delete
const OUString & GetCurrentPersistName() const
const SwOLENode * m_pOLENode
rtl::Reference< SwOLEListener_Impl > m_xListener
OUString GetStyleString()
basegfx::B2DRange m_aRange
Of course Writer needs its own rectangles.
void SSize(const Size &rNew)
tools::Rectangle SVRect() const
A section node represents the start of a section on the UI, i.e.
const SwSection & GetSection() const
SectionType GetType() const
bool HasEmbeddedObject(const OUString &)
css::uno::Reference< css::embed::XEmbeddedObject > CopyAndGetEmbeddedObject(EmbeddedObjectContainer &rSrc, const css::uno::Reference< css::embed::XEmbeddedObject > &xObj, OUString &rName, const OUString &rSrcShellID, const OUString &rDestShellID)
void RemoveEmbeddedObject(const OUString &rName, bool bKeepToTempStorage=true)
css::uno::Reference< css::embed::XEmbeddedObject > GetEmbeddedObject(const OUString &, OUString const *pBaseURL=nullptr)
static ThreadPool & getSharedOptimalPool()
void waitUntilDone(const std::shared_ptr< ThreadTaskTag > &, bool bJoin=true)
void pushTask(std::unique_ptr< ThreadTask > pTask)
static bool isTaskTagDone(const std::shared_ptr< ThreadTaskTag > &)
#define SO3_DUMMY_CLASSID
#define SO3_IFRAME_CLASSID
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, std::u16string_view rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
void Remove(SvBaseLink const *pLink)
void SetSynchron(bool bFlag)
virtual UpdateResult DataChanged(const OUString &rMimeType, const css::uno::Any &rValue)
SvLinkSource * GetRealObject()
void AssignToContainer(comphelper::EmbeddedObjectContainer *pContainer, const OUString &rPersistName)
void SetViewAspect(sal_Int64 nAspect)
void SetIsProtectedHdl(const Link< LinkParamNone *, bool > &rProtectedHdl)
sal_uInt32 getGraphicVersion() const
comphelper::EmbeddedObjectContainer * GetContainer() const
void dumpAsXml(xmlTextWriterPtr pWriter) const
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
void UpdateReplacement(bool bUpdateOle=false)
void Lock(bool bLock=true)
const Graphic * GetGraphic() const
sal_Int64 GetViewAspect() const
Size GetSize(MapMode const *pTargetMapMode) const
void Assign(const css::uno::Reference< css::embed::XEmbeddedObject > &xObj, sal_Int64 nAspect)
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
virtual bool get(DocumentSettingId id) const override
Return the specified document setting.
virtual void set(DocumentSettingId id, bool value) override
Set the specified document setting.
ring_container GetRingContainer()
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames)=0
virtual void ImplCommit()=0
struct _xmlTextWriter * xmlTextWriterPtr
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(99)
#define LINK(Instance, Class, Member)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
IMPL_LINK_NOARG(SwOLEObj, IsProtectedHdl, LinkParamNone *, bool)
static std::shared_ptr< SwOLELRUCache > g_pOLELRU_Cache
const char *const aClassID
OUString SwResId(TranslateId aId)