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

Generated by: LCOV version 1.10