xref: /aoo42x/main/svx/source/svdraw/charthelper.cxx (revision e147e5f6)
178d93489SArmin Le Grand /**************************************************************
2*e147e5f6Smseidel  *
378d93489SArmin Le Grand  * Licensed to the Apache Software Foundation (ASF) under one
478d93489SArmin Le Grand  * or more contributor license agreements.  See the NOTICE file
578d93489SArmin Le Grand  * distributed with this work for additional information
678d93489SArmin Le Grand  * regarding copyright ownership.  The ASF licenses this file
778d93489SArmin Le Grand  * to you under the Apache License, Version 2.0 (the
878d93489SArmin Le Grand  * "License"); you may not use this file except in compliance
978d93489SArmin Le Grand  * with the License.  You may obtain a copy of the License at
10*e147e5f6Smseidel  *
1178d93489SArmin Le Grand  *   http://www.apache.org/licenses/LICENSE-2.0
12*e147e5f6Smseidel  *
1378d93489SArmin Le Grand  * Unless required by applicable law or agreed to in writing,
1478d93489SArmin Le Grand  * software distributed under the License is distributed on an
1578d93489SArmin Le Grand  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1678d93489SArmin Le Grand  * KIND, either express or implied.  See the License for the
1778d93489SArmin Le Grand  * specific language governing permissions and limitations
1878d93489SArmin Le Grand  * under the License.
19*e147e5f6Smseidel  *
2078d93489SArmin Le Grand  *************************************************************/
2178d93489SArmin Le Grand 
22*e147e5f6Smseidel 
23*e147e5f6Smseidel 
2478d93489SArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove
2578d93489SArmin Le Grand #include "precompiled_svx.hxx"
2678d93489SArmin Le Grand 
2778d93489SArmin Le Grand #include <svx/charthelper.hxx>
2878d93489SArmin Le Grand #include <svtools/embedhlp.hxx>
2978d93489SArmin Le Grand #include <tools/globname.hxx>
3078d93489SArmin Le Grand #include <sot/clsids.hxx>
3178d93489SArmin Le Grand #include <com/sun/star/lang/XUnoTunnel.hpp>
3278d93489SArmin Le Grand #include <com/sun/star/util/XUpdatable.hpp>
3378d93489SArmin Le Grand #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
3478d93489SArmin Le Grand #include <com/sun/star/lang/XMultiServiceFactory.hpp>
3578d93489SArmin Le Grand #include <comphelper/processfactory.hxx>
3678d93489SArmin Le Grand #include <com/sun/star/graphic/XPrimitiveFactory2D.hpp>
3778d93489SArmin Le Grand #include <drawinglayer/geometry/viewinformation2d.hxx>
386f0b96b4SArmin Le Grand #include <com/sun/star/chart2/XChartDocument.hpp>
396f0b96b4SArmin Le Grand #include <com/sun/star/drawing/FillStyle.hpp>
406f0b96b4SArmin Le Grand #include <com/sun/star/drawing/LineStyle.hpp>
4178d93489SArmin Le Grand 
4278d93489SArmin Le Grand 
4378d93489SArmin Le Grand using namespace ::com::sun::star;
4478d93489SArmin Le Grand 
4578d93489SArmin Le Grand 
IsChart(const svt::EmbeddedObjectRef & xObjRef)4678d93489SArmin Le Grand bool ChartHelper::IsChart(const svt::EmbeddedObjectRef& xObjRef)
4778d93489SArmin Le Grand {
48*e147e5f6Smseidel 	if(!xObjRef.is())
49*e147e5f6Smseidel 	{
50*e147e5f6Smseidel 		return false;
51*e147e5f6Smseidel 	}
52*e147e5f6Smseidel 
53*e147e5f6Smseidel 	const SvGlobalName aObjClsId(xObjRef->getClassID());
54*e147e5f6Smseidel 
55*e147e5f6Smseidel 	if(SvGlobalName(SO3_SCH_CLASSID_30) == aObjClsId
56*e147e5f6Smseidel 		|| SvGlobalName(SO3_SCH_CLASSID_40) == aObjClsId
57*e147e5f6Smseidel 		|| SvGlobalName(SO3_SCH_CLASSID_50) == aObjClsId
58*e147e5f6Smseidel 		|| SvGlobalName(SO3_SCH_CLASSID_60) == aObjClsId)
59*e147e5f6Smseidel 	{
60*e147e5f6Smseidel 		return true;
61*e147e5f6Smseidel 	}
62*e147e5f6Smseidel 
63*e147e5f6Smseidel 	return false;
6478d93489SArmin Le Grand }
6578d93489SArmin Le Grand 
tryToGetChartContentAsPrimitive2DSequence(const uno::Reference<::frame::XModel> & rXModel,basegfx::B2DRange & rRange)6678d93489SArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence ChartHelper::tryToGetChartContentAsPrimitive2DSequence(
67*e147e5f6Smseidel 	const uno::Reference< ::frame::XModel >& rXModel,
68*e147e5f6Smseidel 	basegfx::B2DRange& rRange)
6978d93489SArmin Le Grand {
70*e147e5f6Smseidel 	drawinglayer::primitive2d::Primitive2DSequence aRetval;
71*e147e5f6Smseidel 
72*e147e5f6Smseidel 	if(rXModel.is())
73*e147e5f6Smseidel 	{
74*e147e5f6Smseidel 		try
75*e147e5f6Smseidel 		{
76*e147e5f6Smseidel 			const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW);
77*e147e5f6Smseidel 			const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance(::rtl::OUString::createFromAscii("com.sun.star.chart2.ChartView")), uno::UNO_QUERY_THROW);
78*e147e5f6Smseidel 			const uno::Reference< util::XUpdatable > xUpdatable(xChartView, uno::UNO_QUERY_THROW);
79*e147e5f6Smseidel 
80*e147e5f6Smseidel 			if(xUpdatable.is())
81*e147e5f6Smseidel 			{
82*e147e5f6Smseidel 				xUpdatable->update();
83*e147e5f6Smseidel 
84*e147e5f6Smseidel 				const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW);
85*e147e5f6Smseidel 				const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW);
86*e147e5f6Smseidel 
87*e147e5f6Smseidel 				if(xShapeAccess.is() && xShapeAccess->getCount())
88*e147e5f6Smseidel 				{
89*e147e5f6Smseidel 					const sal_Int32 nShapeCount(xShapeAccess->getCount());
90*e147e5f6Smseidel 					const uno::Reference< lang::XMultiServiceFactory > xMgr(::comphelper::getProcessServiceFactory());
91*e147e5f6Smseidel 					const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory(
92*e147e5f6Smseidel 						xMgr->createInstance(
93*e147e5f6Smseidel 							String(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.graphic.PrimitiveFactory2D" ))),
94*e147e5f6Smseidel 							uno::UNO_QUERY);
95*e147e5f6Smseidel 
96*e147e5f6Smseidel 					if(xPrimitiveFactory.is())
97*e147e5f6Smseidel 					{
98*e147e5f6Smseidel 						const uno::Sequence< beans::PropertyValue > aParams;
99*e147e5f6Smseidel 						uno::Reference< drawing::XShape > xShape;
100*e147e5f6Smseidel 
101*e147e5f6Smseidel 						for(sal_Int32 a(0); a < nShapeCount; a++)
102*e147e5f6Smseidel 						{
103*e147e5f6Smseidel 							xShapeAccess->getByIndex(a) >>= xShape;
104*e147e5f6Smseidel 
105*e147e5f6Smseidel 							if(xShape.is())
106*e147e5f6Smseidel 							{
107*e147e5f6Smseidel 								const drawinglayer::primitive2d::Primitive2DSequence aNew(
108*e147e5f6Smseidel 									xPrimitiveFactory->createPrimitivesFromXShape(
109*e147e5f6Smseidel 										xShape,
110*e147e5f6Smseidel 										aParams));
111*e147e5f6Smseidel 
112*e147e5f6Smseidel 								drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(
113*e147e5f6Smseidel 									aRetval,
114*e147e5f6Smseidel 									aNew);
115*e147e5f6Smseidel 							}
116*e147e5f6Smseidel 						}
117*e147e5f6Smseidel 					}
118*e147e5f6Smseidel 				}
119*e147e5f6Smseidel 			}
120*e147e5f6Smseidel 		}
121*e147e5f6Smseidel 		catch(uno::Exception&)
122*e147e5f6Smseidel 		{
123*e147e5f6Smseidel 			OSL_ENSURE(false, "Unexpected exception!");
124*e147e5f6Smseidel 		}
125*e147e5f6Smseidel 
126*e147e5f6Smseidel 		if(aRetval.hasElements())
127*e147e5f6Smseidel 		{
128*e147e5f6Smseidel 			const drawinglayer::geometry::ViewInformation2D aViewInformation2D;
129*e147e5f6Smseidel 
130*e147e5f6Smseidel 			rRange = drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval, aViewInformation2D);
131*e147e5f6Smseidel 		}
132*e147e5f6Smseidel 	}
133*e147e5f6Smseidel 
134*e147e5f6Smseidel 	return aRetval;
13578d93489SArmin Le Grand }
13678d93489SArmin Le Grand 
AdaptDefaultsForChart(const uno::Reference<embed::XEmbeddedObject> & xEmbObj,bool,bool)1376f0b96b4SArmin Le Grand void ChartHelper::AdaptDefaultsForChart(
138*e147e5f6Smseidel 	const uno::Reference < embed::XEmbeddedObject > & xEmbObj,
139*e147e5f6Smseidel 	bool /* bNoFillStyle */,
140*e147e5f6Smseidel 	bool /* bNoLineStyle */)
1416f0b96b4SArmin Le Grand {
142*e147e5f6Smseidel 	if( xEmbObj.is())
143*e147e5f6Smseidel 	{
144*e147e5f6Smseidel 		uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
145*e147e5f6Smseidel 		OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
146*e147e5f6Smseidel 		if( !xChartDoc.is())
147*e147e5f6Smseidel 			return;
148*e147e5f6Smseidel 
149*e147e5f6Smseidel 		try
150*e147e5f6Smseidel 		{
151*e147e5f6Smseidel 			// set background to transparent (none)
152*e147e5f6Smseidel 			uno::Reference< beans::XPropertySet > xPageProp( xChartDoc->getPageBackground());
153*e147e5f6Smseidel 			if( xPageProp.is())
154*e147e5f6Smseidel 				xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FillStyle")),
155*e147e5f6Smseidel 											 uno::makeAny( drawing::FillStyle_NONE ));
156*e147e5f6Smseidel 			// set no border
157*e147e5f6Smseidel 			if( xPageProp.is())
158*e147e5f6Smseidel 				xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LineStyle")),
159*e147e5f6Smseidel 											 uno::makeAny( drawing::LineStyle_NONE ));
160*e147e5f6Smseidel 		}
161*e147e5f6Smseidel 		catch( const uno::Exception & )
162*e147e5f6Smseidel 		{
163*e147e5f6Smseidel 			OSL_ENSURE( false, "Exception caught in AdaptDefaultsForChart" );
164*e147e5f6Smseidel 		}
165*e147e5f6Smseidel 	}
1666f0b96b4SArmin Le Grand }
1676f0b96b4SArmin Le Grand 
168*e147e5f6Smseidel /* vim: set noet sw=4 ts=4: */
169