178d93489SArmin Le Grand /************************************************************** 278d93489SArmin Le Grand * 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 1078d93489SArmin Le Grand * 1178d93489SArmin Le Grand * http://www.apache.org/licenses/LICENSE-2.0 1278d93489SArmin Le Grand * 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. 1978d93489SArmin Le Grand * 2078d93489SArmin Le Grand *************************************************************/ 2178d93489SArmin Le Grand 2278d93489SArmin Le Grand // MARKER(update_precomp.py): autogen include statement, do not remove 2378d93489SArmin Le Grand #include "precompiled_svx.hxx" 2478d93489SArmin Le Grand 2578d93489SArmin Le Grand #include <svx/charthelper.hxx> 2678d93489SArmin Le Grand #include <svtools/embedhlp.hxx> 2778d93489SArmin Le Grand #include <tools/globname.hxx> 2878d93489SArmin Le Grand #include <sot/clsids.hxx> 2978d93489SArmin Le Grand #include <com/sun/star/lang/XUnoTunnel.hpp> 3078d93489SArmin Le Grand #include <com/sun/star/util/XUpdatable.hpp> 3178d93489SArmin Le Grand #include <com/sun/star/drawing/XDrawPageSupplier.hpp> 3278d93489SArmin Le Grand #include <com/sun/star/lang/XMultiServiceFactory.hpp> 3378d93489SArmin Le Grand #include <comphelper/processfactory.hxx> 3478d93489SArmin Le Grand #include <com/sun/star/graphic/XPrimitiveFactory2D.hpp> 3578d93489SArmin Le Grand #include <drawinglayer/geometry/viewinformation2d.hxx> 36*6f0b96b4SArmin Le Grand #include <com/sun/star/chart2/XChartDocument.hpp> 37*6f0b96b4SArmin Le Grand #include <com/sun/star/drawing/FillStyle.hpp> 38*6f0b96b4SArmin Le Grand #include <com/sun/star/drawing/LineStyle.hpp> 3978d93489SArmin Le Grand 4078d93489SArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 4178d93489SArmin Le Grand 4278d93489SArmin Le Grand using namespace ::com::sun::star; 4378d93489SArmin Le Grand 4478d93489SArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 4578d93489SArmin Le Grand 4678d93489SArmin Le Grand bool ChartHelper::IsChart(const svt::EmbeddedObjectRef& xObjRef) 4778d93489SArmin Le Grand { 4878d93489SArmin Le Grand if(!xObjRef.is()) 4978d93489SArmin Le Grand { 5078d93489SArmin Le Grand return false; 5178d93489SArmin Le Grand } 5278d93489SArmin Le Grand 5378d93489SArmin Le Grand const SvGlobalName aObjClsId(xObjRef->getClassID()); 5478d93489SArmin Le Grand 5578d93489SArmin Le Grand if(SvGlobalName(SO3_SCH_CLASSID_30) == aObjClsId 5678d93489SArmin Le Grand || SvGlobalName(SO3_SCH_CLASSID_40) == aObjClsId 5778d93489SArmin Le Grand || SvGlobalName(SO3_SCH_CLASSID_50) == aObjClsId 5878d93489SArmin Le Grand || SvGlobalName(SO3_SCH_CLASSID_60) == aObjClsId) 5978d93489SArmin Le Grand { 6078d93489SArmin Le Grand return true; 6178d93489SArmin Le Grand } 6278d93489SArmin Le Grand 6378d93489SArmin Le Grand return false; 6478d93489SArmin Le Grand } 6578d93489SArmin Le Grand 6678d93489SArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence ChartHelper::tryToGetChartContentAsPrimitive2DSequence( 6778d93489SArmin Le Grand const uno::Reference< ::frame::XModel >& rXModel, 6878d93489SArmin Le Grand basegfx::B2DRange& rRange) 6978d93489SArmin Le Grand { 7078d93489SArmin Le Grand drawinglayer::primitive2d::Primitive2DSequence aRetval; 7178d93489SArmin Le Grand 7278d93489SArmin Le Grand if(rXModel.is()) 7378d93489SArmin Le Grand { 7478d93489SArmin Le Grand try 7578d93489SArmin Le Grand { 7678d93489SArmin Le Grand const uno::Reference< lang::XMultiServiceFactory > xChartFact(rXModel, uno::UNO_QUERY_THROW); 7778d93489SArmin Le Grand const uno::Reference< lang::XUnoTunnel > xChartView(xChartFact->createInstance(::rtl::OUString::createFromAscii("com.sun.star.chart2.ChartView")), uno::UNO_QUERY_THROW); 7878d93489SArmin Le Grand const uno::Reference< util::XUpdatable > xUpdatable(xChartView, uno::UNO_QUERY_THROW); 7978d93489SArmin Le Grand 8078d93489SArmin Le Grand if(xUpdatable.is()) 8178d93489SArmin Le Grand { 8278d93489SArmin Le Grand xUpdatable->update(); 8378d93489SArmin Le Grand 8478d93489SArmin Le Grand const uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier(rXModel, uno::UNO_QUERY_THROW); 8578d93489SArmin Le Grand const uno::Reference< container::XIndexAccess > xShapeAccess(xDrawPageSupplier->getDrawPage(), uno::UNO_QUERY_THROW); 8678d93489SArmin Le Grand 8778d93489SArmin Le Grand if(xShapeAccess.is() && xShapeAccess->getCount()) 8878d93489SArmin Le Grand { 8978d93489SArmin Le Grand const sal_Int32 nShapeCount(xShapeAccess->getCount()); 9078d93489SArmin Le Grand const uno::Reference< lang::XMultiServiceFactory > xMgr(::comphelper::getProcessServiceFactory()); 9178d93489SArmin Le Grand const uno::Reference< graphic::XPrimitiveFactory2D > xPrimitiveFactory( 9278d93489SArmin Le Grand xMgr->createInstance( 9378d93489SArmin Le Grand String(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.graphic.PrimitiveFactory2D" ))), 9478d93489SArmin Le Grand uno::UNO_QUERY); 9578d93489SArmin Le Grand 9678d93489SArmin Le Grand if(xPrimitiveFactory.is()) 9778d93489SArmin Le Grand { 9878d93489SArmin Le Grand const uno::Sequence< beans::PropertyValue > aParams; 9978d93489SArmin Le Grand uno::Reference< drawing::XShape > xShape; 10078d93489SArmin Le Grand 10178d93489SArmin Le Grand for(sal_Int32 a(0); a < nShapeCount; a++) 10278d93489SArmin Le Grand { 10378d93489SArmin Le Grand xShapeAccess->getByIndex(a) >>= xShape; 10478d93489SArmin Le Grand 10578d93489SArmin Le Grand if(xShape.is()) 10678d93489SArmin Le Grand { 10778d93489SArmin Le Grand const drawinglayer::primitive2d::Primitive2DSequence aNew( 10878d93489SArmin Le Grand xPrimitiveFactory->createPrimitivesFromXShape( 10978d93489SArmin Le Grand xShape, 11078d93489SArmin Le Grand aParams)); 11178d93489SArmin Le Grand 11278d93489SArmin Le Grand drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence( 11378d93489SArmin Le Grand aRetval, 11478d93489SArmin Le Grand aNew); 11578d93489SArmin Le Grand } 11678d93489SArmin Le Grand } 11778d93489SArmin Le Grand } 11878d93489SArmin Le Grand } 11978d93489SArmin Le Grand } 12078d93489SArmin Le Grand } 12178d93489SArmin Le Grand catch(uno::Exception&) 12278d93489SArmin Le Grand { 12378d93489SArmin Le Grand OSL_ENSURE(false, "Unexpected exception!"); 12478d93489SArmin Le Grand } 12578d93489SArmin Le Grand 12678d93489SArmin Le Grand if(aRetval.hasElements()) 12778d93489SArmin Le Grand { 12878d93489SArmin Le Grand const drawinglayer::geometry::ViewInformation2D aViewInformation2D; 12978d93489SArmin Le Grand 13078d93489SArmin Le Grand rRange = drawinglayer::primitive2d::getB2DRangeFromPrimitive2DSequence(aRetval, aViewInformation2D); 13178d93489SArmin Le Grand } 13278d93489SArmin Le Grand } 13378d93489SArmin Le Grand 13478d93489SArmin Le Grand return aRetval; 13578d93489SArmin Le Grand } 13678d93489SArmin Le Grand 137*6f0b96b4SArmin Le Grand void ChartHelper::AdaptDefaultsForChart( 138*6f0b96b4SArmin Le Grand const uno::Reference < embed::XEmbeddedObject > & xEmbObj, 139*6f0b96b4SArmin Le Grand bool bNoFillStyle, 140*6f0b96b4SArmin Le Grand bool bNoLineStyle) 141*6f0b96b4SArmin Le Grand { 142*6f0b96b4SArmin Le Grand if( xEmbObj.is()) 143*6f0b96b4SArmin Le Grand { 144*6f0b96b4SArmin Le Grand uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY ); 145*6f0b96b4SArmin Le Grand OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" ); 146*6f0b96b4SArmin Le Grand if( !xChartDoc.is()) 147*6f0b96b4SArmin Le Grand return; 148*6f0b96b4SArmin Le Grand 149*6f0b96b4SArmin Le Grand try 150*6f0b96b4SArmin Le Grand { 151*6f0b96b4SArmin Le Grand // set background to transparent (none) 152*6f0b96b4SArmin Le Grand uno::Reference< beans::XPropertySet > xPageProp( xChartDoc->getPageBackground()); 153*6f0b96b4SArmin Le Grand if( xPageProp.is()) 154*6f0b96b4SArmin Le Grand xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FillStyle")), 155*6f0b96b4SArmin Le Grand uno::makeAny( drawing::FillStyle_NONE )); 156*6f0b96b4SArmin Le Grand // set no border 157*6f0b96b4SArmin Le Grand if( xPageProp.is()) 158*6f0b96b4SArmin Le Grand xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LineStyle")), 159*6f0b96b4SArmin Le Grand uno::makeAny( drawing::LineStyle_NONE )); 160*6f0b96b4SArmin Le Grand } 161*6f0b96b4SArmin Le Grand catch( const uno::Exception & ) 162*6f0b96b4SArmin Le Grand { 163*6f0b96b4SArmin Le Grand OSL_ENSURE( false, "Exception caught in AdaptDefaultsForChart" ); 164*6f0b96b4SArmin Le Grand } 165*6f0b96b4SArmin Le Grand } 166*6f0b96b4SArmin Le Grand } 167*6f0b96b4SArmin Le Grand 16878d93489SArmin Le Grand ////////////////////////////////////////////////////////////////////////////// 16978d93489SArmin Le Grand // eof 170