embeddedobj/source/commonembedding/embedobj.cxx      |   60 -
 embeddedobj/source/commonembedding/specialobject.cxx |    9 
 embeddedobj/source/inc/commonembobj.hxx              |    3 
 embeddedobj/source/inc/specialobject.hxx             |    7 
 include/svx/svdoole2.hxx                             |   17 
 include/svx/unoshape.hxx                             |    2 
 sc/source/ui/docshell/documentlinkmgr.cxx            |    9 
 sfx2/source/doc/iframe.cxx                           |   72 +
 svx/source/svdraw/svdoole2.cxx                       |  698 ++++++++++---------
 svx/source/unodraw/shapeimpl.hxx                     |    5 
 svx/source/unodraw/unoshap4.cxx                      |   23 
 sw/inc/ndole.hxx                                     |    4 
 sw/source/core/ole/ndole.cxx                         |  213 +++--
 xmloff/source/draw/ximpshap.cxx                      |   29 
 xmloff/source/draw/ximpshap.hxx                      |    2 
 15 files changed, 701 insertions(+), 452 deletions(-)

New commits:
commit b5c3fa5f071ebca8ca84a88a4738c9cdefc05660
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Apr 20 20:58:21 2023 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue May 2 16:50:34 2023 +0200

    assume IFrame script/macro support isn't needed
    
    seems undocumented at least
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151020
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    (cherry picked from commit a10a5994bddf7646196ff45f6af598420d8663ad)
    
    Change-Id: I316e4f4f25ddb7cf6b7bac4d856a721b987207a3

diff --git a/sfx2/source/doc/iframe.cxx b/sfx2/source/doc/iframe.cxx
index caffa41519d6..1703572a2647 100644
--- a/sfx2/source/doc/iframe.cxx
+++ b/sfx2/source/doc/iframe.cxx
@@ -161,6 +161,7 @@ IFrameObject::IFrameObject(const uno::Reference < 
uno::XComponentContext >& rxCo
         aArguments[0] >>= mxObj;
 }
 
+#if 0
 bool lcl_isScriptURLAllowed(const OUString& aScriptURL)
 {
     boost::optional<css::uno::Sequence<OUString>> allowedEvents(
@@ -185,6 +186,7 @@ bool lcl_isScriptURLAllowed(const OUString& aScriptURL)
 
     return false;
 }
+#endif
 
 sal_Bool SAL_CALL IFrameObject::load(
     const uno::Sequence < css::beans::PropertyValue >& /*lDescriptor*/,
@@ -197,23 +199,16 @@ sal_Bool SAL_CALL IFrameObject::load(
         uno::Reference < util::XURLTransformer > xTrans( 
util::URLTransformer::create( mxContext ) );
         xTrans->parseStrict( aTargetURL );
 
+        INetURLObject aURLObject(aTargetURL.Complete);
+        if (aURLObject.GetProtocol() == INetProtocol::Macro || 
aURLObject.isSchemeEqualTo(u"vnd.sun.star.script"))
+            return false;
+
         uno::Reference<frame::XFramesSupplier> xParentFrame = 
xFrame->getCreator();
         SfxObjectShell* pDoc = SfxMacroLoader::GetObjectShell(xParentFrame);
 
-        if (INetURLObject(aTargetURL.Complete).GetProtocol() == 
INetProtocol::Macro)
-        {
-            if (pDoc && !pDoc->AdjustMacroMode())
-                return false;
-        }
-
-        if (!lcl_isScriptURLAllowed(aTargetURL.Complete))
-            return false;
-
         bool bUpdateAllowed(true);
         if (pDoc)
         {
-            // perhaps should only check for file targets, but lets default to 
making it strong
-            // unless there is a known need to distinguish
             comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = 
pDoc->getEmbeddedObjectContainer();
             bUpdateAllowed = 
rEmbeddedObjectContainer.getUserAllowsLinkUpdate();
         }
commit 75c054528349be688c9f77edaa6d6b61ea00baf5
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Apr 13 11:31:17 2023 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue May 2 16:43:23 2023 +0200

    put floating frames under managed links control
    
    like we do for sections and ole objects that link to their content
    
    individual commits in trunk are:
    
    extract a OCommonEmbeddedObject::SetInplaceActiveState for reuse
    
    no behaviour change intended
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150341
    Tested-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit 183e34a3f8c429c0698951e24c17844e416a3825)
    
    use parent window as dialog parent
    
    it makes no odds, but is more convenient for upcoming modification
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150342
    Tested-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit f93edf343658abd489bde3639d2ffaefd50c0f99)
    
    adjust IFrameObject so it could reuse mxFrame for a reload of content
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150343
    Tested-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit 3a727d26fd9eb6fa140bc3f5cadf3db079d42206)
    
    query getUserAllowsLinkUpdate for the case of content in a floating frame
    
    similarly to how it works for the more common "normal" embedded objects
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149971
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit 52aa46468531918eabfa2031dedf50377ae72cf7)
    
    add a route to get writer Floating Frame links under 'manage links'
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150349
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit 8b8a2844addbd262befb1a2d193dfb590dfa20be)
    
    allow SvxOle2Shape::resetModifiedState to survive having no SdrObject
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150538
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit 02379929bd0e1d1676635f0ca1920422702ebb7c)
    
    create the FloatingFrameShape in a separate step to inserting it
    
    this is derived from the path taken by the AddShape(const OUString&)
    function for this case. No change in behavior is intended.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150526
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit bafec47847a0b9697b3bbe9358e53f8118af3024)
    
    add a route to get calc Floating Frame links under 'manage links'
    
    much harder than writer because the organization and ordering
    of properties and object activation etc is different.
    
    This ended up ugly, but functions.
    
    We set FrameURL before AddShape, we have to do it again later because it
    gets cleared when the SdrOle2Obj is attached to the XShape.  But we want
    FrameURL to exist when AddShape triggers SetPersistName which itself
    triggers SdrOle2Obj::CheckFileLink_Impl and at that point we want to
    know what URL will end up being used. So bodge this by setting FrameURL
    to the temp pre-SdrOle2Obj attached properties and we can smuggle it
    eventually into SdrOle2Obj::SetPersistName at the right point after
    PersistName is set but before SdrOle2Obj::CheckFileLink_Impl is called
    in order to inform the link manager that this is an IFrame that links to
    a URL
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150539
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    (cherry picked from commit 07179a5a5bd00f34acfa8a3f260dd834ae003c63)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150755
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit b91ea614c0b753ab3d378acd0e2db8262e9dbd72)
    
    bc5333b137d2da089b3b701ff615c6ddf43063d0
    7eec3132a23faafd9a2878215a0a117a67bc9bf2
    83e38dfa2f84907c2de9680e91f779d34864a9ad
    f90ff71d6a96342574799312f764badaf97980eb
    ea059262c124e3f44249e49b4189732310d28156
    d09ae0c65a55a37743ad7c184070fb8dd97d8a7f
    67fc199fef9e67fa12ca7873f0fe12137aa16d8f
    
    Change-Id: Ia1d12aa5c9afdc1347f6d4364bc6a0b7f41ee168

diff --git a/embeddedobj/source/commonembedding/embedobj.cxx 
b/embeddedobj/source/commonembedding/embedobj.cxx
index fcc7a9ed30ab..3eadf96c0973 100644
--- a/embeddedobj/source/commonembedding/embedobj.cxx
+++ b/embeddedobj/source/commonembedding/embedobj.cxx
@@ -161,6 +161,37 @@ void OCommonEmbeddedObject::StateChangeNotification_Impl( 
bool bBeforeChange, sa
     }
 }
 
+void OCommonEmbeddedObject::SetInplaceActiveState()
+{
+    if ( !m_xClientSite.is() )
+        throw embed::WrongStateException( "client site not set, yet", *this );
+
+    uno::Reference< embed::XInplaceClient > xInplaceClient( m_xClientSite, 
uno::UNO_QUERY );
+    if ( !xInplaceClient.is() || !xInplaceClient->canInplaceActivate() )
+        throw embed::WrongStateException(); //TODO: can't activate inplace
+    xInplaceClient->activatingInplace();
+
+    uno::Reference< embed::XWindowSupplier > xClientWindowSupplier( 
xInplaceClient, uno::UNO_QUERY_THROW );
+
+    m_xClientWindow = xClientWindowSupplier->getWindow();
+    m_aOwnRectangle = xInplaceClient->getPlacement();
+    m_aClipRectangle = xInplaceClient->getClipRectangle();
+    awt::Rectangle aRectangleToShow = GetRectangleInterception( 
m_aOwnRectangle, m_aClipRectangle );
+
+    // create own window based on the client window
+    // place and resize the window according to the rectangles
+    uno::Reference< awt::XWindowPeer > xClientWindowPeer( m_xClientWindow, 
uno::UNO_QUERY_THROW );
+
+    // dispatch provider may not be provided
+    uno::Reference< frame::XDispatchProvider > xContainerDP = 
xInplaceClient->getInplaceDispatchProvider();
+    bool bOk = m_xDocHolder->ShowInplace( xClientWindowPeer, aRectangleToShow, 
xContainerDP );
+    m_nObjectState = embed::EmbedStates::INPLACE_ACTIVE;
+    if ( !bOk )
+    {
+        SwitchStateTo_Impl( embed::EmbedStates::RUNNING );
+        throw embed::WrongStateException(); //TODO: can't activate inplace
+    }
+}
 
 void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 nNextState )
 {
@@ -234,34 +265,7 @@ void OCommonEmbeddedObject::SwitchStateTo_Impl( sal_Int32 
nNextState )
         {
             if ( nNextState == embed::EmbedStates::INPLACE_ACTIVE )
             {
-                if ( !m_xClientSite.is() )
-                    throw embed::WrongStateException( "client site not set, 
yet", *this );
-
-                uno::Reference< embed::XInplaceClient > xInplaceClient( 
m_xClientSite, uno::UNO_QUERY );
-                if ( !xInplaceClient.is() || 
!xInplaceClient->canInplaceActivate() )
-                    throw embed::WrongStateException(); //TODO: can't activate 
inplace
-                xInplaceClient->activatingInplace();
-
-                uno::Reference< embed::XWindowSupplier > 
xClientWindowSupplier( xInplaceClient, uno::UNO_QUERY_THROW );
-
-                m_xClientWindow = xClientWindowSupplier->getWindow();
-                m_aOwnRectangle = xInplaceClient->getPlacement();
-                m_aClipRectangle = xInplaceClient->getClipRectangle();
-                awt::Rectangle aRectangleToShow = GetRectangleInterception( 
m_aOwnRectangle, m_aClipRectangle );
-
-                // create own window based on the client window
-                // place and resize the window according to the rectangles
-                uno::Reference< awt::XWindowPeer > xClientWindowPeer( 
m_xClientWindow, uno::UNO_QUERY_THROW );
-
-                // dispatch provider may not be provided
-                uno::Reference< frame::XDispatchProvider > xContainerDP = 
xInplaceClient->getInplaceDispatchProvider();
-                bool bOk = m_xDocHolder->ShowInplace( xClientWindowPeer, 
aRectangleToShow, xContainerDP );
-                m_nObjectState = nNextState;
-                if ( !bOk )
-                {
-                    SwitchStateTo_Impl( embed::EmbedStates::RUNNING );
-                    throw embed::WrongStateException(); //TODO: can't activate 
inplace
-                }
+                SetInplaceActiveState();
             }
             else if ( nNextState == embed::EmbedStates::ACTIVE )
             {
diff --git a/embeddedobj/source/commonembedding/specialobject.cxx 
b/embeddedobj/source/commonembedding/specialobject.cxx
index 683fe0aab3f2..c17a39accf2c 100644
--- a/embeddedobj/source/commonembedding/specialobject.cxx
+++ b/embeddedobj/source/commonembedding/specialobject.cxx
@@ -47,6 +47,7 @@ uno::Any SAL_CALL OSpecialEmbeddedObject::queryInterface( 
const uno::Type& rType
     uno::Any aReturn = ::cppu::queryInterface( rType,
                                         static_cast< embed::XEmbeddedObject* 
>( this ),
                                         static_cast< embed::XInplaceObject* >( 
this ),
+                                        static_cast< 
embed::XCommonEmbedPersist* >( static_cast< embed::XEmbedPersist* >( this ) ),
                                         static_cast< embed::XVisualObject* >( 
this ),
                                         static_cast< embed::XClassifiedObject* 
>( this ),
                                         static_cast< 
embed::XComponentSupplier* >( this ),
@@ -160,4 +161,12 @@ void SAL_CALL OSpecialEmbeddedObject::doVerb( sal_Int32 
nVerbID )
         OCommonEmbeddedObject::doVerb( nVerbID );
 }
 
+void SAL_CALL OSpecialEmbeddedObject::reload(
+                const uno::Sequence< beans::PropertyValue >&,
+                const uno::Sequence< beans::PropertyValue >&)
+{
+    // Allow IFrames to reload their content
+    SetInplaceActiveState();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/embeddedobj/source/inc/commonembobj.hxx 
b/embeddedobj/source/inc/commonembobj.hxx
index 50d896440786..56583696304a 100644
--- a/embeddedobj/source/inc/commonembobj.hxx
+++ b/embeddedobj/source/inc/commonembobj.hxx
@@ -231,6 +231,9 @@ private:
                     const css::uno::Sequence< css::beans::PropertyValue >& 
lArguments,
                     const css::uno::Sequence< css::beans::PropertyValue >& 
lObjArgs );
 
+protected:
+    void SetInplaceActiveState();
+
 public:
     OCommonEmbeddedObject(
         const css::uno::Reference< css::uno::XComponentContext >& rxContext,
diff --git a/embeddedobj/source/inc/specialobject.hxx 
b/embeddedobj/source/inc/specialobject.hxx
index 32ad61a7a582..4c4bc70db377 100644
--- a/embeddedobj/source/inc/specialobject.hxx
+++ b/embeddedobj/source/inc/specialobject.hxx
@@ -48,6 +48,13 @@ public:
     virtual void SAL_CALL changeState( sal_Int32 nNewState ) override;
 
     virtual void SAL_CALL doVerb( sal_Int32 nVerbID ) override;
+
+// XCommonEmbedPersist
+
+    virtual void SAL_CALL reload(
+                const css::uno::Sequence< css::beans::PropertyValue >& 
lArguments,
+                const css::uno::Sequence< css::beans::PropertyValue >& 
lObjArgs ) override;
+
 };
 
 #endif
diff --git a/include/svx/svdoole2.hxx b/include/svx/svdoole2.hxx
index b192a438bc19..085b6e04a3a3 100644
--- a/include/svx/svdoole2.hxx
+++ b/include/svx/svdoole2.hxx
@@ -42,6 +42,7 @@ namespace frame { class XModel; }
 namespace svt { class EmbeddedObjectRef; }
 
 class SdrOle2ObjImpl;
+class SvxOle2Shape;
 
 class SVX_DLLPUBLIC SdrOle2Obj : public SdrRectObj
 {
@@ -49,7 +50,7 @@ private:
     std::unique_ptr<SdrOle2ObjImpl> mpImpl;
 
 private:
-    SVX_DLLPRIVATE void Connect_Impl();
+    SVX_DLLPRIVATE void Connect_Impl(SvxOle2Shape* pCreator = nullptr);
     SVX_DLLPRIVATE void Disconnect_Impl();
     SVX_DLLPRIVATE void AddListeners_Impl();
     SVX_DLLPRIVATE void RemoveListeners_Impl();
@@ -105,7 +106,7 @@ public:
     // OLE object has got a separate PersistName member now;
     // !!! use ::SetPersistName( ... ) only, if you know what you do !!!
     const OUString& GetPersistName() const;
-    void        SetPersistName( const OUString& rPersistName );
+    void        SetPersistName( const OUString& rPersistName, SvxOle2Shape* 
pCreator = nullptr );
 
     // One can add an application name to a SdrOle2Obj, which can be queried 
for
     // later on (SD needs this for presentation objects).
@@ -153,7 +154,7 @@ public:
                                          sal_Int64 nAspect );
     static bool Unload( const css::uno::Reference< css::embed::XEmbeddedObject 
>& xObj, sal_Int64 nAspect );
     bool Unload();
-    void Connect();
+    void Connect(SvxOle2Shape* pCreator = nullptr);
     void Disconnect();
     void ObjectLoaded();
 
@@ -200,6 +201,16 @@ public:
     void                Connect() { GetRealObject(); }
 };
 
+class SVX_DLLPUBLIC SdrIFrameLink final : public sfx2::SvBaseLink
+{
+    SdrOle2Obj* m_pObject;
+
+public:
+    explicit SdrIFrameLink(SdrOle2Obj* pObject);
+    virtual ::sfx2::SvBaseLink::UpdateResult DataChanged(
+        const OUString& rMimeType, const css::uno::Any & rValue ) override;
+};
+
 #endif // INCLUDED_SVX_SVDOOLE2_HXX
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/unoshape.hxx b/include/svx/unoshape.hxx
index 0b48d1e433d6..712552a55281 100644
--- a/include/svx/unoshape.hxx
+++ b/include/svx/unoshape.hxx
@@ -597,6 +597,8 @@ public:
     bool createObject( const SvGlobalName &aClassName );
 
     void createLink( const OUString& aLinkURL );
+
+    virtual OUString GetAndClearInitialFrameURL();
 };
 
 
diff --git a/sc/source/ui/docshell/documentlinkmgr.cxx 
b/sc/source/ui/docshell/documentlinkmgr.cxx
index cb3467c8bb69..8ea3c2cce5fb 100644
--- a/sc/source/ui/docshell/documentlinkmgr.cxx
+++ b/sc/source/ui/docshell/documentlinkmgr.cxx
@@ -142,7 +142,7 @@ bool DocumentLinkManager::hasDdeOrOleOrWebServiceLinks(bool 
bDde, bool bOle, boo
         sfx2::SvBaseLink* pBase = rLink.get();
         if (bDde && dynamic_cast<ScDdeLink*>(pBase))
             return true;
-        if (bOle && dynamic_cast<SdrEmbedObjectLink*>(pBase))
+        if (bOle && (dynamic_cast<SdrEmbedObjectLink*>(pBase) || 
dynamic_cast<SdrIFrameLink*>(pBase)))
             return true;
         if (bWebService && dynamic_cast<ScWebServiceLink*>(pBase))
             return true;
@@ -173,6 +173,13 @@ bool 
DocumentLinkManager::updateDdeOrOleOrWebServiceLinks(weld::Window* pWin)
             continue;
         }
 
+        SdrIFrameLink* pIFrameLink = dynamic_cast<SdrIFrameLink*>(pBase);
+        if (pIFrameLink)
+        {
+            pIFrameLink->Update();
+            continue;
+        }
+
         ScWebServiceLink* pWebserviceLink = 
dynamic_cast<ScWebServiceLink*>(pBase);
         if (pWebserviceLink)
         {
diff --git a/sfx2/source/doc/iframe.cxx b/sfx2/source/doc/iframe.cxx
index 6e14f5f254e1..caffa41519d6 100644
--- a/sfx2/source/doc/iframe.cxx
+++ b/sfx2/source/doc/iframe.cxx
@@ -209,31 +209,46 @@ sal_Bool SAL_CALL IFrameObject::load(
         if (!lcl_isScriptURLAllowed(aTargetURL.Complete))
             return false;
 
+        bool bUpdateAllowed(true);
+        if (pDoc)
+        {
+            // perhaps should only check for file targets, but lets default to 
making it strong
+            // unless there is a known need to distinguish
+            comphelper::EmbeddedObjectContainer& rEmbeddedObjectContainer = 
pDoc->getEmbeddedObjectContainer();
+            bUpdateAllowed = 
rEmbeddedObjectContainer.getUserAllowsLinkUpdate();
+        }
+        if (!bUpdateAllowed)
+            return false;
+
         OUString sReferer;
         if (pDoc && pDoc->HasName())
             sReferer = pDoc->GetMedium()->GetName();
 
-        DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
-        VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( 
xFrame->getContainerWindow() );
-        VclPtr<IFrameWindow_Impl> pWin = VclPtr<IFrameWindow_Impl>::Create( 
pParent, maFrmDescr.IsFrameBorderOn() );
-        pWin->SetSizePixel( pParent->GetOutputSizePixel() );
-        pWin->SetBackground();
-        pWin->Show();
-
-        uno::Reference < awt::XWindow > xWindow( 
pWin->GetComponentInterface(), uno::UNO_QUERY );
-        xFrame->setComponent( xWindow, uno::Reference < frame::XController >() 
);
+        uno::Reference<css::awt::XWindow> 
xParentWindow(xFrame->getContainerWindow());
 
-        // we must destroy the IFrame before the parent is destroyed
-        xWindow->addEventListener( this );
-
-        mxFrame = frame::Frame::create( mxContext );
-        uno::Reference < awt::XWindow > xWin( pWin->GetComponentInterface(), 
uno::UNO_QUERY );
-        mxFrame->initialize( xWin );
-        mxFrame->setName( maFrmDescr.GetName() );
-
-        uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, 
uno::UNO_QUERY );
-        if ( xFramesSupplier.is() )
-            mxFrame->setCreator( xFramesSupplier );
+        if (!mxFrame.is())
+        {
+            VclPtr<vcl::Window> pParent = 
VCLUnoHelper::GetWindow(xParentWindow);
+            VclPtr<IFrameWindow_Impl> pWin = 
VclPtr<IFrameWindow_Impl>::Create( pParent, maFrmDescr.IsFrameBorderOn() );
+            pWin->SetSizePixel( pParent->GetOutputSizePixel() );
+            pWin->SetBackground();
+            pWin->Show();
+
+            uno::Reference < awt::XWindow > xWindow( 
pWin->GetComponentInterface(), uno::UNO_QUERY );
+            xFrame->setComponent( xWindow, uno::Reference < frame::XController 
>() );
+
+            // we must destroy the IFrame before the parent is destroyed
+            xWindow->addEventListener( this );
+
+            mxFrame = frame::Frame::create( mxContext );
+            uno::Reference < awt::XWindow > xWin( 
pWin->GetComponentInterface(), uno::UNO_QUERY );
+            mxFrame->initialize( xWin );
+            mxFrame->setName( maFrmDescr.GetName() );
+
+            uno::Reference < frame::XFramesSupplier > xFramesSupplier( xFrame, 
uno::UNO_QUERY );
+            if ( xFramesSupplier.is() )
+                mxFrame->setCreator( xFramesSupplier );
+        }
 
         uno::Sequence < beans::PropertyValue > aProps(3);
         aProps[0].Name = "PluginMode";
diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx
index 8b4faca5f1d3..91a016e9ac93 100644
--- a/svx/source/svdraw/svdoole2.cxx
+++ b/svx/source/svdraw/svdoole2.cxx
@@ -78,6 +78,7 @@
 #include <sdr/contact/viewcontactofsdrole2obj.hxx>
 #include <svx/svdograf.hxx>
 #include <sdr/properties/oleproperties.hxx>
+#include <svx/unoshape.hxx>
 #include <svx/xlineit0.hxx>
 #include <svx/xlnclit.hxx>
 #include <svx/xbtmpit.hxx>
@@ -598,6 +599,35 @@ void SdrEmbedObjectLink::Closed()
     SvBaseLink::Closed();
 }
 
+SdrIFrameLink::SdrIFrameLink(SdrOle2Obj* pObject)
+    : ::sfx2::SvBaseLink(::SfxLinkUpdateMode::ONCALL, 
SotClipboardFormatId::SVXB)
+    , m_pObject(pObject)
+{
+    SetSynchron( false );
+}
+
+::sfx2::SvBaseLink::UpdateResult SdrIFrameLink::DataChanged(
+    const OUString&, const uno::Any& )
+{
+    uno::Reference<embed::XEmbeddedObject> xObject = m_pObject->GetObjRef();
+    uno::Reference<embed::XCommonEmbedPersist> xPersObj(xObject, 
uno::UNO_QUERY);
+    if (xPersObj.is())
+    {
+        // let the IFrameObject reload the link
+        try
+        {
+            xPersObj->reload(uno::Sequence<beans::PropertyValue>(), 
uno::Sequence<beans::PropertyValue>());
+        }
+        catch (const uno::Exception&)
+        {
+        }
+
+        m_pObject->SetChanged();
+    }
+
+    return SUCCESS;
+}
+
 class SdrOle2ObjImpl
 {
 public:
@@ -615,7 +645,7 @@ public:
     bool mbLoadingOLEObjectFailed:1; // New local var to avoid repeated 
loading if load of OLE2 fails
     bool mbConnected:1;
 
-    SdrEmbedObjectLink* mpObjectLink;
+    sfx2::SvBaseLink* mpObjectLink;
     OUString maLinkURL;
 
     rtl::Reference<SvxUnoShapeModifyListener> mxModifyListener;
@@ -815,7 +845,7 @@ bool SdrOle2Obj::IsEmpty() const
     return !mpImpl->mxObjRef.is();
 }
 
-void SdrOle2Obj::Connect()
+void SdrOle2Obj::Connect(SvxOle2Shape* pCreator)
 {
     if( IsEmptyPresObj() )
         return;
@@ -828,7 +858,7 @@ void SdrOle2Obj::Connect()
         return;
     }
 
-    Connect_Impl();
+    Connect_Impl(pCreator);
     AddListeners_Impl();
 }
 
@@ -928,24 +958,51 @@ void SdrOle2Obj::CheckFileLink_Impl()
 
     try
     {
-        uno::Reference< embed::XLinkageSupport > xLinkSupport( 
mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
+        uno::Reference<embed::XEmbeddedObject> xObject = 
mpImpl->mxObjRef.GetObject();
+        if (!xObject)
+            return;
 
-        if ( xLinkSupport.is() && xLinkSupport->isLink() )
-        {
-            OUString aLinkURL = xLinkSupport->getLinkURL();
+        bool bIFrame = false;
 
-            if ( !aLinkURL.isEmpty() )
+        OUString aLinkURL;
+        uno::Reference<embed::XLinkageSupport> xLinkSupport(xObject, 
uno::UNO_QUERY);
+        if (xLinkSupport)
+        {
+            if (xLinkSupport->isLink())
+                aLinkURL = xLinkSupport->getLinkURL();
+        }
+        else
+        {
+            // get IFrame (Floating Frames) listed and updatable from the
+            // manage links dialog
+            SvGlobalName aClassId(xObject->getClassID());
+            if (aClassId == SvGlobalName(SO3_IFRAME_CLASSID))
             {
-                // this is a file link so the model link manager should handle 
it
-                sfx2::LinkManager* 
pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
+                uno::Reference<beans::XPropertySet> 
xSet(xObject->getComponent(), uno::UNO_QUERY);
+                if (xSet.is())
+                    xSet->getPropertyValue("FrameURL") >>= aLinkURL;
+                bIFrame = true;
+            }
+        }
+
+        if (!aLinkURL.isEmpty()) // this is a file link so the model link 
manager should handle it
+        {
+            sfx2::LinkManager* 
pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
 
-                if ( pLinkManager )
+            if ( pLinkManager )
+            {
+                SdrEmbedObjectLink* pEmbedObjectLink = nullptr;
+                if (!bIFrame)
                 {
-                    mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
-                    mpImpl->maLinkURL = aLinkURL;
-                    pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, 
OBJECT_CLIENT_OLE, aLinkURL );
-                    mpImpl->mpObjectLink->Connect();
+                    pEmbedObjectLink = new SdrEmbedObjectLink(this);
+                    mpImpl->mpObjectLink = pEmbedObjectLink;
                 }
+                else
+                    mpImpl->mpObjectLink = new SdrIFrameLink(this);
+                mpImpl->maLinkURL = aLinkURL;
+                pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, 
OBJECT_CLIENT_OLE, aLinkURL );
+                if (pEmbedObjectLink)
+                    pEmbedObjectLink->Connect();
             }
         }
     }
@@ -955,7 +1012,7 @@ void SdrOle2Obj::CheckFileLink_Impl()
     }
 }
 
-void SdrOle2Obj::Connect_Impl()
+void SdrOle2Obj::Connect_Impl(SvxOle2Shape* pCreator)
 {
     if(mpImpl->aPersistName.isEmpty() )
         return;
@@ -996,6 +1053,17 @@ void SdrOle2Obj::Connect_Impl()
             }
         }
 
+        if (pCreator)
+        {
+            OUString sFrameURL(pCreator->GetAndClearInitialFrameURL());
+            if (!sFrameURL.isEmpty() && 
svt::EmbeddedObjectRef::TryRunningState(mpImpl->mxObjRef.GetObject()))
+            {
+                uno::Reference<beans::XPropertySet> 
xSet(mpImpl->mxObjRef->getComponent(), uno::UNO_QUERY);
+                if (xSet.is())
+                    xSet->setPropertyValue("FrameURL", uno::Any(sFrameURL));
+            }
+        }
+
         if ( mpImpl->mxObjRef.is() )
         {
             if ( !mpImpl->mxLightClient.is() )
@@ -1308,14 +1376,14 @@ SdrObjectUniquePtr SdrOle2Obj::getFullDragClone() const
     return createSdrGrafObjReplacement(false);
 }
 
-void SdrOle2Obj::SetPersistName( const OUString& rPersistName )
+void SdrOle2Obj::SetPersistName( const OUString& rPersistName, SvxOle2Shape* 
pCreator )
 {
     DBG_ASSERT( mpImpl->aPersistName.isEmpty(), "Persist name changed!");
 
     mpImpl->aPersistName = rPersistName;
     mpImpl->mbLoadingOLEObjectFailed = false;
 
-    Connect();
+    Connect(pCreator);
     SetChanged();
 }
 
diff --git a/svx/source/unodraw/shapeimpl.hxx b/svx/source/unodraw/shapeimpl.hxx
index a1a4e6963020..4381094d380a 100644
--- a/svx/source/unodraw/shapeimpl.hxx
+++ b/svx/source/unodraw/shapeimpl.hxx
@@ -64,8 +64,11 @@ public:
 
     virtual void Create( SdrObject* pNewOpj, SvxDrawPage* pNewPage ) override;
 };
+
 class SvxFrameShape : public SvxOle2Shape
 {
+private:
+    OUString m_sInitialFrameURL;
 protected:
     // override these for special property handling in subcasses. Return true 
if property is handled
     virtual bool setPropertyValueImpl( const OUString& rName, const 
SfxItemPropertySimpleEntry* pProperty, const css::uno::Any& rValue ) override;
@@ -82,6 +85,8 @@ public:
     virtual void SAL_CALL setPropertyValues( const css::uno::Sequence< 
OUString >& aPropertyNames, const css::uno::Sequence< css::uno::Any >& aValues 
) override;
 
     virtual void Create( SdrObject* pNewOpj, SvxDrawPage* pNewPage ) override;
+
+    virtual OUString GetAndClearInitialFrameURL() override;
 };
 
 
diff --git a/svx/source/unodraw/unoshap4.cxx b/svx/source/unodraw/unoshap4.cxx
index f7629f338858..6dc18d6cf9e4 100644
--- a/svx/source/unodraw/unoshap4.cxx
+++ b/svx/source/unodraw/unoshap4.cxx
@@ -180,7 +180,7 @@ bool SvxOle2Shape::setPropertyValueImpl( const OUString& 
rName, const SfxItemPro
 #else
             pOle = static_cast<SdrOle2Obj*>(GetSdrObject());
 #endif
-            pOle->SetPersistName( aPersistName );
+            pOle->SetPersistName( aPersistName, this );
             return true;
         }
         break;
@@ -501,10 +501,11 @@ void SvxOle2Shape::createLink( const OUString& aLinkURL )
 
 void SvxOle2Shape::resetModifiedState()
 {
-    ::comphelper::IEmbeddedHelper* pPersist = 
GetSdrObject()->getSdrModelFromSdrObject().GetPersist();
+    SdrObject* pObject = GetSdrObject();
+    ::comphelper::IEmbeddedHelper* pPersist = pObject ? 
pObject->getSdrModelFromSdrObject().GetPersist() : nullptr;
     if( pPersist && !pPersist->isEnableSetModified() )
     {
-        SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >( GetSdrObject() );
+        SdrOle2Obj* pOle = dynamic_cast< SdrOle2Obj* >(pObject);
         if( pOle && !pOle->IsEmpty() )
         {
             uno::Reference < util::XModifiable > xMod( pOle->GetObjRef(), 
uno::UNO_QUERY );
@@ -554,6 +555,11 @@ SvGlobalName SvxOle2Shape::GetClassName_Impl(OUString& 
rHexCLSID)
     return aClassName;
 }
 
+OUString SvxOle2Shape::GetAndClearInitialFrameURL()
+{
+    return OUString();
+}
+
 SvxAppletShape::SvxAppletShape(SdrObject* pObject)
     : SvxOle2Shape( pObject, getSvxMapProvider().GetMap(SVXMAP_APPLET), 
getSvxMapProvider().GetPropertySet(SVXMAP_APPLET, 
SdrObject::GetGlobalDrawObjectItemPool())  )
 {
@@ -707,8 +713,19 @@ SvxFrameShape::~SvxFrameShape() throw()
 {
 }
 
+OUString SvxFrameShape::GetAndClearInitialFrameURL()
+{
+    OUString sRet(m_sInitialFrameURL);
+    m_sInitialFrameURL.clear();
+    return sRet;
+}
+
 void SvxFrameShape::Create( SdrObject* pNewObj, SvxDrawPage* pNewPage )
 {
+    uno::Reference<beans::XPropertySet> xSet(static_cast<OWeakObject *>(this), 
uno::UNO_QUERY);
+    if (xSet)
+        xSet->getPropertyValue("FrameURL") >>= m_sInitialFrameURL;
+
     SvxShape::Create( pNewObj, pNewPage );
     const SvGlobalName aIFrameClassId( SO3_IFRAME_CLASSID );
     createObject(aIFrameClassId);
diff --git a/sw/inc/ndole.hxx b/sw/inc/ndole.hxx
index 852fffd84e3d..a2d974942097 100644
--- a/sw/inc/ndole.hxx
+++ b/sw/inc/ndole.hxx
@@ -28,7 +28,7 @@ class SwGrfFormatColl;
 class SwDoc;
 class SwOLENode;
 class SwOLEListener_Impl;
-class SwEmbedObjectLink;
+namespace sfx2 { class SvBaseLink; }
 class DeflateData;
 
 class SW_DLLPUBLIC SwOLEObj
@@ -90,7 +90,7 @@ class SW_DLLPUBLIC SwOLENode: public SwNoTextNode
     bool   mbOLESizeInvalid; /**< Should be considered at SwDoc::PrtOLENotify
                                    (e.g. copied). Is not persistent. */
 
-    SwEmbedObjectLink*  mpObjectLink;
+    sfx2::SvBaseLink*  mpObjectLink;
     OUString maLinkURL;
 
     SwOLENode(  const SwNodeIndex &rWhere,
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index cfade1209469..8ff9b35967ce 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -147,6 +147,8 @@ void SAL_CALL SwOLEListener_Impl::disposing( const 
lang::EventObject& )
 // TODO/LATER: actually SwEmbedObjectLink should be used here, but because 
different objects are used to control
 //             embedded object different link objects with the same 
functionality had to be implemented
 
+namespace {
+
 class SwEmbedObjectLink : public sfx2::SvBaseLink
 {
     SwOLENode*          pOleNode;
@@ -209,6 +211,44 @@ void SwEmbedObjectLink::Closed()
     SvBaseLink::Closed();
 }
 
+class SwIFrameLink : public sfx2::SvBaseLink
+{
+    SwOLENode* m_pOleNode;
+
+public:
+    explicit SwIFrameLink(SwOLENode* pNode)
+        : ::sfx2::SvBaseLink(::SfxLinkUpdateMode::ONCALL, 
SotClipboardFormatId::SVXB)
+        , m_pOleNode(pNode)
+    {
+        SetSynchron( false );
+    }
+
+    ::sfx2::SvBaseLink::UpdateResult DataChanged(
+        const OUString&, const uno::Any& )
+    {
+        uno::Reference<embed::XEmbeddedObject> xObject = 
m_pOleNode->GetOLEObj().GetOleRef();
+        uno::Reference<embed::XCommonEmbedPersist> xPersObj(xObject, 
uno::UNO_QUERY);
+        if (xPersObj.is())
+        {
+            // let the IFrameObject reload the link
+            try
+            {
+                xPersObj->reload(uno::Sequence<beans::PropertyValue>(), 
uno::Sequence<beans::PropertyValue>());
+            }
+            catch (const uno::Exception&)
+            {
+            }
+
+            m_pOleNode->SetChanged();
+        }
+
+        return SUCCESS;
+    }
+
+};
+
+}
+
 SwOLENode::SwOLENode( const SwNodeIndex &rWhere,
                     const svt::EmbeddedObjectRef& xObj,
                     SwGrfFormatColl *pGrfColl,
@@ -607,18 +647,49 @@ void SwOLENode::CheckFileLink_Impl()
 
     try
     {
-        uno::Reference< embed::XLinkageSupport > xLinkSupport( 
maOLEObj.m_xOLERef.GetObject(), uno::UNO_QUERY_THROW );
-        if ( xLinkSupport->isLink() )
+        uno::Reference<embed::XEmbeddedObject> xObject = 
maOLEObj.m_xOLERef.GetObject();
+        if (!xObject)
+            return;
+
+        bool bIFrame = false;
+
+        OUString aLinkURL;
+        uno::Reference<embed::XLinkageSupport> xLinkSupport(xObject, 
uno::UNO_QUERY);
+        if (xLinkSupport)
         {
-            const OUString aLinkURL = xLinkSupport->getLinkURL();
-            if ( !aLinkURL.isEmpty() )
+            if (xLinkSupport->isLink())
+                aLinkURL = xLinkSupport->getLinkURL();
+        }
+        else
+        {
+            // get IFrame (Floating Frames) listed and updatable from the
+            // manage links dialog
+            SvGlobalName aClassId(xObject->getClassID());
+            if (aClassId == SvGlobalName(SO3_IFRAME_CLASSID))
+            {
+                uno::Reference<beans::XPropertySet> 
xSet(xObject->getComponent(), uno::UNO_QUERY);
+                if (xSet.is())
+                    xSet->getPropertyValue("FrameURL") >>= aLinkURL;
+                bIFrame = true;
+            }
+        }
+
+        if (!aLinkURL.isEmpty()) // this is a file link so the model link 
manager should handle it
+        {
+            SwEmbedObjectLink* pEmbedObjectLink = nullptr;
+            if (!bIFrame)
+            {
+                pEmbedObjectLink = new SwEmbedObjectLink(this);
+                mpObjectLink = pEmbedObjectLink;
+            }
+            else
             {
-                // this is a file link so the model link manager should handle 
it
-                mpObjectLink = new SwEmbedObjectLink( this );
-                maLinkURL = aLinkURL;
-                
GetDoc()->getIDocumentLinksAdministration().GetLinkManager().InsertFileLink( 
*mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL );
-                mpObjectLink->Connect();
+                mpObjectLink = new SwIFrameLink(this);
             }
+            maLinkURL = aLinkURL;
+            
GetDoc()->getIDocumentLinksAdministration().GetLinkManager().InsertFileLink( 
*mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL );
+            if (pEmbedObjectLink)
+                pEmbedObjectLink->Connect();
         }
     }
     catch( uno::Exception& )
diff --git a/xmloff/source/draw/ximpshap.cxx b/xmloff/source/draw/ximpshap.cxx
index a7f2f2f76f1b..44b5177501f1 100644
--- a/xmloff/source/draw/ximpshap.cxx
+++ b/xmloff/source/draw/ximpshap.cxx
@@ -3223,9 +3223,35 @@ 
SdXMLFloatingFrameShapeContext::~SdXMLFloatingFrameShapeContext()
 {
 }
 
+uno::Reference<drawing::XShape> 
SdXMLFloatingFrameShapeContext::CreateFloatingFrameShape() const
+{
+    uno::Reference<lang::XMultiServiceFactory> 
xServiceFact(GetImport().GetModel(), uno::UNO_QUERY);
+    if (!xServiceFact.is())
+        return nullptr;
+    uno::Reference<drawing::XShape> xShape(
+            xServiceFact->createInstance("com.sun.star.drawing.FrameShape"), 
uno::UNO_QUERY);
+    return xShape;
+}
+
 void SdXMLFloatingFrameShapeContext::StartElement( const css::uno::Reference< 
css::xml::sax::XAttributeList >& )
 {
-    AddShape("com.sun.star.drawing.FrameShape");
+    uno::Reference<drawing::XShape> 
xShape(SdXMLFloatingFrameShapeContext::CreateFloatingFrameShape());
+
+    uno::Reference< beans::XPropertySet > xProps(xShape, uno::UNO_QUERY);
+    // set FrameURL before AddShape, we have to do it again later because it
+    // gets cleared when the SdrOle2Obj is attached to the XShape.  But we want
+    // FrameURL to exist when AddShape triggers SetPersistName which itself
+    // triggers SdrOle2Obj::CheckFileLink_Impl and at that point we want to
+    // know what URL will end up being used. So bodge this by setting FrameURL
+    // to the temp pre-SdrOle2Obj attached properties and we can smuggle it
+    // eventually into SdrOle2Obj::SetPersistName at the right point after
+    // PersistName is set but before SdrOle2Obj::CheckFileLink_Impl is called
+    // in order to inform the link manager that this is an IFrame that links to
+    // a URL
+    if (xProps && !maHref.isEmpty())
+        xProps->setPropertyValue("FrameURL", Any(maHref));
+
+    AddShape(xShape);
 
     if( mxShape.is() )
     {
@@ -3234,7 +3260,6 @@ void SdXMLFloatingFrameShapeContext::StartElement( const 
css::uno::Reference< cs
         // set pos, size, shear and rotate
         SetTransformation();
 
-        uno::Reference< beans::XPropertySet > xProps( mxShape, uno::UNO_QUERY 
);
         if( xProps.is() )
         {
             if( !maFrameName.isEmpty() )
diff --git a/xmloff/source/draw/ximpshap.hxx b/xmloff/source/draw/ximpshap.hxx
index fae45f88f00a..a00c87e8a0da 100644
--- a/xmloff/source/draw/ximpshap.hxx
+++ b/xmloff/source/draw/ximpshap.hxx
@@ -513,6 +513,8 @@ private:
     OUString maFrameName;
     OUString maHref;
 
+    css::uno::Reference<css::drawing::XShape> CreateFloatingFrameShape() const;
+
 public:
 
     SdXMLFloatingFrameShapeContext( SvXMLImport& rImport, sal_uInt16 nPrfx,
commit c489dff8e376692fa1d079b92be4c12aae32f8dc
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Jul 30 10:35:44 2020 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue May 2 16:07:32 2023 +0200

    loplugin:flatten in sw/core/ole..sw/core/table 
[sw/source/core/ole/ndole.cxx]
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99886
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    (cherry picked from commit c9edb99bdc74715e7d952b2b95a4d75a73300207)
    
    Change-Id: If74f1cfca114d52566164656c34a0764cfbaad43

diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index 9000d6ef1b9e..cfade1209469 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -572,22 +572,22 @@ void SwOLENode::BreakFileLink_Impl()
 {
     SfxObjectShell* pPers = GetDoc()->GetPersist();
 
-    if ( pPers )
+    if ( !pPers )
+        return;
+
+    uno::Reference< embed::XStorage > xStorage = pPers->GetStorage();
+    if ( !xStorage.is() )
+        return;
+
+    try
+    {
+        uno::Reference< embed::XLinkageSupport > xLinkSupport( 
maOLEObj.GetOleRef(), uno::UNO_QUERY_THROW );
+        xLinkSupport->breakLink( xStorage, maOLEObj.GetCurrentPersistName() );
+        DisconnectFileLink_Impl();
+        maLinkURL.clear();
+    }
+    catch( uno::Exception& )
     {
-        uno::Reference< embed::XStorage > xStorage = pPers->GetStorage();
-        if ( xStorage.is() )
-        {
-            try
-            {
-                uno::Reference< embed::XLinkageSupport > xLinkSupport( 
maOLEObj.GetOleRef(), uno::UNO_QUERY_THROW );
-                xLinkSupport->breakLink( xStorage, 
maOLEObj.GetCurrentPersistName() );
-                DisconnectFileLink_Impl();
-                maLinkURL.clear();
-            }
-            catch( uno::Exception& )
-            {
-            }
-        }
     }
 }
 
@@ -602,27 +602,27 @@ void SwOLENode::DisconnectFileLink_Impl()
 
 void SwOLENode::CheckFileLink_Impl()
 {
-    if ( maOLEObj.m_xOLERef.GetObject().is() && !mpObjectLink )
+    if ( !(maOLEObj.m_xOLERef.GetObject().is() && !mpObjectLink) )
+        return;
+
+    try
     {
-        try
+        uno::Reference< embed::XLinkageSupport > xLinkSupport( 
maOLEObj.m_xOLERef.GetObject(), uno::UNO_QUERY_THROW );
+        if ( xLinkSupport->isLink() )
         {
-            uno::Reference< embed::XLinkageSupport > xLinkSupport( 
maOLEObj.m_xOLERef.GetObject(), uno::UNO_QUERY_THROW );
-            if ( xLinkSupport->isLink() )
+            const OUString aLinkURL = xLinkSupport->getLinkURL();
+            if ( !aLinkURL.isEmpty() )
             {
-                const OUString aLinkURL = xLinkSupport->getLinkURL();
-                if ( !aLinkURL.isEmpty() )
-                {
-                    // this is a file link so the model link manager should 
handle it
-                    mpObjectLink = new SwEmbedObjectLink( this );
-                    maLinkURL = aLinkURL;
-                    
GetDoc()->getIDocumentLinksAdministration().GetLinkManager().InsertFileLink( 
*mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL );
-                    mpObjectLink->Connect();
-                }
+                // this is a file link so the model link manager should handle 
it
+                mpObjectLink = new SwEmbedObjectLink( this );
+                maLinkURL = aLinkURL;
+                
GetDoc()->getIDocumentLinksAdministration().GetLinkManager().InsertFileLink( 
*mpObjectLink, OBJECT_CLIENT_OLE, aLinkURL );
+                mpObjectLink->Connect();
             }
         }
-        catch( uno::Exception& )
-        {
-        }
+    }
+    catch( uno::Exception& )
+    {
     }
 }
 
@@ -862,39 +862,39 @@ SwOLEObj::~SwOLEObj() COVERITY_NOEXCEPT_FALSE
 void SwOLEObj::SetNode( SwOLENode* pNode )
 {
     m_pOLENode = pNode;
-    if ( m_aName.isEmpty() )
-    {
-        SwDoc* pDoc = pNode->GetDoc();
-
-        // If there's already a SvPersist instance, we use it
-        SfxObjectShell* p = pDoc->GetPersist();
-        if( !p )
-        {
-            // TODO/LATER: Isn't an EmbeddedObjectContainer sufficient here?
-            // What happens to the document?
-            OSL_ENSURE( false, "Why are we creating a DocShell here??" );
-            p = new SwDocShell( pDoc, SfxObjectCreateMode::INTERNAL );
-            p->DoInitNew();
-        }
+    if ( !m_aName.isEmpty() )
+        return;
 
-        OUString aObjName;
-        uno::Reference < container::XChild > xChild( m_xOLERef.GetObject(), 
uno::UNO_QUERY );
-        if ( xChild.is() && xChild->getParent() != p->GetModel() )
-            // it is possible that the parent was set already
-            xChild->setParent( p->GetModel() );
-        if (!p->GetEmbeddedObjectContainer().InsertEmbeddedObject( 
m_xOLERef.GetObject(), aObjName ) )
-        {
-            OSL_FAIL( "InsertObject failed" );
-            if ( xChild.is() )
-                xChild->setParent( nullptr );
-        }
-        else
-            m_xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), 
aObjName );
+    SwDoc* pDoc = pNode->GetDoc();
 
-        const_cast<SwOLENode*>(m_pOLENode)->CheckFileLink_Impl(); // for this 
notification nonconst access is required
+    // If there's already a SvPersist instance, we use it
+    SfxObjectShell* p = pDoc->GetPersist();
+    if( !p )
+    {
+        // TODO/LATER: Isn't an EmbeddedObjectContainer sufficient here?
+        // What happens to the document?
+        OSL_ENSURE( false, "Why are we creating a DocShell here??" );
+        p = new SwDocShell( pDoc, SfxObjectCreateMode::INTERNAL );
+        p->DoInitNew();
+    }
 
-        m_aName = aObjName;
+    OUString aObjName;
+    uno::Reference < container::XChild > xChild( m_xOLERef.GetObject(), 
uno::UNO_QUERY );
+    if ( xChild.is() && xChild->getParent() != p->GetModel() )
+        // it is possible that the parent was set already
+        xChild->setParent( p->GetModel() );
+    if (!p->GetEmbeddedObjectContainer().InsertEmbeddedObject( 
m_xOLERef.GetObject(), aObjName ) )
+    {
+        OSL_FAIL( "InsertObject failed" );
+        if ( xChild.is() )
+            xChild->setParent( nullptr );
     }
+    else
+        m_xOLERef.AssignToContainer( &p->GetEmbeddedObjectContainer(), 
aObjName );
+
+    const_cast<SwOLENode*>(m_pOLENode)->CheckFileLink_Impl(); // for this 
notification nonconst access is required
+
+    m_aName = aObjName;
 }
 
 OUString SwOLEObj::GetStyleString()
@@ -1167,7 +1167,7 @@ void SwOLELRUCache::Load()
 
     if (nVal < m_nLRU_InitSize)
     {
-        std::shared_ptr<SwOLELRUCache> tmp(g_pOLELRU_Cache); // prevent delete 
this
+        std::shared_ptr<SwOLELRUCache> xKeepAlive(g_pOLELRU_Cache); // prevent 
delete this
         // size of cache has been changed
         sal_Int32 nCount = m_OleObjects.size();
         sal_Int32 nPos = nCount;
@@ -1197,20 +1197,20 @@ void SwOLELRUCache::InsertObj( SwOLEObj& rObj )
         m_OleObjects.erase(it);
         it = m_OleObjects.end();
     }
-    if (it == m_OleObjects.end())
+    if (it != m_OleObjects.end())
+        return;
+
+    std::shared_ptr<SwOLELRUCache> xKeepAlive(g_pOLELRU_Cache); // prevent 
delete this
+    // try to remove objects if necessary
+    sal_Int32 nCount = m_OleObjects.size();
+    sal_Int32 nPos = nCount-1;
+    while (nPos >= 0 && nCount >= m_nLRU_InitSize)
     {
-        std::shared_ptr<SwOLELRUCache> tmp(g_pOLELRU_Cache); // prevent delete 
this
-        // try to remove objects if necessary
-        sal_Int32 nCount = m_OleObjects.size();
-        sal_Int32 nPos = nCount-1;
-        while (nPos >= 0 && nCount >= m_nLRU_InitSize)
-        {
-            pObj = m_OleObjects[ nPos-- ];
-            if ( pObj->UnloadObject() )
-                nCount--;
-        }
-        m_OleObjects.push_front(&rObj);
+        pObj = m_OleObjects[ nPos-- ];
+        if ( pObj->UnloadObject() )
+            nCount--;
     }
+    m_OleObjects.push_front(&rObj);
 }
 
 void SwOLELRUCache::RemoveObj( SwOLEObj& rObj )
commit 41c6389a177b651d46459c1837a401e4e0425dc6
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Aug 6 12:47:09 2020 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue May 2 15:44:35 2023 +0200

    loplugin:flatten in svx/svdraw [svx/source/svdraw/svdoole2.cxx]
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100233
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    (cherry picked from commit bfc298d02ca6275588d5897d97ced9498a3e91aa)
    
    Change-Id: I8379e5ebaee2090d2b4dbd05d55b55000915cd7c

diff --git a/svx/source/svdraw/svdoole2.cxx b/svx/source/svdraw/svdoole2.cxx
index 16617ecaf94f..8b4faca5f1d3 100644
--- a/svx/source/svdraw/svdoole2.cxx
+++ b/svx/source/svdraw/svdoole2.cxx
@@ -232,61 +232,61 @@ void SAL_CALL SdrLightEmbeddedClient_Impl::notifyEvent( 
const document::EventObj
     SolarMutexGuard aGuard;
 
     // the code currently makes sense only in case there is no other client
-    if ( mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && 
aEvent.EventName == "OnVisAreaChanged"
-      && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == 
uno::Reference< embed::XEmbeddedClient >( this ) )
-    {
-        try
-        {
-            MapUnit aContainerMapUnit( MapUnit::Map100thMM );
-            uno::Reference< embed::XVisualObject > xParentVis( 
mpObj->GetParentXModel(), uno::UNO_QUERY );
-            if ( xParentVis.is() )
-                aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( 
xParentVis->getMapUnit( mpObj->GetAspect() ) );
+    if ( !(mpObj && mpObj->GetAspect() != embed::Aspects::MSOLE_ICON && 
aEvent.EventName == "OnVisAreaChanged"
+      && mpObj->GetObjRef().is() && mpObj->GetObjRef()->getClientSite() == 
uno::Reference< embed::XEmbeddedClient >( this )) )
+        return;
 
-            MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( 
mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
+    try
+    {
+        MapUnit aContainerMapUnit( MapUnit::Map100thMM );
+        uno::Reference< embed::XVisualObject > xParentVis( 
mpObj->GetParentXModel(), uno::UNO_QUERY );
+        if ( xParentVis.is() )
+            aContainerMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( 
xParentVis->getMapUnit( mpObj->GetAspect() ) );
 
-            tools::Rectangle          aVisArea;
-            awt::Size aSz;
-            try
-            {
-                aSz = mpObj->GetObjRef()->getVisualAreaSize( 
mpObj->GetAspect() );
-            }
-            catch( embed::NoVisualAreaSizeException& )
-            {
-                OSL_FAIL( "No visual area size!" );
-                aSz.Width = 5000;
-                aSz.Height = 5000;
-            }
-            catch( uno::Exception& )
-            {
-                OSL_FAIL( "Unexpected exception!" );
-                aSz.Width = 5000;
-                aSz.Height = 5000;
-            }
+        MapUnit aObjMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( 
mpObj->GetObjRef()->getMapUnit( mpObj->GetAspect() ) );
 
-            aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
-            aVisArea = OutputDevice::LogicToLogic(aVisArea, 
MapMode(aObjMapUnit), MapMode(aContainerMapUnit));
-            Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( 
aVisArea.GetWidth() ) ),
-                                static_cast< long >( m_aScaleHeight * 
Fraction( aVisArea.GetHeight() ) ) );
-            tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
-
-            // react to the change if the difference is bigger than one pixel
-            Size aPixelDiff =
-                Application::GetDefaultDevice()->LogicToPixel(
-                    Size( aLogicRect.GetWidth() - aScaledSize.Width(),
-                          aLogicRect.GetHeight() - aScaledSize.Height() ),
-                    MapMode(aContainerMapUnit));
-            if( aPixelDiff.Width() || aPixelDiff.Height() )
-            {
-                mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), 
aScaledSize ) );
-                mpObj->BroadcastObjectChange();
-            }
-            else
-                mpObj->ActionChanged();
+        tools::Rectangle          aVisArea;
+        awt::Size aSz;
+        try
+        {
+            aSz = mpObj->GetObjRef()->getVisualAreaSize( mpObj->GetAspect() );
+        }
+        catch( embed::NoVisualAreaSizeException& )
+        {
+            OSL_FAIL( "No visual area size!" );
+            aSz.Width = 5000;
+            aSz.Height = 5000;
         }
         catch( uno::Exception& )
         {
             OSL_FAIL( "Unexpected exception!" );
+            aSz.Width = 5000;
+            aSz.Height = 5000;
+        }
+
+        aVisArea.SetSize( Size( aSz.Width, aSz.Height ) );
+        aVisArea = OutputDevice::LogicToLogic(aVisArea, MapMode(aObjMapUnit), 
MapMode(aContainerMapUnit));
+        Size aScaledSize( static_cast< long >( m_aScaleWidth * Fraction( 
aVisArea.GetWidth() ) ),
+                            static_cast< long >( m_aScaleHeight * Fraction( 
aVisArea.GetHeight() ) ) );
+        tools::Rectangle aLogicRect( mpObj->GetLogicRect() );
+
+        // react to the change if the difference is bigger than one pixel
+        Size aPixelDiff =
+            Application::GetDefaultDevice()->LogicToPixel(
+                Size( aLogicRect.GetWidth() - aScaledSize.Width(),
+                      aLogicRect.GetHeight() - aScaledSize.Height() ),
+                MapMode(aContainerMapUnit));
+        if( aPixelDiff.Width() || aPixelDiff.Height() )
+        {
+            mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), 
aScaledSize ) );
+            mpObj->BroadcastObjectChange();
         }
+        else
+            mpObj->ActionChanged();
+    }
+    catch( uno::Exception& )
+    {
+        OSL_FAIL( "Unexpected exception!" );
     }
 }
 
@@ -499,32 +499,32 @@ void SAL_CALL 
SdrLightEmbeddedClient_Impl::changedPlacement( const awt::Rectangl
     tools::Rectangle aNewLogicRect = 
Application::GetDefaultDevice()->PixelToLogic(aNewPixelRect, 
MapMode(aContainerMapUnit));
     tools::Rectangle aLogicRect = impl_getScaledRect_nothrow();
 
-    if ( aNewLogicRect != aLogicRect )
-    {
-        // the calculation of the object area has not changed the object size
-        // it should be done here then
-        //SfxBooleanFlagGuard aGuard( m_bResizeNoScale, true );
-
-        // new size of the object area without scaling
-        Size aNewObjSize( long( aNewLogicRect.GetWidth() / m_aScaleWidth ),
-                          long( aNewLogicRect.GetHeight() / m_aScaleHeight ) );
+    if ( aNewLogicRect == aLogicRect )
+        return;
 
-        // now remove scaling from new placement and keep this at the new 
object area
-        aNewLogicRect.SetSize( aNewObjSize );
-        // react to the change if the difference is bigger than one pixel
-        Size aPixelDiff =
-            Application::GetDefaultDevice()->LogicToPixel(
-                Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
-                      aLogicRect.GetHeight() - aNewObjSize.Height() ),
-                MapMode(aContainerMapUnit));
-        if( aPixelDiff.Width() || aPixelDiff.Height() )
-        {
-            mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), 
aNewObjSize ) );
-            mpObj->BroadcastObjectChange();
-        }
-        else
-            mpObj->ActionChanged();
+    // the calculation of the object area has not changed the object size
+    // it should be done here then
+    //SfxBooleanFlagGuard aGuard( m_bResizeNoScale, true );
+
+    // new size of the object area without scaling
+    Size aNewObjSize( long( aNewLogicRect.GetWidth() / m_aScaleWidth ),
+                      long( aNewLogicRect.GetHeight() / m_aScaleHeight ) );
+
+    // now remove scaling from new placement and keep this at the new object 
area
+    aNewLogicRect.SetSize( aNewObjSize );
+    // react to the change if the difference is bigger than one pixel
+    Size aPixelDiff =
+        Application::GetDefaultDevice()->LogicToPixel(
+            Size( aLogicRect.GetWidth() - aNewObjSize.Width(),
+                  aLogicRect.GetHeight() - aNewObjSize.Height() ),
+            MapMode(aContainerMapUnit));
+    if( aPixelDiff.Width() || aPixelDiff.Height() )
+    {
+        mpObj->SetLogicRect( tools::Rectangle( aLogicRect.TopLeft(), 
aNewObjSize ) );
+        mpObj->BroadcastObjectChange();
     }
+    else
+        mpObj->ActionChanged();
 }
 // XWindowSupplier
 
@@ -890,23 +890,23 @@ void SdrOle2Obj::BreakFileLink_Impl()
 {
     uno::Reference<document::XStorageBasedDocument> 
xDoc(getSdrModelFromSdrObject().getUnoModel(), uno::UNO_QUERY);
 
-    if ( xDoc.is() )
+    if ( !xDoc.is() )
+        return;
+
+    uno::Reference< embed::XStorage > xStorage = xDoc->getDocumentStorage();
+    if ( !xStorage.is() )
+        return;
+
+    try
     {
-        uno::Reference< embed::XStorage > xStorage = 
xDoc->getDocumentStorage();
-        if ( xStorage.is() )
-        {
-            try
-            {
-                uno::Reference< embed::XLinkageSupport > xLinkSupport( 
mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY_THROW );
-                xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
-                DisconnectFileLink_Impl();
-                mpImpl->maLinkURL.clear();
-            }
-            catch( css::uno::Exception& )
-            {
-                TOOLS_WARN_EXCEPTION( "svx", 
"SdrOle2Obj::BreakFileLink_Impl()" );
-            }
-        }
+        uno::Reference< embed::XLinkageSupport > xLinkSupport( 
mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY_THROW );
+        xLinkSupport->breakLink( xStorage, mpImpl->aPersistName );
+        DisconnectFileLink_Impl();
+        mpImpl->maLinkURL.clear();
+    }
+    catch( css::uno::Exception& )
+    {
+        TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::BreakFileLink_Impl()" );
     }
 }
 
@@ -923,105 +923,105 @@ void SdrOle2Obj::DisconnectFileLink_Impl()
 
 void SdrOle2Obj::CheckFileLink_Impl()
 {
-    if (mpImpl->mxObjRef.GetObject().is() && !mpImpl->mpObjectLink)
+    if (!(mpImpl->mxObjRef.GetObject().is() && !mpImpl->mpObjectLink))
+        return;
+
+    try
     {
-        try
+        uno::Reference< embed::XLinkageSupport > xLinkSupport( 
mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
+
+        if ( xLinkSupport.is() && xLinkSupport->isLink() )
         {
-            uno::Reference< embed::XLinkageSupport > xLinkSupport( 
mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
+            OUString aLinkURL = xLinkSupport->getLinkURL();
 
-            if ( xLinkSupport.is() && xLinkSupport->isLink() )
+            if ( !aLinkURL.isEmpty() )
             {
-                OUString aLinkURL = xLinkSupport->getLinkURL();
+                // this is a file link so the model link manager should handle 
it
+                sfx2::LinkManager* 
pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
 
-                if ( !aLinkURL.isEmpty() )
+                if ( pLinkManager )
                 {
-                    // this is a file link so the model link manager should 
handle it
-                    sfx2::LinkManager* 
pLinkManager(getSdrModelFromSdrObject().GetLinkManager());
-
-                    if ( pLinkManager )
-                    {
-                        mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
-                        mpImpl->maLinkURL = aLinkURL;
-                        pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, 
OBJECT_CLIENT_OLE, aLinkURL );
-                        mpImpl->mpObjectLink->Connect();
-                    }
+                    mpImpl->mpObjectLink = new SdrEmbedObjectLink( this );
+                    mpImpl->maLinkURL = aLinkURL;
+                    pLinkManager->InsertFileLink( *mpImpl->mpObjectLink, 
OBJECT_CLIENT_OLE, aLinkURL );
+                    mpImpl->mpObjectLink->Connect();
                 }
             }
         }
-        catch (const css::uno::Exception&)
-        {
-            TOOLS_WARN_EXCEPTION("svx", "SdrOle2Obj::CheckFileLink_Impl()");
-        }
+    }
+    catch (const css::uno::Exception&)
+    {
+        TOOLS_WARN_EXCEPTION("svx", "SdrOle2Obj::CheckFileLink_Impl()");
     }
 }
 
 void SdrOle2Obj::Connect_Impl()
 {
-    if(!mpImpl->aPersistName.isEmpty() )
+    if(mpImpl->aPersistName.isEmpty() )
+        return;
+
+    try
     {
-        try
+        ::comphelper::IEmbeddedHelper* 
pPers(getSdrModelFromSdrObject().GetPersist());
+
+        if ( pPers )
         {
-            ::comphelper::IEmbeddedHelper* 
pPers(getSdrModelFromSdrObject().GetPersist());
+            comphelper::EmbeddedObjectContainer& rContainer = 
pPers->getEmbeddedObjectContainer();
 
-            if ( pPers )
+            if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
+              || ( mpImpl->mxObjRef.is() && !rContainer.HasEmbeddedObject( 
mpImpl->mxObjRef.GetObject() ) ) )
             {
-                comphelper::EmbeddedObjectContainer& rContainer = 
pPers->getEmbeddedObjectContainer();
-
-                if ( !rContainer.HasEmbeddedObject( mpImpl->aPersistName )
-                  || ( mpImpl->mxObjRef.is() && !rContainer.HasEmbeddedObject( 
mpImpl->mxObjRef.GetObject() ) ) )
-                {
-                    // object not known to container document
-                    // No object -> disaster!
-                    DBG_ASSERT( mpImpl->mxObjRef.is(), "No object in 
connect!");
-                    if ( mpImpl->mxObjRef.is() )
-                    {
-                        // object came from the outside, now add it to the 
container
-                        OUString aTmp;
-                        rContainer.InsertEmbeddedObject( 
mpImpl->mxObjRef.GetObject(), aTmp );
-                        mpImpl->aPersistName = aTmp;
-                    }
-                }
-                else if ( !mpImpl->mxObjRef.is() )
+                // object not known to container document
+                // No object -> disaster!
+                DBG_ASSERT( mpImpl->mxObjRef.is(), "No object in connect!");
+                if ( mpImpl->mxObjRef.is() )
                 {
-                    mpImpl->mxObjRef.Assign( rContainer.GetEmbeddedObject( 
mpImpl->aPersistName ), mpImpl->mxObjRef.GetViewAspect() );
-                    mpImpl->mbTypeAsked = false;
-                }
-
-                if ( mpImpl->mxObjRef.GetObject().is() )
-                {
-                    mpImpl->mxObjRef.AssignToContainer( &rContainer, 
mpImpl->aPersistName );
-                    mpImpl->mbConnected = true;
-                    mpImpl->mxObjRef.Lock();
+                    // object came from the outside, now add it to the 
container
+                    OUString aTmp;
+                    rContainer.InsertEmbeddedObject( 
mpImpl->mxObjRef.GetObject(), aTmp );
+                    mpImpl->aPersistName = aTmp;
                 }
             }
+            else if ( !mpImpl->mxObjRef.is() )
+            {
+                mpImpl->mxObjRef.Assign( rContainer.GetEmbeddedObject( 
mpImpl->aPersistName ), mpImpl->mxObjRef.GetViewAspect() );
+                mpImpl->mbTypeAsked = false;
+            }
 
-            if ( mpImpl->mxObjRef.is() )
+            if ( mpImpl->mxObjRef.GetObject().is() )
             {
-                if ( !mpImpl->mxLightClient.is() )
-                    mpImpl->mxLightClient = new SdrLightEmbeddedClient_Impl( 
this );
+                mpImpl->mxObjRef.AssignToContainer( &rContainer, 
mpImpl->aPersistName );
+                mpImpl->mbConnected = true;
+                mpImpl->mxObjRef.Lock();
+            }
+        }
 
-                mpImpl->mxObjRef->addStateChangeListener( 
mpImpl->mxLightClient.get() );
-                mpImpl->mxObjRef->addEventListener( uno::Reference< 
document::XEventListener >( mpImpl->mxLightClient.get() ) );
+        if ( mpImpl->mxObjRef.is() )
+        {
+            if ( !mpImpl->mxLightClient.is() )
+                mpImpl->mxLightClient = new SdrLightEmbeddedClient_Impl( this 
);
 
-                if ( mpImpl->mxObjRef->getCurrentState() != 
embed::EmbedStates::LOADED )
-                    GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
+            mpImpl->mxObjRef->addStateChangeListener( 
mpImpl->mxLightClient.get() );
+            mpImpl->mxObjRef->addEventListener( uno::Reference< 
document::XEventListener >( mpImpl->mxLightClient.get() ) );
 
-                CheckFileLink_Impl();
+            if ( mpImpl->mxObjRef->getCurrentState() != 
embed::EmbedStates::LOADED )
+                GetSdrGlobalData().GetOLEObjCache().InsertObj(this);
 
-                uno::Reference< container::XChild > xChild( 
mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
-                if( xChild.is() )
-                {
-                    uno::Reference< uno::XInterface > xParent( 
getSdrModelFromSdrObject().getUnoModel());
-                    if( xParent.is())
-                        xChild->setParent( 
getSdrModelFromSdrObject().getUnoModel() );
-                }
+            CheckFileLink_Impl();
 
+            uno::Reference< container::XChild > xChild( 
mpImpl->mxObjRef.GetObject(), uno::UNO_QUERY );
+            if( xChild.is() )
+            {
+                uno::Reference< uno::XInterface > xParent( 
getSdrModelFromSdrObject().getUnoModel());
+                if( xParent.is())
+                    xChild->setParent( 
getSdrModelFromSdrObject().getUnoModel() );
             }
+
         }
-        catch( css::uno::Exception& )
-        {
-            TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::Connect_Impl()" );
-        }
+    }
+    catch( css::uno::Exception& )
+    {
+        TOOLS_WARN_EXCEPTION( "svx", "SdrOle2Obj::Connect_Impl()" );
     }
 }
 
@@ -1032,20 +1032,20 @@ void SdrOle2Obj::ObjectLoaded()
 
 void SdrOle2Obj::AddListeners_Impl()
 {
-    if( mpImpl->mxObjRef.is() && mpImpl->mxObjRef->getCurrentState() != 
embed::EmbedStates::LOADED )
+    if( !(mpImpl->mxObjRef.is() && mpImpl->mxObjRef->getCurrentState() != 
embed::EmbedStates::LOADED) )
+        return;
+
+    // register modify listener
+    if (!mpImpl->mxModifyListener.is())
     {
-        // register modify listener
-        if (!mpImpl->mxModifyListener.is())
-        {
-            mpImpl->mxModifyListener = new SvxUnoShapeModifyListener(this);
-        }
+        mpImpl->mxModifyListener = new SvxUnoShapeModifyListener(this);
+    }
 
-        uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), 
uno::UNO_QUERY );
-        if (xBC.is())
-        {
-            uno::Reference<util::XModifyListener> 
xListener(mpImpl->mxModifyListener.get());
-            xBC->addModifyListener( xListener );
-        }
+    uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), 
uno::UNO_QUERY );
+    if (xBC.is())
+    {
+        uno::Reference<util::XModifyListener> 
xListener(mpImpl->mxModifyListener.get());
+        xBC->addModifyListener( xListener );
     }
 }
 
@@ -1066,25 +1066,25 @@ void SdrOle2Obj::Disconnect()
 
 void SdrOle2Obj::RemoveListeners_Impl()
 {
-    if ( mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty() )
+    if ( !(mpImpl->mxObjRef.is() && !mpImpl->aPersistName.isEmpty()) )
+        return;
+
+    try
     {
-        try
+        sal_Int32 nState = mpImpl->mxObjRef->getCurrentState();
+        if ( nState != embed::EmbedStates::LOADED )
         {
-            sal_Int32 nState = mpImpl->mxObjRef->getCurrentState();
-            if ( nState != embed::EmbedStates::LOADED )
+            uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), 
uno::UNO_QUERY );
+            if (xBC.is() && mpImpl->mxModifyListener.is())
             {
-                uno::Reference< util::XModifyBroadcaster > xBC( getXModel(), 
uno::UNO_QUERY );
-                if (xBC.is() && mpImpl->mxModifyListener.is())
-                {
-                    uno::Reference<util::XModifyListener> 
xListener(mpImpl->mxModifyListener.get());
-                    xBC->removeModifyListener( xListener );
-                }
+                uno::Reference<util::XModifyListener> 
xListener(mpImpl->mxModifyListener.get());
+                xBC->removeModifyListener( xListener );
             }
         }
-        catch( css::uno::Exception& )
-        {
-            TOOLS_WARN_EXCEPTION( "svx",  "SdrOle2Obj::RemoveListeners_Impl()" 
);
-        }
+    }
+    catch( css::uno::Exception& )
+    {
+        TOOLS_WARN_EXCEPTION( "svx",  "SdrOle2Obj::RemoveListeners_Impl()" );
     }
 }
 
@@ -1453,149 +1453,149 @@ void SdrOle2Obj::ImpSetVisAreaSize()
 
     // the object area of an embedded object was changed, e.g. by user 
interaction an a selected object
     GetObjRef();
-    if (mpImpl->mxObjRef.is())
+    if (!mpImpl->mxObjRef.is())
+        return;
+
+    sal_Int64 nMiscStatus = mpImpl->mxObjRef->getStatus( GetAspect() );
+
+    // the client is required to get access to scaling
+    SfxInPlaceClient* pClient(
+        SfxInPlaceClient::GetClient(
+            dynamic_cast<SfxObjectShell*>(
+                getSdrModelFromSdrObject().GetPersist()),
+                mpImpl->mxObjRef.GetObject()));
+    const bool bHasOwnClient(
+        mpImpl->mxLightClient.is() &&
+        mpImpl->mxObjRef->getClientSite() == uno::Reference< 
embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) );
+
+    if ( pClient || bHasOwnClient )
     {
-        sal_Int64 nMiscStatus = mpImpl->mxObjRef->getStatus( GetAspect() );
-
-        // the client is required to get access to scaling
-        SfxInPlaceClient* pClient(
-            SfxInPlaceClient::GetClient(
-                dynamic_cast<SfxObjectShell*>(
-                    getSdrModelFromSdrObject().GetPersist()),
-                    mpImpl->mxObjRef.GetObject()));
-        const bool bHasOwnClient(
-            mpImpl->mxLightClient.is() &&
-            mpImpl->mxObjRef->getClientSite() == uno::Reference< 
embed::XEmbeddedClient >( mpImpl->mxLightClient.get() ) );
-
-        if ( pClient || bHasOwnClient )
+        // TODO: IMHO we need to do similar things when object is UIActive or 
OutplaceActive?!
+        if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
+                svt::EmbeddedObjectRef::TryRunningState( 
mpImpl->mxObjRef.GetObject() ))
+                || mpImpl->mxObjRef->getCurrentState() == 
embed::EmbedStates::INPLACE_ACTIVE
+                )
         {
-            // TODO: IMHO we need to do similar things when object is UIActive 
or OutplaceActive?!
-            if ( ((nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) 
&&
-                    svt::EmbeddedObjectRef::TryRunningState( 
mpImpl->mxObjRef.GetObject() ))
-                    || mpImpl->mxObjRef->getCurrentState() == 
embed::EmbedStates::INPLACE_ACTIVE
-                    )
+            Fraction aScaleWidth;
+            Fraction aScaleHeight;
+            if ( pClient )
             {
-                Fraction aScaleWidth;
-                Fraction aScaleHeight;
-                if ( pClient )
-                {
-                    aScaleWidth = pClient->GetScaleWidth();
-                    aScaleHeight = pClient->GetScaleHeight();
-                }
-                else
-                {
-                    aScaleWidth = mpImpl->mxLightClient->GetScaleWidth();
-                    aScaleHeight = mpImpl->mxLightClient->GetScaleHeight();
-                }
+                aScaleWidth = pClient->GetScaleWidth();
+                aScaleHeight = pClient->GetScaleHeight();
+            }
+            else
+            {
+                aScaleWidth = mpImpl->mxLightClient->GetScaleWidth();
+                aScaleHeight = mpImpl->mxLightClient->GetScaleHeight();
+            }
 
-                // The object wants to resize itself (f.e. Chart wants to 
recalculate the layout)
-                // or object is inplace active and so has a window that must 
be resized also
-                // In these cases the change in the object area size will be 
reflected in a change of the
-                // objects' visual area. The scaling will not change, but it 
might exist already and must
-                // be used in calculations
-                MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( 
mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
-                Size aVisSize( static_cast<long>( Fraction( maRect.GetWidth() 
) / aScaleWidth ),
-                                static_cast<long>( Fraction( 
maRect.GetHeight() ) / aScaleHeight ) );
-
-                aVisSize = OutputDevice::LogicToLogic(
-                    aVisSize,
-                    MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
-                    MapMode(aMapUnit));
-                awt::Size aSz;
-                aSz.Width = aVisSize.Width();
-                aSz.Height = aVisSize.Height();
-                mpImpl->mxObjRef->setVisualAreaSize( GetAspect(), aSz );
+            // The object wants to resize itself (f.e. Chart wants to 
recalculate the layout)
+            // or object is inplace active and so has a window that must be 
resized also
+            // In these cases the change in the object area size will be 
reflected in a change of the
+            // objects' visual area. The scaling will not change, but it might 
exist already and must
+            // be used in calculations
+            MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( 
mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
+            Size aVisSize( static_cast<long>( Fraction( maRect.GetWidth() ) / 
aScaleWidth ),
+                            static_cast<long>( Fraction( maRect.GetHeight() ) 
/ aScaleHeight ) );
+
+            aVisSize = OutputDevice::LogicToLogic(
+                aVisSize,
+                MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
+                MapMode(aMapUnit));
+            awt::Size aSz;
+            aSz.Width = aVisSize.Width();
+            aSz.Height = aVisSize.Height();
+            mpImpl->mxObjRef->setVisualAreaSize( GetAspect(), aSz );
 
-                try
-                {
-                    aSz = mpImpl->mxObjRef->getVisualAreaSize( GetAspect() );
-                }
-                catch( embed::NoVisualAreaSizeException& )
-                {}
+            try
+            {
+                aSz = mpImpl->mxObjRef->getVisualAreaSize( GetAspect() );
+            }
+            catch( embed::NoVisualAreaSizeException& )
+            {}
 
-                tools::Rectangle aAcceptedVisArea;
-                aAcceptedVisArea.SetSize( Size( static_cast<long>( Fraction( 
long( aSz.Width ) ) * aScaleWidth ),
-                                                static_cast<long>( Fraction( 
long( aSz.Height ) ) * aScaleHeight ) ) );
-                if (aVisSize != aAcceptedVisArea.GetSize())
-                {
-                    // server changed VisArea to its liking and the VisArea is 
different than the suggested one
-                    // store the new value as given by the object
-                    MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( 
mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
-                    maRect.SetSize(
-                        OutputDevice::LogicToLogic(
-                            aAcceptedVisArea.GetSize(),
-                            MapMode(aNewMapUnit),
-                            
MapMode(getSdrModelFromSdrObject().GetScaleUnit())));
-                }
+            tools::Rectangle aAcceptedVisArea;
+            aAcceptedVisArea.SetSize( Size( static_cast<long>( Fraction( long( 
aSz.Width ) ) * aScaleWidth ),
+                                            static_cast<long>( Fraction( long( 
aSz.Height ) ) * aScaleHeight ) ) );
+            if (aVisSize != aAcceptedVisArea.GetSize())
+            {
+                // server changed VisArea to its liking and the VisArea is 
different than the suggested one
+                // store the new value as given by the object
+                MapUnit aNewMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( 
mpImpl->mxObjRef->getMapUnit( GetAspect() ) );
+                maRect.SetSize(
+                    OutputDevice::LogicToLogic(
+                        aAcceptedVisArea.GetSize(),
+                        MapMode(aNewMapUnit),
+                        MapMode(getSdrModelFromSdrObject().GetScaleUnit())));
+            }
 
-                // make the new object area known to the client
-                // compared to the "else" branch aRect might have been changed 
by the object and no additional scaling was applied
-                // WHY this -> OSL_ASSERT( pClient );
-                if( pClient )
-                    pClient->SetObjArea(maRect);
+            // make the new object area known to the client
+            // compared to the "else" branch aRect might have been changed by 
the object and no additional scaling was applied
+            // WHY this -> OSL_ASSERT( pClient );
+            if( pClient )
+                pClient->SetObjArea(maRect);
 
-                // we need a new replacement image as the object has resized 
itself
+            // we need a new replacement image as the object has resized itself
 
-                //#i79578# don't request a new replacement image for charts to 
often
-                //a chart sends a modified call to the framework if it was 
changed
-                //thus the replacement update is already handled there
-                if( !IsChart() )
-                    mpImpl->mxObjRef.UpdateReplacement();
-            }
-            else
+            //#i79578# don't request a new replacement image for charts to 
often
+            //a chart sends a modified call to the framework if it was changed
+            //thus the replacement update is already handled there
+            if( !IsChart() )
+                mpImpl->mxObjRef.UpdateReplacement();
+        }
+        else
+        {
+            // The object isn't active and does not want to resize itself so 
the changed object area size
+            // will be reflected in a changed object scaling
+            Fraction aScaleWidth;
+            Fraction aScaleHeight;
+            Size aObjAreaSize;
+            if ( CalculateNewScaling( aScaleWidth, aScaleHeight, aObjAreaSize 
) )
             {
-                // The object isn't active and does not want to resize itself 
so the changed object area size
-                // will be reflected in a changed object scaling
-                Fraction aScaleWidth;
-                Fraction aScaleHeight;
-                Size aObjAreaSize;
-                if ( CalculateNewScaling( aScaleWidth, aScaleHeight, 
aObjAreaSize ) )
+                if ( pClient )
                 {
-                    if ( pClient )
-                    {
-                        tools::Rectangle aScaleRect(maRect.TopLeft(), 
aObjAreaSize);
-                        pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, 
aScaleHeight);
-                    }
-                    else
-                    {
-                        mpImpl->mxLightClient->SetSizeScale( aScaleWidth, 
aScaleHeight );
-                    }
+                    tools::Rectangle aScaleRect(maRect.TopLeft(), 
aObjAreaSize);
+                    pClient->SetObjAreaAndScale( aScaleRect, aScaleWidth, 
aScaleHeight);
+                }
+                else
+                {
+                    mpImpl->mxLightClient->SetSizeScale( aScaleWidth, 
aScaleHeight );
                 }
             }
         }
-        else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) 
&&
-            svt::EmbeddedObjectRef::TryRunningState( 
mpImpl->mxObjRef.GetObject() ) )
+    }
+    else if( (nMiscStatus & embed::EmbedMisc::MS_EMBED_RECOMPOSEONRESIZE) &&
+        svt::EmbeddedObjectRef::TryRunningState( mpImpl->mxObjRef.GetObject() 
) )
+    {
+        //also handle not sfx based ole objects e.g. charts
+        //#i83860# resizing charts in impress distorts fonts
+        uno::Reference< embed::XVisualObject > xVisualObject( getXModel(), 
uno::UNO_QUERY );
+        if( xVisualObject.is() )
         {
-            //also handle not sfx based ole objects e.g. charts
-            //#i83860# resizing charts in impress distorts fonts
-            uno::Reference< embed::XVisualObject > xVisualObject( getXModel(), 
uno::UNO_QUERY );
-            if( xVisualObject.is() )
-            {
-                const MapUnit aMapUnit(
-                    VCLUnoHelper::UnoEmbed2VCLMapUnit(
-                        mpImpl->mxObjRef->getMapUnit(GetAspect())));
-                const Point aTL( maRect.TopLeft() );
-                const Point aBR( maRect.BottomRight() );
-                const Point aTL2(
-                    OutputDevice::LogicToLogic(
-                        aTL,
-                        MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
-                        MapMode(aMapUnit)));
-                const Point aBR2(
-                    OutputDevice::LogicToLogic(
-                        aBR,
-                        MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
-                        MapMode(aMapUnit)));
-                const tools::Rectangle aNewRect(
-                    aTL2,
-                    aBR2);
-
-                xVisualObject->setVisualAreaSize(
-                    GetAspect(),
-                    awt::Size(
-                        aNewRect.GetWidth(),
-                        aNewRect.GetHeight()));
-            }
+            const MapUnit aMapUnit(
+                VCLUnoHelper::UnoEmbed2VCLMapUnit(
+                    mpImpl->mxObjRef->getMapUnit(GetAspect())));
+            const Point aTL( maRect.TopLeft() );
+            const Point aBR( maRect.BottomRight() );
+            const Point aTL2(
+                OutputDevice::LogicToLogic(
+                    aTL,
+                    MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
+                    MapMode(aMapUnit)));
+            const Point aBR2(
+                OutputDevice::LogicToLogic(
+                    aBR,
+                    MapMode(getSdrModelFromSdrObject().GetScaleUnit()),
+                    MapMode(aMapUnit)));
+            const tools::Rectangle aNewRect(
+                aTL2,
+                aBR2);
+
+            xVisualObject->setVisualAreaSize(
+                GetAspect(),
+                awt::Size(
+                    aNewRect.GetWidth(),
+                    aNewRect.GetHeight()));
         }
     }
 }
commit aa811e44db1ff88caab58a88a2602d00b6f157b4
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Tue Apr 11 10:13:37 2023 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue May 2 15:14:59 2023 +0200

    set Referer on loading IFrames
    
    so tools, options, security, options,
    "block any links from document not..."
    applies to their contents.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150221
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150751
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>
    (cherry picked from commit acff9ca0579333b45d10ae5f8cd48172f563dddd)
    
    Change-Id: I04839aea6b07a4a76ac147a85045939ccd9c3c79

diff --git a/sfx2/source/doc/iframe.cxx b/sfx2/source/doc/iframe.cxx
index 6dca7bcddb56..6e14f5f254e1 100644
--- a/sfx2/source/doc/iframe.cxx
+++ b/sfx2/source/doc/iframe.cxx
@@ -38,6 +38,7 @@
 #include <svtools/miscopt.hxx>
 #include <svl/ownlist.hxx>
 #include <svl/itemprop.hxx>
+#include <sfx2/docfile.hxx>
 #include <sfx2/frmdescr.hxx>
 #include <sfx2/objsh.hxx>
 #include <sfx2/sfxdlg.hxx>
@@ -196,10 +197,11 @@ sal_Bool SAL_CALL IFrameObject::load(
         uno::Reference < util::XURLTransformer > xTrans( 
util::URLTransformer::create( mxContext ) );
         xTrans->parseStrict( aTargetURL );
 
+        uno::Reference<frame::XFramesSupplier> xParentFrame = 
xFrame->getCreator();
+        SfxObjectShell* pDoc = SfxMacroLoader::GetObjectShell(xParentFrame);
+
         if (INetURLObject(aTargetURL.Complete).GetProtocol() == 
INetProtocol::Macro)
         {
-            uno::Reference<frame::XFramesSupplier> xParentFrame = 
xFrame->getCreator();
-            SfxObjectShell* pDoc = 
SfxMacroLoader::GetObjectShell(xParentFrame);
             if (pDoc && !pDoc->AdjustMacroMode())
                 return false;
         }
@@ -207,6 +209,10 @@ sal_Bool SAL_CALL IFrameObject::load(
         if (!lcl_isScriptURLAllowed(aTargetURL.Complete))
             return false;
 
+        OUString sReferer;
+        if (pDoc && pDoc->HasName())
+            sReferer = pDoc->GetMedium()->GetName();
+
         DBG_ASSERT( !mxFrame.is(), "Frame already existing!" );
         VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow( 
xFrame->getContainerWindow() );
         VclPtr<IFrameWindow_Impl> pWin = VclPtr<IFrameWindow_Impl>::Create( 
pParent, maFrmDescr.IsFrameBorderOn() );
@@ -229,11 +235,13 @@ sal_Bool SAL_CALL IFrameObject::load(
         if ( xFramesSupplier.is() )
             mxFrame->setCreator( xFramesSupplier );
 
-        uno::Sequence < beans::PropertyValue > aProps(2);
+        uno::Sequence < beans::PropertyValue > aProps(3);
         aProps[0].Name = "PluginMode";
         aProps[0].Value <<= sal_Int16(2);
         aProps[1].Name = "ReadOnly";
         aProps[1].Value <<= true;
+        aProps[2].Name = "Referer";
+        aProps[2].Value <<= sReferer;
         uno::Reference < frame::XDispatch > xDisp = mxFrame->queryDispatch( 
aTargetURL, "_self", 0 );
         if ( xDisp.is() )
             xDisp->dispatch( aTargetURL, aProps );

Reply via email to