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 0 : bool ChartHelper::IsChart(const svt::EmbeddedObjectRef& xObjRef)
39 : {
40 0 : if(!xObjRef.is())
41 : {
42 0 : return false;
43 : }
44 :
45 0 : const SvGlobalName aObjClsId(xObjRef->getClassID());
46 :
47 0 : if(SvGlobalName(SO3_SCH_CLASSID_30) == aObjClsId
48 0 : || SvGlobalName(SO3_SCH_CLASSID_40) == aObjClsId
49 0 : || SvGlobalName(SO3_SCH_CLASSID_50) == aObjClsId
50 0 : || SvGlobalName(SO3_SCH_CLASSID_60) == aObjClsId)
51 : {
52 0 : return true;
53 : }
54 :
55 0 : return false;
56 : }
57 :
58 0 : drawinglayer::primitive2d::Primitive2DSequence ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
59 : const uno::Reference< ::frame::XModel >& rXModel,
60 : basegfx::B2DRange& rRange)
61 : {
62 0 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
63 :
64 0 : if(rXModel.is())
65 : {
66 : try
67 : {
68 0 : const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
69 0 : const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance("com.sun.star.chart2.ChartView"), uno::UNO_QUERY_THROW);
70 0 : const uno::Reference< util::XUpdatable > xUpdatable(xChartView, uno::UNO_QUERY_THROW);
71 :
72 0 : if(xUpdatable.is())
73 : {
74 0 : xUpdatable->update();
75 :
76 0 : const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
77 0 : const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
78 :
79 0 : if(xShapeAccess.is() && xShapeAccess->getCount())
80 : {
81 0 : const sal_Int32 nShapeCount(xShapeAccess->getCount());
82 0 : const uno::Reference< uno::XComponentContext > xContext(::comphelper::getProcessComponentContext());
83 : const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory =
84 0 : graphic::PrimitiveFactory2D::create( xContext );
85 :
86 0 : const uno::Sequence< beans::PropertyValue > aParams;
87 0 : uno::Reference< drawing::XShape > xShape;
88 :
89 0 : for(sal_Int32 a(0); a < nShapeCount; a++)
90 : {
91 0 : xShapeAccess->getByIndex(a) >>= xShape;
92 :
93 0 : if(xShape.is())
94 : {
95 : const drawinglayer::primitive2d::Primitive2DSequence aNew(
96 0 : xPrimitiveFactory->createPrimitivesFromXShape(
97 : xShape,
98 0 : aParams));
99 :
100 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
101 : aRetval,
102 0 : aNew);
103 : }
104 0 : }
105 0 : }
106 0 : }
107 : }
108 0 : catch(uno::Exception&)
109 : {
110 : OSL_ENSURE(false, "Unexpected exception!");
111 : }
112 :
113 0 : if(aRetval.hasElements())
114 : {
115 0 : const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
116 :
117 0 : rRange = drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval, aViewInformation2D);
118 : }
119 : }
120 :
121 0 : 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: */
|