LCOV - code coverage report
Current view: top level - xmloff/source/chart - SchXMLLegendContext.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 59 76 77.6 %
Date: 2012-08-25 Functions: 6 7 85.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 62 157 39.5 %

           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                 :            : #include "SchXMLLegendContext.hxx"
      30                 :            : #include "SchXMLEnumConverter.hxx"
      31                 :            : 
      32                 :            : #include <xmloff/xmlnmspe.hxx>
      33                 :            : #include <xmloff/xmlement.hxx>
      34                 :            : #include <xmloff/prstylei.hxx>
      35                 :            : #include <xmloff/nmspmap.hxx>
      36                 :            : #include <xmloff/xmluconv.hxx>
      37                 :            : 
      38                 :            : #include <com/sun/star/chart/ChartLegendPosition.hpp>
      39                 :            : #include <com/sun/star/chart/ChartLegendExpansion.hpp>
      40                 :            : #include <com/sun/star/drawing/FillStyle.hpp>
      41                 :            : 
      42                 :            : using namespace ::xmloff::token;
      43                 :            : using namespace com::sun::star;
      44                 :            : 
      45                 :            : using rtl::OUString;
      46                 :            : using com::sun::star::uno::Reference;
      47                 :            : 
      48                 :            : //----------------------------------------
      49                 :            : 
      50                 :            : namespace
      51                 :            : {
      52                 :            : 
      53                 :            : enum LegendAttributeTokens
      54                 :            : {
      55                 :            :     XML_TOK_LEGEND_POSITION,
      56                 :            :     XML_TOK_LEGEND_X,
      57                 :            :     XML_TOK_LEGEND_Y,
      58                 :            :     XML_TOK_LEGEND_STYLE_NAME,
      59                 :            :     XML_TOK_LEGEND_EXPANSION,
      60                 :            :     XML_TOK_LEGEND_EXPANSION_ASPECT_RATIO,
      61                 :            :     XML_TOK_LEGEND_WIDTH,
      62                 :            :     XML_TOK_LEGEND_WIDTH_EXT,
      63                 :            :     XML_TOK_LEGEND_HEIGHT,
      64                 :            :     XML_TOK_LEGEND_HEIGHT_EXT
      65                 :            : };
      66                 :            : 
      67                 :            : SvXMLTokenMapEntry aLegendAttributeTokenMap[] =
      68                 :            : {
      69                 :            :     { XML_NAMESPACE_CHART,      XML_LEGEND_POSITION,    XML_TOK_LEGEND_POSITION     },
      70                 :            :     { XML_NAMESPACE_SVG,        XML_X,                  XML_TOK_LEGEND_X            },
      71                 :            :     { XML_NAMESPACE_SVG,        XML_Y,                  XML_TOK_LEGEND_Y            },
      72                 :            :     { XML_NAMESPACE_CHART,      XML_STYLE_NAME,         XML_TOK_LEGEND_STYLE_NAME   },
      73                 :            :     { XML_NAMESPACE_STYLE,      XML_LEGEND_EXPANSION,   XML_TOK_LEGEND_EXPANSION    },
      74                 :            :     { XML_NAMESPACE_STYLE,      XML_LEGEND_EXPANSION_ASPECT_RATIO,   XML_TOK_LEGEND_EXPANSION_ASPECT_RATIO    },
      75                 :            :     { XML_NAMESPACE_SVG,        XML_WIDTH,              XML_TOK_LEGEND_WIDTH        },
      76                 :            :     { XML_NAMESPACE_CHART_EXT,  XML_WIDTH,              XML_TOK_LEGEND_WIDTH_EXT    },
      77                 :            :     { XML_NAMESPACE_SVG,        XML_HEIGHT,             XML_TOK_LEGEND_HEIGHT       },
      78                 :            :     { XML_NAMESPACE_CHART_EXT,  XML_HEIGHT,             XML_TOK_LEGEND_HEIGHT_EXT   },
      79                 :            :     XML_TOKEN_MAP_END
      80                 :            : };
      81                 :            : 
      82                 :            : class LegendAttributeTokenMap : public SvXMLTokenMap
      83                 :            : {
      84                 :            : public:
      85                 :          2 :     LegendAttributeTokenMap(): SvXMLTokenMap( aLegendAttributeTokenMap ) {}
      86         [ -  + ]:          2 :     virtual ~LegendAttributeTokenMap() {}
      87                 :            : };
      88                 :            : 
      89                 :            : //a LegendAttributeTokenMap Singleton
      90                 :            : struct theLegendAttributeTokenMap : public rtl::Static< LegendAttributeTokenMap, theLegendAttributeTokenMap > {};
      91                 :            : 
      92                 :            : }//end anonymous namespace
      93                 :            : 
      94                 :            : //----------------------------------------
      95                 :            : 
      96                 :          6 : SchXMLLegendContext::SchXMLLegendContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, const rtl::OUString& rLocalName ) :
      97                 :            :     SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ),
      98                 :          6 :     mrImportHelper( rImpHelper )
      99                 :            : {
     100                 :          6 : }
     101                 :            : 
     102                 :          6 : void SchXMLLegendContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList )
     103                 :            : {
     104                 :          6 :     uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument();
     105         [ -  + ]:          6 :     if( !xDoc.is() )
     106                 :            :         return;
     107                 :            : 
     108                 :            :     // turn on legend
     109         [ +  - ]:          6 :     uno::Reference< beans::XPropertySet > xDocProp( xDoc, uno::UNO_QUERY );
     110         [ +  - ]:          6 :     if( xDocProp.is() )
     111                 :            :     {
     112                 :            :         try
     113                 :            :         {
     114 [ +  - ][ +  - ]:          6 :             xDocProp->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "HasLegend" )), uno::makeAny( sal_True ) );
         [ +  - ][ +  - ]
                 [ #  # ]
     115                 :            :         }
     116         [ #  # ]:          0 :         catch(const beans::UnknownPropertyException&)
     117                 :            :         {
     118                 :            :             OSL_TRACE( "Property HasLegend not found" );
     119                 :            :         }
     120                 :            :     }
     121                 :            : 
     122 [ +  - ][ +  - ]:          6 :     uno::Reference< drawing::XShape > xLegendShape( xDoc->getLegend(), uno::UNO_QUERY );
                 [ +  - ]
     123         [ +  - ]:          6 :     uno::Reference< beans::XPropertySet > xLegendProps( xLegendShape, uno::UNO_QUERY );
     124 [ +  - ][ -  + ]:          6 :     if( !xLegendShape.is() || !xLegendProps.is() )
                 [ -  + ]
     125                 :            :     {
     126                 :            :         OSL_TRACE( "legend could not be created" );
     127                 :            :         return;
     128                 :            :     }
     129                 :            : 
     130                 :            :     // parse attributes
     131 [ +  - ][ +  - ]:          6 :     sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0;
                 [ +  - ]
     132         [ +  - ]:          6 :     const SvXMLTokenMap& rAttrTokenMap = theLegendAttributeTokenMap::get();
     133                 :            : 
     134                 :          6 :     awt::Point aLegendPos;
     135                 :          6 :     bool bHasXPosition=false;
     136                 :          6 :     bool bHasYPosition=false;
     137                 :          6 :     awt::Size aLegendSize;
     138                 :          6 :     bool bHasWidth=false;
     139                 :          6 :     bool bHasHeight=false;
     140                 :          6 :     chart::ChartLegendExpansion nLegendExpansion = chart::ChartLegendExpansion_HIGH;
     141                 :          6 :     bool bHasExpansion=false;
     142                 :            : 
     143                 :          6 :     rtl::OUString sAutoStyleName;
     144                 :          6 :     uno::Any aAny;
     145                 :            : 
     146         [ +  + ]:         30 :     for( sal_Int16 i = 0; i < nAttrCount; i++ )
     147                 :            :     {
     148 [ +  - ][ +  - ]:         24 :         rtl::OUString sAttrName = xAttrList->getNameByIndex( i );
     149                 :         24 :         rtl::OUString aLocalName;
     150 [ +  - ][ +  - ]:         24 :         rtl::OUString aValue = xAttrList->getValueByIndex( i );
     151         [ +  - ]:         24 :         sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName );
     152                 :            : 
     153 [ +  - ][ +  +  :         24 :         switch( rAttrTokenMap.Get( nPrefix, aLocalName ))
          +  +  -  -  -  
                   -  - ]
     154                 :            :         {
     155                 :            :             case XML_TOK_LEGEND_POSITION:
     156                 :            :                 {
     157                 :            :                     try
     158                 :            :                     {
     159 [ +  - ][ +  - ]:          6 :                         if( SchXMLEnumConverter::getLegendPositionConverter().importXML( aValue, aAny, GetImport().GetMM100UnitConverter() ) )
                 [ +  - ]
     160 [ +  - ][ +  - ]:          6 :                             xLegendProps->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Alignment" )), aAny );
         [ +  - ][ #  # ]
     161                 :            :                     }
     162         [ #  # ]:          0 :                     catch(const beans::UnknownPropertyException&)
     163                 :            :                     {
     164                 :            :                         OSL_TRACE( "Property Alignment (legend) not found" );
     165                 :            :                     }
     166                 :            :                 }
     167                 :          6 :                 break;
     168                 :            : 
     169                 :            :             case XML_TOK_LEGEND_X:
     170                 :          6 :                 GetImport().GetMM100UnitConverter().convertMeasureToCore(
     171         [ +  - ]:          6 :                         aLegendPos.X, aValue );
     172                 :          6 :                 bHasXPosition = true;
     173                 :          6 :                 break;
     174                 :            :             case XML_TOK_LEGEND_Y:
     175                 :          6 :                 GetImport().GetMM100UnitConverter().convertMeasureToCore(
     176         [ +  - ]:          6 :                         aLegendPos.Y, aValue );
     177                 :          6 :                 bHasYPosition = true;
     178                 :          6 :                 break;
     179                 :            :             case XML_TOK_LEGEND_STYLE_NAME:
     180                 :          6 :                 sAutoStyleName = aValue;
     181                 :          6 :                 break;
     182                 :            :             case XML_TOK_LEGEND_EXPANSION:
     183 [ #  # ][ #  # ]:          0 :                 SchXMLEnumConverter::getLegendPositionConverter().importXML( aValue, aAny, GetImport().GetMM100UnitConverter() );
     184         [ #  # ]:          0 :                 bHasExpansion = (aAny>>=nLegendExpansion);
     185                 :          0 :                 break;
     186                 :            :             case XML_TOK_LEGEND_EXPANSION_ASPECT_RATIO:
     187                 :          0 :                 break;
     188                 :            :             case XML_TOK_LEGEND_WIDTH:
     189                 :            :             case XML_TOK_LEGEND_WIDTH_EXT:
     190                 :          0 :                 GetImport().GetMM100UnitConverter().convertMeasureToCore(
     191         [ #  # ]:          0 :                         aLegendSize.Width, aValue );
     192                 :          0 :                 bHasWidth = true;
     193                 :          0 :                 break;
     194                 :            :             case XML_TOK_LEGEND_HEIGHT:
     195                 :            :             case XML_TOK_LEGEND_HEIGHT_EXT:
     196                 :          0 :                 GetImport().GetMM100UnitConverter().convertMeasureToCore(
     197         [ #  # ]:          0 :                         aLegendSize.Height, aValue );
     198                 :          0 :                 bHasHeight = true;
     199                 :          0 :                 break;
     200                 :            :             default:
     201                 :          0 :                 break;
     202                 :            :         }
     203                 :         24 :     }
     204                 :            : 
     205 [ +  - ][ +  - ]:          6 :     if( bHasXPosition && bHasYPosition )
     206 [ +  - ][ +  - ]:          6 :         xLegendShape->setPosition( aLegendPos );
     207                 :            : 
     208 [ -  + ][ #  # ]:          6 :     if( bHasExpansion && nLegendExpansion!= chart::ChartLegendExpansion_CUSTOM )
     209 [ #  # ][ #  # ]:          0 :         xLegendProps->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Expansion" )), uno::makeAny(nLegendExpansion) );
         [ #  # ][ #  # ]
     210 [ -  + ][ #  # ]:          6 :     else if( bHasHeight && bHasWidth )
     211 [ #  # ][ #  # ]:          0 :         xLegendShape->setSize( aLegendSize );
     212                 :            : 
     213                 :            :     // the fill style has the default "none" in XML, but "solid" in the model.
     214 [ +  - ][ +  - ]:          6 :     xLegendProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillStyle" )), uno::makeAny( drawing::FillStyle_NONE ));
         [ +  - ][ +  - ]
     215                 :            : 
     216                 :            :     // set auto-styles for Legend
     217                 :          6 :     const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext();
     218         [ +  - ]:          6 :     if( pStylesCtxt )
     219                 :            :     {
     220                 :            :         const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext(
     221         [ +  - ]:          6 :             mrImportHelper.GetChartFamilyID(), sAutoStyleName );
     222                 :            : 
     223 [ +  - ][ +  - ]:          6 :         if( pStyle && pStyle->ISA( XMLPropStyleContext ))
         [ +  - ][ +  - ]
                 [ +  - ]
     224         [ +  - ]:          6 :             (( XMLPropStyleContext* )pStyle )->FillPropertySet( xLegendProps );
     225 [ -  + ][ -  + ]:          6 :     }
         [ -  + ][ +  - ]
     226                 :            : }
     227                 :            : 
     228                 :          6 : SchXMLLegendContext::~SchXMLLegendContext()
     229                 :            : {
     230         [ -  + ]:         12 : }
     231                 :            : 
     232                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10