LCOV - code coverage report
Current view: top level - chart2/source/tools - ConfigColorScheme.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 39 55 70.9 %
Date: 2012-08-25 Functions: 14 21 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 32 84 38.1 %

           Branch data     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                 :            : 
      21                 :            : #include "ConfigColorScheme.hxx"
      22                 :            : #include "ContainerHelper.hxx"
      23                 :            : #include "macros.hxx"
      24                 :            : 
      25                 :            : #include <unotools/configitem.hxx>
      26                 :            : #include <sal/macros.h>
      27                 :            : 
      28                 :            : #include <set>
      29                 :            : 
      30                 :            : using namespace ::com::sun::star;
      31                 :            : 
      32                 :            : using ::com::sun::star::uno::Reference;
      33                 :            : using ::com::sun::star::uno::Sequence;
      34                 :            : using ::rtl::OUString;
      35                 :            : 
      36                 :            : namespace
      37                 :            : {
      38                 :            : 
      39                 :         16 : static const OUString aSeriesPropName( RTL_CONSTASCII_USTRINGPARAM("Series"));
      40                 :            : 
      41                 :            : } // anonymous namespace
      42                 :            : 
      43                 :            : // --------------------------------------------------------------------------------
      44                 :            : 
      45                 :            : namespace chart
      46                 :            : {
      47                 :            : 
      48                 :         59 : uno::Reference< chart2::XColorScheme > createConfigColorScheme( const uno::Reference< uno::XComponentContext > & xContext )
      49                 :            : {
      50 [ +  - ][ +  - ]:         59 :     return new ConfigColorScheme( xContext );
      51                 :            : }
      52                 :            : 
      53                 :            : namespace impl
      54                 :            : {
      55                 :            : class ChartConfigItem : public ::utl::ConfigItem
      56                 :            : {
      57                 :            : public:
      58                 :            :     explicit ChartConfigItem( ConfigItemListener & rListener );
      59                 :            :     virtual ~ChartConfigItem();
      60                 :            : 
      61                 :            :     void addPropertyNotification( const OUString & rPropertyName );
      62                 :            : 
      63                 :            :     uno::Any getProperty( const OUString & aPropertyName );
      64                 :            : 
      65                 :            : protected:
      66                 :            :     // ____ ::utl::ConfigItem ____
      67                 :            :     virtual void                    Commit();
      68                 :            :     virtual void Notify( const Sequence< OUString > & aPropertyNames );
      69                 :            : 
      70                 :            : private:
      71                 :            :     ConfigItemListener & m_rListener;
      72                 :            :     ::std::set< OUString >        m_aPropertiesToNotify;
      73                 :            : };
      74                 :            : 
      75                 :         50 : ChartConfigItem::ChartConfigItem( ConfigItemListener & rListener ) :
      76                 :            :         ::utl::ConfigItem( C2U("Office.Chart/DefaultColor")),
      77 [ +  - ][ +  - ]:         50 :     m_rListener( rListener )
      78                 :         50 : {}
      79                 :            : 
      80                 :         50 : ChartConfigItem::~ChartConfigItem()
      81         [ -  + ]:        100 : {}
      82                 :            : 
      83                 :          0 : void ChartConfigItem::Notify( const Sequence< OUString > & aPropertyNames )
      84                 :            : {
      85         [ #  # ]:          0 :     for( sal_Int32 nIdx=0; nIdx<aPropertyNames.getLength(); ++nIdx )
      86                 :            :     {
      87 [ #  # ][ #  # ]:          0 :         if( m_aPropertiesToNotify.find( aPropertyNames[nIdx] ) != m_aPropertiesToNotify.end())
      88                 :          0 :             m_rListener.notify( aPropertyNames[nIdx] );
      89                 :            :     }
      90                 :          0 : }
      91                 :            : 
      92                 :          0 : void ChartConfigItem::Commit()
      93                 :          0 : {}
      94                 :            : 
      95                 :         50 : void ChartConfigItem::addPropertyNotification( const OUString & rPropertyName )
      96                 :            : {
      97                 :         50 :     m_aPropertiesToNotify.insert( rPropertyName );
      98         [ +  - ]:         50 :     EnableNotification( ContainerHelper::ContainerToSequence( m_aPropertiesToNotify ));
      99                 :         50 : }
     100                 :            : 
     101                 :         50 : uno::Any ChartConfigItem::getProperty( const OUString & aPropertyName )
     102                 :            : {
     103                 :            :     Sequence< uno::Any > aValues(
     104 [ +  - ][ +  - ]:         50 :         GetProperties( Sequence< OUString >( &aPropertyName, 1 )));
                 [ +  - ]
     105         [ -  + ]:         50 :     if( ! aValues.getLength())
     106                 :          0 :         return uno::Any();
     107 [ +  - ][ +  - ]:         50 :     return aValues[0];
     108                 :            : }
     109                 :            : 
     110                 :            : } // namespace impl
     111                 :            : 
     112                 :            : // --------------------------------------------------------------------------------
     113                 :            : 
     114                 :            : // explicit
     115                 :         59 : ConfigColorScheme::ConfigColorScheme(
     116                 :            :     const Reference< uno::XComponentContext > & xContext ) :
     117                 :            :         m_xContext( xContext  ),
     118                 :            :         m_nNumberOfColors( 0 ),
     119 [ +  - ][ +  - ]:         59 :         m_bNeedsUpdate( true )
     120                 :            : {
     121                 :         59 : }
     122                 :            : 
     123 [ +  - ][ +  - ]:         59 : ConfigColorScheme::~ConfigColorScheme()
                 [ +  - ]
     124         [ -  + ]:        118 : {}
     125                 :            : 
     126                 :         50 : void ConfigColorScheme::retrieveConfigColors()
     127                 :            : {
     128         [ +  - ]:         50 :     if( ! m_xContext.is())
     129                 :            :         return;
     130                 :            : 
     131                 :            :     // create config item if necessary
     132         [ +  - ]:         50 :     if( ! m_apChartConfigItem.get())
     133                 :            :     {
     134                 :            :         m_apChartConfigItem.reset(
     135 [ +  - ][ +  - ]:         50 :             new impl::ChartConfigItem( *this ));
     136         [ +  - ]:         50 :         m_apChartConfigItem->addPropertyNotification( aSeriesPropName );
     137                 :            :     }
     138                 :            :     OSL_ASSERT( m_apChartConfigItem.get());
     139         [ +  - ]:         50 :     if( ! m_apChartConfigItem.get())
     140                 :            :         return;
     141                 :            : 
     142                 :            :     // retrieve colors
     143                 :            :     uno::Any aValue(
     144         [ +  - ]:         50 :         m_apChartConfigItem->getProperty( aSeriesPropName ));
     145 [ +  - ][ +  - ]:         50 :     if( aValue >>= m_aColorSequence )
     146                 :         50 :         m_nNumberOfColors = m_aColorSequence.getLength();
     147                 :         50 :     m_bNeedsUpdate = false;
     148                 :            : }
     149                 :            : 
     150                 :            : // ____ XColorScheme ____
     151                 :        450 : ::sal_Int32 SAL_CALL ConfigColorScheme::getColorByIndex( ::sal_Int32 nIndex )
     152                 :            :     throw (uno::RuntimeException)
     153                 :            : {
     154         [ +  + ]:        450 :     if( m_bNeedsUpdate )
     155                 :         50 :         retrieveConfigColors();
     156                 :            : 
     157         [ +  - ]:        450 :     if( m_nNumberOfColors > 0 )
     158                 :        450 :         return static_cast< sal_Int32 >( m_aColorSequence[ nIndex % m_nNumberOfColors ] );
     159                 :            : 
     160                 :            :     // fall-back: hard-coded standard colors
     161                 :            :     static sal_Int32 nDefaultColors[] =  {
     162                 :            :         0x9999ff, 0x993366, 0xffffcc,
     163                 :            :         0xccffff, 0x660066, 0xff8080,
     164                 :            :         0x0066cc, 0xccccff, 0x000080,
     165                 :            :         0xff00ff, 0x00ffff, 0xffff00
     166                 :            :     };
     167                 :            : 
     168                 :            :     static const sal_Int32 nMaxDefaultColors = SAL_N_ELEMENTS( nDefaultColors );
     169                 :        450 :     return nDefaultColors[ nIndex % nMaxDefaultColors ];
     170                 :            : }
     171                 :            : 
     172                 :          0 : void ConfigColorScheme::notify( const OUString & rPropertyName )
     173                 :            : {
     174         [ #  # ]:          0 :     if( rPropertyName.equals( aSeriesPropName ))
     175                 :          0 :         m_bNeedsUpdate = true;
     176                 :          0 : }
     177                 :            : 
     178                 :            : // ================================================================================
     179                 :            : 
     180                 :          0 : Sequence< OUString > ConfigColorScheme::getSupportedServiceNames_Static()
     181                 :            : {
     182                 :          0 :     Sequence< OUString > aServices( 1 );
     183 [ #  # ][ #  # ]:          0 :     aServices[ 0 ] = C2U( "com.sun.star.chart2.ColorScheme" );
     184                 :          0 :     return aServices;
     185                 :            : }
     186                 :            : 
     187                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     188 [ #  # ][ #  # ]:         30 : APPHELPER_XSERVICEINFO_IMPL( ConfigColorScheme,
         [ #  # ][ #  # ]
                 [ #  # ]
     189                 :            :                              C2U( "com.sun.star.comp.chart2.ConfigDefaultColorScheme" ))
     190                 :            : 
     191                 :            : // ================================================================================
     192                 :            : 
     193 [ +  - ][ +  - ]:         48 : } //  namespace chart
     194                 :            : 
     195                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10