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