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

Generated by: LCOV version 1.10