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 <ndtxt.hxx>
29 #include <fmtfld.hxx>
30 #include <dbfld.hxx>
31 #include <docsh.hxx>
32 #include <pam.hxx>
33 #include <osl/diagnose.h>
34 
35 using namespace ::com::sun::star::uno;
36 
38  : SwUndo(SwUndoId::FIELD, rPos.GetDoc())
39 {
40  nNodeIndex = rPos.nNode.GetIndex();
41  nOffset = rPos.nContent.GetIndex();
42  pDoc = rPos.GetDoc();
43 }
44 
46 {
47 }
48 
50 {
51  SwNode * pNode = pDoc->GetNodes()[nNodeIndex];
52  SwNodeIndex aNodeIndex(*pNode);
53  SwIndex aIndex(pNode->GetContentNode(), nOffset);
54  SwPosition aResult(aNodeIndex, aIndex);
55 
56  return aResult;
57 }
58 
60  const SwField & rOldField,
61  const SwField & rNewField,
62  SwMsgPoolItem * _pHint, bool _bUpdate)
63  : SwUndoField(rPos)
64  , pOldField(rOldField.CopyField())
65  , pNewField(rNewField.CopyField())
66  , pHint(_pHint)
67  , bUpdate(_bUpdate)
68 {
69  OSL_ENSURE(pOldField, "No old field!");
70  OSL_ENSURE(pNewField, "No new field!");
71  OSL_ENSURE(pDoc, "No document!");
72 }
73 
75 {
76 }
77 
79 {
81  const SwField * pField = pTextField ? pTextField->GetFormatField().GetField() : nullptr;
82 
83  if (pField)
84  {
86  }
87 }
88 
90 {
92  const SwField * pField = pTextField ? pTextField->GetFormatField().GetField() : nullptr;
93 
94  if (pField)
95  {
97  SwFormatField* pDstFormatField = const_cast<SwFormatField*>(&pTextField->GetFormatField());
98 
99  if (pDoc->getIDocumentFieldsAccess().GetFieldType(SwFieldIds::Postit, OUString(), false) == pDstFormatField->GetField()->GetTyp())
100  pDoc->GetDocShell()->Broadcast( SwFormatFieldHint( pDstFormatField, SwFormatFieldHintWhich::INSERTED ) );
101  }
102 }
103 
105 {
106  DoImpl();
107 }
108 
110 {
111  ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
112  DoImpl();
113 }
114 
116  const Any & rOldVal, const Any & rNewVal,
117  sal_uInt16 _nWhich)
118  : SwUndoField(rPos), aOldVal(rOldVal), aNewVal(rNewVal), nWhich(_nWhich)
119 {
120 }
121 
123 {
124 }
125 
127 {
129 
130  if (pField)
131  pField->PutValue(aOldVal, nWhich);
132 }
133 
135 {
137 
138  if (pField)
139  pField->PutValue(aNewVal, nWhich);
140 }
141 
143 {
144  DoImpl();
145 }
146 
148 {
149  DoImpl();
150 }
151 
152 /* 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:71
css::uno::Any aOldVal
Definition: SwUndoField.hxx:66
SwUndoId
Definition: swundo.hxx:29
virtual void RedoImpl(::sw::UndoRedoContext &) override
SwDocShell * GetDocShell()
Definition: doc.hxx:1340
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:279
SwUndoField(const SwPosition &rPos)
Definition: SwUndoField.cxx:37
static SwField * GetFieldAtPos(const SwPosition &rPos)
Returns the field at a certain position.
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:176
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:389
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:314
SwDoc * pDoc
Definition: SwUndoField.hxx:36
sal_uLong GetIndex() const
Definition: ndindex.hxx:151
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:49
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:59
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:45
std::unique_ptr< SwField > pOldField
Definition: SwUndoField.hxx:46
SwFieldType * GetTyp() const
Definition: fldbas.hxx:382
sal_uInt16 const nWhich
Definition: SwUndoField.hxx:67
virtual void RedoImpl(::sw::UndoRedoContext &) override
sal_Int32 GetIndex() const
Definition: index.hxx:95
SwNodes & GetNodes()
Definition: doc.hxx:403
virtual ~SwUndoFieldFromAPI() override
virtual void UndoImpl(::sw::UndoRedoContext &) override
Definition: SwUndoField.cxx:78
css::uno::Any aNewVal
Definition: SwUndoField.hxx:66
virtual ~SwUndoFieldFromDoc() override
Definition: SwUndoField.cxx:74
bool const bUpdate
Definition: SwUndoField.hxx:48
Base class of the Writer document model elements.
Definition: node.hxx:79