1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <UndoNumbering.hxx>
21 #include <hintids.hxx>
22 #include <editeng/lrspitem.hxx>
24 #include <IDocumentUndoRedo.hxx>
28 #include <UndoCore.hxx>
31 SwUndoInsNum::SwUndoInsNum( const SwNumRule
& rOldRule
,
32 const SwNumRule
& rNewRule
,
35 aNumRule( rNewRule
), pHistory( 0 ), nSttSet( ULONG_MAX
),
36 pOldNumRule( new SwNumRule( rOldRule
)), nLRSavePos( 0 )
40 SwUndoInsNum::SwUndoInsNum( const SwPaM
& rPam
, const SwNumRule
& rRule
)
41 : SwUndo( UNDO_INSNUM
), SwUndRng( rPam
),
42 aNumRule( rRule
), pHistory( 0 ),
43 nSttSet( ULONG_MAX
), pOldNumRule( 0 ), nLRSavePos( 0 )
47 SwUndoInsNum::SwUndoInsNum( const SwPosition
& rPos
, const SwNumRule
& rRule
,
48 const String
& rReplaceRule
)
49 : SwUndo( UNDO_INSNUM
),
50 aNumRule( rRule
), pHistory( 0 ),
51 nSttSet( ULONG_MAX
), pOldNumRule( 0 ),
52 sReplaceRule( rReplaceRule
), nLRSavePos( 0 )
55 nEndNode
= 0, nEndCntnt
= USHRT_MAX
;
56 nSttNode
= rPos
.nNode
.GetIndex();
57 nSttCntnt
= rPos
.nContent
.GetIndex();
60 SwUndoInsNum::~SwUndoInsNum()
66 SwRewriter
SwUndoInsNum::GetRewriter() const
69 if( UNDO_INSFMTATTR
== GetId() )
70 aResult
.AddRule(UndoArg1
, aNumRule
.GetName());
74 void SwUndoInsNum::UndoImpl(::sw::UndoRedoContext
& rContext
)
76 SwDoc
& rDoc
= rContext
.GetDoc();
79 rDoc
.ChgNumRuleFmts( *pOldNumRule
);
84 if( ULONG_MAX
!= nSttSet
&&
85 0 != ( pNd
= rDoc
.GetNodes()[ nSttSet
]->GetTxtNode() ))
86 pNd
->SetListRestart( sal_True
);
93 // Update immediately so that potential "old" LRSpaces will be valid again.
94 // For that search firstly the correct NumRule names!
95 if( !pNd
&& nSttNode
)
96 pNd
= rDoc
.GetNodes()[ nSttNode
]->GetTxtNode();
98 pHistory
->TmpRollback( &rDoc
, nLRSavePos
);
101 pHistory
->TmpRollback( &rDoc
, 0 );
102 pHistory
->SetTmpEnd( pHistory
->Count() );
107 AddUndoRedoPaM(rContext
);
111 void SwUndoInsNum::RedoImpl(::sw::UndoRedoContext
& rContext
)
113 SwDoc
& rDoc
= rContext
.GetDoc();
116 rDoc
.ChgNumRuleFmts( aNumRule
);
119 SwPaM
& rPam( AddUndoRedoPaM(rContext
) );
120 if( sReplaceRule
.Len() )
122 rDoc
.ReplaceNumRule(*rPam
.GetPoint(),
123 sReplaceRule
, aNumRule
.GetName() );
127 // #i42921# - adapt to changed signature
128 rDoc
.SetNumRule(rPam
, aNumRule
, false);
133 void SwUndoInsNum::SetLRSpaceEndPos()
136 nLRSavePos
= pHistory
->Count();
139 void SwUndoInsNum::RepeatImpl(::sw::RepeatContext
& rContext
)
141 SwDoc
& rDoc(rContext
.GetDoc());
144 if( !sReplaceRule
.Len() )
146 // #i42921# - adapt to changed signature
147 rDoc
.SetNumRule(rContext
.GetRepeatPaM(), aNumRule
, false);
152 rDoc
.ChgNumRuleFmts( aNumRule
);
156 SwHistory
* SwUndoInsNum::GetHistory()
159 pHistory
= new SwHistory
;
163 void SwUndoInsNum::SaveOldNumRule( const SwNumRule
& rOld
)
166 pOldNumRule
= new SwNumRule( rOld
);
169 SwUndoDelNum::SwUndoDelNum( const SwPaM
& rPam
)
170 : SwUndo( UNDO_DELNUM
), SwUndRng( rPam
)
172 aNodes
.reserve( nEndNode
- nSttNode
> 255 ? 255 : nEndNode
- nSttNode
);
173 pHistory
= new SwHistory
;
176 SwUndoDelNum::~SwUndoDelNum()
181 void SwUndoDelNum::UndoImpl(::sw::UndoRedoContext
& rContext
)
183 SwDoc
& rDoc
= rContext
.GetDoc();
185 pHistory
->TmpRollback( &rDoc
, 0 );
186 pHistory
->SetTmpEnd( pHistory
->Count() );
188 for( std::vector
<NodeLevel
>::const_iterator i
= aNodes
.begin(); i
!= aNodes
.end(); ++i
)
190 SwTxtNode
* pNd
= rDoc
.GetNodes()[ i
->index
]->GetTxtNode();
191 OSL_ENSURE( pNd
, "Where has the TextNode gone?" );
192 pNd
->SetAttrListLevel( i
->level
);
194 if( pNd
->GetCondFmtColl() )
198 AddUndoRedoPaM(rContext
);
201 void SwUndoDelNum::RedoImpl(::sw::UndoRedoContext
& rContext
)
203 SwPaM
& rPam( AddUndoRedoPaM(rContext
) );
204 rContext
.GetDoc().DelNumRules(rPam
);
207 void SwUndoDelNum::RepeatImpl(::sw::RepeatContext
& rContext
)
209 rContext
.GetDoc().DelNumRules(rContext
.GetRepeatPaM());
212 void SwUndoDelNum::AddNode( const SwTxtNode
& rNd
, sal_Bool
)
214 if( rNd
.GetNumRule() )
216 aNodes
.push_back( NodeLevel( rNd
.GetIndex(), rNd
.GetActualListLevel() ) );
220 SwUndoMoveNum::SwUndoMoveNum( const SwPaM
& rPam
, long nOff
, bool bIsOutlMv
)
221 : SwUndo( bIsOutlMv
? UNDO_OUTLINE_UD
: UNDO_MOVENUM
),
223 nNewStt( 0 ), nOffset( nOff
)
225 // nOffset: Down => 1
229 void SwUndoMoveNum::UndoImpl(::sw::UndoRedoContext
& rContext
)
231 sal_uLong nTmpStt
= nSttNode
, nTmpEnd
= nEndNode
;
233 if( nEndNode
|| USHRT_MAX
!= nEndCntnt
) // section?
235 if( nNewStt
< nSttNode
) // moved forwards
236 nEndNode
= nEndNode
- ( nSttNode
- nNewStt
);
238 nEndNode
= nEndNode
+ ( nNewStt
- nSttNode
);
242 SwPaM
& rPam( AddUndoRedoPaM(rContext
) );
243 rContext
.GetDoc().MoveParagraph( rPam
, -nOffset
,
244 UNDO_OUTLINE_UD
== GetId() );
249 void SwUndoMoveNum::RedoImpl(::sw::UndoRedoContext
& rContext
)
251 SwPaM
& rPam( AddUndoRedoPaM(rContext
) );
252 rContext
.GetDoc().MoveParagraph(rPam
, nOffset
, UNDO_OUTLINE_UD
== GetId());
255 void SwUndoMoveNum::RepeatImpl(::sw::RepeatContext
& rContext
)
257 SwDoc
& rDoc
= rContext
.GetDoc();
258 if( UNDO_OUTLINE_UD
== GetId() )
260 rDoc
.MoveOutlinePara(rContext
.GetRepeatPaM(),
261 0 < nOffset
? 1 : -1 );
265 rDoc
.MoveParagraph(rContext
.GetRepeatPaM(), nOffset
, false);
269 SwUndoNumUpDown::SwUndoNumUpDown( const SwPaM
& rPam
, short nOff
)
270 : SwUndo( nOff
> 0 ? UNDO_NUMUP
: UNDO_NUMDOWN
), SwUndRng( rPam
),
273 // nOffset: Down => 1
277 void SwUndoNumUpDown::UndoImpl(::sw::UndoRedoContext
& rContext
)
279 SwPaM
& rPam( AddUndoRedoPaM(rContext
) );
280 rContext
.GetDoc().NumUpDown(rPam
, 1 != nOffset
);
283 void SwUndoNumUpDown::RedoImpl(::sw::UndoRedoContext
& rContext
)
285 SwPaM
& rPam( AddUndoRedoPaM(rContext
) );
286 rContext
.GetDoc().NumUpDown(rPam
, 1 == nOffset
);
289 void SwUndoNumUpDown::RepeatImpl(::sw::RepeatContext
& rContext
)
291 rContext
.GetDoc().NumUpDown(rContext
.GetRepeatPaM(), 1 == nOffset
);
295 SwUndoNumOrNoNum::SwUndoNumOrNoNum( const SwNodeIndex
& rIdx
, sal_Bool bOldNum
,
297 : SwUndo( UNDO_NUMORNONUM
), nIdx( rIdx
.GetIndex() ), mbNewNum(bNewNum
),
302 // #115901#, #i40034#
303 void SwUndoNumOrNoNum::UndoImpl(::sw::UndoRedoContext
& rContext
)
305 SwNodeIndex
aIdx( rContext
.GetDoc().GetNodes(), nIdx
);
306 SwTxtNode
* pTxtNd
= aIdx
.GetNode().GetTxtNode();
310 pTxtNd
->SetCountedInList(mbOldNum
);
314 // #115901#, #i40034#
315 void SwUndoNumOrNoNum::RedoImpl(::sw::UndoRedoContext
& rContext
)
317 SwNodeIndex
aIdx( rContext
.GetDoc().GetNodes(), nIdx
);
318 SwTxtNode
* pTxtNd
= aIdx
.GetNode().GetTxtNode();
322 pTxtNd
->SetCountedInList(mbNewNum
);
327 void SwUndoNumOrNoNum::RepeatImpl(::sw::RepeatContext
& rContext
)
329 SwDoc
& rDoc
= rContext
.GetDoc();
330 if (mbOldNum
&& ! mbNewNum
)
332 rDoc
.NumOrNoNum(rContext
.GetRepeatPaM().GetPoint()->nNode
, false);
334 else if ( ! mbOldNum
&& mbNewNum
)
336 rDoc
.NumOrNoNum(rContext
.GetRepeatPaM().GetPoint()->nNode
, true);
340 SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition
& rPos
, sal_Bool bFlg
)
341 : SwUndo( UNDO_SETNUMRULESTART
),
342 nIdx( rPos
.nNode
.GetIndex() ), nOldStt( USHRT_MAX
),
343 nNewStt( USHRT_MAX
), bSetSttValue( sal_False
), bFlag( bFlg
)
347 SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition
& rPos
, sal_uInt16 nStt
)
348 : SwUndo( UNDO_SETNUMRULESTART
),
349 nIdx( rPos
.nNode
.GetIndex() ),
350 nOldStt( USHRT_MAX
), nNewStt( nStt
), bSetSttValue( sal_True
)
352 SwTxtNode
* pTxtNd
= rPos
.nNode
.GetNode().GetTxtNode();
355 if ( pTxtNd
->HasAttrListRestartValue() )
357 nOldStt
= static_cast<sal_uInt16
>(pTxtNd
->GetAttrListRestartValue());
361 nOldStt
= USHRT_MAX
; // indicating, that the list restart value is not set
366 void SwUndoNumRuleStart::UndoImpl(::sw::UndoRedoContext
& rContext
)
368 SwDoc
& rDoc
= rContext
.GetDoc();
369 SwPosition
const aPos( *rDoc
.GetNodes()[ nIdx
] );
372 rDoc
.SetNodeNumStart( aPos
, nOldStt
);
376 rDoc
.SetNumRuleStart( aPos
, !bFlag
);
380 void SwUndoNumRuleStart::RedoImpl(::sw::UndoRedoContext
& rContext
)
382 SwDoc
& rDoc
= rContext
.GetDoc();
383 SwPosition
const aPos( *rDoc
.GetNodes()[ nIdx
] );
386 rDoc
.SetNodeNumStart( aPos
, nNewStt
);
390 rDoc
.SetNumRuleStart( aPos
, bFlag
);
394 void SwUndoNumRuleStart::RepeatImpl(::sw::RepeatContext
& rContext
)
396 SwDoc
& rDoc
= rContext
.GetDoc();
399 rDoc
.SetNodeNumStart(*rContext
.GetRepeatPaM().GetPoint(), nNewStt
);
403 rDoc
.SetNumRuleStart(*rContext
.GetRepeatPaM().GetPoint(), bFlag
);
407 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */