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 bool _bUpdate)
61 : SwUndoField(rPos)
62 , m_pOldField(rOldField.CopyField())
63 , m_pNewField(rNewField.CopyField())
64 , m_bUpdate(_bUpdate)
65{
66 OSL_ENSURE(m_pOldField, "No old field!");
67 OSL_ENSURE(m_pNewField, "No new field!");
68 OSL_ENSURE(m_pDoc, "No document!");
69}
70
72{
73}
74
76{
78 const SwField * pField = pTextField ? pTextField->GetFormatField().GetField() : nullptr;
79
80 if (pField)
81 {
83 }
84}
85
87{
89 const SwField * pField = pTextField ? pTextField->GetFormatField().GetField() : nullptr;
90
91 if (pField)
92 {
94 SwFormatField* pDstFormatField = const_cast<SwFormatField*>(&pTextField->GetFormatField());
95
96 if (m_pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false) == pDstFormatField->GetField()->GetTyp())
97 m_pDoc->GetDocShell()->Broadcast( SwFormatFieldHint( pDstFormatField, SwFormatFieldHintWhich::INSERTED ) );
98 }
99}
100
102{
103 DoImpl();
104}
105
107{
108 ::sw::UndoGuard const undoGuard(m_pDoc->GetIDocumentUndoRedo());
109 DoImpl();
110}
111
113 Any aOldVal, Any aNewVal,
114 sal_uInt16 _nWhich)
115 : SwUndoField(rPos), m_aOldVal(std::move(aOldVal)), m_aNewVal(std::move(aNewVal)), m_nWhich(_nWhich)
116{
117}
118
120{
121}
122
124{
126
127 if (pField)
128 pField->PutValue(m_aOldVal, m_nWhich);
129}
130
132{
134
135 if (pField)
136 pField->PutValue(m_aNewVal, m_nWhich);
137}
138
140{
141 DoImpl();
142}
143
145{
146 DoImpl();
147}
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
virtual bool UpdateField(SwTextField *rDstFormatField, SwField &rSrcField, bool bUpdateTableFields)=0
Updates a field.
Marks a character position inside a document model content node (SwContentNode)
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:158
SwNodes & GetNodes()
Definition: doc.hxx:422
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:371
SwDocShell * GetDocShell()
Definition: doc.hxx:1370
Base class of all fields.
Definition: fldbas.hxx:296
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:382
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
const SwField * GetField() const
Definition: fmtfld.hxx:131
Base class of the Writer document model elements.
Definition: node.hxx:98
SwContentNode * GetContentNode()
Definition: node.hxx:666
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
SwUndoFieldFromDoc(const SwPosition &rPos, const SwField &aOldField, const SwField &aNewField, bool bUpdate)
Definition: SwUndoField.cxx:57
virtual ~SwUndoFieldFromDoc() override
Definition: SwUndoField.cxx:71
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: SwUndoField.cxx:75
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
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:38
SwNodeOffset GetNodeIndex() const
Definition: pam.hxx:78
sal_Int32 GetContentIndex() const
Definition: pam.hxx:85
SwDoc & GetDoc() const
Returns the document this position is in.
Definition: pam.cxx:218
SwUndoId
Definition: swundo.hxx:30