Kaydet (Commit) 68d87e98 authored tarafından Caolán McNamara's avatar Caolán McNamara

Resolves: fdo#86552 undo want to take ownership of nodes, but can't

Revert "fdo#75757 remove inheritance from std::vector"

This reverts commit 63d8977f.

Change-Id: Idc9902a77ee2c1cb21b9e3b477b2d960772a022e
üst 5214b96a
......@@ -150,6 +150,21 @@ struct TEIMEInfos
void DestroyAttribs();
};
// ----------------- Wrapper for old Tools List -------------------
#include <vector>
#include <algorithm>
template <class T> class ToolsList : public ::std::vector< T >
{
public:
size_t Count() const { return ::std::vector< T >::size(); }
size_t GetPos( T pObject ) const { return ( ::std::find( this->begin(), this->end(), pObject ) ) - this->begin(); }
T GetObject( size_t nIndex ) const { return (*this)[nIndex]; }
void Insert( T pObject, size_t nPos ) { ::std::vector< T >::insert( this->begin()+nPos, pObject ); }
void Remove( size_t nPos ) { ::std::vector< T >::erase( this->begin()+nPos ); }
};
#endif // INCLUDED_VCL_TEXTDATA_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -407,33 +407,38 @@ void TextNode::Append( const TextNode& rNode )
}
}
bool TextNode::operator==(TextNode const& other) const
{
return maText == other.maText && &maCharAttribs == &other.maCharAttribs;
}
TextDoc::TextDoc()
{
mnLeftMargin = 0;
};
TextDoc::~TextDoc()
{
DestroyTextNodes();
}
void TextDoc::Clear()
{
DestroyTextNodes();
}
void TextDoc::DestroyTextNodes()
{
for ( sal_uLong nNode = 0; nNode < maTextNodes.Count(); nNode++ )
delete maTextNodes.GetObject( nNode );
maTextNodes.clear();
}
OUString TextDoc::GetText( const sal_Unicode* pSep ) const
{
sal_uLong nNodes = maTextNodes.size();
sal_uLong nNodes = maTextNodes.Count();
OUString aASCIIText;
sal_uLong nLastNode = nNodes-1;
for ( sal_uLong nNode = 0; nNode < nNodes; nNode++ )
{
const TextNode& pNode = maTextNodes[ nNode ];
OUString aTmp( pNode.GetText() );
TextNode* pNode = maTextNodes.GetObject( nNode );
OUString aTmp( pNode->GetText() );
aASCIIText += aTmp;
if ( pSep && ( nNode != nLastNode ) )
aASCIIText += pSep;
......@@ -446,8 +451,9 @@ OUString TextDoc::GetText( sal_uLong nPara ) const
{
OUString aText;
if ( nPara < maTextNodes.size() )
aText = maTextNodes[ nPara ].GetText();
TextNode* pNode = ( nPara < maTextNodes.Count() ) ? maTextNodes.GetObject( nPara ) : 0;
if ( pNode )
aText = pNode->GetText();
return aText;
}
......@@ -455,7 +461,7 @@ OUString TextDoc::GetText( sal_uLong nPara ) const
sal_uLong TextDoc::GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel ) const
{
sal_uLong nLen = 0;
sal_uLong nNodes = maTextNodes.size();
sal_uLong nNodes = maTextNodes.Count();
if ( nNodes )
{
sal_uLong nStartNode = 0;
......@@ -468,10 +474,10 @@ sal_uLong TextDoc::GetTextLen( const sal_Unicode* pSep, const TextSelection* pSe
for ( sal_uLong nNode = nStartNode; nNode <= nEndNode; nNode++ )
{
const TextNode& pNode = maTextNodes[ nNode ];
TextNode* pNode = maTextNodes.GetObject( nNode );
sal_uInt16 nS = 0;
sal_Int32 nE = pNode.GetText().getLength();
sal_Int32 nE = pNode->GetText().getLength();
if ( pSel && ( nNode == pSel->GetStart().GetPara() ) )
nS = pSel->GetStart().GetIndex();
if ( pSel && ( nNode == pSel->GetEnd().GetPara() ) )
......@@ -489,11 +495,11 @@ sal_uLong TextDoc::GetTextLen( const sal_Unicode* pSep, const TextSelection* pSe
TextPaM TextDoc::InsertText( const TextPaM& rPaM, sal_Unicode c )
{
DBG_ASSERT( c != 0x0A, "TextDoc::InsertText: Newline not allowed in paragraph!" );
DBG_ASSERT( c != 0x0D, "TextDoc::InsertText: Newline not allowed in paragraph!" );
DBG_ASSERT( c != 0x0A, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" );
DBG_ASSERT( c != 0x0D, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" );
TextNode& pNode = maTextNodes[ rPaM.GetPara() ];
pNode.InsertText( rPaM.GetIndex(), c );
TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() );
pNode->InsertText( rPaM.GetIndex(), c );
TextPaM aPaM( rPaM.GetPara(), rPaM.GetIndex()+1 );
return aPaM;
......@@ -501,11 +507,11 @@ TextPaM TextDoc::InsertText( const TextPaM& rPaM, sal_Unicode c )
TextPaM TextDoc::InsertText( const TextPaM& rPaM, const OUString& rStr )
{
DBG_ASSERT( rStr.indexOf( 0x0A ) == -1, "TextDoc::InsertText: Newline not allowed in paragraph!" );
DBG_ASSERT( rStr.indexOf( 0x0D ) == -1, "TextDoc::InsertText: Newline not allowed in paragraph!" );
DBG_ASSERT( rStr.indexOf( 0x0A ) == -1, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" );
DBG_ASSERT( rStr.indexOf( 0x0D ) == -1, "TextDoc::InsertText: Zeilentrenner in Absatz nicht erlaubt!" );
TextNode& pNode = maTextNodes[ rPaM.GetPara() ];
pNode.InsertText( rPaM.GetIndex(), rStr );
TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() );
pNode->InsertText( rPaM.GetIndex(), rStr );
TextPaM aPaM( rPaM.GetPara(), rPaM.GetIndex()+rStr.getLength() );
return aPaM;
......@@ -513,45 +519,47 @@ TextPaM TextDoc::InsertText( const TextPaM& rPaM, const OUString& rStr )
TextPaM TextDoc::InsertParaBreak( const TextPaM& rPaM, bool bKeepEndingAttribs )
{
TextNode& pNode = maTextNodes[ rPaM.GetPara() ];
TextNode* pNew = pNode.Split( rPaM.GetIndex(), bKeepEndingAttribs );
TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() );
TextNode* pNew = pNode->Split( rPaM.GetIndex(), bKeepEndingAttribs );
maTextNodes.insert( maTextNodes.begin()+rPaM.GetPara()+1, pNew );
maTextNodes.Insert( pNew, rPaM.GetPara()+1 );
TextPaM aPaM( rPaM.GetPara()+1, 0 );
return aPaM;
}
TextPaM TextDoc::ConnectParagraphs( TextNode& pLeft, const TextNode& pRight )
TextPaM TextDoc::ConnectParagraphs( TextNode* pLeft, TextNode* pRight )
{
sal_Int32 nPrevLen = pLeft.GetText().getLength();
pLeft.Append( pRight );
sal_Int32 nPrevLen = pLeft->GetText().getLength();
pLeft->Append( *pRight );
// the paragraph on the right vanishes
RemoveNode( ::std::find( maTextNodes.cbegin(), maTextNodes.cend(), pRight ) - maTextNodes.cbegin() );
sal_uLong nRight = maTextNodes.GetPos( pRight );
maTextNodes.Remove( nRight );
delete pRight;
sal_uLong nLeft = std::find( maTextNodes.begin(), maTextNodes.end(), pLeft ) - maTextNodes.begin();
sal_uLong nLeft = maTextNodes.GetPos( pLeft );
TextPaM aPaM( nLeft, nPrevLen );
return aPaM;
}
TextPaM TextDoc::RemoveChars( const TextPaM& rPaM, sal_uInt16 nChars )
{
TextNode& pNode = maTextNodes[ rPaM.GetPara() ];
pNode.RemoveText( rPaM.GetIndex(), nChars );
TextNode* pNode = maTextNodes.GetObject( rPaM.GetPara() );
pNode->RemoveText( rPaM.GetIndex(), nChars );
return rPaM;
}
bool TextDoc::IsValidPaM( const TextPaM& rPaM )
{
if ( rPaM.GetPara() >= maTextNodes.size() )
if ( rPaM.GetPara() >= maTextNodes.Count() )
{
OSL_FAIL( "PaM: Para out of range" );
return false;
}
TextNode& pNode = maTextNodes[ rPaM.GetPara() ];
if ( rPaM.GetIndex() > pNode.GetText().getLength() )
TextNode * pNode = maTextNodes.GetObject( rPaM.GetPara() );
if ( rPaM.GetIndex() > pNode->GetText().getLength() )
{
OSL_FAIL( "PaM: Index out of range" );
return false;
......
......@@ -85,15 +85,12 @@ public:
TextNode* Split( sal_uInt16 nPos, bool bKeepEndigAttribs );
void Append( const TextNode& rNode );
bool operator ==(TextNode const& other) const;
};
class TextDoc
{
private:
typedef boost::ptr_vector<TextNode> TextNodes;
TextNodes maTextNodes;
ToolsList<TextNode*> maTextNodes;
sal_uInt16 mnLeftMargin;
protected:
......@@ -101,22 +98,19 @@ protected:
public:
TextDoc();
~TextDoc() {};
~TextDoc();
void Clear();
const TextNode& GetNode(sal_uInt16 pos) const { return maTextNodes[pos]; }
TextNode* GetNode(sal_uInt16 pos) { return &maTextNodes[pos]; }
size_t CountNodes() { return maTextNodes.size(); }
void InsertNode( TextNode* node, size_t nPos ) { maTextNodes.insert( maTextNodes.begin() + nPos, node ); }
void RemoveNode( size_t nPos ) { maTextNodes.erase( maTextNodes.begin()+nPos ); }
ToolsList<TextNode*>& GetNodes() { return maTextNodes; }
const ToolsList<TextNode*>& GetNodes() const { return maTextNodes; }
TextPaM RemoveChars( const TextPaM& rPaM, sal_uInt16 nChars );
TextPaM InsertText( const TextPaM& rPaM, sal_Unicode c );
TextPaM InsertText( const TextPaM& rPaM, const OUString& rStr );
TextPaM InsertParaBreak( const TextPaM& rPaM, bool bKeepEndingAttribs );
TextPaM ConnectParagraphs( TextNode& pLeft, const TextNode& pRight );
TextPaM ConnectParagraphs( TextNode* pLeft, TextNode* pRight );
sal_uLong GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel = NULL ) const;
OUString GetText( const sal_Unicode* pSep ) const;
......
This diff is collapsed.
......@@ -173,20 +173,20 @@ void TextUndoDelPara::Undo()
void TextUndoDelPara::Redo()
{
// pNode is not valid anymore in case an Undo joined paragraphs
mpNode = GetDoc()->GetNode( mnPara );
mpNode = GetDoc()->GetNodes().GetObject( mnPara );
delete GetTEParaPortions()->GetObject( mnPara );
GetTEParaPortions()->Remove( mnPara );
// do not delete Node because of Undo!
GetDoc()->RemoveNode( mnPara );
GetDoc()->GetNodes().Remove( mnPara );
GetTextEngine()->ImpParagraphRemoved( mnPara );
mbDelObject = true; // belongs again to the Undo
sal_uLong nParas = GetDoc()->CountNodes();
sal_uLong nParas = GetDoc()->GetNodes().Count();
sal_uLong n = mnPara < nParas ? mnPara : (nParas-1);
TextNode* pN = GetDoc()->GetNode( n );
TextNode* pN = GetDoc()->GetNodes().GetObject( n );
TextPaM aPaM( n, pN->GetText().getLength() );
SetSelection( aPaM );
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment