1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cfgchart.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include <com/sun/star/uno/Sequence.hxx>
38 // header for SvStream
39 #include <tools/stream.hxx>
40 // header for SAL_STATIC_CAST
41 #include <sal/types.h>
43 #include "cfgchart.hxx"
44 #include <svx/dialmgr.hxx>
45 #include <svx/dialogs.hrc>
47 #define ROW_COLOR_COUNT 12
49 using namespace com::sun::star
;
51 TYPEINIT1( SvxChartColorTableItem
, SfxPoolItem
);
53 SvxChartColorTable::SvxChartColorTable()
56 SvxChartColorTable::SvxChartColorTable( const SvxChartColorTable
& _rSource
) :
57 m_aColorEntries( _rSource
.m_aColorEntries
)
61 size_t SvxChartColorTable::size() const
63 return m_aColorEntries
.size();
66 const XColorEntry
& SvxChartColorTable::operator[]( size_t _nIndex
) const
68 if ( _nIndex
>= m_aColorEntries
.size() )
70 DBG_ERRORFILE( "SvxChartColorTable::[] invalid index" );
71 return m_aColorEntries
[ 0 ];
74 return m_aColorEntries
[ _nIndex
];
77 ColorData
SvxChartColorTable::getColorData( size_t _nIndex
) const
79 if ( _nIndex
>= m_aColorEntries
.size() )
81 DBG_ERRORFILE( "SvxChartColorTable::getColorData invalid index" );
85 // GetColor should be const but unfortunately isn't
86 return const_cast< XColorEntry
& >( m_aColorEntries
[ _nIndex
] ).GetColor().GetRGBColor();
90 void SvxChartColorTable::clear()
92 m_aColorEntries
.clear();
95 void SvxChartColorTable::append( const XColorEntry
& _rEntry
)
97 m_aColorEntries
.push_back( _rEntry
);
100 void SvxChartColorTable::replace( size_t _nIndex
, const XColorEntry
& _rEntry
)
102 DBG_ASSERT( _nIndex
<= m_aColorEntries
.size(),
103 "SvxChartColorTable::replace invalid index" );
105 Color aCol1
= m_aColorEntries
[ _nIndex
].GetColor(), aCol2
;
106 m_aColorEntries
[ _nIndex
] = _rEntry
;
107 aCol2
= m_aColorEntries
[ _nIndex
].GetColor();
108 if ( aCol2
!= const_cast< XColorEntry
& >( _rEntry
).GetColor() )
110 DBG_ERRORFILE( "wrong color" );
114 void SvxChartColorTable::useDefault()
116 ColorData aColors
[] = {
117 RGB_COLORDATA( 0x00, 0x45, 0x86 ),
118 RGB_COLORDATA( 0xff, 0x42, 0x0e ),
119 RGB_COLORDATA( 0xff, 0xd3, 0x20 ),
120 RGB_COLORDATA( 0x57, 0x9d, 0x1c ),
121 RGB_COLORDATA( 0x7e, 0x00, 0x21 ),
122 RGB_COLORDATA( 0x83, 0xca, 0xff ),
123 RGB_COLORDATA( 0x31, 0x40, 0x04 ),
124 RGB_COLORDATA( 0xae, 0xcf, 0x00 ),
125 RGB_COLORDATA( 0x4b, 0x1f, 0x6f ),
126 RGB_COLORDATA( 0xff, 0x95, 0x0e ),
127 RGB_COLORDATA( 0xc5, 0x00, 0x0b ),
128 RGB_COLORDATA( 0x00, 0x84, 0xd1 )
133 String
aResName( SVX_RES( RID_SVXSTR_DIAGRAM_ROW
) );
134 String aPrefix
, aPostfix
, aName
;
135 xub_StrLen nPos
= aResName
.SearchAscii( "$(ROW)" );
136 if( nPos
!= STRING_NOTFOUND
)
138 aPrefix
= String( aResName
, 0, nPos
);
139 aPostfix
= String( aResName
, nPos
+ sizeof( "$(ROW)" ) - 1, STRING_LEN
);
144 for( sal_Int32 i
=0; i
<ROW_COLOR_COUNT
; i
++ )
147 aName
.Append( String::CreateFromInt32( i
+ 1 ));
148 aName
.Append( aPostfix
);
150 append( XColorEntry( aColors
[ i
% sizeof( aColors
) ], aName
));
155 bool SvxChartColorTable::operator==( const SvxChartColorTable
& _rOther
) const
157 // note: XColorEntry has no operator ==
158 bool bEqual
= ( this->m_aColorEntries
.size() == _rOther
.m_aColorEntries
.size() );
162 for( size_t i
= 0; i
< m_aColorEntries
.size(); ++i
)
164 if( getColorData( i
) != _rOther
.getColorData( i
))
175 // ====================
176 // class SvxChartOptions
177 // ====================
179 SvxChartOptions::SvxChartOptions() :
180 ::utl::ConfigItem( rtl::OUString::createFromAscii( "Office.Chart" )),
181 mbIsInitialized( FALSE
)
183 maPropertyNames
.realloc( 1 );
184 maPropertyNames
[ 0 ] = ::rtl::OUString::createFromAscii( "DefaultColor/Series" );
187 SvxChartOptions::~SvxChartOptions()
191 const SvxChartColorTable
& SvxChartOptions::GetDefaultColors()
193 if ( !mbIsInitialized
)
194 mbIsInitialized
= RetrieveOptions();
198 void SvxChartOptions::SetDefaultColors( const SvxChartColorTable
& aCol
)
204 BOOL
SvxChartOptions::RetrieveOptions()
206 // get sequence containing all properties
208 uno::Sequence
< ::rtl::OUString
> aNames
= GetPropertyNames();
209 uno::Sequence
< uno::Any
> aProperties( aNames
.getLength());
210 aProperties
= GetProperties( aNames
);
212 if( aProperties
.getLength() == aNames
.getLength())
214 // 1. default colors for series
216 uno::Sequence
< sal_Int64
> aColorSeq
;
217 aProperties
[ 0 ] >>= aColorSeq
;
219 sal_Int32 nCount
= aColorSeq
.getLength();
222 // create strings for entry names
223 String
aResName( SVX_RES( RID_SVXSTR_DIAGRAM_ROW
) );
224 String aPrefix
, aPostfix
, aName
;
225 xub_StrLen nPos
= aResName
.SearchAscii( "$(ROW)" );
226 if( nPos
!= STRING_NOTFOUND
)
228 aPrefix
= String( aResName
, 0, nPos
);
229 aPostfix
= String( aResName
, nPos
+ sizeof( "$(ROW)" ) - 1, STRING_LEN
);
235 for( sal_Int32 i
=0; i
< nCount
; i
++ )
237 aCol
.SetColor( SAL_STATIC_CAST( ColorData
, aColorSeq
[ i
] ));
240 aName
.Append( String::CreateFromInt32( i
+ 1 ));
241 aName
.Append( aPostfix
);
243 maDefColors
.append( XColorEntry( aCol
, aName
));
250 void SvxChartOptions::Commit()
252 uno::Sequence
< ::rtl::OUString
> aNames
= GetPropertyNames();
253 uno::Sequence
< uno::Any
> aValues( aNames
.getLength());
255 if( aValues
.getLength() >= 1 )
257 // 1. default colors for series
258 // convert list to sequence
259 const size_t nCount
= maDefColors
.size();
260 uno::Sequence
< sal_Int64
> aColors( nCount
);
261 for( size_t i
=0; i
< nCount
; i
++ )
263 ColorData aData
= maDefColors
.getColorData( i
);
264 aColors
[ i
] = aData
;
267 aValues
[ 0 ] <<= aColors
;
270 PutProperties( aNames
, aValues
);
273 // --------------------
274 // class SvxChartColorTableItem
275 // --------------------
277 SvxChartColorTableItem::SvxChartColorTableItem( USHORT nWhich_
, const SvxChartColorTable
& aTable
) :
278 SfxPoolItem( nWhich_
),
279 m_aColorTable( aTable
)
283 SvxChartColorTableItem::SvxChartColorTableItem( const SvxChartColorTableItem
& rOther
) :
284 SfxPoolItem( rOther
),
285 m_aColorTable( rOther
.m_aColorTable
)
289 SfxPoolItem
* __EXPORT
SvxChartColorTableItem::Clone( SfxItemPool
* ) const
291 return new SvxChartColorTableItem( *this );
294 int __EXPORT
SvxChartColorTableItem::operator==( const SfxPoolItem
& rAttr
) const
296 DBG_ASSERT( SfxPoolItem::operator==( rAttr
), "SvxChartColorTableItem::operator== : types differ" );
298 const SvxChartColorTableItem
* rCTItem( dynamic_cast< const SvxChartColorTableItem
* >( & rAttr
));
301 return (this->m_aColorTable
== rCTItem
->GetColorTable());
307 void __EXPORT
SvxChartColorTableItem::SetOptions( SvxChartOptions
* pOpts
) const
310 pOpts
->SetDefaultColors( m_aColorTable
);
314 SvxChartColorTable
& SvxChartColorTableItem::GetColorTable()
316 return m_aColorTable
;
319 const SvxChartColorTable
& SvxChartColorTableItem::GetColorTable() const
321 return m_aColorTable
;
324 void SvxChartColorTableItem::ReplaceColorByIndex( size_t _nIndex
, const XColorEntry
& _rEntry
)
326 m_aColorTable
.replace( _nIndex
, _rEntry
);