LCOV - code coverage report
Current view: top level - chart2/source/model/main - Diagram.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 251 310 81.0 %
Date: 2015-06-13 12:38:46 Functions: 38 50 76.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "Diagram.hxx"
      21             : #include "macros.hxx"
      22             : #include "PropertyHelper.hxx"
      23             : #include "Wall.hxx"
      24             : #include "UserDefinedProperties.hxx"
      25             : #include "ConfigColorScheme.hxx"
      26             : #include "DiagramHelper.hxx"
      27             : #include "ContainerHelper.hxx"
      28             : #include "ThreeDHelper.hxx"
      29             : #include "CloneHelper.hxx"
      30             : #include "AxisHelper.hxx"
      31             : #include "SceneProperties.hxx"
      32             : #include "DisposeHelper.hxx"
      33             : #include "BaseGFXHelper.hxx"
      34             : #include <unonames.hxx>
      35             : 
      36             : #include <basegfx/numeric/ftools.hxx>
      37             : #include <rtl/instance.hxx>
      38             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      39             : #include <com/sun/star/chart2/RelativePosition.hpp>
      40             : #include <com/sun/star/chart2/RelativeSize.hpp>
      41             : #include <com/sun/star/drawing/CameraGeometry.hpp>
      42             : 
      43             : #include <com/sun/star/drawing/HomogenMatrix.hpp>
      44             : #include <cppuhelper/supportsservice.hxx>
      45             : 
      46             : #include <algorithm>
      47             : #include <iterator>
      48             : #include <functional>
      49             : 
      50             : using namespace ::com::sun::star;
      51             : using namespace ::com::sun::star::beans::PropertyAttribute;
      52             : 
      53             : using ::com::sun::star::beans::Property;
      54             : using ::com::sun::star::uno::Sequence;
      55             : using ::com::sun::star::uno::Reference;
      56             : using ::com::sun::star::uno::Any;
      57             : using ::osl::MutexGuard;
      58             : 
      59             : namespace
      60             : {
      61             : 
      62             : enum
      63             : {
      64             :     PROP_DIAGRAM_REL_POS,
      65             :     PROP_DIAGRAM_REL_SIZE,
      66             :     PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS,
      67             :     PROP_DIAGRAM_SORT_BY_X_VALUES,
      68             :     PROP_DIAGRAM_CONNECT_BARS,
      69             :     PROP_DIAGRAM_GROUP_BARS_PER_AXIS,
      70             :     PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS,
      71             :     PROP_DIAGRAM_STARTING_ANGLE,
      72             :     PROP_DIAGRAM_RIGHT_ANGLED_AXES,
      73             :     PROP_DIAGRAM_PERSPECTIVE,
      74             :     PROP_DIAGRAM_ROTATION_HORIZONTAL,
      75             :     PROP_DIAGRAM_ROTATION_VERTICAL,
      76             :     PROP_DIAGRAM_MISSING_VALUE_TREATMENT,
      77             :     PROP_DIAGRAM_3DRELATIVEHEIGHT,
      78             :     PROP_DIAGRAM_DATATABLEHBORDER,
      79             :     PROP_DIAGRAM_DATATABLEVBORDER,
      80             :     PROP_DIAGRAM_DATATABLEOUTLINE,
      81             :     PROP_DIAGRAM_EXTERNALDATA
      82             : };
      83             : 
      84          16 : void lcl_AddPropertiesToVector(
      85             :     ::std::vector< Property > & rOutProperties )
      86             : {
      87             :     rOutProperties.push_back(
      88             :         Property( "RelativePosition",
      89             :                   PROP_DIAGRAM_REL_POS,
      90          16 :                   cppu::UnoType<chart2::RelativePosition>::get(),
      91             :                   beans::PropertyAttribute::BOUND
      92          32 :                   | beans::PropertyAttribute::MAYBEVOID ));
      93             : 
      94             :     rOutProperties.push_back(
      95             :         Property( "RelativeSize",
      96             :                   PROP_DIAGRAM_REL_SIZE,
      97          16 :                   cppu::UnoType<chart2::RelativeSize>::get(),
      98             :                   beans::PropertyAttribute::BOUND
      99          32 :                   | beans::PropertyAttribute::MAYBEVOID ));
     100             : 
     101             :     rOutProperties.push_back(
     102             :         Property( "PosSizeExcludeAxes",
     103             :                   PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS,
     104          16 :                   cppu::UnoType<bool>::get(),
     105             :                   beans::PropertyAttribute::BOUND
     106          32 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     107             : 
     108             :     rOutProperties.push_back(
     109             :         Property( CHART_UNONAME_SORT_BY_XVALUES,
     110             :                   PROP_DIAGRAM_SORT_BY_X_VALUES,
     111          16 :                   cppu::UnoType<bool>::get(),
     112             :                   beans::PropertyAttribute::BOUND
     113          32 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     114             : 
     115             :     rOutProperties.push_back(
     116             :         Property( "ConnectBars",
     117             :                   PROP_DIAGRAM_CONNECT_BARS,
     118          16 :                   cppu::UnoType<bool>::get(),
     119             :                   beans::PropertyAttribute::BOUND
     120          32 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     121             : 
     122             :     rOutProperties.push_back(
     123             :         Property( "GroupBarsPerAxis",
     124             :                   PROP_DIAGRAM_GROUP_BARS_PER_AXIS,
     125          16 :                   cppu::UnoType<bool>::get(),
     126             :                   beans::PropertyAttribute::BOUND
     127          32 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     128             : 
     129             :     rOutProperties.push_back(
     130             :         Property( "IncludeHiddenCells",
     131             :                   PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS,
     132          16 :                   cppu::UnoType<bool>::get(),
     133             :                   beans::PropertyAttribute::BOUND
     134          32 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     135             : 
     136             :     rOutProperties.push_back(
     137             :         Property( "StartingAngle",
     138             :                   PROP_DIAGRAM_STARTING_ANGLE,
     139          16 :                   cppu::UnoType<sal_Int32>::get(),
     140             :                   beans::PropertyAttribute::BOUND
     141          32 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     142             : 
     143             :     rOutProperties.push_back(
     144             :         Property( "RightAngledAxes",
     145             :                   PROP_DIAGRAM_RIGHT_ANGLED_AXES,
     146          16 :                   cppu::UnoType<bool>::get(),
     147             :                   beans::PropertyAttribute::BOUND
     148          32 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     149             : 
     150             :     rOutProperties.push_back(
     151             :         Property( "Perspective",
     152             :                   PROP_DIAGRAM_PERSPECTIVE,
     153          16 :                   cppu::UnoType<sal_Int32>::get(),
     154          16 :                   beans::PropertyAttribute::MAYBEVOID ));
     155             : 
     156             :     rOutProperties.push_back(
     157             :         Property( "RotationHorizontal",
     158             :                   PROP_DIAGRAM_ROTATION_HORIZONTAL,
     159          16 :                   cppu::UnoType<sal_Int32>::get(),
     160          16 :                   beans::PropertyAttribute::MAYBEVOID ));
     161             : 
     162             :     rOutProperties.push_back(
     163             :         Property( "RotationVertical",
     164             :                   PROP_DIAGRAM_ROTATION_VERTICAL,
     165          16 :                   cppu::UnoType<sal_Int32>::get(),
     166          16 :                   beans::PropertyAttribute::MAYBEVOID ));
     167             : 
     168             :     rOutProperties.push_back(
     169             :         Property( "MissingValueTreatment",
     170             :                   PROP_DIAGRAM_MISSING_VALUE_TREATMENT,
     171          16 :                   cppu::UnoType<sal_Int32>::get(),
     172             :                   beans::PropertyAttribute::BOUND
     173          32 :                   | beans::PropertyAttribute::MAYBEVOID ));
     174             :    rOutProperties.push_back(
     175             :         Property( "3DRelativeHeight",
     176             :                   PROP_DIAGRAM_3DRELATIVEHEIGHT,
     177          16 :                   cppu::UnoType<sal_Int32>::get(),
     178          16 :                   beans::PropertyAttribute::MAYBEVOID ));
     179             :    rOutProperties.push_back(
     180             :        Property( "DataTableHBorder",
     181             :                PROP_DIAGRAM_DATATABLEHBORDER,
     182          16 :                  cppu::UnoType<bool>::get(),
     183             :                  beans::PropertyAttribute::BOUND
     184          32 :                  | beans::PropertyAttribute::MAYBEDEFAULT ));
     185             :    rOutProperties.push_back(
     186             :        Property( "DataTableVBorder",
     187             :                PROP_DIAGRAM_DATATABLEVBORDER,
     188          16 :                  cppu::UnoType<bool>::get(),
     189             :                  beans::PropertyAttribute::BOUND
     190          32 :                  | beans::PropertyAttribute::MAYBEDEFAULT ));
     191             :    rOutProperties.push_back(
     192             :        Property( "DataTableOutline",
     193             :                PROP_DIAGRAM_DATATABLEOUTLINE,
     194          16 :                  cppu::UnoType<bool>::get(),
     195             :                  beans::PropertyAttribute::BOUND
     196          32 :                  | beans::PropertyAttribute::MAYBEDEFAULT ));
     197             :    rOutProperties.push_back(
     198             :         Property( "ExternalData",
     199             :                   PROP_DIAGRAM_EXTERNALDATA,
     200          16 :                   cppu::UnoType<OUString>::get(),
     201          16 :                   beans::PropertyAttribute::MAYBEVOID ));
     202          16 : }
     203             : 
     204             : struct StaticDiagramDefaults_Initializer
     205             : {
     206          17 :     ::chart::tPropertyValueMap* operator()()
     207             :     {
     208          17 :         static ::chart::tPropertyValueMap aStaticDefaults;
     209          17 :         lcl_AddDefaultsToMap( aStaticDefaults );
     210          17 :         return &aStaticDefaults;
     211             :     }
     212             : private:
     213          17 :     static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
     214             :     {
     215          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS, true );
     216          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_SORT_BY_X_VALUES, false );
     217          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_CONNECT_BARS, false );
     218          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_GROUP_BARS_PER_AXIS, true );
     219          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS, true );
     220          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_RIGHT_ANGLED_AXES, false );
     221          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_DATATABLEHBORDER, false );
     222          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_DATATABLEVBORDER, false );
     223          17 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_DATATABLEOUTLINE, false );
     224          17 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_DIAGRAM_STARTING_ANGLE, 90 );
     225          17 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_DIAGRAM_3DRELATIVEHEIGHT, 100 );
     226          17 :          ::chart::SceneProperties::AddDefaultsToMap( rOutMap );
     227          17 :     }
     228             : };
     229             : 
     230             : struct StaticDiagramDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticDiagramDefaults_Initializer >
     231             : {
     232             : };
     233             : 
     234             : struct StaticDiagramInfoHelper_Initializer
     235             : {
     236          16 :     ::cppu::OPropertyArrayHelper* operator()()
     237             :     {
     238          16 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
     239          16 :         return &aPropHelper;
     240             :     }
     241             : 
     242             : private:
     243          16 :     static Sequence< Property > lcl_GetPropertySequence()
     244             :     {
     245          16 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     246          16 :         lcl_AddPropertiesToVector( aProperties );
     247          16 :         ::chart::SceneProperties::AddPropertiesToVector( aProperties );
     248          16 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
     249             : 
     250             :         ::std::sort( aProperties.begin(), aProperties.end(),
     251          16 :                      ::chart::PropertyNameLess() );
     252             : 
     253          16 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     254             :     }
     255             : };
     256             : 
     257             : struct StaticDiagramInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticDiagramInfoHelper_Initializer >
     258             : {
     259             : };
     260             : 
     261             : struct StaticDiagramInfo_Initializer
     262             : {
     263           6 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     264             :     {
     265             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     266           6 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticDiagramInfoHelper::get() ) );
     267           6 :         return &xPropertySetInfo;
     268             :     }
     269             : };
     270             : 
     271             : struct StaticDiagramInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticDiagramInfo_Initializer >
     272             : {
     273             : };
     274             : 
     275             : /// clones a UNO-sequence of UNO-References
     276             : typedef Reference< chart2::XCoordinateSystem > lcl_tCooSysRef;
     277             : typedef ::std::map< lcl_tCooSysRef, lcl_tCooSysRef >  lcl_tCooSysMapping;
     278             : typedef ::std::vector< lcl_tCooSysRef >               lcl_tCooSysVector;
     279             : 
     280           0 : lcl_tCooSysMapping lcl_CloneCoordinateSystems(
     281             :         const lcl_tCooSysVector & rSource,
     282             :         lcl_tCooSysVector & rDestination )
     283             : {
     284           0 :     lcl_tCooSysMapping aResult;
     285             : 
     286           0 :     for( lcl_tCooSysVector::const_iterator aIt( rSource.begin());
     287           0 :          aIt != rSource.end(); ++aIt )
     288             :     {
     289           0 :         lcl_tCooSysRef xClone;
     290             :         ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >
     291           0 :               xCloneable( *aIt, ::com::sun::star::uno::UNO_QUERY );
     292           0 :         if( xCloneable.is())
     293           0 :             xClone.set( xCloneable->createClone(), ::com::sun::star::uno::UNO_QUERY );
     294             : 
     295           0 :         if( xClone.is())
     296             :         {
     297           0 :             rDestination.push_back( xClone );
     298           0 :             aResult.insert( lcl_tCooSysMapping::value_type( *aIt, xClone ));
     299             :         }
     300             :         else
     301           0 :             rDestination.push_back( *aIt );
     302           0 :     }
     303             : 
     304           0 :     return aResult;
     305             : }
     306             : 
     307             : } // anonymous namespace
     308             : 
     309             : namespace chart
     310             : {
     311             : 
     312         319 : Diagram::Diagram( uno::Reference< uno::XComponentContext > const & xContext ) :
     313             :         ::property::OPropertySet( m_aMutex ),
     314             :         m_xContext( xContext ),
     315         319 :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     316             : {
     317             :     // Set camera position to a default position (that should be set hard, so
     318             :     // that it will be exported.  The property default is a camera looking
     319             :     // straight ono the scene).  These defaults have been acquired from the old
     320             :     // chart implementation.
     321             :     setFastPropertyValue_NoBroadcast(
     322             :         SceneProperties::PROP_SCENE_CAMERA_GEOMETRY, uno::makeAny(
     323         319 :             ThreeDHelper::getDefaultCameraGeometry()));
     324         319 : }
     325             : 
     326           0 : Diagram::Diagram( const Diagram & rOther ) :
     327             :         MutexContainer(),
     328             :         impl::Diagram_Base(),
     329             :         ::property::OPropertySet( rOther, m_aMutex ),
     330             :     m_xContext( rOther.m_xContext ),
     331           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     332             : {
     333             :     lcl_tCooSysMapping aCooSysMapping =
     334           0 :         lcl_CloneCoordinateSystems( rOther.m_aCoordSystems, m_aCoordSystems );
     335           0 :     ModifyListenerHelper::addListenerToAllElements( m_aCoordSystems, m_xModifyEventForwarder );
     336             : 
     337           0 :     m_xWall.set( CloneHelper::CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xWall ));
     338           0 :     m_xFloor.set( CloneHelper::CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xFloor ));
     339           0 :     m_xTitle.set( CloneHelper::CreateRefClone< Reference< chart2::XTitle > >()( rOther.m_xTitle ));
     340           0 :     m_xLegend.set( CloneHelper::CreateRefClone< Reference< chart2::XLegend > >()( rOther.m_xLegend ));
     341             : 
     342           0 :     ModifyListenerHelper::addListener( m_xWall, m_xModifyEventForwarder );
     343           0 :     ModifyListenerHelper::addListener( m_xFloor, m_xModifyEventForwarder );
     344           0 :     ModifyListenerHelper::addListener( m_xTitle, m_xModifyEventForwarder );
     345           0 :     ModifyListenerHelper::addListener( m_xLegend, m_xModifyEventForwarder );
     346           0 : }
     347             : 
     348         957 : Diagram::~Diagram()
     349             : {
     350             :     try
     351             :     {
     352         319 :         ModifyListenerHelper::removeListenerFromAllElements( m_aCoordSystems, m_xModifyEventForwarder );
     353             : 
     354         319 :         ModifyListenerHelper::removeListener( m_xWall, m_xModifyEventForwarder );
     355         319 :         ModifyListenerHelper::removeListener( m_xFloor, m_xModifyEventForwarder );
     356         319 :         ModifyListenerHelper::removeListener( m_xTitle, m_xModifyEventForwarder );
     357         319 :         ModifyListenerHelper::removeListener( m_xLegend, m_xModifyEventForwarder );
     358             :     }
     359           0 :     catch( const uno::Exception & ex )
     360             :     {
     361             :         ASSERT_EXCEPTION( ex );
     362             :     }
     363         638 : }
     364             : 
     365             : // ____ XDiagram ____
     366       17864 : uno::Reference< beans::XPropertySet > SAL_CALL Diagram::getWall()
     367             :     throw (uno::RuntimeException, std::exception)
     368             : {
     369       17864 :     uno::Reference< beans::XPropertySet > xRet;
     370       17864 :     bool bAddListener = false;
     371             :     {
     372       17864 :         MutexGuard aGuard( GetMutex() );
     373       17864 :         if( !m_xWall.is() )
     374             :         {
     375         318 :             m_xWall.set( new Wall() );
     376         318 :             bAddListener = true;
     377             :         }
     378       17864 :         xRet =  m_xWall;
     379             :     }
     380       17864 :     if(bAddListener)
     381         318 :         ModifyListenerHelper::addListener( xRet, m_xModifyEventForwarder );
     382       17864 :     return xRet;
     383             : }
     384             : 
     385       15456 : uno::Reference< beans::XPropertySet > SAL_CALL Diagram::getFloor()
     386             :     throw (uno::RuntimeException, std::exception)
     387             : {
     388       15456 :     uno::Reference< beans::XPropertySet > xRet;
     389       15456 :     bool bAddListener = false;
     390             :     {
     391       15456 :         MutexGuard aGuard( GetMutex() );
     392       15456 :         if( !m_xFloor.is() )
     393             :         {
     394         190 :             m_xFloor.set( new Wall() );
     395         190 :             bAddListener = true;
     396             :         }
     397       15456 :         xRet = m_xFloor;
     398             :     }
     399       15456 :     if(bAddListener)
     400         190 :         ModifyListenerHelper::addListener( xRet, m_xModifyEventForwarder );
     401       15456 :     return xRet;
     402             : }
     403             : 
     404       45276 : uno::Reference< chart2::XLegend > SAL_CALL Diagram::getLegend()
     405             :     throw (uno::RuntimeException, std::exception)
     406             : {
     407       45276 :     MutexGuard aGuard( GetMutex() );
     408       45276 :     return m_xLegend;
     409             : }
     410             : 
     411         227 : void SAL_CALL Diagram::setLegend( const uno::Reference< chart2::XLegend >& xNewLegend )
     412             :     throw (uno::RuntimeException, std::exception)
     413             : {
     414         227 :     Reference< chart2::XLegend > xOldLegend;
     415             :     {
     416         227 :         MutexGuard aGuard( GetMutex() );
     417         227 :         if( m_xLegend == xNewLegend )
     418         227 :             return;
     419         227 :         xOldLegend = m_xLegend;
     420         227 :         m_xLegend = xNewLegend;
     421             :     }
     422         227 :     if( xOldLegend.is())
     423           0 :         ModifyListenerHelper::removeListener( xOldLegend, m_xModifyEventForwarder );
     424         227 :     if( xNewLegend.is())
     425         227 :         ModifyListenerHelper::addListener( xNewLegend, m_xModifyEventForwarder );
     426         227 :     fireModifyEvent();
     427             : }
     428             : 
     429        2535 : Reference< chart2::XColorScheme > SAL_CALL Diagram::getDefaultColorScheme()
     430             :     throw (uno::RuntimeException, std::exception)
     431             : {
     432        2535 :     Reference< chart2::XColorScheme > xRet;
     433             :     {
     434        2535 :         MutexGuard aGuard( GetMutex() );
     435        2535 :         xRet = m_xColorScheme;
     436             :     }
     437             : 
     438        2535 :     if( !xRet.is())
     439             :     {
     440         248 :         xRet.set( createConfigColorScheme( m_xContext ));
     441         248 :         MutexGuard aGuard( GetMutex() );
     442         248 :         m_xColorScheme = xRet;
     443             :     }
     444        2535 :     return xRet;
     445             : }
     446             : 
     447           0 : void SAL_CALL Diagram::setDefaultColorScheme( const Reference< chart2::XColorScheme >& xColorScheme )
     448             :     throw (uno::RuntimeException, std::exception)
     449             : {
     450             :     {
     451           0 :         MutexGuard aGuard( GetMutex() );
     452           0 :         m_xColorScheme.set( xColorScheme );
     453             :     }
     454           0 :     fireModifyEvent();
     455           0 : }
     456             : 
     457          19 : void SAL_CALL Diagram::setDiagramData(
     458             :     const Reference< chart2::data::XDataSource >& xDataSource,
     459             :     const Sequence< beans::PropertyValue >& aArguments )
     460             :         throw (uno::RuntimeException, std::exception)
     461             : {
     462          38 :     uno::Reference< lang::XMultiServiceFactory > xChartTypeManager( m_xContext->getServiceManager()->createInstanceWithContext(
     463          19 :             "com.sun.star.chart2.ChartTypeManager", m_xContext ), uno::UNO_QUERY );
     464          38 :     DiagramHelper::tTemplateWithServiceName aTemplateAndService = DiagramHelper::getTemplateForDiagram( this, xChartTypeManager );
     465          38 :     uno::Reference< chart2::XChartTypeTemplate > xTemplate( aTemplateAndService.first );
     466          19 :     if( !xTemplate.is() )
     467           0 :         xTemplate.set( xChartTypeManager->createInstance( "com.sun.star.chart2.template.Column" ), uno::UNO_QUERY );
     468          19 :     if(!xTemplate.is())
     469          19 :         return;
     470          38 :     xTemplate->changeDiagramData( this, xDataSource, aArguments );
     471             : }
     472             : 
     473             : // ____ XTitled ____
     474        5515 : uno::Reference< chart2::XTitle > SAL_CALL Diagram::getTitleObject()
     475             :     throw (uno::RuntimeException, std::exception)
     476             : {
     477        5515 :     MutexGuard aGuard( GetMutex() );
     478        5515 :     return m_xTitle;
     479             : }
     480             : 
     481          32 : void SAL_CALL Diagram::setTitleObject( const uno::Reference< chart2::XTitle >& xNewTitle )
     482             :     throw (uno::RuntimeException, std::exception)
     483             : {
     484          32 :     Reference< chart2::XTitle > xOldTitle;
     485             :     {
     486          32 :         MutexGuard aGuard( GetMutex() );
     487          32 :         if( m_xTitle == xNewTitle )
     488          32 :             return;
     489          32 :         xOldTitle = m_xTitle;
     490          32 :         m_xTitle = xNewTitle;
     491             :     }
     492          32 :     if( xOldTitle.is())
     493           1 :         ModifyListenerHelper::removeListener( xOldTitle, m_xModifyEventForwarder );
     494          32 :     if( xNewTitle.is())
     495          31 :         ModifyListenerHelper::addListener( xNewTitle, m_xModifyEventForwarder );
     496          32 :     fireModifyEvent();
     497             : }
     498             : 
     499             : // ____ X3DDefaultSetter ____
     500           0 : void SAL_CALL Diagram::set3DSettingsToDefault()
     501             :     throw (uno::RuntimeException, std::exception)
     502             : {
     503           0 :     ThreeDHelper::set3DSettingsToDefault( this );
     504           0 : }
     505             : 
     506           0 : void SAL_CALL Diagram::setDefaultRotation()
     507             :     throw (uno::RuntimeException, std::exception)
     508             : {
     509           0 :     ThreeDHelper::setDefaultRotation( this );
     510           0 : }
     511             : 
     512           0 : void SAL_CALL Diagram::setDefaultIllumination()
     513             :     throw (uno::RuntimeException, std::exception)
     514             : {
     515           0 :     ThreeDHelper::setDefaultIllumination( this );
     516           0 : }
     517             : 
     518             : // ____ XCoordinateSystemContainer ____
     519         231 : void SAL_CALL Diagram::addCoordinateSystem(
     520             :     const uno::Reference< chart2::XCoordinateSystem >& aCoordSys )
     521             :     throw (lang::IllegalArgumentException,
     522             :            uno::RuntimeException, std::exception)
     523             : {
     524             :     {
     525         231 :         MutexGuard aGuard( GetMutex() );
     526         693 :         if( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys )
     527         693 :             != m_aCoordSystems.end())
     528           0 :             throw lang::IllegalArgumentException();
     529             : 
     530         231 :         if( m_aCoordSystems.size()>=1 )
     531             :         {
     532             :             OSL_FAIL( "more than one coordinatesystem is not supported yet by the fileformat" );
     533         231 :             return;
     534             :         }
     535         231 :         m_aCoordSystems.push_back( aCoordSys );
     536             :     }
     537         231 :     ModifyListenerHelper::addListener( aCoordSys, m_xModifyEventForwarder );
     538         231 :     fireModifyEvent();
     539             : }
     540             : 
     541          20 : void SAL_CALL Diagram::removeCoordinateSystem(
     542             :     const uno::Reference< chart2::XCoordinateSystem >& aCoordSys )
     543             :     throw (container::NoSuchElementException,
     544             :            uno::RuntimeException, std::exception)
     545             : {
     546             :     {
     547          20 :         MutexGuard aGuard( GetMutex() );
     548             :         ::std::vector< uno::Reference< chart2::XCoordinateSystem > >::iterator
     549          20 :               aIt( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys ));
     550          20 :         if( aIt == m_aCoordSystems.end())
     551             :             throw container::NoSuchElementException(
     552             :                 "The given coordinate-system is no element of the container",
     553           0 :                 static_cast< uno::XWeak * >( this ));
     554          20 :         m_aCoordSystems.erase( aIt );
     555             :     }
     556          20 :     ModifyListenerHelper::removeListener( aCoordSys, m_xModifyEventForwarder );
     557          20 :     fireModifyEvent();
     558          20 : }
     559             : 
     560      462854 : uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > SAL_CALL Diagram::getCoordinateSystems()
     561             :     throw (uno::RuntimeException, std::exception)
     562             : {
     563      462854 :     MutexGuard aGuard( GetMutex() );
     564      462854 :     return ContainerHelper::ContainerToSequence( m_aCoordSystems );
     565             : }
     566             : 
     567         109 : void SAL_CALL Diagram::setCoordinateSystems(
     568             :     const Sequence< Reference< chart2::XCoordinateSystem > >& aCoordinateSystems )
     569             :     throw (lang::IllegalArgumentException,
     570             :            uno::RuntimeException, std::exception)
     571             : {
     572         109 :     tCoordinateSystemContainerType aNew;
     573         218 :     tCoordinateSystemContainerType aOld;
     574         109 :     if( aCoordinateSystems.getLength()>0 )
     575             :     {
     576             :         OSL_ENSURE( aCoordinateSystems.getLength()<=1, "more than one coordinatesystem is not supported yet by the fileformat" );
     577         109 :         aNew.push_back( aCoordinateSystems[0] );
     578             :     }
     579             :     {
     580         109 :         MutexGuard aGuard( GetMutex() );
     581         109 :         std::swap( aOld, m_aCoordSystems );
     582         109 :         m_aCoordSystems = aNew;
     583             :     }
     584         109 :     ModifyListenerHelper::removeListenerFromAllElements( aOld, m_xModifyEventForwarder );
     585         109 :     ModifyListenerHelper::addListenerToAllElements( aNew, m_xModifyEventForwarder );
     586         218 :     fireModifyEvent();
     587         109 : }
     588             : 
     589             : // ____ XCloneable ____
     590           0 : Reference< util::XCloneable > SAL_CALL Diagram::createClone()
     591             :     throw (uno::RuntimeException, std::exception)
     592             : {
     593           0 :     MutexGuard aGuard( GetMutex() );
     594           0 :     return Reference< util::XCloneable >( new Diagram( *this ));
     595             : }
     596             : 
     597             : // ____ XModifyBroadcaster ____
     598         318 : void SAL_CALL Diagram::addModifyListener( const Reference< util::XModifyListener >& aListener )
     599             :     throw (uno::RuntimeException, std::exception)
     600             : {
     601             :     try
     602             :     {
     603         318 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     604         318 :         xBroadcaster->addModifyListener( aListener );
     605             :     }
     606           0 :     catch( const uno::Exception & ex )
     607             :     {
     608             :         ASSERT_EXCEPTION( ex );
     609             :     }
     610         318 : }
     611             : 
     612         318 : void SAL_CALL Diagram::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     613             :     throw (uno::RuntimeException, std::exception)
     614             : {
     615             :     try
     616             :     {
     617         318 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     618         318 :         xBroadcaster->removeModifyListener( aListener );
     619             :     }
     620           0 :     catch( const uno::Exception & ex )
     621             :     {
     622             :         ASSERT_EXCEPTION( ex );
     623             :     }
     624         318 : }
     625             : 
     626             : // ____ XModifyListener ____
     627           0 : void SAL_CALL Diagram::modified( const lang::EventObject& aEvent )
     628             :     throw (uno::RuntimeException, std::exception)
     629             : {
     630           0 :     m_xModifyEventForwarder->modified( aEvent );
     631           0 : }
     632             : 
     633             : // ____ XEventListener (base of XModifyListener) ____
     634           0 : void SAL_CALL Diagram::disposing( const lang::EventObject& /* Source */ )
     635             :     throw (uno::RuntimeException, std::exception)
     636             : {
     637             :     // nothing
     638           0 : }
     639             : 
     640             : // ____ OPropertySet ____
     641        2235 : void Diagram::firePropertyChangeEvent()
     642             : {
     643        2235 :     fireModifyEvent();
     644        2235 : }
     645             : 
     646        2854 : void Diagram::fireModifyEvent()
     647             : {
     648        2854 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     649        2854 : }
     650             : 
     651           1 : Sequence< OUString > Diagram::getSupportedServiceNames_Static()
     652             : {
     653           1 :     Sequence< OUString > aServices( 3 );
     654             : 
     655           1 :     aServices[ 0 ] = "com.sun.star.chart2.Diagram";
     656           1 :     aServices[ 1 ] = "com.sun.star.layout.LayoutElement";
     657           1 :     aServices[ 2 ] = "com.sun.star.beans.PropertySet";
     658           1 :     return aServices;
     659             : }
     660             : 
     661             : // ____ OPropertySet ____
     662       21029 : uno::Any Diagram::GetDefaultValue( sal_Int32 nHandle ) const
     663             :     throw(beans::UnknownPropertyException)
     664             : {
     665       21029 :     const tPropertyValueMap& rStaticDefaults = *StaticDiagramDefaults::get();
     666       21029 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     667       21029 :     if( aFound == rStaticDefaults.end() )
     668        6937 :         return uno::Any();
     669       14092 :     return (*aFound).second;
     670             : }
     671             : 
     672             : // ____ OPropertySet ____
     673       67102 : ::cppu::IPropertyArrayHelper & SAL_CALL Diagram::getInfoHelper()
     674             : {
     675       67102 :     return *StaticDiagramInfoHelper::get();
     676             : }
     677             : 
     678             : // ____ XPropertySet ____
     679         544 : uno::Reference< beans::XPropertySetInfo > SAL_CALL Diagram::getPropertySetInfo()
     680             :     throw (uno::RuntimeException, std::exception)
     681             : {
     682         544 :     return *StaticDiagramInfo::get();
     683             : }
     684             : 
     685             : // ____ XFastPropertySet ____
     686        2343 : void SAL_CALL Diagram::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
     687             :     throw(beans::UnknownPropertyException,
     688             :           beans::PropertyVetoException,
     689             :           lang::IllegalArgumentException,
     690             :           lang::WrappedTargetException, uno::RuntimeException, std::exception)
     691             : {
     692             :     //special treatment for some 3D properties
     693        2343 :     if( PROP_DIAGRAM_PERSPECTIVE == nHandle )
     694             :     {
     695          36 :         sal_Int32 fPerspective = 20;
     696          36 :         if( rValue >>=fPerspective )
     697          36 :             ThreeDHelper::setCameraDistance( this, ThreeDHelper::PerspectiveToCameraDistance( fPerspective ) );
     698             :     }
     699        2307 :     else if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle
     700        2271 :         || PROP_DIAGRAM_ROTATION_VERTICAL == nHandle )
     701             :     {
     702          72 :         sal_Int32 nNewAngleDegree = 0;
     703          72 :         if( rValue >>=nNewAngleDegree )
     704             :         {
     705             :             sal_Int32 nHorizontal, nVertical;
     706          72 :             ThreeDHelper::getRotationFromDiagram( this, nHorizontal, nVertical );
     707          72 :             if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle )
     708          36 :                 nHorizontal = nNewAngleDegree;
     709             :             else
     710          36 :                 nVertical = nNewAngleDegree;
     711          72 :             ThreeDHelper::setRotationToDiagram( this, nHorizontal, nVertical );
     712          72 :         }
     713             :     }
     714             :     else
     715        2235 :         ::property::OPropertySet::setFastPropertyValue( nHandle, rValue );
     716        2343 : }
     717             : 
     718       28742 : void SAL_CALL Diagram::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
     719             : {
     720             :     //special treatment for some 3D properties
     721       28742 :     if( nHandle == PROP_DIAGRAM_PERSPECTIVE )
     722             :     {
     723             :         sal_Int32 nPerspective = ::basegfx::fround( ThreeDHelper::CameraDistanceToPerspective(
     724          13 :             ThreeDHelper::getCameraDistance( const_cast< Diagram* >( this ) ) ) );
     725          13 :         rValue = uno::makeAny(nPerspective);
     726             :     }
     727       28729 :     else if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle
     728       28716 :         || PROP_DIAGRAM_ROTATION_VERTICAL == nHandle )
     729             :     {
     730             :         sal_Int32 nHorizontal, nVertical;
     731          26 :         ThreeDHelper::getRotationFromDiagram( const_cast< Diagram* >( this ), nHorizontal, nVertical );
     732          26 :         sal_Int32 nAngleDegree = 0;
     733          26 :         if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle )
     734          13 :             nAngleDegree = nHorizontal;
     735             :         else
     736          13 :             nAngleDegree = nVertical;
     737          26 :         rValue = uno::makeAny(nAngleDegree);
     738             :     }
     739             :     else
     740       28703 :         ::property::OPropertySet::getFastPropertyValue( rValue,nHandle );
     741       28742 : }
     742             : 
     743             : using impl::Diagram_Base;
     744             : 
     745     3043804 : IMPLEMENT_FORWARD_XINTERFACE2( Diagram, Diagram_Base, ::property::OPropertySet )
     746           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( Diagram, Diagram_Base, ::property::OPropertySet )
     747             : 
     748             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     749           1 : OUString SAL_CALL Diagram::getImplementationName()
     750             :     throw( css::uno::RuntimeException, std::exception )
     751             : {
     752           1 :     return getImplementationName_Static();
     753             : }
     754             : 
     755           1 : OUString Diagram::getImplementationName_Static()
     756             : {
     757           1 :     return OUString("com.sun.star.comp.chart2.Diagram");
     758             : }
     759             : 
     760           0 : sal_Bool SAL_CALL Diagram::supportsService( const OUString& rServiceName )
     761             :     throw( css::uno::RuntimeException, std::exception )
     762             : {
     763           0 :     return cppu::supportsService(this, rServiceName);
     764             : }
     765             : 
     766           1 : css::uno::Sequence< OUString > SAL_CALL Diagram::getSupportedServiceNames()
     767             :     throw( css::uno::RuntimeException, std::exception )
     768             : {
     769           1 :     return getSupportedServiceNames_Static();
     770             : }
     771             : 
     772             : } //  namespace chart
     773             : 
     774             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     775         319 : com_sun_star_comp_chart2_Diagram_get_implementation(css::uno::XComponentContext *context,
     776             :         css::uno::Sequence<css::uno::Any> const &)
     777             : {
     778         319 :     return cppu::acquire(new ::chart::Diagram(context));
     779             : }
     780             : 
     781             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11