LCOV - code coverage report
Current view: top level - xmloff/source/text - XMLTextShapeStyleContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 64 76 84.2 %
Date: 2014-11-03 Functions: 14 16 87.5 %
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 <tools/debug.hxx>
      21             : #include <com/sun/star/document/XEventsSupplier.hpp>
      22             : #include <xmloff/xmlnmspe.hxx>
      23             : #include <xmloff/xmltoken.hxx>
      24             : #include "XMLTextPropertySetContext.hxx"
      25             : #include <xmloff/xmlimp.hxx>
      26             : #include <xmloff/XMLEventsImportContext.hxx>
      27             : #include "XMLShapePropertySetContext.hxx"
      28             : #include "XMLTextColumnsContext.hxx"
      29             : #include "XMLBackgroundImageContext.hxx"
      30             : #include <xmloff/txtprmap.hxx>
      31             : #include <xmloff/xmltypes.hxx>
      32             : #include <xmloff/maptype.hxx>
      33             : 
      34             : #include <xmloff/XMLTextShapeStyleContext.hxx>
      35             : 
      36             : using namespace ::com::sun::star::document;
      37             : using namespace ::com::sun::star::uno;
      38             : using namespace ::com::sun::star::xml::sax;
      39             : using namespace ::com::sun::star::style;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::xmloff::token;
      42             : 
      43             : class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext
      44             : {
      45             : public:
      46             :     XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx,
      47             :         const OUString& rLName,
      48             :         const Reference< XAttributeList >& xAttrList,
      49             :                  sal_uInt32 nFamily,
      50             :         ::std::vector< XMLPropertyState > &rProps,
      51             :         const rtl::Reference < SvXMLImportPropertyMapper > &rMap );
      52             : 
      53             :     virtual ~XMLTextShapePropertySetContext_Impl();
      54             : 
      55             :     using SvXMLPropertySetContext::CreateChildContext;
      56             :     virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix,
      57             :         const OUString& rLocalName,
      58             :         const Reference< XAttributeList >& xAttrList,
      59             :         ::std::vector< XMLPropertyState > &rProperties,
      60             :         const XMLPropertyState& rProp) SAL_OVERRIDE;
      61             : };
      62             : 
      63         608 : XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl(
      64             :                  SvXMLImport& rImport, sal_uInt16 nPrfx,
      65             :                  const OUString& rLName,
      66             :                  const Reference< XAttributeList > & xAttrList,
      67             :                  sal_uInt32 nFamily,
      68             :                  ::std::vector< XMLPropertyState > &rProps,
      69             :                  const rtl::Reference < SvXMLImportPropertyMapper > &rMap ) :
      70             :     XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily,
      71         608 :                                 rProps, rMap )
      72             : {
      73         608 : }
      74             : 
      75        1216 : XMLTextShapePropertySetContext_Impl::~XMLTextShapePropertySetContext_Impl()
      76             : {
      77        1216 : }
      78             : 
      79          56 : SvXMLImportContext *XMLTextShapePropertySetContext_Impl::CreateChildContext(
      80             :                    sal_uInt16 nPrefix,
      81             :                    const OUString& rLocalName,
      82             :                    const Reference< XAttributeList > & xAttrList,
      83             :                    ::std::vector< XMLPropertyState > &rProperties,
      84             :                    const XMLPropertyState& rProp )
      85             : {
      86          56 :     SvXMLImportContext *pContext = 0;
      87             : 
      88         112 :     switch( mxMapper->getPropertySetMapper()
      89         112 :                     ->GetEntryContextId( rProp.mnIndex ) )
      90             :     {
      91             :     case CTF_TEXTCOLUMNS:
      92          10 :         pContext = new XMLTextColumnsContext( GetImport(), nPrefix,
      93             :                                                    rLocalName, xAttrList, rProp,
      94          10 :                                                    rProperties );
      95          10 :         break;
      96             : 
      97             :     case CTF_BACKGROUND_URL:
      98             :         DBG_ASSERT( rProp.mnIndex >= 3 &&
      99             :                     CTF_BACKGROUND_TRANSPARENCY ==
     100             :                         mxMapper->getPropertySetMapper()
     101             :                         ->GetEntryContextId( rProp.mnIndex-3 ) &&
     102             :                     CTF_BACKGROUND_POS  == mxMapper->getPropertySetMapper()
     103             :                         ->GetEntryContextId( rProp.mnIndex-2 ) &&
     104             :                     CTF_BACKGROUND_FILTER  == mxMapper->getPropertySetMapper()
     105             :                         ->GetEntryContextId( rProp.mnIndex-1 ),
     106             :                     "invalid property map!");
     107             :         pContext =
     108          46 :             new XMLBackgroundImageContext( GetImport(), nPrefix,
     109             :                                            rLocalName, xAttrList,
     110             :                                            rProp,
     111             :                                            rProp.mnIndex-2,
     112             :                                            rProp.mnIndex-1,
     113             :                                            rProp.mnIndex-3,
     114          46 :                                            rProperties );
     115          46 :         break;
     116             :     }
     117             : 
     118          56 :     if( !pContext )
     119             :         pContext = XMLShapePropertySetContext::CreateChildContext(
     120           0 :                         nPrefix, rLocalName, xAttrList, rProperties, rProp );
     121             : 
     122          56 :     return pContext;
     123             : }
     124             : 
     125        1534 : void XMLTextShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey,
     126             :                                         const OUString& rLocalName,
     127             :                                         const OUString& rValue )
     128             : {
     129        3068 :     if( XML_NAMESPACE_STYLE == nPrefixKey &&
     130        1534 :         IsXMLToken( rLocalName, XML_AUTO_UPDATE ) )
     131             :     {
     132           2 :           if( IsXMLToken( rValue, XML_TRUE ) )
     133           2 :             bAutoUpdate = true;
     134             :     }
     135             :     else
     136             :     {
     137        1532 :         XMLShapeStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
     138             :     }
     139        1534 : }
     140             : 
     141        4722 : TYPEINIT1( XMLTextShapeStyleContext, XMLShapeStyleContext );
     142             : 
     143         608 : XMLTextShapeStyleContext::XMLTextShapeStyleContext( SvXMLImport& rImport,
     144             :         sal_uInt16 nPrfx, const OUString& rLName,
     145             :         const Reference< XAttributeList > & xAttrList,
     146             :         SvXMLStylesContext& rStyles, sal_uInt16 nFamily,
     147             :         bool /*bDefaultStyle*/ ) :
     148             :     XMLShapeStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles,
     149             :                           nFamily ),
     150             :     sIsAutoUpdate( "IsAutoUpdate" ),
     151         608 :     bAutoUpdate( false )
     152             : {
     153         608 : }
     154             : 
     155        1216 : XMLTextShapeStyleContext::~XMLTextShapeStyleContext()
     156             : {
     157        1216 : }
     158             : 
     159         608 : SvXMLImportContext *XMLTextShapeStyleContext::CreateChildContext(
     160             :         sal_uInt16 nPrefix,
     161             :         const OUString& rLocalName,
     162             :         const Reference< XAttributeList > & xAttrList )
     163             : {
     164         608 :     SvXMLImportContext *pContext = 0;
     165             : 
     166         608 :     if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
     167             :     {
     168         608 :         sal_uInt32 nFamily = 0;
     169         608 :         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
     170           0 :             nFamily = XML_TYPE_PROP_TEXT;
     171         608 :         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
     172           0 :             nFamily = XML_TYPE_PROP_PARAGRAPH;
     173         608 :         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
     174         608 :             nFamily = XML_TYPE_PROP_GRAPHIC;
     175         608 :         if( nFamily )
     176             :         {
     177             :             rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
     178         608 :                 GetStyles()->GetImportPropertyMapper( GetFamily() );
     179         608 :             if( xImpPrMap.is() )
     180             :             {
     181             :                 pContext = new XMLTextShapePropertySetContext_Impl(
     182         608 :                         GetImport(), nPrefix, rLocalName, xAttrList, nFamily,
     183         608 :                         GetProperties(), xImpPrMap );
     184         608 :             }
     185         608 :         }
     186             :     }
     187           0 :     else if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
     188           0 :               IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) )
     189             :     {
     190             :         // create and remember events import context
     191             :         // (for delayed processing of events)
     192           0 :         pContext = new XMLEventsImportContext( GetImport(), nPrefix,
     193           0 :                                                    rLocalName);
     194           0 :         xEventContext = pContext;
     195             :     }
     196             : 
     197         608 :     if( !pContext )
     198             :         pContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName,
     199           0 :                                                           xAttrList );
     200             : 
     201         608 :     return pContext;
     202             : }
     203             : 
     204         238 : void XMLTextShapeStyleContext::CreateAndInsert( bool bOverwrite )
     205             : {
     206         238 :     XMLShapeStyleContext::CreateAndInsert( bOverwrite );
     207         238 :     Reference < XStyle > xStyle = GetStyle();
     208         238 :     if( !xStyle.is() || !(bOverwrite || IsNew()) )
     209         238 :         return;
     210             : 
     211         476 :     Reference < XPropertySet > xPropSet( xStyle, UNO_QUERY );
     212             :     Reference< XPropertySetInfo > xPropSetInfo =
     213         476 :                 xPropSet->getPropertySetInfo();
     214         238 :     if( xPropSetInfo->hasPropertyByName( sIsAutoUpdate ) )
     215             :     {
     216         238 :         Any aAny;
     217         238 :         sal_Bool bTmp = bAutoUpdate;
     218         238 :         aAny.setValue( &bTmp, ::getBooleanCppuType() );
     219         238 :         xPropSet->setPropertyValue( sIsAutoUpdate, aAny );
     220             :     }
     221             : 
     222             :     // tell the style about it's events (if applicable)
     223         238 :     if( xEventContext.Is() )
     224             :     {
     225             :         // set event suppplier and release reference to context
     226           0 :         Reference<XEventsSupplier> xEventsSupplier(xStyle, UNO_QUERY);
     227           0 :         static_cast<XMLEventsImportContext *>(&xEventContext)->SetEvents(xEventsSupplier);
     228           0 :         xEventContext = 0;
     229         238 :     }
     230             : }
     231             : 
     232         238 : void XMLTextShapeStyleContext::Finish( bool bOverwrite )
     233             : {
     234         238 :     XMLPropStyleContext::Finish( bOverwrite );
     235         238 : }
     236             : 
     237             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10