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>
23 #include "swtable.hxx"
26 #include <editeng/formatbreakitem.hxx>
27 #include <fmtpdsc.hxx>
29 #include <UndoCore.hxx>
31 #include "redline.hxx"
33 #include <IShellCursorSupplier.hxx>
35 //------------------------------------------------------------------
38 SwUndoSplitNode::SwUndoSplitNode( SwDoc
* pDoc
, const SwPosition
& rPos
,
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() )
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()
70 void SwUndoSplitNode::UndoImpl(::sw::UndoRedoContext
& rContext
)
72 SwDoc
*const pDoc
= & rContext
.GetDoc();
73 SwPaM
& rPam( rContext
.GetCursorSupplier().CreateNewShellCursor() );
77 // than a TextNode was added directly before the current table
78 SwNodeIndex
& rIdx
= rPam
.GetPoint()->nNode
;
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();
91 const SfxPoolItem
*pItem
;
92 if( SFX_ITEM_SET
== pNdSet
->GetItemState( RES_PAGEDESC
, sal_False
,
94 pTableFmt
->SetFmtAttr( *pItem
);
96 if( SFX_ITEM_SET
== pNdSet
->GetItemState( RES_BREAK
, sal_False
,
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
);
110 SwTxtNode
* pTNd
= pDoc
->GetNodes()[ nNode
]->GetTxtNode();
113 rPam
.GetPoint()->nNode
= *pTNd
;
114 rPam
.GetPoint()->nContent
.Assign(pTNd
, pTNd
->GetTxt().getLength());
116 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
119 rPam
.GetMark()->nNode
++;
120 rPam
.GetMark()->nContent
.Assign( rPam
.GetMark()->
121 nNode
.GetNode().GetCntntNode(), 0 );
122 pDoc
->DeleteRedline( rPam
, true, USHRT_MAX
);
126 RemoveIdxRel( nNode
+1, *rPam
.GetPoint() );
131 rPam
.GetPoint()->nContent
= 0;
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
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");
157 rPam
.GetPoint()->nContent
.Assign( pTNd
, nCntnt
);
159 SwDoc
* pDoc
= rPam
.GetDoc();
160 pDoc
->SplitNode( *rPam
.GetPoint(), bChkTblStt
);
163 pHistory
->SetTmpEnd( pHistory
->Count() );
165 if( ( pRedlData
&& IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() )) ||
166 ( !( nsRedlineMode_t::REDLINE_IGNORE
& GetRedlineMode() ) &&
167 !pDoc
->GetRedlineTbl().empty() ))
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
);
180 pDoc
->SplitRedline( rPam
);
188 void SwUndoSplitNode::RepeatImpl(::sw::RepeatContext
& rContext
)
190 rContext
.GetDoc().SplitNode(
191 *rContext
.GetRepeatPaM().GetPoint(), bChkTblStt
);
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */