From 1b922da415339726fb0186246dba6a03429b33bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jacobo=20Aragunde=20P=C3=A9rez?= Date: Sat, 22 Mar 2014 10:43:05 +0100 Subject: [PATCH] sw/qa: Code refactor. Change-Id: I552b5111901a2e1011a2bd0acaf0231dadd56614 --- sw/source/filter/ww8/docxsdrexport.cxx | 77 +++++++++++++------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/sw/source/filter/ww8/docxsdrexport.cxx b/sw/source/filter/ww8/docxsdrexport.cxx index c7e9970e5c23..4d755fc7fcde 100644 --- a/sw/source/filter/ww8/docxsdrexport.cxx +++ b/sw/source/filter/ww8/docxsdrexport.cxx @@ -50,29 +50,37 @@ using namespace oox; namespace { -OUString lclGetAnchorIdFromGrabBag(const SdrObject* pObj) +template +T lclGetProperty(uno::Reference rShape, OUString rPropName) { - OUString aResult; - uno::Reference xShape(const_cast(pObj)->getUnoShape(), uno::UNO_QUERY); - uno::Reference xPropertySet(xShape, uno::UNO_QUERY); + T aResult; + uno::Reference xPropertySet(rShape, uno::UNO_QUERY); uno::Reference xPropSetInfo; if (!xPropertySet.is()) return aResult; xPropSetInfo = xPropertySet->getPropertySetInfo(); - if (xPropSetInfo.is() && xPropSetInfo->hasPropertyByName("FrameInteropGrabBag")) + if (xPropSetInfo.is() && xPropSetInfo->hasPropertyByName(rPropName)) { - uno::Sequence< beans::PropertyValue > propList; - xPropertySet->getPropertyValue("FrameInteropGrabBag") >>= propList; - for (sal_Int32 nProp = 0; nProp < propList.getLength(); ++nProp) + xPropertySet->getPropertyValue(rPropName) >>= aResult; + } + return aResult; +} + +OUString lclGetAnchorIdFromGrabBag(const SdrObject* pObj) +{ + OUString aResult; + uno::Reference xShape(const_cast(pObj)->getUnoShape(), uno::UNO_QUERY); + uno::Sequence< beans::PropertyValue > propList = + lclGetProperty< uno::Sequence >(xShape, "FrameInteropGrabBag"); + for (sal_Int32 nProp = 0; nProp < propList.getLength(); ++nProp) + { + OUString aPropName = propList[nProp].Name; + if (aPropName == "AnchorId") { - OUString aPropName = propList[nProp].Name; - if (aPropName == "AnchorId") - { - propList[nProp].Value >>= aResult; - break; - } + propList[nProp].Value >>= aResult; + break; } } return aResult; @@ -555,31 +563,6 @@ void DocxSdrExport::writeDMLDrawing(const SdrObject* pSdrObject, const SwFrmFmt* pFS->singleElementNS(XML_wp, XML_docPr, xDocPrAttrListRef); uno::Reference xServiceInfo(xShape, uno::UNO_QUERY_THROW); - uno::Reference< beans::XPropertySet > xPropertySet(xShape, uno::UNO_QUERY); - uno::Reference< beans::XPropertySetInfo > xPropSetInfo; - if (xPropertySet.is()) - xPropSetInfo = xPropertySet->getPropertySetInfo(); - - bool bLockedCanvas = false; - if (xPropSetInfo.is() && xPropSetInfo->hasPropertyByName("InteropGrabBag")) - { - uno::Sequence< beans::PropertyValue > propList; - xPropertySet->getPropertyValue("InteropGrabBag") >>= propList; - for (sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp) - { - OUString propName = propList[nProp].Name; - if (propName == "LockedCanvas") - { - /* - * Export as Locked Canvas only if the drawing - * was originally a Locked Canvas and is now inside a Text Frame. - */ - - bLockedCanvas = m_pImpl->m_bIsInDMLTextFrame; - break; - } - } - } const char* pNamespace = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape"; if (xServiceInfo->supportsService("com.sun.star.drawing.GroupShape")) pNamespace = "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"; @@ -592,6 +575,22 @@ void DocxSdrExport::writeDMLDrawing(const SdrObject* pSdrObject, const SwFrmFmt* XML_uri, pNamespace, FSEND); + bool bLockedCanvas = false; + uno::Sequence< beans::PropertyValue > propList = + lclGetProperty< uno::Sequence >(xShape, "InteropGrabBag"); + for (sal_Int32 nProp=0; nProp < propList.getLength(); ++nProp) + { + OUString propName = propList[nProp].Name; + if (propName == "LockedCanvas") + { + /* + * Export as Locked Canvas only if the drawing + * was originally a Locked Canvas and is now inside a Text Frame. + */ + bLockedCanvas = m_pImpl->m_bIsInDMLTextFrame; + break; + } + } if (bLockedCanvas) pFS->startElementNS(XML_lc, XML_lockedCanvas, FSNS(XML_xmlns, XML_lc), "http://schemas.openxmlformats.org/drawingml/2006/lockedCanvas",