LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextFrameHyperlinkContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 51 67 76.1 %
Date: 2015-06-13 12:38:46 Functions: 10 13 76.9 %
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 <sax/tools/converter.hxx>
      21             : 
      22             : #include <xmloff/xmlimp.hxx>
      23             : #include <xmloff/nmspmap.hxx>
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <xmloff/xmltoken.hxx>
      26             : #include "XMLTextFrameContext.hxx"
      27             : #include "XMLTextFrameHyperlinkContext.hxx"
      28             : 
      29             : #include <txtparaimphint.hxx>
      30             : 
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::com::sun::star::text;
      33             : using namespace ::com::sun::star::xml::sax;
      34             : using namespace ::com::sun::star::beans;
      35             : using namespace ::xmloff::token;
      36             : 
      37             : namespace drawing = com::sun::star::drawing;
      38             : 
      39          44 : TYPEINIT1( XMLTextFrameHyperlinkContext, SvXMLImportContext );
      40             : 
      41           2 : XMLTextFrameHyperlinkContext::XMLTextFrameHyperlinkContext(
      42             :         SvXMLImport& rImport,
      43             :         sal_uInt16 nPrfx, const OUString& rLName,
      44             :         const Reference< XAttributeList > & xAttrList,
      45             :         TextContentAnchorType eATyp ) :
      46             :     SvXMLImportContext( rImport, nPrfx, rLName ),
      47             :     eDefaultAnchorType( eATyp ),
      48           2 :     bMap( false )
      49             : {
      50           2 :     OUString sShow;
      51             :     const SvXMLTokenMap& rTokenMap =
      52           2 :         GetImport().GetTextImport()->GetTextHyperlinkAttrTokenMap();
      53             : 
      54           2 :     sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0;
      55          10 :     for( sal_Int16 i=0; i < nAttrCount; i++ )
      56             :     {
      57           8 :         const OUString& rAttrName = xAttrList->getNameByIndex( i );
      58          16 :         const OUString& rValue = xAttrList->getValueByIndex( i );
      59             : 
      60          16 :         OUString aLocalName;
      61             :         sal_uInt16 nPrefix =
      62           8 :             GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName,
      63           8 :                                                             &aLocalName );
      64           8 :         switch( rTokenMap.Get( nPrefix, aLocalName ) )
      65             :         {
      66             :         case XML_TOK_TEXT_HYPERLINK_HREF:
      67           2 :             sHRef = GetImport().GetAbsoluteReference( rValue );
      68           2 :             break;
      69             :         case XML_TOK_TEXT_HYPERLINK_NAME:
      70           2 :             sName = rValue;
      71           2 :             break;
      72             :         case XML_TOK_TEXT_HYPERLINK_TARGET_FRAME:
      73           1 :             sTargetFrameName = rValue;
      74           1 :             break;
      75             :         case XML_TOK_TEXT_HYPERLINK_SHOW:
      76           1 :             sShow = rValue;
      77           1 :             break;
      78             :         case XML_TOK_TEXT_HYPERLINK_SERVER_MAP:
      79             :             {
      80           0 :                 bool bTmp(false);
      81           0 :                 if (::sax::Converter::convertBool( bTmp, rValue ))
      82             :                 {
      83           0 :                     bMap = bTmp;
      84             :                 }
      85             :             }
      86           0 :             break;
      87             :         }
      88           8 :     }
      89             : 
      90           2 :     if( !sShow.isEmpty() && sTargetFrameName.isEmpty() )
      91             :     {
      92           0 :         if( IsXMLToken( sShow, XML_NEW ) )
      93           0 :             sTargetFrameName = "_blank";
      94           0 :         else if( IsXMLToken( sShow, XML_REPLACE ) )
      95           0 :             sTargetFrameName = "_self";
      96           2 :     }
      97           2 : }
      98             : 
      99           4 : XMLTextFrameHyperlinkContext::~XMLTextFrameHyperlinkContext()
     100             : {
     101           4 : }
     102             : 
     103           2 : void XMLTextFrameHyperlinkContext::EndElement()
     104             : {
     105           2 : }
     106             : 
     107           2 : SvXMLImportContext *XMLTextFrameHyperlinkContext::CreateChildContext(
     108             :         sal_uInt16 nPrefix,
     109             :         const OUString& rLocalName,
     110             :         const Reference< XAttributeList > & xAttrList )
     111             : {
     112           2 :     SvXMLImportContext *pContext = 0;
     113           2 :     XMLTextFrameContext *pTextFrameContext = 0;
     114             : 
     115           2 :     if( XML_NAMESPACE_DRAW == nPrefix )
     116             :     {
     117           2 :         if( IsXMLToken( rLocalName, XML_FRAME ) )
     118           2 :             pTextFrameContext = new XMLTextFrameContext( GetImport(), nPrefix,
     119             :                                                 rLocalName, xAttrList,
     120           2 :                                                 eDefaultAnchorType );
     121             :     }
     122             : 
     123           2 :     if( pTextFrameContext )
     124             :     {
     125           2 :         pTextFrameContext->SetHyperlink( sHRef, sName, sTargetFrameName, bMap );
     126           2 :         pContext = pTextFrameContext;
     127           2 :         xFrameContext = pContext;
     128             :     }
     129             :     else
     130           0 :         pContext = new SvXMLImportContext( GetImport(), nPrefix, rLocalName );
     131             : 
     132           2 :     return pContext;
     133             : }
     134             : 
     135             : 
     136           2 : TextContentAnchorType XMLTextFrameHyperlinkContext::GetAnchorType() const
     137             : {
     138           2 :     if( xFrameContext.Is() )
     139             :     {
     140           2 :         SvXMLImportContext *pContext = &xFrameContext;
     141           2 :         return PTR_CAST( XMLTextFrameContext, pContext ) ->GetAnchorType();
     142             :     }
     143             :     else
     144           0 :         return eDefaultAnchorType;
     145             : 
     146             : }
     147             : 
     148           2 : Reference < XTextContent > XMLTextFrameHyperlinkContext::GetTextContent() const
     149             : {
     150           2 :     Reference <XTextContent > xTxt;
     151           2 :     if( xFrameContext.Is() )
     152             :     {
     153           2 :         SvXMLImportContext *pContext = &xFrameContext;
     154           2 :         xTxt = PTR_CAST( XMLTextFrameContext, pContext )->GetTextContent();
     155             :     }
     156             : 
     157           2 :     return xTxt;
     158             : }
     159             : 
     160             : // Frame "to character": anchor moves from first to last char after saving (#i33242#)
     161           0 : Reference < drawing::XShape > XMLTextFrameHyperlinkContext::GetShape() const
     162             : {
     163           0 :     Reference < drawing::XShape > xShape;
     164           0 :     if( xFrameContext.Is() )
     165             :     {
     166           0 :         SvXMLImportContext *pContext = &xFrameContext;
     167           0 :         xShape = PTR_CAST( XMLTextFrameContext, pContext )->GetShape();
     168             :     }
     169             : 
     170           0 :     return xShape;
     171             : }
     172             : 
     173             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11