LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/tools - LegendHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 43 23.3 %
Date: 2012-12-27 Functions: 1 4 25.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 "LegendHelper.hxx"
      21             : #include "macros.hxx"
      22             : #include <com/sun/star/chart/ChartLegendExpansion.hpp>
      23             : #include <com/sun/star/chart2/LegendPosition.hpp>
      24             : #include <com/sun/star/chart2/RelativePosition.hpp>
      25             : #include <com/sun/star/chart2/XChartDocument.hpp>
      26             : #include <com/sun/star/chart2/XLegend.hpp>
      27             : #include <com/sun/star/lang/XServiceInfo.hpp>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : using ::com::sun::star::uno::Reference;
      31             : 
      32             : //.............................................................................
      33             : namespace chart
      34             : {
      35             : //.............................................................................
      36             : 
      37             : 
      38           0 : Reference< chart2::XLegend > LegendHelper::showLegend( const Reference< frame::XModel >& xModel
      39             :                                                     , const uno::Reference< uno::XComponentContext >& xContext )
      40             : {
      41           0 :     uno::Reference< chart2::XLegend > xLegend = LegendHelper::getLegend( xModel, xContext, true );
      42           0 :     uno::Reference< beans::XPropertySet > xProp( xLegend, uno::UNO_QUERY );
      43           0 :     if( xProp.is())
      44             :     {
      45           0 :         xProp->setPropertyValue( C2U("Show"), uno::makeAny(sal_True) );
      46             : 
      47           0 :         chart2::RelativePosition aRelativePosition;
      48           0 :         if( !(xProp->getPropertyValue( C2U( "RelativePosition" )) >>=  aRelativePosition) )
      49             :         {
      50           0 :             chart2::LegendPosition ePos = chart2::LegendPosition_LINE_END;
      51           0 :             if( !(xProp->getPropertyValue( C2U( "AnchorPosition" )) >>= ePos ) )
      52           0 :                 xProp->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( ePos ));
      53             : 
      54             :             ::com::sun::star::chart::ChartLegendExpansion eExpansion =
      55             :                     ( ePos == chart2::LegendPosition_LINE_END ||
      56             :                       ePos == chart2::LegendPosition_LINE_START )
      57             :                     ? ::com::sun::star::chart::ChartLegendExpansion_HIGH
      58           0 :                     : ::com::sun::star::chart::ChartLegendExpansion_WIDE;
      59           0 :             if( !(xProp->getPropertyValue( C2U( "Expansion" )) >>= eExpansion ) )
      60           0 :                 xProp->setPropertyValue( C2U( "Expansion" ), uno::makeAny( eExpansion ));
      61             : 
      62           0 :             xProp->setPropertyValue( C2U( "RelativePosition" ), uno::Any());
      63             :         }
      64             : 
      65             :     }
      66           0 :     return xLegend;
      67             : }
      68             : 
      69           0 : void LegendHelper::hideLegend( const Reference< frame::XModel >& xModel )
      70             : {
      71           0 :     uno::Reference< chart2::XLegend > xLegend = LegendHelper::getLegend( xModel, 0, false );
      72           0 :     uno::Reference< beans::XPropertySet > xProp( xLegend, uno::UNO_QUERY );
      73           0 :     if( xProp.is())
      74             :     {
      75           0 :         xProp->setPropertyValue( C2U("Show"), uno::makeAny(sal_False) );
      76           0 :     }
      77           0 : }
      78             : 
      79          41 : uno::Reference< chart2::XLegend > LegendHelper::getLegend(
      80             :       const uno::Reference< frame::XModel >& xModel
      81             :     , const uno::Reference< uno::XComponentContext >& xContext
      82             :     , bool bCreate )
      83             : {
      84          41 :     uno::Reference< chart2::XLegend > xResult;
      85             : 
      86          41 :     uno::Reference< chart2::XChartDocument > xChartDoc( xModel, uno::UNO_QUERY );
      87          41 :     if( xChartDoc.is())
      88             :     {
      89             :         try
      90             :         {
      91          41 :             uno::Reference< chart2::XDiagram > xDia( xChartDoc->getFirstDiagram());
      92          41 :             if( xDia.is() )
      93             :             {
      94          41 :                 xResult.set( xDia->getLegend() );
      95          41 :                 if( bCreate && !xResult.is() && xContext.is() )
      96             :                 {
      97           0 :                     xResult.set( xContext->getServiceManager()->createInstanceWithContext(
      98           0 :                         C2U( "com.sun.star.chart2.Legend" ), xContext ), uno::UNO_QUERY );
      99           0 :                     xDia->setLegend( xResult );
     100             :                 }
     101             :             }
     102             :             else if(bCreate)
     103             :             {
     104             :                 OSL_FAIL("need diagram for creation of legend");
     105          41 :             }
     106             :         }
     107           0 :         catch( const uno::Exception & ex )
     108             :         {
     109             :             ASSERT_EXCEPTION( ex );
     110             :         }
     111             :     }
     112             : 
     113          41 :     return xResult;
     114             : }
     115             : 
     116           0 : bool LegendHelper::hasLegend( const uno::Reference< chart2::XDiagram > & xDiagram )
     117             : {
     118           0 :     bool bReturn = false;
     119           0 :     if( xDiagram.is())
     120             :     {
     121           0 :         uno::Reference< beans::XPropertySet > xLegendProp( xDiagram->getLegend(), uno::UNO_QUERY );
     122           0 :         if( xLegendProp.is())
     123           0 :             xLegendProp->getPropertyValue( C2U("Show")) >>= bReturn;
     124             :     }
     125             : 
     126           0 :     return bReturn;
     127             : }
     128             : 
     129             : //.............................................................................
     130             : } //namespace chart
     131             : //.............................................................................
     132             : 
     133             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10