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

Generated by: LCOV version 1.10