diff --git a/sw/source/filter/ww8/wrtw8sty.cxx b/sw/source/filter/ww8/wrtw8sty.cxx --- a/sw/source/filter/ww8/wrtw8sty.cxx +++ b/sw/source/filter/ww8/wrtw8sty.cxx @@ -33,6 +33,8 @@ #include #include +#include + #include #include #include @@ -84,6 +86,16 @@ using namespace sw::util; using namespace nsHdFtFlags; +/// For the output of sections. +struct WW8_PdAttrDesc +{ + ::boost::scoped_array m_pData; + sal_uInt16 m_nLen; + WW8_FC m_nSepxFcPos; + WW8_PdAttrDesc() : m_nLen(0), m_nSepxFcPos(0xffffffff) /*default: none*/ + { } +}; + struct WW8_SED { SVBT16 aBits1; // orientation change + internal, Default: 6 @@ -948,10 +960,10 @@ MSWordSections::MSWordSections( MSWordEx } WW8_WrPlcSepx::WW8_WrPlcSepx( MSWordExportBase& rExport ) - : MSWordSections( rExport ), - aCps( 4, 4 ), - pAttrs( 0 ), - pTxtPos( 0 ) + : MSWordSections( rExport ) + , aCps( 4, 4 ) + , m_bHeaderFooterWritten(false) + , pTxtPos( 0 ) { // to be in sync with the AppendSection() call in the MSWordSections // constructor @@ -964,16 +976,19 @@ MSWordSections::~MSWordSections() WW8_WrPlcSepx::~WW8_WrPlcSepx() { - sal_uInt16 nLen = aSects.Count(); - if( pAttrs ) - { - while( nLen ) - delete[] pAttrs[ --nLen ].pData; - delete[] pAttrs; - } delete pTxtPos; } +bool MSWordSections::HeaderFooterWritten() +{ + return false; // only relevant for WW8 +} + +bool WW8_WrPlcSepx::HeaderFooterWritten() +{ + return m_bHeaderFooterWritten; +} + sal_uInt16 MSWordSections::CurrentNumberOfColumns( const SwDoc &rDoc ) const { ASSERT( aSects.Count(), "no segement inserted yet" ); @@ -1019,6 +1034,9 @@ const WW8_SepInfo* MSWordSections::Curre void MSWordSections::AppendSection( const SwPageDesc* pPd, const SwSectionFmt* pSectionFmt, sal_uLong nLnNumRestartNo ) { + if (HeaderFooterWritten()) { + return; // #i117955# prevent new sections in endnotes + } aSects.Insert( WW8_SepInfo( pPd, pSectionFmt, nLnNumRestartNo ), aSects.Count() ); NeedsDocumentProtected( aSects[aSects.Count()-1] ); @@ -1027,6 +1045,9 @@ void MSWordSections::AppendSection( cons void WW8_WrPlcSepx::AppendSep( WW8_CP nStartCp, const SwPageDesc* pPd, const SwSectionFmt* pSectionFmt, sal_uLong nLnNumRestartNo ) { + if (HeaderFooterWritten()) { + return; // #i117955# prevent new sections in endnotes + } aCps.Insert( nStartCp, aCps.Count() ); AppendSection( pPd, pSectionFmt, nLnNumRestartNo ); @@ -1035,6 +1056,9 @@ void WW8_WrPlcSepx::AppendSep( WW8_CP nS void MSWordSections::AppendSection( const SwFmtPageDesc& rPD, const SwNode& rNd, const SwSectionFmt* pSectionFmt, sal_uLong nLnNumRestartNo ) { + if (HeaderFooterWritten()) { + return; // #i117955# prevent new sections in endnotes + } WW8_SepInfo aI( rPD.GetPageDesc(), pSectionFmt, nLnNumRestartNo, rPD.GetNumOffset(), &rNd ); aSects.Insert( aI, aSects.Count() ); @@ -1044,6 +1068,9 @@ void MSWordSections::AppendSection( cons void WW8_WrPlcSepx::AppendSep( WW8_CP nStartCp, const SwFmtPageDesc& rPD, const SwNode& rNd, const SwSectionFmt* pSectionFmt, sal_uLong nLnNumRestartNo ) { + if (HeaderFooterWritten()) { + return; // #i117955# prevent new sections in endnotes + } aCps.Insert(nStartCp, aCps.Count()); AppendSection( rPD, rNd, pSectionFmt, nLnNumRestartNo ); @@ -1423,17 +1450,18 @@ void WW8Export::SetupSectionPositions( W if ( !pA ) return; - if ( pO->Count() ) - { // waren Attrs vorhanden ? - pA->nLen = pO->Count(); - pA->pData = new sal_uInt8 [pO->Count()]; - memcpy( pA->pData, pO->GetData(), pO->Count() ); // -> merken + if (pO->Count()) // are there attributes? + { + pA->m_nLen = pO->Count(); + pA->m_pData.reset(new sal_uInt8[pO->Count()]); + // store for later + memcpy( pA->m_pData.get(), pO->GetData(), pO->Count() ); pO->Remove( 0, pO->Count() ); // leeren fuer HdFt-Text } else - { // keine Attrs da - pA->pData = 0; - pA->nLen = 0; + { + pA->m_pData.reset(); + pA->m_nLen = 0; } } @@ -1711,7 +1739,6 @@ void MSWordExportBase::SectionProperties bool WW8_WrPlcSepx::WriteKFTxt( WW8Export& rWrt ) { - pAttrs = new WW8_PdAttrDesc[ aSects.Count() ]; sal_uLong nCpStart = rWrt.Fc2Cp( rWrt.Strm().Tell() ); ASSERT( !pTxtPos, "wer hat den Pointer gesetzt?" ); @@ -1722,15 +1749,17 @@ bool WW8_WrPlcSepx::WriteKFTxt( WW8Expor unsigned int nOldIndex = rWrt.GetHdFtIndex(); rWrt.SetHdFtIndex( 0 ); + // FIXME: this writes the section properties, but not of all sections; + // it's possible that later in the document (e.g. in endnotes) sections + // are added, but they won't have their properties written here! + m_bHeaderFooterWritten = true; for ( sal_uInt16 i = 0; i < aSects.Count(); ++i ) { - WW8_PdAttrDesc* pA = pAttrs + i; - pA->pData = 0; - pA->nLen = 0; - pA->nSepxFcPos = 0xffffffff; // Default: none + ::boost::shared_ptr const pAttrDesc(new WW8_PdAttrDesc); + m_SectionAttributes.push_back(pAttrDesc); WW8_SepInfo& rSepInfo = aSects[i]; - rWrt.SectionProperties( rSepInfo, pA ); + rWrt.SectionProperties( rSepInfo, pAttrDesc.get() ); } rWrt.SetHdFtIndex( nOldIndex ); //0 @@ -1758,17 +1787,16 @@ bool WW8_WrPlcSepx::WriteKFTxt( WW8Expor void WW8_WrPlcSepx::WriteSepx( SvStream& rStrm ) const { - sal_uInt16 i; - for( i = 0; i < aSects.Count(); i++ ) // ueber alle Sections + for (size_t i = 0; i < m_SectionAttributes.size(); i++) // all sections { - WW8_PdAttrDesc* pA = pAttrs + i; - if( pA->nLen && pA->pData != NULL) + WW8_PdAttrDesc *const pA = m_SectionAttributes[i].get(); + if (pA->m_nLen && pA->m_pData != NULL) { SVBT16 nL; - pA->nSepxFcPos = rStrm.Tell(); - ShortToSVBT16( pA->nLen, nL ); + pA->m_nSepxFcPos = rStrm.Tell(); + ShortToSVBT16( pA->m_nLen, nL ); rStrm.Write( nL, 2 ); - rStrm.Write( pA->pData, pA->nLen ); + rStrm.Write( pA->m_pData.get(), pA->m_nLen ); } } } @@ -1791,10 +1819,10 @@ void WW8_WrPlcSepx::WritePlcSed( WW8Expo static WW8_SED aSed = {{4, 0},{0, 0, 0, 0},{0, 0},{0xff, 0xff, 0xff, 0xff}}; // ( ueber alle Sections ) - for( i = 0; i < aSects.Count(); i++ ) + for (size_t j = 0; j < m_SectionAttributes.size(); j++ ) { - WW8_PdAttrDesc* pA = pAttrs + i; - UInt32ToSVBT32( pA->nSepxFcPos, aSed.fcSepx ); // Sepx-Pos + // Sepx-Pos + UInt32ToSVBT32( m_SectionAttributes[j]->m_nSepxFcPos, aSed.fcSepx ); rWrt.pTableStrm->Write( &aSed, sizeof( aSed ) ); } rWrt.pFib->fcPlcfsed = nFcStart; diff --git a/sw/source/filter/ww8/wrtww8.hxx b/sw/source/filter/ww8/wrtww8.hxx --- a/sw/source/filter/ww8/wrtww8.hxx +++ b/sw/source/filter/ww8/wrtww8.hxx @@ -199,6 +199,8 @@ public: MSWordSections( MSWordExportBase& rExport ); virtual ~MSWordSections(); + virtual bool HeaderFooterWritten(); + void AppendSection( const SwPageDesc* pPd, const SwSectionFmt* pSectionFmt = 0, sal_uLong nLnNumRestartNo = 0 ); @@ -231,7 +233,9 @@ public: class WW8_WrPlcSepx : public MSWordSections { SvULongs aCps; // PTRARR von CPs - WW8_PdAttrDesc* pAttrs; + ::std::vector< ::boost::shared_ptr > m_SectionAttributes; + // HACK to prevent adding sections in endnotes + bool m_bHeaderFooterWritten; WW8_WrPlc0* pTxtPos; // Pos der einzelnen Header / Footer // No copy, no assign @@ -242,6 +246,8 @@ public: WW8_WrPlcSepx( MSWordExportBase& rExport ); ~WW8_WrPlcSepx(); + virtual bool HeaderFooterWritten(); // override + void AppendSep( WW8_CP nStartCp, const SwPageDesc* pPd, const SwSectionFmt* pSectionFmt = 0, @@ -1490,14 +1496,6 @@ public: void setIPat(sal_uInt16 ipat) { m_ipat = ipat; } }; -/// For the output of sections. -struct WW8_PdAttrDesc -{ - sal_uInt8* pData; - sal_uInt16 nLen; - WW8_FC nSepxFcPos; -}; - #endif // _WRTWW8_HXX /* vi:set tabstop=4 shiftwidth=4 expandtab: */ diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -438,8 +438,8 @@ void MSWordExportBase::OutputSectionBrea bool bBreakSet = false; const SwPageDesc * pPageDesc = rNd.FindPageDesc(sal_False); - - if (pAktPageDesc != pPageDesc) + + if ((!Sections().HeaderFooterWritten()) && (pAktPageDesc != pPageDesc)) { bBreakSet = true; bNewPageDesc = true;