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

Generated by: LCOV version 1.10