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

Generated by: LCOV version 1.10