diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2017-12-08 22:15:21 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2017-12-09 13:20:09 +0100 |
commit | 0622e5db4e330de000f1318540c85e3223f45b40 (patch) | |
tree | dbf95e16093837829fef2b2e46dddc1c1e87b4f1 /sw/source | |
parent | e0920fb441e5747e683af3a5748b893e4778b9f9 (diff) |
tdf#114338 don't crash on watermark insert w/ existing header
Change-Id: I63abaf48c33d6660f1829b7d503de295e4a57f9c
Reviewed-on: https://gerrit.libreoffice.org/46126
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
(cherry picked from commit d4a54ec92674773bc0f9358a3d9090915a3c8fb0)
Reviewed-on: https://gerrit.libreoffice.org/46140
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/core/edit/edfcol.cxx | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index 60bba7d3c3d7..d679a4105acd 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -169,8 +169,10 @@ bool lcl_hasField(const uno::Reference<text::XText>& xText, const OUString& rSer } /// Search for a frame with WATERMARK_NAME in name of type rServiceName in xText. Returns found name in rShapeName. -uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XText>& xText, const OUString& rServiceName, OUString& rShapeName) +uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XText>& xText, + const OUString& rServiceName, OUString& rShapeName, bool& bSuccess) { + bSuccess = false; uno::Reference<container::XEnumerationAccess> xParagraphEnumerationAccess(xText, uno::UNO_QUERY); uno::Reference<container::XEnumeration> xParagraphs = xParagraphEnumerationAccess->createEnumeration(); while (xParagraphs->hasMoreElements()) @@ -179,6 +181,8 @@ uno::Reference<drawing::XShape> lcl_getWatermark(const uno::Reference<text::XTex if (!xTextPortionEnumerationAccess.is()) continue; + bSuccess = true; + uno::Reference<container::XEnumeration> xTextPortions = xTextPortionEnumerationAccess->createEnumeration(); while (xTextPortions->hasMoreElements()) { @@ -1382,7 +1386,8 @@ SfxWatermarkItem SwEditShell::GetWatermark() OUString aShapeServiceName = "com.sun.star.drawing.CustomShape"; OUString sWatermark = ""; - uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark); + bool bSuccess = false; + uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark, bSuccess); if (xWatermark.is()) { @@ -1416,10 +1421,14 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, const uno::Reference<beans::XPropertySet>& xPageStyle, const uno::Reference<text::XText>& xHeaderText) { + if (!xHeaderText.is()) + return; + uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xModel, uno::UNO_QUERY); OUString aShapeServiceName = "com.sun.star.drawing.CustomShape"; OUString sWatermark = WATERMARK_NAME; - uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark); + bool bSuccess = false; + uno::Reference<drawing::XShape> xWatermark = lcl_getWatermark(xHeaderText, aShapeServiceName, sWatermark, bSuccess); bool bDeleteWatermark = rWatermark.GetText().isEmpty(); if (xWatermark.is()) @@ -1453,7 +1462,7 @@ void lcl_placeWatermarkInHeader(const SfxWatermarkItem& rWatermark, } } - if (xWatermark.is() || bDeleteWatermark) + if (!bSuccess || xWatermark.is() || bDeleteWatermark) return; OUString sFont = rWatermark.GetFont(); |