1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26
27 #include <UndoNumbering.hxx>
28
29 #include <hintids.hxx>
30 #include <editeng/lrspitem.hxx>
31 #include <doc.hxx>
32 #include <IDocumentUndoRedo.hxx>
33 #include <swundo.hxx> // fuer die UndoIds
34 #include <pam.hxx>
35 #include <ndtxt.hxx>
36 #include <UndoCore.hxx>
37 #include <rolbck.hxx>
38
39
40 SV_DECL_PTRARR_DEL( _SfxPoolItems, SfxPoolItem*, 16, 16 )
41 SV_IMPL_PTRARR( _SfxPoolItems, SfxPoolItem* );
42
43
SwUndoInsNum(const SwNumRule & rOldRule,const SwNumRule & rNewRule,SwUndoId nUndoId)44 SwUndoInsNum::SwUndoInsNum( const SwNumRule& rOldRule,
45 const SwNumRule& rNewRule,
46 SwUndoId nUndoId )
47 : SwUndo( nUndoId ),
48 aNumRule( rNewRule ), pHistory( 0 ), nSttSet( ULONG_MAX ),
49 pOldNumRule( new SwNumRule( rOldRule )), nLRSavePos( 0 )
50 {
51 }
52
SwUndoInsNum(const SwPaM & rPam,const SwNumRule & rRule)53 SwUndoInsNum::SwUndoInsNum( const SwPaM& rPam, const SwNumRule& rRule )
54 : SwUndo( UNDO_INSNUM ), SwUndRng( rPam ),
55 aNumRule( rRule ), pHistory( 0 ),
56 nSttSet( ULONG_MAX ), pOldNumRule( 0 ), nLRSavePos( 0 )
57 {
58 }
59
SwUndoInsNum(const SwPosition & rPos,const SwNumRule & rRule,const String & rReplaceRule)60 SwUndoInsNum::SwUndoInsNum( const SwPosition& rPos, const SwNumRule& rRule,
61 const String& rReplaceRule )
62 : SwUndo( UNDO_INSNUM ),
63 aNumRule( rRule ), pHistory( 0 ),
64 nSttSet( ULONG_MAX ), pOldNumRule( 0 ),
65 sReplaceRule( rReplaceRule ), nLRSavePos( 0 )
66 {
67 // keine Selektion !!
68 nEndNode = 0, nEndCntnt = USHRT_MAX;
69 nSttNode = rPos.nNode.GetIndex();
70 nSttCntnt = rPos.nContent.GetIndex();
71 }
72
~SwUndoInsNum()73 SwUndoInsNum::~SwUndoInsNum()
74 {
75 delete pHistory;
76 delete pOldNumRule;
77 }
78
GetRewriter() const79 SwRewriter SwUndoInsNum::GetRewriter() const
80 {
81 SwRewriter aResult;
82 if( UNDO_INSFMTATTR == GetId() )
83 aResult.AddRule(UNDO_ARG1, aNumRule.GetName());
84 return aResult;
85 }
86
UndoImpl(::sw::UndoRedoContext & rContext)87 void SwUndoInsNum::UndoImpl(::sw::UndoRedoContext & rContext)
88 {
89 SwDoc & rDoc = rContext.GetDoc();
90
91 if( pOldNumRule )
92 rDoc.ChgNumRuleFmts( *pOldNumRule );
93
94 if( pHistory )
95 {
96 SwTxtNode* pNd;
97 if( ULONG_MAX != nSttSet &&
98 0 != ( pNd = rDoc.GetNodes()[ nSttSet ]->GetTxtNode() ))
99 pNd->SetListRestart( sal_True );
100 else
101 pNd = 0;
102
103
104 if( nLRSavePos )
105 {
106 // sofort Updaten, damit eventuell "alte" LRSpaces wieder
107 // gueltig werden.
108 // !!! Dafuer suche aber erstmal den richtigen NumRule - Namen!
109 if( !pNd && nSttNode )
110 pNd = rDoc.GetNodes()[ nSttNode ]->GetTxtNode();
111
112 // This code seems to be superfluous because the methods
113 // don't have any known side effects.
114 // ToDo: iasue i83806 should be used to remove this code
115 const SwNumRule* pNdRule;
116 if( pNd )
117 pNdRule = pNd->GetNumRule();
118 else
119 pNdRule = rDoc.FindNumRulePtr( aNumRule.GetName() );
120 // End of ToDo for issue i83806
121
122 pHistory->TmpRollback( &rDoc, nLRSavePos );
123
124 }
125 pHistory->TmpRollback( &rDoc, 0 );
126 pHistory->SetTmpEnd( pHistory->Count() );
127 }
128
129 if (nSttNode)
130 {
131 AddUndoRedoPaM(rContext);
132 }
133 }
134
RedoImpl(::sw::UndoRedoContext & rContext)135 void SwUndoInsNum::RedoImpl(::sw::UndoRedoContext & rContext)
136 {
137 SwDoc & rDoc = rContext.GetDoc();
138
139 if( pOldNumRule )
140 rDoc.ChgNumRuleFmts( aNumRule );
141 else if( pHistory )
142 {
143 SwPaM & rPam( AddUndoRedoPaM(rContext) );
144 if( sReplaceRule.Len() )
145 {
146 rDoc.ReplaceNumRule(*rPam.GetPoint(),
147 sReplaceRule, aNumRule.GetName() );
148 }
149 else
150 {
151 // --> OD 2005-02-25 #i42921# - adapt to changed signature
152 // --> OD 2008-03-18 #refactorlists#
153 rDoc.SetNumRule(rPam, aNumRule, false);
154 // <--
155 }
156 }
157 }
158
SetLRSpaceEndPos()159 void SwUndoInsNum::SetLRSpaceEndPos()
160 {
161 if( pHistory )
162 nLRSavePos = pHistory->Count();
163 }
164
RepeatImpl(::sw::RepeatContext & rContext)165 void SwUndoInsNum::RepeatImpl(::sw::RepeatContext & rContext)
166 {
167 SwDoc & rDoc(rContext.GetDoc());
168 if( nSttNode )
169 {
170 if( !sReplaceRule.Len() )
171 {
172 // --> OD 2005-02-25 #i42921# - adapt to changed signature
173 // --> OD 2008-03-18 #refactorlists#
174 rDoc.SetNumRule(rContext.GetRepeatPaM(), aNumRule, false);
175 // <--
176 }
177 }
178 else
179 {
180 rDoc.ChgNumRuleFmts( aNumRule );
181 }
182 }
183
GetHistory()184 SwHistory* SwUndoInsNum::GetHistory()
185 {
186 if( !pHistory )
187 pHistory = new SwHistory;
188 return pHistory;
189 }
190
SaveOldNumRule(const SwNumRule & rOld)191 void SwUndoInsNum::SaveOldNumRule( const SwNumRule& rOld )
192 {
193 if( !pOldNumRule )
194 pOldNumRule = new SwNumRule( rOld );
195 }
196
197 /* */
198
199
SwUndoDelNum(const SwPaM & rPam)200 SwUndoDelNum::SwUndoDelNum( const SwPaM& rPam )
201 : SwUndo( UNDO_DELNUM ), SwUndRng( rPam ),
202 aNodeIdx( sal_uInt8( nEndNode - nSttNode > 255 ? 255 : nEndNode - nSttNode ))
203 {
204 pHistory = new SwHistory;
205 }
206
~SwUndoDelNum()207 SwUndoDelNum::~SwUndoDelNum()
208 {
209 delete pHistory;
210 }
211
UndoImpl(::sw::UndoRedoContext & rContext)212 void SwUndoDelNum::UndoImpl(::sw::UndoRedoContext & rContext)
213 {
214 SwDoc & rDoc = rContext.GetDoc();
215
216 pHistory->TmpRollback( &rDoc, 0 );
217 pHistory->SetTmpEnd( pHistory->Count() );
218
219 for( sal_uInt16 n = 0; n < aNodeIdx.Count(); ++n )
220 {
221 SwTxtNode* pNd = rDoc.GetNodes()[ aNodeIdx[ n ] ]->GetTxtNode();
222 ASSERT( pNd, "Where is TextNode gone?" );
223 pNd->SetAttrListLevel(aLevels[ n ] );
224
225 if( pNd->GetCondFmtColl() )
226 pNd->ChkCondColl();
227 }
228
229 AddUndoRedoPaM(rContext);
230 }
231
RedoImpl(::sw::UndoRedoContext & rContext)232 void SwUndoDelNum::RedoImpl(::sw::UndoRedoContext & rContext)
233 {
234 SwPaM & rPam( AddUndoRedoPaM(rContext) );
235 rContext.GetDoc().DelNumRules(rPam);
236 }
237
RepeatImpl(::sw::RepeatContext & rContext)238 void SwUndoDelNum::RepeatImpl(::sw::RepeatContext & rContext)
239 {
240 rContext.GetDoc().DelNumRules(rContext.GetRepeatPaM());
241 }
242
AddNode(const SwTxtNode & rNd,sal_Bool)243 void SwUndoDelNum::AddNode( const SwTxtNode& rNd, sal_Bool )
244 {
245 if( rNd.GetNumRule() )
246 {
247 sal_uInt16 nIns = aNodeIdx.Count();
248 aNodeIdx.Insert( rNd.GetIndex(), nIns );
249
250 aLevels.insert( aLevels.begin() + nIns, static_cast<sal_uInt8>(rNd.GetActualListLevel()) );
251 }
252 }
253
254
255 /* */
256
257
SwUndoMoveNum(const SwPaM & rPam,long nOff,sal_Bool bIsOutlMv)258 SwUndoMoveNum::SwUndoMoveNum( const SwPaM& rPam, long nOff, sal_Bool bIsOutlMv )
259 : SwUndo( bIsOutlMv ? UNDO_OUTLINE_UD : UNDO_MOVENUM ),
260 SwUndRng( rPam ),
261 nNewStt( 0 ), nOffset( nOff )
262 {
263 // nOffset: nach unten => 1
264 // nach oben => -1
265 }
266
UndoImpl(::sw::UndoRedoContext & rContext)267 void SwUndoMoveNum::UndoImpl(::sw::UndoRedoContext & rContext)
268 {
269 sal_uLong nTmpStt = nSttNode, nTmpEnd = nEndNode;
270
271 if( nEndNode || USHRT_MAX != nEndCntnt ) // Bereich ?
272 {
273 if( nNewStt < nSttNode ) // nach vorne verschoben
274 nEndNode = nEndNode - ( nSttNode - nNewStt );
275 else
276 nEndNode = nEndNode + ( nNewStt - nSttNode );
277 }
278 nSttNode = nNewStt;
279
280 //JP 22.06.95: wird wollen die Bookmarks/Verzeichnisse behalten, oder?
281 // SetPaM( rUndoIter );
282 // RemoveIdxFromRange( *rUndoIter.pAktPam, sal_True );
283
284 SwPaM & rPam( AddUndoRedoPaM(rContext) );
285 rContext.GetDoc().MoveParagraph( rPam, -nOffset,
286 UNDO_OUTLINE_UD == GetId() );
287 nSttNode = nTmpStt;
288 nEndNode = nTmpEnd;
289 }
290
RedoImpl(::sw::UndoRedoContext & rContext)291 void SwUndoMoveNum::RedoImpl(::sw::UndoRedoContext & rContext)
292 {
293 //JP 22.06.95: wird wollen die Bookmarks/Verzeichnisse behalten, oder?
294 // SetPaM( rUndoIter );
295 // RemoveIdxFromRange( *rUndoIter.pAktPam, sal_True );
296
297 SwPaM & rPam( AddUndoRedoPaM(rContext) );
298 rContext.GetDoc().MoveParagraph(rPam, nOffset, UNDO_OUTLINE_UD == GetId());
299 }
300
RepeatImpl(::sw::RepeatContext & rContext)301 void SwUndoMoveNum::RepeatImpl(::sw::RepeatContext & rContext)
302 {
303 SwDoc & rDoc = rContext.GetDoc();
304 if( UNDO_OUTLINE_UD == GetId() )
305 {
306 rDoc.MoveOutlinePara(rContext.GetRepeatPaM(),
307 0 < nOffset ? 1 : -1 );
308 }
309 else
310 {
311 rDoc.MoveParagraph(rContext.GetRepeatPaM(), nOffset, sal_False);
312 }
313 }
314
315 /* */
316
317
SwUndoNumUpDown(const SwPaM & rPam,short nOff)318 SwUndoNumUpDown::SwUndoNumUpDown( const SwPaM& rPam, short nOff )
319 : SwUndo( nOff > 0 ? UNDO_NUMUP : UNDO_NUMDOWN ), SwUndRng( rPam ),
320 nOffset( nOff )
321 {
322 // nOffset: Down => 1
323 // Up => -1
324 }
325
UndoImpl(::sw::UndoRedoContext & rContext)326 void SwUndoNumUpDown::UndoImpl(::sw::UndoRedoContext & rContext)
327 {
328 SwPaM & rPam( AddUndoRedoPaM(rContext) );
329 rContext.GetDoc().NumUpDown(rPam, 1 != nOffset );
330 }
331
RedoImpl(::sw::UndoRedoContext & rContext)332 void SwUndoNumUpDown::RedoImpl(::sw::UndoRedoContext & rContext)
333 {
334 SwPaM & rPam( AddUndoRedoPaM(rContext) );
335 rContext.GetDoc().NumUpDown(rPam, 1 == nOffset);
336 }
337
RepeatImpl(::sw::RepeatContext & rContext)338 void SwUndoNumUpDown::RepeatImpl(::sw::RepeatContext & rContext)
339 {
340 rContext.GetDoc().NumUpDown(rContext.GetRepeatPaM(), 1 == nOffset);
341 }
342
343 /* */
344
345 // #115901#
SwUndoNumOrNoNum(const SwNodeIndex & rIdx,sal_Bool bOldNum,sal_Bool bNewNum)346 SwUndoNumOrNoNum::SwUndoNumOrNoNum( const SwNodeIndex& rIdx, sal_Bool bOldNum,
347 sal_Bool bNewNum)
348 : SwUndo( UNDO_NUMORNONUM ), nIdx( rIdx.GetIndex() ), mbNewNum(bNewNum),
349 mbOldNum(bOldNum)
350 {
351 }
352
353 // #115901#, #i40034#
UndoImpl(::sw::UndoRedoContext & rContext)354 void SwUndoNumOrNoNum::UndoImpl(::sw::UndoRedoContext & rContext)
355 {
356 SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), nIdx );
357 SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
358
359 if (NULL != pTxtNd)
360 {
361 pTxtNd->SetCountedInList(mbOldNum);
362 }
363 }
364
365 // #115901#, #i40034#
RedoImpl(::sw::UndoRedoContext & rContext)366 void SwUndoNumOrNoNum::RedoImpl(::sw::UndoRedoContext & rContext)
367 {
368 SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), nIdx );
369 SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
370
371 if (NULL != pTxtNd)
372 {
373 pTxtNd->SetCountedInList(mbNewNum);
374 }
375 }
376
377 // #115901#
RepeatImpl(::sw::RepeatContext & rContext)378 void SwUndoNumOrNoNum::RepeatImpl(::sw::RepeatContext & rContext)
379 {
380 SwDoc & rDoc = rContext.GetDoc();
381 if (mbOldNum && ! mbNewNum)
382 {
383 rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->nNode, sal_False);
384 }
385 else if ( ! mbOldNum && mbNewNum )
386 {
387 rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->nNode, sal_True);
388 }
389 }
390
391 /* */
392
SwUndoNumRuleStart(const SwPosition & rPos,sal_Bool bFlg)393 SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, sal_Bool bFlg )
394 : SwUndo( UNDO_SETNUMRULESTART ),
395 nIdx( rPos.nNode.GetIndex() ), nOldStt( USHRT_MAX ),
396 nNewStt( USHRT_MAX ), bSetSttValue( sal_False ), bFlag( bFlg )
397 {
398 }
399
SwUndoNumRuleStart(const SwPosition & rPos,sal_uInt16 nStt)400 SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, sal_uInt16 nStt )
401 : SwUndo( UNDO_SETNUMRULESTART ),
402 nIdx( rPos.nNode.GetIndex() ),
403 nOldStt( USHRT_MAX ), nNewStt( nStt ), bSetSttValue( sal_True )
404 {
405 SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
406 if ( pTxtNd )
407 {
408 // --> OD 2008-02-28 #refactorlists#
409 if ( pTxtNd->HasAttrListRestartValue() )
410 {
411 nOldStt = static_cast<sal_uInt16>(pTxtNd->GetAttrListRestartValue());
412 }
413 else
414 {
415 nOldStt = USHRT_MAX; // indicating, that the list restart value is not set
416 }
417 // <--
418 }
419 }
420
421
UndoImpl(::sw::UndoRedoContext & rContext)422 void SwUndoNumRuleStart::UndoImpl(::sw::UndoRedoContext & rContext)
423 {
424 SwDoc & rDoc = rContext.GetDoc();
425 SwPosition const aPos( *rDoc.GetNodes()[ nIdx ] );
426 if( bSetSttValue )
427 {
428 rDoc.SetNodeNumStart( aPos, nOldStt );
429 }
430 else
431 {
432 rDoc.SetNumRuleStart( aPos, !bFlag );
433 }
434 }
435
436
RedoImpl(::sw::UndoRedoContext & rContext)437 void SwUndoNumRuleStart::RedoImpl(::sw::UndoRedoContext & rContext)
438 {
439 SwDoc & rDoc = rContext.GetDoc();
440 SwPosition const aPos( *rDoc.GetNodes()[ nIdx ] );
441 if( bSetSttValue )
442 {
443 rDoc.SetNodeNumStart( aPos, nNewStt );
444 }
445 else
446 {
447 rDoc.SetNumRuleStart( aPos, bFlag );
448 }
449 }
450
451
RepeatImpl(::sw::RepeatContext & rContext)452 void SwUndoNumRuleStart::RepeatImpl(::sw::RepeatContext & rContext)
453 {
454 SwDoc & rDoc = rContext.GetDoc();
455 if( bSetSttValue )
456 {
457 rDoc.SetNodeNumStart(*rContext.GetRepeatPaM().GetPoint(), nNewStt);
458 }
459 else
460 {
461 rDoc.SetNumRuleStart(*rContext.GetRepeatPaM().GetPoint(), bFlag);
462 }
463 }
464
465
466