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 <osl/diagnose.h>
32 
33 using namespace ::com::sun::star::uno;
34 
36  : SwUndo(SwUndoId::FIELD, rPos.GetDoc())
37 {
38  m_nNodeIndex = rPos.nNode.GetIndex();
39  m_nOffset = rPos.nContent.GetIndex();
40  m_pDoc = rPos.GetDoc();
41 }
42 
44 {
45 }
46 
48 {
49  SwNode * pNode = m_pDoc->GetNodes()[m_nNodeIndex];
50  SwNodeIndex aNodeIndex(*pNode);
52  SwPosition aResult(aNodeIndex, 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  const Any & rOldVal, const Any & rNewVal,
115  sal_uInt16 _nWhich)
116  : SwUndoField(rPos), m_aOldVal(rOldVal), m_aNewVal(rNewVal), 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: */
sal_uInt16 m_nWhich
Definition: SwUndoField.hxx:67
Marks a position in the document model.
Definition: pam.hxx:35
const SwField * GetField() const
Definition: fmtfld.hxx:111
sal_Int32 m_nOffset
Definition: SwUndoField.hxx:33
SwUndoId
Definition: swundo.hxx:29
virtual void RedoImpl(::sw::UndoRedoContext &) override
SwDocShell * GetDocShell()
Definition: doc.hxx:1348
virtual SwFieldType * GetFieldType(SwFieldIds nResId, const OUString &rName, bool bDbFieldMatching) const =0
SwNodeIndex nNode
Definition: pam.hxx:37
Base class of all fields.
Definition: fldbas.hxx:293
SwUndoField(const SwPosition &rPos)
Definition: SwUndoField.cxx:35
static SwField * GetFieldAtPos(const SwPosition &rPos)
Returns the field at a certain position.
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:144
sal_uLong m_nNodeIndex
Definition: SwUndoField.hxx:32
virtual bool UpdateField(SwTextField *rDstFormatField, SwField &rSrcField, SwMsgPoolItem *pMsgHint, bool bUpdateTableFields)=0
Updates a field.
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
SwIndex nContent
Definition: pam.hxx:38
SwDoc * GetDoc() const
Returns the document this position is in.
Definition: pam.cxx:178
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:345
std::unique_ptr< SwField > m_pOldField
Definition: SwUndoField.hxx:46
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
virtual void UndoImpl(::sw::UndoRedoContext &) override
virtual void RepeatImpl(::sw::RepeatContext &) override
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
static SwTextField * GetTextFieldAtPos(const SwPosition &rPos)
Returns the field at a certain position.
SwPosition GetPosition()
Definition: SwUndoField.cxx:47
SwUndoFieldFromAPI(const SwPosition &rPos, const css::uno::Any &rOldVal, const css::uno::Any &rNewVal, sal_uInt16 nWhich)
std::unique_ptr< SwField > m_pNewField
Definition: SwUndoField.hxx:46
SwUndoFieldFromDoc(const SwPosition &rPos, const SwField &aOldField, const SwField &aNewField, SwMsgPoolItem *pHint, bool bUpdate)
Definition: SwUndoField.cxx:57
SwContentNode * GetContentNode()
Definition: node.hxx:615
Marks a character position inside a document model node.
Definition: index.hxx:33
virtual void RepeatImpl(::sw::RepeatContext &) override
Marks a node in the document model.
Definition: ndindex.hxx:31
css::uno::Any m_aOldVal
Definition: SwUndoField.hxx:66
virtual ~SwUndoField() override
Definition: SwUndoField.cxx:43
SwMsgPoolItem * m_pHint
Definition: SwUndoField.hxx:47
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
virtual void RedoImpl(::sw::UndoRedoContext &) override
css::uno::Any m_aNewVal
Definition: SwUndoField.hxx:66
std::deque< AttacherIndex_Impl > aIndex
sal_Int32 GetIndex() const
Definition: index.hxx:91
SwNodes & GetNodes()
Definition: doc.hxx:403
SwDoc * m_pDoc
Definition: SwUndoField.hxx:36
virtual ~SwUndoFieldFromAPI() override
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: SwUndoField.cxx:76
virtual ~SwUndoFieldFromDoc() override
Definition: SwUndoField.cxx:72
Base class of the Writer document model elements.
Definition: node.hxx:79