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 virtual void Closed()
override;
160 virtual ::sfx2::SvBaseLink::UpdateResult
DataChanged(
161 const OUString& rMimeType,
const css::uno::Any & rValue )
override;
180 OSL_ENSURE( xObject.is(),
"The object must exist always!" );
188 sal_Int32
nState = xObject->getCurrentState();
189 if (
nState != embed::EmbedStates::LOADED )
192 xObject->changeState( embed::EmbedStates::LOADED );
193 xObject->changeState(
nState );
196 catch (
const uno::Exception&)
211 SvBaseLink::Closed();
220 mbOLESizeInvalid( false ),
221 mpObjectLink( nullptr )
227 const OUString &rString,
232 maOLEObj( rString, nAspect ),
233 mbOLESizeInvalid( false ),
234 mpObjectLink( nullptr )
266 OSL_ENSURE(
false,
"Why are we creating a DocShell here?" );
273 xChild->setParent(
p->GetModel() );
280 xChild->setParent(
nullptr );
281 OSL_FAIL(
"InsertObject failed" );
296 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwOLENode"));
297 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
298 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST(
"index"),
299 BAD_CAST(OString::number(sal_Int32(
GetIndex())).getStr()));
303 (void)xmlTextWriterEndElement(pWriter);
315#if OSL_DEBUG_LEVEL > 0
317 OSL_ENSURE(
p,
"No document!" );
321 OSL_ENSURE( !pCnt || &rCnt == pCnt,
"The helper is assigned to unexpected container!" );
329 xChild->setParent(
nullptr );
347 bool bKeepObjectToTempStorage =
true;
352 uno::Reference< chart2::XChartDocument > xChart( xIP->getComponent(), UNO_QUERY );
353 if (xChart.is() && !xChart->hasInternalDataProvider())
355 bKeepObjectToTempStorage =
false;
369 catch (
const uno::Exception&)
384 OSL_ENSURE( pGrfColl,
"SwNodes::MakeOLENode: Formatpointer is 0." );
387 new SwOLENode( rWhere, xObj, pGrfColl,
nullptr );
396 xChild->setParent( pDocSh->
GetModel() );
405 OSL_ENSURE( pGrfColl,
"SwNodes::MakeOLENode: Formatpointer is 0." );
408 new SwOLENode( rWhere, rName, nAspect, pGrfColl, pAutoAttr );
417 xChild->setParent( pDocSh->
GetModel() );
425 MapMode aMapMode( MapUnit::MapTwip );
437 pPersistShell =
new SwDocShell( rDoc, SfxObjectCreateMode::INTERNAL );
474 const SwNode* pAnchorNd =
this;
485 }
while( pAnchorNd->
GetIndex() < nEndExtraIdx );
511 return !
p->GetEmbeddedObjectContainer().HasEmbeddedObject(
maOLEObj.
m_aName );
525 bool bResult =
false;
529 OUString aNewLinkURL;
531 if ( !aNewLinkURL.equalsIgnoreAsciiCase(
maLinkURL ) )
537 uno::Reference< embed::XCommonEmbedPersist > xPersObj( xObj, uno::UNO_QUERY );
538 OSL_ENSURE( xPersObj.is(),
"The object must exist!" );
543 sal_Int32 nCurState = xObj->getCurrentState();
544 if ( nCurState != embed::EmbedStates::LOADED )
545 xObj->changeState( embed::EmbedStates::LOADED );
549 "URL", aNewLinkURL) };
550 xPersObj->reload( aArgs, uno::Sequence< beans::PropertyValue >() );
555 if ( nCurState != embed::EmbedStates::LOADED )
556 xObj->changeState( nCurState );
558 catch (
const uno::Exception&)
580 uno::Reference< embed::XStorage > xStorage = pPers->
GetStorage();
581 if ( !xStorage.is() )
586 uno::Reference< embed::XLinkageSupport > xLinkSupport(
maOLEObj.
GetOleRef(), uno::UNO_QUERY_THROW );
591 catch( uno::Exception& )
613 if ( xLinkSupport->isLink() )
615 const OUString aLinkURL = xLinkSupport->getLinkURL();
616 if ( !aLinkURL.isEmpty() )
626 catch( uno::Exception& )
634 bool bIsChart(
false );
636 const uno::Reference< embed::XEmbeddedObject > xEmbObj =
652 if(
nullptr == pFrame)
669 if(rShell.VisArea().Overlaps(aFrameArea) &&
OUTDEV_WINDOW == rShell.GetOut()->GetOutDevType())
672 rShell.GetWin()->Invalidate(aFrameArea.
SVRect());
677namespace {
class DeflateThread; }
695 std::shared_ptr<comphelper::ThreadTaskTag>
mpTag;
740 :
comphelper::ThreadTask(rDeflateData.mpTag), mrDeflateData(rDeflateData)
745 virtual void doWork()
override
757 catch (
const uno::Exception&)
764 delete &mrDeflateData;
774 m_pOLENode( nullptr ),
776 m_nGraphicVersion( 0 )
787 m_pOLENode( nullptr ),
789 m_nGraphicVersion( 0 )
818#if OSL_DEBUG_LEVEL > 0
820 OSL_ENSURE(
p,
"No document!" );
824 OSL_ENSURE( !pCnt || &rCnt == pCnt,
"The helper is assigned to unexpected container!" );
832 xChild->setParent(
nullptr );
847 catch ( uno::Exception& )
874 OSL_ENSURE(
false,
"Why are we creating a DocShell here??" );
875 p =
new SwDocShell( rDoc, SfxObjectCreateMode::INTERNAL );
881 if ( xChild.is() && xChild->getParent() !=
p->GetModel() )
883 xChild->setParent(
p->GetModel() );
884 if (!
p->GetEmbeddedObjectContainer().InsertEmbeddedObject(
m_xOLERef.
GetObject(), aObjName ) )
886 OSL_FAIL(
"InsertObject failed" );
888 xChild->setParent(
nullptr );
931 auto pFlyFrame =
static_cast<SwFlyFrame*
>(pUpper);
932 const SwFrame* pAnchor = pFlyFrame->GetAnchorFrame();
946 assert(
p &&
"No SvPersist present");
949 uno::Reference < embed::XEmbeddedObject > xObj =
p->GetEmbeddedObjectContainer().GetEmbeddedObject(
m_aName, &
sDocumentBaseURL);
950 OSL_ENSURE( !
m_xOLERef.
is(),
"Calling GetOleRef() recursively is not permitted" );
981 else if (
m_xOLERef->getCurrentState() == embed::EmbedStates::RUNNING )
1011 : m_rManager(const_cast<
SwDoc&>(rDoc).GetDocumentSettingManager())
1028 sal_Int32
nState = xObj.is() ? xObj->getCurrentState() : embed::EmbedStates::LOADED;
1029 bool bIsActive = (
nState != embed::EmbedStates::LOADED &&
nState != embed::EmbedStates::RUNNING );
1030 sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1032 if( nState != embed::EmbedStates::LOADED && !pDoc->
IsInDtor() && !bIsActive &&
1033 embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1034 embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) )
1043 uno::Reference < util::XModifiable > xMod( xObj->getComponent(), uno::UNO_QUERY );
1044 if( xMod.is() && xMod->isModified() )
1046 uno::Reference < embed::XEmbedPersist > xPers( xObj, uno::UNO_QUERY );
1047 assert(xPers.is() &&
"Modified object without persistence in cache!");
1054 xObj->changeState( embed::EmbedStates::LOADED );
1056 catch (
const uno::Exception&)
1071 uno::Reference< embed::XEmbeddedObject > xEmbObj =
GetOleRef();
1072 if ( !xEmbObj.is() )
1077 return SwResId(STR_MATH_FORMULA);
1125 const uno::Reference< frame::XModel > aXModel(
m_xOLERef->getComponent(), uno::UNO_QUERY);
1130 static bool bAsynchronousLoadingAllowed =
false;
1133 !bAsynchronousLoadingAllowed)
1148 std::unique_ptr<DeflateThread> pNew(
new DeflateThread(*
m_pDeflateData) );
1182 (void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwOLEObj"));
1183 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
1187 (void)xmlTextWriterEndElement(pWriter);
1190SwOLELRUCache::SwOLELRUCache()
1192 , m_nLRU_InitSize( 20 )
1194 EnableNotification( GetPropertyNames() );
1198uno::Sequence< OUString > SwOLELRUCache::GetPropertyNames()
1209void SwOLELRUCache::ImplCommit()
1213void SwOLELRUCache::Load()
1217 const Any*
pValues = aValues.getConstArray();
1218 OSL_ENSURE( aValues.getLength() == aNames.getLength(),
"GetProperties failed" );
1219 if (aValues.getLength() != aNames.getLength() || !
pValues->hasValue())
1225 if (nVal < m_nLRU_InitSize)
1229 sal_Int32
nCount = m_OleObjects.size();
1233 while( nCount > nVal )
1243 m_nLRU_InitSize = nVal;
1246void SwOLELRUCache::InsertObj(
SwOLEObj& rObj )
1249 if (
auto const it = std::find(m_OleObjects.begin(), m_OleObjects.end(), pObj);
1250 it != m_OleObjects.end())
1252 if (it == m_OleObjects.begin())
1255 m_OleObjects.erase(it);
1260 sal_Int32
nCount = m_OleObjects.size();
1262 while (nPos >= 0 && nCount >= m_nLRU_InitSize)
1264 pObj = m_OleObjects[
nPos-- ];
1268 m_OleObjects.push_front(&rObj);
1271void SwOLELRUCache::RemoveObj(
SwOLEObj& rObj )
1273 auto const it = std::find(m_OleObjects.begin(), m_OleObjects.end(), &rObj);
1274 if (it != m_OleObjects.end())
1276 m_OleObjects.erase(it);
1278 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()
virtual void Closed() override
virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(const OUString &rMimeType, const css::uno::Any &rValue) override
SwEmbedObjectLink(SwOLENode *pNode)
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)
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
SwEmbedObjectLink * mpObjectLink
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
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)
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)