sw/source/core/doc/textboxhelper.cxx |   54 +++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

New commits:
commit 09df81f33b1ed286aa8c544a32a530d1fcf53adf
Author:     Attila Bakos (NISZ) <bakos.attilakar...@nisz.hu>
AuthorDate: Wed Oct 21 15:50:25 2020 +0200
Commit:     Gabor Kelemen <kelemen.gab...@nisz.hu>
CommitDate: Wed Apr 21 14:32:30 2021 +0200

    tdf#137798 sw: apply textbox Text alignment
    
    set in "Text" dialog window using "Text Anchor"
    in Format -> Text Box and Shape -> Text
    attributes... on the selected text box.
    
    Follow up of commit 726c911b90b9a3170fa6b3a34bb952a8d2dbe148
    (tdf#137025 sw: apply textbox padding set in Text).
    
    Change-Id: I8c575ceb1d0b0772c1f7d99dc746531b0cd7ceb4
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104632
    Tested-by: Jenkins
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    (cherry picked from commit 0b5801fc2c768d1774957c2c122c9061d3a74756)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114371
    Tested-by: Gabor Kelemen <kelemen.gab...@nisz.hu>
    Reviewed-by: Gabor Kelemen <kelemen.gab...@nisz.hu>

diff --git a/sw/source/core/doc/textboxhelper.cxx 
b/sw/source/core/doc/textboxhelper.cxx
index 43e77acd9fea..2fc1c1474ff6 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -47,6 +47,8 @@
 #include <com/sun/star/table/BorderLine2.hpp>
 #include <com/sun/star/text/WritingMode.hpp>
 #include <com/sun/star/text/WritingMode2.hpp>
+#include <com/sun/star/drawing/TextHorizontalAdjust.hpp>
+#include <com/sun/star/style/ParagraphAdjust.hpp>
 
 using namespace com::sun::star;
 
@@ -164,6 +166,8 @@ void SwTextBoxHelper::create(SwFrameFormat* pShape, bool 
bCopyText)
     if (xShapePropertySet->getPropertyValue(UNO_NAME_TEXT_WRITINGMODE) >>= 
eMode)
         syncProperty(pShape, RES_FRAMEDIR, 0, uno::makeAny(sal_Int16(eMode)));
 
+    // TODO: Text dialog attr setting to frame
+
     const SwFormatAnchor& rAnch = pShape->GetAnchor();
     if ((rAnch.GetAnchorId() == RndStdIds::FLY_AT_PAGE && rAnch.GetPageNum() 
!= 0)
         || ((rAnch.GetAnchorId() == RndStdIds::FLY_AT_PARA
@@ -429,6 +433,45 @@ tools::Rectangle 
SwTextBoxHelper::getTextRectangle(SwFrameFormat* pShape, bool b
 void SwTextBoxHelper::syncProperty(SwFrameFormat* pShape, const OUString& 
rPropertyName,
                                    const css::uno::Any& rValue)
 {
+    // Textframes does not have valid horizontal adjust property, so map it to 
paragraph adjust property
+    if (rPropertyName == UNO_NAME_TEXT_HORZADJUST)
+    {
+        SwFrameFormat* pFormat = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT);
+        if (!pFormat)
+            return;
+
+        auto xTextFrame = SwXTextFrame::CreateXTextFrame(*pFormat->GetDoc(), 
pFormat);
+        uno::Reference<text::XTextCursor> xCursor = 
xTextFrame->getText()->createTextCursor();
+
+        // Select all paragraps in the textframe
+        xCursor->gotoStart(false);
+        xCursor->gotoEnd(true);
+        uno::Reference<beans::XPropertySet> xFrameParaProps(xCursor, 
uno::UNO_QUERY);
+
+        // And simply map the property
+        switch (rValue.get<drawing::TextHorizontalAdjust>())
+        {
+            case drawing::TextHorizontalAdjust::TextHorizontalAdjust_CENTER:
+                xFrameParaProps->setPropertyValue(
+                    UNO_NAME_PARA_ADJUST,
+                    
uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_CENTER)); //3
+                break;
+            case drawing::TextHorizontalAdjust::TextHorizontalAdjust_LEFT:
+                xFrameParaProps->setPropertyValue(
+                    UNO_NAME_PARA_ADJUST,
+                    
uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_LEFT)); //0
+                break;
+            case drawing::TextHorizontalAdjust::TextHorizontalAdjust_RIGHT:
+                xFrameParaProps->setPropertyValue(
+                    UNO_NAME_PARA_ADJUST,
+                    
uno::makeAny(style::ParagraphAdjust::ParagraphAdjust_RIGHT)); //1
+                break;
+            default:
+                break;
+        }
+        return;
+    }
+
     if (rPropertyName == "CustomShapeGeometry")
     {
         // CustomShapeGeometry changes the textbox position offset and size, 
so adjust both.
@@ -870,6 +913,7 @@ void SwTextBoxHelper::updateTextBoxMargin(SdrObject* pObj)
     if (!pParentFormat)
         return;
 
+    // Sync the padding
     syncProperty(pParentFormat, UNO_NAME_TEXT_LEFTDIST,
                  xPropertySet->getPropertyValue(UNO_NAME_TEXT_LEFTDIST));
     syncProperty(pParentFormat, UNO_NAME_TEXT_RIGHTDIST,
@@ -878,6 +922,16 @@ void SwTextBoxHelper::updateTextBoxMargin(SdrObject* pObj)
                  xPropertySet->getPropertyValue(UNO_NAME_TEXT_UPPERDIST));
     syncProperty(pParentFormat, UNO_NAME_TEXT_LOWERDIST,
                  xPropertySet->getPropertyValue(UNO_NAME_TEXT_LOWERDIST));
+
+    // Sync the text aligning
+    syncProperty(pParentFormat, UNO_NAME_TEXT_VERTADJUST,
+                 xPropertySet->getPropertyValue(UNO_NAME_TEXT_VERTADJUST));
+    syncProperty(pParentFormat, UNO_NAME_TEXT_HORZADJUST,
+                 xPropertySet->getPropertyValue(UNO_NAME_TEXT_HORZADJUST));
+
+    //FIXME: Sync autogrow: needs repositioning after sync
+    //syncProperty(pParentFormat, RES_FRM_SIZE, MID_FRMSIZE_IS_AUTO_HEIGHT,
+    //             
xPropertySet->getPropertyValue(UNO_NAME_TEXT_AUTOGROWHEIGHT));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to