[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - 2 commits - sw/qa sw/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Mon Jul 8 08:32:14 UTC 2019


 sw/qa/extras/uiwriter/uiwriter2.cxx                   |   13 +++++
 sw/qa/extras/ww8export/data/image-comment-at-char.doc |binary
 sw/qa/extras/ww8export/ww8export3.cxx                 |   17 +++++++
 sw/source/filter/basflt/fltshell.cxx                  |   11 ++++
 sw/source/filter/ww8/wrtw8sty.cxx                     |   25 +++++++++--
 sw/source/filter/ww8/wrtww8.cxx                       |    3 -
 sw/source/filter/ww8/wrtww8.hxx                       |    7 ++-
 sw/source/uibase/wrtsh/delete.cxx                     |   40 ++++++++++++++++++
 8 files changed, 108 insertions(+), 8 deletions(-)

New commits:
commit 8570cc04a47ba3172899a57d12ed89d4c2a69012
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jul 3 14:05:05 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jul 8 10:31:41 2019 +0200

    sw comments on frames: delete comment of frame when deleting frame
    
    Also group the two actions together, so only 1 undo action is visible to
    the user, not 2.
    
    (cherry picked from commit 86fd893e32ef7a737b2c4b60e0938146b102fc07)
    
    Conflicts:
            sw/qa/extras/uiwriter/uiwriter2.cxx
            sw/source/uibase/wrtsh/delete.cxx
    
    Change-Id: Idba5a63b1653e96db4f9567a38b3f4ca740eb1df
    Reviewed-on: https://gerrit.libreoffice.org/75120
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index daa813247bf4..7a6ccec9adfc 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -12,6 +12,7 @@
 #include <swdtflvr.hxx>
 #include <wrtsh.hxx>
 #include <redline.hxx>
+#include <svl/stritem.hxx>
 #include <flyfrms.hxx>
 #include <UndoManager.hxx>
 #include <edtwin.hxx>
@@ -539,6 +540,18 @@ void SwUiWriterTest2::testImageCommentAtChar()
                          getProperty<OUString>(getRun(xPara, 4), "TextPortionType"));
     CPPUNIT_ASSERT_EQUAL(OUString("Text"),
                          getProperty<OUString>(getRun(xPara, 5), "TextPortionType"));
+
+    // Insert content to the comment, and select the image again.
+    SfxStringItem aItem(FN_INSERT_STRING, "x");
+    pView->GetViewFrame()->GetDispatcher()->ExecuteList(FN_INSERT_STRING, SfxCallMode::SYNCHRON,
+                                                        { &aItem });
+    pView->GetViewFrame()->GetDispatcher()->Execute(FN_CNTNT_TO_NEXT_FRAME, SfxCallMode::SYNCHRON);
+    // Now delete the image.
+    pView->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON);
+    // Without the accompanying fix in place, this test would have failed with 'Expected: 0; Actual:
+    // 1', i.e. the comment of the image was not deleted when the image was deleted.
+    CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0),
+                         pDoc->getIDocumentMarkAccess()->getAnnotationMarksCount());
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
diff --git a/sw/source/uibase/wrtsh/delete.cxx b/sw/source/uibase/wrtsh/delete.cxx
index f18af272eaf3..0d060586645c 100644
--- a/sw/source/uibase/wrtsh/delete.cxx
+++ b/sw/source/uibase/wrtsh/delete.cxx
@@ -23,6 +23,10 @@
 #include <view.hxx>
 #include <drawbase.hxx>
 #include <unobaseclass.hxx>
+#include <fmtanchr.hxx>
+#include <flyfrm.hxx>
+#include <ndtxt.hxx>
+#include <IDocumentUndoRedo.hxx>
 
 inline void SwWrtShell::OpenMark()
 {
@@ -367,8 +371,44 @@ long SwWrtShell::DelRight()
             // #108205# Remember object's position.
             Point aTmpPt = GetObjRect().TopLeft();
 
+            // Remember the anchof of the selected object before deletion.
+            std::unique_ptr<SwPosition> pAnchor;
+            SwFlyFrame* pFly = GetSelectedFlyFrame();
+            if (pFly)
+            {
+                SwFrameFormat* pFormat = pFly->GetFormat();
+                if (pFormat && pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AT_CHAR)
+                {
+                    if (pFormat->GetAnchor().GetContentAnchor())
+                    {
+                        pAnchor.reset(new SwPosition(*pFormat->GetAnchor().GetContentAnchor()));
+                    }
+                }
+            }
+
+            // Group deletion of the object and its comment together.
+            mxDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::EMPTY, nullptr);
+
             DelSelectedObj();
 
+            if (pAnchor)
+            {
+                SwTextNode* pTextNode = pAnchor->nNode.GetNode().GetTextNode();
+                if (pTextNode)
+                {
+                    const SwTextField* pField(
+                        pTextNode->GetFieldTextAttrAt(pAnchor->nContent.GetIndex(), true));
+                    if (pField)
+                    {
+                        // Remove the comment of the deleted object.
+                        *GetCurrentShellCursor().GetPoint() = *pAnchor;
+                        DelRight();
+                    }
+                }
+            }
+
+            mxDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::EMPTY, nullptr);
+
             // #108205# Set cursor to remembered position.
             SetCursor(&aTmpPt);
 
commit 720176cef0e5a563fd295963241594c92ac0126a
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Wed Jul 3 10:35:48 2019 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jul 8 10:31:35 2019 +0200

    sw comments on frames: fix DOC handling
    
    The export part didn't use HasFlysAt() to decide what to do with empty
    annotation marks.
    
    Regarding the import side, the only problem was that the start of the
    annotation range wasn't adjusted to cover the comment anchor, similar to
    what the UI and the UNO API already does.
    
    (cherry picked from commit 132803f99818bffbdc260918ad7a304f228f2843)
    
    Conflicts:
            sw/qa/extras/ww8export/ww8export3.cxx
    
    Change-Id: Ibcbaafa9f3f70de95a70b424aca31ebdc9df099d
    Reviewed-on: https://gerrit.libreoffice.org/75119
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sw/qa/extras/ww8export/data/image-comment-at-char.doc b/sw/qa/extras/ww8export/data/image-comment-at-char.doc
new file mode 100644
index 000000000000..e0d5e2cba456
Binary files /dev/null and b/sw/qa/extras/ww8export/data/image-comment-at-char.doc differ
diff --git a/sw/qa/extras/ww8export/ww8export3.cxx b/sw/qa/extras/ww8export/ww8export3.cxx
index 32b4197452b1..2062f2976819 100644
--- a/sw/qa/extras/ww8export/ww8export3.cxx
+++ b/sw/qa/extras/ww8export/ww8export3.cxx
@@ -129,6 +129,23 @@ DECLARE_WW8EXPORT_TEST(testTdf118375export, "tdf118375_240degClockwise.doc")
     CPPUNIT_ASSERT_DOUBLES_EQUAL(1152.0, static_cast<double>(nPosY), 1.0);
 }
 
+DECLARE_WW8EXPORT_TEST(testImageCommentAtChar, "image-comment-at-char.doc")
+{
+    uno::Reference<text::XTextRange> xPara = getParagraph(1);
+    CPPUNIT_ASSERT_EQUAL(OUString("Text"),
+                         getProperty<OUString>(getRun(xPara, 1), "TextPortionType"));
+    // Without the accompanying fix in place, this test would have failed with 'Expected:
+    // Annotation; Actual: Frame', i.e. the comment start before the image was lost.
+    CPPUNIT_ASSERT_EQUAL(OUString("Annotation"),
+                         getProperty<OUString>(getRun(xPara, 2), "TextPortionType"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Frame"),
+                         getProperty<OUString>(getRun(xPara, 3), "TextPortionType"));
+    CPPUNIT_ASSERT_EQUAL(OUString("AnnotationEnd"),
+                         getProperty<OUString>(getRun(xPara, 4), "TextPortionType"));
+    CPPUNIT_ASSERT_EQUAL(OUString("Text"),
+                         getProperty<OUString>(getRun(xPara, 5), "TextPortionType"));
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/basflt/fltshell.cxx b/sw/source/filter/basflt/fltshell.cxx
index bcfa1e5b61b9..bd64b05ea2a8 100644
--- a/sw/source/filter/basflt/fltshell.cxx
+++ b/sw/source/filter/basflt/fltshell.cxx
@@ -659,6 +659,17 @@ void SwFltControlStack::SetAttrInDoc(const SwPosition& rTmpPos,
                     if (pPostIt)
                     {
                         assert(pPostIt->GetName().isEmpty());
+
+                        if (!aRegion.HasMark())
+                        {
+                            // Annotation range was found in the file, but start/end is the same,
+                            // pointing after the postit placeholder (see assert above).
+                            // Adjust the start of the range to actually cover the comment, similar
+                            // to what the UI and the UNO API does.
+                            aRegion.SetMark();
+                            --aRegion.Start()->nContent;
+                        }
+
                         pDoc->getIDocumentMarkAccess()->makeAnnotationMark(aRegion, OUString());
                     }
                     else
diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx
index 3353084ef6e3..dbb3aad12cd0 100644
--- a/sw/source/filter/ww8/wrtw8sty.cxx
+++ b/sw/source/filter/ww8/wrtw8sty.cxx
@@ -1971,9 +1971,20 @@ WW8_Annotation::WW8_Annotation(const SwRedlineData* pRedline)
     maDateTime = pRedline->GetTimeStamp();
 }
 
-void WW8_WrPlcAnnotations::AddRangeStartPosition(const OUString& rName, WW8_CP nStartCp)
+bool WW8_Annotation::HasRange() const
 {
-    m_aRangeStartPositions[rName] = nStartCp;
+    if (m_nRangeStart != m_nRangeEnd)
+    {
+        return true;
+    }
+
+    return !m_bIgnoreEmpty;
+}
+
+void WW8_WrPlcAnnotations::AddRangeStartPosition(const OUString& rName, WW8_CP nStartCp,
+                                                 bool bIgnoreEmpty)
+{
+    m_aRangeStartPositions[rName] = std::make_pair(nStartCp, bIgnoreEmpty);
 }
 
 void WW8_WrPlcAnnotations::Append( WW8_CP nCp, const SwPostItField *pPostIt )
@@ -1982,7 +1993,11 @@ void WW8_WrPlcAnnotations::Append( WW8_CP nCp, const SwPostItField *pPostIt )
     WW8_Annotation* p;
     if( m_aRangeStartPositions.find(pPostIt->GetName()) != m_aRangeStartPositions.end() )
     {
-        p = new WW8_Annotation(pPostIt, m_aRangeStartPositions[pPostIt->GetName()], nCp);
+        std::pair<WW8_CP, bool> aPair = m_aRangeStartPositions[pPostIt->GetName()];
+        WW8_CP nStartCp = aPair.first;
+        bool bIgnoreEmpty = aPair.second;
+        p = new WW8_Annotation(pPostIt, nStartCp, nCp);
+        p->m_bIgnoreEmpty = bIgnoreEmpty;
         m_aRangeStartPositions.erase(pPostIt->GetName());
     }
     else
@@ -2188,7 +2203,7 @@ void WW8_WrPlcSubDoc::WriteGenericPlc( WW8Export& rWrt, sal_uInt8 nTTyp,
                     const WW8_Annotation& rAtn = *static_cast<const WW8_Annotation*>(aContent[i]);
                     aStrArr.emplace_back(rAtn.msOwner,rAtn.m_sInitials);
                     // record start and end positions for ranges
-                    if( rAtn.m_nRangeStart != rAtn.m_nRangeEnd )
+                    if (rAtn.HasRange())
                     {
                         aRangeStartPos.emplace_back(rAtn.m_nRangeStart, nIdx);
                         aRangeEndPos.emplace_back(rAtn.m_nRangeEnd, nIdx);
@@ -2413,7 +2428,7 @@ void WW8_WrPlcSubDoc::WriteGenericPlc( WW8Export& rWrt, sal_uInt8 nTTyp,
                 SwWW8Writer::WriteShort( *rWrt.pTableStrm, nFndPos );
                 SwWW8Writer::WriteShort( *rWrt.pTableStrm, 0 );
                 SwWW8Writer::WriteShort( *rWrt.pTableStrm, 0 );
-                if( rAtn.m_nRangeStart != rAtn.m_nRangeEnd )
+                if (rAtn.HasRange())
                 {
                     SwWW8Writer::WriteLong( *rWrt.pTableStrm, nlTag );
                     ++nlTag;
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 612dee47e903..e7cef61f0db1 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -1485,7 +1485,8 @@ void WW8Export::AppendAnnotationMarks(const SwWW8AttrIter& rAttrs, sal_Int32 nAk
             const sal_Int32 nStart = pMark->GetMarkStart().nContent.GetIndex();
             if (nStart == nAktPos)
             {
-                m_pAtn->AddRangeStartPosition(pMark->GetName(), Fc2Cp(Strm().Tell()));
+                m_pAtn->AddRangeStartPosition(pMark->GetName(), Fc2Cp(Strm().Tell()),
+                                              !rAttrs.HasFlysAt(nAktPos));
             }
         }
     }
diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx
index 755c9fdf39bc..56a458e876a9 100644
--- a/sw/source/filter/ww8/wrtww8.hxx
+++ b/sw/source/filter/ww8/wrtww8.hxx
@@ -1218,8 +1218,11 @@ struct WW8_Annotation
     OUString m_sInitials;
     DateTime maDateTime;
     WW8_CP m_nRangeStart, m_nRangeEnd;
+    bool m_bIgnoreEmpty = true;
     WW8_Annotation(const SwPostItField* pPostIt, WW8_CP nRangeStart, WW8_CP nRangeEnd);
     explicit WW8_Annotation(const SwRedlineData* pRedline);
+    /// An annotation has a range if start != end or the m_bIgnoreEmpty flag is cleared.
+    bool HasRange() const;
 };
 
 class WW8_WrPlcAnnotations : public WW8_WrPlcSubDoc  // double Plc for Postits
@@ -1229,12 +1232,12 @@ private:
     WW8_WrPlcAnnotations& operator=(WW8_WrPlcAnnotations&) = delete;
     std::set<const SwRedlineData*> maProcessedRedlines;
 
-    std::map<const OUString, WW8_CP> m_aRangeStartPositions;
+    std::map<const OUString, std::pair<WW8_CP, bool>> m_aRangeStartPositions;
 public:
     WW8_WrPlcAnnotations() {}
     virtual ~WW8_WrPlcAnnotations() override;
 
-    void AddRangeStartPosition(const OUString& rName, WW8_CP nStartCp);
+    void AddRangeStartPosition(const OUString& rName, WW8_CP nStartCp, bool bIgnoreEmpty);
     void Append( WW8_CP nCp, const SwPostItField* pPostIt );
     void Append( WW8_CP nCp, const SwRedlineData* pRedLine );
     bool IsNewRedlineComment( const SwRedlineData* pRedLine );


More information about the Libreoffice-commits mailing list