1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SwUndoField.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
33 #include <tools/rtti.hxx>
34 #include <SwUndoField.hxx>
44 using namespace ::com::sun::star::uno
;
46 SwUndoField::SwUndoField(const SwPosition
& rPos
, SwUndoId _nId
)
49 nNodeIndex
= rPos
.nNode
.GetIndex();
50 nOffset
= rPos
.nContent
.GetIndex();
54 SwUndoField::~SwUndoField()
58 SwPosition
SwUndoField::GetPosition()
60 SwNode
* pNode
= pDoc
->GetNodes()[nNodeIndex
];
61 SwNodeIndex
aNodeIndex(*pNode
);
62 SwIndex
aIndex(pNode
->GetCntntNode(), nOffset
);
63 SwPosition
aResult(aNodeIndex
, aIndex
);
68 SwUndoFieldFromDoc::SwUndoFieldFromDoc(const SwPosition
& rPos
,
69 const SwField
& _aOldField
,
70 const SwField
& _aNewField
,
71 SwMsgPoolItem
* _pHnt
, BOOL _bUpdate
, SwUndoId _nId
)
72 : SwUndoField(rPos
,_nId
), pOldField(_aOldField
.Copy()),
73 pNewField(_aNewField
.Copy()), pHnt(_pHnt
),
76 ASSERT(pOldField
, "No old field!");
77 ASSERT(pNewField
, "No new field!");
78 ASSERT(pDoc
, "No document!");
81 SwUndoFieldFromDoc::~SwUndoFieldFromDoc()
87 void SwUndoFieldFromDoc::Undo( SwUndoIter
& )
89 SwTxtFld
* pTxtFld
= SwDoc::GetTxtFld(GetPosition());
90 const SwField
* pField
= pTxtFld
->GetFld().GetFld();
94 BOOL bUndo
= pDoc
->DoesUndo();
97 pDoc
->UpdateFld(pTxtFld
, *pOldField
, pHnt
, bUpdate
);
102 void SwUndoFieldFromDoc::Redo( SwUndoIter
& )
104 SwTxtFld
* pTxtFld
= SwDoc::GetTxtFld(GetPosition());
105 const SwField
* pField
= pTxtFld
->GetFld().GetFld();
109 BOOL bUndo
= pDoc
->DoesUndo();
112 pDoc
->UpdateFld(pTxtFld
, *pNewField
, pHnt
, bUpdate
);
113 SwFmtFld
* pDstFmtFld
= (SwFmtFld
*)&pTxtFld
->GetFld();
115 if ( pDoc
->GetFldType(RES_POSTITFLD
, aEmptyStr
,false) == pDstFmtFld
->GetFld()->GetTyp() )
116 pDoc
->GetDocShell()->Broadcast( SwFmtFldHint( pDstFmtFld
, SWFMTFLD_INSERTED
) );
121 void SwUndoFieldFromDoc::Repeat(SwUndoIter
& rIt
)
126 SwUndoFieldFromAPI::SwUndoFieldFromAPI(const SwPosition
& rPos
,
127 const Any
& rOldVal
, const Any
& rNewVal
,
129 : SwUndoField(rPos
), aOldVal(rOldVal
), aNewVal(rNewVal
), nWhich(_nWhich
)
133 SwUndoFieldFromAPI::~SwUndoFieldFromAPI()
137 void SwUndoFieldFromAPI::Undo( SwUndoIter
& )
139 SwField
* pField
= SwDoc::GetField(GetPosition());
142 pField
->PutValue(aOldVal
, nWhich
);
145 void SwUndoFieldFromAPI::Redo( SwUndoIter
& )
147 SwField
* pField
= SwDoc::GetField(GetPosition());
150 pField
->PutValue(aNewVal
, nWhich
);
154 void SwUndoFieldFromAPI::Repeat(SwUndoIter
& rIter
)