[Libreoffice-commits] core.git: Branch 'private/swe/libreoffice-5-2+backports' - sc/source

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Thu Mar 22 16:24:09 UTC 2018


 sc/source/core/data/drwlayer.cxx |   54 +++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 16 deletions(-)

New commits:
commit 92eb0237929b3af48e1450b1f3b6bdca6dc925a3
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Thu Mar 22 09:15:11 2018 +0100

    tdf#116510 Copy cell anchored images too when copying cells
    
    Reviewed-on: https://gerrit.libreoffice.org/51725
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    (cherry picked from commit d8b7119859897fa98b6588e2426a13fbd51cf3dd)
    
    Change-Id: Ia64100a00e65b7871c44a9b4700ca86782897a8e

diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index df389893bd18..000bbcc85a46 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -238,6 +238,23 @@ static void lcl_ReverseTwipsToMM( Rectangle& rRect )
     ReverseTwipsToMM( rRect.Bottom() );
 }
 
+static ScRange lcl_getClipRangeFromClipDoc(ScDocument* pClipDoc, SCTAB nClipTab)
+{
+    if (!pClipDoc)
+        return ScRange();
+
+    SCCOL nClipStartX;
+    SCROW nClipStartY;
+    SCCOL nClipEndX;
+    SCROW nClipEndY;
+    pClipDoc->GetClipStart(nClipStartX, nClipStartY);
+    pClipDoc->GetClipArea(nClipEndX, nClipEndY, true);
+    nClipEndX = nClipEndX + nClipStartX;
+    nClipEndY += nClipStartY; // GetClipArea returns the difference
+
+    return ScRange(nClipStartX, nClipStartY, nClipTab, nClipEndX, nClipEndY, nClipTab);
+}
+
 ScDrawLayer::ScDrawLayer( ScDocument* pDocument, const OUString& rName ) :
     FmFormModel( SvtPathOptions().GetPalettePath(),
                  nullptr,                          // SfxItemPool* Pool
@@ -1430,8 +1447,18 @@ void ScDrawLayer::CopyToClip( ScDocument* pClipDoc, SCTAB nTab, const Rectangle&
         while (pOldObject)
         {
             Rectangle aObjRect = pOldObject->GetCurrentBoundRect();
+
+            bool bObjectInArea = rRange.IsInside(aObjRect);
+            const ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pOldObject);
+            if (pObjData)
+            {
+                ScRange aClipRange = lcl_getClipRangeFromClipDoc(pClipDoc, nTab);
+                bObjectInArea = bObjectInArea || aClipRange.In(pObjData->maStart);
+            }
+
             // do not copy internal objects (detective) and note captions
-            if ( rRange.IsInside( aObjRect ) && (pOldObject->GetLayer() != SC_LAYER_INTERN) && !IsNoteCaption( pOldObject ) )
+            if (bObjectInArea && pOldObject->GetLayer() != SC_LAYER_INTERN
+                && !IsNoteCaption(pOldObject))
             {
                 if ( !pDestModel )
                 {
@@ -1614,7 +1641,16 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const
     {
         Rectangle aObjRect = pOldObject->GetCurrentBoundRect();
         // do not copy internal objects (detective) and note captions
-        if ( rSourceRange.IsInside( aObjRect ) && (pOldObject->GetLayer() != SC_LAYER_INTERN) && !IsNoteCaption( pOldObject ) )
+
+        SCTAB nClipTab = bRestoreDestTabName ? nDestTab : nSourceTab;
+        ScRange aClipRange = lcl_getClipRangeFromClipDoc(pClipDoc, nClipTab);
+
+        bool bObjectInArea = rSourceRange.IsInside(aObjRect);
+        const ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pOldObject);
+        if (pObjData) // Consider images anchored to the copied cell
+            bObjectInArea = bObjectInArea || aClipRange.In(pObjData->maStart);
+        if (bObjectInArea && (pOldObject->GetLayer() != SC_LAYER_INTERN)
+            && !IsNoteCaption(pOldObject))
         {
             SdrObject* pNewObject = pOldObject->Clone();
             pNewObject->SetModel(this);
@@ -1659,22 +1695,8 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const
                         if( !aRangesVector.empty() )
                         {
                             bool bInSourceRange = false;
-                            ScRange aClipRange;
                             if ( pClipDoc )
                             {
-                                SCCOL nClipStartX;
-                                SCROW nClipStartY;
-                                SCCOL nClipEndX;
-                                SCROW nClipEndY;
-                                pClipDoc->GetClipStart( nClipStartX, nClipStartY );
-                                pClipDoc->GetClipArea( nClipEndX, nClipEndY, true );
-                                nClipEndX = nClipEndX + nClipStartX;
-                                nClipEndY += nClipStartY;   // GetClipArea returns the difference
-
-                                SCTAB nClipTab = bRestoreDestTabName ? nDestTab : nSourceTab;
-                                aClipRange = ScRange( nClipStartX, nClipStartY, nClipTab,
-                                                        nClipEndX, nClipEndY, nClipTab );
-
                                 bInSourceRange = lcl_IsAllInRange( aRangesVector, aClipRange );
                             }
 


More information about the Libreoffice-commits mailing list