Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
34 :
35 : // SPLITNODE
36 :
37 0 : SwUndoSplitNode::SwUndoSplitNode( SwDoc* pDoc, const SwPosition& rPos,
38 : sal_Bool bChkTable )
39 0 : : SwUndo( UNDO_SPLITNODE ), pHistory( 0 ), pRedlData( 0 ), nNode( rPos.nNode.GetIndex() ),
40 0 : nCntnt( rPos.nContent.GetIndex() ),
41 0 : bTblFlag( sal_False ), bChkTblStt( bChkTable )
42 : {
43 0 : SwTxtNode *const pTxtNd = rPos.nNode.GetNode().GetTxtNode();
44 : OSL_ENSURE( pTxtNd, "only for TextNode" );
45 0 : if( pTxtNd->GetpSwpHints() )
46 : {
47 0 : pHistory = new SwHistory;
48 : pHistory->CopyAttr( pTxtNd->GetpSwpHints(), nNode, 0,
49 0 : pTxtNd->GetTxt().getLength(), false );
50 0 : if( !pHistory->Count() )
51 0 : DELETEZ( pHistory );
52 : }
53 : // consider Redline
54 0 : if( pDoc->IsRedlineOn() )
55 : {
56 0 : pRedlData = new SwRedlineData( nsRedlineType_t::REDLINE_INSERT, pDoc->GetRedlineAuthor() );
57 0 : SetRedlineMode( pDoc->GetRedlineMode() );
58 : }
59 :
60 0 : nParRsid = pTxtNd->GetParRsid();
61 0 : }
62 :
63 0 : SwUndoSplitNode::~SwUndoSplitNode()
64 : {
65 0 : delete pHistory;
66 0 : delete pRedlData;
67 0 : }
68 :
69 0 : void SwUndoSplitNode::UndoImpl(::sw::UndoRedoContext & rContext)
70 : {
71 0 : SwDoc *const pDoc = & rContext.GetDoc();
72 0 : SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
73 0 : rPam.DeleteMark();
74 0 : if( bTblFlag )
75 : {
76 : // than a TextNode was added directly before the current table
77 0 : SwNodeIndex& rIdx = rPam.GetPoint()->nNode;
78 0 : rIdx = nNode;
79 : SwTxtNode* pTNd;
80 0 : SwNode* pCurrNd = pDoc->GetNodes()[ nNode + 1 ];
81 0 : SwTableNode* pTblNd = pCurrNd->FindTableNode();
82 0 : if( pCurrNd->IsCntntNode() && pTblNd &&
83 0 : 0 != ( pTNd = pDoc->GetNodes()[ pTblNd->GetIndex()-1 ]->GetTxtNode() ))
84 : {
85 : // move break attributes
86 0 : SwFrmFmt* pTableFmt = pTblNd->GetTable().GetFrmFmt();
87 0 : const SfxItemSet* pNdSet = pTNd->GetpSwAttrSet();
88 0 : if( pNdSet )
89 : {
90 : const SfxPoolItem *pItem;
91 0 : if( SFX_ITEM_SET == pNdSet->GetItemState( RES_PAGEDESC, false,
92 0 : &pItem ) )
93 0 : pTableFmt->SetFmtAttr( *pItem );
94 :
95 0 : if( SFX_ITEM_SET == pNdSet->GetItemState( RES_BREAK, false,
96 0 : &pItem ) )
97 0 : pTableFmt->SetFmtAttr( *pItem );
98 : }
99 :
100 : // than delete it again
101 0 : SwNodeIndex aDelNd( *pTblNd, -1 );
102 0 : rPam.GetPoint()->nContent.Assign( (SwCntntNode*)pCurrNd, 0 );
103 0 : RemoveIdxRel( aDelNd.GetIndex(), *rPam.GetPoint() );
104 0 : pDoc->GetNodes().Delete( aDelNd );
105 : }
106 : }
107 : else
108 : {
109 0 : SwTxtNode * pTNd = pDoc->GetNodes()[ nNode ]->GetTxtNode();
110 0 : if( pTNd )
111 : {
112 0 : rPam.GetPoint()->nNode = *pTNd;
113 0 : rPam.GetPoint()->nContent.Assign(pTNd, pTNd->GetTxt().getLength());
114 :
115 0 : if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
116 : {
117 0 : rPam.SetMark();
118 0 : rPam.GetMark()->nNode++;
119 0 : rPam.GetMark()->nContent.Assign( rPam.GetMark()->
120 0 : nNode.GetNode().GetCntntNode(), 0 );
121 0 : pDoc->DeleteRedline( rPam, true, USHRT_MAX );
122 0 : rPam.DeleteMark();
123 : }
124 :
125 0 : RemoveIdxRel( nNode+1, *rPam.GetPoint() );
126 :
127 0 : pTNd->JoinNext();
128 0 : if( pHistory )
129 : {
130 0 : rPam.GetPoint()->nContent = 0;
131 0 : rPam.SetMark();
132 0 : rPam.GetPoint()->nContent = pTNd->GetTxt().getLength();
133 :
134 0 : pDoc->RstTxtAttrs( rPam, true );
135 0 : pHistory->TmpRollback( pDoc, 0, false );
136 : }
137 :
138 0 : pDoc->UpdateParRsid( pTNd, nParRsid );
139 : }
140 : }
141 :
142 : // also set the cursor onto undo section
143 0 : rPam.DeleteMark();
144 0 : rPam.GetPoint()->nNode = nNode;
145 0 : rPam.GetPoint()->nContent.Assign( rPam.GetCntntNode(), nCntnt );
146 0 : }
147 :
148 0 : void SwUndoSplitNode::RedoImpl(::sw::UndoRedoContext & rContext)
149 : {
150 0 : SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
151 0 : rPam.GetPoint()->nNode = nNode;
152 0 : SwTxtNode * pTNd = rPam.GetNode()->GetTxtNode();
153 : OSL_ENSURE(pTNd, "SwUndoSplitNode::RedoImpl(): SwTxtNode expected");
154 0 : if (pTNd)
155 : {
156 0 : rPam.GetPoint()->nContent.Assign( pTNd, nCntnt );
157 :
158 0 : SwDoc* pDoc = rPam.GetDoc();
159 0 : pDoc->SplitNode( *rPam.GetPoint(), bChkTblStt );
160 :
161 0 : if( pHistory )
162 0 : pHistory->SetTmpEnd( pHistory->Count() );
163 :
164 0 : if( ( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() )) ||
165 0 : ( !( nsRedlineMode_t::REDLINE_IGNORE & GetRedlineMode() ) &&
166 0 : !pDoc->GetRedlineTbl().empty() ))
167 : {
168 0 : rPam.SetMark();
169 0 : if( rPam.Move( fnMoveBackward ))
170 : {
171 0 : if( pRedlData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineMode() ))
172 : {
173 0 : RedlineMode_t eOld = pDoc->GetRedlineMode();
174 0 : pDoc->SetRedlineMode_intern((RedlineMode_t)(eOld & ~nsRedlineMode_t::REDLINE_IGNORE));
175 0 : pDoc->AppendRedline( new SwRangeRedline( *pRedlData, rPam ), true);
176 0 : pDoc->SetRedlineMode_intern( eOld );
177 : }
178 : else
179 0 : pDoc->SplitRedline( rPam );
180 0 : rPam.Exchange();
181 : }
182 0 : rPam.DeleteMark();
183 : }
184 : }
185 0 : }
186 :
187 0 : void SwUndoSplitNode::RepeatImpl(::sw::RepeatContext & rContext)
188 : {
189 0 : rContext.GetDoc().SplitNode(
190 0 : *rContext.GetRepeatPaM().GetPoint(), bChkTblStt );
191 0 : }
192 :
193 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|