android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / core / undo / unspnd.cxx
blob8dc653303251541e7fa14c91e2ba1fdcc005e20c
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 <IDocumentRedlineAccess.hxx>
23 #include <pam.hxx>
24 #include <swtable.hxx>
25 #include <ndtxt.hxx>
26 #include <swcrsr.hxx>
27 #include <swundo.hxx>
28 #include <frmfmt.hxx>
29 #include <UndoCore.hxx>
30 #include <rolbck.hxx>
31 #include <redline.hxx>
32 #include <docary.hxx>
33 #include <fmtpdsc.hxx>
34 #include <IShellCursorSupplier.hxx>
35 #include <osl/diagnose.h>
36 #include <editeng/formatbreakitem.hxx>
38 // SPLITNODE
40 SwUndoSplitNode::SwUndoSplitNode( SwDoc& rDoc, const SwPosition& rPos,
41 bool bChkTable )
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())
55 m_pHistory.reset();
58 // consider Redline
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()
70 m_pHistory.reset();
71 m_pRedlineData.reset();
74 void SwUndoSplitNode::UndoImpl(::sw::UndoRedoContext & rContext)
76 SwDoc *const pDoc = & rContext.GetDoc();
77 SwCursor & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
78 rPam.DeleteMark();
79 if( m_bTableFlag )
81 // than a TextNode was added directly before the current table
82 SwPosition& rPos = *rPam.GetPoint();
83 rPos.Assign(m_nNode);
84 SwTextNode* pTNd;
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();
93 if( pNdSet )
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 );
108 else
110 SwTextNode * pTNd = pDoc->GetNodes()[ m_nNode ]->GetTextNode();
111 if( pTNd )
113 rPam.GetPoint()->Assign(*pTNd, pTNd->GetText().getLength());
115 if( IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() ))
117 rPam.SetMark();
118 rPam.GetMark()->Adjust(SwNodeOffset(1));
119 pDoc->getIDocumentRedlineAccess().DeleteRedline( rPam, true, RedlineType::Any );
120 rPam.DeleteMark();
123 RemoveIdxRel( m_nNode+1, *rPam.GetPoint() );
125 pTNd->JoinNext();
126 if (m_pHistory)
128 rPam.GetPoint()->SetContent(0);
129 rPam.SetMark();
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
141 rPam.DeleteMark();
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");
151 if (!pTNd)
152 return;
154 rPam.GetPoint()->SetContent( m_nContent );
156 SwDoc& rDoc = rPam.GetDoc();
157 rDoc.getIDocumentContentOperations().SplitNode( *rPam.GetPoint(), m_bCheckTableStart );
159 if (m_pHistory)
161 m_pHistory->SetTmpEnd(m_pHistory->Count());
164 if( !(( m_pRedlineData && IDocumentRedlineAccess::IsRedlineOn( GetRedlineFlags() )) ||
165 ( !( RedlineFlags::Ignore & GetRedlineFlags() ) &&
166 !rDoc.getIDocumentRedlineAccess().GetRedlineTable().empty() )))
167 return;
169 rPam.SetMark();
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 );
179 else
180 rDoc.getIDocumentRedlineAccess().SplitRedline( rPam );
181 rPam.Exchange();
183 rPam.DeleteMark();
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: */