LCOV - code coverage report
Current view: top level - svx/source/svdraw - charthelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 50 68 73.5 %
Date: 2014-11-03 Functions: 3 4 75.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 <svx/charthelper.hxx>
      21             : #include <tools/globname.hxx>
      22             : #include <comphelper/classids.hxx>
      23             : #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
      24             : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
      25             : #include <com/sun/star/embed/XEmbeddedObject.hpp>
      26             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      27             : #include <com/sun/star/util/XUpdatable.hpp>
      28             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : #include <comphelper/processfactory.hxx>
      31             : #include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
      32             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      33             : #include <com/sun/star/chart2/XChartDocument.hpp>
      34             : #include <com/sun/star/drawing/FillStyle.hpp>
      35             : #include <com/sun/star/drawing/LineStyle.hpp>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39        1897 : bool ChartHelper::isGL3DDiagram( const css::uno::Reference<css::chart2::XDiagram>& xDiagram )
      40             : {
      41        1897 :     uno::Reference<chart2::XCoordinateSystemContainer> xCooSysContainer(xDiagram, uno::UNO_QUERY);
      42             : 
      43        1897 :     if (!xCooSysContainer.is())
      44         315 :         return false;
      45             : 
      46        3164 :     uno::Sequence< uno::Reference<chart2::XCoordinateSystem> > aCooSysList = xCooSysContainer->getCoordinateSystems();
      47        3164 :     for (sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS)
      48             :     {
      49        1582 :         uno::Reference<chart2::XCoordinateSystem> xCooSys = aCooSysList[nCS];
      50             : 
      51             :         //iterate through all chart types in the current coordinate system
      52        3164 :         uno::Reference<chart2::XChartTypeContainer> xChartTypeContainer(xCooSys, uno::UNO_QUERY);
      53             :         OSL_ASSERT( xChartTypeContainer.is());
      54        1582 :         if( !xChartTypeContainer.is() )
      55           0 :             continue;
      56             : 
      57        3164 :         uno::Sequence< uno::Reference<chart2::XChartType> > aChartTypeList = xChartTypeContainer->getChartTypes();
      58        3206 :         for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
      59             :         {
      60        1624 :             uno::Reference<chart2::XChartType> xChartType = aChartTypeList[nT];
      61        3248 :             OUString aChartType = xChartType->getChartType();
      62        1624 :             if( aChartType == "com.sun.star.chart2.GL3DBarChartType" )
      63           0 :                 return true;
      64        1624 :         }
      65        1582 :     }
      66             : 
      67        3479 :     return false;
      68             : }
      69             : 
      70         327 : void ChartHelper::updateChart(const uno::Reference< ::frame::XModel >& rXModel)
      71             : {
      72         327 :     if (!rXModel.is())
      73         327 :         return;
      74             : 
      75             :     try
      76             :     {
      77         327 :         const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
      78         654 :         const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance("com.sun.star.chart2.ChartView"), uno::UNO_QUERY_THROW);
      79         654 :         const uno::Reference< util::XUpdatable > xUpdatable(xChartView, uno::UNO_QUERY_THROW);
      80             : 
      81         327 :         if (xUpdatable.is())
      82         654 :             xUpdatable->update();
      83             :     }
      84           0 :     catch(uno::Exception&)
      85             :     {
      86             :         OSL_ENSURE(false, "Unexpected exception!");
      87             :     }
      88             : }
      89             : 
      90         327 : drawinglayer::primitive2d::Primitive2DSequence ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
      91             :     const uno::Reference< ::frame::XModel >& rXModel,
      92             :     basegfx::B2DRange& rRange)
      93             : {
      94         327 :     drawinglayer::primitive2d::Primitive2DSequence aRetval;
      95             : 
      96         327 :     if (!rXModel.is())
      97           0 :         return aRetval;
      98             : 
      99         327 :     updateChart(rXModel);
     100             : 
     101             :     try
     102             :     {
     103         327 :         const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
     104         654 :         const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
     105             : 
     106         327 :         if(xShapeAccess.is() && xShapeAccess->getCount())
     107             :         {
     108         327 :             const sal_Int32 nShapeCount(xShapeAccess->getCount());
     109         327 :             const uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
     110             :             const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory =
     111         650 :                 graphic::PrimitiveFactory2D::create( xContext );
     112             : 
     113         646 :             const uno::Sequence< beans::PropertyValue > aParams;
     114         646 :             uno::Reference< drawing::XShape > xShape;
     115             : 
     116         646 :             for(sal_Int32 a(0); a < nShapeCount; a++)
     117             :             {
     118         323 :                 xShapeAccess->getByIndex(a) >>= xShape;
     119             : 
     120         323 :                 if(xShape.is())
     121             :                 {
     122             :                     const drawinglayer::primitive2d::Primitive2DSequence aNew(
     123         323 :                             xPrimitiveFactory->createPrimitivesFromXShape(
     124             :                                 xShape,
     125         323 :                                 aParams));
     126             : 
     127             :                     drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
     128             :                             aRetval,
     129         323 :                             aNew);
     130             :                 }
     131         327 :             }
     132         327 :         }
     133             :     }
     134           4 :     catch(uno::Exception&)
     135             :     {
     136             :         OSL_ENSURE(false, "Unexpected exception!");
     137             :     }
     138             : 
     139         327 :     if(aRetval.hasElements())
     140             :     {
     141         323 :         const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
     142             : 
     143         323 :         rRange = drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval, aViewInformation2D);
     144             :     }
     145             : 
     146         327 :     return aRetval;
     147             : }
     148             : 
     149           0 : void ChartHelper::AdaptDefaultsForChart(
     150             :     const uno::Reference < embed::XEmbeddedObject > & xEmbObj,
     151             :     bool /* bNoFillStyle */,
     152             :     bool /* bNoLineStyle */)
     153             : {
     154           0 :     if( xEmbObj.is())
     155             :     {
     156           0 :         uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
     157             :         OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
     158           0 :         if( !xChartDoc.is())
     159           0 :             return;
     160             : 
     161             :         try
     162             :         {
     163             :             // set background to transparent (none)
     164           0 :             uno::Reference< beans::XPropertySet > xPageProp( xChartDoc->getPageBackground());
     165           0 :             if( xPageProp.is())
     166           0 :                 xPageProp->setPropertyValue( "FillStyle",
     167           0 :                                              uno::makeAny( drawing::FillStyle_NONE ));
     168             :             // set no border
     169           0 :             if( xPageProp.is())
     170           0 :                 xPageProp->setPropertyValue( "LineStyle",
     171           0 :                                              uno::makeAny( drawing::LineStyle_NONE ));
     172             :         }
     173           0 :         catch( const uno::Exception & )
     174             :         {
     175             :             OSL_FAIL( "Exception caught in AdaptDefaultsForChart" );
     176           0 :         }
     177             :     }
     178             : }
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10