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  nNodeIndex = rPos.nNode.GetIndex();
39  nOffset = rPos.nContent.GetIndex();
40  pDoc = rPos.GetDoc();
41 }
42 
44 {
45 }
46 
48 {
49  SwNode * pNode = pDoc->GetNodes()[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  , pOldField(rOldField.CopyField())
63  , pNewField(rNewField.CopyField())
64  , pHint(_pHint)
65  , bUpdate(_bUpdate)
66 {
67  OSL_ENSURE(pOldField, "No old field!");
68  OSL_ENSURE(pNewField, "No new field!");
69  OSL_ENSURE(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 (pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false) == pDstFormatField->GetField()->GetTyp())
98  pDoc->GetDocShell()->Broadcast( SwFormatFieldHint( pDstFormatField, SwFormatFieldHintWhich::INSERTED ) );
99  }
100 }
101 
103 {
104  DoImpl();
105 }
106 
108 {
109  ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
110  DoImpl();
111 }
112 
114  const Any & rOldVal, const Any & rNewVal,
115  sal_uInt16 _nWhich)
116  : SwUndoField(rPos), aOldVal(rOldVal), aNewVal(rNewVal), nWhich(_nWhich)
117 {
118 }
119 
121 {
122 }
123 
125 {
127 
128  if (pField)
129  pField->PutValue(aOldVal, nWhich);
130 }
131 
133 {
135 
136  if (pField)
137  pField->PutValue(aNewVal, nWhich);
138 }
139 
141 {
142  DoImpl();
143 }
144 
146 {
147  DoImpl();
148 }
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nOffset
Definition: SwUndoField.hxx:33
Marks a position in the document model.
Definition: pam.hxx:35
const SwField * GetField() const
Definition: fmtfld.hxx:110
css::uno::Any aOldVal
Definition: SwUndoField.hxx:66
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:143
virtual bool UpdateField(SwTextField *rDstFormatField, SwField &rSrcField, SwMsgPoolItem *pMsgHint, bool bUpdateTableFields)=0
Updates a field.
sal_uLong nNodeIndex
Definition: SwUndoField.hxx:32
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:356
SwIndex nContent
Definition: pam.hxx:38
SwDoc * GetDoc() const
Returns the document this position is in.
Definition: pam.cxx:177
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:345
SwDoc * pDoc
Definition: SwUndoField.hxx:36
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.
std::unique_ptr< SwField > pNewField
Definition: SwUndoField.hxx:46
SwPosition GetPosition()
Definition: SwUndoField.cxx:47
SwUndoFieldFromAPI(const SwPosition &rPos, const css::uno::Any &rOldVal, const css::uno::Any &rNewVal, sal_uInt16 nWhich)
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:37
virtual void RepeatImpl(::sw::RepeatContext &) override
Marks a node in the document model.
Definition: ndindex.hxx:31
SwMsgPoolItem *const pHint
Definition: SwUndoField.hxx:47
virtual ~SwUndoField() override
Definition: SwUndoField.cxx:43
std::unique_ptr< SwField > pOldField
Definition: SwUndoField.hxx:46
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
sal_uInt16 const nWhich
Definition: SwUndoField.hxx:67
virtual void RedoImpl(::sw::UndoRedoContext &) override
std::deque< AttacherIndex_Impl > aIndex
sal_Int32 GetIndex() const
Definition: index.hxx:95
SwNodes & GetNodes()
Definition: doc.hxx:404
virtual ~SwUndoFieldFromAPI() override
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: SwUndoField.cxx:76
css::uno::Any aNewVal
Definition: SwUndoField.hxx:66
virtual ~SwUndoFieldFromDoc() override
Definition: SwUndoField.cxx:72
bool const bUpdate
Definition: SwUndoField.hxx:48
Base class of the Writer document model elements.
Definition: node.hxx:79