masterfix DEV300: #i10000# build fix
[LibreOffice.git] / cui / source / options / cfgchart.cxx
blob64c631266e3f72e2973cc1119b4783ba6298b877
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_cui.hxx"
31 #include <com/sun/star/uno/Sequence.hxx>
32 // header for SvStream
33 #include <tools/stream.hxx>
34 // header for SAL_STATIC_CAST
35 #include <sal/types.h>
36 #include "cfgchart.hxx"
37 #include <dialmgr.hxx>
38 #include <cuires.hrc>
40 #define ROW_COLOR_COUNT 12
42 using namespace com::sun::star;
44 TYPEINIT1( SvxChartColorTableItem, SfxPoolItem );
46 SvxChartColorTable::SvxChartColorTable()
49 SvxChartColorTable::SvxChartColorTable( const SvxChartColorTable & _rSource ) :
50 m_aColorEntries( _rSource.m_aColorEntries )
53 // accessors
54 size_t SvxChartColorTable::size() const
56 return m_aColorEntries.size();
59 const XColorEntry & SvxChartColorTable::operator[]( size_t _nIndex ) const
61 if ( _nIndex >= m_aColorEntries.size() )
63 DBG_ERRORFILE( "SvxChartColorTable::[] invalid index" );
64 return m_aColorEntries[ 0 ];
67 return m_aColorEntries[ _nIndex ];
70 ColorData SvxChartColorTable::getColorData( size_t _nIndex ) const
72 if ( _nIndex >= m_aColorEntries.size() )
74 DBG_ERRORFILE( "SvxChartColorTable::getColorData invalid index" );
75 return COL_BLACK;
78 // GetColor should be const but unfortunately isn't
79 return const_cast< XColorEntry & >( m_aColorEntries[ _nIndex ] ).GetColor().GetRGBColor();
82 // mutators
83 void SvxChartColorTable::clear()
85 m_aColorEntries.clear();
88 void SvxChartColorTable::append( const XColorEntry & _rEntry )
90 m_aColorEntries.push_back( _rEntry );
93 void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry )
95 DBG_ASSERT( _nIndex <= m_aColorEntries.size(),
96 "SvxChartColorTable::replace invalid index" );
98 Color aCol1 = m_aColorEntries[ _nIndex ].GetColor(), aCol2;
99 m_aColorEntries[ _nIndex ] = _rEntry;
100 aCol2 = m_aColorEntries[ _nIndex ].GetColor();
101 if ( aCol2 != const_cast< XColorEntry& >( _rEntry ).GetColor() )
103 DBG_ERRORFILE( "wrong color" );
107 void SvxChartColorTable::useDefault()
109 ColorData aColors[] = {
110 RGB_COLORDATA( 0x00, 0x45, 0x86 ),
111 RGB_COLORDATA( 0xff, 0x42, 0x0e ),
112 RGB_COLORDATA( 0xff, 0xd3, 0x20 ),
113 RGB_COLORDATA( 0x57, 0x9d, 0x1c ),
114 RGB_COLORDATA( 0x7e, 0x00, 0x21 ),
115 RGB_COLORDATA( 0x83, 0xca, 0xff ),
116 RGB_COLORDATA( 0x31, 0x40, 0x04 ),
117 RGB_COLORDATA( 0xae, 0xcf, 0x00 ),
118 RGB_COLORDATA( 0x4b, 0x1f, 0x6f ),
119 RGB_COLORDATA( 0xff, 0x95, 0x0e ),
120 RGB_COLORDATA( 0xc5, 0x00, 0x0b ),
121 RGB_COLORDATA( 0x00, 0x84, 0xd1 )
124 clear();
126 String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) );
127 String aPrefix, aPostfix, aName;
128 xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" );
129 if( nPos != STRING_NOTFOUND )
131 aPrefix = String( aResName, 0, nPos );
132 aPostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN );
134 else
135 aPrefix = aResName;
137 for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
139 aName = aPrefix;
140 aName.Append( String::CreateFromInt32( i + 1 ));
141 aName.Append( aPostfix );
143 append( XColorEntry( aColors[ i % sizeof( aColors ) ], aName ));
147 // comparison
148 bool SvxChartColorTable::operator==( const SvxChartColorTable & _rOther ) const
150 // note: XColorEntry has no operator ==
151 bool bEqual = ( this->m_aColorEntries.size() == _rOther.m_aColorEntries.size() );
153 if( bEqual )
155 for( size_t i = 0; i < m_aColorEntries.size(); ++i )
157 if( getColorData( i ) != _rOther.getColorData( i ))
159 bEqual = false;
160 break;
165 return bEqual;
168 // ====================
169 // class SvxChartOptions
170 // ====================
172 SvxChartOptions::SvxChartOptions() :
173 ::utl::ConfigItem( rtl::OUString::createFromAscii( "Office.Chart" )),
174 mbIsInitialized( sal_False )
176 maPropertyNames.realloc( 1 );
177 maPropertyNames[ 0 ] = ::rtl::OUString::createFromAscii( "DefaultColor/Series" );
180 SvxChartOptions::~SvxChartOptions()
184 const SvxChartColorTable& SvxChartOptions::GetDefaultColors()
186 if ( !mbIsInitialized )
187 mbIsInitialized = RetrieveOptions();
188 return maDefColors;
191 void SvxChartOptions::SetDefaultColors( const SvxChartColorTable& aCol )
193 maDefColors = aCol;
194 SetModified();
197 sal_Bool SvxChartOptions::RetrieveOptions()
199 // get sequence containing all properties
201 uno::Sequence< ::rtl::OUString > aNames = GetPropertyNames();
202 uno::Sequence< uno::Any > aProperties( aNames.getLength());
203 aProperties = GetProperties( aNames );
205 if( aProperties.getLength() == aNames.getLength())
207 // 1. default colors for series
208 maDefColors.clear();
209 uno::Sequence< sal_Int64 > aColorSeq;
210 aProperties[ 0 ] >>= aColorSeq;
212 sal_Int32 nCount = aColorSeq.getLength();
213 Color aCol;
215 // create strings for entry names
216 String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) );
217 String aPrefix, aPostfix, aName;
218 xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" );
219 if( nPos != STRING_NOTFOUND )
221 aPrefix = String( aResName, 0, nPos );
222 aPostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN );
224 else
225 aPrefix = aResName;
227 // set color values
228 for( sal_Int32 i=0; i < nCount; i++ )
230 aCol.SetColor( SAL_STATIC_CAST( ColorData, aColorSeq[ i ] ));
232 aName = aPrefix;
233 aName.Append( String::CreateFromInt32( i + 1 ));
234 aName.Append( aPostfix );
236 maDefColors.append( XColorEntry( aCol, aName ));
238 return sal_True;
240 return sal_False;
243 void SvxChartOptions::Commit()
245 uno::Sequence< ::rtl::OUString > aNames = GetPropertyNames();
246 uno::Sequence< uno::Any > aValues( aNames.getLength());
248 if( aValues.getLength() >= 1 )
250 // 1. default colors for series
251 // convert list to sequence
252 const size_t nCount = maDefColors.size();
253 uno::Sequence< sal_Int64 > aColors( nCount );
254 for( size_t i=0; i < nCount; i++ )
256 ColorData aData = maDefColors.getColorData( i );
257 aColors[ i ] = aData;
260 aValues[ 0 ] <<= aColors;
263 PutProperties( aNames, aValues );
266 void SvxChartOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
270 // --------------------
271 // class SvxChartColorTableItem
272 // --------------------
274 SvxChartColorTableItem::SvxChartColorTableItem( sal_uInt16 nWhich_, const SvxChartColorTable& aTable ) :
275 SfxPoolItem( nWhich_ ),
276 m_aColorTable( aTable )
280 SvxChartColorTableItem::SvxChartColorTableItem( const SvxChartColorTableItem& rOther ) :
281 SfxPoolItem( rOther ),
282 m_aColorTable( rOther.m_aColorTable )
286 SfxPoolItem* __EXPORT SvxChartColorTableItem::Clone( SfxItemPool * ) const
288 return new SvxChartColorTableItem( *this );
291 int __EXPORT SvxChartColorTableItem::operator==( const SfxPoolItem& rAttr ) const
293 DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "SvxChartColorTableItem::operator== : types differ" );
295 const SvxChartColorTableItem * rCTItem( dynamic_cast< const SvxChartColorTableItem * >( & rAttr ));
296 if( rCTItem )
298 return (this->m_aColorTable == rCTItem->GetColorTable());
301 return 0;
304 void __EXPORT SvxChartColorTableItem::SetOptions( SvxChartOptions* pOpts ) const
306 if ( pOpts )
307 pOpts->SetDefaultColors( m_aColorTable );
311 SvxChartColorTable & SvxChartColorTableItem::GetColorTable()
313 return m_aColorTable;
316 const SvxChartColorTable & SvxChartColorTableItem::GetColorTable() const
318 return m_aColorTable;
321 void SvxChartColorTableItem::ReplaceColorByIndex( size_t _nIndex, const XColorEntry & _rEntry )
323 m_aColorTable.replace( _nIndex, _rEntry );