LCOV - code coverage report
Current view: top level - libreoffice/cui/source/options - cfgchart.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 139 0.0 %
Date: 2012-12-27 Functions: 0 33 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 <com/sun/star/uno/Sequence.hxx>
      21             : #include <tools/stream.hxx>            // header for SvStream
      22             : #include "cfgchart.hxx"
      23             : #include <dialmgr.hxx>
      24             : #include <cuires.hrc>
      25             : 
      26             : #define ROW_COLOR_COUNT 12
      27             : 
      28             : using namespace com::sun::star;
      29             : 
      30           0 : TYPEINIT1( SvxChartColorTableItem, SfxPoolItem );
      31             : 
      32           0 : SvxChartColorTable::SvxChartColorTable()
      33           0 : {}
      34             : 
      35           0 : SvxChartColorTable::SvxChartColorTable( const SvxChartColorTable & _rSource ) :
      36             :         m_aColorEntries( _rSource.m_aColorEntries ),
      37           0 :         nNextElementNumber( m_aColorEntries.size() + 1 )
      38           0 : {}
      39             : 
      40             : // accessors
      41           0 : size_t SvxChartColorTable::size() const
      42             : {
      43           0 :     return m_aColorEntries.size();
      44             : }
      45             : 
      46           0 : const XColorEntry & SvxChartColorTable::operator[]( size_t _nIndex ) const
      47             : {
      48           0 :     if ( _nIndex >= m_aColorEntries.size() )
      49             :     {
      50             :         SAL_WARN( "cui.options", "SvxChartColorTable::[] invalid index" );
      51           0 :         return m_aColorEntries[ 0 ];
      52             :     }
      53             : 
      54           0 :     return m_aColorEntries[ _nIndex ];
      55             : }
      56             : 
      57           0 : ColorData SvxChartColorTable::getColorData( size_t _nIndex ) const
      58             : {
      59           0 :     if ( _nIndex >= m_aColorEntries.size() )
      60             :     {
      61             :         SAL_WARN( "cui.options", "SvxChartColorTable::getColorData invalid index" );
      62           0 :         return COL_BLACK;
      63             :     }
      64             : 
      65             :     // GetColor should be const but unfortunately isn't
      66           0 :     return const_cast< XColorEntry & >( m_aColorEntries[ _nIndex ] ).GetColor().GetRGBColor();
      67             : }
      68             : 
      69             : // mutators
      70           0 : void SvxChartColorTable::clear()
      71             : {
      72           0 :     m_aColorEntries.clear();
      73           0 :     nNextElementNumber = 1;
      74           0 : }
      75             : 
      76           0 : void SvxChartColorTable::append( const XColorEntry & _rEntry )
      77             : {
      78           0 :     m_aColorEntries.push_back( _rEntry );
      79           0 : }
      80             : 
      81           0 : void SvxChartColorTable::remove( size_t _nIndex )
      82             : {
      83           0 :     if (m_aColorEntries.size() > 0)
      84           0 :         m_aColorEntries.erase( m_aColorEntries.begin() + _nIndex);
      85             : 
      86           0 :     for (size_t i=0 ; i<m_aColorEntries.size(); i++)
      87             :     {
      88           0 :         m_aColorEntries[ i ].SetName( getDefaultName( i ) );
      89             :     }
      90           0 : }
      91             : 
      92           0 : void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry )
      93             : {
      94             :     DBG_ASSERT( _nIndex <= m_aColorEntries.size(),
      95             :                 "SvxChartColorTable::replace invalid index" );
      96             : 
      97           0 :     m_aColorEntries[ _nIndex ] = _rEntry;
      98           0 : }
      99             : 
     100           0 : void SvxChartColorTable::useDefault()
     101             : {
     102             :     ColorData aColors[] = {
     103             :         RGB_COLORDATA( 0x00, 0x45, 0x86 ),
     104             :         RGB_COLORDATA( 0xff, 0x42, 0x0e ),
     105             :         RGB_COLORDATA( 0xff, 0xd3, 0x20 ),
     106             :         RGB_COLORDATA( 0x57, 0x9d, 0x1c ),
     107             :         RGB_COLORDATA( 0x7e, 0x00, 0x21 ),
     108             :         RGB_COLORDATA( 0x83, 0xca, 0xff ),
     109             :         RGB_COLORDATA( 0x31, 0x40, 0x04 ),
     110             :         RGB_COLORDATA( 0xae, 0xcf, 0x00 ),
     111             :         RGB_COLORDATA( 0x4b, 0x1f, 0x6f ),
     112             :         RGB_COLORDATA( 0xff, 0x95, 0x0e ),
     113             :         RGB_COLORDATA( 0xc5, 0x00, 0x0b ),
     114             :         RGB_COLORDATA( 0x00, 0x84, 0xd1 )
     115           0 :     };
     116             : 
     117           0 :     clear();
     118             : 
     119           0 :     for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
     120             :     {
     121           0 :         append( XColorEntry( aColors[ i % sizeof( aColors ) ], getDefaultName( i ) ));
     122             :     }
     123           0 : }
     124             : 
     125           0 : String SvxChartColorTable::getDefaultName( size_t _nIndex )
     126             : {
     127           0 :     String aName;
     128             : 
     129           0 :     if (sDefaultNamePrefix.Len() == 0)
     130             :     {
     131           0 :         String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) );
     132           0 :         xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" );
     133           0 :         if( nPos != STRING_NOTFOUND )
     134             :         {
     135           0 :             sDefaultNamePrefix = String( aResName, 0, nPos );
     136           0 :             sDefaultNamePostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN );
     137             :         }
     138             :         else
     139             :         {
     140           0 :             sDefaultNamePrefix = aResName;
     141           0 :         }
     142             :     }
     143             : 
     144           0 :     aName = sDefaultNamePrefix;
     145           0 :     aName.Append( String::CreateFromInt32 ( _nIndex + 1 ) );
     146           0 :     aName.Append( sDefaultNamePostfix );
     147           0 :     nNextElementNumber++;
     148             : 
     149           0 :     return aName;
     150             : }
     151             : 
     152             : // comparison
     153           0 : bool SvxChartColorTable::operator==( const SvxChartColorTable & _rOther ) const
     154             : {
     155             :     // note: XColorEntry has no operator ==
     156           0 :     bool bEqual = ( this->m_aColorEntries.size() == _rOther.m_aColorEntries.size() );
     157             : 
     158           0 :     if( bEqual )
     159             :     {
     160           0 :         for( size_t i = 0; i < m_aColorEntries.size(); ++i )
     161             :         {
     162           0 :             if( getColorData( i ) != _rOther.getColorData( i ))
     163             :             {
     164           0 :                 bEqual = false;
     165           0 :                 break;
     166             :             }
     167             :         }
     168             :     }
     169             : 
     170           0 :     return bEqual;
     171             : }
     172             : 
     173             : // ====================
     174             : // class SvxChartOptions
     175             : // ====================
     176             : 
     177           0 : SvxChartOptions::SvxChartOptions() :
     178             :     ::utl::ConfigItem( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office.Chart") ) ),
     179           0 :     mbIsInitialized( sal_False )
     180             : {
     181           0 :     maPropertyNames.realloc( 1 );
     182           0 :     maPropertyNames[ 0 ] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultColor/Series") );
     183           0 : }
     184             : 
     185           0 : SvxChartOptions::~SvxChartOptions()
     186             : {
     187           0 : }
     188             : 
     189           0 : const SvxChartColorTable& SvxChartOptions::GetDefaultColors()
     190             : {
     191           0 :     if ( !mbIsInitialized )
     192           0 :         mbIsInitialized = RetrieveOptions();
     193           0 :     return maDefColors;
     194             : }
     195             : 
     196           0 : void SvxChartOptions::SetDefaultColors( const SvxChartColorTable& aCol )
     197             : {
     198           0 :     maDefColors = aCol;
     199           0 :     SetModified();
     200           0 : }
     201             : 
     202           0 : sal_Bool SvxChartOptions::RetrieveOptions()
     203             : {
     204             :     // get sequence containing all properties
     205             : 
     206           0 :     uno::Sequence< ::rtl::OUString > aNames = GetPropertyNames();
     207           0 :     uno::Sequence< uno::Any > aProperties( aNames.getLength());
     208           0 :     aProperties = GetProperties( aNames );
     209             : 
     210           0 :     if( aProperties.getLength() == aNames.getLength())
     211             :     {
     212             :         // 1. default colors for series
     213           0 :         maDefColors.clear();
     214           0 :         uno::Sequence< sal_Int64 > aColorSeq;
     215           0 :         aProperties[ 0 ] >>= aColorSeq;
     216             : 
     217           0 :         sal_Int32 nCount = aColorSeq.getLength();
     218           0 :         Color aCol;
     219             : 
     220             :         // create strings for entry names
     221           0 :         String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) );
     222           0 :         String aPrefix, aPostfix, aName;
     223           0 :         xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" );
     224           0 :         if( nPos != STRING_NOTFOUND )
     225             :         {
     226           0 :             aPrefix = String( aResName, 0, nPos );
     227           0 :             aPostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN );
     228             :         }
     229             :         else
     230           0 :             aPrefix = aResName;
     231             : 
     232             :         // set color values
     233           0 :         for( sal_Int32 i=0; i < nCount; i++ )
     234             :         {
     235           0 :             aCol.SetColor( (static_cast< ColorData >(aColorSeq[ i ] )));
     236             : 
     237           0 :             aName = aPrefix;
     238           0 :             aName.Append( String::CreateFromInt32( i + 1 ));
     239           0 :             aName.Append( aPostfix );
     240             : 
     241           0 :             maDefColors.append( XColorEntry( aCol, aName ));
     242             :         }
     243           0 :         return sal_True;
     244             :     }
     245           0 :     return sal_False;
     246             : }
     247             : 
     248           0 : void SvxChartOptions::Commit()
     249             : {
     250           0 :     uno::Sequence< ::rtl::OUString > aNames = GetPropertyNames();
     251           0 :     uno::Sequence< uno::Any > aValues( aNames.getLength());
     252             : 
     253           0 :     if( aValues.getLength() >= 1 )
     254             :     {
     255             :         // 1. default colors for series
     256             :         // convert list to sequence
     257           0 :         const size_t nCount = maDefColors.size();
     258           0 :         uno::Sequence< sal_Int64 > aColors( nCount );
     259           0 :         for( size_t i=0; i < nCount; i++ )
     260             :         {
     261           0 :             ColorData aData = maDefColors.getColorData( i );
     262           0 :             aColors[ i ] = aData;
     263             :         }
     264             : 
     265           0 :         aValues[ 0 ] <<= aColors;
     266             :     }
     267             : 
     268           0 :     PutProperties( aNames, aValues );
     269           0 : }
     270             : 
     271           0 : void SvxChartOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
     272             : {
     273           0 : }
     274             : 
     275             : // --------------------
     276             : // class SvxChartColorTableItem
     277             : // --------------------
     278             : 
     279           0 : SvxChartColorTableItem::SvxChartColorTableItem( sal_uInt16 nWhich_, const SvxChartColorTable& aTable ) :
     280             :     SfxPoolItem( nWhich_ ),
     281           0 :     m_aColorTable( aTable )
     282             : {
     283           0 : }
     284             : 
     285           0 : SvxChartColorTableItem::SvxChartColorTableItem( const SvxChartColorTableItem& rOther ) :
     286             :     SfxPoolItem( rOther ),
     287           0 :     m_aColorTable( rOther.m_aColorTable )
     288             : {
     289           0 : }
     290             : 
     291           0 : SfxPoolItem* SvxChartColorTableItem::Clone( SfxItemPool * ) const
     292             : {
     293           0 :     return new SvxChartColorTableItem( *this );
     294             : }
     295             : 
     296           0 : int SvxChartColorTableItem::operator==( const SfxPoolItem& rAttr ) const
     297             : {
     298             :     DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "SvxChartColorTableItem::operator== : types differ" );
     299             : 
     300           0 :     const SvxChartColorTableItem * rCTItem( dynamic_cast< const SvxChartColorTableItem * >( & rAttr ));
     301           0 :     if( rCTItem )
     302             :     {
     303           0 :         return (this->m_aColorTable == rCTItem->GetColorList());
     304             :     }
     305             : 
     306           0 :     return 0;
     307             : }
     308             : 
     309           0 : void SvxChartColorTableItem::SetOptions( SvxChartOptions* pOpts ) const
     310             : {
     311           0 :     if ( pOpts )
     312           0 :         pOpts->SetDefaultColors( m_aColorTable );
     313           0 : }
     314             : 
     315             : 
     316           0 : SvxChartColorTable & SvxChartColorTableItem::GetColorList()
     317             : {
     318           0 :     return m_aColorTable;
     319             : }
     320             : 
     321           0 : const SvxChartColorTable & SvxChartColorTableItem::GetColorList() const
     322             : {
     323           0 :     return m_aColorTable;
     324             : }
     325             : 
     326           0 : void SvxChartColorTableItem::ReplaceColorByIndex( size_t _nIndex, const XColorEntry & _rEntry )
     327             : {
     328           0 :     m_aColorTable.replace( _nIndex, _rEntry );
     329           0 : }
     330             : 
     331             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10