LCOV - code coverage report
Current view: top level - sw/source/core/access - acchyperlink.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 124 0.8 %
Date: 2015-06-13 12:38:46 Functions: 2 14 14.3 %
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 <comphelper/accessiblekeybindinghelper.hxx>
      21             : #include <comphelper/processfactory.hxx>
      22             : #include <com/sun/star/frame/XDesktop.hpp>
      23             : #include <com/sun/star/frame/XComponentLoader.hpp>
      24             : #include <com/sun/star/document/XLinkTargetSupplier.hpp>
      25             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      26             : #include <swurl.hxx>
      27             : #include <osl/mutex.hxx>
      28             : #include <vcl/svapp.hxx>
      29             : #include <ndtxt.hxx>
      30             : #include <txtinet.hxx>
      31             : #include <accpara.hxx>
      32             : #include <acchyperlink.hxx>
      33             : 
      34             : using namespace ::com::sun::star;
      35             : using namespace ::com::sun::star::accessibility;
      36             : using ::com::sun::star::lang::IndexOutOfBoundsException;
      37             : 
      38           0 : SwAccessibleHyperlink::SwAccessibleHyperlink( size_t nHPos,
      39             :     SwAccessibleParagraph *p, sal_Int32 nStt, sal_Int32 nEnd ) :
      40             :     nHintPos( nHPos ),
      41             :     xPara( p ),
      42             :     nStartIdx( nStt ),
      43           0 :     nEndIdx( nEnd )
      44             : {
      45           0 : }
      46             : 
      47           0 : const SwTextAttr *SwAccessibleHyperlink::GetTextAttr() const
      48             : {
      49           0 :     const SwTextAttr *pTextAttr = 0;
      50           0 :     if( xPara.is() && xPara->GetMap() )
      51             :     {
      52           0 :         const SwTextNode *pTextNd = xPara->GetTextNode();
      53           0 :         const SwpHints *pHints = pTextNd->GetpSwpHints();
      54           0 :         if( pHints && nHintPos < pHints->Count() )
      55             :         {
      56           0 :             const SwTextAttr *pHt = (*pHints)[nHintPos];
      57           0 :             if( RES_TXTATR_INETFMT == pHt->Which() )
      58           0 :                 pTextAttr = pHt;
      59             :         }
      60             :     }
      61             : 
      62           0 :     return pTextAttr;
      63             : }
      64             : 
      65             : // XAccessibleAction
      66           0 : sal_Int32 SAL_CALL SwAccessibleHyperlink::getAccessibleActionCount()
      67             :         throw (uno::RuntimeException, std::exception)
      68             : {
      69           0 :      return isValid() ? 1 : 0;
      70             : }
      71             : 
      72           0 : sal_Bool SAL_CALL SwAccessibleHyperlink::doAccessibleAction( sal_Int32 nIndex )
      73             :         throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
      74             : {
      75           0 :     SolarMutexGuard aGuard;
      76             : 
      77           0 :     bool bRet = false;
      78             : 
      79           0 :     if(nIndex != 0)
      80           0 :         throw lang::IndexOutOfBoundsException();
      81           0 :     const SwTextAttr *pTextAttr = GetTextAttr();
      82           0 :     if( pTextAttr )
      83             :     {
      84           0 :         const SwFormatINetFormat& rINetFormat = pTextAttr->GetINetFormat();
      85           0 :         if( !rINetFormat.GetValue().isEmpty() )
      86             :         {
      87           0 :             SwViewShell *pVSh = xPara->GetShell();
      88           0 :             if( pVSh )
      89             :             {
      90           0 :                 LoadURL(*pVSh, rINetFormat.GetValue(), URLLOAD_NOFILTER,
      91           0 :                          rINetFormat.GetTargetFrame());
      92             :                 OSL_ENSURE( pTextAttr == rINetFormat.GetTextINetFormat(),
      93             :                          "lost my txt attr" );
      94           0 :                 const SwTextINetFormat* pTextAttr2 = rINetFormat.GetTextINetFormat();
      95           0 :                 if( pTextAttr2 )
      96             :                 {
      97           0 :                     const_cast<SwTextINetFormat*>(pTextAttr2)->SetVisited(true);
      98           0 :                     const_cast<SwTextINetFormat*>(pTextAttr2)->SetVisitedValid(true);
      99             :                 }
     100           0 :                 bRet = true;
     101             :             }
     102             :         }
     103             :     }
     104             : 
     105           0 :     return bRet;
     106             : }
     107             : 
     108           0 : OUString SAL_CALL SwAccessibleHyperlink::getAccessibleActionDescription(
     109             :         sal_Int32 nIndex )
     110             :         throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
     111             : {
     112           0 :     if(nIndex != 0)
     113           0 :         throw lang::IndexOutOfBoundsException();
     114             : 
     115           0 :     const SwTextAttr *pTextAttr = GetTextAttr();
     116           0 :     if( pTextAttr )
     117             :     {
     118           0 :         const SwFormatINetFormat& rINetFormat = pTextAttr->GetINetFormat();
     119           0 :         return rINetFormat.GetValue();
     120             :     }
     121             : 
     122           0 :     return OUString();
     123             : }
     124             : 
     125             : uno::Reference< XAccessibleKeyBinding > SAL_CALL
     126           0 :     SwAccessibleHyperlink::getAccessibleActionKeyBinding( sal_Int32 )
     127             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
     128             : {
     129           0 :     uno::Reference< XAccessibleKeyBinding > xKeyBinding;
     130             : 
     131           0 :     if( isValid() )
     132             :     {
     133             :         ::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper =
     134           0 :                new ::comphelper::OAccessibleKeyBindingHelper();
     135           0 :         xKeyBinding = pKeyBindingHelper;
     136             : 
     137           0 :         awt::KeyStroke aKeyStroke;
     138           0 :         aKeyStroke.Modifiers = 0;
     139           0 :         aKeyStroke.KeyCode = KEY_RETURN;
     140           0 :         aKeyStroke.KeyChar = 0;
     141           0 :         aKeyStroke.KeyFunc = 0;
     142           0 :         pKeyBindingHelper->AddKeyBinding( aKeyStroke );
     143             :     }
     144             : 
     145           0 :     return xKeyBinding;
     146             : }
     147             : 
     148             : // XAccessibleHyperlink
     149           0 : uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionAnchor(
     150             :         sal_Int32 nIndex)
     151             :         throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
     152             : {
     153           0 :     SolarMutexGuard g;
     154             : 
     155           0 :     uno::Any aRet;
     156           0 :     if(nIndex != 0)
     157           0 :         throw lang::IndexOutOfBoundsException();
     158           0 :     OUString text( xPara->GetString() );
     159           0 :     OUString retText =  text.copy(nStartIdx, nEndIdx - nStartIdx);
     160           0 :     aRet <<= retText;
     161           0 :     return aRet;
     162             : }
     163             : 
     164           0 : uno::Any SAL_CALL SwAccessibleHyperlink::getAccessibleActionObject(
     165             :             sal_Int32 nIndex )
     166             :     throw (lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception)
     167             : {
     168           0 :     SolarMutexGuard g;
     169             : 
     170           0 :     if(nIndex != 0)
     171           0 :         throw lang::IndexOutOfBoundsException();
     172           0 :     const SwTextAttr *pTextAttr = GetTextAttr();
     173           0 :     OUString retText;
     174           0 :     if( pTextAttr )
     175             :     {
     176           0 :         const SwFormatINetFormat& rINetFormat = pTextAttr->GetINetFormat();
     177           0 :         retText = OUString( rINetFormat.GetValue() );
     178             :     }
     179           0 :     uno::Any aRet;
     180           0 :     aRet <<= retText;
     181           0 :     return aRet;
     182             : }
     183             : 
     184           0 : sal_Int32 SAL_CALL SwAccessibleHyperlink::getStartIndex()
     185             :         throw (uno::RuntimeException, std::exception)
     186             : {
     187           0 :     return nStartIdx;
     188             : }
     189             : 
     190           0 : sal_Int32 SAL_CALL SwAccessibleHyperlink::getEndIndex()
     191             :         throw (uno::RuntimeException, std::exception)
     192             : {
     193           0 :     return nEndIdx;
     194             : }
     195             : 
     196           0 : sal_Bool SAL_CALL SwAccessibleHyperlink::isValid(  )
     197             :         throw (uno::RuntimeException, std::exception)
     198             : {
     199           0 :     SolarMutexGuard aGuard;
     200           0 :     if (xPara.is())
     201             :     {
     202           0 :         const SwTextAttr *pTextAttr = GetTextAttr();
     203           0 :         OUString sText;
     204           0 :         if( pTextAttr )
     205             :         {
     206           0 :             const SwFormatINetFormat& rINetFormat = pTextAttr->GetINetFormat();
     207           0 :             sText = OUString( rINetFormat.GetValue() );
     208           0 :             OUString sToken = "#";
     209           0 :             sal_Int32 nPos = sText.indexOf(sToken);
     210           0 :             if (nPos==0)//document link
     211             :             {
     212           0 :                 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
     213           0 :                 if( ! xFactory.is() )
     214           0 :                     return sal_False;
     215           0 :                 uno::Reference< com::sun::star::frame::XDesktop > xDesktop( xFactory->createInstance( "com.sun.star.frame.Desktop" ),
     216           0 :                     uno::UNO_QUERY );
     217           0 :                 if( !xDesktop.is() )
     218           0 :                     return sal_False;
     219           0 :                 uno::Reference< lang::XComponent > xComp;
     220           0 :                 xComp = xDesktop->getCurrentComponent();
     221           0 :                 if( !xComp.is() )
     222           0 :                     return sal_False;
     223           0 :                 uno::Reference< com::sun::star::document::XLinkTargetSupplier >  xLTS(xComp, uno::UNO_QUERY);
     224           0 :                 if ( !xLTS.is())
     225           0 :                     return sal_False;
     226             : 
     227           0 :                 uno::Reference< ::com::sun::star::container::XNameAccess > xLinks = xLTS->getLinks();
     228           0 :                 uno::Reference< ::com::sun::star::container::XNameAccess > xSubLinks;
     229           0 :                 const uno::Sequence< OUString > aNames( xLinks->getElementNames() );
     230           0 :                 const sal_uLong nLinks = aNames.getLength();
     231           0 :                 const OUString* pNames = aNames.getConstArray();
     232             : 
     233           0 :                 for( sal_uLong i = 0; i < nLinks; i++ )
     234             :                 {
     235           0 :                     uno::Any aAny;
     236           0 :                     OUString aLink( *pNames++ );
     237           0 :                     aAny = xLinks->getByName( aLink );
     238           0 :                     aAny >>= xSubLinks;
     239           0 :                     if (xSubLinks->hasByName(sText.copy(1)) )
     240           0 :                         return sal_True;
     241           0 :                 }
     242             :             }
     243             :             else//internet
     244           0 :                 return sal_True;
     245           0 :         }
     246             :     }//xpara valid
     247           0 :     return sal_False;
     248             : }
     249             : 
     250           0 : void SwAccessibleHyperlink::Invalidate()
     251             : {
     252           0 :     SolarMutexGuard aGuard;
     253           0 :     xPara = 0;
     254         177 : }
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11