LCOV - code coverage report
Current view: top level - sw/source/core/access - textmarkuphelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 65 0.0 %
Date: 2014-04-11 Functions: 0 6 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             : #include <textmarkuphelper.hxx>
      21             : #include <accportions.hxx>
      22             : 
      23             : #include <vector>
      24             : #include <algorithm>
      25             : 
      26             : #include <com/sun/star/text/TextMarkupType.hpp>
      27             : #include <com/sun/star/accessibility/TextSegment.hpp>
      28             : 
      29             : #include <ndtxt.hxx>
      30             : #include <wrong.hxx>
      31             : 
      32             : using namespace com::sun::star;
      33             : 
      34             : // helper functions
      35             : namespace {
      36           0 :     const SwWrongList* getTextMarkupList( const SwTxtNode& rTxtNode,
      37             :                                           const sal_Int32 nTextMarkupType )
      38             :         throw (::com::sun::star::lang::IllegalArgumentException,
      39             :                ::com::sun::star::uno::RuntimeException)
      40             :     {
      41           0 :         const SwWrongList* pTextMarkupList( 0 );
      42           0 :         switch ( nTextMarkupType )
      43             :         {
      44             :             case text::TextMarkupType::SPELLCHECK:
      45             :             {
      46           0 :                 pTextMarkupList = rTxtNode.GetWrong();
      47             :             }
      48           0 :             break;
      49             :             case text::TextMarkupType::PROOFREADING:
      50             :             {
      51             :                 // support not implemented yet
      52           0 :                 pTextMarkupList = 0;
      53             :             }
      54           0 :             break;
      55             :             case text::TextMarkupType::SMARTTAG:
      56             :             {
      57             :                 // support not implemented yet
      58           0 :                 pTextMarkupList = 0;
      59             :             }
      60           0 :             break;
      61             :             default:
      62             :             {
      63           0 :                 throw lang::IllegalArgumentException();
      64             :             }
      65             :         }
      66             : 
      67           0 :         return pTextMarkupList;
      68             :     }
      69             : }
      70             : 
      71             : // implementation of class <SwTextMarkupoHelper>
      72           0 : SwTextMarkupHelper::SwTextMarkupHelper( const SwAccessiblePortionData& rPortionData,
      73             :                                         const SwTxtNode& rTxtNode )
      74             :     : mrPortionData( rPortionData )
      75             :     // #i108125#
      76             :     , mpTxtNode( &rTxtNode )
      77           0 :     , mpTextMarkupList( 0 )
      78             : {
      79           0 : }
      80             : 
      81             : // #i108125#
      82           0 : SwTextMarkupHelper::SwTextMarkupHelper( const SwAccessiblePortionData& rPortionData,
      83             :                                         const SwWrongList& rTextMarkupList )
      84             :     : mrPortionData( rPortionData )
      85             :     , mpTxtNode( 0 )
      86           0 :     , mpTextMarkupList( &rTextMarkupList )
      87             : {
      88           0 : }
      89             : 
      90           0 : sal_Int32 SwTextMarkupHelper::getTextMarkupCount( const sal_Int32 nTextMarkupType )
      91             :         throw (::com::sun::star::lang::IllegalArgumentException,
      92             :                ::com::sun::star::uno::RuntimeException)
      93             : {
      94           0 :     sal_Int32 nTextMarkupCount( 0 );
      95             : 
      96             :     // #i108125#
      97             :     const SwWrongList* pTextMarkupList =
      98             :                             mpTextMarkupList
      99             :                             ? mpTextMarkupList
     100           0 :                             : getTextMarkupList( *mpTxtNode, nTextMarkupType );
     101           0 :     if ( pTextMarkupList )
     102             :     {
     103           0 :         nTextMarkupCount = pTextMarkupList->Count();
     104             :     }
     105             : 
     106           0 :     return nTextMarkupCount;
     107             : }
     108             : 
     109             : ::com::sun::star::accessibility::TextSegment
     110           0 :         SwTextMarkupHelper::getTextMarkup( const sal_Int32 nTextMarkupIndex,
     111             :                                            const sal_Int32 nTextMarkupType )
     112             :         throw (::com::sun::star::lang::IndexOutOfBoundsException,
     113             :                ::com::sun::star::lang::IllegalArgumentException,
     114             :                ::com::sun::star::uno::RuntimeException)
     115             : {
     116           0 :     if ( nTextMarkupIndex >= getTextMarkupCount( nTextMarkupType ) ||
     117             :          nTextMarkupIndex < 0 )
     118             :     {
     119           0 :         throw lang::IndexOutOfBoundsException();
     120             :     }
     121             : 
     122           0 :     ::com::sun::star::accessibility::TextSegment aTextMarkupSegment;
     123           0 :     aTextMarkupSegment.SegmentStart = -1;
     124           0 :     aTextMarkupSegment.SegmentEnd = -1;
     125             : 
     126             :     // #i108125#
     127             :     const SwWrongList* pTextMarkupList =
     128             :                             mpTextMarkupList
     129             :                             ? mpTextMarkupList
     130           0 :                             : getTextMarkupList( *mpTxtNode, nTextMarkupType );
     131           0 :     if ( pTextMarkupList )
     132             :     {
     133             :         const SwWrongArea* pTextMarkup =
     134           0 :                 pTextMarkupList->GetElement( static_cast<sal_uInt16>(nTextMarkupIndex) );
     135           0 :         if ( pTextMarkup )
     136             :         {
     137           0 :             const OUString rText = mrPortionData.GetAccessibleString();
     138             :             const sal_Int32 nStartPos =
     139           0 :                             mrPortionData.GetAccessiblePosition( pTextMarkup->mnPos );
     140             :             const sal_Int32 nEndPos =
     141           0 :                             mrPortionData.GetAccessiblePosition( pTextMarkup->mnPos + pTextMarkup->mnLen );
     142           0 :             aTextMarkupSegment.SegmentText = rText.copy( nStartPos, nEndPos - nStartPos );
     143           0 :             aTextMarkupSegment.SegmentStart = nStartPos;
     144           0 :             aTextMarkupSegment.SegmentEnd = nEndPos;
     145             :         }
     146             :         else
     147             :         {
     148             :             OSL_FAIL( "<SwTextMarkupHelper::getTextMarkup(..)> - missing <SwWrongArea> instance" );
     149             :         }
     150             :     }
     151             : 
     152           0 :     return aTextMarkupSegment;
     153             : }
     154             : 
     155             : ::com::sun::star::uno::Sequence< ::com::sun::star::accessibility::TextSegment >
     156           0 :         SwTextMarkupHelper::getTextMarkupAtIndex( const sal_Int32 nCharIndex,
     157             :                                                   const sal_Int32 nTextMarkupType )
     158             :         throw (::com::sun::star::lang::IndexOutOfBoundsException,
     159             :                ::com::sun::star::lang::IllegalArgumentException,
     160             :                ::com::sun::star::uno::RuntimeException)
     161             : {
     162             :     // assumption:
     163             :     // value of <nCharIndex> is in range [0..length of accessible text)
     164             : 
     165           0 :     const sal_Int32 nCoreCharIndex = mrPortionData.GetModelPosition( nCharIndex );
     166             :     // Handling of portions with core length == 0 at the beginning of the
     167             :     // paragraph - e.g. numbering portion.
     168           0 :     if ( mrPortionData.GetAccessiblePosition( nCoreCharIndex ) > nCharIndex )
     169             :     {
     170           0 :         return uno::Sequence< ::com::sun::star::accessibility::TextSegment >();
     171             :     }
     172             : 
     173             :     // #i108125#
     174             :     const SwWrongList* pTextMarkupList =
     175             :                             mpTextMarkupList
     176             :                             ? mpTextMarkupList
     177           0 :                             : getTextMarkupList( *mpTxtNode, nTextMarkupType );
     178           0 :     ::std::vector< ::com::sun::star::accessibility::TextSegment > aTmpTextMarkups;
     179           0 :     if ( pTextMarkupList )
     180             :     {
     181           0 :         const OUString rText = mrPortionData.GetAccessibleString();
     182             : 
     183           0 :         const sal_uInt16 nTextMarkupCount = pTextMarkupList->Count();
     184           0 :         for ( sal_uInt16 nTextMarkupIdx = 0; nTextMarkupIdx < nTextMarkupCount; ++nTextMarkupIdx )
     185             :         {
     186             :             const SwWrongArea* pTextMarkup =
     187           0 :                     pTextMarkupList->GetElement( static_cast<sal_uInt16>(nTextMarkupIdx) );
     188             :             OSL_ENSURE( pTextMarkup,
     189             :                     "<SwTextMarkupHelper::getTextMarkup(..)> - missing <SwWrongArea> instance" );
     190           0 :             if ( pTextMarkup &&
     191           0 :                  pTextMarkup->mnPos <= nCoreCharIndex &&
     192           0 :                  nCoreCharIndex < ( pTextMarkup->mnPos + pTextMarkup->mnLen ) )
     193             :             {
     194             :                 const sal_Int32 nStartPos =
     195           0 :                     mrPortionData.GetAccessiblePosition( pTextMarkup->mnPos );
     196             :                 const sal_Int32 nEndPos =
     197           0 :                     mrPortionData.GetAccessiblePosition( pTextMarkup->mnPos + pTextMarkup->mnLen );
     198           0 :                 ::com::sun::star::accessibility::TextSegment aTextMarkupSegment;
     199           0 :                 aTextMarkupSegment.SegmentText = rText.copy( nStartPos, nEndPos - nStartPos );
     200           0 :                 aTextMarkupSegment.SegmentStart = nStartPos;
     201           0 :                 aTextMarkupSegment.SegmentEnd = nEndPos;
     202           0 :                 aTmpTextMarkups.push_back( aTextMarkupSegment );
     203             :             }
     204           0 :         }
     205             :     }
     206             : 
     207             :     uno::Sequence< ::com::sun::star::accessibility::TextSegment > aTextMarkups(
     208           0 :                                                     aTmpTextMarkups.size() );
     209           0 :     ::std::copy( aTmpTextMarkups.begin(), aTmpTextMarkups.end(), aTextMarkups.begin() );
     210             : 
     211           0 :     return aTextMarkups;
     212             : }
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10