1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/uno/Sequence.hxx>
21 #include <tools/debug.hxx>
22 #include <sal/log.hxx>
23 #include "cfgchart.hxx"
24 #include <dialmgr.hxx>
25 #include <strings.hrc>
27 #define ROW_COLOR_COUNT 12
29 using namespace com::sun::star
;
32 size_t SvxChartColorTable::size() const
34 return m_aColorEntries
.size();
37 const XColorEntry
& SvxChartColorTable::operator[]( size_t _nIndex
) const
39 if ( _nIndex
>= m_aColorEntries
.size() )
41 SAL_WARN( "cui.options", "SvxChartColorTable::[] invalid index" );
42 return m_aColorEntries
[ 0 ];
45 return m_aColorEntries
[ _nIndex
];
48 Color
SvxChartColorTable::getColor( size_t _nIndex
) const
50 if ( _nIndex
>= m_aColorEntries
.size() )
52 SAL_WARN( "cui.options", "SvxChartColorTable::getColorData invalid index" );
56 return m_aColorEntries
[ _nIndex
].GetColor().GetRGBColor();
60 void SvxChartColorTable::clear()
62 m_aColorEntries
.clear();
65 void SvxChartColorTable::append( const XColorEntry
& _rEntry
)
67 m_aColorEntries
.push_back( _rEntry
);
70 void SvxChartColorTable::remove( size_t _nIndex
)
72 if (!m_aColorEntries
.empty())
73 m_aColorEntries
.erase( m_aColorEntries
.begin() + _nIndex
);
75 for (size_t i
=0 ; i
<m_aColorEntries
.size(); i
++)
77 m_aColorEntries
[ i
].SetName( getDefaultName( i
) );
81 void SvxChartColorTable::replace( size_t _nIndex
, const XColorEntry
& _rEntry
)
83 DBG_ASSERT( _nIndex
<= m_aColorEntries
.size(),
84 "SvxChartColorTable::replace invalid index" );
86 m_aColorEntries
[ _nIndex
] = _rEntry
;
89 void SvxChartColorTable::useDefault()
91 static const Color aColors
[] = {
92 Color( 0x00, 0x45, 0x86 ),
93 Color( 0xff, 0x42, 0x0e ),
94 Color( 0xff, 0xd3, 0x20 ),
95 Color( 0x57, 0x9d, 0x1c ),
96 Color( 0x7e, 0x00, 0x21 ),
97 Color( 0x83, 0xca, 0xff ),
98 Color( 0x31, 0x40, 0x04 ),
99 Color( 0xae, 0xcf, 0x00 ),
100 Color( 0x4b, 0x1f, 0x6f ),
101 Color( 0xff, 0x95, 0x0e ),
102 Color( 0xc5, 0x00, 0x0b ),
103 Color( 0x00, 0x84, 0xd1 )
108 for( sal_Int32 i
=0; i
<ROW_COLOR_COUNT
; i
++ )
110 append( XColorEntry( aColors
[ i
% sizeof( aColors
) ], getDefaultName( i
) ));
114 OUString
SvxChartColorTable::getDefaultName( size_t _nIndex
)
118 OUString sDefaultNamePrefix
;
119 OUString sDefaultNamePostfix
;
120 OUString
aResName( CuiResId( RID_SVXSTR_DIAGRAM_ROW
) );
121 sal_Int32 nPos
= aResName
.indexOf( "$(ROW)" );
124 sDefaultNamePrefix
= aResName
.copy( 0, nPos
);
125 sDefaultNamePostfix
= aResName
.copy( nPos
+ sizeof( "$(ROW)" ) - 1 );
129 sDefaultNamePrefix
= aResName
;
132 aName
= sDefaultNamePrefix
+ OUString::number(_nIndex
+ 1) + sDefaultNamePostfix
;
138 bool SvxChartColorTable::operator==( const SvxChartColorTable
& _rOther
) const
140 // note: XColorEntry has no operator ==
141 bool bEqual
= ( m_aColorEntries
.size() == _rOther
.m_aColorEntries
.size() );
145 for( size_t i
= 0; i
< m_aColorEntries
.size(); ++i
)
147 if( getColor( i
) != _rOther
.getColor( i
))
159 // class SvxChartOptions
162 SvxChartOptions::SvxChartOptions() :
163 ::utl::ConfigItem( "Office.Chart" ),
164 mbIsInitialized( false )
166 maPropertyNames
.realloc( 1 );
167 maPropertyNames
[ 0 ] = "DefaultColor/Series";
170 SvxChartOptions::~SvxChartOptions()
174 const SvxChartColorTable
& SvxChartOptions::GetDefaultColors()
176 if ( !mbIsInitialized
)
177 mbIsInitialized
= RetrieveOptions();
181 void SvxChartOptions::SetDefaultColors( const SvxChartColorTable
& aCol
)
187 bool SvxChartOptions::RetrieveOptions()
189 // get sequence containing all properties
191 uno::Sequence
< OUString
> aNames
= GetPropertyNames();
192 uno::Sequence
< uno::Any
> aProperties( aNames
.getLength());
193 aProperties
= GetProperties( aNames
);
195 if( aProperties
.getLength() == aNames
.getLength())
197 // 1. default colors for series
199 uno::Sequence
< sal_Int64
> aColorSeq
;
200 aProperties
[ 0 ] >>= aColorSeq
;
202 sal_Int32 nCount
= aColorSeq
.getLength();
205 // create strings for entry names
206 OUString
aResName( CuiResId( RID_SVXSTR_DIAGRAM_ROW
) );
207 OUString aPrefix
, aPostfix
, aName
;
208 sal_Int32 nPos
= aResName
.indexOf( "$(ROW)" );
211 aPrefix
= aResName
.copy( 0, nPos
);
212 sal_Int32 idx
= nPos
+ sizeof( "$(ROW)" ) - 1;
213 aPostfix
= aResName
.copy( idx
);
219 for( sal_Int32 i
=0; i
< nCount
; i
++ )
221 aCol
= Color(aColorSeq
[ i
]);
223 aName
= aPrefix
+ OUString::number(i
+ 1) + aPostfix
;
225 maDefColors
.append( XColorEntry( aCol
, aName
));
232 void SvxChartOptions::ImplCommit()
234 uno::Sequence
< OUString
> aNames
= GetPropertyNames();
235 uno::Sequence
< uno::Any
> aValues( aNames
.getLength());
237 if( aValues
.hasElements() )
239 // 1. default colors for series
240 // convert list to sequence
241 const size_t nCount
= maDefColors
.size();
242 uno::Sequence
< sal_Int64
> aColors( nCount
);
243 for( size_t i
=0; i
< nCount
; i
++ )
245 Color aData
= maDefColors
.getColor( i
);
246 aColors
[ i
] = sal_uInt32(aData
);
249 aValues
[ 0 ] <<= aColors
;
252 PutProperties( aNames
, aValues
);
255 void SvxChartOptions::Notify( const css::uno::Sequence
< OUString
>& )
260 // class SvxChartColorTableItem
263 SvxChartColorTableItem::SvxChartColorTableItem( sal_uInt16 nWhich_
, const SvxChartColorTable
& aTable
) :
264 SfxPoolItem( nWhich_
),
265 m_aColorTable( aTable
)
269 SfxPoolItem
* SvxChartColorTableItem::Clone( SfxItemPool
* ) const
271 return new SvxChartColorTableItem( *this );
274 bool SvxChartColorTableItem::operator==( const SfxPoolItem
& rAttr
) const
276 assert(SfxPoolItem::operator==(rAttr
));
278 return static_cast<const SvxChartColorTableItem
& >( rAttr
).m_aColorTable
== m_aColorTable
;
281 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */