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

Generated by: LCOV version 1.10