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

Generated by: LCOV version 1.10