Update ooo320-m1
[ooovba.git] / sw / source / core / undo / unnum.cxx
blobdd2d59fc173cf6cd031395b6b7415a4171bd569e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unnum.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <hintids.hxx>
36 #include <svx/lrspitem.hxx>
37 #include <doc.hxx>
38 #include <swundo.hxx> // fuer die UndoIds
39 #include <pam.hxx>
40 #include <ndtxt.hxx>
41 #include <undobj.hxx>
42 #include <rolbck.hxx>
45 SV_DECL_PTRARR_DEL( _SfxPoolItems, SfxPoolItem*, 16, 16 )
46 SV_IMPL_PTRARR( _SfxPoolItems, SfxPoolItem* );
48 inline SwDoc& SwUndoIter::GetDoc() const { return *pAktPam->GetDoc(); }
50 SwUndoInsNum::SwUndoInsNum( const SwNumRule& rOldRule,
51 const SwNumRule& rNewRule,
52 SwUndoId nUndoId )
53 : SwUndo( nUndoId ),
54 aNumRule( rNewRule ), pHistory( 0 ), nSttSet( ULONG_MAX ),
55 pOldNumRule( new SwNumRule( rOldRule )), nLRSavePos( 0 )
59 SwUndoInsNum::SwUndoInsNum( const SwPaM& rPam, const SwNumRule& rRule )
60 : SwUndo( UNDO_INSNUM ), SwUndRng( rPam ),
61 aNumRule( rRule ), pHistory( 0 ),
62 nSttSet( ULONG_MAX ), pOldNumRule( 0 ), nLRSavePos( 0 )
66 SwUndoInsNum::SwUndoInsNum( const SwPosition& rPos, const SwNumRule& rRule,
67 const String& rReplaceRule )
68 : SwUndo( UNDO_INSNUM ),
69 aNumRule( rRule ), pHistory( 0 ),
70 nSttSet( ULONG_MAX ), pOldNumRule( 0 ),
71 sReplaceRule( rReplaceRule ), nLRSavePos( 0 )
73 // keine Selektion !!
74 nEndNode = 0, nEndCntnt = USHRT_MAX;
75 nSttNode = rPos.nNode.GetIndex();
76 nSttCntnt = rPos.nContent.GetIndex();
79 SwUndoInsNum::~SwUndoInsNum()
81 delete pHistory;
82 delete pOldNumRule;
85 SwRewriter SwUndoInsNum::GetRewriter() const
87 SwRewriter aResult;
88 if( UNDO_INSFMTATTR == GetId() )
89 aResult.AddRule(UNDO_ARG1, aNumRule.GetName());
90 return aResult;
93 void SwUndoInsNum::Undo( SwUndoIter& rUndoIter )
95 SwDoc& rDoc = rUndoIter.GetDoc();
96 if( nSttNode )
97 SetPaM( rUndoIter );
99 BOOL bUndo = rDoc.DoesUndo();
100 rDoc.DoUndo( FALSE );
102 if( pOldNumRule )
103 rDoc.ChgNumRuleFmts( *pOldNumRule );
105 if( pHistory )
107 SwTxtNode* pNd;
108 if( ULONG_MAX != nSttSet &&
109 0 != ( pNd = rDoc.GetNodes()[ nSttSet ]->GetTxtNode() ))
110 pNd->SetListRestart( TRUE );
111 else
112 pNd = 0;
115 if( nLRSavePos )
117 // sofort Updaten, damit eventuell "alte" LRSpaces wieder
118 // gueltig werden.
119 // !!! Dafuer suche aber erstmal den richtigen NumRule - Namen!
120 if( !pNd && nSttNode )
121 pNd = rDoc.GetNodes()[ nSttNode ]->GetTxtNode();
123 // This code seems to be superfluous because the methods
124 // don't have any known side effects.
125 // ToDo: iasue i83806 should be used to remove this code
126 const SwNumRule* pNdRule;
127 if( pNd )
128 pNdRule = pNd->GetNumRule();
129 else
130 pNdRule = rDoc.FindNumRulePtr( aNumRule.GetName() );
131 // End of ToDo for issue i83806
133 pHistory->TmpRollback( &rDoc, nLRSavePos );
136 pHistory->TmpRollback( &rDoc, 0 );
137 pHistory->SetTmpEnd( pHistory->Count() );
140 if( nSttNode )
141 SetPaM( rUndoIter );
142 rDoc.DoUndo( bUndo );
146 void SwUndoInsNum::Redo( SwUndoIter& rUndoIter )
148 SwDoc& rDoc = rUndoIter.GetDoc();
150 if( pOldNumRule )
151 rDoc.ChgNumRuleFmts( aNumRule );
152 else if( pHistory )
154 SetPaM( rUndoIter );
155 if( sReplaceRule.Len() )
156 rDoc.ReplaceNumRule( *rUndoIter.pAktPam->GetPoint(),
157 sReplaceRule, aNumRule.GetName() );
158 else
160 // --> OD 2005-02-25 #i42921# - adapt to changed signature
161 // --> OD 2008-03-18 #refactorlists#
162 rDoc.SetNumRule( *rUndoIter.pAktPam, aNumRule, false );
163 // <--
168 void SwUndoInsNum::SetLRSpaceEndPos()
170 if( pHistory )
171 nLRSavePos = pHistory->Count();
174 void SwUndoInsNum::Repeat( SwUndoIter& rUndoIter )
176 if( nSttNode )
178 if( !sReplaceRule.Len() )
180 // --> OD 2005-02-25 #i42921# - adapt to changed signature
181 // --> OD 2008-03-18 #refactorlists#
182 rUndoIter.GetDoc().SetNumRule( *rUndoIter.pAktPam, aNumRule, false );
183 // <--
186 else
187 rUndoIter.GetDoc().ChgNumRuleFmts( aNumRule );
190 SwHistory* SwUndoInsNum::GetHistory()
192 if( !pHistory )
193 pHistory = new SwHistory;
194 return pHistory;
197 void SwUndoInsNum::SaveOldNumRule( const SwNumRule& rOld )
199 if( !pOldNumRule )
200 pOldNumRule = new SwNumRule( rOld );
203 /* \f */
206 SwUndoDelNum::SwUndoDelNum( const SwPaM& rPam )
207 : SwUndo( UNDO_DELNUM ), SwUndRng( rPam ),
208 aNodeIdx( BYTE( nEndNode - nSttNode > 255 ? 255 : nEndNode - nSttNode )),
209 aLevels( BYTE( nEndNode - nSttNode > 255 ? 255 : nEndNode - nSttNode ))
211 pHistory = new SwHistory;
215 SwUndoDelNum::~SwUndoDelNum()
217 delete pHistory;
221 void SwUndoDelNum::Undo( SwUndoIter& rUndoIter )
223 SwDoc& rDoc = rUndoIter.GetDoc();
224 SetPaM( rUndoIter );
226 BOOL bUndo = rDoc.DoesUndo();
227 rDoc.DoUndo( FALSE );
229 pHistory->TmpRollback( &rDoc, 0 );
230 pHistory->SetTmpEnd( pHistory->Count() );
232 for( USHORT n = 0; n < aNodeIdx.Count(); ++n )
234 SwTxtNode* pNd = rDoc.GetNodes()[ aNodeIdx[ n ] ]->GetTxtNode();
235 ASSERT( pNd, "wo ist der TextNode geblieben?" );
236 pNd->SetAttrListLevel(aLevels[ n ] );
238 if( pNd->GetCondFmtColl() )
239 pNd->ChkCondColl();
242 SetPaM( rUndoIter );
243 rDoc.DoUndo( bUndo );
247 void SwUndoDelNum::Redo( SwUndoIter& rUndoIter )
249 SetPaM( rUndoIter );
250 rUndoIter.GetDoc().DelNumRules( *rUndoIter.pAktPam );
254 void SwUndoDelNum::Repeat( SwUndoIter& rUndoIter )
256 SetPaM( rUndoIter );
257 rUndoIter.GetDoc().DelNumRules( *rUndoIter.pAktPam );
260 void SwUndoDelNum::AddNode( const SwTxtNode& rNd, BOOL )
262 if( rNd.GetNumRule() )
264 USHORT nIns = aNodeIdx.Count();
265 aNodeIdx.Insert( rNd.GetIndex(), nIns );
267 aLevels.Insert( static_cast<BYTE>(rNd.GetActualListLevel()), nIns );
272 /* \f */
275 SwUndoMoveNum::SwUndoMoveNum( const SwPaM& rPam, long nOff, BOOL bIsOutlMv )
276 : SwUndo( bIsOutlMv ? UNDO_OUTLINE_UD : UNDO_MOVENUM ),
277 SwUndRng( rPam ),
278 nNewStt( 0 ), nOffset( nOff )
280 // nOffset: nach unten => 1
281 // nach oben => -1
285 void SwUndoMoveNum::Undo( SwUndoIter& rUndoIter )
287 ULONG nTmpStt = nSttNode, nTmpEnd = nEndNode;
289 if( nEndNode || USHRT_MAX != nEndCntnt ) // Bereich ?
291 if( nNewStt < nSttNode ) // nach vorne verschoben
292 nEndNode = nEndNode - ( nSttNode - nNewStt );
293 else
294 nEndNode = nEndNode + ( nNewStt - nSttNode );
296 nSttNode = nNewStt;
298 //JP 22.06.95: wird wollen die Bookmarks/Verzeichnisse behalten, oder?
299 // SetPaM( rUndoIter );
300 // RemoveIdxFromRange( *rUndoIter.pAktPam, TRUE );
302 SetPaM( rUndoIter );
303 rUndoIter.GetDoc().MoveParagraph( *rUndoIter.pAktPam, -nOffset,
304 UNDO_OUTLINE_UD == GetId() );
305 nSttNode = nTmpStt;
306 nEndNode = nTmpEnd;
310 void SwUndoMoveNum::Redo( SwUndoIter& rUndoIter )
312 //JP 22.06.95: wird wollen die Bookmarks/Verzeichnisse behalten, oder?
313 // SetPaM( rUndoIter );
314 // RemoveIdxFromRange( *rUndoIter.pAktPam, TRUE );
316 SetPaM( rUndoIter );
317 rUndoIter.GetDoc().MoveParagraph( *rUndoIter.pAktPam, nOffset,
318 UNDO_OUTLINE_UD == GetId() );
322 void SwUndoMoveNum::Repeat( SwUndoIter& rUndoIter )
324 if( UNDO_OUTLINE_UD == GetId() )
325 rUndoIter.GetDoc().MoveOutlinePara( *rUndoIter.pAktPam,
326 0 < nOffset ? 1 : -1 );
327 else
328 rUndoIter.GetDoc().MoveParagraph( *rUndoIter.pAktPam, nOffset, FALSE );
331 /* \f */
334 SwUndoNumUpDown::SwUndoNumUpDown( const SwPaM& rPam, short nOff )
335 : SwUndo( nOff > 0 ? UNDO_NUMUP : UNDO_NUMDOWN ), SwUndRng( rPam ),
336 nOffset( nOff )
338 // nOffset: Down => 1
339 // Up => -1
343 void SwUndoNumUpDown::Undo( SwUndoIter& rUndoIter )
345 SetPaM( rUndoIter );
346 rUndoIter.GetDoc().NumUpDown( *rUndoIter.pAktPam, 1 != nOffset );
350 void SwUndoNumUpDown::Redo( SwUndoIter& rUndoIter )
352 SetPaM( rUndoIter );
353 rUndoIter.GetDoc().NumUpDown( *rUndoIter.pAktPam, 1 == nOffset );
357 void SwUndoNumUpDown::Repeat( SwUndoIter& rUndoIter )
359 rUndoIter.GetDoc().NumUpDown( *rUndoIter.pAktPam, 1 == nOffset );
362 /* \f */
364 // #115901#
365 SwUndoNumOrNoNum::SwUndoNumOrNoNum( const SwNodeIndex& rIdx, BOOL bOldNum,
366 BOOL bNewNum)
367 : SwUndo( UNDO_NUMORNONUM ), nIdx( rIdx.GetIndex() ), mbNewNum(bNewNum),
368 mbOldNum(bOldNum)
372 // #115901#, #i40034#
373 void SwUndoNumOrNoNum::Undo( SwUndoIter& rUndoIter )
375 SwNodeIndex aIdx( rUndoIter.GetDoc().GetNodes(), nIdx );
376 SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
378 if (NULL != pTxtNd)
380 pTxtNd->SetCountedInList(mbOldNum);
384 // #115901#, #i40034#
385 void SwUndoNumOrNoNum::Redo( SwUndoIter& rUndoIter )
387 SwNodeIndex aIdx( rUndoIter.GetDoc().GetNodes(), nIdx );
388 SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
390 if (NULL != pTxtNd)
392 pTxtNd->SetCountedInList(mbNewNum);
396 // #115901#
397 void SwUndoNumOrNoNum::Repeat( SwUndoIter& rUndoIter )
400 if (mbOldNum && ! mbNewNum)
401 rUndoIter.GetDoc().NumOrNoNum( rUndoIter.pAktPam->GetPoint()->nNode,
402 FALSE);
403 else if ( ! mbOldNum && mbNewNum )
404 rUndoIter.GetDoc().NumOrNoNum( rUndoIter.pAktPam->GetPoint()->nNode,
405 TRUE);
408 /* \f */
410 SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, BOOL bFlg )
411 : SwUndo( UNDO_SETNUMRULESTART ),
412 nIdx( rPos.nNode.GetIndex() ), nOldStt( USHRT_MAX ),
413 nNewStt( USHRT_MAX ), bSetSttValue( FALSE ), bFlag( bFlg )
417 SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, USHORT nStt )
418 : SwUndo( UNDO_SETNUMRULESTART ),
419 nIdx( rPos.nNode.GetIndex() ),
420 nOldStt( USHRT_MAX ), nNewStt( nStt ), bSetSttValue( TRUE )
422 SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
423 if ( pTxtNd )
425 // --> OD 2008-02-28 #refactorlists#
426 if ( pTxtNd->HasAttrListRestartValue() )
428 nOldStt = static_cast<USHORT>(pTxtNd->GetAttrListRestartValue());
430 else
432 nOldStt = USHRT_MAX; // indicating, that the list restart value is not set
434 // <--
439 void SwUndoNumRuleStart::Undo( SwUndoIter& rUndoIter )
441 SwPosition aPos( *rUndoIter.GetDoc().GetNodes()[ nIdx ] );
442 if( bSetSttValue )
443 rUndoIter.GetDoc().SetNodeNumStart( aPos, nOldStt );
444 else
445 rUndoIter.GetDoc().SetNumRuleStart( aPos, !bFlag );
449 void SwUndoNumRuleStart::Redo( SwUndoIter& rUndoIter )
451 SwDoc& rDoc = rUndoIter.GetDoc();
453 SwPosition aPos( *rDoc.GetNodes()[ nIdx ] );
454 if( bSetSttValue )
455 rDoc.SetNodeNumStart( aPos, nNewStt );
456 else
457 rDoc.SetNumRuleStart( aPos, bFlag );
461 void SwUndoNumRuleStart::Repeat( SwUndoIter& rUndoIter )
463 if( bSetSttValue )
464 rUndoIter.GetDoc().SetNodeNumStart( *rUndoIter.pAktPam->GetPoint(), nNewStt );
465 else
466 rUndoIter.GetDoc().SetNumRuleStart( *rUndoIter.pAktPam->GetPoint(), bFlag );