LibreOffice Module sw (master) 1
unnum.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 <UndoNumbering.hxx>
21#include <doc.hxx>
22#include <swundo.hxx>
23#include <pam.hxx>
24#include <ndtxt.hxx>
25#include <UndoCore.hxx>
26#include <rolbck.hxx>
27#include <utility>
28#include <osl/diagnose.h>
29
31 const SwNumRule& rNewRule,
32 const SwDoc& rDoc,
33 SwUndoId nUndoId)
34 : SwUndo( nUndoId, &rDoc ),
35 m_aNumRule( rNewRule ),
36 m_pOldNumRule( new SwNumRule( rOldRule )), m_nLRSavePos( 0 )
37{
38}
39
40SwUndoInsNum::SwUndoInsNum( const SwPaM& rPam, const SwNumRule& rRule )
41 : SwUndo( SwUndoId::INSNUM, &rPam.GetDoc() ), SwUndRng( rPam ),
42 m_aNumRule( rRule ),
43 m_nLRSavePos( 0 )
44{
45}
46
48 OUString aReplaceRule )
49 : SwUndo( SwUndoId::INSNUM, &rPos.GetNode().GetDoc() ),
50 m_aNumRule( rRule ),
51 m_sReplaceRule(std::move( aReplaceRule )), m_nLRSavePos( 0 )
52{
53 // No selection!
56 m_nSttNode = rPos.GetNodeIndex();
58}
59
61{
62 m_pHistory.reset();
63 m_pOldNumRule.reset();
64}
65
67{
68 SwRewriter aResult;
71 return aResult;
72}
73
75{
76 SwDoc & rDoc = rContext.GetDoc();
77
78 if( m_pOldNumRule )
80
81 if( m_pHistory )
82 {
83 if( m_nLRSavePos )
84 {
85 // Update immediately so that potential "old" LRSpaces will be valid again.
86 m_pHistory->TmpRollback( &rDoc, m_nLRSavePos );
87
88 }
89 m_pHistory->TmpRollback( &rDoc, 0 );
90 m_pHistory->SetTmpEnd( m_pHistory->Count() );
91 }
92
93 if (m_nSttNode)
94 {
95 AddUndoRedoPaM(rContext);
96 }
97}
98
100{
101 SwDoc & rDoc = rContext.GetDoc();
102
103 if ( m_pOldNumRule )
105 else if ( m_pHistory )
106 {
107 SwPaM & rPam( AddUndoRedoPaM(rContext) );
108 if( !m_sReplaceRule.isEmpty() )
109 {
111 }
112 else
113 {
114 // #i42921# - adapt to changed signature
115 rDoc.SetNumRule(rPam, m_aNumRule, false);
116 }
117 }
118}
119
121{
122 if( m_pHistory )
123 m_nLRSavePos = m_pHistory->Count();
124}
125
127{
128 SwDoc & rDoc( rContext.GetDoc() );
129 if ( m_nSttNode )
130 {
131 if( m_sReplaceRule.isEmpty() )
132 {
133 // #i42921# - adapt to changed signature
134 rDoc.SetNumRule(rContext.GetRepeatPaM(), m_aNumRule, false);
135 }
136 }
137 else
138 {
140 }
141}
142
144{
145 if( !m_pHistory )
146 m_pHistory.reset(new SwHistory);
147 return m_pHistory.get();
148}
149
151{
152 if( !m_pOldNumRule )
153 m_pOldNumRule.reset(new SwNumRule( rOld ));
154}
155
157 : SwUndo( SwUndoId::DELNUM, &rPam.GetDoc() ), SwUndRng( rPam )
158{
160 m_aNodes.reserve( std::min<sal_Int32>(sal_Int32(m_nEndNode - m_nSttNode), 255) );
161 m_pHistory.reset( new SwHistory );
162}
163
165{
166}
167
169{
170 SwDoc & rDoc = rContext.GetDoc();
171
172 m_pHistory->TmpRollback( &rDoc, 0 );
173 m_pHistory->SetTmpEnd( m_pHistory->Count() );
174
175 for( const auto& rNode : m_aNodes )
176 {
177 SwTextNode* pNd = rDoc.GetNodes()[ rNode.index ]->GetTextNode();
178 OSL_ENSURE( pNd, "Where has the TextNode gone?" );
179 pNd->SetAttrListLevel( rNode.level );
180
181 if( pNd->GetCondFormatColl() )
182 pNd->ChkCondColl();
183 }
184
185 AddUndoRedoPaM(rContext);
186}
187
189{
190 SwPaM & rPam( AddUndoRedoPaM(rContext) );
191 rContext.GetDoc().DelNumRules(rPam);
192}
193
195{
196 rContext.GetDoc().DelNumRules(rContext.GetRepeatPaM());
197}
198
200{
201 if( rNd.GetNumRule() )
202 {
203 m_aNodes.emplace_back( rNd.GetIndex(), rNd.GetActualListLevel() );
204 }
205}
206
207SwUndoMoveNum::SwUndoMoveNum( const SwPaM& rPam, SwNodeOffset nOff, bool bIsOutlMv )
208 : SwUndo( bIsOutlMv ? SwUndoId::OUTLINE_UD : SwUndoId::MOVENUM, &rPam.GetDoc() ),
209 SwUndRng( rPam ),
210 m_nNewStart( 0 ), m_nOffset( nOff )
211{
212 // nOffset: Down => 1
213 // Up => -1
214}
215
217{
218 SwNodeOffset nTmpStt = m_nSttNode, nTmpEnd = m_nEndNode;
219
220 if (m_nEndNode || m_nEndContent != COMPLETE_STRING) // section?
221 {
222 if( m_nNewStart < m_nSttNode ) // moved forwards
224 else
226 }
228
229 SwPaM & rPam( AddUndoRedoPaM(rContext) );
230 rContext.GetDoc().MoveParagraph( rPam, -m_nOffset,
232 m_nSttNode = nTmpStt;
233 m_nEndNode = nTmpEnd;
234}
235
237{
238 SwPaM & rPam( AddUndoRedoPaM(rContext) );
240}
241
243{
244 SwDoc & rDoc = rContext.GetDoc();
245 if( SwUndoId::OUTLINE_UD == GetId() )
246 {
247 rDoc.MoveOutlinePara(rContext.GetRepeatPaM(),
248 SwNodeOffset(0) < m_nOffset ? 1 : -1 );
249 }
250 else
251 {
252 rDoc.MoveParagraph(rContext.GetRepeatPaM(), m_nOffset);
253 }
254}
255
256SwUndoNumUpDown::SwUndoNumUpDown( const SwPaM& rPam, short nOff )
257 : SwUndo( nOff > 0 ? SwUndoId::NUMUP : SwUndoId::NUMDOWN, &rPam.GetDoc() ),
258 SwUndRng( rPam ),
259 m_nOffset( nOff )
260{
261 // nOffset: Down => 1
262 // Up => -1
263}
264
266{
267 SwPaM & rPam( AddUndoRedoPaM(rContext) );
268 rContext.GetDoc().NumUpDown(rPam, 1 != m_nOffset );
269}
270
272{
273 SwPaM & rPam( AddUndoRedoPaM(rContext) );
274 rContext.GetDoc().NumUpDown(rPam, 1 == m_nOffset);
275}
276
278{
279 rContext.GetDoc().NumUpDown(rContext.GetRepeatPaM(), 1 == m_nOffset);
280}
281
283 bool bNewNum)
284 : SwUndo( SwUndoId::NUMORNONUM, &rIdx.GetDoc() ),
285 m_nIndex( rIdx.GetIndex() ), mbNewNum(bNewNum),
286 mbOldNum(bOldNum)
287{
288}
289
290// #115901#, #i40034#
292{
293 SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), m_nIndex );
294 SwTextNode * pTextNd = aIdx.GetNode().GetTextNode();
295
296 if (nullptr != pTextNd)
297 {
298 pTextNd->SetCountedInList(mbOldNum);
299 }
300}
301
302// #115901#, #i40034#
304{
305 SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), m_nIndex );
306 SwTextNode * pTextNd = aIdx.GetNode().GetTextNode();
307
308 if (nullptr != pTextNd)
309 {
310 pTextNd->SetCountedInList(mbNewNum);
311 }
312}
313
315{
316 SwDoc & rDoc = rContext.GetDoc();
317 if (mbOldNum && ! mbNewNum)
318 {
319 rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->GetNode());
320 }
321 else if ( ! mbOldNum && mbNewNum )
322 {
323 rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->GetNode(), true);
324 }
325}
326
328 : SwUndo( SwUndoId::SETNUMRULESTART, &rPos.GetDoc() ),
329 m_nIndex( rPos.GetNodeIndex() ), m_nOldStart( USHRT_MAX ),
330 m_nNewStart( USHRT_MAX ), m_bSetStartValue( false ), m_bFlag( bFlg )
331{
332}
333
335 : SwUndo(SwUndoId::SETNUMRULESTART, &rPos.GetDoc())
336 , m_nIndex(rPos.GetNodeIndex())
337 , m_nOldStart(USHRT_MAX)
338 , m_nNewStart(nStt)
339 , m_bSetStartValue(true)
340 , m_bFlag(false)
341{
342 SwTextNode* pTextNd = rPos.GetNode().GetTextNode();
343 if ( pTextNd )
344 {
345 if ( pTextNd->HasAttrListRestartValue() )
346 {
347 m_nOldStart = o3tl::narrowing<sal_uInt16>(pTextNd->GetAttrListRestartValue());
348 }
349 else
350 {
351 m_nOldStart = USHRT_MAX; // indicating, that the list restart value is not set
352 }
353 }
354}
355
357{
358 SwDoc & rDoc = rContext.GetDoc();
359 SwPosition const aPos( *rDoc.GetNodes()[ m_nIndex ] );
360 if( m_bSetStartValue )
361 {
362 rDoc.SetNodeNumStart( aPos, m_nOldStart );
363 }
364 else
365 {
366 rDoc.SetNumRuleStart( aPos, !m_bFlag );
367 }
368}
369
371{
372 SwDoc & rDoc = rContext.GetDoc();
373 SwPosition const aPos( *rDoc.GetNodes()[ m_nIndex ] );
374 if( m_bSetStartValue )
375 {
376 rDoc.SetNodeNumStart( aPos, m_nNewStart );
377 }
378 else
379 {
380 rDoc.SetNumRuleStart( aPos, m_bFlag );
381 }
382}
383
385{
386 SwDoc & rDoc = rContext.GetDoc();
387 if( m_bSetStartValue )
388 {
390 }
391 else
392 {
393 rDoc.SetNumRuleStart(*rContext.GetRepeatPaM().GetPoint(), m_bFlag);
394 }
395}
396
397/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ UndoArg1
Definition: SwRewriter.hxx:29
void ChkCondColl(const SwTextFormatColl *pColl=nullptr)
Definition: node.cxx:2022
SwFormatColl * GetCondFormatColl() const
Definition: node.hxx:715
Definition: doc.hxx:197
bool MoveOutlinePara(const SwPaM &rPam, SwOutlineNodes::difference_type nOffset)
Outline - move up / move down.
Definition: docnum.cxx:447
void SetNodeNumStart(const SwPosition &rPos, sal_uInt16 nStt)
Definition: docnum.cxx:1033
bool NumOrNoNum(SwNode &rIdx, bool bDel=false)
Definition: docnum.cxx:2388
void ReplaceNumRule(const SwPosition &rPos, const OUString &rOldRule, const OUString &rNewRule)
Definition: docnum.cxx:1174
bool MoveParagraph(SwPaM &, SwNodeOffset nOffset, bool bIsOutlMv=false)
Move selected paragraphs (not only numberings) according to offsets.
Definition: docnum.cxx:1822
SwNodes & GetNodes()
Definition: doc.hxx:422
void DelNumRules(const SwPaM &, SwRootFrame const *pLayout=nullptr)
Definition: docnum.cxx:1316
void SetNumRuleStart(const SwPosition &rPos, bool bFlag=true)
Definition: docnum.cxx:1011
OUString SetNumRule(const SwPaM &, const SwNumRule &, bool bCreateNewList, SwRootFrame const *pLayout=nullptr, const OUString &sContinuedListId=OUString(), bool bSetItem=true, const bool bResetIndentAttrs=false)
Accept changes of outline styles for OutlineRule.
Definition: docnum.cxx:861
void ChgNumRuleFormats(const SwNumRule &rRule)
Definition: docnum.cxx:1095
bool NumUpDown(const SwPaM &, bool bDown, SwRootFrame const *pLayout=nullptr)
Definition: docnum.cxx:1706
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:123
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
const OUString & GetName() const
Definition: numrule.hxx:224
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:188
const SwPosition * GetPoint() const
Definition: pam.hxx:253
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:25
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
void SetAttrListLevel(int nLevel)
Sets the list level of this text node.
Definition: ndtxt.cxx:4218
SwNumberTree::tSwNumTreeNumber GetAttrListRestartValue() const
Definition: ndtxt.cxx:4332
void SetCountedInList(bool bCounted)
Definition: ndtxt.cxx:4378
SwNumRule * GetNumRule(bool bInParent=true) const
Returns numbering rule of this text node.
Definition: ndtxt.cxx:2921
int GetActualListLevel(SwListRedlineType eRedline=SwListRedlineType::SHOW) const
Returns the actual list level of this text node, when it is a list item.
Definition: ndtxt.cxx:4248
bool HasAttrListRestartValue() const
Definition: ndtxt.cxx:4327
SwPaM & AddUndoRedoPaM(::sw::UndoRedoContext &, bool const bCorrToContent=false) const
Definition: undobj.cxx:100
sal_Int32 m_nSttContent
Definition: undobj.hxx:232
SwNodeOffset m_nSttNode
Definition: undobj.hxx:231
SwNodeOffset m_nEndNode
Definition: undobj.hxx:231
sal_Int32 m_nEndContent
Definition: undobj.hxx:232
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:188
std::unique_ptr< SwHistory > m_pHistory
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unnum.cxx:194
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:168
SwUndoDelNum(const SwPaM &rPam)
Definition: unnum.cxx:156
void AddNode(const SwTextNode &rNd)
Definition: unnum.cxx:199
std::vector< NodeLevel > m_aNodes
virtual ~SwUndoDelNum() override
Definition: unnum.cxx:164
sal_uInt16 m_nLRSavePos
void SaveOldNumRule(const SwNumRule &rOld)
Definition: unnum.cxx:150
OUString m_sReplaceRule
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unnum.cxx:126
SwUndoInsNum(const SwPaM &rPam, const SwNumRule &rRule)
Definition: unnum.cxx:40
SwHistory * GetHistory()
Definition: unnum.cxx:143
void SetLRSpaceEndPos()
Definition: unnum.cxx:120
std::unique_ptr< SwNumRule > m_pOldNumRule
virtual ~SwUndoInsNum() override
Definition: unnum.cxx:60
std::unique_ptr< SwHistory > m_pHistory
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:74
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:99
SwNumRule m_aNumRule
virtual SwRewriter GetRewriter() const override
Returns the rewriter for this object.
Definition: unnum.cxx:66
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:236
SwUndoMoveNum(const SwPaM &rPam, SwNodeOffset nOffset, bool bIsOutlMv)
Definition: unnum.cxx:207
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:216
SwNodeOffset m_nOffset
SwNodeOffset m_nNewStart
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unnum.cxx:242
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unnum.cxx:314
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:291
SwNodeOffset m_nIndex
SwUndoNumOrNoNum(const SwNode &rIdx, bool mbOldNum, bool mbNewNum)
Definition: unnum.cxx:282
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:303
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:356
SwUndoNumRuleStart(const SwPosition &rPos, bool bDelete)
Definition: unnum.cxx:327
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:370
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unnum.cxx:384
SwNodeOffset m_nIndex
SwUndoNumUpDown(const SwPaM &rPam, short nOffset)
Definition: unnum.cxx:256
virtual void RepeatImpl(::sw::RepeatContext &) override
Definition: unnum.cxx:277
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:265
virtual void RedoImpl(::sw::UndoRedoContext &) override
Definition: unnum.cxx:271
SwUndoId GetId() const
Definition: undobj.hxx:102
SwDoc & GetDoc() const
Definition: UndoCore.hxx:132
SwPaM & GetRepeatPaM()
Definition: UndoCore.hxx:134
SwDoc & GetDoc() const
Definition: UndoCore.hxx:95
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
SwContentNode * GetNode(SwPaM &rPam, bool &rbFirst, SwMoveFnCollection const &fnMove, bool const bInReadOnly, SwRootFrame const *const i_pLayout)
This function returns the next node in direction of search.
Definition: pam.cxx:1043
Marks a position in the document model.
Definition: pam.hxx:38
SwNode & GetNode() const
Definition: pam.hxx:81
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:78
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
constexpr sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:57
SwUndoId
Definition: swundo.hxx:30
@ SETNUMRULESTART