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/diagnose_ex.h>
22 #include <com/sun/star/embed/XEmbeddedObject.hpp>
23 #include <com/sun/star/lang/XUnoTunnel.hpp>
24 #include <com/sun/star/util/XUpdatable2.hpp>
25 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/chart2/XChartDocument.hpp>
29 #include <com/sun/star/drawing/FillStyle.hpp>
30 #include <com/sun/star/drawing/LineStyle.hpp>
32 
33 using namespace ::com::sun::star;
34 
35 void ChartHelper::updateChart( const uno::Reference< ::frame::XModel >& rXModel )
36 {
37  if (!rXModel.is())
38  return;
39 
40  try
41  {
42  const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
43  const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance("com.sun.star.chart2.ChartView"), uno::UNO_QUERY_THROW);
44  const uno::Reference<util::XUpdatable2> xUpdatable(xChartView, uno::UNO_QUERY_THROW);
45 
46  xUpdatable->updateHard();
47  }
48  catch(uno::Exception&)
49  {
50  OSL_ENSURE(false, "Unexpected exception!");
51  }
52 }
53 
55  const uno::Reference< ::frame::XModel >& rXModel,
56  basegfx::B2DRange& rRange)
57 {
59 
60  if (!rXModel.is())
61  return aRetval;
62 
63  // don't broadcast until we're finished building, more efficient
64  rXModel->lockControllers();
65  updateChart(rXModel);
66  rXModel->unlockControllers();
67 
68  try
69  {
70  const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
71  const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
72 
73  if(xShapeAccess->getCount())
74  {
75  const sal_Int32 nShapeCount(xShapeAccess->getCount());
76  const uno::Sequence< beans::PropertyValue > aParams;
77  uno::Reference< drawing::XShape > xShape;
78 
79  for(sal_Int32 a(0); a < nShapeCount; a++)
80  {
81  xShapeAccess->getByIndex(a) >>= xShape;
82 
83  if(xShape.is())
84  {
86  xShape,
87  aParams,
88  aRetval);
89  }
90  }
91  }
92  }
93  catch(uno::Exception&)
94  {
95  OSL_ENSURE(false, "Unexpected exception!");
96  }
97 
98  if(!aRetval.empty())
99  {
100  const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
101 
102  rRange = aRetval.getB2DRange(aViewInformation2D);
103  }
104 
105  return aRetval;
106 }
107 
109  const uno::Reference < embed::XEmbeddedObject > & xEmbObj)
110 {
111  if( !xEmbObj.is())
112  return;
113 
114  uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
115  OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
116  if( !xChartDoc.is())
117  return;
118 
119  try
120  {
121  if (uno::Reference< beans::XPropertySet > xPageProp = xChartDoc->getPageBackground())
122  {
123  // set background to transparent (none)
124  xPageProp->setPropertyValue("FillStyle", uno::Any(drawing::FillStyle_NONE));
125  // set no border
126  xPageProp->setPropertyValue("LineStyle", uno::Any(drawing::LineStyle_NONE));
127  }
128  }
129  catch( const uno::Exception & )
130  {
131  TOOLS_WARN_EXCEPTION("svx.svdraw", "");
132  }
133 }
134 
135 /* 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:54
#define TOOLS_WARN_EXCEPTION(area, stream)
uno_Any a
static void AdaptDefaultsForChart(const css::uno::Reference< css::embed::XEmbeddedObject > &xEmbObj)
virtual css::uno::Sequence< css::uno::Reference< css::graphic::XPrimitive2D > > SAL_CALL createPrimitivesFromXShape(const css::uno::Reference< css::drawing::XShape > &xShape, const css::uno::Sequence< css::beans::PropertyValue > &aParms) override
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:35