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

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Fri Dec 22 16:45:37 UTC 2017


 sc/inc/column.hxx                |    2 ++
 sc/inc/drwlayer.hxx              |    4 +++-
 sc/source/core/data/column.cxx   |   35 +++++++++++++++++++++++++++++++++++
 sc/source/core/data/drwlayer.cxx |   24 +++++++++++++++++++++++-
 sc/source/core/data/table3.cxx   |   27 ++++++++++++++++++++++++++-
 5 files changed, 89 insertions(+), 3 deletions(-)

New commits:
commit efb190857650b2f2592be783a0e2997b8eeaf768
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Wed Dec 20 11:30:36 2017 +0100

    tdf#98931 Consider cell-anchored images when sorting
    
    (cherry picked from commit 06567dd9c92fc2d3971fc0ce893c74d019176c5e)
    
    Change-Id: Id9a56a15f776d5adbe382a9bca167bff48b69a0c
    Reviewed-on: https://gerrit.libreoffice.org/46982
    Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
    Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 939716443d20..2188c539bf41 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -29,6 +29,7 @@
 #include "mtvelements.hxx"
 #include <formula/types.hxx>
 #include <svl/zforlist.hxx>
+#include <svx/svdobj.hxx>
 
 #include <set>
 #include <vector>
@@ -608,6 +609,7 @@ public:
                             sc::ColumnBlockPosition& maDestBlockPos, bool bCloneCaption = true, SCROW nRowOffsetDest=0 ) const;
 
     void UpdateNoteCaptions( SCROW nRow1, SCROW nRow2 );
+    void UpdateDrawObjects( std::vector<std::vector<SdrObject*>> pObjects, SCROW nRowStart, SCROW nRowEnd );
 
     void InterpretDirtyCells( SCROW nRow1, SCROW nRow2 );
 
diff --git a/sc/inc/drwlayer.hxx b/sc/inc/drwlayer.hxx
index 54951b506f36..64c8b1980c68 100644
--- a/sc/inc/drwlayer.hxx
+++ b/sc/inc/drwlayer.hxx
@@ -104,7 +104,6 @@ private:
     void            MoveCells( SCTAB nTab, SCCOL nCol1,SCROW nRow1, SCCOL nCol2,SCROW nRow2,
                                 SCsCOL nDx,SCsROW nDy, bool bUpdateNoteCaptionPos );
 
-    void            RecalcPos( SdrObject* pObj, ScDrawObjData& rData, bool bNegativePage, bool bUpdateNoteCaptionPos );
     void            ResizeLastRectFromAnchor( SdrObject* pObj, ScDrawObjData& rData, bool bUseLogicRect, bool bNegativePage, bool bCanResize, bool bHiddenAsZero = true );
 
 public:
@@ -142,6 +141,8 @@ public:
     void            MoveArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1, SCCOL nCol2,SCROW nRow2,
                                 SCsCOL nDx,SCsROW nDy, bool bInsDel, bool bUpdateNoteCaptionPos = true );
 
+    void            RecalcPos( SdrObject* pObj, ScDrawObjData& rData, bool bNegativePage, bool bUpdateNoteCaptionPos );
+
     bool            HasObjectsInRows( SCTAB nTab, SCROW nStartRow, SCROW nEndRow );
 
     void            DeleteObjectsInArea( SCTAB nTab, SCCOL nCol1,SCROW nRow1,
@@ -182,6 +183,7 @@ public:
     static void             SetCellAnchoredFromPosition( SdrObject &rObj, const ScDocument &rDoc, SCTAB nTab );
     static void             UpdateCellAnchorFromPositionEnd( SdrObject &rObj, ScDrawObjData &rAnchor, const ScDocument &rDoc, SCTAB nTab, bool bUseLogicRect = true );
     static ScAnchorType     GetAnchorType( const SdrObject& );
+    std::vector<SdrObject*> GetObjectsAnchoredToCell(const ScAddress& rPos);
 
     // positions for detektive lines
     static ScDrawObjData* GetObjData( SdrObject* pObj, bool bCreate=false );
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index b70796390989..91b078e37d9b 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -45,6 +45,8 @@
 #include <refhint.hxx>
 #include <stlalgorithm.hxx>
 #include <formulagroup.hxx>
+#include <userdat.hxx>
+#include <drwlayer.hxx>
 
 #include <svl/poolcach.hxx>
 #include <svl/zforlist.hxx>
@@ -1896,6 +1898,39 @@ void ScColumn::UpdateNoteCaptions( SCROW nRow1, SCROW nRow2 )
     NoteCaptionUpdater aFunc(nCol, nTab);
     sc::ProcessNote(maCellNotes.begin(), maCellNotes, nRow1, nRow2, aFunc);
 }
+void ScColumn::UpdateDrawObjects(std::vector<std::vector<SdrObject*>> pObjects, SCROW nRowStart, SCROW nRowEnd)
+{
+    int nObj = 0;
+    for (SCROW nCurrentRow = nRowStart; nCurrentRow <= nRowEnd; nCurrentRow++, nObj++)
+    {
+        if (pObjects[nObj].empty())
+            continue; // No draw objects in this row
+
+        for (auto &pObject : pObjects[nObj])
+        {
+            // Get anchor data
+            ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pObject, false);
+            const ScAddress aOldStart = pObjData->maStart;
+            const ScAddress aOldEnd = pObjData->maEnd;
+
+            // Set start address
+            ScAddress aNewStart = ScAddress(nCol, nCurrentRow, nTab);
+            pObjData->maStart = aNewStart;
+
+            // Set end address
+            const SCCOL nObjectColSpan = aOldEnd.Col() - aOldStart.Col();
+            const SCROW nObjectRowSpan = aOldEnd.Row() - aOldStart.Row();
+            ScAddress aNewEnd = aNewStart;
+            aNewEnd.IncRow(nObjectRowSpan);
+            aNewEnd.IncCol(nObjectColSpan);
+            pObjData->maEnd = aNewEnd;
+
+            // Update draw object according to new anchor
+            ScDrawLayer* pDrawLayer = GetDoc().GetDrawLayer();
+            pDrawLayer->RecalcPos(pObject, *pObjData, false, false);
+        }
+    }
+}
 
 void ScColumn::SwapCol(ScColumn& rCol)
 {
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 7ea675821d0a..501cb275c973 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -1936,7 +1936,6 @@ void ScDrawLayer::GetCellAnchorFromPosition( SdrObject &rObj, ScDrawObjData &rAn
         rAnchor.maEndOffset.X() = aObjRect.Right()-aCellRect.Left();
     else
         rAnchor.maEndOffset.X() = aCellRect.Right()-aObjRect.Left();
-
 }
 
 void ScDrawLayer::UpdateCellAnchorFromPositionEnd( SdrObject &rObj, ScDrawObjData &rAnchor, const ScDocument &rDoc, SCTAB nTab, bool bUseLogicRect )
@@ -1977,6 +1976,29 @@ ScAnchorType ScDrawLayer::GetAnchorType( const SdrObject &rObj )
     return ScDrawLayer::GetObjData(const_cast<SdrObject*>(&rObj)) ? SCA_CELL : SCA_PAGE;
 }
 
+std::vector<SdrObject*> ScDrawLayer::GetObjectsAnchoredToCell(const ScAddress& rCell)
+{
+    SdrPage* pPage = GetPage(static_cast<sal_uInt16>(rCell.Tab()));
+    if (!pPage || pPage->GetObjCount() < 1)
+        return std::vector<SdrObject*>();
+
+    std::vector<SdrObject*> pObjects;
+    SdrObjListIter aIter( *pPage, IM_FLAT );
+    SdrObject* pObject = aIter.Next();
+    ScDrawObjData* pObjData;
+    while (pObject)
+    {
+        if (!dynamic_cast<SdrCaptionObj*>(pObject)) // Caption objects are handled differently
+        {
+            pObjData = GetObjData(pObject);
+            if (pObjData && pObjData->maStart == rCell) // Object is anchored to this cell
+                pObjects.push_back(pObject);
+        }
+        pObject = aIter.Next();
+    }
+    return pObjects;
+}
+
 ScDrawObjData* ScDrawLayer::GetNonRotatedObjData( SdrObject* pObj, bool bCreate )
 {
     sal_uInt16 nCount = pObj ? pObj->GetUserDataCount() : 0;
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index afe21d794e5a..509731d0eff0 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -22,6 +22,7 @@
 #include <unotools/textsearch.hxx>
 #include <svl/zforlist.hxx>
 #include <svl/zformat.hxx>
+#include <svx/svdobj.hxx>
 #include <unotools/charclass.hxx>
 #include <unotools/collatorwrapper.hxx>
 #include <com/sun/star/i18n/CollatorOptions.hpp>
@@ -64,6 +65,7 @@
 #include <listenerquery.hxx>
 #include <bcaslot.hxx>
 #include <reordermap.hxx>
+#include <drwlayer.hxx>
 
 #include <svl/sharedstringpool.hxx>
 
@@ -228,9 +230,10 @@ public:
         ScRefCellValue maCell;
         const sc::CellTextAttr* mpAttr;
         const ScPostIt* mpNote;
+        std::vector<SdrObject*> maDrawObjects;
         const ScPatternAttr* mpPattern;
 
-        Cell() : mpAttr(nullptr), mpNote(nullptr), mpPattern(nullptr) {}
+        Cell() : mpAttr(nullptr), mpNote(nullptr), maDrawObjects(), mpPattern(nullptr) {}
     };
 
     struct Row
@@ -439,6 +442,17 @@ void initDataRows(
             rCell.maCell = rCol.GetCellValue(aBlockPos, nRow);
             rCell.mpAttr = rCol.GetCellTextAttr(aBlockPos, nRow);
             rCell.mpNote = rCol.GetCellNote(aBlockPos, nRow);
+            ScDrawLayer* pDrawLayer = rTab.GetDoc().GetDrawLayer();
+            if (pDrawLayer)
+            {
+                ScAddress aCellPos(nCol, nRow, rTab.GetTab());
+                std::vector<SdrObject*> pObjects = pDrawLayer->GetObjectsAnchoredToCell(aCellPos);
+                rCell.maDrawObjects = pObjects;
+            }
+            else
+            {
+                SAL_WARN("sc", "Could not retrieve anchored images, no DrawLayer available");
+            }
 
             if (!bUniformPattern && bPattern)
                 rCell.mpPattern = rCol.GetPattern(nRow);
@@ -549,6 +563,7 @@ struct SortedColumn
     sc::CellTextAttrStoreType maCellTextAttrs;
     sc::BroadcasterStoreType maBroadcasters;
     sc::CellNoteStoreType maCellNotes;
+    std::vector<std::vector<SdrObject*>> maCellDrawObjects;
 
     PatRangeType maPatterns;
     PatRangeType::const_iterator miPatternPos;
@@ -561,6 +576,7 @@ struct SortedColumn
         maCellTextAttrs(nTopEmptyRows),
         maBroadcasters(nTopEmptyRows),
         maCellNotes(nTopEmptyRows),
+        maCellDrawObjects(),
         maPatterns(0, MAXROWCOUNT, nullptr),
         miPatternPos(maPatterns.begin()) {}
 
@@ -811,6 +827,9 @@ void fillSortedColumnArray(
             else
                 rNoteStore.push_back_empty();
 
+            // Add cell anchored images
+            aSortedCols.at(j).get()->maCellDrawObjects.push_back(rCell.maDrawObjects);
+
             if (rCell.mpPattern)
                 aSortedCols.at(j).get()->setPattern(aCellPos.Row(), rCell.mpPattern);
         }
@@ -1120,6 +1139,9 @@ void ScTable::SortReorderByRow(
             aCol[nThisCol].UpdateNoteCaptions(nRow1, nRow2);
         }
 
+        // Update draw object positions
+        aCol[nThisCol].UpdateDrawObjects(aSortedCols[i].get()->maCellDrawObjects, nRow1, nRow2);
+
         {
             // Get all row spans where the pattern is not NULL.
             std::vector<PatternSpan> aSpans =
@@ -1318,6 +1340,9 @@ void ScTable::SortReorderByRowRefUpdate(
             aCol[nThisCol].UpdateNoteCaptions(nRow1, nRow2);
         }
 
+        // Update draw object positions
+        aCol[nThisCol].UpdateDrawObjects(aSortedCols[i].get()->maCellDrawObjects, nRow1, nRow2);
+
         {
             // Get all row spans where the pattern is not NULL.
             std::vector<PatternSpan> aSpans =


More information about the Libreoffice-commits mailing list