LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLShapeStyleContext.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 94 114 82.5 %
Date: 2015-06-13 12:38:46 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       29515 : TYPEINIT1( XMLShapeStyleContext, XMLPropStyleContext );
      47             : 
      48        3563 : 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        3563 :     m_bIsNumRuleAlreadyConverted( false )
      57             : {
      58        3563 : }
      59             : 
      60        5627 : XMLShapeStyleContext::~XMLShapeStyleContext()
      61             : {
      62        5627 : }
      63             : 
      64        9128 : void XMLShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey, const OUString& rLocalName, const OUString& rValue )
      65             : {
      66        9128 :     if (m_sControlDataStyleName.isEmpty() && (::xmloff::token::GetXMLToken(::xmloff::token::XML_DATA_STYLE_NAME) == rLocalName))
      67             :     {
      68           0 :         m_sControlDataStyleName = rValue;
      69             :     }
      70        9128 :     else if( (XML_NAMESPACE_STYLE == nPrefixKey) && IsXMLToken( rLocalName, ::xmloff::token::XML_LIST_STYLE_NAME ) )
      71             :     {
      72          10 :         m_sListStyleName = rValue;
      73             :     }
      74             :     else
      75             :     {
      76        9118 :         XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
      77             : 
      78       21899 :         if( (XML_NAMESPACE_STYLE == nPrefixKey) &&
      79       14673 :             ( IsXMLToken( rLocalName, ::xmloff::token::XML_NAME ) || IsXMLToken( rLocalName, ::xmloff::token::XML_DISPLAY_NAME ) ) )
      80             :         {
      81        3663 :             if( !GetName().isEmpty() && !GetDisplayName().isEmpty() && GetName() != GetDisplayName() )
      82             :             {
      83         100 :                 const_cast< SvXMLImport&>( GetImport() ).
      84         200 :                     AddStyleDisplayName( GetFamily(), GetName(), GetDisplayName() );
      85             :             }
      86             :         }
      87             :     }
      88        9128 : }
      89             : 
      90        3582 : SvXMLImportContext *XMLShapeStyleContext::CreateChildContext(
      91             :         sal_uInt16 nPrefix,
      92             :         const OUString& rLocalName,
      93             :         const Reference< xml::sax::XAttributeList > & xAttrList )
      94             : {
      95        3582 :     SvXMLImportContext *pContext = 0;
      96             : 
      97        3582 :     if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix )
      98             :     {
      99        3582 :         sal_uInt32 nFamily = 0;
     100        3582 :         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
     101         982 :             nFamily = XML_TYPE_PROP_TEXT;
     102        2600 :         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
     103         870 :             nFamily = XML_TYPE_PROP_PARAGRAPH;
     104        1730 :         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
     105        1706 :             nFamily = XML_TYPE_PROP_GRAPHIC;
     106        3582 :         if( nFamily )
     107             :         {
     108             :             rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap =
     109        3558 :                 GetStyles()->GetImportPropertyMapper( GetFamily() );
     110        3558 :             if( xImpPrMap.is() )
     111        3558 :                 pContext = new XMLShapePropertySetContext( GetImport(), nPrefix,
     112             :                                                         rLocalName, xAttrList,
     113             :                                                         nFamily,
     114        3558 :                                                         GetProperties(),
     115        7116 :                                                         xImpPrMap );
     116             :         }
     117             :     }
     118             : 
     119        3582 :     if( !pContext )
     120             :         pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
     121          24 :                                                           xAttrList );
     122             : 
     123        3582 :     return pContext;
     124             : }
     125             : 
     126        5262 : void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet > & rPropSet )
     127             : {
     128        5262 :     if( !m_bIsNumRuleAlreadyConverted )
     129             :     {
     130        3545 :         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        3545 :         const rtl::Reference< XMLPropertySetMapper >&rMapper = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
     135             : 
     136        3545 :         ::std::vector< XMLPropertyState > &rProperties = GetProperties();
     137        3545 :         ::std::vector< XMLPropertyState >::iterator end( rProperties.end() );
     138        3545 :         ::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       49361 :         for( property = rProperties.begin(); property != end; ++property )
     143             :         {
     144             :             // find properties with context
     145       45816 :             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        3545 :         if( (property == end) && ( !m_sListStyleName.isEmpty() ) )
     153             :         {
     154          10 :             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          10 :             XMLPropertyState aNewState( nIndex );
     158          10 :             rProperties.push_back( aNewState );
     159          10 :             end = rProperties.end();
     160          10 :             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        3545 :         if( property != end )
     166             :         {
     167          10 :             if( m_sListStyleName.isEmpty() )
     168             :             {
     169           0 :                 property->maValue >>= m_sListStyleName;
     170             :             }
     171             : 
     172          10 :             const SvxXMLListStyleContext *pListStyle = GetImport().GetTextImport()->FindAutoListStyle( m_sListStyleName );
     173             : 
     174             :             DBG_ASSERT( pListStyle, "list-style not found for shape style" );
     175          10 :             if( pListStyle )
     176             :             {
     177           8 :                 uno::Reference< container::XIndexReplace > xNumRule( SvxXMLListStyleContext::CreateNumRule( GetImport().GetModel() ) );
     178           8 :                 pListStyle->FillUnoNumRule(xNumRule);
     179           8 :                 property->maValue <<= xNumRule;
     180             :             }
     181             :             else
     182             :             {
     183           2 :                 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        5262 :     };
     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        5262 :         GetStyles()->GetImportPropertyMapper( GetFamily() );
     216             :     DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
     217        5262 :     if( xImpPrMap.is() )
     218        5262 :         xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs );
     219             : 
     220       10524 :     Reference< XPropertySetInfo > xInfo;
     221             :     // get property set mapper
     222       10524 :     rtl::Reference<XMLPropertySetMapper> xPropMapper( xImpPrMap->getPropertySetMapper() );
     223             : 
     224       63144 :     for( sal_uInt16 i=0; aContextIDs[i].nContextID != -1; i++ )
     225             :     {
     226       57882 :         sal_Int32 nIndex = aContextIDs[i].nIndex;
     227       57882 :         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         591 :             struct XMLPropertyState& rState = GetProperties()[nIndex];
     238         591 :             OUString sStyleName;
     239         591 :             rState.maValue >>= sStyleName;
     240         591 :             sStyleName = GetImport().GetStyleDisplayName( aFamilies[i], sStyleName );
     241             :             // All of these attributes refer to something with draw:name
     242             :             // of type styleName = NCName which is non-empty.
     243             :             // tdf#89802: for Writer frames there would be no exception here but
     244             :             // it will fail later on attach() and take out the entire frame
     245         591 :             if (sStyleName.isEmpty())
     246             :             {
     247          80 :                 Sequence<OUString> const seq{ sStyleName };
     248          80 :                 GetImport().SetError(
     249             :                     XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
     250         160 :                     seq, "empty style name reference", NULL );
     251          80 :                 break;
     252             :             }
     253             : 
     254             :             try
     255             :             {
     256             : 
     257             :                 // set property
     258         511 :                 const OUString& rPropertyName = xPropMapper->GetEntryAPIName(rState.mnIndex);
     259         511 :                 if( !xInfo.is() )
     260         436 :                     xInfo = rPropSet->getPropertySetInfo();
     261         511 :                 if ( xInfo->hasPropertyByName( rPropertyName ) )
     262             :                 {
     263         511 :                     rPropSet->setPropertyValue( rPropertyName, Any( sStyleName ) );
     264             :                 }
     265             :             }
     266           0 :             catch ( const ::com::sun::star::lang::IllegalArgumentException& e )
     267             :             {
     268           0 :                 Sequence<OUString> aSeq(1);
     269           0 :                 aSeq[0] = sStyleName;
     270           0 :                 GetImport().SetError(
     271             :                     XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
     272           0 :                     aSeq, e.Message, NULL );
     273             :             }
     274         511 :             break;
     275             :         }
     276             :         case CTF_SD_OLE_VIS_AREA_IMPORT_LEFT:
     277             :         case CTF_SD_OLE_VIS_AREA_IMPORT_TOP:
     278             :         case CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH:
     279             :         case CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT:
     280             :         {
     281           3 :             struct XMLPropertyState& rState = GetProperties()[nIndex];
     282           3 :             const OUString& rPropertyName = xPropMapper->GetEntryAPIName(rState.mnIndex);
     283             :             try
     284             :             {
     285           3 :                 if( !xInfo.is() )
     286           3 :                     xInfo = rPropSet->getPropertySetInfo();
     287           3 :                 if ( xInfo->hasPropertyByName( rPropertyName ) )
     288             :                 {
     289           0 :                     rPropSet->setPropertyValue( rPropertyName, rState.maValue );
     290             :                 }
     291             :             }
     292           0 :             catch ( const ::com::sun::star::lang::IllegalArgumentException& e )
     293             :             {
     294           0 :                 Sequence<OUString> aSeq;
     295           0 :                 GetImport().SetError(
     296             :                     XMLERROR_STYLE_PROP_VALUE | XMLERROR_FLAG_WARNING,
     297           0 :                     aSeq, e.Message, NULL );
     298             :             }
     299           3 :             break;
     300             :         }
     301             :         }
     302             :     }
     303             : 
     304        5262 :     if (!m_sControlDataStyleName.isEmpty())
     305             :     {   // we had a data-style-name attribute
     306             : 
     307             :         // set the formatting on the control model of the control shape
     308           0 :         uno::Reference< drawing::XControlShape > xControlShape(rPropSet, uno::UNO_QUERY);
     309             :         DBG_ASSERT(xControlShape.is(), "XMLShapeStyleContext::FillPropertySet: data style for a non-control shape!");
     310           0 :         if (xControlShape.is())
     311             :         {
     312           0 :             uno::Reference< beans::XPropertySet > xControlModel(xControlShape->getControl(), uno::UNO_QUERY);
     313             :             DBG_ASSERT(xControlModel.is(), "XMLShapeStyleContext::FillPropertySet: no control model for the shape!");
     314           0 :             if (xControlModel.is())
     315             :             {
     316           0 :                 GetImport().GetFormImport()->applyControlNumberStyle(xControlModel, m_sControlDataStyleName);
     317           0 :             }
     318           0 :         }
     319        5262 :     }
     320        5262 : }
     321             : 
     322         697 : void XMLShapeStyleContext::Finish( bool /*bOverwrite*/ )
     323             : {
     324         697 : }
     325             : 
     326             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11