Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <tools/rtti.hxx>
31 : :
32 : : #include <SwUndoField.hxx>
33 : : #include <swundo.hxx>
34 : : #include <doc.hxx>
35 : : #include <IDocumentUndoRedo.hxx>
36 : : #include <txtfld.hxx>
37 : : #include <fldbas.hxx>
38 : : #include <ndtxt.hxx>
39 : : #include <fmtfld.hxx>
40 : : #include <dbfld.hxx>
41 : : #include <docsh.hxx>
42 : :
43 : : using namespace ::com::sun::star::uno;
44 : :
45 : 62 : SwUndoField::SwUndoField(const SwPosition & rPos, SwUndoId _nId )
46 : 62 : : SwUndo(_nId)
47 : : {
48 : 62 : nNodeIndex = rPos.nNode.GetIndex();
49 : 62 : nOffset = rPos.nContent.GetIndex();
50 [ + - ]: 62 : pDoc = rPos.GetDoc();
51 : 62 : }
52 : :
53 : 62 : SwUndoField::~SwUndoField()
54 : : {
55 [ - + ]: 62 : }
56 : :
57 : 0 : SwPosition SwUndoField::GetPosition()
58 : : {
59 [ # # ][ # # ]: 0 : SwNode * pNode = pDoc->GetNodes()[nNodeIndex];
60 [ # # ]: 0 : SwNodeIndex aNodeIndex(*pNode);
61 [ # # ][ # # ]: 0 : SwIndex aIndex(pNode->GetCntntNode(), nOffset);
62 [ # # ]: 0 : SwPosition aResult(aNodeIndex, aIndex);
63 : :
64 [ # # ][ # # ]: 0 : return aResult;
65 : : }
66 : :
67 : 0 : SwUndoFieldFromDoc::SwUndoFieldFromDoc(const SwPosition & rPos,
68 : : const SwField & rOldField,
69 : : const SwField & rNewField,
70 : : SwMsgPoolItem * _pHnt, sal_Bool _bUpdate, SwUndoId _nId)
71 : : : SwUndoField(rPos,_nId)
72 [ # # ]: 0 : , pOldField(rOldField.CopyField())
73 [ # # ]: 0 : , pNewField(rNewField.CopyField())
74 : : , pHnt(_pHnt)
75 : 0 : , bUpdate(_bUpdate)
76 : : {
77 : : OSL_ENSURE(pOldField, "No old field!");
78 : : OSL_ENSURE(pNewField, "No new field!");
79 : : OSL_ENSURE(pDoc, "No document!");
80 : 0 : }
81 : :
82 : 0 : SwUndoFieldFromDoc::~SwUndoFieldFromDoc()
83 : : {
84 [ # # ][ # # ]: 0 : delete pOldField;
85 [ # # ][ # # ]: 0 : delete pNewField;
86 [ # # ]: 0 : }
87 : :
88 : 0 : void SwUndoFieldFromDoc::UndoImpl(::sw::UndoRedoContext &)
89 : : {
90 [ # # ]: 0 : SwTxtFld * pTxtFld = SwDoc::GetTxtFld(GetPosition());
91 : :
92 [ # # ]: 0 : const SwField * pField = pTxtFld ? pTxtFld->GetFld().GetFld() : NULL;
93 : :
94 [ # # ]: 0 : if (pField)
95 : : {
96 : 0 : pDoc->UpdateFld(pTxtFld, *pOldField, pHnt, bUpdate);
97 : : }
98 : 0 : }
99 : :
100 : 0 : void SwUndoFieldFromDoc::DoImpl()
101 : : {
102 [ # # ]: 0 : SwTxtFld * pTxtFld = SwDoc::GetTxtFld(GetPosition());
103 [ # # ]: 0 : const SwField * pField = pTxtFld ? pTxtFld->GetFld().GetFld() : NULL;
104 : :
105 [ # # ]: 0 : if (pField)
106 : : {
107 : 0 : pDoc->UpdateFld(pTxtFld, *pNewField, pHnt, bUpdate);
108 : 0 : SwFmtFld* pDstFmtFld = (SwFmtFld*)&pTxtFld->GetFld();
109 : :
110 [ # # ]: 0 : if ( pDoc->GetFldType(RES_POSTITFLD, aEmptyStr,false) == pDstFmtFld->GetFld()->GetTyp() )
111 [ # # ]: 0 : pDoc->GetDocShell()->Broadcast( SwFmtFldHint( pDstFmtFld, SWFMTFLD_INSERTED ) );
112 : : }
113 : 0 : }
114 : :
115 : 0 : void SwUndoFieldFromDoc::RedoImpl(::sw::UndoRedoContext &)
116 : : {
117 : 0 : DoImpl();
118 : 0 : }
119 : :
120 : 0 : void SwUndoFieldFromDoc::RepeatImpl(::sw::RepeatContext &)
121 : : {
122 [ # # ][ # # ]: 0 : ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
123 [ # # ][ # # ]: 0 : DoImpl();
124 : 0 : }
125 : :
126 : 62 : SwUndoFieldFromAPI::SwUndoFieldFromAPI(const SwPosition & rPos,
127 : : const Any & rOldVal, const Any & rNewVal,
128 : : sal_uInt16 _nWhich)
129 : 62 : : SwUndoField(rPos), aOldVal(rOldVal), aNewVal(rNewVal), nWhich(_nWhich)
130 : : {
131 : 62 : }
132 : :
133 : 62 : SwUndoFieldFromAPI::~SwUndoFieldFromAPI()
134 : : {
135 [ - + ]: 124 : }
136 : :
137 : 0 : void SwUndoFieldFromAPI::UndoImpl(::sw::UndoRedoContext &)
138 : : {
139 [ # # ]: 0 : SwField * pField = SwDoc::GetField(GetPosition());
140 : :
141 [ # # ]: 0 : if (pField)
142 : 0 : pField->PutValue(aOldVal, nWhich);
143 : 0 : }
144 : :
145 : 0 : void SwUndoFieldFromAPI::DoImpl()
146 : : {
147 [ # # ]: 0 : SwField * pField = SwDoc::GetField(GetPosition());
148 : :
149 [ # # ]: 0 : if (pField)
150 : 0 : pField->PutValue(aNewVal, nWhich);
151 : 0 : }
152 : :
153 : 0 : void SwUndoFieldFromAPI::RedoImpl(::sw::UndoRedoContext &)
154 : : {
155 : 0 : DoImpl();
156 : 0 : }
157 : :
158 : 0 : void SwUndoFieldFromAPI::RepeatImpl(::sw::RepeatContext &)
159 : : {
160 : 0 : DoImpl();
161 : 0 : }
162 : :
163 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|