xref: /aoo41x/main/cui/source/options/cfgchart.cxx (revision 2ee96f1c)
1*2ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2ee96f1cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2ee96f1cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2ee96f1cSAndrew Rist  * distributed with this work for additional information
6*2ee96f1cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2ee96f1cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2ee96f1cSAndrew Rist  * "License"); you may not use this file except in compliance
9*2ee96f1cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2ee96f1cSAndrew Rist  *
11*2ee96f1cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2ee96f1cSAndrew Rist  *
13*2ee96f1cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2ee96f1cSAndrew Rist  * software distributed under the License is distributed on an
15*2ee96f1cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2ee96f1cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*2ee96f1cSAndrew Rist  * specific language governing permissions and limitations
18*2ee96f1cSAndrew Rist  * under the License.
19*2ee96f1cSAndrew Rist  *
20*2ee96f1cSAndrew Rist  *************************************************************/
21*2ee96f1cSAndrew Rist 
22*2ee96f1cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
28cdf0e10cSrcweir // header for SvStream
29cdf0e10cSrcweir #include <tools/stream.hxx>
30cdf0e10cSrcweir // header for SAL_STATIC_CAST
31cdf0e10cSrcweir #include <sal/types.h>
32cdf0e10cSrcweir #include "cfgchart.hxx"
33cdf0e10cSrcweir #include <dialmgr.hxx>
34cdf0e10cSrcweir #include <cuires.hrc>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #define ROW_COLOR_COUNT 12
37cdf0e10cSrcweir 
38cdf0e10cSrcweir using namespace com::sun::star;
39cdf0e10cSrcweir 
40cdf0e10cSrcweir TYPEINIT1( SvxChartColorTableItem, SfxPoolItem );
41cdf0e10cSrcweir 
SvxChartColorTable()42cdf0e10cSrcweir SvxChartColorTable::SvxChartColorTable()
43cdf0e10cSrcweir {}
44cdf0e10cSrcweir 
SvxChartColorTable(const SvxChartColorTable & _rSource)45cdf0e10cSrcweir SvxChartColorTable::SvxChartColorTable( const SvxChartColorTable & _rSource ) :
46cdf0e10cSrcweir         m_aColorEntries( _rSource.m_aColorEntries )
47cdf0e10cSrcweir {}
48cdf0e10cSrcweir 
49cdf0e10cSrcweir // accessors
size() const50cdf0e10cSrcweir size_t SvxChartColorTable::size() const
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     return m_aColorEntries.size();
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
operator [](size_t _nIndex) const55cdf0e10cSrcweir const XColorEntry & SvxChartColorTable::operator[]( size_t _nIndex ) const
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     if ( _nIndex >= m_aColorEntries.size() )
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         DBG_ERRORFILE( "SvxChartColorTable::[] invalid index" );
60cdf0e10cSrcweir         return m_aColorEntries[ 0 ];
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     return m_aColorEntries[ _nIndex ];
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
getColorData(size_t _nIndex) const66cdf0e10cSrcweir ColorData SvxChartColorTable::getColorData( size_t _nIndex ) const
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     if ( _nIndex >= m_aColorEntries.size() )
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir         DBG_ERRORFILE( "SvxChartColorTable::getColorData invalid index" );
71cdf0e10cSrcweir         return COL_BLACK;
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     // GetColor should be const but unfortunately isn't
75cdf0e10cSrcweir     return const_cast< XColorEntry & >( m_aColorEntries[ _nIndex ] ).GetColor().GetRGBColor();
76cdf0e10cSrcweir }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir // mutators
clear()79cdf0e10cSrcweir void SvxChartColorTable::clear()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     m_aColorEntries.clear();
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
append(const XColorEntry & _rEntry)84cdf0e10cSrcweir void SvxChartColorTable::append( const XColorEntry & _rEntry )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     m_aColorEntries.push_back( _rEntry );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
replace(size_t _nIndex,const XColorEntry & _rEntry)89cdf0e10cSrcweir void SvxChartColorTable::replace( size_t _nIndex, const XColorEntry & _rEntry )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     DBG_ASSERT( _nIndex <= m_aColorEntries.size(),
92cdf0e10cSrcweir                 "SvxChartColorTable::replace invalid index" );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	Color aCol1 = m_aColorEntries[ _nIndex ].GetColor(), aCol2;
95cdf0e10cSrcweir     m_aColorEntries[ _nIndex ] = _rEntry;
96cdf0e10cSrcweir 	aCol2 = m_aColorEntries[ _nIndex ].GetColor();
97cdf0e10cSrcweir 	if ( aCol2 != const_cast< XColorEntry& >( _rEntry ).GetColor() )
98cdf0e10cSrcweir 	{
99cdf0e10cSrcweir 		DBG_ERRORFILE( "wrong color" );
100cdf0e10cSrcweir 	}
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
useDefault()103cdf0e10cSrcweir void SvxChartColorTable::useDefault()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	ColorData aColors[] = {
106cdf0e10cSrcweir 		RGB_COLORDATA( 0x00, 0x45, 0x86 ),
107cdf0e10cSrcweir 		RGB_COLORDATA( 0xff, 0x42, 0x0e ),
108cdf0e10cSrcweir 		RGB_COLORDATA( 0xff, 0xd3, 0x20 ),
109cdf0e10cSrcweir 		RGB_COLORDATA( 0x57, 0x9d, 0x1c ),
110cdf0e10cSrcweir 		RGB_COLORDATA( 0x7e, 0x00, 0x21 ),
111cdf0e10cSrcweir 		RGB_COLORDATA( 0x83, 0xca, 0xff ),
112cdf0e10cSrcweir 		RGB_COLORDATA( 0x31, 0x40, 0x04 ),
113cdf0e10cSrcweir 		RGB_COLORDATA( 0xae, 0xcf, 0x00 ),
114cdf0e10cSrcweir 		RGB_COLORDATA( 0x4b, 0x1f, 0x6f ),
115cdf0e10cSrcweir 		RGB_COLORDATA( 0xff, 0x95, 0x0e ),
116cdf0e10cSrcweir 		RGB_COLORDATA( 0xc5, 0x00, 0x0b ),
117cdf0e10cSrcweir 		RGB_COLORDATA( 0x00, 0x84, 0xd1 )
118cdf0e10cSrcweir 	};
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     clear();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) );
123cdf0e10cSrcweir 	String aPrefix, aPostfix, aName;
124cdf0e10cSrcweir 	xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" );
125cdf0e10cSrcweir 	if( nPos != STRING_NOTFOUND )
126cdf0e10cSrcweir 	{
127cdf0e10cSrcweir 		aPrefix = String( aResName, 0, nPos );
128cdf0e10cSrcweir 		aPostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN );
129cdf0e10cSrcweir 	}
130cdf0e10cSrcweir 	else
131cdf0e10cSrcweir 		aPrefix = aResName;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 	for( sal_Int32 i=0; i<ROW_COLOR_COUNT; i++ )
134cdf0e10cSrcweir 	{
135cdf0e10cSrcweir 		aName = aPrefix;
136cdf0e10cSrcweir 		aName.Append( String::CreateFromInt32( i + 1 ));
137cdf0e10cSrcweir 		aName.Append( aPostfix );
138cdf0e10cSrcweir 
139cdf0e10cSrcweir         append( XColorEntry( aColors[ i % sizeof( aColors ) ], aName ));
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir // comparison
operator ==(const SvxChartColorTable & _rOther) const144cdf0e10cSrcweir bool SvxChartColorTable::operator==( const SvxChartColorTable & _rOther ) const
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     // note: XColorEntry has no operator ==
147cdf0e10cSrcweir     bool bEqual = ( this->m_aColorEntries.size() == _rOther.m_aColorEntries.size() );
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     if( bEqual )
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         for( size_t i = 0; i < m_aColorEntries.size(); ++i )
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             if( getColorData( i ) != _rOther.getColorData( i ))
154cdf0e10cSrcweir             {
155cdf0e10cSrcweir                 bEqual = false;
156cdf0e10cSrcweir                 break;
157cdf0e10cSrcweir             }
158cdf0e10cSrcweir         }
159cdf0e10cSrcweir     }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     return bEqual;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir // ====================
165cdf0e10cSrcweir // class SvxChartOptions
166cdf0e10cSrcweir // ====================
167cdf0e10cSrcweir 
SvxChartOptions()168cdf0e10cSrcweir SvxChartOptions::SvxChartOptions() :
169cdf0e10cSrcweir 	::utl::ConfigItem( rtl::OUString::createFromAscii( "Office.Chart" )),
170cdf0e10cSrcweir 	mbIsInitialized( sal_False )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	maPropertyNames.realloc( 1 );
173cdf0e10cSrcweir 	maPropertyNames[ 0 ] = ::rtl::OUString::createFromAscii( "DefaultColor/Series" );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
~SvxChartOptions()176cdf0e10cSrcweir SvxChartOptions::~SvxChartOptions()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
GetDefaultColors()180cdf0e10cSrcweir const SvxChartColorTable& SvxChartOptions::GetDefaultColors()
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 	if ( !mbIsInitialized )
183cdf0e10cSrcweir 		mbIsInitialized = RetrieveOptions();
184cdf0e10cSrcweir 	return maDefColors;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
SetDefaultColors(const SvxChartColorTable & aCol)187cdf0e10cSrcweir void SvxChartOptions::SetDefaultColors( const SvxChartColorTable& aCol )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	maDefColors = aCol;
190cdf0e10cSrcweir 	SetModified();
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
RetrieveOptions()193cdf0e10cSrcweir sal_Bool SvxChartOptions::RetrieveOptions()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir 	// get sequence containing all properties
196cdf0e10cSrcweir 
197cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aNames = GetPropertyNames();
198cdf0e10cSrcweir 	uno::Sequence< uno::Any > aProperties( aNames.getLength());
199cdf0e10cSrcweir 	aProperties = GetProperties( aNames );
200cdf0e10cSrcweir 
201cdf0e10cSrcweir 	if( aProperties.getLength() == aNames.getLength())
202cdf0e10cSrcweir 	{
203cdf0e10cSrcweir 		// 1. default colors for series
204cdf0e10cSrcweir         maDefColors.clear();
205cdf0e10cSrcweir 		uno::Sequence< sal_Int64 > aColorSeq;
206cdf0e10cSrcweir 		aProperties[ 0 ] >>= aColorSeq;
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 		sal_Int32 nCount = aColorSeq.getLength();
209cdf0e10cSrcweir 		Color aCol;
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 		// create strings for entry names
212cdf0e10cSrcweir 		String aResName( CUI_RES( RID_SVXSTR_DIAGRAM_ROW ) );
213cdf0e10cSrcweir 		String aPrefix, aPostfix, aName;
214cdf0e10cSrcweir 		xub_StrLen nPos = aResName.SearchAscii( "$(ROW)" );
215cdf0e10cSrcweir 		if( nPos != STRING_NOTFOUND )
216cdf0e10cSrcweir 		{
217cdf0e10cSrcweir 			aPrefix = String( aResName, 0, nPos );
218cdf0e10cSrcweir 			aPostfix = String( aResName, nPos + sizeof( "$(ROW)" ) - 1, STRING_LEN );
219cdf0e10cSrcweir 		}
220cdf0e10cSrcweir 		else
221cdf0e10cSrcweir 			aPrefix = aResName;
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 		// set color values
224cdf0e10cSrcweir 		for( sal_Int32 i=0; i < nCount; i++ )
225cdf0e10cSrcweir 		{
226cdf0e10cSrcweir 			aCol.SetColor( SAL_STATIC_CAST( ColorData, aColorSeq[ i ] ));
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 			aName = aPrefix;
229cdf0e10cSrcweir 			aName.Append( String::CreateFromInt32( i + 1 ));
230cdf0e10cSrcweir 			aName.Append( aPostfix );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir             maDefColors.append( XColorEntry( aCol, aName ));
233cdf0e10cSrcweir 		}
234cdf0e10cSrcweir 		return sal_True;
235cdf0e10cSrcweir 	}
236cdf0e10cSrcweir 	return sal_False;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir 
Commit()239cdf0e10cSrcweir void SvxChartOptions::Commit()
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	uno::Sequence< ::rtl::OUString > aNames = GetPropertyNames();
242cdf0e10cSrcweir 	uno::Sequence< uno::Any > aValues( aNames.getLength());
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	if( aValues.getLength() >= 1 )
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir 		// 1. default colors for series
247cdf0e10cSrcweir 		// convert list to sequence
248cdf0e10cSrcweir 		const size_t nCount = maDefColors.size();
249cdf0e10cSrcweir 		uno::Sequence< sal_Int64 > aColors( nCount );
250cdf0e10cSrcweir 		for( size_t i=0; i < nCount; i++ )
251cdf0e10cSrcweir 		{
252cdf0e10cSrcweir 			ColorData aData = maDefColors.getColorData( i );
253cdf0e10cSrcweir 			aColors[ i ] = aData;
254cdf0e10cSrcweir 		}
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 		aValues[ 0 ] <<= aColors;
257cdf0e10cSrcweir 	}
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 	PutProperties( aNames, aValues );
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
Notify(const com::sun::star::uno::Sequence<rtl::OUString> &)262cdf0e10cSrcweir void SvxChartOptions::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir // --------------------
267cdf0e10cSrcweir // class SvxChartColorTableItem
268cdf0e10cSrcweir // --------------------
269cdf0e10cSrcweir 
SvxChartColorTableItem(sal_uInt16 nWhich_,const SvxChartColorTable & aTable)270cdf0e10cSrcweir SvxChartColorTableItem::SvxChartColorTableItem( sal_uInt16 nWhich_, const SvxChartColorTable& aTable ) :
271cdf0e10cSrcweir 	SfxPoolItem( nWhich_ ),
272cdf0e10cSrcweir 	m_aColorTable( aTable )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
SvxChartColorTableItem(const SvxChartColorTableItem & rOther)276cdf0e10cSrcweir SvxChartColorTableItem::SvxChartColorTableItem( const SvxChartColorTableItem& rOther ) :
277cdf0e10cSrcweir 	SfxPoolItem( rOther ),
278cdf0e10cSrcweir 	m_aColorTable( rOther.m_aColorTable )
279cdf0e10cSrcweir {
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
Clone(SfxItemPool *) const282cdf0e10cSrcweir SfxPoolItem* __EXPORT SvxChartColorTableItem::Clone( SfxItemPool * ) const
283cdf0e10cSrcweir {
284cdf0e10cSrcweir 	return new SvxChartColorTableItem( *this );
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rAttr) const287cdf0e10cSrcweir int __EXPORT SvxChartColorTableItem::operator==( const SfxPoolItem& rAttr ) const
288cdf0e10cSrcweir {
289cdf0e10cSrcweir 	DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "SvxChartColorTableItem::operator== : types differ" );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     const SvxChartColorTableItem * rCTItem( dynamic_cast< const SvxChartColorTableItem * >( & rAttr ));
292cdf0e10cSrcweir     if( rCTItem )
293cdf0e10cSrcweir     {
294cdf0e10cSrcweir         return (this->m_aColorTable == rCTItem->GetColorTable());
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     return 0;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir 
SetOptions(SvxChartOptions * pOpts) const300cdf0e10cSrcweir void __EXPORT SvxChartColorTableItem::SetOptions( SvxChartOptions* pOpts ) const
301cdf0e10cSrcweir {
302cdf0e10cSrcweir 	if ( pOpts )
303cdf0e10cSrcweir 		pOpts->SetDefaultColors( m_aColorTable );
304cdf0e10cSrcweir }
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 
GetColorTable()307cdf0e10cSrcweir SvxChartColorTable & SvxChartColorTableItem::GetColorTable()
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     return m_aColorTable;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
GetColorTable() const312cdf0e10cSrcweir const SvxChartColorTable & SvxChartColorTableItem::GetColorTable() const
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     return m_aColorTable;
315cdf0e10cSrcweir }
316cdf0e10cSrcweir 
ReplaceColorByIndex(size_t _nIndex,const XColorEntry & _rEntry)317cdf0e10cSrcweir void SvxChartColorTableItem::ReplaceColorByIndex( size_t _nIndex, const XColorEntry & _rEntry )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     m_aColorTable.replace( _nIndex, _rEntry );
320cdf0e10cSrcweir }
321