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
))
161 SvxChartOptions::SvxChartOptions() :
162 ::utl::ConfigItem( "Office.Chart" ),
163 mbIsInitialized( false ),
164 maPropertyNames
{ "DefaultColor/Series" }
168 SvxChartOptions::~SvxChartOptions()
172 const SvxChartColorTable
& SvxChartOptions::GetDefaultColors()
174 if ( !mbIsInitialized
)
175 mbIsInitialized
= RetrieveOptions();
179 void SvxChartOptions::SetDefaultColors( const SvxChartColorTable
& aCol
)
185 bool SvxChartOptions::RetrieveOptions()
187 // get sequence containing all properties
189 uno::Sequence
< OUString
> aNames
= GetPropertyNames();
190 uno::Sequence
< uno::Any
> aProperties( aNames
.getLength());
191 aProperties
= GetProperties( aNames
);
193 if( aProperties
.getLength() == aNames
.getLength())
195 // 1. default colors for series
197 uno::Sequence
< sal_Int64
> aColorSeq
;
198 aProperties
[ 0 ] >>= aColorSeq
;
200 sal_Int32 nCount
= aColorSeq
.getLength();
203 // create strings for entry names
204 OUString
aResName( CuiResId( RID_SVXSTR_DIAGRAM_ROW
) );
205 OUString aPrefix
, aPostfix
, aName
;
206 sal_Int32 nPos
= aResName
.indexOf( "$(ROW)" );
209 aPrefix
= aResName
.copy( 0, nPos
);
210 sal_Int32 idx
= nPos
+ sizeof( "$(ROW)" ) - 1;
211 aPostfix
= aResName
.copy( idx
);
217 for( sal_Int32 i
=0; i
< nCount
; i
++ )
219 aCol
= Color(ColorTransparency
, aColorSeq
[ i
]);
221 aName
= aPrefix
+ OUString::number(i
+ 1) + aPostfix
;
223 maDefColors
.append( XColorEntry( aCol
, aName
));
230 void SvxChartOptions::ImplCommit()
232 uno::Sequence
< OUString
> aNames
= GetPropertyNames();
233 uno::Sequence
< uno::Any
> aValues( aNames
.getLength());
235 if( aValues
.hasElements() )
237 // 1. default colors for series
238 // convert list to sequence
239 const size_t nCount
= maDefColors
.size();
240 uno::Sequence
< sal_Int64
> aColors( nCount
);
241 auto aColorsRange
= asNonConstRange(aColors
);
242 for( size_t i
=0; i
< nCount
; i
++ )
244 Color aData
= maDefColors
.getColor( i
);
245 aColorsRange
[ i
] = sal_uInt32(aData
);
248 aValues
.getArray()[0] <<= aColors
;
251 PutProperties( aNames
, aValues
);
254 void SvxChartOptions::Notify( const css::uno::Sequence
< OUString
>& )
261 SvxChartColorTableItem::SvxChartColorTableItem( sal_uInt16 nWhich_
, const SvxChartColorTable
& aTable
) :
262 SfxPoolItem( nWhich_
),
263 m_aColorTable( aTable
)
267 SvxChartColorTableItem
* SvxChartColorTableItem::Clone( SfxItemPool
* ) const
269 return new SvxChartColorTableItem( *this );
272 bool SvxChartColorTableItem::operator==( const SfxPoolItem
& rAttr
) const
274 assert(SfxPoolItem::operator==(rAttr
));
276 return static_cast<const SvxChartColorTableItem
& >( rAttr
).m_aColorTable
== m_aColorTable
;
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */