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

Generated by: LCOV version 1.10