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>
40 #include <section.hxx>
52 #include <strings.hrc>
57 #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();
76 virtual void ImplCommit()
override;
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?" );
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 );
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());
677 namespace {
class DeflateThread; }
695 std::shared_ptr<comphelper::ThreadTaskTag>
mpTag;
698 explicit DeflateData(
const uno::Reference< frame::XModel >& rXModel)
701 mpTag(
comphelper::ThreadPool::createThreadTaskTag() )
740 :
comphelper::ThreadTask(rDeflateData.mpTag), mrDeflateData(rDeflateData)
745 virtual void doWork()
override
757 catch (
const uno::Exception&)
764 delete &mrDeflateData;
774 m_pOLENode( nullptr ),
786 m_pOLENode( nullptr ),
816 #if OSL_DEBUG_LEVEL > 0
818 OSL_ENSURE( p,
"No document!" );
822 OSL_ENSURE( !pCnt || &rCnt == pCnt,
"The helper is assigned to unexpected container!" );
830 xChild->setParent(
nullptr );
845 catch ( uno::Exception& )
872 OSL_ENSURE(
false,
"Why are we creating a DocShell here??" );
873 p =
new SwDocShell( rDoc, SfxObjectCreateMode::INTERNAL );
879 if ( xChild.is() && xChild->getParent() != p->
GetModel() )
884 OSL_FAIL(
"InsertObject failed" );
886 xChild->setParent(
nullptr );
929 auto pFlyFrame =
static_cast<SwFlyFrame*
>(pUpper);
930 const SwFrame* pAnchor = pFlyFrame->GetAnchorFrame();
944 assert(p &&
"No SvPersist present");
948 OSL_ENSURE( !
m_xOLERef.
is(),
"Calling GetOleRef() recursively is not permitted" );
979 else if (
m_xOLERef->getCurrentState() == embed::EmbedStates::RUNNING )
1009 : m_rManager(const_cast<
SwDoc&>(rDoc).GetDocumentSettingManager())
1026 sal_Int32
nState = xObj.is() ? xObj->getCurrentState() : embed::EmbedStates::LOADED;
1027 bool bIsActive = ( nState != embed::EmbedStates::LOADED && nState != embed::EmbedStates::RUNNING );
1028 sal_Int64 nMiscStatus = xObj->getStatus( nAspect );
1030 if( nState != embed::EmbedStates::LOADED && !pDoc->
IsInDtor() && !bIsActive &&
1031 embed::EmbedMisc::MS_EMBED_ALWAYSRUN != ( nMiscStatus & embed::EmbedMisc::MS_EMBED_ALWAYSRUN ) &&
1032 embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY != ( nMiscStatus & embed::EmbedMisc::EMBED_ACTIVATEIMMEDIATELY ) )
1041 uno::Reference < util::XModifiable > xMod( xObj->getComponent(), uno::UNO_QUERY );
1042 if( xMod.is() && xMod->isModified() )
1044 uno::Reference < embed::XEmbedPersist > xPers( xObj, uno::UNO_QUERY );
1045 assert(xPers.is() &&
"Modified object without persistence in cache!");
1052 xObj->changeState( embed::EmbedStates::LOADED );
1054 catch (
const uno::Exception&)
1069 uno::Reference< embed::XEmbeddedObject > xEmbObj =
GetOleRef();
1070 if ( !xEmbObj.is() )
1075 return SwResId(STR_MATH_FORMULA);
1107 const uno::Reference< frame::XModel > aXModel(
m_xOLERef->getComponent(), uno::UNO_QUERY);
1112 static bool bAsynchronousLoadingAllowed =
false;
1115 !bAsynchronousLoadingAllowed)
1130 std::unique_ptr<DeflateThread> pNew(
new DeflateThread(*
m_pDeflateData) );
1161 (
void)xmlTextWriterStartElement(pWriter, BAD_CAST(
"SwOLEObj"));
1162 (
void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST(
"ptr"),
"%p",
this);
1166 (
void)xmlTextWriterEndElement(pWriter);
1169 SwOLELRUCache::SwOLELRUCache()
1171 , m_nLRU_InitSize( 20 )
1173 EnableNotification( GetPropertyNames() );
1177 uno::Sequence< OUString > SwOLELRUCache::GetPropertyNames()
1188 void SwOLELRUCache::ImplCommit()
1192 void SwOLELRUCache::Load()
1196 const Any*
pValues = aValues.getConstArray();
1197 OSL_ENSURE( aValues.getLength() == aNames.getLength(),
"GetProperties failed" );
1198 if (aValues.getLength() != aNames.getLength() || !pValues->hasValue())
1204 if (nVal < m_nLRU_InitSize)
1208 sal_Int32
nCount = m_OleObjects.size();
1209 sal_Int32
nPos = nCount;
1212 while( nCount > nVal )
1214 SwOLEObj *
const pObj = m_OleObjects[ --nPos ];
1222 m_nLRU_InitSize = nVal;
1225 void SwOLELRUCache::InsertObj(
SwOLEObj& rObj )
1228 if (
auto const it = std::find(m_OleObjects.begin(), m_OleObjects.end(), pObj);
1229 it != m_OleObjects.end())
1231 if (it == m_OleObjects.begin())
1234 m_OleObjects.erase(it);
1239 sal_Int32 nCount = m_OleObjects.size();
1240 sal_Int32 nPos = nCount-1;
1241 while (nPos >= 0 && nCount >= m_nLRU_InitSize)
1243 pObj = m_OleObjects[ nPos-- ];
1247 m_OleObjects.push_front(&rObj);
1250 void SwOLELRUCache::RemoveObj(
SwOLEObj& rObj )
1252 auto const it = std::find(m_OleObjects.begin(), m_OleObjects.end(), &rObj);
1253 if (it != m_OleObjects.end())
1255 m_OleObjects.erase(it);
1257 if (m_OleObjects.empty())
void SetAspect(sal_Int64 nAspect)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
#define LINK(Instance, Class, Member)
virtual void SAL_CALL stateChanged(const lang::EventObject &aEvent,::sal_Int32 nOldState,::sal_Int32 nNewState) override
SwSectionNode * FindSectionNode()
Search section node, in which it is.
void SetDescription(const OUString &rDescription)
css::uno::Reference< css::embed::XEmbeddedObject > CreateEmbeddedObject(const css::uno::Sequence< sal_Int8 > &, OUString &, OUString const *pBaseURL=nullptr)
Base class of the Writer layout elements.
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
const css::uno::Reference< css::embed::XEmbeddedObject > & GetObject() const
const char *const aClassID
SwOLENode(const SwNodeIndex &rWhere, const svt::EmbeddedObjectRef &, SwGrfFormatColl *pGrfColl, SwAttrSet const *pAutoAttr)
sal_Int64 GetAspect() const
~PurgeGuard() COVERITY_NOEXCEPT_FALSE
bool HasAutomaticContour() const
virtual SwContentNode * MakeCopy(SwDoc &, const SwNodeIndex &, bool bNewFrames) const override
Is in ndcopy.cxx.
constexpr OUStringLiteral sDocumentBaseURL
const SwOLEObj & GetOLEObj() const
virtual bool get(DocumentSettingId id) const override
Return the specified document setting.
OUString msChartTableName
with chart objects: name of referenced table.
SwDocShell * GetDocShell()
SwDoc & GetDoc()
Which Doc contains the nodes-array?
OUString GetDescription()
void InsertFileLink(sfx2::SvBaseLink &, SvBaseLinkObjectType nFileType, std::u16string_view rFileNm, const OUString *pFilterNm=nullptr, const OUString *pRange=nullptr)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
const OUString & GetChartTableName() const
std::unique_ptr< DeflateData > m_pDeflateData
void SetTitle(const OUString &rTitle)
css::uno::Reference< css::embed::XEmbeddedObject > const & GetOleRef()
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
rtl::Reference< SwOLEListener_Impl > m_xListener
css::uno::Reference< css::frame::XModel3 > GetModel() const
IDocumentLinksAdministration const & getIDocumentLinksAdministration() const
virtual void set(DocumentSettingId id, bool value) override
Set the specified document setting.
bool HasEmbeddedObject(const OUString &)
void SetTmpDocShell(SfxObjectShellLock rLock)
in case during copying of embedded object a new shell is created, it should be set here and cleaned l...
Of course Writer needs its own rectangles.
virtual OUString getDocumentBaseURL() const override
std::atomic< bool > mbKilled
void waitUntilDone(const std::shared_ptr< ThreadTaskTag > &, bool bJoin=true)
void DisconnectFileLink_Impl()
static sal_uInt16 IsChart(const SvGlobalName &rName)
virtual ~SwOLENode() override
void UpdateReplacement(bool bUpdateOle=false)
const tools::PolyPolygon * HasContour() const
const SwSection & GetSection() const
css::uno::Reference< css::embed::XStorage > const & GetStorage()
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Dumps the node structure to the given destination (file nodes.xml in the current directory by default...
OUString SwResId(TranslateId aId)
IMPL_LINK_NOARG(SwOLEObj, IsProtectedHdl, LinkParamNone *, bool)
bool UpdateLinkURL_Impl()
drawinglayer::primitive2d::Primitive2DContainer const & tryToGetChartContentAsPrimitive2DSequence(basegfx::B2DRange &rRange, bool bSynchron)
static drawinglayer::primitive2d::Primitive2DContainer tryToGetChartContentAsPrimitive2DSequence(const css::uno::Reference< css::frame::XModel > &rXModel, basegfx::B2DRange &rRange)
~SwOLEObj() COVERITY_NOEXCEPT_FALSE
const SwRect & getFrameArea() const
svt::EmbeddedObjectRef & GetObject()
drawinglayer::primitive2d::Primitive2DContainer m_aPrimitive2DSequence
const Graphic * GetGraphic() const
void dumpAsXml(xmlTextWriterPtr pWriter) const
const SwOLENode * m_pOLENode
SwEmbedObjectLink(SwOLENode *pNode)
static sal_uInt16 IsMath(const SvGlobalName &rName)
uno::Reference< frame::XModel > maXModel
::sw::DocumentSettingManager & m_rManager
const OUString & GetCurrentPersistName() const
virtual void Closed() override
basegfx::B2DRange maRange
static ThreadPool & getSharedOptimalPool()
virtual bool ResetAttr(sal_uInt16 nWhich1, sal_uInt16 nWhich2=0)
SwOLENode * MakeOLENode(const SwNodeIndex &rWhere, const svt::EmbeddedObjectRef &, SwGrfFormatColl *pColl)
in ndole.cxx
const SwAttrSet * GetpSwAttrSet() const
void SetOLEPrtNotifyPending(bool bSet=true)
void AssignToContainer(comphelper::EmbeddedObjectContainer *pContainer, const OUString &rPersistName)
virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(const OUString &rMimeType, const css::uno::Any &rValue) override
Holder for local data for a parallel-executed task to load a chart model.
comphelper::EmbeddedObjectContainer * GetContainer() const
drawinglayer::primitive2d::Primitive2DContainer maPrimitive2DSequence
void pushTask(std::unique_ptr< ThreadTask > pTask)
const SwStartNode * StartOfSectionNode() const
void Remove(SvBaseLink const *pLink)
#define SO3_DUMMY_CLASSID
void Assign(const css::uno::Reference< css::embed::XEmbeddedObject > &xObj, sal_Int64 nAspect)
const Graphic * GetGraphic()
SwNodeOffset GetIndex() const
SwLayoutFrame * GetUpper()
static bool isTaskTagDone(const std::shared_ptr< ThreadTaskTag > &)
SvLinkSource * GetRealObject()
Layout frame for SwNoTextNode, i.e. graphics and OLE nodes (including charts).
Marks a node in the document model.
OUString GetStyleString()
SwNodes & GetNodes()
Node is in which nodes-array/doc?
SwEmbedObjectLink * mpObjectLink
ring_container GetRingContainer()
std::shared_ptr< comphelper::ThreadTaskTag > mpTag
void SSize(const Size &rNew)
virtual Size GetTwipSize() const override
DeflateData(const uno::Reference< frame::XModel > &rXModel)
virtual bool SavePersistentData() override
OLE object is transported into UNDO area.
virtual void SAL_CALL changingState(const lang::EventObject &aEvent,::sal_Int32 nOldState,::sal_Int32 nNewState) override
void SetNode(SwOLENode *pNode)
bool IsOLEObjectDeleted() const
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
css::uno::Reference< css::embed::XEmbeddedObject > GetEmbeddedObject(const OUString &, OUString const *pBaseURL=nullptr)
bool IsOleRef() const
To avoid unnecessary loading of object.
void SetChartTableName(const OUString &rNm)
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
void RemoveEmbeddedObject(const OUString &rName, bool bKeepToTempStorage=true)
static std::shared_ptr< SwOLELRUCache > g_pOLELRU_Cache
const PropertyValue * pValues
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
void SetViewAspect(sal_Int64 nAspect)
SwOLEListener_Impl(SwOLEObj *pObj)
void SetIsProtectedHdl(const Link< LinkParamNone *, bool > &rProtectedHdl)
general base class for all free-flowing frames
void dumpAsXml(xmlTextWriterPtr pWriter) const
OUString GetTitle() const
void CheckFileLink_Impl()
virtual void SAL_CALL disposing(const lang::EventObject &aEvent) override
virtual bool RestorePersistentData() override
Loading an OLE object that has been moved to the Undo Area.
void BreakFileLink_Impl()
PurgeGuard(const SwDoc &rDoc)
::sw::DocumentSettingManager & GetDocumentSettingManager()
SfxObjectShell * GetPersist() const
Size GetSize(MapMode const *pTargetMapMode) const
svt::EmbeddedObjectRef m_xOLERef
Either ref or name are known.
bool InsertEmbeddedObject(const css::uno::Reference< css::embed::XEmbeddedObject > &, OUString &)
SwOLEObj(const SwOLEObj &rObj)=delete
void SetOLESizeInvalid(bool b)
virtual sfx2::LinkManager & GetLinkManager()=0
const basegfx::B2DRange & getRange() const
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)
const drawinglayer::primitive2d::Primitive2DContainer & getSequence() const
struct _xmlTextWriter * xmlTextWriterPtr
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
void SetSynchron(bool bFlag)
basegfx::B2DRange m_aRange
SectionType GetType() const
sal_Int64 GetViewAspect() const
const SwGrfFormatColl * GetDfltGrfFormatColl() const
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
void Lock(bool bLock=true)
SwFrameFormat * GetFlyFormat() const
If node is in a fly return the respective format.
void SetContour(const tools::PolyPolygon *pPoly, bool bAutomatic=false)
bool m_bDetectedRangeSegmentation false
bool IsProtected() const
Is the Frame or rather the Section in which it lies protected?
Base class of the Writer document model elements.
OUString GetDescription() const
Remove OLE-object from "memory".
bool IsInGlobalDocSection() const