LibreOffice Module svx (master)  1
charthelper.cxx
Go to the documentation of this file.
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/XUpdatable2.hpp>
28 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
29 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/graphic/PrimitiveFactory2D.hpp>
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 void ChartHelper::updateChart( const uno::Reference< ::frame::XModel >& rXModel )
40 {
41  if (!rXModel.is())
42  return;
43 
44  try
45  {
46  const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
47  const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance("com.sun.star.chart2.ChartView"), uno::UNO_QUERY_THROW);
48  const uno::Reference<util::XUpdatable2> xUpdatable(xChartView, uno::UNO_QUERY_THROW);
49 
50  xUpdatable->updateHard();
51  }
52  catch(uno::Exception&)
53  {
54  OSL_ENSURE(false, "Unexpected exception!");
55  }
56 }
57 
59  const uno::Reference< ::frame::XModel >& rXModel,
60  basegfx::B2DRange& rRange)
61 {
63 
64  if (!rXModel.is())
65  return aRetval;
66 
67  updateChart(rXModel);
68 
69  try
70  {
71  const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
72  const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
73 
74  if(xShapeAccess->getCount())
75  {
76  const sal_Int32 nShapeCount(xShapeAccess->getCount());
77  const uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
78  const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory =
79  graphic::PrimitiveFactory2D::create( xContext );
80 
81  const uno::Sequence< beans::PropertyValue > aParams;
82  uno::Reference< drawing::XShape > xShape;
83 
84  for(sal_Int32 a(0); a < nShapeCount; a++)
85  {
86  xShapeAccess->getByIndex(a) >>= xShape;
87 
88  if(xShape.is())
89  {
91  xPrimitiveFactory->createPrimitivesFromXShape(
92  xShape,
93  aParams));
94 
95  aRetval.append(aNew);
96  }
97  }
98  }
99  }
100  catch(uno::Exception&)
101  {
102  OSL_ENSURE(false, "Unexpected exception!");
103  }
104 
105  if(!aRetval.empty())
106  {
107  const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
108 
109  rRange = aRetval.getB2DRange(aViewInformation2D);
110  }
111 
112  return aRetval;
113 }
114 
116  const uno::Reference < embed::XEmbeddedObject > & xEmbObj)
117 {
118  if( xEmbObj.is())
119  {
120  uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
121  OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
122  if( !xChartDoc.is())
123  return;
124 
125  try
126  {
127  if (uno::Reference< beans::XPropertySet > xPageProp = xChartDoc->getPageBackground())
128  {
129  // set background to transparent (none)
130  xPageProp->setPropertyValue("FillStyle", uno::makeAny(drawing::FillStyle_NONE));
131  // set no border
132  xPageProp->setPropertyValue("LineStyle", uno::makeAny(drawing::LineStyle_NONE));
133  }
134  }
135  catch( const uno::Exception & )
136  {
137  OSL_FAIL( "Exception caught in AdaptDefaultsForChart" );
138  }
139  }
140 }
141 
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static drawinglayer::primitive2d::Primitive2DContainer tryToGetChartContentAsPrimitive2DSequence(const css::uno::Reference< css::frame::XModel > &rXModel, basegfx::B2DRange &rRange)
Definition: charthelper.cxx:58
css::uno::Sequence< Primitive2DReference > Primitive2DSequence
uno_Any a
static void AdaptDefaultsForChart(const css::uno::Reference< css::embed::XEmbeddedObject > &xEmbObj)
virtual void append(const Primitive2DReference &) override
Reference< XComponentContext > getProcessComponentContext()
basegfx::B2DRange getB2DRange(const geometry::ViewInformation2D &aViewInformation) const
static void updateChart(const css::uno::Reference< css::frame::XModel > &rXModel)
Use chart's XUpdatable::update() to update values.
Definition: charthelper.cxx:39