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 <swundo.hxx>
27 #include <frmfmt.hxx>
28 #include <UndoCore.hxx>
29 #include <rolbck.hxx>
30 #include <redline.hxx>
31 #include <docary.hxx>
32 #include <IShellCursorSupplier.hxx>
33 #include <osl/diagnose.h>
34 
35 // SPLITNODE
36 
38  bool bChkTable )
39  : SwUndo( SwUndoId::SPLITNODE, pDoc ), nNode( rPos.nNode.GetIndex() ),
40  nContent( rPos.nContent.GetIndex() ),
41  bTableFlag( false ), bChkTableStt( bChkTable )
42 {
43  SwTextNode *const pTextNd = rPos.nNode.GetNode().GetTextNode();
44  OSL_ENSURE( pTextNd, "only for TextNode" );
45  if( pTextNd->GetpSwpHints() )
46  {
47  m_pHistory.reset(new SwHistory);
48  m_pHistory->CopyAttr(pTextNd->GetpSwpHints(), nNode, 0,
49  pTextNd->GetText().getLength(), false );
50  if (!m_pHistory->Count())
51  {
52  m_pHistory.reset();
53  }
54  }
55  // consider Redline
57  {
58  pRedlData.reset( new SwRedlineData( RedlineType::Insert, pDoc->getIDocumentRedlineAccess().GetRedlineAuthor() ) );
60  }
61 
62  nParRsid = pTextNd->GetParRsid();
63 }
64 
66 {
67  m_pHistory.reset();
68  pRedlData.reset();
69 }
70 
72 {
73  SwDoc *const pDoc = & rContext.GetDoc();
74  SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
75  rPam.DeleteMark();
76  if( bTableFlag )
77  {
78  // than a TextNode was added directly before the current table
79  SwNodeIndex& rIdx = rPam.GetPoint()->nNode;
80  rIdx = nNode;
81  SwTextNode* pTNd;
82  SwNode* pCurrNd = pDoc->GetNodes()[ nNode + 1 ];
83  SwTableNode* pTableNd = pCurrNd->FindTableNode();
84  if( pCurrNd->IsContentNode() && pTableNd &&
85  nullptr != ( pTNd = pDoc->GetNodes()[ pTableNd->GetIndex()-1 ]->GetTextNode() ))
86  {
87  // move break attributes
88  SwFrameFormat* pTableFormat = pTableNd->GetTable().GetFrameFormat();
89  const SfxItemSet* pNdSet = pTNd->GetpSwAttrSet();
90  if( pNdSet )
91  {
92  const SfxPoolItem *pItem;
93  if( SfxItemState::SET == pNdSet->GetItemState( RES_PAGEDESC, false,
94  &pItem ) )
95  pTableFormat->SetFormatAttr( *pItem );
96 
97  if( SfxItemState::SET == pNdSet->GetItemState( RES_BREAK, false,
98  &pItem ) )
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()[ 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( 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, nParRsid );
141  }
142  }
143 
144  // also set the cursor onto undo section
145  rPam.DeleteMark();
146  rPam.GetPoint()->nNode = nNode;
147  rPam.GetPoint()->nContent.Assign( rPam.GetContentNode(), nContent );
148 }
149 
151 {
152  SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
153  rPam.GetPoint()->nNode = nNode;
154  SwTextNode * pTNd = rPam.GetNode().GetTextNode();
155  OSL_ENSURE(pTNd, "SwUndoSplitNode::RedoImpl(): SwTextNode expected");
156  if (pTNd)
157  {
158  rPam.GetPoint()->nContent.Assign( pTNd, nContent );
159 
160  SwDoc* pDoc = rPam.GetDoc();
161  pDoc->getIDocumentContentOperations().SplitNode( *rPam.GetPoint(), bChkTableStt );
162 
163  if (m_pHistory)
164  {
165  m_pHistory->SetTmpEnd(m_pHistory->Count());
166  }
167 
171  {
172  rPam.SetMark();
173  if( rPam.Move( fnMoveBackward ))
174  {
176  {
179  pDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *pRedlData, rPam ), true);
181  }
182  else
183  pDoc->getIDocumentRedlineAccess().SplitRedline( rPam );
184  rPam.Exchange();
185  }
186  rPam.DeleteMark();
187  }
188  }
189 }
190 
192 {
194  *rContext.GetRepeatPaM().GetPoint(), bChkTableStt );
195 }
196 
197 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(93)
void DeleteMark()
Definition: pam.hxx:177
sal_uLong GetIndex() const
Definition: node.hxx:282
Marks a position in the document model.
Definition: pam.hxx:35
bool UpdateParRsid(SwTextNode *pTextNode, sal_uInt32 nVal=0)
Definition: docfmt.cxx:434
const OUString & GetText() const
Definition: ndtxt.hxx:211
SwUndoId
Definition: swundo.hxx:29
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:219
virtual ~SwUndoSplitNode() override
Definition: unspnd.cxx:65
virtual SwPaM & CreateNewShellCursor()=0
virtual AppendResult AppendRedline(SwRangeRedline *pNewRedl, bool bCallDelete)=0
Append a new redline.
sal_Int32 nContent
virtual void SetRedlineFlags_intern(RedlineFlags eMode)=0
Set a new redline mode.
SwNodeIndex nNode
Definition: pam.hxx:37
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:128
sal_uInt32 GetParRsid() const
Definition: ndtxt.cxx:5211
Definition: doc.hxx:186
std::unique_ptr< SwRedlineData > pRedlData
void SetRedlineFlags(RedlineFlags eMode)
Definition: undobj.hxx:119
constexpr TypedWhichId< SvxFormatBreakItem > RES_BREAK(94)
SwNode & GetNode() const
Definition: ndindex.hxx:119
SwUndoSplitNode(SwDoc *pDoc, const SwPosition &rPos, bool bChkTable)
Definition: unspnd.cxx:37
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:314
virtual SwContentNode * JoinNext() override
Definition: ndtxt.cxx:939
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:201
IShellCursorSupplier & GetCursorSupplier()
Definition: UndoCore.hxx:96
std::unique_ptr< SwHistory > m_pHistory
void Delete(const SwNodeIndex &rPos, sal_uLong nNodes=1)
delete nodes
Definition: nodes.cxx:1065
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unspnd.cxx:191
bool empty() const
Definition: docary.hxx:265
static bool IsRedlineOn(const RedlineFlags eM)
SwDoc & GetDoc() const
Definition: UndoCore.hxx:126
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unspnd.cxx:150
const SwTable & GetTable() const
Definition: node.hxx:497
SwDoc & GetDoc() const
Definition: UndoCore.hxx:94
RedlineFlags GetRedlineFlags() const
Definition: undobj.hxx:118
sal_uInt32 nParRsid
virtual std::size_t GetRedlineAuthor()=0
bool IsContentNode() const
Definition: node.hxx:628
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:443
Style of a layout element.
Definition: frmfmt.hxx:57
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SwPosition * GetPoint() const
Definition: pam.hxx:207
virtual bool DeleteRedline(const SwPaM &rPam, bool bSaveInUndo, RedlineType nDelType)=0
Marks a node in the document model.
Definition: ndindex.hxx:31
void RstTextAttrs(const SwPaM &rRg, bool bInclRefToxMark=false, bool bExactRange=false, SwRootFrame const *pLayout=nullptr)
Definition: docfmt.cxx:220
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
ignore Redlines
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
virtual bool SplitRedline(const SwPaM &rPam)=0
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:334
virtual bool IsRedlineOn() const =0
Query if redlining is on.
SwNodes & GetNodes()
Definition: doc.hxx:405
static void RemoveIdxRel(sal_uLong, const SwPosition &)
Definition: undobj.cxx:151
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unspnd.cxx:71
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:350
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:836
Base class of the Writer document model elements.
Definition: node.hxx:79