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

Miklos Vajna vmiklos at collabora.co.uk
Thu May 29 05:44:14 PDT 2014


 sw/inc/textboxhelper.hxx             |    6 +--
 sw/source/core/doc/textboxhelper.cxx |   69 ++++++++++++++++++++++++-----------
 sw/source/core/unocore/unodraw.cxx   |    4 +-
 3 files changed, 54 insertions(+), 25 deletions(-)

New commits:
commit ac687b4d6a1b853ca5a70e2f06b705764d400bcc
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu May 29 14:28:40 2014 +0200

    SwTextBoxHelper: use UNO_NAME_* constants
    
    Change-Id: Ie2ce95f46c19fa6c693619242a65bccc442a7fe7

diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index a1a14dc..02980e3 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -18,8 +18,10 @@
 #include <unotextbodyhf.hxx>
 #include <unotextrange.hxx>
 #include <unomid.h>
+#include <unoprnms.hxx>
 #include <dflyobj.hxx>
 
+#include <editeng/unoprnms.hxx>
 #include <svx/svdoashp.hxx>
 #include <svx/unopage.hxx>
 #include <svx/svdpage.hxx>
@@ -47,14 +49,14 @@ void SwTextBoxHelper::create(SwFrmFmt* pShape)
         // Initialize properties.
         uno::Reference<beans::XPropertySet> xPropertySet(xTextFrame, uno::UNO_QUERY);
         uno::Any aEmptyBorder = uno::makeAny(table::BorderLine2());
-        xPropertySet->setPropertyValue("TopBorder", aEmptyBorder);
-        xPropertySet->setPropertyValue("BottomBorder", aEmptyBorder);
-        xPropertySet->setPropertyValue("LeftBorder", aEmptyBorder);
-        xPropertySet->setPropertyValue("RightBorder", aEmptyBorder);
+        xPropertySet->setPropertyValue(UNO_NAME_TOP_BORDER, aEmptyBorder);
+        xPropertySet->setPropertyValue(UNO_NAME_BOTTOM_BORDER, aEmptyBorder);
+        xPropertySet->setPropertyValue(UNO_NAME_LEFT_BORDER, aEmptyBorder);
+        xPropertySet->setPropertyValue(UNO_NAME_RIGHT_BORDER, aEmptyBorder);
 
-        xPropertySet->setPropertyValue("FillTransparence", uno::makeAny(sal_Int32(100)));
+        xPropertySet->setPropertyValue(UNO_NAME_FILL_TRANSPARENCE, uno::makeAny(sal_Int32(100)));
 
-        xPropertySet->setPropertyValue("SizeType", uno::makeAny(text::SizeType::FIX));
+        xPropertySet->setPropertyValue(UNO_NAME_SIZE_TYPE, uno::makeAny(text::SizeType::FIX));
 
         // Link its text range to the original shape.
         uno::Reference<text::XTextRange> xTextBox(xTextFrame, uno::UNO_QUERY_THROW);
@@ -72,12 +74,12 @@ void SwTextBoxHelper::create(SwFrmFmt* pShape)
         syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_SIZE, uno::makeAny(xShape->getSize()));
 
         uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY);
-        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_ORIENT, xShapePropertySet->getPropertyValue("HoriOrient"));
-        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_RELATION, xShapePropertySet->getPropertyValue("HoriOrientRelation"));
-        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_ORIENT, xShapePropertySet->getPropertyValue("VertOrient"));
-        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_RELATION, xShapePropertySet->getPropertyValue("VertOrientRelation"));
-        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_POSITION, xShapePropertySet->getPropertyValue("HoriOrientPosition"));
-        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_POSITION, xShapePropertySet->getPropertyValue("VertOrientPosition"));
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_ORIENT, xShapePropertySet->getPropertyValue(UNO_NAME_HORI_ORIENT));
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_RELATION, xShapePropertySet->getPropertyValue(UNO_NAME_HORI_ORIENT_RELATION));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_ORIENT, xShapePropertySet->getPropertyValue(UNO_NAME_VERT_ORIENT));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_RELATION, xShapePropertySet->getPropertyValue(UNO_NAME_VERT_ORIENT_RELATION));
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_POSITION, xShapePropertySet->getPropertyValue(UNO_NAME_HORI_ORIENT_POSITION));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_POSITION, xShapePropertySet->getPropertyValue(UNO_NAME_VERT_ORIENT_POSITION));
     }
 }
 
@@ -247,13 +249,13 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
             switch (nMemberId)
             {
             case MID_HORIORIENT_ORIENT:
-                aPropertyName = "HoriOrient";
+                aPropertyName = UNO_NAME_HORI_ORIENT;
                 break;
             case MID_HORIORIENT_RELATION:
-                aPropertyName = "HoriOrientRelation";
+                aPropertyName = UNO_NAME_HORI_ORIENT_RELATION;
                 break;
             case MID_HORIORIENT_POSITION:
-                aPropertyName = "HoriOrientPosition";
+                aPropertyName = UNO_NAME_HORI_ORIENT_POSITION;
                 bAdjustX = true;
                 break;
             }
@@ -262,19 +264,19 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
             switch (nMemberId)
             {
             case MID_VERTORIENT_ORIENT:
-                aPropertyName = "VertOrient";
+                aPropertyName = UNO_NAME_VERT_ORIENT;
                 break;
             case MID_VERTORIENT_RELATION:
-                aPropertyName = "VertOrientRelation";
+                aPropertyName = UNO_NAME_VERT_ORIENT_RELATION;
                 break;
             case MID_VERTORIENT_POSITION:
-                aPropertyName = "VertOrientPosition";
+                aPropertyName = UNO_NAME_VERT_ORIENT_POSITION;
                 bAdjustY = true;
                 break;
             }
             break;
         case RES_FRM_SIZE:
-            aPropertyName = "Size";
+            aPropertyName = UNO_NAME_SIZE;
             bAdjustSize = true;
             break;
         case RES_ANCHOR:
@@ -284,7 +286,7 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
                 if (aValue.get<text::TextContentAnchorType>() == text::TextContentAnchorType_AS_CHARACTER)
                 {
                     uno::Reference<beans::XPropertySet> xPropertySet(static_cast<cppu::OWeakObject*>(SwXFrames::GetObject(*pFmt, FLYCNTTYPE_FRM)), uno::UNO_QUERY);
-                    xPropertySet->setPropertyValue("Surround", uno::makeAny(text::WrapTextMode_THROUGHT));
+                    xPropertySet->setPropertyValue(UNO_NAME_SURROUND, uno::makeAny(text::WrapTextMode_THROUGHT));
                     return;
                 }
                 break;
commit 6823b19257c56ba6be2b102e91788f9ef86113ef
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu May 29 12:29:18 2014 +0200

    SwTextBoxHelper::syncProperty(): no need to pass the property name
    
    Change-Id: Ic2f6ae15fd81826d2bc6f8796e33c3c93b34e240

diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index cb0a643..5deb5f6 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -37,7 +37,7 @@ public:
     /// Get interface of a shape's TextBox, if there is any.
     static css::uno::Any queryInterface(SwFrmFmt* pShape, const css::uno::Type& rType);
     /// Sync property of TextBox with the one of the shape.
-    static void syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, const OUString& rPropertyName, const css::uno::Any& rValue);
+    static void syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, const css::uno::Any& rValue);
     /// If we have an associated TextFrame, then return that.
     static SwFrmFmt* findTextBox(SwFrmFmt* pShape);
     /// Return the textbox rectangle of a draw shape (in twips).
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index ad4bf62..a1a14dc 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -69,15 +69,15 @@ void SwTextBoxHelper::create(SwFrmFmt* pShape)
 
         // Also initialize the properties, which are not constant, but inherited from the shape's ones.
         uno::Reference<drawing::XShape> xShape(pShape->FindRealSdrObject()->getUnoShape(), uno::UNO_QUERY);
-        syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_SIZE, "Size", uno::makeAny(xShape->getSize()));
+        syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_SIZE, uno::makeAny(xShape->getSize()));
 
         uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY);
-        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_ORIENT, "HoriOrient", xShapePropertySet->getPropertyValue("HoriOrient"));
-        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_RELATION, "HoriOrientRelation", xShapePropertySet->getPropertyValue("HoriOrientRelation"));
-        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_ORIENT, "VertOrient", xShapePropertySet->getPropertyValue("VertOrient"));
-        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_RELATION, "VertOrientRelation", xShapePropertySet->getPropertyValue("VertOrientRelation"));
-        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_POSITION, "HoriOrientPosition", xShapePropertySet->getPropertyValue("HoriOrientPosition"));
-        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_POSITION, "VertOrientPosition", xShapePropertySet->getPropertyValue("VertOrientPosition"));
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_ORIENT, xShapePropertySet->getPropertyValue("HoriOrient"));
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_RELATION, xShapePropertySet->getPropertyValue("HoriOrientRelation"));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_ORIENT, xShapePropertySet->getPropertyValue("VertOrient"));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_RELATION, xShapePropertySet->getPropertyValue("VertOrientRelation"));
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_POSITION, xShapePropertySet->getPropertyValue("HoriOrientPosition"));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_POSITION, xShapePropertySet->getPropertyValue("VertOrientPosition"));
     }
 }
 
@@ -226,19 +226,18 @@ Rectangle SwTextBoxHelper::getTextRectangle(SwFrmFmt* pShape, bool bAbsolute)
     return aRet;
 }
 
-void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 nMemberId, const OUString& rPropertyName, const css::uno::Any& rValue)
+void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 nMemberId, const css::uno::Any& rValue)
 {
     // No shape yet? Then nothing to do, initial properties are set by create().
     if (!pShape)
         return;
 
-    OUString aPropertyName = rPropertyName;
     uno::Any aValue(rValue);
     nMemberId &= ~CONVERT_TWIPS;
 
     if (SwFrmFmt* pFmt = findTextBox(pShape))
     {
-        bool bSync = false;
+        OUString aPropertyName;
         bool bAdjustX = false;
         bool bAdjustY = false;
         bool bAdjustSize = false;
@@ -248,11 +247,13 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
             switch (nMemberId)
             {
             case MID_HORIORIENT_ORIENT:
+                aPropertyName = "HoriOrient";
+                break;
             case MID_HORIORIENT_RELATION:
-                bSync = true;
+                aPropertyName = "HoriOrientRelation";
                 break;
             case MID_HORIORIENT_POSITION:
-                bSync = true;
+                aPropertyName = "HoriOrientPosition";
                 bAdjustX = true;
                 break;
             }
@@ -261,17 +262,19 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
             switch (nMemberId)
             {
             case MID_VERTORIENT_ORIENT:
+                aPropertyName = "VertOrient";
+                break;
             case MID_VERTORIENT_RELATION:
-                bSync = true;
+                aPropertyName = "VertOrientRelation";
                 break;
             case MID_VERTORIENT_POSITION:
-                bSync = true;
+                aPropertyName = "VertOrientPosition";
                 bAdjustY = true;
                 break;
             }
             break;
         case RES_FRM_SIZE:
-            bSync = true;
+            aPropertyName = "Size";
             bAdjustSize = true;
             break;
         case RES_ANCHOR:
@@ -289,7 +292,7 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
             break;
         }
 
-        if (bSync)
+        if (!aPropertyName.isEmpty())
         {
             // Position/size should be the text position/size, not the shape one as-is.
             if (bAdjustX || bAdjustY || bAdjustSize)
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index 7c49f44..a81ff09 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -1353,7 +1353,7 @@ void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& a
                         pFmt->SetFmtAttr(aSet);
                 }
                 // We have a pFmt and a pEntry as well: try to sync TextBox property.
-                SwTextBoxHelper::syncProperty(pFmt, pEntry->nWID, pEntry->nMemberId, rPropertyName, aValue);
+                SwTextBoxHelper::syncProperty(pFmt, pEntry->nWID, pEntry->nMemberId, aValue);
             }
             else
             {
@@ -2343,7 +2343,7 @@ void SAL_CALL SwXShape::setSize( const awt::Size& aSize )
     {
         mxShape->setSize( aSize );
     }
-    SwTextBoxHelper::syncProperty(GetFrmFmt(), RES_FRM_SIZE, MID_FRMSIZE_SIZE, "Size", uno::makeAny(aSize));
+    SwTextBoxHelper::syncProperty(GetFrmFmt(), RES_FRM_SIZE, MID_FRMSIZE_SIZE, uno::makeAny(aSize));
 }
 // #i31698#
 // implementation of virtual methods from drawing::XShapeDescriptor
commit 3e266853608eb26fb15ac508ba78d74afb72f51c
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu May 29 12:15:28 2014 +0200

    SwTextBoxHelper::create(): initialize position
    
    The situation is a bit more complicated here,
    drawing::XCustomShapeEngine returns the text rectangle in absolute
    coordinates, but that's on the drawpage. So count the relative
    coordinates, and then just adjust the position we got from the original
    shape.
    
    Change-Id: Ibfbc183e5170037c8c281d61ce802a19a7acda17

diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx
index 747e729..cb0a643 100644
--- a/sw/inc/textboxhelper.hxx
+++ b/sw/inc/textboxhelper.hxx
@@ -40,8 +40,8 @@ public:
     static void syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8 nMemberID, const OUString& rPropertyName, const css::uno::Any& rValue);
     /// If we have an associated TextFrame, then return that.
     static SwFrmFmt* findTextBox(SwFrmFmt* pShape);
-    /// Return the textbox rectangle of a draw shape (absolute values, in twips).
-    static Rectangle getTextRectangle(SwFrmFmt* pShape);
+    /// Return the textbox rectangle of a draw shape (in twips).
+    static Rectangle getTextRectangle(SwFrmFmt* pShape, bool bAbsolute = true);
 
     /// Look up TextFrames in a document, which are in fact TextBoxes.
     static std::list<SwFrmFmt*> findTextBoxes(const SwDoc* pDoc);
diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 1e92c67..ad4bf62 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -70,6 +70,14 @@ void SwTextBoxHelper::create(SwFrmFmt* pShape)
         // Also initialize the properties, which are not constant, but inherited from the shape's ones.
         uno::Reference<drawing::XShape> xShape(pShape->FindRealSdrObject()->getUnoShape(), uno::UNO_QUERY);
         syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_SIZE, "Size", uno::makeAny(xShape->getSize()));
+
+        uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY);
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_ORIENT, "HoriOrient", xShapePropertySet->getPropertyValue("HoriOrient"));
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_RELATION, "HoriOrientRelation", xShapePropertySet->getPropertyValue("HoriOrientRelation"));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_ORIENT, "VertOrient", xShapePropertySet->getPropertyValue("VertOrient"));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_RELATION, "VertOrientRelation", xShapePropertySet->getPropertyValue("VertOrientRelation"));
+        syncProperty(pShape, RES_HORI_ORIENT, MID_HORIORIENT_POSITION, "HoriOrientPosition", xShapePropertySet->getPropertyValue("HoriOrientPosition"));
+        syncProperty(pShape, RES_VERT_ORIENT, MID_VERTORIENT_POSITION, "VertOrientPosition", xShapePropertySet->getPropertyValue("VertOrientPosition"));
     }
 }
 
@@ -196,13 +204,25 @@ uno::Any SwTextBoxHelper::queryInterface(SwFrmFmt* pShape, const uno::Type& rTyp
     return aRet;
 }
 
-Rectangle SwTextBoxHelper::getTextRectangle(SwFrmFmt* pShape)
+Rectangle SwTextBoxHelper::getTextRectangle(SwFrmFmt* pShape, bool bAbsolute)
 {
     Rectangle aRet;
     aRet.SetEmpty();
     SdrObjCustomShape* pCustomShape = dynamic_cast<SdrObjCustomShape*>(pShape->FindRealSdrObject());
     if (pCustomShape)
         pCustomShape->GetTextBounds(aRet);
+
+    if (!bAbsolute)
+    {
+        // Relative, so count the logic (reference) rectangle, see the EnhancedCustomShape2d ctor.
+        Point aPoint(pCustomShape->GetSnapRect().Center());
+        Size aSize(pCustomShape->GetLogicRect().GetSize());
+        aPoint.X() -= aSize.Width() / 2;
+        aPoint.Y() -= aSize.Height() / 2;
+        Rectangle aLogicRect(aPoint, aSize);
+        aRet.Move(-1 * aLogicRect.Left(), -1 * aLogicRect.Top());
+    }
+
     return aRet;
 }
 
@@ -274,7 +294,7 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
             // Position/size should be the text position/size, not the shape one as-is.
             if (bAdjustX || bAdjustY || bAdjustSize)
             {
-                Rectangle aRect = getTextRectangle(pShape);
+                Rectangle aRect = getTextRectangle(pShape, /*bAbsolute=*/false);
                 if (!aRect.IsEmpty())
                 {
                     if (bAdjustX || bAdjustY)
@@ -283,9 +303,9 @@ void SwTextBoxHelper::syncProperty(SwFrmFmt* pShape, sal_uInt16 nWID, sal_uInt8
                         if (aValue >>= nValue)
                         {
                             if (bAdjustX)
-                                nValue = TWIPS_TO_MM(aRect.getX());
+                                nValue += TWIPS_TO_MM(aRect.getX());
                             else if (bAdjustY)
-                                nValue = TWIPS_TO_MM(aRect.getY());
+                                nValue += TWIPS_TO_MM(aRect.getY());
                             aValue <<= nValue;
                         }
                     }
commit ad8aeb6e02444aa007ef38a59bbd84d67d60ffad
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu May 29 11:54:39 2014 +0200

    SwTextBoxHelper::create(): initialize size
    
    On import, syncProperty() takes care of this, but in case the user
    interactively adds a textbox, when we need to handle the size in
    create() as well.
    
    Change-Id: I9428a682dbf70550bdfd081900e8098aeb64d38f

diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx
index 7735de5..1e92c67 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -66,6 +66,10 @@ void SwTextBoxHelper::create(SwFrmFmt* pShape)
             aSet.Put(aCntnt);
             pShape->SetFmtAttr(aSet);
         }
+
+        // Also initialize the properties, which are not constant, but inherited from the shape's ones.
+        uno::Reference<drawing::XShape> xShape(pShape->FindRealSdrObject()->getUnoShape(), uno::UNO_QUERY);
+        syncProperty(pShape, RES_FRM_SIZE, MID_FRMSIZE_SIZE, "Size", uno::makeAny(xShape->getSize()));
     }
 }
 


More information about the Libreoffice-commits mailing list