1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "ConfigColorScheme.hxx"
32 #include "ContainerHelper.hxx"
35 #include <unotools/configitem.hxx>
39 using namespace ::com::sun::star
;
41 using ::com::sun::star::uno::Reference
;
42 using ::com::sun::star::uno::Sequence
;
43 using ::rtl::OUString
;
48 static const OUString
aSeriesPropName( RTL_CONSTASCII_USTRINGPARAM("Series"));
50 } // anonymous namespace
52 // --------------------------------------------------------------------------------
57 uno::Reference
< chart2::XColorScheme
> createConfigColorScheme( const uno::Reference
< uno::XComponentContext
> & xContext
)
59 return new ConfigColorScheme( xContext
);
64 class ChartConfigItem
: public ::utl::ConfigItem
67 explicit ChartConfigItem( ConfigItemListener
& rListener
);
68 virtual ~ChartConfigItem();
70 void addPropertyNotification( const OUString
& rPropertyName
);
72 uno::Any
getProperty( const OUString
& aPropertyName
);
75 // ____ ::utl::ConfigItem ____
76 virtual void Commit();
77 virtual void Notify( const Sequence
< OUString
> & aPropertyNames
);
80 ConfigItemListener
& m_rListener
;
81 ::std::set
< OUString
> m_aPropertiesToNotify
;
84 ChartConfigItem::ChartConfigItem( ConfigItemListener
& rListener
) :
85 ::utl::ConfigItem( C2U("Office.Chart/DefaultColor")),
86 m_rListener( rListener
)
89 ChartConfigItem::~ChartConfigItem()
92 void ChartConfigItem::Notify( const Sequence
< OUString
> & aPropertyNames
)
94 for( sal_Int32 nIdx
=0; nIdx
<aPropertyNames
.getLength(); ++nIdx
)
96 if( m_aPropertiesToNotify
.find( aPropertyNames
[nIdx
] ) != m_aPropertiesToNotify
.end())
97 m_rListener
.notify( aPropertyNames
[nIdx
] );
101 void ChartConfigItem::Commit()
104 void ChartConfigItem::addPropertyNotification( const OUString
& rPropertyName
)
106 m_aPropertiesToNotify
.insert( rPropertyName
);
107 EnableNotification( ContainerHelper::ContainerToSequence( m_aPropertiesToNotify
));
110 uno::Any
ChartConfigItem::getProperty( const OUString
& aPropertyName
)
112 Sequence
< uno::Any
> aValues(
113 GetProperties( Sequence
< OUString
>( &aPropertyName
, 1 )));
114 if( ! aValues
.getLength())
121 // --------------------------------------------------------------------------------
124 ConfigColorScheme::ConfigColorScheme(
125 const Reference
< uno::XComponentContext
> & xContext
) :
126 m_xContext( xContext
),
127 m_nNumberOfColors( 0 ),
128 m_bNeedsUpdate( true )
132 ConfigColorScheme::~ConfigColorScheme()
135 void ConfigColorScheme::retrieveConfigColors()
137 if( ! m_xContext
.is())
140 // create config item if necessary
141 if( ! m_apChartConfigItem
.get())
143 m_apChartConfigItem
.reset(
144 new impl::ChartConfigItem( *this ));
145 m_apChartConfigItem
->addPropertyNotification( aSeriesPropName
);
147 OSL_ASSERT( m_apChartConfigItem
.get());
148 if( ! m_apChartConfigItem
.get())
153 m_apChartConfigItem
->getProperty( aSeriesPropName
));
154 if( aValue
>>= m_aColorSequence
)
155 m_nNumberOfColors
= m_aColorSequence
.getLength();
156 m_bNeedsUpdate
= false;
159 // ____ XColorScheme ____
160 ::sal_Int32 SAL_CALL
ConfigColorScheme::getColorByIndex( ::sal_Int32 nIndex
)
161 throw (uno::RuntimeException
)
164 retrieveConfigColors();
166 if( m_nNumberOfColors
> 0 )
167 return static_cast< sal_Int32
>( m_aColorSequence
[ nIndex
% m_nNumberOfColors
] );
169 // fall-back: hard-coded standard colors
170 static sal_Int32 nDefaultColors
[] = {
171 0x9999ff, 0x993366, 0xffffcc,
172 0xccffff, 0x660066, 0xff8080,
173 0x0066cc, 0xccccff, 0x000080,
174 0xff00ff, 0x00ffff, 0xffff00
177 static const sal_Int32 nMaxDefaultColors
= sizeof( nDefaultColors
) / sizeof( sal_Int32
);
178 return nDefaultColors
[ nIndex
% nMaxDefaultColors
];
181 void ConfigColorScheme::notify( const OUString
& rPropertyName
)
183 if( rPropertyName
.equals( aSeriesPropName
))
184 m_bNeedsUpdate
= true;
187 // ================================================================================
189 Sequence
< OUString
> ConfigColorScheme::getSupportedServiceNames_Static()
191 Sequence
< OUString
> aServices( 1 );
192 aServices
[ 0 ] = C2U( "com.sun.star.chart2.ColorScheme" );
196 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
197 APPHELPER_XSERVICEINFO_IMPL( ConfigColorScheme
,
198 C2U( "com.sun.star.comp.chart2.ConfigDefaultColorScheme" ))
200 // ================================================================================