1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <UndoSplitMove.hxx>
22 #include <IDocumentRedlineAccess.hxx>
24 #include <swtable.hxx>
29 #include <UndoCore.hxx>
31 #include <redline.hxx>
33 #include <fmtpdsc.hxx>
34 #include <IShellCursorSupplier.hxx>
35 #include <osl/diagnose.h>
36 #include <editeng/formatbreakitem.hxx>
40 SwUndoSplitNode::SwUndoSplitNode( SwDoc
& rDoc
, const SwPosition
& rPos
,
42 : SwUndo( SwUndoId::SPLITNODE
, &rDoc
), m_nNode( rPos
.GetNodeIndex() ),
43 m_nContent( rPos
.GetContentIndex() ),
44 m_bTableFlag( false ), m_bCheckTableStart( bChkTable
)
46 SwTextNode
*const pTextNd
= rPos
.GetNode().GetTextNode();
47 OSL_ENSURE( pTextNd
, "only for TextNode" );
48 if( pTextNd
->GetpSwpHints() )
50 m_pHistory
.reset(new SwHistory
);
51 m_pHistory
->CopyAttr(pTextNd
->GetpSwpHints(), m_nNode
, 0,
52 pTextNd
->GetText().getLength(), false );
53 if (!m_pHistory
->Count())
59 if( rDoc
.getIDocumentRedlineAccess().IsRedlineOn() )
61 m_pRedlineData
.reset( new SwRedlineData( RedlineType::Insert
, rDoc
.getIDocumentRedlineAccess().GetRedlineAuthor() ) );
62 SetRedlineFlags( rDoc
.getIDocumentRedlineAccess().GetRedlineFlags() );
65 m_nParRsid
= pTextNd
->GetParRsid();
68 SwUndoSplitNode::~SwUndoSplitNode()
71 m_pRedlineData
.reset();
74 void SwUndoSplitNode::UndoImpl(::sw::UndoRedoContext
& rContext
)
76 SwDoc
*const pDoc
= & rContext
.GetDoc();
77 SwCursor
& rPam( rContext
.GetCursorSupplier().CreateNewShellCursor() );
81 // than a TextNode was added directly before the current table
82 SwPosition
& rPos
= *rPam
.GetPoint();
85 SwNode
* pCurrNd
= pDoc
->GetNodes()[ m_nNode
+ 1 ];
86 SwTableNode
* pTableNd
= pCurrNd
->FindTableNode();
87 if( pCurrNd
->IsContentNode() && pTableNd
&&
88 nullptr != ( pTNd
= pDoc
->GetNodes()[ pTableNd
->GetIndex()-1 ]->GetTextNode() ))
90 // move break attributes
91 SwFrameFormat
* pTableFormat
= pTableNd
->GetTable().GetFrameFormat();
92 const SfxItemSet
* pNdSet
= pTNd
->GetpSwAttrSet();
95 if( const SwFormatPageDesc
* pItem
= pNdSet
->GetItemIfSet( RES_PAGEDESC
, false ) )
96 pTableFormat
->SetFormatAttr( *pItem
);
98 if( const SvxFormatBreakItem
* pItem
= pNdSet
->GetItemIfSet( RES_BREAK
, false ) )
99 pTableFormat
->SetFormatAttr( *pItem
);
102 // than delete it again
103 SwNodeIndex
aDelNd( *pTableNd
, -1 );
104 RemoveIdxRel( aDelNd
.GetIndex(), *rPam
.GetPoint() );
105 pDoc
->GetNodes().Delete( aDelNd
);
110 SwTextNode
* pTNd
= pDoc
->GetNodes()[ m_nNode
]->GetTextNode();
113 rPam
.GetPoint()->Assign(*pTNd
, pTNd
->GetText().getLength());
115 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ))
118 rPam
.GetMark()->Adjust(SwNodeOffset(1));
119 pDoc
->getIDocumentRedlineAccess().DeleteRedline( rPam
, true, RedlineType::Any
);
123 RemoveIdxRel( m_nNode
+1, *rPam
.GetPoint() );
128 rPam
.GetPoint()->SetContent(0);
130 rPam
.GetPoint()->SetContent(pTNd
->GetText().getLength());
132 pDoc
->RstTextAttrs( rPam
, true );
133 m_pHistory
->TmpRollback( pDoc
, 0, false );
136 pDoc
->UpdateParRsid( pTNd
, m_nParRsid
);
140 // also set the cursor onto undo section
142 rPam
.GetPoint()->Assign( m_nNode
, m_nContent
);
145 void SwUndoSplitNode::RedoImpl(::sw::UndoRedoContext
& rContext
)
147 SwCursor
& rPam( rContext
.GetCursorSupplier().CreateNewShellCursor() );
148 rPam
.GetPoint()->Assign(m_nNode
);
149 SwTextNode
* pTNd
= rPam
.GetPointNode().GetTextNode();
150 OSL_ENSURE(pTNd
, "SwUndoSplitNode::RedoImpl(): SwTextNode expected");
154 rPam
.GetPoint()->SetContent( m_nContent
);
156 SwDoc
& rDoc
= rPam
.GetDoc();
157 rDoc
.getIDocumentContentOperations().SplitNode( *rPam
.GetPoint(), m_bCheckTableStart
);
161 m_pHistory
->SetTmpEnd(m_pHistory
->Count());
164 if( !(( m_pRedlineData
&& IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) ||
165 ( !( RedlineFlags::Ignore
& GetRedlineFlags() ) &&
166 !rDoc
.getIDocumentRedlineAccess().GetRedlineTable().empty() )))
170 if( rPam
.Move( fnMoveBackward
))
172 if( m_pRedlineData
&& IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ))
174 RedlineFlags eOld
= rDoc
.getIDocumentRedlineAccess().GetRedlineFlags();
175 rDoc
.getIDocumentRedlineAccess().SetRedlineFlags_intern(eOld
& ~RedlineFlags::Ignore
);
176 rDoc
.getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *m_pRedlineData
, rPam
), true);
177 rDoc
.getIDocumentRedlineAccess().SetRedlineFlags_intern( eOld
);
180 rDoc
.getIDocumentRedlineAccess().SplitRedline( rPam
);
186 void SwUndoSplitNode::RepeatImpl(::sw::RepeatContext
& rContext
)
188 rContext
.GetDoc().getIDocumentContentOperations().SplitNode(
189 *rContext
.GetRepeatPaM().GetPoint(), m_bCheckTableStart
);
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */