LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLShapeStyleContext.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 88 109 80.7 %
Date: 2014-11-03 Functions: 10 12 83.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 <tools/debug.hxx>
      21             : #include <xmloff/XMLShapeStyleContext.hxx>
      22             : #include "XMLShapePropertySetContext.hxx"
      23             : #include <xmloff/contextid.hxx>
      24             : #include <com/sun/star/drawing/XControlShape.hpp>
      25             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      26             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      27             : #include <com/sun/star/drawing/FillStyle.hpp>
      28             : #include <xmloff/xmlimp.hxx>
      29             : #include <xmloff/xmlnumi.hxx>
      30             : #include <xmloff/xmlnmspe.hxx>
      31             : #include <xmloff/xmltoken.hxx>
      32             : #include <xmloff/xmlerror.hxx>
      33             : #include <xmloff/maptype.hxx>
      34             : 
      35             : #include "sdpropls.hxx"
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::beans;
      40             : using namespace ::com::sun::star::drawing;
      41             : using ::xmloff::token::IsXMLToken;
      42             : using ::xmloff::token::XML_TEXT_PROPERTIES;
      43             : using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
      44             : using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
      45             : 
      46       37520 : TYPEINIT1( XMLShapeStyleContext, XMLPropStyleContext );
      47             : 
      48        5258 : XMLShapeStyleContext::XMLShapeStyleContext(
      49             :     SvXMLImport& rImport,
      50             :     sal_uInt16 nPrfx,
      51             :     const OUString& rLName,
      52             :     const uno::Reference< xml::sax::XAttributeList >& xAttrList,
      53             :     SvXMLStylesContext& rStyles,
      54             :     sal_uInt16 nFamily)
      55             : :   XMLPropStyleContext(rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
      56        5258 :     m_bIsNumRuleAlreadyConverted( false )
      57             : {
      58        5258 : }
      59             : 
      60        7250 : XMLShapeStyleContext::~XMLShapeStyleContext()
      61             : {
      62        7250 : }
      63             : 
      64       12506 : void XMLShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName, const OUString& rValue )
      65             : {
      66       12506 :     if (m_sControlDataStyleName.isEmpty() && (::xmloff::token::GetXMLToken(::xmloff::token::XML_DATA_STYLE_NAME) == rLocalName))
      67             :     {
      68           0 :         m_sControlDataStyleName = rValue;
      69             :     }
      70       12506 :     else if( (XML_NAMESPACE_STYLE == nPrefixKey) && IsXMLToken( rLocalName, ::xmloff::token::XML_LIST_STYLE_NAME ) )
      71             :     {
      72          16 :         m_sListStyleName = rValue;
      73             :     }
      74             :     else
      75             :     {
      76       12490 :         XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
      77             : 
      78       30324 :         if( (XML_NAMESPACE_STYLE == nPrefixKey) &&
      79       19722 :             ( IsXMLToken( rLocalName, ::xmloff::token::XML_NAME ) || IsXMLToken( rLocalName, ::xmloff::token::XML_DISPLAY_NAME ) ) )
      80             :         {
      81        5344 :             if( !GetName().isEmpty() && !GetDisplayName().isEmpty() && GetName() != GetDisplayName() )
      82             :             {
      83          86 :                 const_cast< SvXMLImport&>( GetImport() ).
      84         172 :                     AddStyleDisplayName( GetFamily(), GetName(), GetDisplayName() );
      85             :             }
      86             :         }
      87             :     }
      88       12506 : }
      89             : 
      90        3244 : SvXMLImportContext *XMLShapeStyleContext::CreateChildContext(
      91             :         sal_uInt16 nPrefix,
      92             :         const OUString& rLocalName,
      93             :         const Reference< xml::sax::XAttributeList > & xAttrList )
      94             : {
      95        3244 :     SvXMLImportContext *pContext = 0;
      96             : 
      97        3244 :     if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
      98             :     {
      99        3244 :         sal_uInt32 nFamily = 0;
     100        3244 :         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
     101         802 :             nFamily = XML_TYPE_PROP_TEXT;
     102        2442 :         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
     103         712 :             nFamily = XML_TYPE_PROP_PARAGRAPH;
     104        1730 :         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
     105        1700 :             nFamily = XML_TYPE_PROP_GRAPHIC;
     106        3244 :         if( nFamily )
     107             :         {
     108             :             rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
     109        3214 :                 GetStyles()->GetImportPropertyMapper( GetFamily() );
     110        3214 :             if( xImpPrMap.is() )
     111        3214 :                 pContext = new XMLShapePropertySetContext( GetImport(), nPrefix,
     112             :                                                         rLocalName, xAttrList,
     113             :                                                         nFamily,
     114        3214 :                                                         GetProperties(),
     115        6428 :                                                         xImpPrMap );
     116             :         }
     117             :     }
     118             : 
     119        3244 :     if( !pContext )
     120             :         pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
     121          30 :                                                           xAttrList );
     122             : 
     123        3244 :     return pContext;
     124             : }
     125             : 
     126        8088 : void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet > & rPropSet )
     127             : {
     128        8088 :     if( !m_bIsNumRuleAlreadyConverted )
     129             :     {
     130        5222 :         m_bIsNumRuleAlreadyConverted = true;
     131             : 
     132             :         // for compatibility to beta files, search for CTF_SD_NUMBERINGRULES_NAME to
     133             :         // import numbering rules from the style:properties element
     134        5222 :         const rtl::Reference< XMLPropertySetMapper >&rMapper = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
     135             : 
     136        5222 :         ::std::vector< XMLPropertyState > &rProperties = GetProperties();
     137        5222 :         ::std::vector< XMLPropertyState >::iterator end( rProperties.end() );
     138        5222 :         ::std::vector< XMLPropertyState >::iterator property;
     139             : 
     140             :         // first, look for the old format, where we had a text:list-style-name
     141             :         // attribute in the style:properties element
     142       62718 :         for( property = rProperties.begin(); property != end; ++property )
     143             :         {
     144             :             // find properties with context
     145       57496 :             if( (property->mnIndex != -1) && (rMapper->GetEntryContextId( property->mnIndex ) == CTF_SD_NUMBERINGRULES_NAME) )
     146           0 :                 break;
     147             :         }
     148             : 
     149             :         // if we did not find an old list-style-name in the properties, and we need one
     150             :         // because we got a style:list-style attribute in the style-style element
     151             :         // we generate one
     152        5222 :         if( (property == end) && ( !m_sListStyleName.isEmpty() ) )
     153             :         {
     154          16 :             sal_Int32 nIndex = rMapper->FindEntryIndex( CTF_SD_NUMBERINGRULES_NAME );
     155             :             DBG_ASSERT( -1 != nIndex, "can't find numbering rules property entry, can't set numbering rule!" );
     156             : 
     157          16 :             XMLPropertyState aNewState( nIndex );
     158          16 :             rProperties.push_back( aNewState );
     159          16 :             end = rProperties.end();
     160          16 :             property = end - 1;
     161             :         }
     162             : 
     163             :         // so, if we have an old or a new list style name, we set its value to
     164             :         // a numbering rule
     165        5222 :         if( property != end )
     166             :         {
     167          16 :             if( m_sListStyleName.isEmpty() )
     168             :             {
     169           0 :                 property->maValue >>= m_sListStyleName;
     170             :             }
     171             : 
     172          16 :             const SvxXMLListStyleContext *pListStyle = GetImport().GetTextImport()->FindAutoListStyle( m_sListStyleName );
     173             : 
     174             :             DBG_ASSERT( pListStyle, "list-style not found for shape style" );
     175          16 :             if( pListStyle )
     176             :             {
     177          16 :                 uno::Reference< container::XIndexReplace > xNumRule( SvxXMLListStyleContext::CreateNumRule( GetImport().GetModel() ) );
     178          16 :                 pListStyle->FillUnoNumRule(xNumRule, NULL /* const SvI18NMap * ??? */ );
     179          16 :                 property->maValue <<= xNumRule;
     180             :             }
     181             :             else
     182             :             {
     183           0 :                 property->mnIndex = -1;
     184             :             }
     185             :         }
     186             :     }
     187             : 
     188             :     struct _ContextID_Index_Pair aContextIDs[] =
     189             :     {
     190             :         { CTF_DASHNAME , -1 },
     191             :         { CTF_LINESTARTNAME , -1 },
     192             :         { CTF_LINEENDNAME , -1 },
     193             :         { CTF_FILLGRADIENTNAME, -1 },
     194             :         { CTF_FILLTRANSNAME , -1 },
     195             :         { CTF_FILLHATCHNAME , -1 },
     196             :         { CTF_FILLBITMAPNAME , -1 },
     197             :         { CTF_SD_OLE_VIS_AREA_IMPORT_LEFT, -1 },
     198             :         { CTF_SD_OLE_VIS_AREA_IMPORT_TOP, -1 },
     199             :         { CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH, -1 },
     200             :         { CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT, -1 },
     201             :         { -1, -1 }
     202        8088 :     };
     203             :     static const sal_uInt16 aFamilies[] =
     204             :     {
     205             :         XML_STYLE_FAMILY_SD_STROKE_DASH_ID,
     206             :         XML_STYLE_FAMILY_SD_MARKER_ID,
     207             :         XML_STYLE_FAMILY_SD_MARKER_ID,
     208             :         XML_STYLE_FAMILY_SD_GRADIENT_ID,
     209             :         XML_STYLE_FAMILY_SD_GRADIENT_ID,
     210             :         XML_STYLE_FAMILY_SD_HATCH_ID,
     211             :         XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
     212             :     };
     213             : 
     214             :     rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
     215        8088 :         GetStyles()->GetImportPropertyMapper( GetFamily() );
     216             :     DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
     217        8088 :     if( xImpPrMap.is() )
     218        8088 :         xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs );
     219             : 
     220       16176 :     Reference< XPropertySetInfo > xInfo;
     221             :     // get property set mapper
     222       16176 :     rtl::Reference<XMLPropertySetMapper> xPropMapper( xImpPrMap->getPropertySetMapper() );
     223             : 
     224       97056 :     for( sal_uInt16 i=0; aContextIDs[i].nContextID != -1; i++ )
     225             :     {
     226       88968 :         sal_Int32 nIndex = aContextIDs[i].nIndex;
     227       88968 :         if( nIndex != -1 ) switch( aContextIDs[i].nContextID )
     228             :         {
     229             :         case CTF_DASHNAME:
     230             :         case CTF_LINESTARTNAME:
     231             :         case CTF_LINEENDNAME:
     232             :         case CTF_FILLGRADIENTNAME:
     233             :         case CTF_FILLTRANSNAME:
     234             :         case CTF_FILLHATCHNAME:
     235             :         case CTF_FILLBITMAPNAME:
     236             :         {
     237         700 :             struct XMLPropertyState& rState = GetProperties()[nIndex];
     238         700 :             OUString sStyleName;
     239         700 :             rState.maValue >>= sStyleName;
     240         700 :             sStyleName = GetImport().GetStyleDisplayName( aFamilies[i], sStyleName );
     241             :             try
     242             :             {
     243             : 
     244             :                 // set property
     245         700 :                 const OUString& rPropertyName = xPropMapper->GetEntryAPIName(rState.mnIndex);
     246         700 :                 if( !xInfo.is() )
     247         618 :                     xInfo = rPropSet->getPropertySetInfo();
     248         700 :                 if ( xInfo->hasPropertyByName( rPropertyName ) )
     249             :                 {
     250         700 :                     rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) );
     251             :                 }
     252             :             }
     253           0 :             catch ( const ::com::sun::star::lang::IllegalArgumentException& e )
     254             :             {
     255           0 :                 Sequence<OUString> aSeq(1);
     256           0 :                 aSeq[0] = sStyleName;
     257           0 :                 GetImport().SetError(
     258             :                     XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
     259           0 :                     aSeq, e.Message, NULL );
     260             :             }
     261         700 :             break;
     262             :         }
     263             :         case CTF_SD_OLE_VIS_AREA_IMPORT_LEFT:
     264             :         case CTF_SD_OLE_VIS_AREA_IMPORT_TOP:
     265             :         case CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH:
     266             :         case CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT:
     267             :         {
     268           6 :             struct XMLPropertyState& rState = GetProperties()[nIndex];
     269           6 :             const OUString& rPropertyName = xPropMapper->GetEntryAPIName(rState.mnIndex);
     270             :             try
     271             :             {
     272           6 :                 if( !xInfo.is() )
     273           6 :                     xInfo = rPropSet->getPropertySetInfo();
     274           6 :                 if ( xInfo->hasPropertyByName( rPropertyName ) )
     275             :                 {
     276           0 :                     rPropSet->setPropertyValue( rPropertyName, rState.maValue );
     277             :                 }
     278             :             }
     279           0 :             catch ( const ::com::sun::star::lang::IllegalArgumentException& e )
     280             :             {
     281           0 :                 Sequence<OUString> aSeq;
     282           0 :                 GetImport().SetError(
     283             :                     XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
     284           0 :                     aSeq, e.Message, NULL );
     285             :             }
     286           6 :             break;
     287             :         }
     288             :         }
     289             :     }
     290             : 
     291        8088 :     if (!m_sControlDataStyleName.isEmpty())
     292             :     {   // we had a data-style-name attribute
     293             : 
     294             :         // set the formatting on the control model of the control shape
     295           0 :         uno::Reference< drawing::XControlShape > xControlShape(rPropSet, uno::UNO_QUERY);
     296             :         DBG_ASSERT(xControlShape.is(), "XMLShapeStyleContext::FillPropertySet: data style for a non-control shape!");
     297           0 :         if (xControlShape.is())
     298             :         {
     299           0 :             uno::Reference< beans::XPropertySet > xControlModel(xControlShape->getControl(), uno::UNO_QUERY);
     300             :             DBG_ASSERT(xControlModel.is(), "XMLShapeStyleContext::FillPropertySet: no control model for the shape!");
     301           0 :             if (xControlModel.is())
     302             :             {
     303           0 :                 GetImport().GetFormImport()->applyControlNumberStyle(xControlModel, m_sControlDataStyleName);
     304           0 :             }
     305           0 :         }
     306        8088 :     }
     307        8088 : }
     308             : 
     309         818 : void XMLShapeStyleContext::Finish( bool /*bOverwrite*/ )
     310             : {
     311         818 : }
     312             : 
     313             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10