LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/undo - SwUndoField.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 66 0.0 %
Date: 2012-12-27 Functions: 0 18 0.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             : 
      21             : #include <tools/rtti.hxx>
      22             : 
      23             : #include <SwUndoField.hxx>
      24             : #include <swundo.hxx>
      25             : #include <doc.hxx>
      26             : #include <IDocumentUndoRedo.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           0 : SwUndoField::SwUndoField(const SwPosition & rPos, SwUndoId _nId )
      37           0 :     : SwUndo(_nId)
      38             : {
      39           0 :     nNodeIndex = rPos.nNode.GetIndex();
      40           0 :     nOffset = rPos.nContent.GetIndex();
      41           0 :     pDoc = rPos.GetDoc();
      42           0 : }
      43             : 
      44           0 : SwUndoField::~SwUndoField()
      45             : {
      46           0 : }
      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, sal_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 = SwDoc::GetTxtFld(GetPosition());
      82             : 
      83           0 :     const SwField * pField = pTxtFld ? pTxtFld->GetFld().GetFld() : NULL;
      84             : 
      85           0 :     if (pField)
      86             :     {
      87           0 :         pDoc->UpdateFld(pTxtFld, *pOldField, pHnt, bUpdate);
      88             :     }
      89           0 : }
      90             : 
      91           0 : void SwUndoFieldFromDoc::DoImpl()
      92             : {
      93           0 :     SwTxtFld * pTxtFld = SwDoc::GetTxtFld(GetPosition());
      94           0 :     const SwField * pField = pTxtFld ? pTxtFld->GetFld().GetFld() : NULL;
      95             : 
      96           0 :     if (pField)
      97             :     {
      98           0 :         pDoc->UpdateFld(pTxtFld, *pNewField, pHnt, bUpdate);
      99           0 :         SwFmtFld* pDstFmtFld = (SwFmtFld*)&pTxtFld->GetFld();
     100             : 
     101           0 :         if ( pDoc->GetFldType(RES_POSTITFLD, aEmptyStr,false) == pDstFmtFld->GetFld()->GetTyp() )
     102           0 :             pDoc->GetDocShell()->Broadcast( SwFmtFldHint( pDstFmtFld, SWFMTFLD_INSERTED ) );
     103             :     }
     104           0 : }
     105             : 
     106           0 : void SwUndoFieldFromDoc::RedoImpl(::sw::UndoRedoContext &)
     107             : {
     108           0 :     DoImpl();
     109           0 : }
     110             : 
     111           0 : void SwUndoFieldFromDoc::RepeatImpl(::sw::RepeatContext &)
     112             : {
     113           0 :     ::sw::UndoGuard const undoGuard(pDoc->GetIDocumentUndoRedo());
     114           0 :     DoImpl();
     115           0 : }
     116             : 
     117           0 : SwUndoFieldFromAPI::SwUndoFieldFromAPI(const SwPosition & rPos,
     118             :                                        const Any & rOldVal, const Any & rNewVal,
     119             :                                        sal_uInt16 _nWhich)
     120           0 :     : SwUndoField(rPos), aOldVal(rOldVal), aNewVal(rNewVal), nWhich(_nWhich)
     121             : {
     122           0 : }
     123             : 
     124           0 : SwUndoFieldFromAPI::~SwUndoFieldFromAPI()
     125             : {
     126           0 : }
     127             : 
     128           0 : void SwUndoFieldFromAPI::UndoImpl(::sw::UndoRedoContext &)
     129             : {
     130           0 :     SwField * pField = SwDoc::GetField(GetPosition());
     131             : 
     132           0 :     if (pField)
     133           0 :         pField->PutValue(aOldVal, nWhich);
     134           0 : }
     135             : 
     136           0 : void SwUndoFieldFromAPI::DoImpl()
     137             : {
     138           0 :     SwField * pField = SwDoc::GetField(GetPosition());
     139             : 
     140           0 :     if (pField)
     141           0 :         pField->PutValue(aNewVal, nWhich);
     142           0 : }
     143             : 
     144           0 : void SwUndoFieldFromAPI::RedoImpl(::sw::UndoRedoContext &)
     145             : {
     146           0 :     DoImpl();
     147           0 : }
     148             : 
     149           0 : void SwUndoFieldFromAPI::RepeatImpl(::sw::RepeatContext &)
     150             : {
     151           0 :     DoImpl();
     152           0 : }
     153             : 
     154             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10