sw/source/core/txtnode/ndtxt.cxx | 443 +++++++++++++-------------------------- 1 file changed, 150 insertions(+), 293 deletions(-)
New commits: commit 54a6e4841cd4b62faca090df8a7c4f2a1bf24b44 Author: Michael Stahl <[email protected]> Date: Mon Jun 1 15:12:09 2015 +0200 sw: SwTxtNode::CutImpl(): destination must be different node Remove more dead code.: Change-Id: I9572228be0e5393351a7d22eb23e1f188423a219 diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index b7b1c71..3087212 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -2036,6 +2036,8 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwIndex & rDestStart, assert(GetDoc() == pDest->GetDoc()); // must be same document + assert(pDest != this); // destination must be different node + if( !nLen ) { // wurde keine Laenge angegeben, dann Kopiere die Attribute @@ -2048,306 +2050,189 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwIndex & rDestStart, sal_Int32 nDestStart = rDestStart.GetIndex(); // alte Pos merken const sal_Int32 nInitSize = pDest->m_Text.getLength(); - // wird in sich selbst verschoben, muss es gesondert behandelt werden !! - if( pDest == this ) - { - OSL_FAIL("mst: entering dead and bitrotted code; fasten your seatbelts!"); - assert(false); - OUStringBuffer buf(m_Text); - buf.insert(nDestStart, m_Text.copy(nTextStartIdx, nLen)); - buf.remove( - nTextStartIdx + ((nDestStart < nTextStartIdx) ? nLen : 0), nLen); - m_Text = buf.makeStringAndClear(); - - const sal_Int32 nEnd = rStart.GetIndex() + nLen; - - // dann suche mal alle Attribute zusammen, die im verschobenen - // Bereich liegen. Diese werden in das extra Array verschoben, - // damit sich die Indizies beim Updaten nicht veraendern !!! - SwpHts aArr; - - // 2. Attribute verschieben - // durch das Attribute-Array, bis der Anfang des Geltungsbereiches - // des Attributs hinter dem zu verschiebenden Bereich liegt - size_t nAttrCnt = 0; - while ( m_pSwpHints && nAttrCnt < m_pSwpHints->Count() ) - { - SwTextAttr * const pHt = m_pSwpHints->GetTextHint(nAttrCnt); - const sal_Int32 nAttrStartIdx = pHt->GetStart(); - if (!( nAttrStartIdx < nEnd )) - break; - const sal_Int32 * const pEndIdx = pHt->GetEnd(); - const sal_uInt16 nWhich = pHt->Which(); - SwTextAttr *pNewHt = 0; - - if(nAttrStartIdx < nTextStartIdx) - { - // Anfang liegt vor dem Bereich - if ( RES_TXTATR_REFMARK != nWhich && !pHt->HasDummyChar() && - pEndIdx && *pEndIdx > nTextStartIdx ) - { - // Attribut mit einem Bereich - // und das Ende des Attribut liegt im Bereich - pNewHt = MakeTextAttr( *GetDoc(), pHt->GetAttr(), 0, - *pEndIdx > nEnd - ? nLen - : *pEndIdx - nTextStartIdx ); - } - } - else - { - // der Anfang liegt vollstaendig im Bereich - if( !pEndIdx || *pEndIdx < nEnd ) - { - // Attribut verschieben - m_pSwpHints->Delete( pHt ); - // die Start/End Indicies neu setzen - pHt->GetStart() = nAttrStartIdx - nTextStartIdx; - if( pEndIdx ) - *pHt->GetEnd() = *pEndIdx - nTextStartIdx; - aArr.push_back( pHt ); - continue; // while-Schleife weiter, ohne ++ ! - } - // das Ende liegt dahinter - else if (RES_TXTATR_REFMARK != nWhich && !pHt->HasDummyChar()) - { - pNewHt = MakeTextAttr( *GetDoc(), - pHt->GetAttr(), - nAttrStartIdx - nTextStartIdx, - ( *pEndIdx > nEnd - ? nLen - : *pEndIdx - nTextStartIdx )); - } - } - if( pNewHt ) - { - // die Daten kopieren - lcl_CopyHint( nWhich, pHt, pNewHt, 0, this ); - aArr.push_back( pNewHt ); - } - ++nAttrCnt; - } - - if( bUpdate ) - { - // Update aller Indizies - Update( rDestStart, nLen, false, true ); - } + pDest->m_Text = pDest->m_Text.replaceAt(nDestStart, 0, + m_Text.copy(nTextStartIdx, nLen)); + m_Text = m_Text.replaceAt(nTextStartIdx, nLen, ""); + if (GetSpaceLeft() < 0) + { // FIXME: could only happen when called from SwRangeRedline::Show. + // unfortunately can't really do anything here to handle that... + abort(); + } + nLen = pDest->m_Text.getLength() - nInitSize; // update w/ current size! + if (!nLen) // String nicht gewachsen ?? + return; - CHECK_SWPHINTS(this); + if (bUpdate) + { + // Update aller Indizies + pDest->Update( rDestStart, nLen, false, true); + } - Update( rStart, nLen, true, true ); + CHECK_SWPHINTS(pDest); - CHECK_SWPHINTS(this); + const sal_Int32 nEnd = rStart.GetIndex() + nLen; + bool const bUndoNodes = + GetDoc()->GetIDocumentUndoRedo().IsUndoNodes(GetNodes()); - // dann setze die kopierten/geloeschten Attribute in den Node - if( nDestStart <= nTextStartIdx ) + // harte Absatz umspannende Attribute kopieren + if (HasSwAttrSet()) + { + // alle, oder nur die CharAttribute ? + if( nInitSize || pDest->HasSwAttrSet() || + nLen != pDest->GetText().getLength()) { - nTextStartIdx = nTextStartIdx + nLen; + SfxItemSet aCharSet( pDest->GetDoc()->GetAttrPool(), + RES_CHRATR_BEGIN, RES_CHRATR_END-1, + RES_TXTATR_INETFMT, RES_TXTATR_INETFMT, + RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT, + RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1, + 0 ); + aCharSet.Put( *GetpSwAttrSet() ); + if( aCharSet.Count() ) + pDest->SetAttr( aCharSet, nDestStart, nDestStart + nLen ); } else { - nDestStart = nDestStart - nLen; - } - - for ( size_t n = 0; n < aArr.size(); ++n ) - { - SwTextAttr *const pNewHt = aArr[n]; - pNewHt->GetStart() = nDestStart + pNewHt->GetStart(); - sal_Int32 * const pEndIdx = pNewHt->GetEnd(); - if ( pEndIdx ) - { - *pEndIdx = nDestStart + *pEndIdx; - } - InsertHint( pNewHt, SetAttrMode::NOTXTATRCHR ); + GetpSwAttrSet()->CopyToModify( *pDest ); } } - else - { - pDest->m_Text = pDest->m_Text.replaceAt(nDestStart, 0, - m_Text.copy(nTextStartIdx, nLen)); - m_Text = m_Text.replaceAt(nTextStartIdx, nLen, ""); - if (GetSpaceLeft()<0) - { // FIXME: could only happen when called from SwRangeRedline::Show. - // unfortunately can't really do anything here to handle that... - abort(); - } - nLen = pDest->m_Text.getLength() - nInitSize; // update w/ current size! - if( !nLen ) // String nicht gewachsen ?? - return; - - if( bUpdate ) - { - // Update aller Indizies - pDest->Update( rDestStart, nLen, false, true); - } - - CHECK_SWPHINTS(pDest); - const sal_Int32 nEnd = rStart.GetIndex() + nLen; - bool const bUndoNodes = - GetDoc()->GetIDocumentUndoRedo().IsUndoNodes(GetNodes()); + // 2. Attribute verschieben + // durch das Attribute-Array, bis der Anfang des Geltungsbereiches + // des Attributs hinter dem zu verschiebenden Bereich liegt + bool bMergePortionsNeeded(false); + size_t nAttrCnt = 0; + while (m_pSwpHints && (nAttrCnt < m_pSwpHints->Count())) + { + SwTextAttr * const pHt = m_pSwpHints->GetTextHint(nAttrCnt); + const sal_Int32 nAttrStartIdx = pHt->GetStart(); + if (!( nAttrStartIdx < nEnd )) + break; + const sal_Int32 * const pEndIdx = pHt->GetEnd(); + const sal_uInt16 nWhich = pHt->Which(); + SwTextAttr *pNewHt = 0; - // harte Absatz umspannende Attribute kopieren - if( HasSwAttrSet() ) + // if the hint has a dummy character, then it must not be split! + if(nAttrStartIdx < nTextStartIdx) { - // alle, oder nur die CharAttribute ? - if( nInitSize || pDest->HasSwAttrSet() || - nLen != pDest->GetText().getLength()) - { - SfxItemSet aCharSet( pDest->GetDoc()->GetAttrPool(), - RES_CHRATR_BEGIN, RES_CHRATR_END-1, - RES_TXTATR_INETFMT, RES_TXTATR_INETFMT, - RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT, - RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1, - 0 ); - aCharSet.Put( *GetpSwAttrSet() ); - if( aCharSet.Count() ) - pDest->SetAttr( aCharSet, nDestStart, nDestStart + nLen ); - } - else + // Anfang liegt vor dem Bereich + if (!pHt->HasDummyChar() && ( RES_TXTATR_REFMARK != nWhich + || bUndoNodes ) && pEndIdx && *pEndIdx > nTextStartIdx) { - GetpSwAttrSet()->CopyToModify( *pDest ); + // Attribut mit einem Bereich + // und das Ende des Attribut liegt im Bereich + pNewHt = MakeTextAttr( *pDest->GetDoc(), pHt->GetAttr(), + nDestStart, + nDestStart + ( + *pEndIdx > nEnd + ? nLen + : *pEndIdx - nTextStartIdx ) ); } } - - // 2. Attribute verschieben - // durch das Attribute-Array, bis der Anfang des Geltungsbereiches - // des Attributs hinter dem zu verschiebenden Bereich liegt - bool bMergePortionsNeeded(false); - size_t nAttrCnt = 0; - while ( m_pSwpHints && (nAttrCnt < m_pSwpHints->Count()) ) + else { - SwTextAttr * const pHt = m_pSwpHints->GetTextHint(nAttrCnt); - const sal_Int32 nAttrStartIdx = pHt->GetStart(); - if (!( nAttrStartIdx < nEnd )) - break; - const sal_Int32 * const pEndIdx = pHt->GetEnd(); - const sal_uInt16 nWhich = pHt->Which(); - SwTextAttr *pNewHt = 0; - - // if the hint has a dummy character, then it must not be split! - if(nAttrStartIdx < nTextStartIdx) + // der Anfang liegt vollstaendig im Bereich + if (!pEndIdx || *pEndIdx < nEnd || + (!bUndoNodes && RES_TXTATR_REFMARK == nWhich) + || pHt->HasDummyChar() ) { - // Anfang liegt vor dem Bereich - if( !pHt->HasDummyChar() && ( RES_TXTATR_REFMARK != nWhich - || bUndoNodes ) && pEndIdx && *pEndIdx > nTextStartIdx ) + // do not delete note and later add it -> sidebar flickering + if (GetDoc()->GetDocShell()) { - // Attribut mit einem Bereich - // und das Ende des Attribut liegt im Bereich - pNewHt = MakeTextAttr( *pDest->GetDoc(), pHt->GetAttr(), - nDestStart, - nDestStart + ( - *pEndIdx > nEnd - ? nLen - : *pEndIdx - nTextStartIdx ) ); + GetDoc()->GetDocShell()->Broadcast( SfxSimpleHint(SFX_HINT_USER04)); } - } - else - { - // der Anfang liegt vollstaendig im Bereich - if( !pEndIdx || *pEndIdx < nEnd || - (!bUndoNodes && RES_TXTATR_REFMARK == nWhich) - || pHt->HasDummyChar() ) + // Attribut verschieben + m_pSwpHints->Delete( pHt ); + // die Start/End Indicies neu setzen + if (pHt->IsFormatIgnoreStart() || pHt->IsFormatIgnoreEnd()) { - // do not delete note and later add it -> sidebar flickering - if ( GetDoc()->GetDocShell() ) - { - GetDoc()->GetDocShell()->Broadcast( SfxSimpleHint(SFX_HINT_USER04)); - } - // Attribut verschieben - m_pSwpHints->Delete( pHt ); - // die Start/End Indicies neu setzen - if (pHt->IsFormatIgnoreStart() || pHt->IsFormatIgnoreEnd()) - { - bMergePortionsNeeded = true; - } - pHt->GetStart() = - nDestStart + (nAttrStartIdx - nTextStartIdx); - if( pEndIdx ) - { - *pHt->GetEnd() = nDestStart + ( - *pEndIdx > nEnd - ? nLen - : *pEndIdx - nTextStartIdx ); - } - pDest->InsertHint( pHt, - SetAttrMode::NOTXTATRCHR - | SetAttrMode::DONTREPLACE ); - if ( GetDoc()->GetDocShell() ) - { - GetDoc()->GetDocShell()->Broadcast( SfxSimpleHint(SFX_HINT_USER04)); - } - continue; // while-Schleife weiter, ohne ++ ! + bMergePortionsNeeded = true; } - // das Ende liegt dahinter - else if( RES_TXTATR_REFMARK != nWhich || bUndoNodes ) + pHt->GetStart() = + nDestStart + (nAttrStartIdx - nTextStartIdx); + if (pEndIdx) { - pNewHt = MakeTextAttr( *GetDoc(), pHt->GetAttr(), - nDestStart + (nAttrStartIdx - nTextStartIdx), - nDestStart + ( *pEndIdx > nEnd - ? nLen - : *pEndIdx - nTextStartIdx )); + *pHt->GetEnd() = nDestStart + ( + *pEndIdx > nEnd + ? nLen + : *pEndIdx - nTextStartIdx ); } - } - if ( pNewHt ) - { - const bool bSuccess( pDest->InsertHint( pNewHt, - SetAttrMode::NOTXTATRCHR - | SetAttrMode::DONTREPLACE - | SetAttrMode::IS_COPY) ); - if (bSuccess) + pDest->InsertHint( pHt, + SetAttrMode::NOTXTATRCHR + | SetAttrMode::DONTREPLACE ); + if (GetDoc()->GetDocShell()) { - lcl_CopyHint( nWhich, pHt, pNewHt, nullptr, pDest ); + GetDoc()->GetDocShell()->Broadcast( SfxSimpleHint(SFX_HINT_USER04)); } + continue; // while-Schleife weiter, ohne ++ ! } - ++nAttrCnt; - } - // sollten jetzt noch leere Attribute rumstehen, dann haben diese - // eine hoehere Praezedenz. Also herausholen und das Array updaten. - // Die dabei entstehenden leeren Hints werden von den gesicherten - // "uebergeplaettet". (Bug: 6977) - if( m_pSwpHints && nAttrCnt < m_pSwpHints->Count() ) - { - SwpHts aArr; - while ( nAttrCnt < m_pSwpHints->Count() ) + // das Ende liegt dahinter + else if (RES_TXTATR_REFMARK != nWhich || bUndoNodes) { - SwTextAttr * const pHt = m_pSwpHints->GetTextHint(nAttrCnt); - if ( nEnd != pHt->GetStart() ) - break; - const sal_Int32 * const pEndIdx = pHt->GetEnd(); - if ( pEndIdx && *pEndIdx == nEnd ) - { - aArr.push_back( pHt ); - m_pSwpHints->Delete( pHt ); - } - else - { - ++nAttrCnt; - } + pNewHt = MakeTextAttr( *GetDoc(), pHt->GetAttr(), + nDestStart + (nAttrStartIdx - nTextStartIdx), + nDestStart + (*pEndIdx > nEnd + ? nLen + : *pEndIdx - nTextStartIdx)); } - Update( rStart, nLen, true, true ); - - for ( size_t n = 0; n < aArr.size(); ++n ) + } + if (pNewHt) + { + const bool bSuccess( pDest->InsertHint( pNewHt, + SetAttrMode::NOTXTATRCHR + | SetAttrMode::DONTREPLACE + | SetAttrMode::IS_COPY) ); + if (bSuccess) { - SwTextAttr * const pHt = aArr[ n ]; - pHt->GetStart() = *pHt->GetEnd() = rStart.GetIndex(); - InsertHint( pHt ); + lcl_CopyHint( nWhich, pHt, pNewHt, nullptr, pDest ); } } - else + ++nAttrCnt; + } + // sollten jetzt noch leere Attribute rumstehen, dann haben diese + // eine hoehere Praezedenz. Also herausholen und das Array updaten. + // Die dabei entstehenden leeren Hints werden von den gesicherten + // "uebergeplaettet". (Bug: 6977) + if (m_pSwpHints && nAttrCnt < m_pSwpHints->Count()) + { + SwpHts aArr; + while (nAttrCnt < m_pSwpHints->Count()) { - Update( rStart, nLen, true, true ); + SwTextAttr * const pHt = m_pSwpHints->GetTextHint(nAttrCnt); + if (nEnd != pHt->GetStart()) + break; + const sal_Int32 * const pEndIdx = pHt->GetEnd(); + if (pEndIdx && *pEndIdx == nEnd) + { + aArr.push_back( pHt ); + m_pSwpHints->Delete( pHt ); + } + else + { + ++nAttrCnt; + } } + Update( rStart, nLen, true, true ); - if (bMergePortionsNeeded) + for (size_t n = 0; n < aArr.size(); ++n) { - m_pSwpHints->MergePortions(*this); + SwTextAttr * const pHt = aArr[ n ]; + pHt->GetStart() = *pHt->GetEnd() = rStart.GetIndex(); + InsertHint( pHt ); } + } + else + { + Update( rStart, nLen, true, true ); + } - CHECK_SWPHINTS(this); + if (bMergePortionsNeeded) + { + m_pSwpHints->MergePortions(*this); } + CHECK_SWPHINTS(this); + TryDeleteSwpHints(); // Frames benachrichtigen; commit 38e5251a82669d25928291712508651158b027b5 Author: Michael Stahl <[email protected]> Date: Mon Jun 1 15:05:48 2015 +0200 sw: SwTxtNode::CutImpl(): destination must be in same SwDoc Change-Id: I541dad26125bcd98e9c74016ecd03cd7f8bc71e6 diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 976e5c3..b7b1c71 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -2034,15 +2034,7 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwIndex & rDestStart, { assert(pDest); // Cut requires a destination - // nicht im Dokument verschieben ? - if( GetDoc() != pDest->GetDoc() ) - { - OSL_FAIL("mst: entering dead and bitrotted code; fasten your seatbelts!"); - assert(false); - CopyText( pDest, rDestStart, rStart, nLen); - EraseText(rStart, nLen); - return; - } + assert(GetDoc() == pDest->GetDoc()); // must be same document if( !nLen ) { @@ -2193,14 +2185,8 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwIndex & rDestStart, CHECK_SWPHINTS(pDest); const sal_Int32 nEnd = rStart.GetIndex() + nLen; - SwDoc* const pOtherDoc = (pDest->GetDoc() != GetDoc()) - ? pDest->GetDoc() : 0; - bool const bUndoNodes = !pOtherDoc - && GetDoc()->GetIDocumentUndoRedo().IsUndoNodes(GetNodes()); - - OSL_ENSURE(!pOtherDoc, - "mst: entering dead and bitrotted code; fasten your seatbelts!"); - assert(!pOtherDoc); + bool const bUndoNodes = + GetDoc()->GetIDocumentUndoRedo().IsUndoNodes(GetNodes()); // harte Absatz umspannende Attribute kopieren if( HasSwAttrSet() ) @@ -2261,7 +2247,7 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwIndex & rDestStart, { // der Anfang liegt vollstaendig im Bereich if( !pEndIdx || *pEndIdx < nEnd || - (!pOtherDoc && !bUndoNodes && RES_TXTATR_REFMARK == nWhich) + (!bUndoNodes && RES_TXTATR_REFMARK == nWhich) || pHt->HasDummyChar() ) { // do not delete note and later add it -> sidebar flickering @@ -2312,7 +2298,7 @@ void SwTextNode::CutImpl( SwTextNode * const pDest, const SwIndex & rDestStart, | SetAttrMode::IS_COPY) ); if (bSuccess) { - lcl_CopyHint( nWhich, pHt, pNewHt, pOtherDoc, pDest ); + lcl_CopyHint( nWhich, pHt, pNewHt, nullptr, pDest ); } } ++nAttrCnt; commit 5dc453ac9027828c6a2319126b620d8d9e6c08ba Author: Michael Stahl <[email protected]> Date: Mon Jun 1 14:54:33 2015 +0200 sw: SwTxtNode::CutText() requires a destination Remove dead code. Change-Id: Ib6a75718d411effe87d59d30420e2e9d7f15984e diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index 4956a35..976e5c3 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -2024,29 +2024,15 @@ OUString SwTextNode::InsertText( const OUString & rStr, const SwIndex & rIdx, void SwTextNode::CutText( SwTextNode * const pDest, const SwIndex & rStart, const sal_Int32 nLen ) { - if(pDest) - { - SwIndex aDestStt(pDest, pDest->GetText().getLength()); - CutImpl( pDest, aDestStt, rStart, nLen, false ); - } - else - { - OSL_FAIL("mst: entering dead and bitrotted code; fasten your seatbelts!"); - assert(false); - EraseText( rStart, nLen ); - } + assert(pDest); // Cut requires a destination + SwIndex aDestStt(pDest, pDest->GetText().getLength()); + CutImpl( pDest, aDestStt, rStart, nLen, false ); } void SwTextNode::CutImpl( SwTextNode * const pDest, const SwIndex & rDestStart, const SwIndex & rStart, sal_Int32 nLen, const bool bUpdate ) { - if(!pDest) - { - OSL_FAIL("mst: entering dead and bitrotted code; fasten your seatbelts!"); - assert(false); - EraseText( rStart, nLen ); - return; - } + assert(pDest); // Cut requires a destination // nicht im Dokument verschieben ? if( GetDoc() != pDest->GetDoc() ) _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
