1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
23*b1cdbd2cSJim Jagielski #include "precompiled_svx.hxx"
24*b1cdbd2cSJim Jagielski
25*b1cdbd2cSJim Jagielski #include <svx/charthelper.hxx>
26*b1cdbd2cSJim Jagielski #include <svtools/embedhlp.hxx>
27*b1cdbd2cSJim Jagielski #include <tools/globname.hxx>
28*b1cdbd2cSJim Jagielski #include <sot/clsids.hxx>
29*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XUnoTunnel.hpp>
30*b1cdbd2cSJim Jagielski #include <com/sun/star/util/XUpdatable.hpp>
31*b1cdbd2cSJim Jagielski #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
32*b1cdbd2cSJim Jagielski #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33*b1cdbd2cSJim Jagielski #include <comphelper/processfactory.hxx>
34*b1cdbd2cSJim Jagielski #include <com/sun/star/graphic/XPrimitiveFactory2D.hpp>
35*b1cdbd2cSJim Jagielski #include <drawinglayer/geometry/viewinformation2d.hxx>
36*b1cdbd2cSJim Jagielski #include <com/sun/star/chart2/XChartDocument.hpp>
37*b1cdbd2cSJim Jagielski #include <com/sun/star/drawing/FillStyle.hpp>
38*b1cdbd2cSJim Jagielski #include <com/sun/star/drawing/LineStyle.hpp>
39*b1cdbd2cSJim Jagielski
40*b1cdbd2cSJim Jagielski //////////////////////////////////////////////////////////////////////////////
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski using namespace ::com::sun::star;
43*b1cdbd2cSJim Jagielski
44*b1cdbd2cSJim Jagielski //////////////////////////////////////////////////////////////////////////////
45*b1cdbd2cSJim Jagielski
IsChart(const svt::EmbeddedObjectRef & xObjRef)46*b1cdbd2cSJim Jagielski bool ChartHelper::IsChart(const svt::EmbeddedObjectRef& xObjRef)
47*b1cdbd2cSJim Jagielski {
48*b1cdbd2cSJim Jagielski if(!xObjRef.is())
49*b1cdbd2cSJim Jagielski {
50*b1cdbd2cSJim Jagielski return false;
51*b1cdbd2cSJim Jagielski }
52*b1cdbd2cSJim Jagielski
53*b1cdbd2cSJim Jagielski const SvGlobalName aObjClsId(xObjRef->getClassID());
54*b1cdbd2cSJim Jagielski
55*b1cdbd2cSJim Jagielski if(SvGlobalName(SO3_SCH_CLASSID_30) == aObjClsId
56*b1cdbd2cSJim Jagielski || SvGlobalName(SO3_SCH_CLASSID_40) == aObjClsId
57*b1cdbd2cSJim Jagielski || SvGlobalName(SO3_SCH_CLASSID_50) == aObjClsId
58*b1cdbd2cSJim Jagielski || SvGlobalName(SO3_SCH_CLASSID_60) == aObjClsId)
59*b1cdbd2cSJim Jagielski {
60*b1cdbd2cSJim Jagielski return true;
61*b1cdbd2cSJim Jagielski }
62*b1cdbd2cSJim Jagielski
63*b1cdbd2cSJim Jagielski return false;
64*b1cdbd2cSJim Jagielski }
65*b1cdbd2cSJim Jagielski
tryToGetChartContentAsPrimitive2DSequence(const uno::Reference<::frame::XModel> & rXModel,basegfx::B2DRange & rRange)66*b1cdbd2cSJim Jagielski drawinglayer::primitive2d::Primitive2DSequence ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
67*b1cdbd2cSJim Jagielski const uno::Reference< ::frame::XModel >& rXModel,
68*b1cdbd2cSJim Jagielski basegfx::B2DRange& rRange)
69*b1cdbd2cSJim Jagielski {
70*b1cdbd2cSJim Jagielski drawinglayer::primitive2d::Primitive2DSequence aRetval;
71*b1cdbd2cSJim Jagielski
72*b1cdbd2cSJim Jagielski if(rXModel.is())
73*b1cdbd2cSJim Jagielski {
74*b1cdbd2cSJim Jagielski try
75*b1cdbd2cSJim Jagielski {
76*b1cdbd2cSJim Jagielski const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
77*b1cdbd2cSJim Jagielski const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance(::rtl::OUString::createFromAscii("com.sun.star.chart2.ChartView")), uno::UNO_QUERY_THROW);
78*b1cdbd2cSJim Jagielski const uno::Reference< util::XUpdatable > xUpdatable(xChartView, uno::UNO_QUERY_THROW);
79*b1cdbd2cSJim Jagielski
80*b1cdbd2cSJim Jagielski if(xUpdatable.is())
81*b1cdbd2cSJim Jagielski {
82*b1cdbd2cSJim Jagielski xUpdatable->update();
83*b1cdbd2cSJim Jagielski
84*b1cdbd2cSJim Jagielski const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
85*b1cdbd2cSJim Jagielski const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
86*b1cdbd2cSJim Jagielski
87*b1cdbd2cSJim Jagielski if(xShapeAccess.is() && xShapeAccess->getCount())
88*b1cdbd2cSJim Jagielski {
89*b1cdbd2cSJim Jagielski const sal_Int32 nShapeCount(xShapeAccess->getCount());
90*b1cdbd2cSJim Jagielski const uno::Reference< lang::XMultiServiceFactory > xMgr(::comphelper::getProcessServiceFactory());
91*b1cdbd2cSJim Jagielski const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory(
92*b1cdbd2cSJim Jagielski xMgr->createInstance(
93*b1cdbd2cSJim Jagielski String(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.graphic.PrimitiveFactory2D" ))),
94*b1cdbd2cSJim Jagielski uno::UNO_QUERY);
95*b1cdbd2cSJim Jagielski
96*b1cdbd2cSJim Jagielski if(xPrimitiveFactory.is())
97*b1cdbd2cSJim Jagielski {
98*b1cdbd2cSJim Jagielski const uno::Sequence< beans::PropertyValue > aParams;
99*b1cdbd2cSJim Jagielski uno::Reference< drawing::XShape > xShape;
100*b1cdbd2cSJim Jagielski
101*b1cdbd2cSJim Jagielski for(sal_Int32 a(0); a < nShapeCount; a++)
102*b1cdbd2cSJim Jagielski {
103*b1cdbd2cSJim Jagielski xShapeAccess->getByIndex(a) >>= xShape;
104*b1cdbd2cSJim Jagielski
105*b1cdbd2cSJim Jagielski if(xShape.is())
106*b1cdbd2cSJim Jagielski {
107*b1cdbd2cSJim Jagielski const drawinglayer::primitive2d::Primitive2DSequence aNew(
108*b1cdbd2cSJim Jagielski xPrimitiveFactory->createPrimitivesFromXShape(
109*b1cdbd2cSJim Jagielski xShape,
110*b1cdbd2cSJim Jagielski aParams));
111*b1cdbd2cSJim Jagielski
112*b1cdbd2cSJim Jagielski drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
113*b1cdbd2cSJim Jagielski aRetval,
114*b1cdbd2cSJim Jagielski aNew);
115*b1cdbd2cSJim Jagielski }
116*b1cdbd2cSJim Jagielski }
117*b1cdbd2cSJim Jagielski }
118*b1cdbd2cSJim Jagielski }
119*b1cdbd2cSJim Jagielski }
120*b1cdbd2cSJim Jagielski }
121*b1cdbd2cSJim Jagielski catch(uno::Exception&)
122*b1cdbd2cSJim Jagielski {
123*b1cdbd2cSJim Jagielski OSL_ENSURE(false, "Unexpected exception!");
124*b1cdbd2cSJim Jagielski }
125*b1cdbd2cSJim Jagielski
126*b1cdbd2cSJim Jagielski if(aRetval.hasElements())
127*b1cdbd2cSJim Jagielski {
128*b1cdbd2cSJim Jagielski const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
129*b1cdbd2cSJim Jagielski
130*b1cdbd2cSJim Jagielski rRange = drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval, aViewInformation2D);
131*b1cdbd2cSJim Jagielski }
132*b1cdbd2cSJim Jagielski }
133*b1cdbd2cSJim Jagielski
134*b1cdbd2cSJim Jagielski return aRetval;
135*b1cdbd2cSJim Jagielski }
136*b1cdbd2cSJim Jagielski
AdaptDefaultsForChart(const uno::Reference<embed::XEmbeddedObject> & xEmbObj,bool,bool)137*b1cdbd2cSJim Jagielski void ChartHelper::AdaptDefaultsForChart(
138*b1cdbd2cSJim Jagielski const uno::Reference < embed::XEmbeddedObject > & xEmbObj,
139*b1cdbd2cSJim Jagielski bool /* bNoFillStyle */,
140*b1cdbd2cSJim Jagielski bool /* bNoLineStyle */)
141*b1cdbd2cSJim Jagielski {
142*b1cdbd2cSJim Jagielski if( xEmbObj.is())
143*b1cdbd2cSJim Jagielski {
144*b1cdbd2cSJim Jagielski uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
145*b1cdbd2cSJim Jagielski OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
146*b1cdbd2cSJim Jagielski if( !xChartDoc.is())
147*b1cdbd2cSJim Jagielski return;
148*b1cdbd2cSJim Jagielski
149*b1cdbd2cSJim Jagielski try
150*b1cdbd2cSJim Jagielski {
151*b1cdbd2cSJim Jagielski // set background to transparent (none)
152*b1cdbd2cSJim Jagielski uno::Reference< beans::XPropertySet > xPageProp( xChartDoc->getPageBackground());
153*b1cdbd2cSJim Jagielski if( xPageProp.is())
154*b1cdbd2cSJim Jagielski xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FillStyle")),
155*b1cdbd2cSJim Jagielski uno::makeAny( drawing::FillStyle_NONE ));
156*b1cdbd2cSJim Jagielski // set no border
157*b1cdbd2cSJim Jagielski if( xPageProp.is())
158*b1cdbd2cSJim Jagielski xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LineStyle")),
159*b1cdbd2cSJim Jagielski uno::makeAny( drawing::LineStyle_NONE ));
160*b1cdbd2cSJim Jagielski }
161*b1cdbd2cSJim Jagielski catch( const uno::Exception & )
162*b1cdbd2cSJim Jagielski {
163*b1cdbd2cSJim Jagielski OSL_ENSURE( false, "Exception caught in AdaptDefaultsForChart" );
164*b1cdbd2cSJim Jagielski }
165*b1cdbd2cSJim Jagielski }
166*b1cdbd2cSJim Jagielski }
167*b1cdbd2cSJim Jagielski
168*b1cdbd2cSJim Jagielski //////////////////////////////////////////////////////////////////////////////
169*b1cdbd2cSJim Jagielski // eof
170