1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_cui.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx> 32*cdf0e10cSrcweir // header for SvStream 33*cdf0e10cSrcweir #include <tools/stream.hxx> 34*cdf0e10cSrcweir // header for SAL_STATIC_CAST 35*cdf0e10cSrcweir #include <sal/types.h> 36*cdf0e10cSrcweir #include "cfgchart.hxx" 37*cdf0e10cSrcweir #include <dialmgr.hxx> 38*cdf0e10cSrcweir #include <cuires.hrc> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #define ROW_COLOR_COUNT 12 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir using namespace com::sun::star; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir TYPEINIT1( SvxChartColorTableItem, SfxPoolItem ); 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir SvxChartColorTable::SvxChartColorTable() 47*cdf0e10cSrcweir {} 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir SvxChartColorTable::SvxChartColorTable( const SvxChartColorTable & _rSource ) : 50*cdf0e10cSrcweir m_aColorEntries( _rSource.m_aColorEntries ) 51*cdf0e10cSrcweir {} 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir // accessors 54*cdf0e10cSrcweir size_t SvxChartColorTable::size() const 55*cdf0e10cSrcweir { 56*cdf0e10cSrcweir return m_aColorEntries.size(); 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir const XColorEntry & SvxChartColorTable::operator[]( size_t _nIndex ) const 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir if ( _nIndex >= m_aColorEntries.size() ) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir DBG_ERRORFILE( "SvxChartColorTable::[] invalid index" ); 64*cdf0e10cSrcweir return m_aColorEntries[ 0 ]; 65*cdf0e10cSrcweir } 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir return m_aColorEntries[ _nIndex ]; 68*cdf0e10cSrcweir } 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir ColorData SvxChartColorTable::getColorData( size_t _nIndex ) const 71*cdf0e10cSrcweir { 72*cdf0e10cSrcweir if ( _nIndex >= m_aColorEntries.size() ) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir DBG_ERRORFILE( "SvxChartColorTable::getColorData invalid index" ); 75*cdf0e10cSrcweir return COL_BLACK; 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir // GetColor should be const but unfortunately isn't 79*cdf0e10cSrcweir return const_cast< XColorEntry & >( m_aColorEntries[ _nIndex ] ).GetColor().GetRGBColor(); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // mutators 83*cdf0e10cSrcweir void SvxChartColorTable::clear() 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir m_aColorEntries.clear(); 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir void SvxChartColorTable::append( const XColorEntry & _rEntry ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir m_aColorEntries.push_back( _rEntry ); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry ) 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir DBG_ASSERT( _nIndex <= m_aColorEntries.size(), 96*cdf0e10cSrcweir "SvxChartColorTable::replace invalid index" ); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir Color aCol1 = m_aColorEntries[ _nIndex ].GetColor(), aCol2; 99*cdf0e10cSrcweir m_aColorEntries[ _nIndex ] = _rEntry; 100*cdf0e10cSrcweir aCol2 = m_aColorEntries[ _nIndex ].GetColor(); 101*cdf0e10cSrcweir if ( aCol2 != const_cast< XColorEntry& >( _rEntry ).GetColor() ) 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir DBG_ERRORFILE( "wrong color" ); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir void SvxChartColorTable::useDefault() 108*cdf0e10cSrcweir { 109*cdf0e10cSrcweir ColorData aColors[] = { 110*cdf0e10cSrcweir RGB_COLORDATA( 0x00, 0x45, 0x86 ), 111*cdf0e10cSrcweir RGB_COLORDATA( 0xff, 0x42, 0x0e ), 112*cdf0e10cSrcweir RGB_COLORDATA( 0xff, 0xd3, 0x20 ), 113*cdf0e10cSrcweir RGB_COLORDATA( 0x57, 0x9d, 0x1c ), 114*cdf0e10cSrcweir RGB_COLORDATA( 0x7e, 0x00, 0x21 ), 115*cdf0e10cSrcweir RGB_COLORDATA( 0x83, 0xca, 0xff ), 116*cdf0e10cSrcweir RGB_COLORDATA( 0x31, 0x40, 0x04 ), 117*cdf0e10cSrcweir RGB_COLORDATA( 0xae, 0xcf, 0x00 ), 118*cdf0e10cSrcweir RGB_COLORDATA( 0x4b, 0x1f, 0x6f ), 119*cdf0e10cSrcweir RGB_COLORDATA( 0xff, 0x95, 0x0e ), 120*cdf0e10cSrcweir RGB_COLORDATA( 0xc5, 0x00, 0x0b ), 121*cdf0e10cSrcweir RGB_COLORDATA( 0x00, 0x84, 0xd1 ) 122*cdf0e10cSrcweir }; 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir clear(); 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) ); 127*cdf0e10cSrcweir String aPrefix, aPostfix, aName; 128*cdf0e10cSrcweir xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" ); 129*cdf0e10cSrcweir if( nPos != STRING_NOTFOUND ) 130*cdf0e10cSrcweir { 131*cdf0e10cSrcweir aPrefix = String( aResName, 0, nPos ); 132*cdf0e10cSrcweir aPostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN ); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir else 135*cdf0e10cSrcweir aPrefix = aResName; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir aName = aPrefix; 140*cdf0e10cSrcweir aName.Append( String::CreateFromInt32( i + 1 )); 141*cdf0e10cSrcweir aName.Append( aPostfix ); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir append( XColorEntry( aColors[ i % sizeof( aColors ) ], aName )); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // comparison 148*cdf0e10cSrcweir bool SvxChartColorTable::operator==( const SvxChartColorTable & _rOther ) const 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir // note: XColorEntry has no operator == 151*cdf0e10cSrcweir bool bEqual = ( this->m_aColorEntries.size() == _rOther.m_aColorEntries.size() ); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir if( bEqual ) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir for( size_t i = 0; i < m_aColorEntries.size(); ++i ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir if( getColorData( i ) != _rOther.getColorData( i )) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir bEqual = false; 160*cdf0e10cSrcweir break; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir return bEqual; 166*cdf0e10cSrcweir } 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // ==================== 169*cdf0e10cSrcweir // class SvxChartOptions 170*cdf0e10cSrcweir // ==================== 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir SvxChartOptions::SvxChartOptions() : 173*cdf0e10cSrcweir ::utl::ConfigItem( rtl::OUString::createFromAscii( "Office.Chart" )), 174*cdf0e10cSrcweir mbIsInitialized( sal_False ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir maPropertyNames.realloc( 1 ); 177*cdf0e10cSrcweir maPropertyNames[ 0 ] = ::rtl::OUString::createFromAscii( "DefaultColor/Series" ); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir SvxChartOptions::~SvxChartOptions() 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir const SvxChartColorTable& SvxChartOptions::GetDefaultColors() 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir if ( !mbIsInitialized ) 187*cdf0e10cSrcweir mbIsInitialized = RetrieveOptions(); 188*cdf0e10cSrcweir return maDefColors; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir void SvxChartOptions::SetDefaultColors( const SvxChartColorTable& aCol ) 192*cdf0e10cSrcweir { 193*cdf0e10cSrcweir maDefColors = aCol; 194*cdf0e10cSrcweir SetModified(); 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir sal_Bool SvxChartOptions::RetrieveOptions() 198*cdf0e10cSrcweir { 199*cdf0e10cSrcweir // get sequence containing all properties 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aNames = GetPropertyNames(); 202*cdf0e10cSrcweir uno::Sequence< uno::Any > aProperties( aNames.getLength()); 203*cdf0e10cSrcweir aProperties = GetProperties( aNames ); 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir if( aProperties.getLength() == aNames.getLength()) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir // 1. default colors for series 208*cdf0e10cSrcweir maDefColors.clear(); 209*cdf0e10cSrcweir uno::Sequence< sal_Int64 > aColorSeq; 210*cdf0e10cSrcweir aProperties[ 0 ] >>= aColorSeq; 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir sal_Int32 nCount = aColorSeq.getLength(); 213*cdf0e10cSrcweir Color aCol; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // create strings for entry names 216*cdf0e10cSrcweir String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) ); 217*cdf0e10cSrcweir String aPrefix, aPostfix, aName; 218*cdf0e10cSrcweir xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" ); 219*cdf0e10cSrcweir if( nPos != STRING_NOTFOUND ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir aPrefix = String( aResName, 0, nPos ); 222*cdf0e10cSrcweir aPostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN ); 223*cdf0e10cSrcweir } 224*cdf0e10cSrcweir else 225*cdf0e10cSrcweir aPrefix = aResName; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir // set color values 228*cdf0e10cSrcweir for( sal_Int32 i=0; i < nCount; i++ ) 229*cdf0e10cSrcweir { 230*cdf0e10cSrcweir aCol.SetColor( SAL_STATIC_CAST( ColorData, aColorSeq[ i ] )); 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir aName = aPrefix; 233*cdf0e10cSrcweir aName.Append( String::CreateFromInt32( i + 1 )); 234*cdf0e10cSrcweir aName.Append( aPostfix ); 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir maDefColors.append( XColorEntry( aCol, aName )); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir return sal_True; 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir return sal_False; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir void SvxChartOptions::Commit() 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aNames = GetPropertyNames(); 246*cdf0e10cSrcweir uno::Sequence< uno::Any > aValues( aNames.getLength()); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir if( aValues.getLength() >= 1 ) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir // 1. default colors for series 251*cdf0e10cSrcweir // convert list to sequence 252*cdf0e10cSrcweir const size_t nCount = maDefColors.size(); 253*cdf0e10cSrcweir uno::Sequence< sal_Int64 > aColors( nCount ); 254*cdf0e10cSrcweir for( size_t i=0; i < nCount; i++ ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir ColorData aData = maDefColors.getColorData( i ); 257*cdf0e10cSrcweir aColors[ i ] = aData; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir aValues[ 0 ] <<= aColors; 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir PutProperties( aNames, aValues ); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir void SvxChartOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir } 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir // -------------------- 271*cdf0e10cSrcweir // class SvxChartColorTableItem 272*cdf0e10cSrcweir // -------------------- 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir SvxChartColorTableItem::SvxChartColorTableItem( sal_uInt16 nWhich_, const SvxChartColorTable& aTable ) : 275*cdf0e10cSrcweir SfxPoolItem( nWhich_ ), 276*cdf0e10cSrcweir m_aColorTable( aTable ) 277*cdf0e10cSrcweir { 278*cdf0e10cSrcweir } 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir SvxChartColorTableItem::SvxChartColorTableItem( const SvxChartColorTableItem& rOther ) : 281*cdf0e10cSrcweir SfxPoolItem( rOther ), 282*cdf0e10cSrcweir m_aColorTable( rOther.m_aColorTable ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir SfxPoolItem* __EXPORT SvxChartColorTableItem::Clone( SfxItemPool * ) const 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir return new SvxChartColorTableItem( *this ); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir int __EXPORT SvxChartColorTableItem::operator==( const SfxPoolItem& rAttr ) const 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "SvxChartColorTableItem::operator== : types differ" ); 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir const SvxChartColorTableItem * rCTItem( dynamic_cast< const SvxChartColorTableItem * >( & rAttr )); 296*cdf0e10cSrcweir if( rCTItem ) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir return (this->m_aColorTable == rCTItem->GetColorTable()); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir return 0; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir void __EXPORT SvxChartColorTableItem::SetOptions( SvxChartOptions* pOpts ) const 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir if ( pOpts ) 307*cdf0e10cSrcweir pOpts->SetDefaultColors( m_aColorTable ); 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir SvxChartColorTable & SvxChartColorTableItem::GetColorTable() 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir return m_aColorTable; 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir 316*cdf0e10cSrcweir const SvxChartColorTable & SvxChartColorTableItem::GetColorTable() const 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir return m_aColorTable; 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir void SvxChartColorTableItem::ReplaceColorByIndex( size_t _nIndex, const XColorEntry & _rEntry ) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir m_aColorTable.replace( _nIndex, _rEntry ); 324*cdf0e10cSrcweir } 325