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