update credits
[LibreOffice.git] / sw / source / core / undo / unspnd.cxx
blobe65b15a17c85159762a7d0ad5d25dae3e5af992b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
21 #include "doc.hxx"
22 #include "pam.hxx"
23 #include "swtable.hxx"
24 #include "ndtxt.hxx"
25 #include "swundo.hxx"
26 #include <editeng/formatbreakitem.hxx>
27 #include <fmtpdsc.hxx>
28 #include <frmfmt.hxx>
29 #include <UndoCore.hxx>
30 #include "rolbck.hxx"
31 #include "redline.hxx"
32 #include "docary.hxx"
33 #include <IShellCursorSupplier.hxx>
35 //------------------------------------------------------------------
36 // SPLITNODE
38 SwUndoSplitNode::SwUndoSplitNode( SwDoc* pDoc, const SwPosition& rPos,
39 sal_Bool bChkTable )
40 : SwUndo( UNDO_SPLITNODE ), pHistory( 0 ), pRedlData( 0 ), nNode( rPos.nNode.GetIndex() ),
41 nCntnt( rPos.nContent.GetIndex() ),
42 bTblFlag( sal_False ), bChkTblStt( bChkTable )
44 SwTxtNode *const pTxtNd = rPos.nNode.GetNode().GetTxtNode();
45 OSL_ENSURE( pTxtNd, "only for TextNode" );
46 if( pTxtNd->GetpSwpHints() )
48 pHistory = new SwHistory;
49 pHistory->CopyAttr( pTxtNd->GetpSwpHints(), nNode, 0,
50 pTxtNd->GetTxt().getLength(), false );
51 if( !pHistory->Count() )
52 DELETEZ( pHistory );
54 // consider Redline
55 if( pDoc->IsRedlineOn() )
57 pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, pDoc->GetRedlineAuthor() );
58 SetRedlineMode( pDoc->GetRedlineMode() );
61 nParRsid = pTxtNd->GetParRsid();
64 SwUndoSplitNode::~SwUndoSplitNode()
66 delete pHistory;
67 delete pRedlData;
70 void SwUndoSplitNode::UndoImpl(::sw::UndoRedoContext & rContext)
72 SwDoc *const pDoc = & rContext.GetDoc();
73 SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
74 rPam.DeleteMark();
75 if( bTblFlag )
77 // than a TextNode was added directly before the current table
78 SwNodeIndex& rIdx = rPam.GetPoint()->nNode;
79 rIdx = nNode;
80 SwTxtNode* pTNd;
81 SwNode* pCurrNd = pDoc->GetNodes()[ nNode + 1 ];
82 SwTableNode* pTblNd = pCurrNd->FindTableNode();
83 if( pCurrNd->IsCntntNode() && pTblNd &&
84 0 != ( pTNd = pDoc->GetNodes()[ pTblNd->GetIndex()-1 ]->GetTxtNode() ))
86 // move break attributes
87 SwFrmFmt* pTableFmt = pTblNd->GetTable().GetFrmFmt();
88 const SfxItemSet* pNdSet = pTNd->GetpSwAttrSet();
89 if( pNdSet )
91 const SfxPoolItem *pItem;
92 if( SFX_ITEM_SET == pNdSet->GetItemState( RES_PAGEDESC, sal_False,
93 &pItem ) )
94 pTableFmt->SetFmtAttr( *pItem );
96 if( SFX_ITEM_SET == pNdSet->GetItemState( RES_BREAK, sal_False,
97 &pItem ) )
98 pTableFmt->SetFmtAttr( *pItem );
101 // than delete it again
102 SwNodeIndex aDelNd( *pTblNd, -1 );
103 rPam.GetPoint()->nContent.Assign( (SwCntntNode*)pCurrNd, 0 );
104 RemoveIdxRel( aDelNd.GetIndex(), *rPam.GetPoint() );
105 pDoc->GetNodes().Delete( aDelNd );
108 else
110 SwTxtNode * pTNd = pDoc->GetNodes()[ nNode ]->GetTxtNode();
111 if( pTNd )
113 rPam.GetPoint()->nNode = *pTNd;
114 rPam.GetPoint()->nContent.Assign(pTNd, pTNd->GetTxt().getLength());
116 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
118 rPam.SetMark();
119 rPam.GetMark()->nNode++;
120 rPam.GetMark()->nContent.Assign( rPam.GetMark()->
121 nNode.GetNode().GetCntntNode(), 0 );
122 pDoc->DeleteRedline( rPam, true, USHRT_MAX );
123 rPam.DeleteMark();
126 RemoveIdxRel( nNode+1, *rPam.GetPoint() );
128 pTNd->JoinNext();
129 if( pHistory )
131 rPam.GetPoint()->nContent = 0;
132 rPam.SetMark();
133 rPam.GetPoint()->nContent = pTNd->GetTxt().getLength();
135 pDoc->RstTxtAttrs( rPam, true );
136 pHistory->TmpRollback( pDoc, 0, false );
139 pDoc->UpdateParRsid( pTNd, nParRsid );
143 // also set the cursor onto undo section
144 rPam.DeleteMark();
145 rPam.GetPoint()->nNode = nNode;
146 rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), nCntnt );
149 void SwUndoSplitNode::RedoImpl(::sw::UndoRedoContext & rContext)
151 SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
152 rPam.GetPoint()->nNode = nNode;
153 SwTxtNode * pTNd = rPam.GetNode()->GetTxtNode();
154 OSL_ENSURE(pTNd, "SwUndoSplitNode::RedoImpl(): SwTxtNode expected");
155 if (pTNd)
157 rPam.GetPoint()->nContent.Assign( pTNd, nCntnt );
159 SwDoc* pDoc = rPam.GetDoc();
160 pDoc->SplitNode( *rPam.GetPoint(), bChkTblStt );
162 if( pHistory )
163 pHistory->SetTmpEnd( pHistory->Count() );
165 if( ( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() )) ||
166 ( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
167 !pDoc->GetRedlineTbl().empty() ))
169 rPam.SetMark();
170 if( rPam.Move( fnMoveBackward ))
172 if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
174 RedlineMode_t eOld = pDoc->GetRedlineMode();
175 pDoc->SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
176 pDoc->AppendRedline( new SwRedline( *pRedlData, rPam ), true);
177 pDoc->SetRedlineMode_intern( eOld );
179 else
180 pDoc->SplitRedline( rPam );
181 rPam.Exchange();
183 rPam.DeleteMark();
188 void SwUndoSplitNode::RepeatImpl(::sw::RepeatContext & rContext)
190 rContext.GetDoc().SplitNode(
191 *rContext.GetRepeatPaM().GetPoint(), bChkTblStt );
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */