xref: /AOO41X/main/svx/source/svdraw/charthelper.cxx (revision b2b2039ba7dd97d141d07a39bcdaeebd6c6f8ef7)
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>
366f0b96b4SArmin Le Grand #include <com/sun/star/chart2/XChartDocument.hpp>
376f0b96b4SArmin Le Grand #include <com/sun/star/drawing/FillStyle.hpp>
386f0b96b4SArmin 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 
IsChart(const svt::EmbeddedObjectRef & xObjRef)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 
tryToGetChartContentAsPrimitive2DSequence(const uno::Reference<::frame::XModel> & rXModel,basegfx::B2DRange & rRange)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 
AdaptDefaultsForChart(const uno::Reference<embed::XEmbeddedObject> & xEmbObj,bool,bool)1376f0b96b4SArmin Le Grand void ChartHelper::AdaptDefaultsForChart(
1386f0b96b4SArmin Le Grand     const uno::Reference < embed::XEmbeddedObject > & xEmbObj,
139*b2b2039bSPavel Janík     bool /* bNoFillStyle */,
140*b2b2039bSPavel Janík     bool /* bNoLineStyle */)
1416f0b96b4SArmin Le Grand {
1426f0b96b4SArmin Le Grand     if( xEmbObj.is())
1436f0b96b4SArmin Le Grand     {
1446f0b96b4SArmin Le Grand         uno::Reference< chart2::XChartDocument > xChartDoc( xEmbObj->getComponent(), uno::UNO_QUERY );
1456f0b96b4SArmin Le Grand         OSL_ENSURE( xChartDoc.is(), "Trying to set chart property to non-chart OLE" );
1466f0b96b4SArmin Le Grand         if( !xChartDoc.is())
1476f0b96b4SArmin Le Grand             return;
1486f0b96b4SArmin Le Grand 
1496f0b96b4SArmin Le Grand         try
1506f0b96b4SArmin Le Grand         {
1516f0b96b4SArmin Le Grand             // set background to transparent (none)
1526f0b96b4SArmin Le Grand             uno::Reference< beans::XPropertySet > xPageProp( xChartDoc->getPageBackground());
1536f0b96b4SArmin Le Grand             if( xPageProp.is())
1546f0b96b4SArmin Le Grand                 xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FillStyle")),
1556f0b96b4SArmin Le Grand                                              uno::makeAny( drawing::FillStyle_NONE ));
1566f0b96b4SArmin Le Grand             // set no border
1576f0b96b4SArmin Le Grand             if( xPageProp.is())
1586f0b96b4SArmin Le Grand                 xPageProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LineStyle")),
1596f0b96b4SArmin Le Grand                                              uno::makeAny( drawing::LineStyle_NONE ));
1606f0b96b4SArmin Le Grand         }
1616f0b96b4SArmin Le Grand         catch( const uno::Exception & )
1626f0b96b4SArmin Le Grand         {
1636f0b96b4SArmin Le Grand             OSL_ENSURE( false, "Exception caught in AdaptDefaultsForChart" );
1646f0b96b4SArmin Le Grand         }
1656f0b96b4SArmin Le Grand     }
1666f0b96b4SArmin Le Grand }
1676f0b96b4SArmin Le Grand 
16878d93489SArmin Le Grand //////////////////////////////////////////////////////////////////////////////
16978d93489SArmin Le Grand // eof
170