sw/qa/extras/uiwriter/data/ole2.png |binary
 sw/qa/extras/uiwriter/uiwriter2.cxx |   29 +++++++++++++++++++++++++++++
 sw/source/core/frmedt/fefly1.cxx    |   12 ++++++++++++
 sw/source/uibase/wrtsh/wrtsh1.cxx   |    5 +++++
 4 files changed, 46 insertions(+)

New commits:
commit 4430201e39e4d352aaa547db0d0d7b5b7b3cbcef
Author:     László Németh <nem...@numbertext.org>
AuthorDate: Wed Jun 9 15:56:09 2021 +0200
Commit:     Balazs Varga <varga.bala...@nisz.hu>
CommitDate: Thu Oct 21 12:12:43 2021 +0200

    tdf#141994 track changes: record insertion of images
    
    by adding a SwRangeRedline to the anchoring point of
    the image inserted with Insert->Image... or
    "Insert Image" of the Standard toolbar.
    
    Note: Only images anchored as characters can be
    recorded this way, so change the default to-character
    anchoring at enabled change tracking. (In other office
    suites, as-character insertion is the default anchoring
    for inserted images with disabled change tracking, too.)
    
    Follow-up to commit d6322bcedc197a654abc7d64bfea8cf570f123bf
    "tdf#59463 track changes: record deletion of images".
    
    Change-Id: I593abbdb6f9f2b1a5265f112103479c1833166af
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116924
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 68b6004fe9df184bcbaf46dd53abfec228219df6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123969
    Tested-by: Balazs Varga <varga.bala...@nisz.hu>
    Reviewed-by: Balazs Varga <varga.bala...@nisz.hu>

diff --git a/sw/qa/extras/uiwriter/data/ole2.png 
b/sw/qa/extras/uiwriter/data/ole2.png
new file mode 100644
index 000000000000..fdad35484e7c
Binary files /dev/null and b/sw/qa/extras/uiwriter/data/ole2.png differ
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx 
b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 1a6d455abfb3..0559d52612cf 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/text/XTextTable.hpp>
 #include <com/sun/star/table/XTableRows.hpp>
 #include <comphelper/propertysequence.hxx>
+#include <comphelper/propertyvalue.hxx>
 #include <comphelper/configuration.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <i18nlangtag/languagetag.hxx>
@@ -3090,6 +3091,34 @@ CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, 
testTrackImageDeletion)
     CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), 
rTable.size());
 }
 
+CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTrackImageInsertion)
+{
+    loadURL("private:factory/swriter", nullptr);
+    SwXTextDocument* pTextDoc = 
dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+
+    // turn on red-lining and show changes
+    IDocumentRedlineAccess& rIDRA(pDoc->getIDocumentRedlineAccess());
+
+    rIDRA.SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowDelete | 
RedlineFlags::ShowInsert);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        
IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+
+    // Insert an image with change tracking
+    OUString aImageURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + 
"ole2.png";
+    uno::Sequence<beans::PropertyValue> aArgs = {
+        comphelper::makePropertyValue("FileName", aImageURL),
+    };
+    dispatchCommand(mxComponent, ".uno:InsertGraphic", aArgs);
+
+    const SwRedlineTable& rTable = rIDRA.GetRedlineTable();
+    // this was 0 (missing recording of insertion of images)
+    CPPUNIT_ASSERT_EQUAL(static_cast<SwRedlineTable::size_type>(1), 
rTable.size());
+}
+
 CPPUNIT_TEST_FIXTURE(SwUiWriterTest2, testTdf120338)
 {
     load(DATA_DIRECTORY, "tdf120338.docx");
diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 7afe6ee04afa..173c98a97d14 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -48,6 +48,8 @@
 #include <IDocumentUndoRedo.hxx>
 #include <IDocumentState.hxx>
 #include <IDocumentLayoutAccess.hxx>
+#include <IDocumentRedlineAccess.hxx>
+#include <redline.hxx>
 #include <dview.hxx>
 #include <dflyobj.hxx>
 #include <dcontact.hxx>
@@ -890,6 +892,16 @@ void SwFEShell::Insert( const OUString& rGrfName, const 
OUString& rFltName,
 
     if( pFrame )
     {
+        // add a redline to the anchor point at tracked insertion of picture
+        if ( IsRedlineOn() )
+        {
+            SwPosition aPos(*pFormat->GetAnchor().GetContentAnchor());
+            SwPaM aPaM(aPos.nNode.GetNode(), aPos.nContent.GetIndex(),
+                    aPos.nNode.GetNode(), aPos.nContent.GetIndex() + 1);
+            GetDoc()->getIDocumentRedlineAccess().AppendRedline(
+                    new SwRangeRedline( RedlineType::Insert, aPaM ), true);
+        }
+
         // fdo#36681: Invalidate the content and layout to refresh
         // the picture anchoring properly
         SwPageFrame* pPageFrame = pFrame->FindPageFrameOfAnchor();
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 8251a9978142..7816800d99b7 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -315,6 +315,11 @@ void SwWrtShell::Insert( const OUString &rPath, const 
OUString &rFilter,
         pFrameMgr->SetHeightSizeType(SwFrameSize::Fixed);
     }
 
+    // during change tracking, insert the image anchored as character
+    // (to create an SwRangeRedline on its anchor point)
+    if ( IsRedlineOn() && nAnchorType != RndStdIds::FLY_AS_CHAR )
+        pFrameMgr->SetAnchor( RndStdIds::FLY_AS_CHAR );
+
     // Insert the graphic
     SwFEShell::Insert(rPath, rFilter, &rGrf, &pFrameMgr->GetAttrSet());
     if ( bOwnMgr )

Reply via email to