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

Generated by: LCOV version 1.10