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

Generated by: LCOV version 1.10