LibreOffice Module cui (master)  1
cfgchart.cxx
Go to the documentation of this file.
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/debug.hxx>
22 #include <sal/log.hxx>
23 #include "cfgchart.hxx"
24 #include <dialmgr.hxx>
25 #include <strings.hrc>
26 
27 #define ROW_COLOR_COUNT 12
28 
29 using namespace com::sun::star;
30 
31 // accessors
33 {
34  return m_aColorEntries.size();
35 }
36 
37 const XColorEntry & SvxChartColorTable::operator[]( size_t _nIndex ) const
38 {
39  if ( _nIndex >= m_aColorEntries.size() )
40  {
41  SAL_WARN( "cui.options", "SvxChartColorTable::[] invalid index" );
42  return m_aColorEntries[ 0 ];
43  }
44 
45  return m_aColorEntries[ _nIndex ];
46 }
47 
48 Color SvxChartColorTable::getColor( size_t _nIndex ) const
49 {
50  if ( _nIndex >= m_aColorEntries.size() )
51  {
52  SAL_WARN( "cui.options", "SvxChartColorTable::getColorData invalid index" );
53  return COL_BLACK;
54  }
55 
56  return m_aColorEntries[ _nIndex ].GetColor().GetRGBColor();
57 }
58 
59 // mutators
61 {
62  m_aColorEntries.clear();
63 }
64 
65 void SvxChartColorTable::append( const XColorEntry & _rEntry )
66 {
67  m_aColorEntries.push_back( _rEntry );
68 }
69 
70 void SvxChartColorTable::remove( size_t _nIndex )
71 {
72  if (!m_aColorEntries.empty())
73  m_aColorEntries.erase( m_aColorEntries.begin() + _nIndex);
74 
75  for (size_t i=0 ; i<m_aColorEntries.size(); i++)
76  {
77  m_aColorEntries[ i ].SetName( getDefaultName( i ) );
78  }
79 }
80 
81 void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry )
82 {
83  DBG_ASSERT( _nIndex <= m_aColorEntries.size(),
84  "SvxChartColorTable::replace invalid index" );
85 
86  m_aColorEntries[ _nIndex ] = _rEntry;
87 }
88 
90 {
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 )
104  };
105 
106  clear();
107 
108  for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
109  {
110  append( XColorEntry( aColors[ i % sizeof( aColors ) ], getDefaultName( i ) ));
111  }
112 }
113 
114 OUString SvxChartColorTable::getDefaultName( size_t _nIndex )
115 {
116  OUString aName;
117 
118  OUString sDefaultNamePrefix;
119  OUString sDefaultNamePostfix;
120  OUString aResName( CuiResId( RID_SVXSTR_DIAGRAM_ROW ) );
121  sal_Int32 nPos = aResName.indexOf( "$(ROW)" );
122  if( nPos != -1 )
123  {
124  sDefaultNamePrefix = aResName.copy( 0, nPos );
125  sDefaultNamePostfix = aResName.copy( nPos + sizeof( "$(ROW)" ) - 1 );
126  }
127  else
128  {
129  sDefaultNamePrefix = aResName;
130  }
131 
132  aName = sDefaultNamePrefix + OUString::number(_nIndex + 1) + sDefaultNamePostfix;
133 
134  return aName;
135 }
136 
137 // comparison
139 {
140  // note: XColorEntry has no operator ==
141  bool bEqual = ( m_aColorEntries.size() == _rOther.m_aColorEntries.size() );
142 
143  if( bEqual )
144  {
145  for( size_t i = 0; i < m_aColorEntries.size(); ++i )
146  {
147  if( getColor( i ) != _rOther.getColor( i ))
148  {
149  bEqual = false;
150  break;
151  }
152  }
153  }
154 
155  return bEqual;
156 }
157 
158 
159 
160 
162  ::utl::ConfigItem( "Office.Chart" ),
163  mbIsInitialized( false )
164 {
165  maPropertyNames.realloc( 1 );
166  maPropertyNames[ 0 ] = "DefaultColor/Series";
167 }
168 
170 {
171 }
172 
174 {
175  if ( !mbIsInitialized )
177  return maDefColors;
178 }
179 
181 {
182  maDefColors = aCol;
183  SetModified();
184 }
185 
187 {
188  // get sequence containing all properties
189 
190  uno::Sequence< OUString > aNames = GetPropertyNames();
191  uno::Sequence< uno::Any > aProperties( aNames.getLength());
192  aProperties = GetProperties( aNames );
193 
194  if( aProperties.getLength() == aNames.getLength())
195  {
196  // 1. default colors for series
197  maDefColors.clear();
198  uno::Sequence< sal_Int64 > aColorSeq;
199  aProperties[ 0 ] >>= aColorSeq;
200 
201  sal_Int32 nCount = aColorSeq.getLength();
202  Color aCol;
203 
204  // create strings for entry names
205  OUString aResName( CuiResId( RID_SVXSTR_DIAGRAM_ROW ) );
206  OUString aPrefix, aPostfix, aName;
207  sal_Int32 nPos = aResName.indexOf( "$(ROW)" );
208  if( nPos != -1 )
209  {
210  aPrefix = aResName.copy( 0, nPos );
211  sal_Int32 idx = nPos + sizeof( "$(ROW)" ) - 1;
212  aPostfix = aResName.copy( idx );
213  }
214  else
215  aPrefix = aResName;
216 
217  // set color values
218  for( sal_Int32 i=0; i < nCount; i++ )
219  {
220  aCol = Color(aColorSeq[ i ]);
221 
222  aName = aPrefix + OUString::number(i + 1) + aPostfix;
223 
224  maDefColors.append( XColorEntry( aCol, aName ));
225  }
226  return true;
227  }
228  return false;
229 }
230 
232 {
233  uno::Sequence< OUString > aNames = GetPropertyNames();
234  uno::Sequence< uno::Any > aValues( aNames.getLength());
235 
236  if( aValues.hasElements() )
237  {
238  // 1. default colors for series
239  // convert list to sequence
240  const size_t nCount = maDefColors.size();
241  uno::Sequence< sal_Int64 > aColors( nCount );
242  for( size_t i=0; i < nCount; i++ )
243  {
245  aColors[ i ] = sal_uInt32(aData);
246  }
247 
248  aValues[ 0 ] <<= aColors;
249  }
250 
251  PutProperties( aNames, aValues );
252 }
253 
254 void SvxChartOptions::Notify( const css::uno::Sequence< OUString >& )
255 {
256 }
257 
258 
259 
260 
262  SfxPoolItem( nWhich_ ),
263  m_aColorTable( aTable )
264 {
265 }
266 
268 {
269  return new SvxChartColorTableItem( *this );
270 }
271 
273 {
274  assert(SfxPoolItem::operator==(rAttr));
275 
276  return static_cast<const SvxChartColorTableItem & >( rAttr ).m_aColorTable == m_aColorTable;
277 }
278 
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
const char aData[]
virtual void ImplCommit() override
Definition: cfgchart.cxx:231
static OUString getDefaultName(size_t _nIndex)
Definition: cfgchart.cxx:114
virtual ~SvxChartOptions() override
Definition: cfgchart.cxx:169
SvxChartColorTable m_aColorTable
Definition: cfgchart.hxx:97
void append(const XColorEntry &_rEntry)
Definition: cfgchart.cxx:65
PropertiesInfo aProperties
int nCount
size_t size() const
Definition: cfgchart.cxx:32
virtual SvxChartColorTableItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: cfgchart.cxx:267
SvxChartColorTable maDefColors
Definition: cfgchart.hxx:57
bool mbIsInitialized
Definition: cfgchart.hxx:58
void remove(size_t _nIndex)
Definition: cfgchart.cxx:70
const css::uno::Sequence< OUString > & GetPropertyNames() const
Definition: cfgchart.hxx:63
const SvxChartColorTable & GetDefaultColors()
Definition: cfgchart.cxx:173
#define DBG_ASSERT(sCon, aError)
bool PutProperties(const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues)
bool operator==(const SvxChartColorTable &_rOther) const
Definition: cfgchart.cxx:138
int i
SvxChartColorTableItem(sal_uInt16 nWhich, const SvxChartColorTable &)
Definition: cfgchart.cxx:261
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
const XColorEntry & operator[](size_t _nIndex) const
Definition: cfgchart.cxx:37
virtual void Notify(const css::uno::Sequence< OUString > &_rPropertyNames) override
Definition: cfgchart.cxx:254
void replace(size_t _nIndex, const XColorEntry &_rEntry)
Definition: cfgchart.cxx:81
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
virtual bool operator==(const SfxPoolItem &) const override
Definition: cfgchart.cxx:272
Color getColor(size_t _nIndex) const
Definition: cfgchart.cxx:48
bool RetrieveOptions()
Definition: cfgchart.cxx:186
OUString aName
#define ROW_COLOR_COUNT
Definition: cfgchart.cxx:27
std::vector< XColorEntry > m_aColorEntries
Definition: cfgchart.hxx:31
#define SAL_WARN(area, stream)
void SetDefaultColors(const SvxChartColorTable &aCol)
Definition: cfgchart.cxx:180
css::uno::Sequence< OUString > maPropertyNames
Definition: cfgchart.hxx:61
sal_uInt16 nPos