1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unnum.cxx,v $
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>
38 #include <swundo.hxx> // fuer die UndoIds
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
,
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 )
74 nEndNode
= 0, nEndCntnt
= USHRT_MAX
;
75 nSttNode
= rPos
.nNode
.GetIndex();
76 nSttCntnt
= rPos
.nContent
.GetIndex();
79 SwUndoInsNum::~SwUndoInsNum()
85 SwRewriter
SwUndoInsNum::GetRewriter() const
88 if( UNDO_INSFMTATTR
== GetId() )
89 aResult
.AddRule(UNDO_ARG1
, aNumRule
.GetName());
93 void SwUndoInsNum::Undo( SwUndoIter
& rUndoIter
)
95 SwDoc
& rDoc
= rUndoIter
.GetDoc();
99 BOOL bUndo
= rDoc
.DoesUndo();
100 rDoc
.DoUndo( FALSE
);
103 rDoc
.ChgNumRuleFmts( *pOldNumRule
);
108 if( ULONG_MAX
!= nSttSet
&&
109 0 != ( pNd
= rDoc
.GetNodes()[ nSttSet
]->GetTxtNode() ))
110 pNd
->SetListRestart( TRUE
);
117 // sofort Updaten, damit eventuell "alte" LRSpaces wieder
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
;
128 pNdRule
= pNd
->GetNumRule();
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() );
142 rDoc
.DoUndo( bUndo
);
146 void SwUndoInsNum::Redo( SwUndoIter
& rUndoIter
)
148 SwDoc
& rDoc
= rUndoIter
.GetDoc();
151 rDoc
.ChgNumRuleFmts( aNumRule
);
155 if( sReplaceRule
.Len() )
156 rDoc
.ReplaceNumRule( *rUndoIter
.pAktPam
->GetPoint(),
157 sReplaceRule
, aNumRule
.GetName() );
160 // --> OD 2005-02-25 #i42921# - adapt to changed signature
161 // --> OD 2008-03-18 #refactorlists#
162 rDoc
.SetNumRule( *rUndoIter
.pAktPam
, aNumRule
, false );
168 void SwUndoInsNum::SetLRSpaceEndPos()
171 nLRSavePos
= pHistory
->Count();
174 void SwUndoInsNum::Repeat( SwUndoIter
& rUndoIter
)
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 );
187 rUndoIter
.GetDoc().ChgNumRuleFmts( aNumRule
);
190 SwHistory
* SwUndoInsNum::GetHistory()
193 pHistory
= new SwHistory
;
197 void SwUndoInsNum::SaveOldNumRule( const SwNumRule
& rOld
)
200 pOldNumRule
= new SwNumRule( rOld
);
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()
221 void SwUndoDelNum::Undo( SwUndoIter
& rUndoIter
)
223 SwDoc
& rDoc
= rUndoIter
.GetDoc();
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() )
243 rDoc
.DoUndo( bUndo
);
247 void SwUndoDelNum::Redo( SwUndoIter
& rUndoIter
)
250 rUndoIter
.GetDoc().DelNumRules( *rUndoIter
.pAktPam
);
254 void SwUndoDelNum::Repeat( SwUndoIter
& 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
);
275 SwUndoMoveNum::SwUndoMoveNum( const SwPaM
& rPam
, long nOff
, BOOL bIsOutlMv
)
276 : SwUndo( bIsOutlMv
? UNDO_OUTLINE_UD
: UNDO_MOVENUM
),
278 nNewStt( 0 ), nOffset( nOff
)
280 // nOffset: nach unten => 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
);
294 nEndNode
= nEndNode
+ ( nNewStt
- nSttNode
);
298 //JP 22.06.95: wird wollen die Bookmarks/Verzeichnisse behalten, oder?
299 // SetPaM( rUndoIter );
300 // RemoveIdxFromRange( *rUndoIter.pAktPam, TRUE );
303 rUndoIter
.GetDoc().MoveParagraph( *rUndoIter
.pAktPam
, -nOffset
,
304 UNDO_OUTLINE_UD
== GetId() );
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 );
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 );
328 rUndoIter
.GetDoc().MoveParagraph( *rUndoIter
.pAktPam
, nOffset
, FALSE
);
334 SwUndoNumUpDown::SwUndoNumUpDown( const SwPaM
& rPam
, short nOff
)
335 : SwUndo( nOff
> 0 ? UNDO_NUMUP
: UNDO_NUMDOWN
), SwUndRng( rPam
),
338 // nOffset: Down => 1
343 void SwUndoNumUpDown::Undo( SwUndoIter
& rUndoIter
)
346 rUndoIter
.GetDoc().NumUpDown( *rUndoIter
.pAktPam
, 1 != nOffset
);
350 void SwUndoNumUpDown::Redo( SwUndoIter
& rUndoIter
)
353 rUndoIter
.GetDoc().NumUpDown( *rUndoIter
.pAktPam
, 1 == nOffset
);
357 void SwUndoNumUpDown::Repeat( SwUndoIter
& rUndoIter
)
359 rUndoIter
.GetDoc().NumUpDown( *rUndoIter
.pAktPam
, 1 == nOffset
);
365 SwUndoNumOrNoNum::SwUndoNumOrNoNum( const SwNodeIndex
& rIdx
, BOOL bOldNum
,
367 : SwUndo( UNDO_NUMORNONUM
), nIdx( rIdx
.GetIndex() ), mbNewNum(bNewNum
),
372 // #115901#, #i40034#
373 void SwUndoNumOrNoNum::Undo( SwUndoIter
& rUndoIter
)
375 SwNodeIndex
aIdx( rUndoIter
.GetDoc().GetNodes(), nIdx
);
376 SwTxtNode
* pTxtNd
= aIdx
.GetNode().GetTxtNode();
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();
392 pTxtNd
->SetCountedInList(mbNewNum
);
397 void SwUndoNumOrNoNum::Repeat( SwUndoIter
& rUndoIter
)
400 if (mbOldNum
&& ! mbNewNum
)
401 rUndoIter
.GetDoc().NumOrNoNum( rUndoIter
.pAktPam
->GetPoint()->nNode
,
403 else if ( ! mbOldNum
&& mbNewNum
)
404 rUndoIter
.GetDoc().NumOrNoNum( rUndoIter
.pAktPam
->GetPoint()->nNode
,
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();
425 // --> OD 2008-02-28 #refactorlists#
426 if ( pTxtNd
->HasAttrListRestartValue() )
428 nOldStt
= static_cast<USHORT
>(pTxtNd
->GetAttrListRestartValue());
432 nOldStt
= USHRT_MAX
; // indicating, that the list restart value is not set
439 void SwUndoNumRuleStart::Undo( SwUndoIter
& rUndoIter
)
441 SwPosition
aPos( *rUndoIter
.GetDoc().GetNodes()[ nIdx
] );
443 rUndoIter
.GetDoc().SetNodeNumStart( aPos
, nOldStt
);
445 rUndoIter
.GetDoc().SetNumRuleStart( aPos
, !bFlag
);
449 void SwUndoNumRuleStart::Redo( SwUndoIter
& rUndoIter
)
451 SwDoc
& rDoc
= rUndoIter
.GetDoc();
453 SwPosition
aPos( *rDoc
.GetNodes()[ nIdx
] );
455 rDoc
.SetNodeNumStart( aPos
, nNewStt
);
457 rDoc
.SetNumRuleStart( aPos
, bFlag
);
461 void SwUndoNumRuleStart::Repeat( SwUndoIter
& rUndoIter
)
464 rUndoIter
.GetDoc().SetNodeNumStart( *rUndoIter
.pAktPam
->GetPoint(), nNewStt
);
466 rUndoIter
.GetDoc().SetNumRuleStart( *rUndoIter
.pAktPam
->GetPoint(), bFlag
);