Kaydet (Commit) 9cf13c9f authored tarafından Miklos Vajna's avatar Miklos Vajna

sw classification: don't insert multiple watermark objects in header

If the text is different, remove the old shape and then insert the new
one. Otherwise just don't insert a new (identical) shape.

Delete and insert is needed because the shape size depends on its
textural content.

Change-Id: I0c8faa0e3e69416ea0b89fa33155826bc2dc7a4f
üst bff9f2d4
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <editsh.hxx> #include <editsh.hxx>
#include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XEnumerationAccess.hpp>
#include <com/sun/star/container/XContentEnumerationAccess.hpp>
#include <com/sun/star/document/XActionLockable.hpp> #include <com/sun/star/document/XActionLockable.hpp>
#include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/drawing/FillStyle.hpp>
#include <com/sun/star/drawing/HomogenMatrix3.hpp> #include <com/sun/star/drawing/HomogenMatrix3.hpp>
...@@ -112,6 +113,47 @@ bool lcl_hasField(const uno::Reference<text::XText>& xText, const OUString& rSer ...@@ -112,6 +113,47 @@ bool lcl_hasField(const uno::Reference<text::XText>& xText, const OUString& rSer
return false; return false;
} }
/// Search for a frame named rShapeName of type rServiceName in xText.
uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XText>& xText, const OUString& rServiceName, const OUString& rShapeName)
{
uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration();
while (xParagraphs->hasMoreElements())
{
uno::Reference<container::XEnumerationAccess> xTextPortionEnumerationAccess(xParagraphs->nextElement(), uno::UNO_QUERY);
uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration();
while (xTextPortions->hasMoreElements())
{
uno::Reference<beans::XPropertySet> xTextPortion(xTextPortions->nextElement(), uno::UNO_QUERY);
OUString aTextPortionType;
xTextPortion->getPropertyValue(UNO_NAME_TEXT_PORTION_TYPE) >>= aTextPortionType;
if (aTextPortionType != "Frame")
continue;
uno::Reference<container::XContentEnumerationAccess> xContentEnumerationAccess(xTextPortion, uno::UNO_QUERY);
if (!xContentEnumerationAccess.is())
continue;
uno::Reference<container::XEnumeration> xEnumeration = xContentEnumerationAccess->createContentEnumeration("com.sun.star.text.TextContent");
if (!xEnumeration->hasMoreElements())
continue;
uno::Reference<lang::XServiceInfo> xWatermark(xEnumeration->nextElement(), uno::UNO_QUERY);
if (!xWatermark->supportsService(rServiceName))
continue;
uno::Reference<container::XNamed> xNamed(xWatermark, uno::UNO_QUERY);
if (xNamed->getName() != rShapeName)
continue;
uno::Reference<drawing::XShape> xShape(xWatermark, uno::UNO_QUERY);
return xShape;
}
}
return uno::Reference<drawing::XShape>();
}
} // anonymous namespace } // anonymous namespace
SwTextFormatColl& SwEditShell::GetDfltTextFormatColl() const SwTextFormatColl& SwEditShell::GetDfltTextFormatColl() const
...@@ -183,6 +225,24 @@ void SwEditShell::SetClassification(const OUString& rName) ...@@ -183,6 +225,24 @@ void SwEditShell::SetClassification(const OUString& rName)
} }
if (!aWatermark.isEmpty()) if (!aWatermark.isEmpty())
{
OUString aShapeServiceName = "com.sun.star.drawing.CustomShape";
uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, SfxClassificationHelper::PROP_DOCWATERMARK());
if (xWatermark.is())
{
// If the header already contains a watermark, see if it its text is up to date.
uno::Reference<text::XTextRange> xTextRange(xWatermark, uno::UNO_QUERY);
if (xTextRange->getString() != aWatermark)
{
// No: delete it and we'll insert a replacement.
uno::Reference<lang::XComponent> xComponent(xWatermark, uno::UNO_QUERY);
xComponent->dispose();
xWatermark.clear();
}
}
if (!xWatermark.is())
{ {
// Calc the ratio. // Calc the ratio.
double fRatio = 0; double fRatio = 0;
...@@ -216,7 +276,7 @@ void SwEditShell::SetClassification(const OUString& rName) ...@@ -216,7 +276,7 @@ void SwEditShell::SetClassification(const OUString& rName)
sal_Int32 nHeight = nWidth * fRatio; sal_Int32 nHeight = nWidth * fRatio;
// Create and insert the shape. // Create and insert the shape.
uno::Reference<drawing::XShape> xShape(xMultiServiceFactory->createInstance("com.sun.star.drawing.CustomShape"), uno::UNO_QUERY); uno::Reference<drawing::XShape> xShape(xMultiServiceFactory->createInstance(aShapeServiceName), uno::UNO_QUERY);
basegfx::B2DHomMatrix aTransformation; basegfx::B2DHomMatrix aTransformation;
aTransformation.identity(); aTransformation.identity();
aTransformation.scale(nWidth, nHeight); aTransformation.scale(nWidth, nHeight);
...@@ -283,6 +343,7 @@ void SwEditShell::SetClassification(const OUString& rName) ...@@ -283,6 +343,7 @@ void SwEditShell::SetClassification(const OUString& rName)
xLockable->removeActionLock(); xLockable->removeActionLock();
} }
} }
}
if (bFooterIsNeeded) if (bFooterIsNeeded)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment