[Libreoffice-commits] core.git: sw/inc sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Jan 24 07:16:20 UTC 2019


 sw/inc/editsh.hxx                   |    3 +
 sw/qa/extras/uiwriter/uiwriter2.cxx |   55 ++++++++++++++++++++++++++++++++++++
 sw/source/core/edit/edatmisc.cxx    |   27 ++++++++++++++++-
 sw/source/uibase/shells/txtattr.cxx |    2 -
 4 files changed, 83 insertions(+), 4 deletions(-)

New commits:
commit d97fc64a819f834302e384792668507df4cc412c
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Wed Jan 23 11:27:01 2019 +0100
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Thu Jan 24 08:15:52 2019 +0100

    tdf#122893 track changes: keep paragraph alignment
    
    and preset line spaces applied in Show Changes mode, instead of
    losing them after saving the document or hiding the changes.
    
    The bug occurred in paragraphs with directly preceding tracked deletions.
    
    Change-Id: I33d9db8ee3522470c4f2dfdcfbea4060db8769a2
    Reviewed-on: https://gerrit.libreoffice.org/66789
    Reviewed-by: László Németh <nemeth at numbertext.org>
    Tested-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index fc804550f887..18b67e8cf0dd 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -230,7 +230,8 @@ public:
     bool GetCurAttr( SfxItemSet& ,
                      const bool bMergeIndentValuesOfNumRule = false ) const;
     void SetAttrItem( const SfxPoolItem&, SetAttrMode nFlags = SetAttrMode::DEFAULT );
-    void SetAttrSet( const SfxItemSet&, SetAttrMode nFlags = SetAttrMode::DEFAULT, SwPaM* pCursor = nullptr );
+    void SetAttrSet( const SfxItemSet&, SetAttrMode nFlags = SetAttrMode::DEFAULT,
+                     SwPaM* pCursor = nullptr, const bool bParagraphSetting = false );
 
     /** Get RES_CHRATR_* items of one type in the current selection.
      * @param nWhich WhichId of the collected items.
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 2f0242a6964c..c7d1ed25b446 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -10,6 +10,7 @@
 #include <swmodeltestbase.hxx>
 #include <com/sun/star/awt/FontSlant.hpp>
 #include <com/sun/star/frame/DispatchHelper.hpp>
+#include <com/sun/star/style/LineSpacing.hpp>
 #include <comphelper/propertysequence.hxx>
 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <svx/svdpage.hxx>
@@ -54,6 +55,7 @@ public:
     void testUnfloatButton();
     void testUnfloatButtonReadOnlyMode();
     void testUnfloating();
+    void testTdf122893();
 
     CPPUNIT_TEST_SUITE(SwUiWriterTest2);
     CPPUNIT_TEST(testRedlineMoveInsertInDelete);
@@ -71,6 +73,7 @@ public:
     CPPUNIT_TEST(testUnfloatButton);
     CPPUNIT_TEST(testUnfloatButtonReadOnlyMode);
     CPPUNIT_TEST(testUnfloating);
+    CPPUNIT_TEST(testTdf122893);
     CPPUNIT_TEST_SUITE_END();
 
 private:
@@ -683,6 +686,58 @@ void SwUiWriterTest2::testUnfloating()
         pWrtShell->GetLayout()->GetLower()->GetNext()->GetLower()->GetLower()->GetType());
 }
 
+void SwUiWriterTest2::testTdf122893()
+{
+    load(DATA_DIRECTORY, "tdf105413.fodt");
+
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+
+    // all paragraphs are left-aligned with preset single line spacing
+    for (int i = 1; i < 4; ++i)
+    {
+        CPPUNIT_ASSERT_EQUAL(sal_Int32(0), getProperty<sal_Int32>(getParagraph(i), "ParaAdjust"));
+        lcl_dispatchCommand(mxComponent, ".uno:SpacePara1", {});
+    }
+
+    // turn on red-lining and show changes
+    SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+    pDoc->getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::On | RedlineFlags::ShowInsert
+                                                      | RedlineFlags::ShowDelete);
+    CPPUNIT_ASSERT_MESSAGE("redlining should be on",
+                           pDoc->getIDocumentRedlineAccess().IsRedlineOn());
+    CPPUNIT_ASSERT_MESSAGE(
+        "redlines should be visible",
+        IDocumentRedlineAccess::IsShowChanges(pDoc->getIDocumentRedlineAccess().GetRedlineFlags()));
+
+    // Set center-aligned paragraph with preset double line spacing in the 3th paragraph.
+    // Because of the tracked deleted region between them,
+    // this sets also the same formatting in the first paragraph automatically
+    // to keep the changed paragraph formatting at hiding tracked changes or saving the document
+    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->Down(/*bSelect=*/false);
+    pWrtShell->Down(/*bSelect=*/false);
+    pWrtShell->EndPara(/*bSelect=*/false);
+
+    lcl_dispatchCommand(mxComponent, ".uno:CenterPara", {});
+    lcl_dispatchCommand(mxComponent, ".uno:SpacePara2", {});
+
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3),
+                         getProperty<sal_Int32>(getParagraph(3), "ParaAdjust")); // center-aligned
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(200),
+                         getProperty<style::LineSpacing>(getParagraph(3), "ParaLineSpacing")
+                             .Height); // double line spacing
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0),
+                         getProperty<sal_Int32>(getParagraph(2), "ParaAdjust")); // left-aligned
+    CPPUNIT_ASSERT_EQUAL(sal_Int16(100),
+                         getProperty<style::LineSpacing>(getParagraph(2), "ParaLineSpacing")
+                             .Height); // single line spacing
+    // first paragraph is also center-aligned with double line spacing
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getProperty<sal_Int32>(getParagraph(1), "ParaAdjust"));
+    CPPUNIT_ASSERT_EQUAL(
+        sal_Int16(200), getProperty<style::LineSpacing>(getParagraph(1), "ParaLineSpacing").Height);
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2);
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/edit/edatmisc.cxx b/sw/source/core/edit/edatmisc.cxx
index 7926800fdb63..5121d832daa7 100644
--- a/sw/source/core/edit/edatmisc.cxx
+++ b/sw/source/core/edit/edatmisc.cxx
@@ -20,6 +20,7 @@
 #include <editsh.hxx>
 #include <doc.hxx>
 #include <IDocumentUndoRedo.hxx>
+#include <IDocumentRedlineAccess.hxx>
 #include <pam.hxx>
 #include <edimp.hxx>
 #include <swundo.hxx>
@@ -95,6 +96,20 @@ const SfxPoolItem& SwEditShell::GetDefault( sal_uInt16 nFormatHint ) const
     return GetDoc()->GetDefault( nFormatHint );
 }
 
+// tdf#122893 turn off ShowChanges mode to apply paragraph formatting permanently with redlining
+// ie. in all directly preceding deleted paragraphs at the actual cursor positions
+static void lcl_disableShowChangesIfNeeded( SwDoc *const pDoc, const SwNode& rNode, RedlineFlags &eRedlMode )
+{
+    if ( IDocumentRedlineAccess::IsShowChanges(eRedlMode) &&
+        // is there redlining at beginning of the position (possible redline block before the modified node)
+        pDoc->getIDocumentRedlineAccess().GetRedlinePos( rNode, USHRT_MAX ) <
+                   pDoc->getIDocumentRedlineAccess().GetRedlineTable().size() )
+    {
+        eRedlMode = RedlineFlags::ShowInsert | RedlineFlags::Ignore;
+        pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eRedlMode );
+    }
+}
+
 void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, SetAttrMode nFlags )
 {
     SET_CURR_SHELL( this );
@@ -125,12 +140,12 @@ void SwEditShell::SetAttrItem( const SfxPoolItem& rHint, SetAttrMode nFlags )
     EndAllAction();
 }
 
-void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM* pPaM )
+void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM* pPaM, const bool bParagraphSetting )
 {
     SET_CURR_SHELL( this );
-
     SwPaM* pCursor = pPaM ? pPaM : GetCursor();
     StartAllAction();
+    RedlineFlags eRedlMode = GetDoc()->getIDocumentRedlineAccess().GetRedlineFlags(), eOldMode = eRedlMode;
     if( pCursor->GetNext() != pCursor )     // Ring of Cursors
     {
         bool bIsTableMode = IsTableMode();
@@ -141,6 +156,9 @@ void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM*
             if( rTmpCursor.HasMark() && ( bIsTableMode ||
                 *rTmpCursor.GetPoint() != *rTmpCursor.GetMark() ))
             {
+                if (bParagraphSetting)
+                    lcl_disableShowChangesIfNeeded( GetDoc(), (*rTmpCursor.Start()).nNode.GetNode(), eRedlMode);
+
                 GetDoc()->getIDocumentContentOperations().InsertItemSet(rTmpCursor, rSet, nFlags, GetLayout());
             }
         }
@@ -151,9 +169,14 @@ void SwEditShell::SetAttrSet( const SfxItemSet& rSet, SetAttrMode nFlags, SwPaM*
     {
         if( !HasSelection() )
             UpdateAttr();
+
+        if (bParagraphSetting)
+            lcl_disableShowChangesIfNeeded( GetDoc(), (*pCursor->Start()).nNode.GetNode(), eRedlMode);
+
         GetDoc()->getIDocumentContentOperations().InsertItemSet(*pCursor, rSet, nFlags, GetLayout());
     }
     EndAllAction();
+    GetDoc()->getIDocumentRedlineAccess().SetRedlineFlags( eOldMode );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/shells/txtattr.cxx b/sw/source/uibase/shells/txtattr.cxx
index 3832812c30c0..b2b989c50b0c 100644
--- a/sw/source/uibase/shells/txtattr.cxx
+++ b/sw/source/uibase/shells/txtattr.cxx
@@ -436,7 +436,7 @@ SET_LINESPACE:
         rWrtSh.AutoUpdatePara(pColl, aSet);
     }
     else
-        rWrtSh.SetAttrSet( aSet );
+        rWrtSh.SetAttrSet( aSet, SetAttrMode::DEFAULT, nullptr, true);
     rReq.Done();
 }
 


More information about the Libreoffice-commits mailing list