LibreOffice Module sw (master)  1
unspnd.cxx
Go to the documentation of this file.
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>
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>
37 
38 // SPLITNODE
39 
41  bool bChkTable )
42  : SwUndo( SwUndoId::SPLITNODE, &rDoc ), m_nNode( rPos.nNode.GetIndex() ),
43  m_nContent( rPos.nContent.GetIndex() ),
44  m_bTableFlag( false ), m_bCheckTableStart( bChkTable )
45 {
46  SwTextNode *const pTextNd = rPos.nNode.GetNode().GetTextNode();
47  OSL_ENSURE( pTextNd, "only for TextNode" );
48  if( pTextNd->GetpSwpHints() )
49  {
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())
54  {
55  m_pHistory.reset();
56  }
57  }
58  // consider Redline
60  {
61  m_pRedlineData.reset( new SwRedlineData( RedlineType::Insert, rDoc.getIDocumentRedlineAccess().GetRedlineAuthor() ) );
63  }
64 
65  m_nParRsid = pTextNd->GetParRsid();
66 }
67 
69 {
70  m_pHistory.reset();
71  m_pRedlineData.reset();
72 }
73 
75 {
76  SwDoc *const pDoc = & rContext.GetDoc();
77  SwCursor & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
78  rPam.DeleteMark();
79  if( m_bTableFlag )
80  {
81  // than a TextNode was added directly before the current table
82  SwNodeIndex& rIdx = rPam.GetPoint()->nNode;
83  rIdx = 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() ))
89  {
90  // move break attributes
91  SwFrameFormat* pTableFormat = pTableNd->GetTable().GetFrameFormat();
92  const SfxItemSet* pNdSet = pTNd->GetpSwAttrSet();
93  if( pNdSet )
94  {
95  if( const SwFormatPageDesc* pItem = pNdSet->GetItemIfSet( RES_PAGEDESC, false ) )
96  pTableFormat->SetFormatAttr( *pItem );
97 
98  if( const SvxFormatBreakItem* pItem = pNdSet->GetItemIfSet( RES_BREAK, false ) )
99  pTableFormat->SetFormatAttr( *pItem );
100  }
101 
102  // than delete it again
103  SwNodeIndex aDelNd( *pTableNd, -1 );
104  rPam.GetPoint()->nContent.Assign( static_cast<SwContentNode*>(pCurrNd), 0 );
105  RemoveIdxRel( aDelNd.GetIndex(), *rPam.GetPoint() );
106  pDoc->GetNodes().Delete( aDelNd );
107  }
108  }
109  else
110  {
111  SwTextNode * pTNd = pDoc->GetNodes()[ m_nNode ]->GetTextNode();
112  if( pTNd )
113  {
114  rPam.GetPoint()->nNode = *pTNd;
115  rPam.GetPoint()->nContent.Assign(pTNd, pTNd->GetText().getLength());
116 
118  {
119  rPam.SetMark();
120  ++rPam.GetMark()->nNode;
121  rPam.GetMark()->nContent.Assign( rPam.GetMark()->
122  nNode.GetNode().GetContentNode(), 0 );
123  pDoc->getIDocumentRedlineAccess().DeleteRedline( rPam, true, RedlineType::Any );
124  rPam.DeleteMark();
125  }
126 
127  RemoveIdxRel( m_nNode+1, *rPam.GetPoint() );
128 
129  pTNd->JoinNext();
130  if (m_pHistory)
131  {
132  rPam.GetPoint()->nContent = 0;
133  rPam.SetMark();
134  rPam.GetPoint()->nContent = pTNd->GetText().getLength();
135 
136  pDoc->RstTextAttrs( rPam, true );
137  m_pHistory->TmpRollback( pDoc, 0, false );
138  }
139 
140  pDoc->UpdateParRsid( pTNd, m_nParRsid );
141  }
142  }
143 
144  // also set the cursor onto undo section
145  rPam.DeleteMark();
146  rPam.GetPoint()->nNode = m_nNode;
147  rPam.GetPoint()->nContent.Assign( rPam.GetContentNode(), m_nContent );
148 }
149 
151 {
152  SwCursor & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
153  rPam.GetPoint()->nNode = m_nNode;
154  SwTextNode * pTNd = rPam.GetNode().GetTextNode();
155  OSL_ENSURE(pTNd, "SwUndoSplitNode::RedoImpl(): SwTextNode expected");
156  if (!pTNd)
157  return;
158 
159  rPam.GetPoint()->nContent.Assign( pTNd, m_nContent );
160 
161  SwDoc& rDoc = rPam.GetDoc();
162  rDoc.getIDocumentContentOperations().SplitNode( *rPam.GetPoint(), m_bCheckTableStart );
163 
164  if (m_pHistory)
165  {
166  m_pHistory->SetTmpEnd(m_pHistory->Count());
167  }
168 
172  return;
173 
174  rPam.SetMark();
175  if( rPam.Move( fnMoveBackward ))
176  {
178  {
183  }
184  else
186  rPam.Exchange();
187  }
188  rPam.DeleteMark();
189 }
190 
192 {
194  *rContext.GetRepeatPaM().GetPoint(), m_bCheckTableStart );
195 }
196 
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SwCursor & CreateNewShellCursor()=0
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
void DeleteMark()
Definition: pam.hxx:178
SwNodeOffset m_nNode
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
Marks a position in the document model.
Definition: pam.hxx:36
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:35
bool UpdateParRsid(SwTextNode *pTextNode, sal_uInt32 nVal=0)
Definition: docfmt.cxx:436
const OUString & GetText() const
Definition: ndtxt.hxx:218
SwUndoId
Definition: swundo.hxx:29
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:226
virtual ~SwUndoSplitNode() override
Definition: unspnd.cxx:68
virtual AppendResult AppendRedline(SwRangeRedline *pNewRedl, bool bCallDelete)=0
Append a new redline.
virtual void SetRedlineFlags_intern(RedlineFlags eMode)=0
Set a new redline mode.
SwNodeIndex nNode
Definition: pam.hxx:38
sal_uInt32 m_nParRsid
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:134
sal_uInt32 GetParRsid() const
Definition: ndtxt.cxx:5217
Definition: doc.hxx:187
void SetRedlineFlags(RedlineFlags eMode)
Definition: undobj.hxx:120
constexpr TypedWhichId< SvxFormatBreakItem > RES_BREAK(94)
SwNode & GetNode() const
Definition: ndindex.hxx:128
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:315
virtual SwContentNode * JoinNext() override
Definition: ndtxt.cxx:982
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:204
IShellCursorSupplier & GetCursorSupplier()
Definition: UndoCore.hxx:97
std::unique_ptr< SwHistory > m_pHistory
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unspnd.cxx:191
bool empty() const
Definition: docary.hxx:266
static bool IsRedlineOn(const RedlineFlags eM)
SwDoc & GetDoc() const
Definition: UndoCore.hxx:132
sal_Int32 m_nContent
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unspnd.cxx:150
const SwTable & GetTable() const
Definition: node.hxx:506
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:161
SwDoc & GetDoc() const
Definition: UndoCore.hxx:95
RedlineFlags GetRedlineFlags() const
Definition: undobj.hxx:119
virtual std::size_t GetRedlineAuthor()=0
bool IsContentNode() const
Definition: node.hxx:638
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:457
Style of a layout element.
Definition: frmfmt.hxx:59
const SwPosition * GetPoint() const
Definition: pam.hxx:208
virtual bool DeleteRedline(const SwPaM &rPam, bool bSaveInUndo, RedlineType nDelType)=0
SwNodeOffset GetIndex() const
Definition: node.hxx:292
Marks a node in the document model.
Definition: ndindex.hxx:30
SwUndoSplitNode(SwDoc &rDoc, const SwPosition &rPos, bool bChkTable)
Definition: unspnd.cxx:40
void RstTextAttrs(const SwPaM &rRg, bool bInclRefToxMark=false, bool bExactRange=false, SwRootFrame const *pLayout=nullptr)
Definition: docfmt.cxx:221
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:448
ignore Redlines
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
virtual bool SplitRedline(const SwPaM &rPam)=0
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:335
std::unique_ptr< SwRedlineData > m_pRedlineData
virtual bool IsRedlineOn() const =0
Query if redlining is on.
SwNodes & GetNodes()
Definition: doc.hxx:408
void Delete(const SwNodeIndex &rPos, SwNodeOffset nNodes=SwNodeOffset(1))
delete nodes
Definition: nodes.cxx:1085
static void RemoveIdxRel(SwNodeOffset, const SwPosition &)
Definition: undobj.cxx:153
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unspnd.cxx:74
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:358
virtual bool SplitNode(const SwPosition &rPos, bool bChkTableStart)=0
Split a node at rPos (implemented only for TextNode).
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
virtual const SwRedlineTable & GetRedlineTable() const =0
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:864
bool m_bDetectedRangeSegmentation false
Base class of the Writer document model elements.
Definition: node.hxx:81