summaryrefslogtreecommitdiff
path: root/sw/source/core/txtnode
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2015-06-01 15:12:09 +0200
committerMichael Stahl <mstahl@redhat.com>2015-06-01 15:50:39 +0200
commit54a6e4841cd4b62faca090df8a7c4f2a1bf24b44 (patch)
tree9dd58612fb812c53c67c667d9baf644845f08b40 /sw/source/core/txtnode
parent38e5251a82669d25928291712508651158b027b5 (diff)
sw: SwTxtNode::CutImpl(): destination must be different node
Remove more dead code.: Change-Id: I9572228be0e5393351a7d22eb23e1f188423a219
Diffstat (limited to 'sw/source/core/txtnode')
-rw-r--r--sw/source/core/txtnode/ndtxt.cxx405
1 files changed, 145 insertions, 260 deletions
diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx
index b7b1c7145d27..3087212818ac 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;