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>
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 #include <osl/diagnose.h>
36 
37 // SPLITNODE
38 
40  bool bChkTable )
41  : SwUndo( SwUndoId::SPLITNODE, pDoc ), nNode( rPos.nNode.GetIndex() ),
42  nContent( rPos.nContent.GetIndex() ),
43  bTableFlag( false ), bChkTableStt( bChkTable )
44 {
45  SwTextNode *const pTextNd = rPos.nNode.GetNode().GetTextNode();
46  OSL_ENSURE( pTextNd, "only for TextNode" );
47  if( pTextNd->GetpSwpHints() )
48  {
49  m_pHistory.reset(new SwHistory);
50  m_pHistory->CopyAttr(pTextNd->GetpSwpHints(), nNode, 0,
51  pTextNd->GetText().getLength(), false );
52  if (!m_pHistory->Count())
53  {
54  m_pHistory.reset();
55  }
56  }
57  // consider Redline
59  {
62  }
63 
64  nParRsid = pTextNd->GetParRsid();
65 }
66 
68 {
69  m_pHistory.reset();
70  pRedlData.reset();
71 }
72 
74 {
75  SwDoc *const pDoc = & rContext.GetDoc();
76  SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
77  rPam.DeleteMark();
78  if( bTableFlag )
79  {
80  // than a TextNode was added directly before the current table
81  SwNodeIndex& rIdx = rPam.GetPoint()->nNode;
82  rIdx = nNode;
83  SwTextNode* pTNd;
84  SwNode* pCurrNd = pDoc->GetNodes()[ nNode + 1 ];
85  SwTableNode* pTableNd = pCurrNd->FindTableNode();
86  if( pCurrNd->IsContentNode() && pTableNd &&
87  nullptr != ( pTNd = pDoc->GetNodes()[ pTableNd->GetIndex()-1 ]->GetTextNode() ))
88  {
89  // move break attributes
90  SwFrameFormat* pTableFormat = pTableNd->GetTable().GetFrameFormat();
91  const SfxItemSet* pNdSet = pTNd->GetpSwAttrSet();
92  if( pNdSet )
93  {
94  const SfxPoolItem *pItem;
95  if( SfxItemState::SET == pNdSet->GetItemState( RES_PAGEDESC, false,
96  &pItem ) )
97  pTableFormat->SetFormatAttr( *pItem );
98 
99  if( SfxItemState::SET == pNdSet->GetItemState( RES_BREAK, false,
100  &pItem ) )
101  pTableFormat->SetFormatAttr( *pItem );
102  }
103 
104  // than delete it again
105  SwNodeIndex aDelNd( *pTableNd, -1 );
106  rPam.GetPoint()->nContent.Assign( static_cast<SwContentNode*>(pCurrNd), 0 );
107  RemoveIdxRel( aDelNd.GetIndex(), *rPam.GetPoint() );
108  pDoc->GetNodes().Delete( aDelNd );
109  }
110  }
111  else
112  {
113  SwTextNode * pTNd = pDoc->GetNodes()[ nNode ]->GetTextNode();
114  if( pTNd )
115  {
116  rPam.GetPoint()->nNode = *pTNd;
117  rPam.GetPoint()->nContent.Assign(pTNd, pTNd->GetText().getLength());
118 
120  {
121  rPam.SetMark();
122  ++rPam.GetMark()->nNode;
123  rPam.GetMark()->nContent.Assign( rPam.GetMark()->
124  nNode.GetNode().GetContentNode(), 0 );
126  rPam.DeleteMark();
127  }
128 
129  RemoveIdxRel( nNode+1, *rPam.GetPoint() );
130 
131  pTNd->JoinNext();
132  if (m_pHistory)
133  {
134  rPam.GetPoint()->nContent = 0;
135  rPam.SetMark();
136  rPam.GetPoint()->nContent = pTNd->GetText().getLength();
137 
138  pDoc->RstTextAttrs( rPam, true );
139  m_pHistory->TmpRollback( pDoc, 0, false );
140  }
141 
142  pDoc->UpdateParRsid( pTNd, nParRsid );
143  }
144  }
145 
146  // also set the cursor onto undo section
147  rPam.DeleteMark();
148  rPam.GetPoint()->nNode = nNode;
149  rPam.GetPoint()->nContent.Assign( rPam.GetContentNode(), nContent );
150 }
151 
153 {
154  SwPaM & rPam( rContext.GetCursorSupplier().CreateNewShellCursor() );
155  rPam.GetPoint()->nNode = nNode;
156  SwTextNode * pTNd = rPam.GetNode().GetTextNode();
157  OSL_ENSURE(pTNd, "SwUndoSplitNode::RedoImpl(): SwTextNode expected");
158  if (pTNd)
159  {
160  rPam.GetPoint()->nContent.Assign( pTNd, nContent );
161 
162  SwDoc* pDoc = rPam.GetDoc();
163  pDoc->getIDocumentContentOperations().SplitNode( *rPam.GetPoint(), bChkTableStt );
164 
165  if (m_pHistory)
166  {
167  m_pHistory->SetTmpEnd(m_pHistory->Count());
168  }
169 
173  {
174  rPam.SetMark();
175  if( rPam.Move( fnMoveBackward ))
176  {
178  {
181  pDoc->getIDocumentRedlineAccess().AppendRedline( new SwRangeRedline( *pRedlData, rPam ), true);
183  }
184  else
185  pDoc->getIDocumentRedlineAccess().SplitRedline( rPam );
186  rPam.Exchange();
187  }
188  rPam.DeleteMark();
189  }
190  }
191 }
192 
194 {
196  *rContext.GetRepeatPaM().GetPoint(), bChkTableStt );
197 }
198 
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:462
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:67
virtual SwPaM & CreateNewShellCursor()=0
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:37
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:128
sal_uInt32 GetParRsid() const
Definition: ndtxt.cxx:5218
Definition: doc.hxx:185
std::unique_ptr< SwRedlineData > pRedlData
void SetRedlineFlags(RedlineFlags eMode)
Definition: undobj.hxx:119
SwNode & GetNode() const
Definition: ndindex.hxx:118
SwUndoSplitNode(SwDoc *pDoc, const SwPosition &rPos, bool bChkTable)
Definition: unspnd.cxx:39
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:347
virtual SwContentNode * JoinNext() override
Definition: ndtxt.cxx:949
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:1063
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unspnd.cxx:193
bool empty() const
Definition: docary.hxx:367
static bool IsRedlineOn(const RedlineFlags eM)
SwDoc & GetDoc() const
Definition: UndoCore.hxx:126
sal_uLong GetIndex() const
Definition: ndindex.hxx:151
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unspnd.cxx:152
const SwTable & GetTable() const
Definition: node.hxx:497
SwDoc & GetDoc() const
Definition: UndoCore.hxx:94
RedlineFlags GetRedlineFlags() const
Definition: undobj.hxx:118
sal_Int32 const nContent
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
bool const bChkTableStt
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:235
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:458
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:367
virtual bool IsRedlineOn() const =0
Query if redlining is on.
SwNodes & GetNodes()
Definition: doc.hxx:402
static void RemoveIdxRel(sal_uLong, const SwPosition &)
Definition: undobj.cxx:151
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unspnd.cxx:73
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:58
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:351
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
#define RES_PAGEDESC
Definition: hintids.hxx:198
#define RES_BREAK
Definition: hintids.hxx:199
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:843
Base class of the Writer document model elements.
Definition: node.hxx:79