LibreOffice Module sw (master) 1
SwUndoField.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <SwUndoField.hxx>
22#include <swundo.hxx>
23#include <doc.hxx>
24#include <IDocumentUndoRedo.hxx>
26#include <txtfld.hxx>
27#include <fldbas.hxx>
28#include <fmtfld.hxx>
29#include <docsh.hxx>
30#include <pam.hxx>
31#include <utility>
32#include <osl/diagnose.h>
33
34using namespace ::com::sun::star::uno;
35
37 : SwUndo(SwUndoId::FIELD, &rPos.GetDoc())
38{
41 m_pDoc = &rPos.GetDoc();
42}
43
45{
46}
47
49{
50 SwNode * pNode = m_pDoc->GetNodes()[m_nNodeIndex];
52 SwPosition aResult(*pNode, aIndex);
53
54 return aResult;
55}
56
58 const SwField & rOldField,
59 const SwField & rNewField,
60 SwMsgPoolItem * _pHint, bool _bUpdate)
61 : SwUndoField(rPos)
62 , m_pOldField(rOldField.CopyField())
63 , m_pNewField(rNewField.CopyField())
64 , m_pHint(_pHint)
65 , m_bUpdate(_bUpdate)
66{
67 OSL_ENSURE(m_pOldField, "No old field!");
68 OSL_ENSURE(m_pNewField, "No new field!");
69 OSL_ENSURE(m_pDoc, "No document!");
70}
71
73{
74}
75
77{
79 const SwField * pField = pTextField ? pTextField->GetFormatField().GetField() : nullptr;
80
81 if (pField)
82 {
84 }
85}
86
88{
90 const SwField * pField = pTextField ? pTextField->GetFormatField().GetField() : nullptr;
91
92 if (pField)
93 {
95 SwFormatField* pDstFormatField = const_cast<SwFormatField*>(&pTextField->GetFormatField());
96
97 if (m_pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false) == pDstFormatField->GetField()->GetTyp())
98 m_pDoc->GetDocShell()->Broadcast( SwFormatFieldHint( pDstFormatField, SwFormatFieldHintWhich::INSERTED ) );
99 }
100}
101
103{
104 DoImpl();
105}
106
108{
109 ::sw::UndoGuard const undoGuard(m_pDoc->GetIDocumentUndoRedo());
110 DoImpl();
111}
112
114 Any aOldVal, Any aNewVal,
115 sal_uInt16 _nWhich)
116 : SwUndoField(rPos), m_aOldVal(std::move(aOldVal)), m_aNewVal(std::move(aNewVal)), m_nWhich(_nWhich)
117{
118}
119
121{
122}
123
125{
127
128 if (pField)
129 pField->PutValue(m_aOldVal, m_nWhich);
130}
131
133{
135
136 if (pField)
137 pField->PutValue(m_aNewVal, m_nWhich);
138}
139
141{
142 DoImpl();
143}
144
146{
147 DoImpl();
148}
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual bool UpdateField(SwTextField *rDstFormatField, SwField &rSrcField, SwMsgPoolItem *pMsgHint, bool bUpdateTableFields)=0
Updates a field.
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
Marks a character position inside a document model content node (SwContentNode)
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:145
SwNodes & GetNodes()
Definition: doc.hxx:413
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:358
SwDocShell * GetDocShell()
Definition: doc.hxx:1355
Base class of all fields.
Definition: fldbas.hxx:292
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:369
SwFieldType * GetTyp() const
Definition: fldbas.hxx:398
const SwField * GetField() const
Definition: fmtfld.hxx:130
Base class of the Writer document model elements.
Definition: node.hxx:84
SwContentNode * GetContentNode()
Definition: node.hxx:644
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:199
css::uno::Any m_aOldVal
Definition: SwUndoField.hxx:66
SwUndoFieldFromAPI(const SwPosition &rPos, css::uno::Any aOldVal, css::uno::Any aNewVal, sal_uInt16 nWhich)
virtual void UndoImpl(::sw::UndoRedoContext &) override
virtual void RepeatImpl(::sw::RepeatContext &) override
virtual void RedoImpl(::sw::UndoRedoContext &) override
virtual ~SwUndoFieldFromAPI() override
css::uno::Any m_aNewVal
Definition: SwUndoField.hxx:66
sal_uInt16 m_nWhich
Definition: SwUndoField.hxx:67
virtual ~SwUndoFieldFromDoc() override
Definition: SwUndoField.cxx:72
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: SwUndoField.cxx:76
SwUndoFieldFromDoc(const SwPosition &rPos, const SwField &aOldField, const SwField &aNewField, SwMsgPoolItem *pHint, bool bUpdate)
Definition: SwUndoField.cxx:57
virtual void RepeatImpl(::sw::RepeatContext &) override
virtual void RedoImpl(::sw::UndoRedoContext &) override
std::unique_ptr< SwField > m_pNewField
Definition: SwUndoField.hxx:46
std::unique_ptr< SwField > m_pOldField
Definition: SwUndoField.hxx:46
SwMsgPoolItem * m_pHint
Definition: SwUndoField.hxx:47
SwUndoField(const SwPosition &rPos)
Definition: SwUndoField.cxx:36
sal_Int32 m_nOffset
Definition: SwUndoField.hxx:33
virtual ~SwUndoField() override
Definition: SwUndoField.cxx:44
SwPosition GetPosition()
Definition: SwUndoField.cxx:48
SwNodeOffset m_nNodeIndex
Definition: SwUndoField.hxx:32
SwDoc * m_pDoc
Definition: SwUndoField.hxx:36
static SwTextField * GetTextFieldAtPos(const SwPosition &rPos)
Returns the field at a certain position.
static SwField * GetFieldAtPos(const SwPosition &rPos)
Returns the field at a certain position.
std::deque< AttacherIndex_Impl > aIndex
Marks a position in the document model.
Definition: pam.hxx:37
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:77
sal_Int32 GetContentIndex() const
Definition: pam.hxx:84
SwDoc & GetDoc() const
Returns the document this position is in.
Definition: pam.cxx:217
SwUndoId
Definition: swundo.hxx:30