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: ConfigColorScheme.cxx,v $
10 * $Revision: 1.3.44.1 $
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_chart2.hxx"
34 #include "ConfigColorScheme.hxx"
35 #include "ContainerHelper.hxx"
38 #include <unotools/configitem.hxx>
42 using namespace ::com::sun::star
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::uno::Sequence
;
46 using ::rtl::OUString
;
51 static const OUString
aSeriesPropName( RTL_CONSTASCII_USTRINGPARAM("Series"));
53 } // anonymous namespace
55 // --------------------------------------------------------------------------------
60 uno::Reference
< chart2::XColorScheme
> createConfigColorScheme( const uno::Reference
< uno::XComponentContext
> & xContext
)
62 return new ConfigColorScheme( xContext
);
67 class ChartConfigItem
: public ::utl::ConfigItem
70 explicit ChartConfigItem( ConfigItemListener
& rListener
);
71 virtual ~ChartConfigItem();
73 void addPropertyNotification( const OUString
& rPropertyName
);
75 uno::Any
getProperty( const OUString
& aPropertyName
);
78 // ____ ::utl::ConfigItem ____
79 virtual void Notify( const Sequence
< OUString
> & aPropertyNames
);
82 ConfigItemListener
& m_rListener
;
83 ::std::set
< OUString
> m_aPropertiesToNotify
;
86 ChartConfigItem::ChartConfigItem( ConfigItemListener
& rListener
) :
87 ::utl::ConfigItem( C2U("Office.Chart/DefaultColor")),
88 m_rListener( rListener
)
91 ChartConfigItem::~ChartConfigItem()
94 void ChartConfigItem::Notify( const Sequence
< OUString
> & aPropertyNames
)
96 for( sal_Int32 nIdx
=0; nIdx
<aPropertyNames
.getLength(); ++nIdx
)
98 if( m_aPropertiesToNotify
.find( aPropertyNames
[nIdx
] ) != m_aPropertiesToNotify
.end())
99 m_rListener
.notify( aPropertyNames
[nIdx
] );
103 void ChartConfigItem::addPropertyNotification( const OUString
& rPropertyName
)
105 m_aPropertiesToNotify
.insert( rPropertyName
);
106 EnableNotification( ContainerHelper::ContainerToSequence( m_aPropertiesToNotify
));
109 uno::Any
ChartConfigItem::getProperty( const OUString
& aPropertyName
)
111 Sequence
< uno::Any
> aValues(
112 GetProperties( Sequence
< OUString
>( &aPropertyName
, 1 )));
113 if( ! aValues
.getLength())
120 // --------------------------------------------------------------------------------
123 ConfigColorScheme::ConfigColorScheme(
124 const Reference
< uno::XComponentContext
> & xContext
) :
125 m_xContext( xContext
),
126 m_nNumberOfColors( 0 ),
127 m_bNeedsUpdate( true )
131 ConfigColorScheme::~ConfigColorScheme()
134 void ConfigColorScheme::retrieveConfigColors()
136 if( ! m_xContext
.is())
139 // create config item if necessary
140 if( ! m_apChartConfigItem
.get())
142 m_apChartConfigItem
.reset(
143 new impl::ChartConfigItem( *this ));
144 m_apChartConfigItem
->addPropertyNotification( aSeriesPropName
);
146 OSL_ASSERT( m_apChartConfigItem
.get());
147 if( ! m_apChartConfigItem
.get())
152 m_apChartConfigItem
->getProperty( aSeriesPropName
));
153 if( aValue
>>= m_aColorSequence
)
154 m_nNumberOfColors
= m_aColorSequence
.getLength();
155 m_bNeedsUpdate
= false;
158 // ____ XColorScheme ____
159 ::sal_Int32 SAL_CALL
ConfigColorScheme::getColorByIndex( ::sal_Int32 nIndex
)
160 throw (uno::RuntimeException
)
163 retrieveConfigColors();
165 if( m_nNumberOfColors
> 0 )
166 return static_cast< sal_Int32
>( m_aColorSequence
[ nIndex
% m_nNumberOfColors
] );
168 // fall-back: hard-coded standard colors
169 static sal_Int32 nDefaultColors
[] = {
170 0x9999ff, 0x993366, 0xffffcc,
171 0xccffff, 0x660066, 0xff8080,
172 0x0066cc, 0xccccff, 0x000080,
173 0xff00ff, 0x00ffff, 0xffff00
176 static const sal_Int32 nMaxDefaultColors
= sizeof( nDefaultColors
) / sizeof( sal_Int32
);
177 return nDefaultColors
[ nIndex
% nMaxDefaultColors
];
180 void ConfigColorScheme::notify( const OUString
& rPropertyName
)
182 if( rPropertyName
.equals( aSeriesPropName
))
183 m_bNeedsUpdate
= true;
186 // ================================================================================
188 Sequence
< OUString
> ConfigColorScheme::getSupportedServiceNames_Static()
190 Sequence
< OUString
> aServices( 1 );
191 aServices
[ 0 ] = C2U( "com.sun.star.chart2.ColorScheme" );
195 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
196 APPHELPER_XSERVICEINFO_IMPL( ConfigColorScheme
,
197 C2U( "com.sun.star.comp.chart2.ConfigDefaultColorScheme" ))
199 // ================================================================================