sw/qa/uitest/data/tdf138512.odt         |binary
 sw/qa/uitest/writer_tests7/tdf138512.py |   56 ++++++++++++++++++++++++++++++++
 sw/source/uibase/shells/drwbassh.cxx    |   38 +++++++++++++++++----
 3 files changed, 86 insertions(+), 8 deletions(-)

New commits:
commit 54302a574a98d6fc071472f1fa64adaf70864a26
Author:     Attila Bakos (NISZ) <bakos.attilakar...@nisz.hu>
AuthorDate: Wed Jan 20 10:52:26 2021 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Thu Feb 4 13:45:13 2021 +0100

    tdf#138512 sw: fix crash on textbox alignment
    
    Regression from 3347d71b23595919e167bd49932675e77cbbdbbb
    (sw: fix text position at textbox alignment) has been
    fixed by this commit. Hopefully there won't not be newer
    regressions.
    
    Please note the crash only occur on GTK vcl backend so,
    the py-test only with that case will show the problem.
    In the other case there were no crash.
    
    Change-Id: I3280547a6195e240e5b33e0d0931fb60d4d19fff
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/109669
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

diff --git a/sw/qa/uitest/data/tdf138512.odt b/sw/qa/uitest/data/tdf138512.odt
new file mode 100755
index 000000000000..e72fb8eb37d5
Binary files /dev/null and b/sw/qa/uitest/data/tdf138512.odt differ
diff --git a/sw/qa/uitest/writer_tests7/tdf138512.py 
b/sw/qa/uitest/writer_tests7/tdf138512.py
new file mode 100755
index 000000000000..5b0191051d85
--- /dev/null
+++ b/sw/qa/uitest/writer_tests7/tdf138512.py
@@ -0,0 +1,56 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from com.sun.star.text.TextContentAnchorType import  AS_CHARACTER
+import org.libreoffice.unotest
+import pathlib
+import time
+
+
+def get_url_for_data_file(file_name):
+    return 
pathlib.Path(org.libreoffice.unotest.makeCopyFromTDOC(file_name)).as_uri()
+
+class tdf138512(UITestCase):
+
+    def test_tdf138512(self):
+
+        # Open the bugdoc
+        self.ui_test.load_file(get_url_for_data_file("tdf138512.odt"))
+
+        xWriterDoc = self.xUITest.getTopFocusWindow()
+        xWriterEdit = xWriterDoc.getChild("writer_edit")
+        document = self.ui_test.get_component()
+
+        # Check that the anchortype is as_char
+        self.assertEqual( AS_CHARACTER, 
document.DrawPage.getByIndex(0).AnchorType)
+
+        # Select the textbox
+        self.xUITest.executeCommand(".uno:JumpToNextFrame")
+        self.xUITest.executeCommand(".uno:JumpToNextFrame")
+
+        # Align the shape to bottom
+        time.sleep(1)
+        self.xUITest.executeCommand(".uno:AlignDown")
+        time.sleep(1)
+
+        # Align the shape up
+        self.xUITest.executeCommand(".uno:AlignUp")
+        time.sleep(1)
+
+        # Deselect the shape
+        xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "TAB"}))
+        xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "ESC"}))
+
+        # Without the fix this will crash at this point with gtk vcl backend
+        time.sleep(1)
+        self.assertEqual( AS_CHARACTER, 
document.DrawPage.getByIndex(0).AnchorType)
+
+        self.ui_test.close_doc()
+
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/uibase/shells/drwbassh.cxx 
b/sw/source/uibase/shells/drwbassh.cxx
index f901f32cc15d..b73dccb6036d 100644
--- a/sw/source/uibase/shells/drwbassh.cxx
+++ b/sw/source/uibase/shells/drwbassh.cxx
@@ -443,8 +443,7 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq)
             if ( bAlignPossible )
             {
                 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
-                if (rMarkList.GetMarkCount() == 1
-                    && 
!SwTextBoxHelper::hasTextFrame(rMarkList.GetMark(0)->GetMarkedSdrObj()))
+                if (rMarkList.GetMarkCount() == 1)
                 {
                     sal_Int16 nHorizOrient = -1, nVertOrient = -1;
 
@@ -472,13 +471,16 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq)
                             break;
                     }
 
+                    SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
+                    SwFrameFormat* pFrameFormat = FindFrameFormat(pObj);
+                    SwFrameFormat* pTextBox
+                        = SwTextBoxHelper::getOtherTextBoxFormat(pFrameFormat, 
RES_DRAWFRMFMT);
+
                     if (nHorizOrient != -1)
                     {
                         pSh->StartAction();
-                        SdrObject* pObj = 
rMarkList.GetMark(0)->GetMarkedSdrObj();
-                        SwFrameFormat* pFrameFormat = FindFrameFormat( pObj );
                         SwFormatHoriOrient 
aHOrient(pFrameFormat->GetFormatAttr(RES_HORI_ORIENT));
-                        aHOrient.SetHoriOrient( nHorizOrient );
+                        aHOrient.SetHoriOrient(nHorizOrient);
                         pFrameFormat->SetFormatAttr(aHOrient);
                         pSh->EndAction();
                     }
@@ -486,14 +488,34 @@ void SwDrawBaseShell::Execute(SfxRequest const &rReq)
                     if (nVertOrient != -1)
                     {
                         pSh->StartAction();
-                        SdrObject* pObj = 
rMarkList.GetMark(0)->GetMarkedSdrObj();
-                        SwFrameFormat* pFrameFormat = FindFrameFormat( pObj );
                         SwFormatVertOrient 
aVOrient(pFrameFormat->GetFormatAttr(RES_VERT_ORIENT));
-                        aVOrient.SetVertOrient( nVertOrient );
+                        aVOrient.SetVertOrient(nVertOrient);
                         pFrameFormat->SetFormatAttr(aVOrient);
                         pSh->EndAction();
                     }
 
+                    if (pTextBox)
+                    {
+                        Point nShapePos(pFrameFormat->GetHoriOrient().GetPos(),
+                                        
pFrameFormat->GetVertOrient().GetPos());
+                        Point nOffset(
+                            SwTextBoxHelper::getTextRectangle(pFrameFormat, 
false).TopLeft());
+
+                        if (nHorizOrient != -1)
+                        {
+                            SwFormatHoriOrient 
aNewHOri(pTextBox->GetHoriOrient());
+                            aNewHOri.SetPos(nShapePos.X() + nOffset.X());
+                            pTextBox->SetFormatAttr(aNewHOri);
+                        }
+
+                        if (nVertOrient != -1)
+                        {
+                            SwFormatVertOrient 
aNewVOri(pTextBox->GetVertOrient());
+                            aNewVOri.SetPos(nShapePos.Y() + nOffset.Y());
+                            pTextBox->SetFormatAttr(aNewVOri);
+                        }
+                    }
+
                     break;
                 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to