2004-05-18 13:05:36 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 15:02:21 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-05-18 13:05:36 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2004-05-18 13:05:36 +00:00
|
|
|
*
|
2008-04-10 15:02:21 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-05-18 13:05:36 +00:00
|
|
|
*
|
2008-04-10 15:02:21 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-05-18 13:05:36 +00:00
|
|
|
*
|
2008-04-10 15:02:21 +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.
|
2004-05-18 13:05:36 +00:00
|
|
|
*
|
2008-04-10 15:02:21 +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).
|
2004-05-18 13:05:36 +00:00
|
|
|
*
|
2008-04-10 15:02:21 +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.
|
2004-05-18 13:05:36 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 20:48:44 +00:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_sw.hxx"
|
2010-11-25 14:31:08 +01:00
|
|
|
|
2004-05-18 13:05:36 +00:00
|
|
|
#include <tools/rtti.hxx>
|
2010-11-25 14:31:08 +01:00
|
|
|
|
2004-05-18 13:05:36 +00:00
|
|
|
#include <SwUndoField.hxx>
|
|
|
|
#include <swundo.hxx>
|
2006-08-14 15:48:21 +00:00
|
|
|
#include <doc.hxx>
|
2010-11-25 14:31:08 +01:00
|
|
|
#include <IDocumentUndoRedo.hxx>
|
2004-05-18 13:05:36 +00:00
|
|
|
#include <txtfld.hxx>
|
|
|
|
#include <fldbas.hxx>
|
|
|
|
#include <ndtxt.hxx>
|
|
|
|
#include <fmtfld.hxx>
|
|
|
|
#include <dbfld.hxx>
|
2008-02-19 12:48:59 +00:00
|
|
|
#include <docsh.hxx>
|
2007-09-27 08:28:26 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star::uno;
|
2004-05-18 13:05:36 +00:00
|
|
|
|
2008-04-03 15:52:32 +00:00
|
|
|
SwUndoField::SwUndoField(const SwPosition & rPos, SwUndoId _nId )
|
|
|
|
: SwUndo(_nId)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
|
|
|
nNodeIndex = rPos.nNode.GetIndex();
|
|
|
|
nOffset = rPos.nContent.GetIndex();
|
|
|
|
pDoc = rPos.GetDoc();
|
|
|
|
}
|
|
|
|
|
|
|
|
SwUndoField::~SwUndoField()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwPosition SwUndoField::GetPosition()
|
|
|
|
{
|
|
|
|
SwNode * pNode = pDoc->GetNodes()[nNodeIndex];
|
|
|
|
SwNodeIndex aNodeIndex(*pNode);
|
|
|
|
SwIndex aIndex(pNode->GetCntntNode(), nOffset);
|
|
|
|
SwPosition aResult(aNodeIndex, aIndex);
|
|
|
|
|
|
|
|
return aResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
SwUndoFieldFromDoc::SwUndoFieldFromDoc(const SwPosition & rPos,
|
2010-05-21 15:21:49 +02:00
|
|
|
const SwField & rOldField,
|
|
|
|
const SwField & rNewField,
|
2008-04-03 15:52:32 +00:00
|
|
|
SwMsgPoolItem * _pHnt, BOOL _bUpdate, SwUndoId _nId)
|
2010-05-21 15:21:49 +02:00
|
|
|
: SwUndoField(rPos,_nId)
|
|
|
|
, pOldField(rOldField.CopyField())
|
|
|
|
, pNewField(rNewField.CopyField())
|
|
|
|
, pHnt(_pHnt)
|
|
|
|
, bUpdate(_bUpdate)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
|
|
|
ASSERT(pOldField, "No old field!");
|
|
|
|
ASSERT(pNewField, "No new field!");
|
|
|
|
ASSERT(pDoc, "No document!");
|
|
|
|
}
|
|
|
|
|
|
|
|
SwUndoFieldFromDoc::~SwUndoFieldFromDoc()
|
|
|
|
{
|
|
|
|
delete pOldField;
|
|
|
|
delete pNewField;
|
|
|
|
}
|
|
|
|
|
2007-09-27 08:28:26 +00:00
|
|
|
void SwUndoFieldFromDoc::Undo( SwUndoIter& )
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
|
|
|
SwTxtFld * pTxtFld = SwDoc::GetTxtFld(GetPosition());
|
2004-05-26 06:54:03 +00:00
|
|
|
const SwField * pField = pTxtFld->GetFld().GetFld();
|
2004-05-18 13:05:36 +00:00
|
|
|
|
|
|
|
if (pField)
|
|
|
|
{
|
|
|
|
pDoc->UpdateFld(pTxtFld, *pOldField, pHnt, bUpdate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-27 08:28:26 +00:00
|
|
|
void SwUndoFieldFromDoc::Redo( SwUndoIter& )
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
|
|
|
SwTxtFld * pTxtFld = SwDoc::GetTxtFld(GetPosition());
|
2004-05-26 06:54:03 +00:00
|
|
|
const SwField * pField = pTxtFld->GetFld().GetFld();
|
2004-05-18 13:05:36 +00:00
|
|
|
|
|
|
|
if (pField)
|
|
|
|
{
|
|
|
|
pDoc->UpdateFld(pTxtFld, *pNewField, pHnt, bUpdate);
|
2008-02-19 12:48:59 +00:00
|
|
|
SwFmtFld* pDstFmtFld = (SwFmtFld*)&pTxtFld->GetFld();
|
|
|
|
|
|
|
|
if ( pDoc->GetFldType(RES_POSTITFLD, aEmptyStr,false) == pDstFmtFld->GetFld()->GetTyp() )
|
|
|
|
pDoc->GetDocShell()->Broadcast( SwFmtFldHint( pDstFmtFld, SWFMTFLD_INSERTED ) );
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwUndoFieldFromDoc::Repeat(SwUndoIter & rIt)
|
|
|
|
{
|
2010-12-15 09:14:06 +01:00
|
|
|
::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
|
2004-05-18 13:05:36 +00:00
|
|
|
Redo(rIt);
|
|
|
|
}
|
|
|
|
|
|
|
|
SwUndoFieldFromAPI::SwUndoFieldFromAPI(const SwPosition & rPos,
|
|
|
|
const Any & rOldVal, const Any & rNewVal,
|
2007-09-27 08:28:26 +00:00
|
|
|
USHORT _nWhich)
|
|
|
|
: SwUndoField(rPos), aOldVal(rOldVal), aNewVal(rNewVal), nWhich(_nWhich)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwUndoFieldFromAPI::~SwUndoFieldFromAPI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-09-27 08:28:26 +00:00
|
|
|
void SwUndoFieldFromAPI::Undo( SwUndoIter& )
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
|
|
|
SwField * pField = SwDoc::GetField(GetPosition());
|
|
|
|
|
|
|
|
if (pField)
|
2007-09-27 08:28:26 +00:00
|
|
|
pField->PutValue(aOldVal, nWhich);
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
|
|
|
|
2007-09-27 08:28:26 +00:00
|
|
|
void SwUndoFieldFromAPI::Redo( SwUndoIter& )
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
|
|
|
SwField * pField = SwDoc::GetField(GetPosition());
|
|
|
|
|
|
|
|
if (pField)
|
2007-09-27 08:28:26 +00:00
|
|
|
pField->PutValue(aNewVal, nWhich);
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SwUndoFieldFromAPI::Repeat(SwUndoIter & rIter)
|
|
|
|
{
|
|
|
|
Redo(rIter);
|
|
|
|
}
|