LCOV - code coverage report
Current view: top level - sw/source/core/access - parachangetrackinginfo.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 14 71 19.7 %
Date: 2014-04-11 Functions: 3 5 60.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 <parachangetrackinginfo.hxx>
      21             : 
      22             : #include <wrong.hxx>
      23             : #include <com/sun/star/text/TextMarkupType.hpp>
      24             : 
      25             : #include <txtfrm.hxx>
      26             : #include <ndtxt.hxx>
      27             : #include <IDocumentRedlineAccess.hxx>
      28             : #include <docary.hxx>
      29             : #include <redline.hxx>
      30             : 
      31             : #include <algorithm>
      32             : 
      33             : namespace {
      34           0 :     void initChangeTrackTextMarkupLists( const SwTxtFrm& rTxtFrm,
      35             :                                          SwWrongList*& opChangeTrackInsertionTextMarkupList,
      36             :                                          SwWrongList*& opChangeTrackDeletionTextMarkupList,
      37             :                                          SwWrongList*& opChangeTrackFormatChangeTextMarkupList )
      38             :     {
      39           0 :         opChangeTrackInsertionTextMarkupList = new SwWrongList( WRONGLIST_CHANGETRACKING );
      40           0 :         opChangeTrackDeletionTextMarkupList = new SwWrongList( WRONGLIST_CHANGETRACKING );
      41           0 :         opChangeTrackFormatChangeTextMarkupList = new SwWrongList( WRONGLIST_CHANGETRACKING );
      42             : 
      43           0 :         if ( !rTxtFrm.GetTxtNode() )
      44             :         {
      45             :             OSL_FAIL( "<initChangeTrackTextMarkupLists(..) - missing <SwTxtNode> instance!" );
      46           0 :             return;
      47             :         }
      48           0 :         const SwTxtNode& rTxtNode( *(rTxtFrm.GetTxtNode()) );
      49             : 
      50           0 :         const IDocumentRedlineAccess* pIDocChangeTrack( rTxtNode.getIDocumentRedlineAccess() );
      51           0 :         if ( !pIDocChangeTrack )
      52             :         {
      53             :             OSL_FAIL( "<initChangeTrackTextMarkupLists(..) - missing <IDocumentRedlineAccess> instance!" );
      54           0 :             return;
      55             :         }
      56             : 
      57           0 :         if ( !IDocumentRedlineAccess::IsShowChanges( pIDocChangeTrack->GetRedlineMode() ) ||
      58           0 :              pIDocChangeTrack->GetRedlineTbl().empty() )
      59             :         {
      60             :             // nothing to do --> empty change track text markup lists.
      61           0 :             return;
      62             :         }
      63             : 
      64             :         const sal_uInt16 nIdxOfFirstRedlineForTxtNode =
      65           0 :                     pIDocChangeTrack->GetRedlinePos( rTxtNode, USHRT_MAX );
      66           0 :         if ( nIdxOfFirstRedlineForTxtNode == USHRT_MAX )
      67             :         {
      68             :             // nothing to do --> empty change track text markup lists.
      69           0 :             return;
      70             :         }
      71             : 
      72           0 :         const sal_Int32 nTxtFrmTextStartPos = rTxtFrm.IsFollow()
      73             :                                                ? rTxtFrm.GetOfst()
      74           0 :                                                : 0;
      75           0 :         const sal_Int32 nTxtFrmTextEndPos = rTxtFrm.HasFollow()
      76           0 :                                              ? rTxtFrm.GetFollow()->GetOfst()
      77           0 :                                              : rTxtFrm.GetTxt().getLength();
      78             : 
      79             :         // iteration over the redlines which overlap with the text node.
      80           0 :         const SwRedlineTbl& rRedlineTbl = pIDocChangeTrack->GetRedlineTbl();
      81           0 :         const sal_uInt16 nRedlineCount( rRedlineTbl.size() );
      82           0 :         for ( sal_uInt16 nActRedline = nIdxOfFirstRedlineForTxtNode;
      83             :               nActRedline < nRedlineCount;
      84             :               ++nActRedline)
      85             :         {
      86           0 :             const SwRangeRedline* pActRedline = rRedlineTbl[ nActRedline ];
      87           0 :             if ( pActRedline->Start()->nNode > rTxtNode.GetIndex() )
      88             :             {
      89           0 :                 break;
      90             :             }
      91             : 
      92           0 :             sal_Int32 nTxtNodeChangeTrackStart(COMPLETE_STRING);
      93           0 :             sal_Int32 nTxtNodeChangeTrackEnd(COMPLETE_STRING);
      94             :             pActRedline->CalcStartEnd( rTxtNode.GetIndex(),
      95             :                                        nTxtNodeChangeTrackStart,
      96           0 :                                        nTxtNodeChangeTrackEnd );
      97           0 :             if ( nTxtNodeChangeTrackStart > nTxtFrmTextEndPos ||
      98           0 :                  nTxtNodeChangeTrackEnd < nTxtFrmTextStartPos )
      99             :             {
     100             :                 // Consider only redlines which overlap with the text frame's text.
     101           0 :                 continue;
     102             :             }
     103             : 
     104           0 :             SwWrongList* pMarkupList( 0 );
     105           0 :             switch ( pActRedline->GetType() )
     106             :             {
     107             :                 case nsRedlineType_t::REDLINE_INSERT:
     108             :                 {
     109           0 :                     pMarkupList = opChangeTrackInsertionTextMarkupList;
     110             :                 }
     111           0 :                 break;
     112             :                 case nsRedlineType_t::REDLINE_DELETE:
     113             :                 {
     114           0 :                     pMarkupList = opChangeTrackDeletionTextMarkupList;
     115             :                 }
     116           0 :                 break;
     117             :                 case nsRedlineType_t::REDLINE_FORMAT:
     118             :                 {
     119           0 :                     pMarkupList = opChangeTrackFormatChangeTextMarkupList;
     120             :                 }
     121           0 :                 break;
     122             :                 default:
     123             :                 {
     124             :                     // other types are not considered
     125             :                 }
     126             :             }
     127           0 :             if ( pMarkupList )
     128             :             {
     129             :                 const sal_Int32 nTxtFrmChangeTrackStart =
     130           0 :                     std::max(nTxtNodeChangeTrackStart, nTxtFrmTextStartPos);
     131             : 
     132             :                 const sal_Int32 nTxtFrmChangeTrackEnd =
     133           0 :                     std::min(nTxtNodeChangeTrackEnd, nTxtFrmTextEndPos);
     134             : 
     135             :                 pMarkupList->Insert( OUString(), 0,
     136             :                                      nTxtFrmChangeTrackStart,
     137             :                                      nTxtFrmChangeTrackEnd - nTxtFrmChangeTrackStart,
     138           0 :                                      pMarkupList->Count() );
     139             :             }
     140             :         } // eof iteration over the redlines which overlap with the text node
     141             :     }
     142             : } // eof anonymous namespace
     143             : 
     144          47 : SwParaChangeTrackingInfo::SwParaChangeTrackingInfo( const SwTxtFrm& rTxtFrm )
     145             :     : mrTxtFrm( rTxtFrm )
     146             :     , mpChangeTrackInsertionTextMarkupList( 0 )
     147             :     , mpChangeTrackDeletionTextMarkupList( 0 )
     148          47 :     , mpChangeTrackFormatChangeTextMarkupList( 0 )
     149             : {
     150          47 : }
     151             : 
     152          47 : SwParaChangeTrackingInfo::~SwParaChangeTrackingInfo()
     153             : {
     154          47 :     reset();
     155          47 : }
     156             : 
     157         129 : void SwParaChangeTrackingInfo::reset()
     158             : {
     159         129 :     delete mpChangeTrackInsertionTextMarkupList;
     160         129 :     mpChangeTrackInsertionTextMarkupList = 0;
     161             : 
     162         129 :     delete mpChangeTrackDeletionTextMarkupList;
     163         129 :     mpChangeTrackDeletionTextMarkupList = 0;
     164             : 
     165         129 :     delete mpChangeTrackFormatChangeTextMarkupList;
     166         129 :     mpChangeTrackFormatChangeTextMarkupList = 0;
     167         129 : }
     168             : 
     169           0 : const SwWrongList* SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList( const sal_Int32 nTextMarkupType )
     170             : {
     171           0 :     SwWrongList* pChangeTrackingTextMarkupList = 0;
     172             : 
     173           0 :     if ( mpChangeTrackInsertionTextMarkupList == 0 )
     174             :     {
     175             :         OSL_ENSURE( mpChangeTrackDeletionTextMarkupList == 0,
     176             :                 "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..) - <mpChangeTrackDeletionTextMarkupList> expected to be NULL." );
     177             :         OSL_ENSURE( mpChangeTrackFormatChangeTextMarkupList == 0,
     178             :                 "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..) - <mpChangeTrackFormatChangeTextMarkupList> expected to be NULL." );
     179             :         initChangeTrackTextMarkupLists( mrTxtFrm,
     180             :                                         mpChangeTrackInsertionTextMarkupList,
     181             :                                         mpChangeTrackDeletionTextMarkupList,
     182           0 :                                         mpChangeTrackFormatChangeTextMarkupList );
     183             :     }
     184             : 
     185           0 :     switch ( nTextMarkupType )
     186             :     {
     187             :         case css::text::TextMarkupType::TRACK_CHANGE_INSERTION:
     188             :         {
     189           0 :             pChangeTrackingTextMarkupList = mpChangeTrackInsertionTextMarkupList;
     190             :         }
     191           0 :         break;
     192             :         case css::text::TextMarkupType::TRACK_CHANGE_DELETION:
     193             :         {
     194           0 :             pChangeTrackingTextMarkupList = mpChangeTrackDeletionTextMarkupList;
     195             :         }
     196           0 :         break;
     197             :         case css::text::TextMarkupType::TRACK_CHANGE_FORMATCHANGE:
     198             :         {
     199           0 :             pChangeTrackingTextMarkupList = mpChangeTrackFormatChangeTextMarkupList;
     200             :         }
     201           0 :         break;
     202             :         default:
     203             :         {
     204             :             OSL_FAIL( "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..)> - misusage - unexpected text markup type for change tracking." );
     205             :         }
     206             :     }
     207             : 
     208           0 :     return pChangeTrackingTextMarkupList;
     209             : }
     210             : 
     211             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10