LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - GridWrapper.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 53 63 84.1 %
Date: 2014-04-11 Functions: 15 19 78.9 %
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 "GridWrapper.hxx"
      21             : #include "macros.hxx"
      22             : #include "AxisHelper.hxx"
      23             : #include "Chart2ModelContact.hxx"
      24             : #include "ContainerHelper.hxx"
      25             : #include "AxisIndexDefines.hxx"
      26             : #include <comphelper/InlineContainer.hxx>
      27             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      28             : 
      29             : #include "LinePropertiesHelper.hxx"
      30             : #include "UserDefinedProperties.hxx"
      31             : #include "WrappedDefaultProperty.hxx"
      32             : 
      33             : #include <algorithm>
      34             : #include <rtl/ustrbuf.hxx>
      35             : #include <rtl/math.hxx>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::chart2;
      39             : 
      40             : using ::com::sun::star::beans::Property;
      41             : using ::osl::MutexGuard;
      42             : using ::com::sun::star::uno::Reference;
      43             : using ::com::sun::star::uno::Sequence;
      44             : 
      45             : namespace
      46             : {
      47          15 : static const OUString lcl_aServiceName( "com.sun.star.comp.chart.Grid" );
      48             : 
      49             : struct StaticGridWrapperPropertyArray_Initializer
      50             : {
      51           9 :     Sequence< Property >* operator()()
      52             :     {
      53           9 :         static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
      54           9 :         return &aPropSeq;
      55             :     }
      56             : private:
      57           9 :     Sequence< Property > lcl_GetPropertySequence()
      58             :     {
      59           9 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      60           9 :         ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
      61           9 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
      62             : 
      63             :         ::std::sort( aProperties.begin(), aProperties.end(),
      64           9 :                      ::chart::PropertyNameLess() );
      65             : 
      66           9 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
      67             :     }
      68             : };
      69             : 
      70             : struct StaticGridWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticGridWrapperPropertyArray_Initializer >
      71             : {
      72             : };
      73             : 
      74             : } // anonymous namespace
      75             : 
      76             : namespace chart
      77             : {
      78             : namespace wrapper
      79             : {
      80             : 
      81         163 : GridWrapper::GridWrapper(
      82             :     tGridType eType, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
      83             :         m_spChart2ModelContact( spChart2ModelContact ),
      84             :         m_aEventListenerContainer( m_aMutex ),
      85         163 :         m_eType( eType )
      86             : {
      87         163 : }
      88             : 
      89         320 : GridWrapper::~GridWrapper()
      90         320 : {}
      91             : 
      92        4060 : void GridWrapper::getDimensionAndSubGridBool( tGridType eType, sal_Int32& rnDimensionIndex, bool& rbSubGrid )
      93             : {
      94        4060 :     rnDimensionIndex = 1;
      95        4060 :     rbSubGrid = false;
      96             : 
      97        4060 :     switch( eType )
      98             :     {
      99             :         case X_MAJOR_GRID:
     100         557 :             rnDimensionIndex = 0; rbSubGrid = false; break;
     101             :         case Y_MAJOR_GRID:
     102        2707 :             rnDimensionIndex = 1; rbSubGrid = false; break;
     103             :         case Z_MAJOR_GRID:
     104           0 :             rnDimensionIndex = 2; rbSubGrid = false; break;
     105             :         case X_MINOR_GRID:
     106           0 :             rnDimensionIndex = 0; rbSubGrid = true;  break;
     107             :         case Y_MINOR_GRID:
     108         796 :             rnDimensionIndex = 1; rbSubGrid = true;  break;
     109             :         case Z_MINOR_GRID:
     110           0 :             rnDimensionIndex = 2; rbSubGrid = true;  break;
     111             :     }
     112        4060 : }
     113             : 
     114             : // ____ XComponent ____
     115         158 : void SAL_CALL GridWrapper::dispose()
     116             :     throw (uno::RuntimeException, std::exception)
     117             : {
     118         158 :     Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
     119         158 :     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
     120             : 
     121         158 :     clearWrappedPropertySet();
     122         158 : }
     123             : 
     124           0 : void SAL_CALL GridWrapper::addEventListener(
     125             :     const Reference< lang::XEventListener >& xListener )
     126             :     throw (uno::RuntimeException, std::exception)
     127             : {
     128           0 :     m_aEventListenerContainer.addInterface( xListener );
     129           0 : }
     130             : 
     131           0 : void SAL_CALL GridWrapper::removeEventListener(
     132             :     const Reference< lang::XEventListener >& aListener )
     133             :     throw (uno::RuntimeException, std::exception)
     134             : {
     135           0 :     m_aEventListenerContainer.removeInterface( aListener );
     136           0 : }
     137             : 
     138             : // WrappedPropertySet
     139             : 
     140        4060 : Reference< beans::XPropertySet > GridWrapper::getInnerPropertySet()
     141             : {
     142        4060 :     Reference< beans::XPropertySet > xRet;
     143             :     try
     144             :     {
     145        4060 :         Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     146        8120 :         uno::Reference< XCoordinateSystem > xCooSys( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 /*nCooSysIndex*/ ) );
     147             : 
     148        4060 :         sal_Int32 nDimensionIndex = 1;
     149        4060 :         bool bSubGrid = false;
     150        4060 :         getDimensionAndSubGridBool( m_eType, nDimensionIndex, bSubGrid );
     151             : 
     152        4060 :         sal_Int32 nSubGridIndex = bSubGrid ? 0 : -1;
     153        8120 :         xRet.set( AxisHelper::getGridProperties( xCooSys , nDimensionIndex, MAIN_AXIS_INDEX, nSubGridIndex ) );
     154             :     }
     155           0 :     catch( const uno::Exception & ex )
     156             :     {
     157             :         ASSERT_EXCEPTION( ex );
     158             :     }
     159        4060 :     return xRet;
     160             : }
     161             : 
     162         157 : const Sequence< beans::Property >& GridWrapper::getPropertySequence()
     163             : {
     164         157 :     return *StaticGridWrapperPropertyArray::get();
     165             : }
     166             : 
     167         157 : const std::vector< WrappedProperty* > GridWrapper::createWrappedProperties()
     168             : {
     169         157 :     ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
     170             : 
     171         157 :     aWrappedProperties.push_back( new WrappedDefaultProperty( "LineColor", "LineColor", uno::makeAny( sal_Int32( 0x000000) ) ) ); // black
     172             : 
     173         157 :     return aWrappedProperties;
     174             : }
     175             : 
     176           1 : Sequence< OUString > GridWrapper::getSupportedServiceNames_Static()
     177             : {
     178           1 :     Sequence< OUString > aServices( 4 );
     179           1 :     aServices[ 0 ] = "com.sun.star.chart.ChartGrid";
     180           1 :     aServices[ 1 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
     181           1 :     aServices[ 2 ] = "com.sun.star.drawing.LineProperties";
     182           1 :     aServices[ 3 ] = "com.sun.star.beans.PropertySet";
     183             : 
     184           1 :     return aServices;
     185             : }
     186             : 
     187             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     188           2 : APPHELPER_XSERVICEINFO_IMPL( GridWrapper, lcl_aServiceName );
     189             : 
     190             : } //  namespace wrapper
     191          45 : } //  namespace chart
     192             : 
     193             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10