LCOV - code coverage report
Current view: top level - sw/source/core/crsr - annotationmark.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 34 35 97.1 %
Date: 2015-06-13 12:38:46 Functions: 7 9 77.8 %
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 <IDocumentFieldsAccess.hxx>
      25             : #include <IDocumentState.hxx>
      26             : #include <fldbas.hxx>
      27             : #include <calbck.hxx>
      28             : #include <fmtfld.hxx>
      29             : #include <docufld.hxx>
      30             : #include <IDocumentUndoRedo.hxx>
      31             : #include <UndoBookmark.hxx>
      32             : #include <ndtxt.hxx>
      33             : #include <txtfld.hxx>
      34             : 
      35             : namespace sw { namespace mark
      36             : {
      37          58 :     AnnotationMark::AnnotationMark(
      38             :         const SwPaM& rPaM,
      39             :         const OUString& rName )
      40          58 :         : MarkBase( rPaM, rName )
      41             :     {
      42          58 :         if ( rName.getLength() == 0 )
      43             :         {
      44          40 :             SetName( MarkBase::GenerateNewName("__Annotation__") );
      45             :         }
      46          58 :     }
      47             : 
      48         174 :     AnnotationMark::~AnnotationMark()
      49             :     {
      50         174 :     }
      51             : 
      52          58 :     void AnnotationMark::InitDoc(SwDoc* const io_pDoc)
      53             :     {
      54          58 :         SwTextNode *pTextNode = GetMarkEnd().nNode.GetNode().GetTextNode();
      55             : 
      56             :         SwTextField* pTextField = pTextNode ?
      57             :             pTextNode->GetFieldTextAttrAt(
      58          58 :             GetMarkEnd().nContent.GetIndex()-1, true ) : NULL;
      59             :         OSL_ENSURE( pTextField != NULL, "<AnnotationMark::InitDoc(..)> - missing text attribute for annotation field!" );
      60          58 :         if ( pTextField != NULL )
      61             :         {
      62          58 :             const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextField->GetFormatField().GetField());
      63             :             OSL_ENSURE( pPostItField != NULL, "<AnnotationMark::InitDoc(..)> - annotation field missing!" );
      64          58 :             if ( pPostItField != NULL )
      65             :             {
      66             :                 // use the annotation mark's name as the annotation name, if
      67             :                 // - the annotation field has an empty annotation name or
      68             :                 // - the annotation mark's name differs (on mark creation a name clash had been detected)
      69         214 :                 if ( pPostItField->GetName().isEmpty()
      70         192 :                     || OUString( pPostItField->GetName() ) != GetName() )
      71             :                 {
      72          40 :                     const_cast<SwPostItField*>(pPostItField)->SetName( GetName() );
      73             :                 }
      74             :             }
      75             :         }
      76             : 
      77          58 :         if (io_pDoc->GetIDocumentUndoRedo().DoesUndo())
      78             :         {
      79           1 :             io_pDoc->GetIDocumentUndoRedo().AppendUndo( new SwUndoInsBookmark(*this) );
      80             :         }
      81          58 :         io_pDoc->getIDocumentState().SetModified();
      82          58 :     }
      83             : 
      84         135 :     const SwFormatField* AnnotationMark::GetAnnotationFormatField() const
      85             :     {
      86         135 :         SwDoc* pDoc = GetMarkPos().GetDoc();
      87         135 :         if ( pDoc == NULL )
      88             :         {
      89             :             OSL_ENSURE( false, "<AnnotationMark::GetAnnotationFormatField()> - missing document at annotation mark" );
      90           0 :             return NULL;
      91             :         }
      92             : 
      93         135 :         SwFormatField* pAnnotationFormatField = NULL;
      94             : 
      95         135 :         SwFieldType* pType = pDoc->getIDocumentFieldsAccess().GetFieldType( RES_POSTITFLD, OUString(), false );
      96         135 :         SwIterator<SwFormatField,SwFieldType> aIter( *pType );
      97         394 :         for( SwFormatField* pFormatField = aIter.First(); pFormatField != NULL; pFormatField = aIter.Next() )
      98             :         {
      99         394 :             if ( pFormatField->IsFieldInDoc() )
     100             :             {
     101         394 :                 const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pFormatField->GetField());
     102         394 :                 if (pPostItField != NULL && pPostItField->GetName() == GetName())
     103             :                 {
     104         135 :                     pAnnotationFormatField = pFormatField;
     105         135 :                     break;
     106             :                 }
     107             :             }
     108             :         }
     109             : 
     110         135 :         return pAnnotationFormatField;
     111             :     }
     112         177 : }}
     113             : 
     114             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11