LCOV - code coverage report
Current view: top level - xmloff/source/draw - XMLShapeStyleContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 70 109 64.2 %
Date: 2012-08-25 Functions: 10 12 83.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 85 235 36.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <tools/debug.hxx>
      31                 :            : #include <xmloff/XMLShapeStyleContext.hxx>
      32                 :            : #include "XMLShapePropertySetContext.hxx"
      33                 :            : #include <xmloff/contextid.hxx>
      34                 :            : #include <com/sun/star/drawing/XControlShape.hpp>
      35                 :            : #include "com/sun/star/beans/XPropertySetInfo.hpp"
      36                 :            : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      37                 :            : #include <xmloff/xmlimp.hxx>
      38                 :            : #include <xmloff/xmlnumi.hxx>
      39                 :            : #include <xmloff/xmlnmspe.hxx>
      40                 :            : #include <xmloff/xmltoken.hxx>
      41                 :            : #include "xmloff/xmlerror.hxx"
      42                 :            : #include <xmloff/maptype.hxx>
      43                 :            : 
      44                 :            : #include "sdpropls.hxx"
      45                 :            : 
      46                 :            : using ::rtl::OUString;
      47                 :            : using ::rtl::OUStringBuffer;
      48                 :            : 
      49                 :            : using namespace ::com::sun::star;
      50                 :            : using namespace ::com::sun::star::uno;
      51                 :            : using namespace ::com::sun::star::beans;
      52                 :            : using ::xmloff::token::IsXMLToken;
      53                 :            : using ::xmloff::token::XML_TEXT_PROPERTIES;
      54                 :            : using ::xmloff::token::XML_GRAPHIC_PROPERTIES;
      55                 :            : using ::xmloff::token::XML_PARAGRAPH_PROPERTIES;
      56                 :            : 
      57                 :            : //////////////////////////////////////////////////////////////////////////////
      58                 :            : 
      59 [ +  + ][ +  + ]:       5063 : TYPEINIT1( XMLShapeStyleContext, XMLPropStyleContext );
      60                 :            : 
      61                 :        561 : XMLShapeStyleContext::XMLShapeStyleContext(
      62                 :            :     SvXMLImport& rImport,
      63                 :            :     sal_uInt16 nPrfx,
      64                 :            :     const OUString& rLName,
      65                 :            :     const uno::Reference< xml::sax::XAttributeList >& xAttrList,
      66                 :            :     SvXMLStylesContext& rStyles,
      67                 :            :     sal_uInt16 nFamily)
      68                 :            : :   XMLPropStyleContext(rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ),
      69                 :        561 :     m_bIsNumRuleAlreadyConverted( sal_False )
      70                 :            : {
      71                 :        561 : }
      72                 :            : 
      73                 :        561 : XMLShapeStyleContext::~XMLShapeStyleContext()
      74                 :            : {
      75         [ -  + ]:       1004 : }
      76                 :            : 
      77                 :       1473 : void XMLShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey, const ::rtl::OUString& rLocalName, const ::rtl::OUString& rValue )
      78                 :            : {
      79 [ +  - ][ -  + ]:       1473 :     if (m_sControlDataStyleName.isEmpty() && (::xmloff::token::GetXMLToken(::xmloff::token::XML_DATA_STYLE_NAME) == rLocalName))
                 [ -  + ]
      80                 :            :     {
      81                 :          0 :         m_sControlDataStyleName = rValue;
      82                 :            :     }
      83 [ +  - ][ -  + ]:       1473 :     else if( (XML_NAMESPACE_STYLE == nPrefixKey) && IsXMLToken( rLocalName, ::xmloff::token::XML_LIST_STYLE_NAME ) )
                 [ -  + ]
      84                 :            :     {
      85                 :          0 :         m_sListStyleName = rValue;
      86                 :            :     }
      87                 :            :     else
      88                 :            :     {
      89                 :       1473 :         XMLPropStyleContext::SetAttribute( nPrefixKey, rLocalName, rValue );
      90                 :            : 
      91 [ +  + ][ +  -  :       3858 :         if( (XML_NAMESPACE_STYLE == nPrefixKey) &&
             +  +  -  + ]
      92                 :       2385 :             ( IsXMLToken( rLocalName, ::xmloff::token::XML_NAME ) || IsXMLToken( rLocalName, ::xmloff::token::XML_DISPLAY_NAME ) ) )
      93                 :            :         {
      94 [ +  - ][ +  - ]:        561 :             if( !GetName().isEmpty() && !GetDisplayName().isEmpty() && GetName() != GetDisplayName() )
         [ -  + ][ -  + ]
      95                 :            :             {
      96                 :          0 :                 const_cast< SvXMLImport&>( GetImport() ).
      97                 :          0 :                     AddStyleDisplayName( GetFamily(), GetName(), GetDisplayName() );
      98                 :            :             }
      99                 :            :         }
     100                 :            :     }
     101                 :       1473 : }
     102                 :            : 
     103                 :        778 : SvXMLImportContext *XMLShapeStyleContext::CreateChildContext(
     104                 :            :         sal_uInt16 nPrefix,
     105                 :            :         const OUString& rLocalName,
     106                 :            :         const Reference< xml::sax::XAttributeList > & xAttrList )
     107                 :            : {
     108                 :        778 :     SvXMLImportContext *pContext = 0;
     109                 :            : 
     110         [ +  - ]:        778 :     if( XML_NAMESPACE_STYLE == nPrefix )
     111                 :            :     {
     112                 :        778 :         sal_uInt32 nFamily = 0;
     113         [ +  + ]:        778 :         if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) )
     114                 :        200 :             nFamily = XML_TYPE_PROP_TEXT;
     115         [ +  + ]:        578 :         else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) )
     116                 :        175 :             nFamily = XML_TYPE_PROP_PARAGRAPH;
     117         [ +  + ]:        403 :         else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) )
     118                 :        388 :             nFamily = XML_TYPE_PROP_GRAPHIC;
     119         [ +  + ]:        778 :         if( nFamily )
     120                 :            :         {
     121                 :            :             UniReference < SvXMLImportPropertyMapper > xImpPrMap =
     122         [ +  - ]:        763 :                 GetStyles()->GetImportPropertyMapper( GetFamily() );
     123         [ +  - ]:        763 :             if( xImpPrMap.is() )
     124                 :        763 :                 pContext = new XMLShapePropertySetContext( GetImport(), nPrefix,
     125                 :            :                                                         rLocalName, xAttrList,
     126                 :            :                                                         nFamily,
     127                 :        763 :                                                         GetProperties(),
     128 [ +  - ][ +  - ]:        763 :                                                         xImpPrMap );
                 [ +  - ]
     129                 :            :         }
     130                 :            :     }
     131                 :            : 
     132         [ +  + ]:        778 :     if( !pContext )
     133                 :            :         pContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName,
     134                 :         15 :                                                           xAttrList );
     135                 :            : 
     136                 :        778 :     return pContext;
     137                 :            : }
     138                 :            : 
     139                 :        888 : void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet > & rPropSet )
     140                 :            : {
     141         [ +  + ]:        888 :     if( !m_bIsNumRuleAlreadyConverted )
     142                 :            :     {
     143                 :        549 :         m_bIsNumRuleAlreadyConverted = sal_True;
     144                 :            : 
     145                 :            :         // for compatibility to beta files, search for CTF_SD_NUMBERINGRULES_NAME to
     146                 :            :         // import numbering rules from the style:properties element
     147 [ +  - ][ +  - ]:        549 :         const UniReference< XMLPropertySetMapper >&rMapper = GetStyles()->GetImportPropertyMapper( GetFamily() )->getPropertySetMapper();
                 [ +  - ]
     148                 :            : 
     149                 :        549 :         ::std::vector< XMLPropertyState > &rProperties = GetProperties();
     150                 :        549 :         ::std::vector< XMLPropertyState >::iterator end( rProperties.end() );
     151                 :        549 :         ::std::vector< XMLPropertyState >::iterator property;
     152                 :            : 
     153                 :            :         // first, look for the old format, where we had a text:list-style-name
     154                 :            :         // attribute in the style:properties element
     155 [ +  - ][ +  + ]:       7279 :         for( property = rProperties.begin(); property != end; ++property )
     156                 :            :         {
     157                 :            :             // find properties with context
     158 [ +  + ][ +  - ]:       6730 :             if( (property->mnIndex != -1) && (rMapper->GetEntryContextId( property->mnIndex ) == CTF_SD_NUMBERINGRULES_NAME) )
         [ +  - ][ -  + ]
                 [ -  + ]
     159                 :          0 :                 break;
     160                 :            :         }
     161                 :            : 
     162                 :            :         // if we did not find an old list-style-name in the properties, and we need one
     163                 :            :         // because we got a style:list-style attribute in the style-style element
     164                 :            :         // we generate one
     165 [ +  - ][ +  - ]:        549 :         if( (property == end) && ( !m_sListStyleName.isEmpty() ) )
         [ -  + ][ -  + ]
     166                 :            :         {
     167 [ #  # ][ #  # ]:          0 :             sal_Int32 nIndex = rMapper->FindEntryIndex( CTF_SD_NUMBERINGRULES_NAME );
     168                 :            :             DBG_ASSERT( -1 != nIndex, "can't find numbering rules property entry, can't set numbering rule!" );
     169                 :            : 
     170                 :          0 :             XMLPropertyState aNewState( nIndex );
     171         [ #  # ]:          0 :             rProperties.push_back( aNewState );
     172                 :          0 :             end = rProperties.end();
     173         [ #  # ]:          0 :             property = end - 1;
     174                 :            :         }
     175                 :            : 
     176                 :            :         // so, if we have an old or a new list style name, we set its value to
     177                 :            :         // a numbering rule
     178 [ +  - ][ -  + ]:        549 :         if( property != end )
     179                 :            :         {
     180         [ #  # ]:          0 :             if( m_sListStyleName.isEmpty() )
     181                 :            :             {
     182                 :          0 :                 property->maValue >>= m_sListStyleName;
     183                 :            :             }
     184                 :            : 
     185 [ #  # ][ #  # ]:          0 :             const SvxXMLListStyleContext *pListStyle = GetImport().GetTextImport()->FindAutoListStyle( m_sListStyleName );
         [ #  # ][ #  # ]
     186                 :            : 
     187                 :            :             DBG_ASSERT( pListStyle, "list-style not found for shape style" );
     188         [ #  # ]:          0 :             if( pListStyle )
     189                 :            :             {
     190         [ #  # ]:          0 :                 uno::Reference< container::XIndexReplace > xNumRule( pListStyle->CreateNumRule( GetImport().GetModel() ) );
     191         [ #  # ]:          0 :                 pListStyle->FillUnoNumRule(xNumRule, NULL /* const SvI18NMap * ??? */ );
     192         [ #  # ]:          0 :                 property->maValue <<= xNumRule;
     193                 :            :             }
     194                 :            :             else
     195                 :            :             {
     196                 :        549 :                 property->mnIndex = -1;
     197                 :            :             }
     198                 :            :         }
     199                 :            :     }
     200                 :            : 
     201                 :            :     struct _ContextID_Index_Pair aContextIDs[] =
     202                 :            :     {
     203                 :            :         { CTF_DASHNAME , -1 },
     204                 :            :         { CTF_LINESTARTNAME , -1 },
     205                 :            :         { CTF_LINEENDNAME , -1 },
     206                 :            :         { CTF_FILLGRADIENTNAME, -1 },
     207                 :            :         { CTF_FILLTRANSNAME , -1 },
     208                 :            :         { CTF_FILLHATCHNAME , -1 },
     209                 :            :         { CTF_FILLBITMAPNAME , -1 },
     210                 :            :         { CTF_SD_OLE_VIS_AREA_IMPORT_LEFT, -1 },
     211                 :            :         { CTF_SD_OLE_VIS_AREA_IMPORT_TOP, -1 },
     212                 :            :         { CTF_SD_OLE_VIS_AREA_IMPORT_WIDTH, -1 },
     213                 :            :         { CTF_SD_OLE_VIS_AREA_IMPORT_HEIGHT, -1 },
     214                 :            :         { -1, -1 }
     215                 :        888 :     };
     216                 :            :     static sal_uInt16 aFamilies[] =
     217                 :            :     {
     218                 :            :         XML_STYLE_FAMILY_SD_STROKE_DASH_ID,
     219                 :            :         XML_STYLE_FAMILY_SD_MARKER_ID,
     220                 :            :         XML_STYLE_FAMILY_SD_MARKER_ID,
     221                 :            :         XML_STYLE_FAMILY_SD_GRADIENT_ID,
     222                 :            :         XML_STYLE_FAMILY_SD_GRADIENT_ID,
     223                 :            :         XML_STYLE_FAMILY_SD_HATCH_ID,
     224                 :            :         XML_STYLE_FAMILY_SD_FILL_IMAGE_ID
     225                 :            :     };
     226                 :            : 
     227                 :            :     UniReference < SvXMLImportPropertyMapper > xImpPrMap =
     228         [ +  - ]:        888 :         GetStyles()->GetImportPropertyMapper( GetFamily() );
     229                 :            :     DBG_ASSERT( xImpPrMap.is(), "There is the import prop mapper" );
     230         [ +  - ]:        888 :     if( xImpPrMap.is() )
     231 [ +  - ][ +  - ]:        888 :         xImpPrMap->FillPropertySet( GetProperties(), rPropSet, aContextIDs );
     232                 :            : 
     233                 :        888 :     Reference< XPropertySetInfo > xInfo;
     234                 :            :     // get property set mapper
     235 [ +  - ][ +  - ]:        888 :     UniReference<XMLPropertySetMapper> xPropMapper( xImpPrMap->getPropertySetMapper() );
     236                 :            : 
     237         [ +  + ]:      10656 :     for( sal_uInt16 i=0; aContextIDs[i].nContextID != -1; i++ )
     238                 :            :     {
     239                 :       9768 :         sal_Int32 nIndex = aContextIDs[i].nIndex;
     240         [ +  + ]:       9768 :         if( nIndex != -1 ) switch( aContextIDs[i].nContextID )
              [ +  -  - ]
     241                 :            :         {
     242                 :            :         case CTF_DASHNAME:
     243                 :            :         case CTF_LINESTARTNAME:
     244                 :            :         case CTF_LINEENDNAME:
     245                 :            :         case CTF_FILLGRADIENTNAME:
     246                 :            :         case CTF_FILLTRANSNAME:
     247                 :            :         case CTF_FILLHATCHNAME:
     248                 :            :         case CTF_FILLBITMAPNAME:
     249                 :            :         {
     250                 :        143 :             struct XMLPropertyState& rState = GetProperties()[nIndex];
     251                 :        143 :             OUString sStyleName;
     252                 :        143 :             rState.maValue >>= sStyleName;
     253         [ +  - ]:        143 :             sStyleName = GetImport().GetStyleDisplayName( aFamilies[i], sStyleName );
     254                 :            :             try
     255                 :            :             {
     256                 :            : 
     257                 :            :                 // set property
     258 [ +  - ][ +  - ]:        143 :                 const OUString& rPropertyName = xPropMapper->GetEntryAPIName(rState.mnIndex);
     259         [ +  + ]:        143 :                 if( !xInfo.is() )
     260 [ +  - ][ +  - ]:        102 :                     xInfo = rPropSet->getPropertySetInfo();
                 [ +  - ]
     261 [ +  - ][ +  - ]:        143 :                 if ( xInfo->hasPropertyByName( rPropertyName ) )
                 [ +  - ]
     262                 :            :                 {
     263 [ +  - ][ +  - ]:        143 :                     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                 :        143 :             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                 :          0 :             struct XMLPropertyState& rState = GetProperties()[nIndex];
     282 [ #  # ][ #  # ]:          0 :             const OUString& rPropertyName = xPropMapper->GetEntryAPIName(rState.mnIndex);
     283                 :            :             try
     284                 :            :             {
     285         [ #  # ]:          0 :                 if( !xInfo.is() )
     286 [ #  # ][ #  # ]:          0 :                     xInfo = rPropSet->getPropertySetInfo();
                 [ #  # ]
     287 [ #  # ][ #  # ]:          0 :                 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                 :        143 :             break;
     300                 :            :         }
     301                 :            :         }
     302                 :            :     }
     303                 :            : 
     304         [ -  + ]:        888 :     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 [ +  - ][ +  - ]:        888 :     }
     320                 :        888 : }
     321                 :            : 
     322                 :        147 : void XMLShapeStyleContext::Finish( sal_Bool /*bOverwrite*/ )
     323                 :            : {
     324                 :        147 : }
     325                 :            : 
     326                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10