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>
35#include <osl/diagnose.h>
37
38// SPLITNODE
39
41 bool bChkTable )
42 : SwUndo( SwUndoId::SPLITNODE, &rDoc ), m_nNode( rPos.GetNodeIndex() ),
43 m_nContent( rPos.GetContentIndex() ),
44 m_bTableFlag( false ), m_bCheckTableStart( bChkTable )
45{
46 SwTextNode *const pTextNd = rPos.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 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() ))
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 RemoveIdxRel( aDelNd.GetIndex(), *rPam.GetPoint() );
105 pDoc->GetNodes().Delete( aDelNd );
106 }
107 }
108 else
109 {
110 SwTextNode * pTNd = pDoc->GetNodes()[ m_nNode ]->GetTextNode();
111 if( pTNd )
112 {
113 rPam.GetPoint()->Assign(*pTNd, pTNd->GetText().getLength());
114
116 {
117 rPam.SetMark();
118 rPam.GetMark()->Adjust(SwNodeOffset(1));
119 pDoc->getIDocumentRedlineAccess().DeleteRedline( rPam, true, RedlineType::Any );
120 rPam.DeleteMark();
121 }
122
123 RemoveIdxRel( m_nNode+1, *rPam.GetPoint() );
124
125 pTNd->JoinNext();
126 if (m_pHistory)
127 {
128 rPam.GetPoint()->SetContent(0);
129 rPam.SetMark();
130 rPam.GetPoint()->SetContent(pTNd->GetText().getLength());
131
132 pDoc->RstTextAttrs( rPam, true );
133 m_pHistory->TmpRollback( pDoc, 0, false );
134 }
135
136 pDoc->UpdateParRsid( pTNd, m_nParRsid );
137 }
138 }
139
140 // also set the cursor onto undo section
141 rPam.DeleteMark();
142 rPam.GetPoint()->Assign( m_nNode, m_nContent );
143}
144
146{
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;
153
154 rPam.GetPoint()->SetContent( m_nContent );
155
156 SwDoc& rDoc = rPam.GetDoc();
158
159 if (m_pHistory)
160 {
161 m_pHistory->SetTmpEnd(m_pHistory->Count());
162 }
163
167 return;
168
169 rPam.SetMark();
170 if( rPam.Move( fnMoveBackward ))
171 {
173 {
178 }
179 else
181 rPam.Exchange();
182 }
183 rPam.DeleteMark();
184}
185
187{
190}
191
192/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ Ignore
ignore Redlines
virtual bool SplitNode(const SwPosition &rPos, bool bChkTableStart)=0
Split a node at rPos (implemented only for TextNode).
virtual bool IsRedlineOn() const =0
Query if redlining is on.
virtual bool DeleteRedline(const SwPaM &rPam, bool bSaveInUndo, RedlineType nDelType)=0
static bool IsRedlineOn(const RedlineFlags eM)
virtual std::size_t GetRedlineAuthor()=0
virtual bool SplitRedline(const SwPaM &rPam)=0
virtual void SetRedlineFlags_intern(RedlineFlags eMode)=0
Set a new redline mode.
virtual const SwRedlineTable & GetRedlineTable() const =0
virtual AppendResult AppendRedline(SwRangeRedline *pNewRedl, bool bCallDelete)=0
Append a new redline.
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SwAttrSet * GetpSwAttrSet() const
Definition: node.hxx:493
Definition: doc.hxx:197
void RstTextAttrs(const SwPaM &rRg, bool bInclRefToxMark=false, bool bExactRange=false, SwRootFrame const *pLayout=nullptr)
Definition: docfmt.cxx:228
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:329
SwNodes & GetNodes()
Definition: doc.hxx:422
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:349
bool UpdateParRsid(SwTextNode *pTextNode, sal_uInt32 nVal=0)
Definition: docfmt.cxx:442
Pagedescriptor Client of SwPageDesc that is "described" by the attribute.
Definition: fmtpdsc.hxx:36
virtual bool SetFormatAttr(const SfxPoolItem &rAttr)
Definition: format.cxx:447
Style of a layout element.
Definition: frmfmt.hxx:72
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:111
Base class of the Writer document model elements.
Definition: node.hxx:98
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:901
SwNodeOffset GetIndex() const
Definition: node.hxx:312
bool IsContentNode() const
Definition: node.hxx:188
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
void Delete(const SwNodeIndex &rPos, SwNodeOffset nNodes=SwNodeOffset(1))
Definition: nodes.cxx:1070
const SwPosition * GetMark() const
Definition: pam.hxx:255
SwNode & GetPointNode() const
Definition: pam.hxx:275
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:643
void Exchange()
Definition: pam.hxx:242
bool Move(SwMoveFnCollection const &fnMove=fnMoveForward, SwGoInDoc fnGo=GoInContent)
Movement of cursor.
Definition: pam.cxx:657
SwDoc & GetDoc() const
Definition: pam.hxx:291
void DeleteMark()
Definition: pam.hxx:232
const SwPosition * GetPoint() const
Definition: pam.hxx:253
bool empty() const
Definition: docary.hxx:267
const SwTable & GetTable() const
Definition: node.hxx:542
SwTableFormat * GetFrameFormat()
Definition: swtable.hxx:209
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
virtual SwContentNode * JoinNext() override
Definition: ndtxt.cxx:1002
sal_uInt32 GetParRsid() const
Definition: ndtxt.cxx:5387
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:252
const OUString & GetText() const
Definition: ndtxt.hxx:244
std::unique_ptr< SwHistory > m_pHistory
std::unique_ptr< SwRedlineData > m_pRedlineData
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unspnd.cxx:145
virtual ~SwUndoSplitNode() override
Definition: unspnd.cxx:68
sal_Int32 m_nContent
SwUndoSplitNode(SwDoc &rDoc, const SwPosition &rPos, bool bChkTable)
Definition: unspnd.cxx:40
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unspnd.cxx:186
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unspnd.cxx:74
sal_uInt32 m_nParRsid
SwNodeOffset m_nNode
void SetRedlineFlags(RedlineFlags eMode)
Definition: undobj.hxx:121
RedlineFlags GetRedlineFlags() const
Definition: undobj.hxx:120
static void RemoveIdxRel(SwNodeOffset, const SwPosition &)
Definition: undobj.cxx:144
virtual SwCursor & CreateNewShellCursor()=0
SwDoc & GetDoc() const
Definition: UndoCore.hxx:132
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:134
SwDoc & GetDoc() const
Definition: UndoCore.hxx:95
IShellCursorSupplier & GetCursorSupplier()
Definition: UndoCore.hxx:97
constexpr TypedWhichId< SwFormatPageDesc > RES_PAGEDESC(99)
constexpr TypedWhichId< SvxFormatBreakItem > RES_BREAK(100)
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
SwMoveFnCollection const & fnMoveBackward
Definition: paminit.cxx:60
Marks a position in the document model.
Definition: pam.hxx:38
void Adjust(SwNodeOffset nDelta)
Adjust node position, and resets content position to zero.
Definition: pam.cxx:257
SwNode & GetNode() const
Definition: pam.hxx:81
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:231
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:267
SwUndoId
Definition: swundo.hxx:30