From 9acd707d738b99072cb3d7323e94ef96c1d64be5 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 20 Aug 2014 13:56:35 +0100 Subject: fix crashing on exit in static SvxBrushItem dtor site of second ctor Change-Id: Ic319bd36f207a0f1939482a7b4c729b519bb5ce1 --- sw/inc/format.hxx | 2 ++ sw/source/core/attr/format.cxx | 31 +++++++++++++++++++++++++++++-- sw/source/filter/ww8/docxexport.cxx | 21 ++++++++++----------- sw/source/filter/ww8/docxexport.hxx | 2 +- 4 files changed, 42 insertions(+), 14 deletions(-) (limited to 'sw') diff --git a/sw/inc/format.hxx b/sw/inc/format.hxx index 8c3e69e9c5fc..9a52566a5769 100644 --- a/sw/inc/format.hxx +++ b/sw/inc/format.hxx @@ -98,6 +98,8 @@ public: //UUUUinline SfxItemState GetItemState( sal_uInt16 nWhich, bool bSrchInParent = true, const SfxPoolItem **ppItem = 0 ) const; + SfxItemState GetBackgroundState(SvxBrushItem &rItem, + bool bSrchInParent = true) const; virtual bool SetFmtAttr( const SfxPoolItem& rAttr ); virtual bool SetFmtAttr( const SfxItemSet& rSet ); virtual bool ResetFmtAttr( sal_uInt16 nWhich1, sal_uInt16 nWhich2 = 0 ); diff --git a/sw/source/core/attr/format.cxx b/sw/source/core/attr/format.cxx index 59ea2f3bafeb..180b19ef858d 100644 --- a/sw/source/core/attr/format.cxx +++ b/sw/source/core/attr/format.cxx @@ -409,13 +409,12 @@ const SfxPoolItem& SwFmt::GetFmtAttr( sal_uInt16 nWhich, bool bInParents ) const return aSet.Get( nWhich, bInParents ); } - SfxItemState SwFmt::GetItemState( sal_uInt16 nWhich, bool bSrchInParent, const SfxPoolItem **ppItem ) const { if(RES_BACKGROUND == nWhich && (RES_FLYFRMFMT == Which() || RES_FRMFMT == Which())) { //UUUU FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] - SAL_INFO("sw.core", "Do no longer use SvxBrushItem, instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] FillAttributes (simple fallback is in place and used)"); + SAL_INFO("sw.core", "Do no longer use SvxBrushItem, instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] FillAttributes or SwFmt::GetBackgroundStat (simple fallback is in place and used)"); const drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFill = getSdrAllFillAttributesHelper(); // check if the new fill attributes are used @@ -424,6 +423,7 @@ SfxItemState SwFmt::GetItemState( sal_uInt16 nWhich, bool bSrchInParent, const S // if yes, fill the local SvxBrushItem using the new fill attributes // as good as possible to have an instance for the pointer to point // to and return as state that it is set + static SvxBrushItem aSvxBrushItem(RES_BACKGROUND); aSvxBrushItem = getSvxBrushItemFromSourceSet(aSet, RES_BACKGROUND, bSrchInParent); @@ -444,6 +444,33 @@ SfxItemState SwFmt::GetItemState( sal_uInt16 nWhich, bool bSrchInParent, const S return aSet.GetItemState( nWhich, bSrchInParent, ppItem ); } +SfxItemState SwFmt::GetBackgroundState(SvxBrushItem &rItem, bool bSrchInParent) const +{ + if (RES_FLYFRMFMT == Which() || RES_FRMFMT == Which()) + { + //UUUU FALLBACKBREAKHERE should not be used; instead use [XATTR_FILL_FIRST .. XATTR_FILL_LAST] + const drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFill = getSdrAllFillAttributesHelper(); + + // check if the new fill attributes are used + if(aFill.get() && aFill->isUsed()) + { + // if yes, fill the local SvxBrushItem using the new fill attributes + // as good as possible to have an instance for the pointer to point + // to and return as state that it is set + rItem = getSvxBrushItemFromSourceSet(aSet, RES_BACKGROUND, bSrchInParent); + return SFX_ITEM_SET; + } + + // if not return SFX_ITEM_DEFAULT to signal that the item is not set + return SFX_ITEM_DEFAULT; + } + + const SfxPoolItem* pItem = 0; + SfxItemState eRet = aSet.GetItemState(RES_BACKGROUND, bSrchInParent, &pItem); + if (pItem) + rItem = *(const SvxBrushItem*)pItem; + return eRet; +} bool SwFmt::SetFmtAttr( const SfxPoolItem& rAttr ) { diff --git a/sw/source/filter/ww8/docxexport.cxx b/sw/source/filter/ww8/docxexport.cxx index 7f8ef58c3209..065368dd01ec 100644 --- a/sw/source/filter/ww8/docxexport.cxx +++ b/sw/source/filter/ww8/docxexport.cxx @@ -821,7 +821,7 @@ void DocxExport::WriteSettings() } // Display Background Shape - if (boost::optional oBrush = getBackground()) + if (boost::optional oBrush = getBackground()) { // Turn on the 'displayBackgroundShape' pFS->singleElementNS( XML_w, XML_displayBackgroundShape, FSEND ); @@ -1280,19 +1280,18 @@ bool DocxExport::isMirroredMargin() return bMirroredMargins; } -boost::optional DocxExport::getBackground() +boost::optional DocxExport::getBackground() { - boost::optional oRet; + boost::optional oRet; const SwFrmFmt &rFmt = pDoc->GetPageDesc(0).GetMaster(); - const SfxPoolItem* pItem = 0; - SfxItemState eState = rFmt.GetItemState(RES_BACKGROUND, true, &pItem); + SvxBrushItem aBrush(RES_BACKGROUND); + SfxItemState eState = rFmt.GetBackgroundState(aBrush); - if (SFX_ITEM_SET == eState && pItem) + if (SFX_ITEM_SET == eState) { // The 'color' is set for the first page style - take it and use it as the background color of the entire DOCX - const SvxBrushItem* pBrush = (const SvxBrushItem*)pItem; - if (pBrush->GetColor().GetColor() != COL_AUTO) - oRet.reset(pBrush); + if (aBrush.GetColor().GetColor() != COL_AUTO) + oRet.reset(aBrush); } return oRet; } @@ -1303,9 +1302,9 @@ void DocxExport::WriteMainText() m_pDocumentFS->startElementNS( XML_w, XML_document, MainXmlNamespaces( m_pDocumentFS )); // Write background page color - if (boost::optional oBrush = getBackground()) + if (boost::optional oBrush = getBackground()) { - Color backgroundColor = (*oBrush)->GetColor(); + Color backgroundColor = oBrush->GetColor(); OString aBackgroundColorStr = msfilter::util::ConvertColor(backgroundColor); m_pDocumentFS->singleElementNS( XML_w, XML_background, FSNS( XML_w, XML_color ), aBackgroundColorStr, FSEND ); diff --git a/sw/source/filter/ww8/docxexport.hxx b/sw/source/filter/ww8/docxexport.hxx index 3cda882cad62..3c4e708478c5 100644 --- a/sw/source/filter/ww8/docxexport.hxx +++ b/sw/source/filter/ww8/docxexport.hxx @@ -252,7 +252,7 @@ private: void WriteEmbeddings(); /// Get background color of the document, if there is one. - boost::optional getBackground(); + boost::optional getBackground(); /// return true if Page Layout is set as Mirrored bool isMirroredMargin(); -- cgit