LCOV - code coverage report
Current view: top level - svx/source/svdraw - charthelper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 40 54 74.1 %
Date: 2014-04-11 Functions: 2 3 66.7 %
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 <svtools/embedhlp.hxx>
      22             : #include <tools/globname.hxx>
      23             : #include <comphelper/classids.hxx>
      24             : #include <com/sun/star/embed/XEmbeddedObject.hpp>
      25             : #include <com/sun/star/lang/XUnoTunnel.hpp>
      26             : #include <com/sun/star/util/XUpdatable.hpp>
      27             : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
      28             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29             : #include <comphelper/processfactory.hxx>
      30             : #include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
      31             : #include <drawinglayer/geometry/viewinformation2d.hxx>
      32             : #include <com/sun/star/chart2/XChartDocument.hpp>
      33             : #include <com/sun/star/drawing/FillStyle.hpp>
      34             : #include <com/sun/star/drawing/LineStyle.hpp>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38         243 : bool ChartHelper::IsChart(const svt::EmbeddedObjectRef& xObjRef)
      39             : {
      40         243 :     if(!xObjRef.is())
      41             :     {
      42          64 :         return false;
      43             :     }
      44             : 
      45         179 :     const SvGlobalName aObjClsId(xObjRef->getClassID());
      46             : 
      47         716 :     if(SvGlobalName(SO3_SCH_CLASSID_30) == aObjClsId
      48         358 :         || SvGlobalName(SO3_SCH_CLASSID_40) == aObjClsId
      49         358 :         || SvGlobalName(SO3_SCH_CLASSID_50) == aObjClsId
      50         895 :         || SvGlobalName(SO3_SCH_CLASSID_60) == aObjClsId)
      51             :     {
      52         135 :         return true;
      53             :     }
      54             : 
      55          44 :     return false;
      56             : }
      57             : 
      58         138 : drawinglayer::primitive2d::Primitive2DSequence ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
      59             :     const uno::Reference< ::frame::XModel >& rXModel,
      60             :     basegfx::B2DRange& rRange)
      61             : {
      62         138 :     drawinglayer::primitive2d::Primitive2DSequence aRetval;
      63             : 
      64         138 :     if(rXModel.is())
      65             :     {
      66             :         try
      67             :         {
      68         138 :             const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
      69         276 :             const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance("com.sun.star.chart2.ChartView"), uno::UNO_QUERY_THROW);
      70         276 :             const uno::Reference< util::XUpdatable > xUpdatable(xChartView, uno::UNO_QUERY_THROW);
      71             : 
      72         138 :             if(xUpdatable.is())
      73             :             {
      74         138 :                 xUpdatable->update();
      75             : 
      76         138 :                 const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
      77         276 :                 const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
      78             : 
      79         138 :                 if(xShapeAccess.is() && xShapeAccess->getCount())
      80             :                 {
      81         138 :                     const sal_Int32 nShapeCount(xShapeAccess->getCount());
      82         138 :                     const uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
      83             :                     const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory =
      84         274 :                         graphic::PrimitiveFactory2D::create( xContext );
      85             : 
      86         272 :                     const uno::Sequence< beans::PropertyValue > aParams;
      87         272 :                     uno::Reference< drawing::XShape > xShape;
      88             : 
      89         272 :                     for(sal_Int32 a(0); a < nShapeCount; a++)
      90             :                     {
      91         136 :                         xShapeAccess->getByIndex(a) >>= xShape;
      92             : 
      93         136 :                         if(xShape.is())
      94             :                         {
      95             :                             const drawinglayer::primitive2d::Primitive2DSequence aNew(
      96         136 :                                 xPrimitiveFactory->createPrimitivesFromXShape(
      97             :                                     xShape,
      98         136 :                                     aParams));
      99             : 
     100             :                             drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
     101             :                                 aRetval,
     102         136 :                                 aNew);
     103             :                         }
     104         138 :                     }
     105         138 :                 }
     106         138 :             }
     107             :         }
     108           2 :         catch(uno::Exception&)
     109             :         {
     110             :             OSL_ENSURE(false, "Unexpected exception!");
     111             :         }
     112             : 
     113         138 :         if(aRetval.hasElements())
     114             :         {
     115         136 :             const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
     116             : 
     117         136 :             rRange = drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval, aViewInformation2D);
     118             :         }
     119             :     }
     120             : 
     121         138 :     return aRetval;
     122             : }
     123             : 
     124           0 : void ChartHelper::AdaptDefaultsForChart(
     125             :     const uno::Reference < embed::XEmbeddedObject > & xEmbObj,
     126             :     bool /* bNoFillStyle */,
     127             :     bool /* bNoLineStyle */)
     128             : {
     129           0 :     if( xEmbObj.is())
     130             :     {
     131           0 :         uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
     132             :         OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
     133           0 :         if( !xChartDoc.is())
     134           0 :             return;
     135             : 
     136             :         try
     137             :         {
     138             :             // set background to transparent (none)
     139           0 :             uno::Reference< beans::XPropertySet > xPageProp( xChartDoc->getPageBackground());
     140           0 :             if( xPageProp.is())
     141           0 :                 xPageProp->setPropertyValue( "FillStyle",
     142           0 :                                              uno::makeAny( drawing::FillStyle_NONE ));
     143             :             // set no border
     144           0 :             if( xPageProp.is())
     145           0 :                 xPageProp->setPropertyValue( "LineStyle",
     146           0 :                                              uno::makeAny( drawing::LineStyle_NONE ));
     147             :         }
     148           0 :         catch( const uno::Exception & )
     149             :         {
     150             :             OSL_FAIL( "Exception caught in AdaptDefaultsForChart" );
     151           0 :         }
     152             :     }
     153             : }
     154             : 
     155             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10