Files
libreoffice/sw/source/core/undo/unnum.cxx

469 lines
12 KiB
C++
Raw Normal View History

2000-09-18 23:08:29 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 23:08:29 +00:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 23:08:29 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 23:08:29 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 23:08:29 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
2000-09-18 23:08:29 +00:00
#include <hintids.hxx>
#include <editeng/lrspitem.hxx>
2000-09-18 23:08:29 +00:00
#include <doc.hxx>
#include <IDocumentUndoRedo.hxx>
2000-09-18 23:08:29 +00:00
#include <swundo.hxx> // fuer die UndoIds
#include <pam.hxx>
#include <ndtxt.hxx>
#include <UndoCore.hxx>
2000-09-18 23:08:29 +00:00
#include <rolbck.hxx>
SV_DECL_PTRARR_DEL( _SfxPoolItems, SfxPoolItem*, 16, 16 )
2000-09-18 23:08:29 +00:00
SV_IMPL_PTRARR( _SfxPoolItems, SfxPoolItem* );
SwUndoInsNum::SwUndoInsNum( const SwNumRule& rOldRule,
const SwNumRule& rNewRule,
SwUndoId nUndoId )
: SwUndo( nUndoId ),
aNumRule( rNewRule ), pHistory( 0 ), nSttSet( ULONG_MAX ),
pOldNumRule( new SwNumRule( rOldRule )), nLRSavePos( 0 )
2000-09-18 23:08:29 +00:00
{
}
SwUndoInsNum::SwUndoInsNum( const SwPaM& rPam, const SwNumRule& rRule )
: SwUndo( UNDO_INSNUM ), SwUndRng( rPam ),
aNumRule( rRule ), pHistory( 0 ),
nSttSet( ULONG_MAX ), pOldNumRule( 0 ), nLRSavePos( 0 )
2000-09-18 23:08:29 +00:00
{
}
SwUndoInsNum::SwUndoInsNum( const SwPosition& rPos, const SwNumRule& rRule,
const String& rReplaceRule )
: SwUndo( UNDO_INSNUM ),
aNumRule( rRule ), pHistory( 0 ),
2000-09-18 23:08:29 +00:00
nSttSet( ULONG_MAX ), pOldNumRule( 0 ),
sReplaceRule( rReplaceRule ), nLRSavePos( 0 )
2000-09-18 23:08:29 +00:00
{
// keine Selektion !!
nEndNode = 0, nEndCntnt = USHRT_MAX;
nSttNode = rPos.nNode.GetIndex();
nSttCntnt = rPos.nContent.GetIndex();
}
SwUndoInsNum::~SwUndoInsNum()
{
delete pHistory;
delete pOldNumRule;
}
SwRewriter SwUndoInsNum::GetRewriter() const
{
SwRewriter aResult;
if( UNDO_INSFMTATTR == GetId() )
aResult.AddRule(UNDO_ARG1, aNumRule.GetName());
return aResult;
}
void SwUndoInsNum::UndoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc = rContext.GetDoc();
2000-09-18 23:08:29 +00:00
if( pOldNumRule )
rDoc.ChgNumRuleFmts( *pOldNumRule );
if( pHistory )
{
SwTxtNode* pNd;
if( ULONG_MAX != nSttSet &&
0 != ( pNd = rDoc.GetNodes()[ nSttSet ]->GetTxtNode() ))
pNd->SetListRestart( TRUE );
2000-09-18 23:08:29 +00:00
else
pNd = 0;
if( nLRSavePos )
{
// sofort Updaten, damit eventuell "alte" LRSpaces wieder
// gueltig werden.
// !!! Dafuer suche aber erstmal den richtigen NumRule - Namen!
if( !pNd && nSttNode )
pNd = rDoc.GetNodes()[ nSttNode ]->GetTxtNode();
// This code seems to be superfluous because the methods
// don't have any known side effects.
// ToDo: iasue i83806 should be used to remove this code
2000-09-18 23:08:29 +00:00
const SwNumRule* pNdRule;
if( pNd )
pNdRule = pNd->GetNumRule();
else
pNdRule = rDoc.FindNumRulePtr( aNumRule.GetName() );
// End of ToDo for issue i83806
2000-09-18 23:08:29 +00:00
pHistory->TmpRollback( &rDoc, nLRSavePos );
2000-09-18 23:08:29 +00:00
}
pHistory->TmpRollback( &rDoc, 0 );
pHistory->SetTmpEnd( pHistory->Count() );
}
if (nSttNode)
{
AddUndoRedoPaM(rContext);
}
2000-09-18 23:08:29 +00:00
}
void SwUndoInsNum::RedoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc = rContext.GetDoc();
2000-09-18 23:08:29 +00:00
if( pOldNumRule )
rDoc.ChgNumRuleFmts( aNumRule );
else if( pHistory )
{
SwPaM & rPam( AddUndoRedoPaM(rContext) );
2000-09-18 23:08:29 +00:00
if( sReplaceRule.Len() )
{
rDoc.ReplaceNumRule(*rPam.GetPoint(),
2000-09-18 23:08:29 +00:00
sReplaceRule, aNumRule.GetName() );
}
2000-09-18 23:08:29 +00:00
else
{
// --> OD 2005-02-25 #i42921# - adapt to changed signature
// --> OD 2008-03-18 #refactorlists#
rDoc.SetNumRule(rPam, aNumRule, false);
// <--
}
2000-09-18 23:08:29 +00:00
}
}
void SwUndoInsNum::SetLRSpaceEndPos()
{
if( pHistory )
nLRSavePos = pHistory->Count();
}
void SwUndoInsNum::RepeatImpl(::sw::RepeatContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc(rContext.GetDoc());
2000-09-18 23:08:29 +00:00
if( nSttNode )
{
if( !sReplaceRule.Len() )
{
// --> OD 2005-02-25 #i42921# - adapt to changed signature
// --> OD 2008-03-18 #refactorlists#
rDoc.SetNumRule(rContext.GetRepeatPaM(), aNumRule, false);
// <--
}
2000-09-18 23:08:29 +00:00
}
else
{
rDoc.ChgNumRuleFmts( aNumRule );
}
2000-09-18 23:08:29 +00:00
}
SwHistory* SwUndoInsNum::GetHistory()
{
if( !pHistory )
pHistory = new SwHistory;
return pHistory;
}
void SwUndoInsNum::SaveOldNumRule( const SwNumRule& rOld )
{
if( !pOldNumRule )
pOldNumRule = new SwNumRule( rOld );
}
/* */
2000-09-18 23:08:29 +00:00
SwUndoDelNum::SwUndoDelNum( const SwPaM& rPam )
: SwUndo( UNDO_DELNUM ), SwUndRng( rPam ),
aNodeIdx( BYTE( nEndNode - nSttNode > 255 ? 255 : nEndNode - nSttNode ))
2000-09-18 23:08:29 +00:00
{
pHistory = new SwHistory;
}
SwUndoDelNum::~SwUndoDelNum()
{
delete pHistory;
}
void SwUndoDelNum::UndoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc = rContext.GetDoc();
2000-09-18 23:08:29 +00:00
pHistory->TmpRollback( &rDoc, 0 );
pHistory->SetTmpEnd( pHistory->Count() );
for( USHORT n = 0; n < aNodeIdx.Count(); ++n )
{
SwTxtNode* pNd = rDoc.GetNodes()[ aNodeIdx[ n ] ]->GetTxtNode();
ASSERT( pNd, "Where is TextNode gone?" );
pNd->SetAttrListLevel(aLevels[ n ] );
2000-09-18 23:08:29 +00:00
if( pNd->GetCondFmtColl() )
pNd->ChkCondColl();
}
AddUndoRedoPaM(rContext);
2000-09-18 23:08:29 +00:00
}
void SwUndoDelNum::RedoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwPaM & rPam( AddUndoRedoPaM(rContext) );
rContext.GetDoc().DelNumRules(rPam);
2000-09-18 23:08:29 +00:00
}
void SwUndoDelNum::RepeatImpl(::sw::RepeatContext & rContext)
2000-09-18 23:08:29 +00:00
{
rContext.GetDoc().DelNumRules(rContext.GetRepeatPaM());
2000-09-18 23:08:29 +00:00
}
void SwUndoDelNum::AddNode( const SwTxtNode& rNd, BOOL )
2000-09-18 23:08:29 +00:00
{
if( rNd.GetNumRule() )
2000-09-18 23:08:29 +00:00
{
USHORT nIns = aNodeIdx.Count();
2000-09-18 23:08:29 +00:00
aNodeIdx.Insert( rNd.GetIndex(), nIns );
aLevels.insert( aLevels.begin() + nIns, static_cast<BYTE>(rNd.GetActualListLevel()) );
2000-09-18 23:08:29 +00:00
}
}
/* */
2000-09-18 23:08:29 +00:00
SwUndoMoveNum::SwUndoMoveNum( const SwPaM& rPam, long nOff, BOOL bIsOutlMv )
: SwUndo( bIsOutlMv ? UNDO_OUTLINE_UD : UNDO_MOVENUM ),
SwUndRng( rPam ),
nNewStt( 0 ), nOffset( nOff )
2000-09-18 23:08:29 +00:00
{
// nOffset: nach unten => 1
// nach oben => -1
}
void SwUndoMoveNum::UndoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
ULONG nTmpStt = nSttNode, nTmpEnd = nEndNode;
if( nEndNode || USHRT_MAX != nEndCntnt ) // Bereich ?
{
if( nNewStt < nSttNode ) // nach vorne verschoben
nEndNode = nEndNode - ( nSttNode - nNewStt );
else
nEndNode = nEndNode + ( nNewStt - nSttNode );
}
2000-09-18 23:08:29 +00:00
nSttNode = nNewStt;
//JP 22.06.95: wird wollen die Bookmarks/Verzeichnisse behalten, oder?
// SetPaM( rUndoIter );
// RemoveIdxFromRange( *rUndoIter.pAktPam, TRUE );
SwPaM & rPam( AddUndoRedoPaM(rContext) );
rContext.GetDoc().MoveParagraph( rPam, -nOffset,
2000-09-18 23:08:29 +00:00
UNDO_OUTLINE_UD == GetId() );
nSttNode = nTmpStt;
nEndNode = nTmpEnd;
}
void SwUndoMoveNum::RedoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
//JP 22.06.95: wird wollen die Bookmarks/Verzeichnisse behalten, oder?
// SetPaM( rUndoIter );
// RemoveIdxFromRange( *rUndoIter.pAktPam, TRUE );
SwPaM & rPam( AddUndoRedoPaM(rContext) );
rContext.GetDoc().MoveParagraph(rPam, nOffset, UNDO_OUTLINE_UD == GetId());
2000-09-18 23:08:29 +00:00
}
void SwUndoMoveNum::RepeatImpl(::sw::RepeatContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc = rContext.GetDoc();
2000-09-18 23:08:29 +00:00
if( UNDO_OUTLINE_UD == GetId() )
{
rDoc.MoveOutlinePara(rContext.GetRepeatPaM(),
2000-09-18 23:08:29 +00:00
0 < nOffset ? 1 : -1 );
}
2000-09-18 23:08:29 +00:00
else
{
rDoc.MoveParagraph(rContext.GetRepeatPaM(), nOffset, FALSE);
}
2000-09-18 23:08:29 +00:00
}
/* */
2000-09-18 23:08:29 +00:00
SwUndoNumUpDown::SwUndoNumUpDown( const SwPaM& rPam, short nOff )
: SwUndo( nOff > 0 ? UNDO_NUMUP : UNDO_NUMDOWN ), SwUndRng( rPam ),
nOffset( nOff )
2000-09-18 23:08:29 +00:00
{
// nOffset: Down => 1
// Up => -1
}
void SwUndoNumUpDown::UndoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwPaM & rPam( AddUndoRedoPaM(rContext) );
rContext.GetDoc().NumUpDown(rPam, 1 != nOffset );
2000-09-18 23:08:29 +00:00
}
void SwUndoNumUpDown::RedoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwPaM & rPam( AddUndoRedoPaM(rContext) );
rContext.GetDoc().NumUpDown(rPam, 1 == nOffset);
2000-09-18 23:08:29 +00:00
}
void SwUndoNumUpDown::RepeatImpl(::sw::RepeatContext & rContext)
2000-09-18 23:08:29 +00:00
{
rContext.GetDoc().NumUpDown(rContext.GetRepeatPaM(), 1 == nOffset);
2000-09-18 23:08:29 +00:00
}
/* */
2000-09-18 23:08:29 +00:00
// #115901#
SwUndoNumOrNoNum::SwUndoNumOrNoNum( const SwNodeIndex& rIdx, BOOL bOldNum,
BOOL bNewNum)
: SwUndo( UNDO_NUMORNONUM ), nIdx( rIdx.GetIndex() ), mbNewNum(bNewNum),
mbOldNum(bOldNum)
2000-09-18 23:08:29 +00:00
{
}
// #115901#, #i40034#
void SwUndoNumOrNoNum::UndoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), nIdx );
SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
2000-09-18 23:08:29 +00:00
if (NULL != pTxtNd)
{
pTxtNd->SetCountedInList(mbOldNum);
}
}
2000-09-18 23:08:29 +00:00
// #115901#, #i40034#
void SwUndoNumOrNoNum::RedoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwNodeIndex aIdx( rContext.GetDoc().GetNodes(), nIdx );
SwTxtNode * pTxtNd = aIdx.GetNode().GetTxtNode();
2000-09-18 23:08:29 +00:00
if (NULL != pTxtNd)
{
pTxtNd->SetCountedInList(mbNewNum);
}
}
2000-09-18 23:08:29 +00:00
// #115901#
void SwUndoNumOrNoNum::RepeatImpl(::sw::RepeatContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc = rContext.GetDoc();
if (mbOldNum && ! mbNewNum)
{
rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->nNode, FALSE);
}
else if ( ! mbOldNum && mbNewNum )
{
rDoc.NumOrNoNum(rContext.GetRepeatPaM().GetPoint()->nNode, TRUE);
}
2000-09-18 23:08:29 +00:00
}
/* */
2000-09-18 23:08:29 +00:00
SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, BOOL bFlg )
: SwUndo( UNDO_SETNUMRULESTART ),
nIdx( rPos.nNode.GetIndex() ), nOldStt( USHRT_MAX ),
nNewStt( USHRT_MAX ), bSetSttValue( FALSE ), bFlag( bFlg )
2000-09-18 23:08:29 +00:00
{
}
SwUndoNumRuleStart::SwUndoNumRuleStart( const SwPosition& rPos, USHORT nStt )
: SwUndo( UNDO_SETNUMRULESTART ),
nIdx( rPos.nNode.GetIndex() ),
nOldStt( USHRT_MAX ), nNewStt( nStt ), bSetSttValue( TRUE )
2000-09-18 23:08:29 +00:00
{
SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
if ( pTxtNd )
{
// --> OD 2008-02-28 #refactorlists#
if ( pTxtNd->HasAttrListRestartValue() )
{
nOldStt = static_cast<USHORT>(pTxtNd->GetAttrListRestartValue());
}
else
{
nOldStt = USHRT_MAX; // indicating, that the list restart value is not set
}
// <--
}
2000-09-18 23:08:29 +00:00
}
void SwUndoNumRuleStart::UndoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc = rContext.GetDoc();
SwPosition const aPos( *rDoc.GetNodes()[ nIdx ] );
2000-09-18 23:08:29 +00:00
if( bSetSttValue )
{
rDoc.SetNodeNumStart( aPos, nOldStt );
}
2000-09-18 23:08:29 +00:00
else
{
rDoc.SetNumRuleStart( aPos, !bFlag );
}
2000-09-18 23:08:29 +00:00
}
void SwUndoNumRuleStart::RedoImpl(::sw::UndoRedoContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc = rContext.GetDoc();
SwPosition const aPos( *rDoc.GetNodes()[ nIdx ] );
2000-09-18 23:08:29 +00:00
if( bSetSttValue )
{
2000-09-18 23:08:29 +00:00
rDoc.SetNodeNumStart( aPos, nNewStt );
}
2000-09-18 23:08:29 +00:00
else
{
2000-09-18 23:08:29 +00:00
rDoc.SetNumRuleStart( aPos, bFlag );
}
2000-09-18 23:08:29 +00:00
}
void SwUndoNumRuleStart::RepeatImpl(::sw::RepeatContext & rContext)
2000-09-18 23:08:29 +00:00
{
SwDoc & rDoc = rContext.GetDoc();
2000-09-18 23:08:29 +00:00
if( bSetSttValue )
{
rDoc.SetNodeNumStart(*rContext.GetRepeatPaM().GetPoint(), nNewStt);
}
2000-09-18 23:08:29 +00:00
else
{
rDoc.SetNumRuleStart(*rContext.GetRepeatPaM().GetPoint(), bFlag);
}
2000-09-18 23:08:29 +00:00
}