[Libreoffice-commits] core.git: sd/qa svx/source

Regina Henschel (via logerrit) logerrit at kemper.freedesktop.org
Tue Nov 12 10:17:29 UTC 2019


 sd/qa/unit/data/tdf128651_CustomShapeUndo.odp |binary
 sd/qa/unit/uiimpress.cxx                      |   39 ++++++++++++++++++++++++++
 svx/source/svdraw/svdundo.cxx                 |   14 ++++++++-
 3 files changed, 51 insertions(+), 2 deletions(-)

New commits:
commit 7cf0e43d39172cc083e7b64e06cf0730f14bcf19
Author:     Regina Henschel <rb.henschel at t-online.de>
AuthorDate: Sat Nov 9 23:46:22 2019 +0100
Commit:     Regina Henschel <rb.henschel at t-online.de>
CommitDate: Tue Nov 12 11:16:20 2019 +0100

    tdf#128651 SdrObjCustomShape::NbcSetSnapRect needs logic rect
    
    SdrObjCustomShape::NbcSetSnapRect needs a logic rect in its parameter.
    A general change to snap rect as input in NbcSetSnapRect is not
    possible, if the transformation has to be kept. Therefore callers
    need to be adapted. This is done her for SdrUndoAttrObj. The error
    was that for a transformed custom shape with text, undo and redo had
    generated a wrong size of the shape. A least the following actions
    were affected: extrusion on/off, shadow on/off, and changes in line
    or fill properties. The unit test uses extrusion on.
    
    Change-Id: I8b6990d3d57d25f15f18e8690fc49dbe5e2a2728
    Reviewed-on: https://gerrit.libreoffice.org/82367
    Tested-by: Jenkins
    Reviewed-by: Regina Henschel <rb.henschel at t-online.de>

diff --git a/sd/qa/unit/data/tdf128651_CustomShapeUndo.odp b/sd/qa/unit/data/tdf128651_CustomShapeUndo.odp
new file mode 100644
index 000000000000..9e820da094ab
Binary files /dev/null and b/sd/qa/unit/data/tdf128651_CustomShapeUndo.odp differ
diff --git a/sd/qa/unit/uiimpress.cxx b/sd/qa/unit/uiimpress.cxx
index 2125820c7c50..5923651c9db1 100644
--- a/sd/qa/unit/uiimpress.cxx
+++ b/sd/qa/unit/uiimpress.cxx
@@ -19,11 +19,14 @@
 #include <sfx2/viewfrm.hxx>
 #include <svl/intitem.hxx>
 #include <svx/svxids.hrc>
+#include <svx/svdoashp.hxx>
 #include <svl/stritem.hxx>
+#include <undo/undomanager.hxx>
 
 #include <DrawDocShell.hxx>
 #include <ViewShell.hxx>
 #include <app.hrc>
+#include <drawdoc.hxx>
 #include <sdpage.hxx>
 #include <unomodel.hxx>
 
@@ -151,6 +154,42 @@ CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf126197)
     // in SdrObjEditView::SdrEndTextEdit()
     pViewShell2->GetViewFrame()->GetDispatcher()->Execute(SID_DELETE, SfxCallMode::SYNCHRON);
 }
+
+CPPUNIT_TEST_FIXTURE(SdUiImpressTest, testTdf128651)
+{
+    // Error was, that undo and redo changes size of the shape. Affected actions were e.g.
+    // extrusion on/off, shadow on/off, changes on line or fill attributes.
+    // All these actions do not change the snap rectangle.
+    mxComponent = loadFromDesktop(
+        m_directories.getURLFromSrc("sd/qa/unit/data/tdf128651_CustomShapeUndo.odp"));
+    auto pXImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
+    sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+    SdPage* pActualPage = pViewShell->GetActualPage();
+    SdrObject* pObject = pActualPage->GetObj(0);
+    auto pCustomShape = dynamic_cast<SdrObjCustomShape*>(pObject);
+    CPPUNIT_ASSERT_MESSAGE("No Shape", pCustomShape);
+    const sal_Int32 nOrigWidth(pCustomShape->GetSnapRect().GetWidth());
+
+    SdDrawDocument* pDocument = pXImpressDocument->GetDoc();
+    sd::UndoManager* pUndoManager = pDocument->GetUndoManager();
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pUndoManager->GetUndoActionCount());
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(0), pUndoManager->GetRedoActionCount());
+
+    SdrView* pView = pViewShell->GetView();
+    pView->MarkObj(pCustomShape, pView->GetSdrPageView());
+    pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_EXTRUSION_TOGGLE,
+                                                         SfxCallMode::SYNCHRON);
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pUndoManager->GetUndoActionCount());
+
+    pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_UNDO, SfxCallMode::SYNCHRON);
+    const sal_Int32 nUndoWidth(pCustomShape->GetSnapRect().GetWidth());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Undo changes width", nOrigWidth, nUndoWidth);
+
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pUndoManager->GetRedoActionCount());
+    pViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_REDO, SfxCallMode::SYNCHRON);
+    const sal_Int32 nRedoWidth(pCustomShape->GetSnapRect().GetWidth());
+    CPPUNIT_ASSERT_EQUAL_MESSAGE("Redo changes width", nUndoWidth, nRedoWidth);
+}
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/svdraw/svdundo.cxx b/svx/source/svdraw/svdundo.cxx
index e27e6cf42c58..a29142a4a734 100644
--- a/svx/source/svdraw/svdundo.cxx
+++ b/svx/source/svdraw/svdundo.cxx
@@ -46,6 +46,7 @@
 #include <svx/svdotable.hxx> // #i124389#
 #include <vcl/svapp.hxx>
 #include <sfx2/viewsh.hxx>
+#include <svx/svdoashp.hxx>
 
 
 // iterates over all views and unmarks this SdrObject if it is marked
@@ -348,6 +349,8 @@ void SdrUndoAttrObj::Undo()
         // laid out again from AdjustTextFrameWidthAndHeight(). This makes
         // rescuing the size of the object necessary.
         const tools::Rectangle aSnapRect = pObj->GetSnapRect();
+        // SdrObjCustomShape::NbcSetSnapRect needs logic instead of snap rect
+        const tools::Rectangle aLogicRect = pObj->GetLogicRect();
 
         if(pUndoSet)
         {
@@ -382,7 +385,10 @@ void SdrUndoAttrObj::Undo()
         // Restore previous size here when it was changed.
         if(aSnapRect != pObj->GetSnapRect())
         {
-            pObj->NbcSetSnapRect(aSnapRect);
+            if(dynamic_cast<const SdrObjCustomShape*>(pObj))
+                pObj->NbcSetSnapRect(aLogicRect);
+            else
+                pObj->NbcSetSnapRect(aSnapRect);
         }
 
         pObj->GetProperties().BroadcastItemChange(aItemChange);
@@ -425,6 +431,7 @@ void SdrUndoAttrObj::Redo()
         sdr::properties::ItemChangeBroadcaster aItemChange(*pObj);
 
         const tools::Rectangle aSnapRect = pObj->GetSnapRect();
+        const tools::Rectangle aLogicRect = pObj->GetLogicRect();
 
         if(pRedoSet)
         {
@@ -459,7 +466,10 @@ void SdrUndoAttrObj::Redo()
         // Restore previous size here when it was changed.
         if(aSnapRect != pObj->GetSnapRect())
         {
-            pObj->NbcSetSnapRect(aSnapRect);
+            if(dynamic_cast<const SdrObjCustomShape*>(pObj))
+                pObj->NbcSetSnapRect(aLogicRect);
+            else
+                pObj->NbcSetSnapRect(aSnapRect);
         }
 
         pObj->GetProperties().BroadcastItemChange(aItemChange);


More information about the Libreoffice-commits mailing list