1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <SwUndoField.hxx>
24 #include <IDocumentUndoRedo.hxx>
25 #include <DocumentFieldsManager.hxx>
34 using namespace ::com::sun::star::uno
;
36 SwUndoField::SwUndoField(const SwPosition
& rPos
)
37 : SwUndo(SwUndoId::FIELD
, rPos
.GetDoc())
39 nNodeIndex
= rPos
.nNode
.GetIndex();
40 nOffset
= rPos
.nContent
.GetIndex();
44 SwUndoField::~SwUndoField()
48 SwPosition
SwUndoField::GetPosition()
50 SwNode
* pNode
= pDoc
->GetNodes()[nNodeIndex
];
51 SwNodeIndex
aNodeIndex(*pNode
);
52 SwIndex
aIndex(pNode
->GetContentNode(), nOffset
);
53 SwPosition
aResult(aNodeIndex
, aIndex
);
58 SwUndoFieldFromDoc::SwUndoFieldFromDoc(const SwPosition
& rPos
,
59 const SwField
& rOldField
,
60 const SwField
& rNewField
,
61 SwMsgPoolItem
* _pHint
, bool _bUpdate
)
63 , pOldField(rOldField
.CopyField())
64 , pNewField(rNewField
.CopyField())
68 OSL_ENSURE(pOldField
, "No old field!");
69 OSL_ENSURE(pNewField
, "No new field!");
70 OSL_ENSURE(pDoc
, "No document!");
73 SwUndoFieldFromDoc::~SwUndoFieldFromDoc()
79 void SwUndoFieldFromDoc::UndoImpl(::sw::UndoRedoContext
&)
81 SwTextField
* pTextField
= sw::DocumentFieldsManager::GetTextFieldAtPos(GetPosition());
82 const SwField
* pField
= pTextField
? pTextField
->GetFormatField().GetField() : nullptr;
86 pDoc
->getIDocumentFieldsAccess().UpdateField(pTextField
, *pOldField
, pHint
, bUpdate
);
90 void SwUndoFieldFromDoc::DoImpl()
92 SwTextField
* pTextField
= sw::DocumentFieldsManager::GetTextFieldAtPos(GetPosition());
93 const SwField
* pField
= pTextField
? pTextField
->GetFormatField().GetField() : nullptr;
97 pDoc
->getIDocumentFieldsAccess().UpdateField(pTextField
, *pNewField
, pHint
, bUpdate
);
98 SwFormatField
* pDstFormatField
= const_cast<SwFormatField
*>(&pTextField
->GetFormatField());
100 if ( pDoc
->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit
, aEmptyOUStr
, false) == pDstFormatField
->GetField()->GetTyp() )
101 pDoc
->GetDocShell()->Broadcast( SwFormatFieldHint( pDstFormatField
, SwFormatFieldHintWhich::INSERTED
) );
105 void SwUndoFieldFromDoc::RedoImpl(::sw::UndoRedoContext
&)
110 void SwUndoFieldFromDoc::RepeatImpl(::sw::RepeatContext
&)
112 ::sw::UndoGuard
const undoGuard(pDoc
->GetIDocumentUndoRedo());
116 SwUndoFieldFromAPI::SwUndoFieldFromAPI(const SwPosition
& rPos
,
117 const Any
& rOldVal
, const Any
& rNewVal
,
119 : SwUndoField(rPos
), aOldVal(rOldVal
), aNewVal(rNewVal
), nWhich(_nWhich
)
123 SwUndoFieldFromAPI::~SwUndoFieldFromAPI()
127 void SwUndoFieldFromAPI::UndoImpl(::sw::UndoRedoContext
&)
129 SwField
* pField
= sw::DocumentFieldsManager::GetFieldAtPos(GetPosition());
132 pField
->PutValue(aOldVal
, nWhich
);
135 void SwUndoFieldFromAPI::DoImpl()
137 SwField
* pField
= sw::DocumentFieldsManager::GetFieldAtPos(GetPosition());
140 pField
->PutValue(aNewVal
, nWhich
);
143 void SwUndoFieldFromAPI::RedoImpl(::sw::UndoRedoContext
&)
148 void SwUndoFieldFromAPI::RepeatImpl(::sw::RepeatContext
&)
153 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */