LCOV - code coverage report
Current view: top level - sw/source/core/access - parachangetrackinginfo.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 14 69 20.3 %
Date: 2012-08-25 Functions: 3 5 60.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 3 64 4.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2008 by Sun Microsystems, Inc.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <parachangetrackinginfo.hxx>
      31                 :            : 
      32                 :            : #include <wrong.hxx>
      33                 :            : #include <com/sun/star/text/TextMarkupType.hpp>
      34                 :            : 
      35                 :            : #include <txtfrm.hxx>
      36                 :            : #include <ndtxt.hxx>
      37                 :            : #include <IDocumentRedlineAccess.hxx>
      38                 :            : #include <docary.hxx>
      39                 :            : #include <redline.hxx>
      40                 :            : 
      41                 :            : namespace css = com::sun::star;
      42                 :            : 
      43                 :            : namespace {
      44                 :          0 :     void initChangeTrackTextMarkupLists( const SwTxtFrm& rTxtFrm,
      45                 :            :                                          SwWrongList*& opChangeTrackInsertionTextMarkupList,
      46                 :            :                                          SwWrongList*& opChangeTrackDeletionTextMarkupList,
      47                 :            :                                          SwWrongList*& opChangeTrackFormatChangeTextMarkupList )
      48                 :            :     {
      49         [ #  # ]:          0 :         opChangeTrackInsertionTextMarkupList = new SwWrongList( WRONGLIST_CHANGETRACKING );
      50         [ #  # ]:          0 :         opChangeTrackDeletionTextMarkupList = new SwWrongList( WRONGLIST_CHANGETRACKING );
      51         [ #  # ]:          0 :         opChangeTrackFormatChangeTextMarkupList = new SwWrongList( WRONGLIST_CHANGETRACKING );
      52                 :            : 
      53         [ #  # ]:          0 :         if ( !rTxtFrm.GetTxtNode() )
      54                 :            :         {
      55                 :            :             OSL_FAIL( "<initChangeTrackTextMarkupLists(..) - missing <SwTxtNode> instance!" );
      56                 :          0 :             return;
      57                 :            :         }
      58                 :          0 :         const SwTxtNode& rTxtNode( *(rTxtFrm.GetTxtNode()) );
      59                 :            : 
      60                 :          0 :         const IDocumentRedlineAccess* pIDocChangeTrack( rTxtNode.getIDocumentRedlineAccess() );
      61         [ #  # ]:          0 :         if ( !pIDocChangeTrack )
      62                 :            :         {
      63                 :            :             OSL_FAIL( "<initChangeTrackTextMarkupLists(..) - missing <IDocumentRedlineAccess> instance!" );
      64                 :          0 :             return;
      65                 :            :         }
      66                 :            : 
      67   [ #  #  #  # ]:          0 :         if ( !IDocumentRedlineAccess::IsShowChanges( pIDocChangeTrack->GetRedlineMode() ) ||
                 [ #  # ]
      68                 :          0 :              pIDocChangeTrack->GetRedlineTbl().empty() )
      69                 :            :         {
      70                 :            :             // nothing to do --> empty change track text markup lists.
      71                 :          0 :             return;
      72                 :            :         }
      73                 :            : 
      74                 :            :         const sal_uInt16 nIdxOfFirstRedlineForTxtNode =
      75                 :          0 :                     pIDocChangeTrack->GetRedlinePos( rTxtNode, USHRT_MAX );
      76         [ #  # ]:          0 :         if ( nIdxOfFirstRedlineForTxtNode == USHRT_MAX )
      77                 :            :         {
      78                 :            :             // nothing to do --> empty change track text markup lists.
      79                 :          0 :             return;
      80                 :            :         }
      81                 :            : 
      82                 :          0 :         const xub_StrLen nTxtFrmTextStartPos = rTxtFrm.IsFollow()
      83                 :            :                                                ? rTxtFrm.GetOfst()
      84         [ #  # ]:          0 :                                                : 0;
      85                 :          0 :         const xub_StrLen nTxtFrmTextEndPos = rTxtFrm.HasFollow()
      86                 :          0 :                                              ? rTxtFrm.GetFollow()->GetOfst()
      87         [ #  # ]:          0 :                                              : rTxtFrm.GetTxt().Len();
      88                 :            : 
      89                 :            :         // iteration over the redlines which overlap with the text node.
      90                 :          0 :         const SwRedlineTbl& rRedlineTbl = pIDocChangeTrack->GetRedlineTbl();
      91                 :          0 :         const sal_uInt16 nRedlineCount( rRedlineTbl.size() );
      92         [ #  # ]:          0 :         for ( sal_uInt16 nActRedline = nIdxOfFirstRedlineForTxtNode;
      93                 :            :               nActRedline < nRedlineCount;
      94                 :            :               ++nActRedline)
      95                 :            :         {
      96         [ #  # ]:          0 :             const SwRedline* pActRedline = rRedlineTbl[ nActRedline ];
      97 [ #  # ][ #  # ]:          0 :             if ( pActRedline->Start()->nNode > rTxtNode.GetIndex() )
      98                 :            :             {
      99                 :            :                 break;
     100                 :            :             }
     101                 :            : 
     102                 :          0 :             xub_StrLen nTxtNodeChangeTrackStart( STRING_LEN );
     103                 :          0 :             xub_StrLen nTxtNodeChangeTrackEnd( STRING_LEN );
     104                 :            :             pActRedline->CalcStartEnd( rTxtNode.GetIndex(),
     105                 :            :                                        nTxtNodeChangeTrackStart,
     106         [ #  # ]:          0 :                                        nTxtNodeChangeTrackEnd );
     107 [ #  # ][ #  # ]:          0 :             if ( nTxtNodeChangeTrackStart > nTxtFrmTextEndPos ||
     108                 :            :                  nTxtNodeChangeTrackEnd < nTxtFrmTextStartPos )
     109                 :            :             {
     110                 :            :                 // Consider only redlines which overlap with the text frame's text.
     111                 :          0 :                 continue;
     112                 :            :             }
     113                 :            : 
     114                 :          0 :             SwWrongList* pMarkupList( 0 );
     115         [ #  # ]:          0 :             switch ( pActRedline->GetType() )
           [ #  #  #  # ]
     116                 :            :             {
     117                 :            :                 case nsRedlineType_t::REDLINE_INSERT:
     118                 :            :                 {
     119                 :          0 :                     pMarkupList = opChangeTrackInsertionTextMarkupList;
     120                 :            :                 }
     121                 :          0 :                 break;
     122                 :            :                 case nsRedlineType_t::REDLINE_DELETE:
     123                 :            :                 {
     124                 :          0 :                     pMarkupList = opChangeTrackDeletionTextMarkupList;
     125                 :            :                 }
     126                 :          0 :                 break;
     127                 :            :                 case nsRedlineType_t::REDLINE_FORMAT:
     128                 :            :                 {
     129                 :          0 :                     pMarkupList = opChangeTrackFormatChangeTextMarkupList;
     130                 :            :                 }
     131                 :          0 :                 break;
     132                 :            :                 default:
     133                 :            :                 {
     134                 :            :                     // other types are not considered
     135                 :            :                 }
     136                 :            :             }
     137         [ #  # ]:          0 :             if ( pMarkupList )
     138                 :            :             {
     139                 :            :                 const xub_StrLen nTxtFrmChangeTrackStart =
     140                 :            :                                     nTxtNodeChangeTrackStart <= nTxtFrmTextStartPos
     141                 :            :                                     ? nTxtFrmTextStartPos
     142         [ #  # ]:          0 :                                     : nTxtNodeChangeTrackStart;
     143                 :            : 
     144                 :            :                 const xub_StrLen nTxtFrmChangeTrackEnd =
     145                 :            :                                     nTxtNodeChangeTrackEnd >= nTxtFrmTextEndPos
     146                 :            :                                     ? nTxtFrmTextEndPos
     147         [ #  # ]:          0 :                                     : nTxtNodeChangeTrackEnd;
     148                 :            : 
     149                 :            :                 pMarkupList->Insert( rtl::OUString(), 0,
     150                 :            :                                      nTxtFrmChangeTrackStart,
     151                 :            :                                      nTxtFrmChangeTrackEnd - nTxtFrmChangeTrackStart,
     152 [ #  # ][ #  # ]:          0 :                                      pMarkupList->Count() );
     153                 :            :             }
     154                 :            :         } // eof iteration over the redlines which overlap with the text node
     155                 :            :     }
     156                 :            : } // eof anonymous namespace
     157                 :            : 
     158                 :         33 : SwParaChangeTrackingInfo::SwParaChangeTrackingInfo( const SwTxtFrm& rTxtFrm )
     159                 :            :     : mrTxtFrm( rTxtFrm )
     160                 :            :     , mpChangeTrackInsertionTextMarkupList( 0 )
     161                 :            :     , mpChangeTrackDeletionTextMarkupList( 0 )
     162                 :         33 :     , mpChangeTrackFormatChangeTextMarkupList( 0 )
     163                 :            : {
     164                 :         33 : }
     165                 :            : 
     166                 :            : 
     167                 :         33 : SwParaChangeTrackingInfo::~SwParaChangeTrackingInfo()
     168                 :            : {
     169                 :         33 :     reset();
     170                 :         33 : }
     171                 :            : 
     172                 :        207 : void SwParaChangeTrackingInfo::reset()
     173                 :            : {
     174         [ -  + ]:        207 :     delete mpChangeTrackInsertionTextMarkupList;
     175                 :        207 :     mpChangeTrackInsertionTextMarkupList = 0;
     176                 :            : 
     177         [ -  + ]:        207 :     delete mpChangeTrackDeletionTextMarkupList;
     178                 :        207 :     mpChangeTrackDeletionTextMarkupList = 0;
     179                 :            : 
     180         [ -  + ]:        207 :     delete mpChangeTrackFormatChangeTextMarkupList;
     181                 :        207 :     mpChangeTrackFormatChangeTextMarkupList = 0;
     182                 :        207 : }
     183                 :            : 
     184                 :          0 : const SwWrongList* SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList( const sal_Int32 nTextMarkupType )
     185                 :            : {
     186                 :          0 :     SwWrongList* pChangeTrackingTextMarkupList = 0;
     187                 :            : 
     188         [ #  # ]:          0 :     if ( mpChangeTrackInsertionTextMarkupList == 0 )
     189                 :            :     {
     190                 :            :         OSL_ENSURE( mpChangeTrackDeletionTextMarkupList == 0,
     191                 :            :                 "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..) - <mpChangeTrackDeletionTextMarkupList> expected to be NULL." );
     192                 :            :         OSL_ENSURE( mpChangeTrackFormatChangeTextMarkupList == 0,
     193                 :            :                 "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..) - <mpChangeTrackFormatChangeTextMarkupList> expected to be NULL." );
     194                 :            :         initChangeTrackTextMarkupLists( mrTxtFrm,
     195                 :            :                                         mpChangeTrackInsertionTextMarkupList,
     196                 :            :                                         mpChangeTrackDeletionTextMarkupList,
     197                 :          0 :                                         mpChangeTrackFormatChangeTextMarkupList );
     198                 :            :     }
     199                 :            : 
     200   [ #  #  #  # ]:          0 :     switch ( nTextMarkupType )
     201                 :            :     {
     202                 :            :         case css::text::TextMarkupType::TRACK_CHANGE_INSERTION:
     203                 :            :         {
     204                 :          0 :             pChangeTrackingTextMarkupList = mpChangeTrackInsertionTextMarkupList;
     205                 :            :         }
     206                 :          0 :         break;
     207                 :            :         case css::text::TextMarkupType::TRACK_CHANGE_DELETION:
     208                 :            :         {
     209                 :          0 :             pChangeTrackingTextMarkupList = mpChangeTrackDeletionTextMarkupList;
     210                 :            :         }
     211                 :          0 :         break;
     212                 :            :         case css::text::TextMarkupType::TRACK_CHANGE_FORMATCHANGE:
     213                 :            :         {
     214                 :          0 :             pChangeTrackingTextMarkupList = mpChangeTrackFormatChangeTextMarkupList;
     215                 :            :         }
     216                 :          0 :         break;
     217                 :            :         default:
     218                 :            :         {
     219                 :            :             OSL_FAIL( "<SwParaChangeTrackingInfo::getChangeTrackingTextMarkupList(..)> - misusage - unexpected text markup type for change tracking." );
     220                 :            :         }
     221                 :            :     }
     222                 :            : 
     223                 :          0 :     return pChangeTrackingTextMarkupList;
     224                 :            : }
     225                 :            : 
     226                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10