LCOV - code coverage report
Current view: top level - sw/source/core/crsr - annotationmark.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 34 35 97.1 %
Date: 2014-04-11 Functions: 5 7 71.4 %
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 <annotationmark.hxx>
      21             : 
      22             : #include <doc.hxx>
      23             : #include <IDocumentMarkAccess.hxx>
      24             : #include <fldbas.hxx>
      25             : #include <switerator.hxx>
      26             : #include <fmtfld.hxx>
      27             : #include <docufld.hxx>
      28             : #include <IDocumentUndoRedo.hxx>
      29             : #include <UndoBookmark.hxx>
      30             : #include <ndtxt.hxx>
      31             : #include <txtfld.hxx>
      32             : 
      33             : namespace sw { namespace mark
      34             : {
      35          39 :     AnnotationMark::AnnotationMark(
      36             :         const SwPaM& rPaM,
      37             :         const ::rtl::OUString& rName )
      38          39 :         : MarkBase( rPaM, rName )
      39             :     {
      40          39 :         if ( rName.getLength() == 0 )
      41             :         {
      42          28 :             SetName( MarkBase::GenerateNewName( ::rtl::OUString::createFromAscii("__Annotation__") ) );
      43             :         }
      44          39 :     }
      45             : 
      46         117 :     AnnotationMark::~AnnotationMark()
      47             :     {
      48         117 :     }
      49             : 
      50          39 :     void AnnotationMark::InitDoc(SwDoc* const io_pDoc)
      51             :     {
      52             :         SwTxtFld* pTxtFld =
      53          39 :             GetMarkEnd().nNode.GetNode().GetTxtNode()->GetFldTxtAttrAt(
      54          78 :             GetMarkEnd().nContent.GetIndex()-1, true );
      55             :         OSL_ENSURE( pTxtFld != NULL, "<AnnotationMark::InitDoc(..)> - missing text attribute for annotation field!" );
      56          39 :         if ( pTxtFld != NULL )
      57             :         {
      58          39 :             const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTxtFld->GetFmtFld().GetField());
      59             :             OSL_ENSURE( pPostItField != NULL, "<AnnotationMark::InitDoc(..)> - annotation field missing!" );
      60          39 :             if ( pPostItField != NULL )
      61             :             {
      62             :                 // use the annotation mark's name as the annotation name, if
      63             :                 // - the annotation field has an empty annotation name or
      64             :                 // - the annotation mark's name differs (on mark creation a name clash had been detected)
      65         156 :                 if ( pPostItField->GetName().isEmpty()
      66         156 :                     || rtl::OUString( pPostItField->GetName() ) != GetName() )
      67             :                 {
      68          28 :                     const_cast<SwPostItField*>(pPostItField)->SetName( GetName() );
      69             :                 }
      70             :             }
      71             :         }
      72             : 
      73          39 :         if (io_pDoc->GetIDocumentUndoRedo().DoesUndo())
      74             :         {
      75           1 :             io_pDoc->GetIDocumentUndoRedo().AppendUndo( new SwUndoInsBookmark(*this) );
      76             :         }
      77          39 :         io_pDoc->SetModified();
      78          39 :     }
      79             : 
      80          34 :     const SwFmtFld* AnnotationMark::GetAnnotationFmtFld() const
      81             :     {
      82          34 :         SwDoc* pDoc = GetMarkPos().GetDoc();
      83          34 :         if ( pDoc == NULL )
      84             :         {
      85             :             OSL_ENSURE( false, "<AnnotationMark::GetAnnotationFmtFld()> - missing document at annotation mark" );
      86           0 :             return NULL;
      87             :         }
      88             : 
      89          34 :         SwFmtFld* pAnnotationFmtFld = NULL;
      90             : 
      91          34 :         SwFieldType* pType = pDoc->GetFldType( RES_POSTITFLD, OUString(), false );
      92          34 :         SwIterator<SwFmtFld,SwFieldType> aIter( *pType );
      93          53 :         for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld != NULL; pFmtFld = aIter.Next() )
      94             :         {
      95          53 :             if ( pFmtFld->IsFldInDoc() )
      96             :             {
      97          53 :                 const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pFmtFld->GetField());
      98         106 :                 if ( pPostItField != NULL
      99         159 :                      && rtl::OUString( pPostItField->GetName() ) == GetName() )
     100             :                 {
     101          34 :                     pAnnotationFmtFld = pFmtFld;
     102          34 :                     break;
     103             :                 }
     104             :             }
     105             :         }
     106             : 
     107          34 :         return pAnnotationFmtFld;
     108             :     }
     109             : }}
     110             : 
     111             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10