sw/inc/ndole.hxx             |    1 +
 sw/source/core/ole/ndole.cxx |   25 +++++++++++++++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)

New commits:
commit ac0e74209c4f7a7eb7702468cecd3b996227c278
Author:     Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de>
AuthorDate: Tue Oct 25 11:48:18 2022 +0200
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Tue Oct 25 14:26:02 2022 +0200

    tdf#149189 detect and handle graphic change on Sw OLE
    
    If in any way a used SW OLE Chart gets changed
    (example in task uses a script and UNO API), detect
    this and react accordingly. Use getGraphicVersion()
    from EmbeddedObjectRef to decide when to reset bufferd
    graphic data. It gets incremented at all occasions
    where the graphic changes due to being used for a
    similar case already.
    An alternative would be to extend SwOLEListener_Impl
    with a XModifyListener as it is done in
    EmbedEventListener_Impl, that would require all the
    (add|remove)ModifyListener calls and/ managing these,
    plus having a 2nd listener to these when
    EmbeddedObjectRef already provides that. Tried that
    this works also if an alternative would be needed.
    
    Change-Id: Ic27088b0241aa4b5ecfc3c2b6e64994d720b3546
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141803
    Tested-by: Jenkins
    Reviewed-by: Regina Henschel <rb.hensc...@t-online.de>
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>

diff --git a/sw/inc/ndole.hxx b/sw/inc/ndole.hxx
index 89ce94ef9c40..acac9307e496 100644
--- a/sw/inc/ndole.hxx
+++ b/sw/inc/ndole.hxx
@@ -46,6 +46,7 @@ class SW_DLLPUBLIC SwOLEObj
     // eventually buffered data if it is a chart OLE
     drawinglayer::primitive2d::Primitive2DContainer     m_aPrimitive2DSequence;
     basegfx::B2DRange                                   m_aRange;
+    sal_uInt32                                          m_nGraphicVersion;
     std::unique_ptr<DeflateData>                        m_pDeflateData;
 
     SwOLEObj( const SwOLEObj& rObj ) = delete;
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index 633940b7e58a..12e24de606d4 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -773,7 +773,8 @@ private:
 
 SwOLEObj::SwOLEObj( const svt::EmbeddedObjectRef& xObj ) :
     m_pOLENode( nullptr ),
-    m_xOLERef( xObj )
+    m_xOLERef( xObj ),
+    m_nGraphicVersion( 0 )
 {
     m_xOLERef.Lock();
     if ( xObj.is() )
@@ -785,7 +786,8 @@ SwOLEObj::SwOLEObj( const svt::EmbeddedObjectRef& xObj ) :
 
 SwOLEObj::SwOLEObj( OUString aString, sal_Int64 nAspect ) :
     m_pOLENode( nullptr ),
-    m_aName( std::move(aString) )
+    m_aName( std::move(aString) ),
+    m_nGraphicVersion( 0 )
 {
     m_xOLERef.Lock();
     m_xOLERef.SetViewAspect( nAspect );
@@ -1099,10 +1101,26 @@ drawinglayer::primitive2d::Primitive2DContainer const & 
SwOLEObj::tryToGetChartC
             // copy the result data and cleanup
             m_aPrimitive2DSequence = m_pDeflateData->getSequence();
             m_aRange = m_pDeflateData->getRange();
+            m_nGraphicVersion = GetObject().getGraphicVersion();
             m_pDeflateData.reset();
         }
     }
 
+    if(!m_aPrimitive2DSequence.empty() && !m_aRange.isEmpty()
+       && m_nGraphicVersion != GetObject().getGraphicVersion())
+    {
+        // tdf#149189 use getGraphicVersion() from EmbeddedObjectRef
+        // to decide when to reset bufferd data. It gets incremented
+        // at all occasions where the graphic changes. An alternative
+        // would be to extend SwOLEListener_Impl with a XModifyListener
+        // as it is done in EmbedEventListener_Impl, that would
+        // require all the (add|remove)ModifyListener calls and
+        // managing these, plus having a 2nd listener to these when
+        // EmbeddedObjectRef already provides that. Tried that this
+        // works also if an alternative would be needed.
+        resetBufferedData();
+    }
+
     if(m_aPrimitive2DSequence.empty() && m_aRange.isEmpty() && m_xOLERef.is() 
&& m_xOLERef.IsChart())
     {
         const uno::Reference< frame::XModel > 
aXModel(m_xOLERef->getComponent(), uno::UNO_QUERY);
@@ -1139,6 +1157,9 @@ drawinglayer::primitive2d::Primitive2DContainer const & 
SwOLEObj::tryToGetChartC
     {
         // when we have data, also copy the buffered Range data as output
         rRange = m_aRange;
+
+        // tdf#149189 ..and the GraphicVersion number to identify changes
+        m_nGraphicVersion = GetObject().getGraphicVersion();
     }
 
     return m_aPrimitive2DSequence;

Reply via email to