LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/model/main - Diagram.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 175 285 61.4 %
Date: 2012-12-27 Functions: 30 49 61.2 %
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 <basegfx/numeric/ftools.hxx>
      35             : #include <rtl/instance.hxx>
      36             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      37             : #include <com/sun/star/chart2/RelativePosition.hpp>
      38             : #include <com/sun/star/chart2/RelativeSize.hpp>
      39             : #include <com/sun/star/drawing/CameraGeometry.hpp>
      40             : 
      41             : #include <com/sun/star/drawing/HomogenMatrix.hpp>
      42             : 
      43             : #include <algorithm>
      44             : #include <iterator>
      45             : #include <functional>
      46             : 
      47             : using namespace ::com::sun::star;
      48             : using namespace ::com::sun::star::beans::PropertyAttribute;
      49             : 
      50             : using ::rtl::OUString;
      51             : using ::com::sun::star::beans::Property;
      52             : using ::com::sun::star::uno::Sequence;
      53             : using ::com::sun::star::uno::Reference;
      54             : using ::com::sun::star::uno::Any;
      55             : using ::osl::MutexGuard;
      56             : 
      57             : // ======================================================================
      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             : };
      78             : 
      79           1 : void lcl_AddPropertiesToVector(
      80             :     ::std::vector< Property > & rOutProperties )
      81             : {
      82             :     rOutProperties.push_back(
      83             :         Property( C2U( "RelativePosition" ),
      84             :                   PROP_DIAGRAM_REL_POS,
      85           1 :                   ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
      86             :                   beans::PropertyAttribute::BOUND
      87           2 :                   | beans::PropertyAttribute::MAYBEVOID ));
      88             : 
      89             :     rOutProperties.push_back(
      90             :         Property( C2U( "RelativeSize" ),
      91             :                   PROP_DIAGRAM_REL_SIZE,
      92           1 :                   ::getCppuType( reinterpret_cast< const chart2::RelativeSize * >(0)),
      93             :                   beans::PropertyAttribute::BOUND
      94           2 :                   | beans::PropertyAttribute::MAYBEVOID ));
      95             : 
      96             :     rOutProperties.push_back(
      97             :         Property( C2U( "PosSizeExcludeAxes" ),
      98             :                   PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS,
      99           1 :                   ::getBooleanCppuType(),
     100             :                   beans::PropertyAttribute::BOUND
     101           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     102             : 
     103             :     rOutProperties.push_back(
     104             :         Property( C2U( "SortByXValues" ),
     105             :                   PROP_DIAGRAM_SORT_BY_X_VALUES,
     106           1 :                   ::getBooleanCppuType(),
     107             :                   beans::PropertyAttribute::BOUND
     108           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     109             : 
     110             :     rOutProperties.push_back(
     111             :         Property( C2U("ConnectBars"),
     112             :                   PROP_DIAGRAM_CONNECT_BARS,
     113           1 :                   ::getBooleanCppuType(),
     114             :                   beans::PropertyAttribute::BOUND
     115           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     116             : 
     117             :     rOutProperties.push_back(
     118             :         Property( C2U("GroupBarsPerAxis"),
     119             :                   PROP_DIAGRAM_GROUP_BARS_PER_AXIS,
     120           1 :                   ::getBooleanCppuType(),
     121             :                   beans::PropertyAttribute::BOUND
     122           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     123             : 
     124             :     rOutProperties.push_back(
     125             :         Property( C2U("IncludeHiddenCells"),
     126             :                   PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS,
     127           1 :                   ::getBooleanCppuType(),
     128             :                   beans::PropertyAttribute::BOUND
     129           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     130             : 
     131             :     rOutProperties.push_back(
     132             :         Property( C2U( "StartingAngle" ),
     133             :                   PROP_DIAGRAM_STARTING_ANGLE,
     134           1 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0) ),
     135             :                   beans::PropertyAttribute::BOUND
     136           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     137             : 
     138             :     rOutProperties.push_back(
     139             :         Property( C2U("RightAngledAxes"),
     140             :                   PROP_DIAGRAM_RIGHT_ANGLED_AXES,
     141           1 :                   ::getBooleanCppuType(),
     142             :                   beans::PropertyAttribute::BOUND
     143           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     144             : 
     145             :     rOutProperties.push_back(
     146             :         Property( C2U("Perspective"),
     147             :                   PROP_DIAGRAM_PERSPECTIVE,
     148           1 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
     149           1 :                   beans::PropertyAttribute::MAYBEVOID ));
     150             : 
     151             :     rOutProperties.push_back(
     152             :         Property( C2U("RotationHorizontal"),
     153             :                   PROP_DIAGRAM_ROTATION_HORIZONTAL,
     154           1 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
     155           1 :                   beans::PropertyAttribute::MAYBEVOID ));
     156             : 
     157             :     rOutProperties.push_back(
     158             :         Property( C2U("RotationVertical"),
     159             :                   PROP_DIAGRAM_ROTATION_VERTICAL,
     160           1 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
     161           1 :                   beans::PropertyAttribute::MAYBEVOID ));
     162             : 
     163             :     rOutProperties.push_back(
     164             :         Property( C2U( "MissingValueTreatment" ),
     165             :                   PROP_DIAGRAM_MISSING_VALUE_TREATMENT,
     166           1 :                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
     167             :                   beans::PropertyAttribute::BOUND
     168           2 :                   | beans::PropertyAttribute::MAYBEVOID ));
     169           1 : }
     170             : 
     171             : struct StaticDiagramDefaults_Initializer
     172             : {
     173           1 :     ::chart::tPropertyValueMap* operator()()
     174             :     {
     175           1 :         static ::chart::tPropertyValueMap aStaticDefaults;
     176           1 :         lcl_AddDefaultsToMap( aStaticDefaults );
     177           1 :         return &aStaticDefaults;
     178             :     }
     179             : private:
     180           1 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
     181             :     {
     182           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS, true );
     183           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_SORT_BY_X_VALUES, false );
     184           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_CONNECT_BARS, false );
     185           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_GROUP_BARS_PER_AXIS, true );
     186           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS, true );
     187           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_RIGHT_ANGLED_AXES, false );
     188           1 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_DIAGRAM_STARTING_ANGLE, 90 );
     189           1 :         ::chart::SceneProperties::AddDefaultsToMap( rOutMap );
     190           1 :     }
     191             : };
     192             : 
     193             : struct StaticDiagramDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticDiagramDefaults_Initializer >
     194             : {
     195             : };
     196             : 
     197             : struct StaticDiagramInfoHelper_Initializer
     198             : {
     199           1 :     ::cppu::OPropertyArrayHelper* operator()()
     200             :     {
     201           1 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
     202           1 :         return &aPropHelper;
     203             :     }
     204             : 
     205             : private:
     206           1 :     Sequence< Property > lcl_GetPropertySequence()
     207             :     {
     208           1 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     209           1 :         lcl_AddPropertiesToVector( aProperties );
     210           1 :         ::chart::SceneProperties::AddPropertiesToVector( aProperties );
     211           1 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
     212             : 
     213             :         ::std::sort( aProperties.begin(), aProperties.end(),
     214           1 :                      ::chart::PropertyNameLess() );
     215             : 
     216           1 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     217             :     }
     218             : };
     219             : 
     220             : struct StaticDiagramInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticDiagramInfoHelper_Initializer >
     221             : {
     222             : };
     223             : 
     224             : struct StaticDiagramInfo_Initializer
     225             : {
     226           0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     227             :     {
     228             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     229           0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticDiagramInfoHelper::get() ) );
     230           0 :         return &xPropertySetInfo;
     231             :     }
     232             : };
     233             : 
     234             : struct StaticDiagramInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticDiagramInfo_Initializer >
     235             : {
     236             : };
     237             : 
     238             : /// clones a UNO-sequence of UNO-References
     239             : typedef Reference< chart2::XCoordinateSystem > lcl_tCooSysRef;
     240             : typedef ::std::map< lcl_tCooSysRef, lcl_tCooSysRef >  lcl_tCooSysMapping;
     241             : typedef ::std::vector< lcl_tCooSysRef >               lcl_tCooSysVector;
     242             : 
     243           0 : lcl_tCooSysMapping lcl_CloneCoordinateSystems(
     244             :         const lcl_tCooSysVector & rSource,
     245             :         lcl_tCooSysVector & rDestination )
     246             : {
     247           0 :     lcl_tCooSysMapping aResult;
     248             : 
     249           0 :     for( lcl_tCooSysVector::const_iterator aIt( rSource.begin());
     250           0 :          aIt != rSource.end(); ++aIt )
     251             :     {
     252           0 :         lcl_tCooSysRef xClone;
     253             :         ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable >
     254           0 :               xCloneable( *aIt, ::com::sun::star::uno::UNO_QUERY );
     255           0 :         if( xCloneable.is())
     256           0 :             xClone.set( xCloneable->createClone(), ::com::sun::star::uno::UNO_QUERY );
     257             : 
     258           0 :         if( xClone.is())
     259             :         {
     260           0 :             rDestination.push_back( xClone );
     261           0 :             aResult.insert( lcl_tCooSysMapping::value_type( *aIt, xClone ));
     262             :         }
     263             :         else
     264           0 :             rDestination.push_back( *aIt );
     265           0 :     }
     266             : 
     267           0 :     return aResult;
     268             : }
     269             : 
     270             : } // anonymous namespace
     271             : 
     272             : // ======================================================================
     273             : 
     274             : namespace chart
     275             : {
     276             : 
     277          81 : Diagram::Diagram( uno::Reference< uno::XComponentContext > const & xContext ) :
     278             :         ::property::OPropertySet( m_aMutex ),
     279             :         m_xContext( xContext ),
     280          81 :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     281             : {
     282             :     // Set camera position to a default position (that should be set hard, so
     283             :     // that it will be exported.  The property default is a camera looking
     284             :     // straight ono the scene).  These defaults have been acquired from the old
     285             :     // chart implemetation.
     286             :     setFastPropertyValue_NoBroadcast(
     287             :         SceneProperties::PROP_SCENE_CAMERA_GEOMETRY, uno::makeAny(
     288          81 :             ThreeDHelper::getDefaultCameraGeometry()));
     289          81 : }
     290             : 
     291           0 : Diagram::Diagram( const Diagram & rOther ) :
     292             :         MutexContainer(),
     293             :         impl::Diagram_Base(),
     294             :         ::property::OPropertySet( rOther, m_aMutex ),
     295             :     m_xContext( rOther.m_xContext ),
     296           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     297             : {
     298             :     lcl_tCooSysMapping aCooSysMapping =
     299           0 :         lcl_CloneCoordinateSystems( rOther.m_aCoordSystems, m_aCoordSystems );
     300           0 :     ModifyListenerHelper::addListenerToAllElements( m_aCoordSystems, m_xModifyEventForwarder );
     301             : 
     302           0 :     m_xWall.set( CloneHelper::CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xWall ));
     303           0 :     m_xFloor.set( CloneHelper::CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xFloor ));
     304           0 :     m_xTitle.set( CloneHelper::CreateRefClone< Reference< chart2::XTitle > >()( rOther.m_xTitle ));
     305           0 :     m_xLegend.set( CloneHelper::CreateRefClone< Reference< chart2::XLegend > >()( rOther.m_xLegend ));
     306             : 
     307           0 :     ModifyListenerHelper::addListener( m_xWall, m_xModifyEventForwarder );
     308           0 :     ModifyListenerHelper::addListener( m_xFloor, m_xModifyEventForwarder );
     309           0 :     ModifyListenerHelper::addListener( m_xTitle, m_xModifyEventForwarder );
     310           0 :     ModifyListenerHelper::addListener( m_xLegend, m_xModifyEventForwarder );
     311           0 : }
     312             : 
     313         243 : Diagram::~Diagram()
     314             : {
     315             :     try
     316             :     {
     317          81 :         ModifyListenerHelper::removeListenerFromAllElements( m_aCoordSystems, m_xModifyEventForwarder );
     318             : 
     319          81 :         ModifyListenerHelper::removeListener( m_xWall, m_xModifyEventForwarder );
     320          81 :         ModifyListenerHelper::removeListener( m_xFloor, m_xModifyEventForwarder );
     321          81 :         ModifyListenerHelper::removeListener( m_xTitle, m_xModifyEventForwarder );
     322          81 :         ModifyListenerHelper::removeListener( m_xLegend, m_xModifyEventForwarder );
     323             :     }
     324           0 :     catch( const uno::Exception & ex )
     325             :     {
     326             :         ASSERT_EXCEPTION( ex );
     327             :     }
     328         162 : }
     329             : 
     330             : // ____ XDiagram ____
     331         122 : uno::Reference< beans::XPropertySet > SAL_CALL Diagram::getWall()
     332             :     throw (uno::RuntimeException)
     333             : {
     334         122 :     uno::Reference< beans::XPropertySet > xRet;
     335         122 :     bool bAddListener = false;
     336             :     {
     337         122 :         MutexGuard aGuard( GetMutex() );
     338         122 :         if( !m_xWall.is() )
     339             :         {
     340          81 :             m_xWall.set( new Wall() );
     341          81 :             bAddListener = true;
     342             :         }
     343         122 :         xRet =  m_xWall;
     344             :     }
     345         122 :     if(bAddListener)
     346          81 :         ModifyListenerHelper::addListener( xRet, m_xModifyEventForwarder );
     347         122 :     return xRet;
     348             : }
     349             : 
     350          41 : uno::Reference< beans::XPropertySet > SAL_CALL Diagram::getFloor()
     351             :     throw (uno::RuntimeException)
     352             : {
     353          41 :     uno::Reference< beans::XPropertySet > xRet;
     354          41 :     bool bAddListener = false;
     355             :     {
     356          41 :         MutexGuard aGuard( GetMutex() );
     357          41 :         if( !m_xFloor.is() )
     358             :         {
     359          41 :             m_xFloor.set( new Wall() );
     360          41 :             bAddListener = true;
     361             :         }
     362          41 :         xRet = m_xFloor;
     363             :     }
     364          41 :     if(bAddListener)
     365          41 :         ModifyListenerHelper::addListener( xRet, m_xModifyEventForwarder );
     366          41 :     return xRet;
     367             : }
     368             : 
     369          41 : uno::Reference< chart2::XLegend > SAL_CALL Diagram::getLegend()
     370             :     throw (uno::RuntimeException)
     371             : {
     372          41 :     MutexGuard aGuard( GetMutex() );
     373          41 :     return m_xLegend;
     374             : }
     375             : 
     376          62 : void SAL_CALL Diagram::setLegend( const uno::Reference< chart2::XLegend >& xNewLegend )
     377             :     throw (uno::RuntimeException)
     378             : {
     379          62 :     Reference< chart2::XLegend > xOldLegend;
     380             :     {
     381          62 :         MutexGuard aGuard( GetMutex() );
     382          62 :         if( m_xLegend == xNewLegend )
     383          62 :             return;
     384          62 :         xOldLegend = m_xLegend;
     385          62 :         m_xLegend = xNewLegend;
     386             :     }
     387          62 :     if( xOldLegend.is())
     388           0 :         ModifyListenerHelper::removeListener( xOldLegend, m_xModifyEventForwarder );
     389          62 :     if( xNewLegend.is())
     390          62 :         ModifyListenerHelper::addListener( xNewLegend, m_xModifyEventForwarder );
     391          62 :     fireModifyEvent();
     392             : }
     393             : 
     394         164 : Reference< chart2::XColorScheme > SAL_CALL Diagram::getDefaultColorScheme()
     395             :     throw (uno::RuntimeException)
     396             : {
     397         164 :     Reference< chart2::XColorScheme > xRet;
     398             :     {
     399         164 :         MutexGuard aGuard( GetMutex() );
     400         164 :         xRet = m_xColorScheme;
     401             :     }
     402             : 
     403         164 :     if( !xRet.is())
     404             :     {
     405          41 :         xRet.set( createConfigColorScheme( m_xContext ));
     406          41 :         MutexGuard aGuard( GetMutex() );
     407          41 :         m_xColorScheme = xRet;
     408             :     }
     409         164 :     return xRet;
     410             : }
     411             : 
     412           0 : void SAL_CALL Diagram::setDefaultColorScheme( const Reference< chart2::XColorScheme >& xColorScheme )
     413             :     throw (uno::RuntimeException)
     414             : {
     415             :     {
     416           0 :         MutexGuard aGuard( GetMutex() );
     417           0 :         m_xColorScheme.set( xColorScheme );
     418             :     }
     419           0 :     fireModifyEvent();
     420           0 : }
     421             : 
     422           0 : void SAL_CALL Diagram::setDiagramData(
     423             :     const Reference< chart2::data::XDataSource >& xDataSource,
     424             :     const Sequence< beans::PropertyValue >& aArguments )
     425             :         throw (uno::RuntimeException)
     426             : {
     427           0 :     uno::Reference< lang::XMultiServiceFactory > xChartTypeManager( m_xContext->getServiceManager()->createInstanceWithContext(
     428           0 :             C2U( "com.sun.star.chart2.ChartTypeManager" ), m_xContext ), uno::UNO_QUERY );
     429           0 :     DiagramHelper::tTemplateWithServiceName aTemplateAndService = DiagramHelper::getTemplateForDiagram( this, xChartTypeManager );
     430           0 :     uno::Reference< chart2::XChartTypeTemplate > xTemplate( aTemplateAndService.first );
     431           0 :     if( !xTemplate.is() )
     432           0 :         xTemplate.set( xChartTypeManager->createInstance( C2U("com.sun.star.chart2.template.Column") ), uno::UNO_QUERY );
     433           0 :     if(!xTemplate.is())
     434           0 :         return;
     435           0 :     xTemplate->changeDiagramData( this, xDataSource, aArguments );
     436             : }
     437             : 
     438             : // ____ XTitled ____
     439          41 : uno::Reference< chart2::XTitle > SAL_CALL Diagram::getTitleObject()
     440             :     throw (uno::RuntimeException)
     441             : {
     442          41 :     MutexGuard aGuard( GetMutex() );
     443          41 :     return m_xTitle;
     444             : }
     445             : 
     446           0 : void SAL_CALL Diagram::setTitleObject( const uno::Reference< chart2::XTitle >& xNewTitle )
     447             :     throw (uno::RuntimeException)
     448             : {
     449           0 :     Reference< chart2::XTitle > xOldTitle;
     450             :     {
     451           0 :         MutexGuard aGuard( GetMutex() );
     452           0 :         if( m_xTitle == xNewTitle )
     453           0 :             return;
     454           0 :         xOldTitle = m_xTitle;
     455           0 :         m_xTitle = xNewTitle;
     456             :     }
     457           0 :     if( xOldTitle.is())
     458           0 :         ModifyListenerHelper::removeListener( xOldTitle, m_xModifyEventForwarder );
     459           0 :     if( xNewTitle.is())
     460           0 :         ModifyListenerHelper::addListener( xNewTitle, m_xModifyEventForwarder );
     461           0 :     fireModifyEvent();
     462             : }
     463             : 
     464             : // ____ X3DDefaultSetter ____
     465           0 : void SAL_CALL Diagram::set3DSettingsToDefault()
     466             :     throw (uno::RuntimeException)
     467             : {
     468           0 :     ThreeDHelper::set3DSettingsToDefault( this );
     469           0 : }
     470             : 
     471           0 : void SAL_CALL Diagram::setDefaultRotation()
     472             :     throw (uno::RuntimeException)
     473             : {
     474           0 :     ThreeDHelper::setDefaultRotation( this );
     475           0 : }
     476             : 
     477           0 : void SAL_CALL Diagram::setDefaultIllumination()
     478             :     throw (uno::RuntimeException)
     479             : {
     480           0 :     ThreeDHelper::setDefaultIllumination( this );
     481           0 : }
     482             : 
     483             : // ____ XCoordinateSystemContainer ____
     484          40 : void SAL_CALL Diagram::addCoordinateSystem(
     485             :     const uno::Reference< chart2::XCoordinateSystem >& aCoordSys )
     486             :     throw (lang::IllegalArgumentException,
     487             :            uno::RuntimeException)
     488             : {
     489             :     {
     490          40 :         MutexGuard aGuard( GetMutex() );
     491         120 :         if( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys )
     492         120 :             != m_aCoordSystems.end())
     493           0 :             throw lang::IllegalArgumentException();
     494             : 
     495          40 :         if( m_aCoordSystems.size()>=1 )
     496             :         {
     497             :             OSL_FAIL( "more than one coordinatesystem is not supported yet by the fileformat" );
     498          40 :             return;
     499             :         }
     500          40 :         m_aCoordSystems.push_back( aCoordSys );
     501             :     }
     502          40 :     ModifyListenerHelper::addListener( aCoordSys, m_xModifyEventForwarder );
     503          40 :     fireModifyEvent();
     504             : }
     505             : 
     506           0 : void SAL_CALL Diagram::removeCoordinateSystem(
     507             :     const uno::Reference< chart2::XCoordinateSystem >& aCoordSys )
     508             :     throw (container::NoSuchElementException,
     509             :            uno::RuntimeException)
     510             : {
     511             :     {
     512           0 :         MutexGuard aGuard( GetMutex() );
     513             :         ::std::vector< uno::Reference< chart2::XCoordinateSystem > >::iterator
     514           0 :               aIt( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys ));
     515           0 :         if( aIt == m_aCoordSystems.end())
     516             :             throw container::NoSuchElementException(
     517             :                 C2U( "The given coordinate-system is no element of the container" ),
     518           0 :                 static_cast< uno::XWeak * >( this ));
     519           0 :         m_aCoordSystems.erase( aIt );
     520             :     }
     521           0 :     ModifyListenerHelper::removeListener( aCoordSys, m_xModifyEventForwarder );
     522           0 :     fireModifyEvent();
     523           0 : }
     524             : 
     525        1718 : uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > SAL_CALL Diagram::getCoordinateSystems()
     526             :     throw (uno::RuntimeException)
     527             : {
     528        1718 :     MutexGuard aGuard( GetMutex() );
     529        1718 :     return ContainerHelper::ContainerToSequence( m_aCoordSystems );
     530             : }
     531             : 
     532          41 : void SAL_CALL Diagram::setCoordinateSystems(
     533             :     const Sequence< Reference< chart2::XCoordinateSystem > >& aCoordinateSystems )
     534             :     throw (lang::IllegalArgumentException,
     535             :            uno::RuntimeException)
     536             : {
     537          41 :     tCoordinateSystemContainerType aNew;
     538          41 :     tCoordinateSystemContainerType aOld;
     539          41 :     if( aCoordinateSystems.getLength()>0 )
     540             :     {
     541             :         OSL_ENSURE( aCoordinateSystems.getLength()<=1, "more than one coordinatesystem is not supported yet by the fileformat" );
     542          41 :         aNew.push_back( aCoordinateSystems[0] );
     543             :     }
     544             :     {
     545          41 :         MutexGuard aGuard( GetMutex() );
     546          41 :         std::swap( aOld, m_aCoordSystems );
     547          41 :         m_aCoordSystems = aNew;
     548             :     }
     549          41 :     ModifyListenerHelper::removeListenerFromAllElements( aOld, m_xModifyEventForwarder );
     550          41 :     ModifyListenerHelper::addListenerToAllElements( aNew, m_xModifyEventForwarder );
     551          41 :     fireModifyEvent();
     552          41 : }
     553             : 
     554             : // ____ XCloneable ____
     555           0 : Reference< util::XCloneable > SAL_CALL Diagram::createClone()
     556             :     throw (uno::RuntimeException)
     557             : {
     558           0 :     MutexGuard aGuard( GetMutex() );
     559           0 :     return Reference< util::XCloneable >( new Diagram( *this ));
     560             : }
     561             : 
     562             : // ____ XModifyBroadcaster ____
     563          81 : void SAL_CALL Diagram::addModifyListener( const Reference< util::XModifyListener >& aListener )
     564             :     throw (uno::RuntimeException)
     565             : {
     566             :     try
     567             :     {
     568          81 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     569          81 :         xBroadcaster->addModifyListener( aListener );
     570             :     }
     571           0 :     catch( const uno::Exception & ex )
     572             :     {
     573             :         ASSERT_EXCEPTION( ex );
     574             :     }
     575          81 : }
     576             : 
     577          81 : void SAL_CALL Diagram::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     578             :     throw (uno::RuntimeException)
     579             : {
     580             :     try
     581             :     {
     582          81 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     583          81 :         xBroadcaster->removeModifyListener( aListener );
     584             :     }
     585           0 :     catch( const uno::Exception & ex )
     586             :     {
     587             :         ASSERT_EXCEPTION( ex );
     588             :     }
     589          81 : }
     590             : 
     591             : // ____ XModifyListener ____
     592           0 : void SAL_CALL Diagram::modified( const lang::EventObject& aEvent )
     593             :     throw (uno::RuntimeException)
     594             : {
     595           0 :     m_xModifyEventForwarder->modified( aEvent );
     596           0 : }
     597             : 
     598             : // ____ XEventListener (base of XModifyListener) ____
     599           0 : void SAL_CALL Diagram::disposing( const lang::EventObject& /* Source */ )
     600             :     throw (uno::RuntimeException)
     601             : {
     602             :     // nothing
     603           0 : }
     604             : 
     605             : // ____ OPropertySet ____
     606         562 : void Diagram::firePropertyChangeEvent()
     607             : {
     608         562 :     fireModifyEvent();
     609         562 : }
     610             : 
     611         705 : void Diagram::fireModifyEvent()
     612             : {
     613         705 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     614         705 : }
     615             : 
     616             : // ============================================================
     617             : 
     618           1 : Sequence< OUString > Diagram::getSupportedServiceNames_Static()
     619             : {
     620           1 :     Sequence< OUString > aServices( 3 );
     621             : 
     622           1 :     aServices[ 0 ] = C2U( "com.sun.star.chart2.Diagram" );
     623           1 :     aServices[ 1 ] = C2U( "com.sun.star.layout.LayoutElement" );
     624           1 :     aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
     625           1 :     return aServices;
     626             : }
     627             : 
     628             : // ____ OPropertySet ____
     629        1618 : uno::Any Diagram::GetDefaultValue( sal_Int32 nHandle ) const
     630             :     throw(beans::UnknownPropertyException)
     631             : {
     632        1618 :     const tPropertyValueMap& rStaticDefaults = *StaticDiagramDefaults::get();
     633        1618 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     634        1618 :     if( aFound == rStaticDefaults.end() )
     635         601 :         return uno::Any();
     636        1017 :     return (*aFound).second;
     637             : }
     638             : 
     639             : // ____ OPropertySet ____
     640        3076 : ::cppu::IPropertyArrayHelper & SAL_CALL Diagram::getInfoHelper()
     641             : {
     642        3076 :     return *StaticDiagramInfoHelper::get();
     643             : }
     644             : 
     645             : // ____ XPropertySet ____
     646           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL Diagram::getPropertySetInfo()
     647             :     throw (uno::RuntimeException)
     648             : {
     649           0 :     return *StaticDiagramInfo::get();
     650             : }
     651             : 
     652             : // ____ XFastPropertySet ____
     653         562 : void SAL_CALL Diagram::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
     654             :     throw(beans::UnknownPropertyException,
     655             :           beans::PropertyVetoException,
     656             :           lang::IllegalArgumentException,
     657             :           lang::WrappedTargetException, uno::RuntimeException)
     658             : {
     659             :     //special treatment for some 3D properties
     660         562 :     if( PROP_DIAGRAM_PERSPECTIVE == nHandle )
     661             :     {
     662           0 :         sal_Int32 fPerspective = 20;
     663           0 :         if( rValue >>=fPerspective )
     664           0 :             ThreeDHelper::setCameraDistance( this, ThreeDHelper::PerspectiveToCameraDistance( fPerspective ) );
     665             :     }
     666         562 :     else if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle
     667             :         || PROP_DIAGRAM_ROTATION_VERTICAL == nHandle )
     668             :     {
     669           0 :         sal_Int32 nNewAngleDegree = 0;
     670           0 :         if( rValue >>=nNewAngleDegree )
     671             :         {
     672             :             sal_Int32 nHorizontal, nVertical;
     673           0 :             ThreeDHelper::getRotationFromDiagram( const_cast< Diagram* >( this ), nHorizontal, nVertical );
     674           0 :             if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle )
     675           0 :                 nHorizontal = nNewAngleDegree;
     676             :             else
     677           0 :                 nVertical = nNewAngleDegree;
     678           0 :             ThreeDHelper::setRotationToDiagram( this, nHorizontal, nVertical );
     679           0 :         }
     680             :     }
     681             :     else
     682         562 :         ::property::OPropertySet::setFastPropertyValue( nHandle, rValue );
     683         562 : }
     684             : 
     685        1376 : void SAL_CALL Diagram::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const
     686             : {
     687             :     //special treatment for some 3D properties
     688        1376 :     if( nHandle == PROP_DIAGRAM_PERSPECTIVE )
     689             :     {
     690             :         sal_Int32 nPerspective = ::basegfx::fround( ThreeDHelper::CameraDistanceToPerspective(
     691           0 :             ThreeDHelper::getCameraDistance( const_cast< Diagram* >( this ) ) ) );
     692           0 :         rValue = uno::makeAny(nPerspective);
     693             :     }
     694        1376 :     else if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle
     695             :         || PROP_DIAGRAM_ROTATION_VERTICAL == nHandle )
     696             :     {
     697             :         sal_Int32 nHorizontal, nVertical;
     698           0 :         ThreeDHelper::getRotationFromDiagram( const_cast< Diagram* >( this ), nHorizontal, nVertical );
     699           0 :         sal_Int32 nAngleDegree = 0;
     700           0 :         if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle )
     701           0 :             nAngleDegree = nHorizontal;
     702             :         else
     703           0 :             nAngleDegree = nVertical;
     704           0 :         rValue = uno::makeAny(nAngleDegree);
     705             :     }
     706             :     else
     707        1376 :         ::property::OPropertySet::getFastPropertyValue( rValue,nHandle );
     708        1376 : }
     709             : 
     710             : // ================================================================================
     711             : 
     712             : using impl::Diagram_Base;
     713             : 
     714       22157 : IMPLEMENT_FORWARD_XINTERFACE2( Diagram, Diagram_Base, ::property::OPropertySet )
     715           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( Diagram, Diagram_Base, ::property::OPropertySet )
     716             : 
     717             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     718          16 : APPHELPER_XSERVICEINFO_IMPL( Diagram,
     719             :                              C2U( "com.sun.star.comp.chart2.Diagram" ));
     720             : 
     721             : } //  namespace chart
     722             : 
     723             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10