2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-09-16 20:48:44 +00:00
|
|
|
|
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,
|
2011-01-17 15:06:54 +01:00
|
|
|
SwMsgPoolItem * _pHnt, sal_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
|
|
|
{
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE(pOldField, "No old field!");
|
|
|
|
OSL_ENSURE(pNewField, "No new field!");
|
|
|
|
OSL_ENSURE(pDoc, "No document!");
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SwUndoFieldFromDoc::~SwUndoFieldFromDoc()
|
|
|
|
{
|
|
|
|
delete pOldField;
|
|
|
|
delete pNewField;
|
|
|
|
}
|
|
|
|
|
2010-12-15 09:14:11 +01:00
|
|
|
void SwUndoFieldFromDoc::UndoImpl(::sw::UndoRedoContext &)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
2013-11-18 11:29:24 +00:00
|
|
|
SwTxtFld * pTxtFld = SwDoc::GetTxtFldAtPos(GetPosition());
|
2013-09-24 15:03:38 +00:00
|
|
|
const SwField * pField = pTxtFld ? pTxtFld->GetFmtFld().GetField() : NULL;
|
2004-05-18 13:05:36 +00:00
|
|
|
|
|
|
|
if (pField)
|
|
|
|
{
|
|
|
|
pDoc->UpdateFld(pTxtFld, *pOldField, pHnt, bUpdate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 09:14:11 +01:00
|
|
|
void SwUndoFieldFromDoc::DoImpl()
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
2013-11-18 11:29:24 +00:00
|
|
|
SwTxtFld * pTxtFld = SwDoc::GetTxtFldAtPos(GetPosition());
|
2013-09-24 15:03:38 +00:00
|
|
|
const SwField * pField = pTxtFld ? pTxtFld->GetFmtFld().GetField() : NULL;
|
2004-05-18 13:05:36 +00:00
|
|
|
|
|
|
|
if (pField)
|
|
|
|
{
|
|
|
|
pDoc->UpdateFld(pTxtFld, *pNewField, pHnt, bUpdate);
|
2013-09-24 15:03:38 +00:00
|
|
|
SwFmtFld* pDstFmtFld = (SwFmtFld*)&pTxtFld->GetFmtFld();
|
2008-02-19 12:48:59 +00:00
|
|
|
|
2013-09-24 15:03:38 +00:00
|
|
|
if ( pDoc->GetFldType(RES_POSTITFLD, aEmptyOUStr, false) == pDstFmtFld->GetField()->GetTyp() )
|
2008-02-19 12:48:59 +00:00
|
|
|
pDoc->GetDocShell()->Broadcast( SwFmtFldHint( pDstFmtFld, SWFMTFLD_INSERTED ) );
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-12-15 09:14:11 +01:00
|
|
|
void SwUndoFieldFromDoc::RedoImpl(::sw::UndoRedoContext &)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
2010-12-15 09:14:11 +01:00
|
|
|
DoImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwUndoFieldFromDoc::RepeatImpl(::sw::RepeatContext &)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
2010-12-15 09:14:06 +01:00
|
|
|
::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
|
2010-12-15 09:14:11 +01:00
|
|
|
DoImpl();
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SwUndoFieldFromAPI::SwUndoFieldFromAPI(const SwPosition & rPos,
|
|
|
|
const Any & rOldVal, const Any & rNewVal,
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 _nWhich)
|
2007-09-27 08:28:26 +00:00
|
|
|
: SwUndoField(rPos), aOldVal(rOldVal), aNewVal(rNewVal), nWhich(_nWhich)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwUndoFieldFromAPI::~SwUndoFieldFromAPI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-12-15 09:14:11 +01:00
|
|
|
void SwUndoFieldFromAPI::UndoImpl(::sw::UndoRedoContext &)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
2013-11-18 11:29:24 +00:00
|
|
|
SwField * pField = SwDoc::GetFieldAtPos(GetPosition());
|
2004-05-18 13:05:36 +00:00
|
|
|
|
|
|
|
if (pField)
|
2007-09-27 08:28:26 +00:00
|
|
|
pField->PutValue(aOldVal, nWhich);
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
|
|
|
|
2010-12-15 09:14:11 +01:00
|
|
|
void SwUndoFieldFromAPI::DoImpl()
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
2013-11-18 11:29:24 +00:00
|
|
|
SwField * pField = SwDoc::GetFieldAtPos(GetPosition());
|
2004-05-18 13:05:36 +00:00
|
|
|
|
|
|
|
if (pField)
|
2007-09-27 08:28:26 +00:00
|
|
|
pField->PutValue(aNewVal, nWhich);
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
|
|
|
|
2010-12-15 09:14:11 +01:00
|
|
|
void SwUndoFieldFromAPI::RedoImpl(::sw::UndoRedoContext &)
|
|
|
|
{
|
|
|
|
DoImpl();
|
|
|
|
}
|
2004-05-18 13:05:36 +00:00
|
|
|
|
2010-12-15 09:14:11 +01:00
|
|
|
void SwUndoFieldFromAPI::RepeatImpl(::sw::RepeatContext &)
|
2004-05-18 13:05:36 +00:00
|
|
|
{
|
2010-12-15 09:14:11 +01:00
|
|
|
DoImpl();
|
2004-05-18 13:05:36 +00:00
|
|
|
}
|
2010-10-14 08:30:41 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|