LCOV - code coverage report
Current view: top level - sw/source/core/undo - SwUndoField.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 14 66 21.2 %
Date: 2014-11-03 Functions: 7 20 35.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #include <tools/rtti.hxx>
      21             : 
      22             : #include <SwUndoField.hxx>
      23             : #include <swundo.hxx>
      24             : #include <doc.hxx>
      25             : #include <IDocumentUndoRedo.hxx>
      26             : #include <DocumentFieldsManager.hxx>
      27             : #include <txtfld.hxx>
      28             : #include <fldbas.hxx>
      29             : #include <ndtxt.hxx>
      30             : #include <fmtfld.hxx>
      31             : #include <dbfld.hxx>
      32             : #include <docsh.hxx>
      33             : 
      34             : using namespace ::com::sun::star::uno;
      35             : 
      36         104 : SwUndoField::SwUndoField(const SwPosition & rPos, SwUndoId _nId )
      37         104 :     : SwUndo(_nId)
      38             : {
      39         104 :     nNodeIndex = rPos.nNode.GetIndex();
      40         104 :     nOffset = rPos.nContent.GetIndex();
      41         104 :     pDoc = rPos.GetDoc();
      42         104 : }
      43             : 
      44         104 : SwUndoField::~SwUndoField()
      45             : {
      46         104 : }
      47             : 
      48           0 : SwPosition SwUndoField::GetPosition()
      49             : {
      50           0 :     SwNode * pNode = pDoc->GetNodes()[nNodeIndex];
      51           0 :     SwNodeIndex aNodeIndex(*pNode);
      52           0 :     SwIndex aIndex(pNode->GetCntntNode(), nOffset);
      53           0 :     SwPosition aResult(aNodeIndex, aIndex);
      54             : 
      55           0 :     return aResult;
      56             : }
      57             : 
      58           0 : SwUndoFieldFromDoc::SwUndoFieldFromDoc(const SwPosition & rPos,
      59             :                          const SwField & rOldField,
      60             :                          const SwField & rNewField,
      61             :                          SwMsgPoolItem * _pHnt, bool _bUpdate, SwUndoId _nId)
      62             :     : SwUndoField(rPos,_nId)
      63           0 :     , pOldField(rOldField.CopyField())
      64           0 :     , pNewField(rNewField.CopyField())
      65             :     , pHnt(_pHnt)
      66           0 :     , bUpdate(_bUpdate)
      67             : {
      68             :     OSL_ENSURE(pOldField, "No old field!");
      69             :     OSL_ENSURE(pNewField, "No new field!");
      70             :     OSL_ENSURE(pDoc, "No document!");
      71           0 : }
      72             : 
      73           0 : SwUndoFieldFromDoc::~SwUndoFieldFromDoc()
      74             : {
      75           0 :     delete pOldField;
      76           0 :     delete pNewField;
      77           0 : }
      78             : 
      79           0 : void SwUndoFieldFromDoc::UndoImpl(::sw::UndoRedoContext &)
      80             : {
      81           0 :     SwTxtFld * pTxtFld = sw::DocumentFieldsManager::GetTxtFldAtPos(GetPosition());
      82           0 :     const SwField * pField = pTxtFld ? pTxtFld->GetFmtFld().GetField() : NULL;
      83             : 
      84           0 :     if (pField)
      85             :     {
      86           0 :         pDoc->getIDocumentFieldsAccess().UpdateFld(pTxtFld, *pOldField, pHnt, bUpdate);
      87             :     }
      88           0 : }
      89             : 
      90           0 : void SwUndoFieldFromDoc::DoImpl()
      91             : {
      92           0 :     SwTxtFld * pTxtFld = sw::DocumentFieldsManager::GetTxtFldAtPos(GetPosition());
      93           0 :     const SwField * pField = pTxtFld ? pTxtFld->GetFmtFld().GetField() : NULL;
      94             : 
      95           0 :     if (pField)
      96             :     {
      97           0 :         pDoc->getIDocumentFieldsAccess().UpdateFld(pTxtFld, *pNewField, pHnt, bUpdate);
      98           0 :         SwFmtFld* pDstFmtFld = (SwFmtFld*)&pTxtFld->GetFmtFld();
      99             : 
     100           0 :         if ( pDoc->getIDocumentFieldsAccess().GetFldType(RES_POSTITFLD, aEmptyOUStr, false) == pDstFmtFld->GetField()->GetTyp() )
     101           0 :             pDoc->GetDocShell()->Broadcast( SwFmtFldHint( pDstFmtFld, SwFmtFldHintWhich::INSERTED ) );
     102             :     }
     103           0 : }
     104             : 
     105           0 : void SwUndoFieldFromDoc::RedoImpl(::sw::UndoRedoContext &)
     106             : {
     107           0 :     DoImpl();
     108           0 : }
     109             : 
     110           0 : void SwUndoFieldFromDoc::RepeatImpl(::sw::RepeatContext &)
     111             : {
     112           0 :     ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
     113           0 :     DoImpl();
     114           0 : }
     115             : 
     116         104 : SwUndoFieldFromAPI::SwUndoFieldFromAPI(const SwPosition & rPos,
     117             :                                        const Any & rOldVal, const Any & rNewVal,
     118             :                                        sal_uInt16 _nWhich)
     119         104 :     : SwUndoField(rPos), aOldVal(rOldVal), aNewVal(rNewVal), nWhich(_nWhich)
     120             : {
     121         104 : }
     122             : 
     123         208 : SwUndoFieldFromAPI::~SwUndoFieldFromAPI()
     124             : {
     125         208 : }
     126             : 
     127           0 : void SwUndoFieldFromAPI::UndoImpl(::sw::UndoRedoContext &)
     128             : {
     129           0 :     SwField * pField = sw::DocumentFieldsManager::GetFieldAtPos(GetPosition());
     130             : 
     131           0 :     if (pField)
     132           0 :         pField->PutValue(aOldVal, nWhich);
     133           0 : }
     134             : 
     135           0 : void SwUndoFieldFromAPI::DoImpl()
     136             : {
     137           0 :     SwField * pField = sw::DocumentFieldsManager::GetFieldAtPos(GetPosition());
     138             : 
     139           0 :     if (pField)
     140           0 :         pField->PutValue(aNewVal, nWhich);
     141           0 : }
     142             : 
     143           0 : void SwUndoFieldFromAPI::RedoImpl(::sw::UndoRedoContext &)
     144             : {
     145           0 :     DoImpl();
     146           0 : }
     147             : 
     148           0 : void SwUndoFieldFromAPI::RepeatImpl(::sw::RepeatContext &)
     149             : {
     150           0 :     DoImpl();
     151         270 : }
     152             : 
     153             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10