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