LibreOffice Module chart2 (master) 1
ConfigColorScheme.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <ConfigColorScheme.hxx>
21
23#include <sal/macros.h>
26
27#include <set>
28
29using namespace ::com::sun::star;
30
31using ::com::sun::star::uno::Reference;
32using ::com::sun::star::uno::Sequence;
33
34namespace
35{
36
37constexpr OUStringLiteral aSeriesPropName = u"Series";
38
39} // anonymous namespace
40
41namespace chart
42{
43
45{
46 return new ConfigColorScheme( xContext );
47}
48
49namespace impl
50{
52{
53public:
54 explicit ChartConfigItem( ConfigColorScheme & rListener );
55
56 uno::Any getProperty( const OUString & aPropertyName );
57
58protected:
59 // ____ ::utl::ConfigItem ____
60 virtual void ImplCommit() override;
61 virtual void Notify( const Sequence< OUString > & aPropertyNames ) override;
62
63private:
65};
66
68 ::utl::ConfigItem( "Office.Chart/DefaultColor" ),
69 m_rListener( rListener )
70{
71 EnableNotification( { aSeriesPropName } );
72}
73
74void ChartConfigItem::Notify( const Sequence< OUString > & aPropertyNames )
75{
76 for( OUString const & s : aPropertyNames )
77 {
78 if( s == aSeriesPropName )
80 }
81}
82
84{}
85
86uno::Any ChartConfigItem::getProperty( const OUString & aPropertyName )
87{
89 GetProperties( Sequence< OUString >( &aPropertyName, 1 )));
90 if( ! aValues.hasElements())
91 return uno::Any();
92 return aValues[0];
93}
94
95} // namespace impl
96
97// explicit
99 const Reference< uno::XComponentContext > & xContext ) :
100 m_xContext( xContext ),
101 m_nNumberOfColors( 0 ),
102 m_bNeedsUpdate( true )
103{
104}
105
107{}
108
110{
111 if( ! m_xContext.is())
112 return;
113
114 // create config item if necessary
116 {
118 new impl::ChartConfigItem( *this ));
119 }
120 assert(m_apChartConfigItem && "this can only be set at this point");
121
122 // retrieve colors
123 uno::Any aValue(
124 m_apChartConfigItem->getProperty( aSeriesPropName ));
125 if( aValue >>= m_aColorSequence )
127 m_bNeedsUpdate = false;
128}
129
130// ____ XColorScheme ____
131::sal_Int32 SAL_CALL ConfigColorScheme::getColorByIndex( ::sal_Int32 nIndex )
132{
133 if( m_bNeedsUpdate )
135
136 if( m_nNumberOfColors > 0 )
137 return static_cast< sal_Int32 >( m_aColorSequence[ nIndex % m_nNumberOfColors ] );
138
139 // fall-back: hard-coded standard colors
140 static const sal_Int32 nDefaultColors[] = {
141 0x9999ff, 0x993366, 0xffffcc,
142 0xccffff, 0x660066, 0xff8080,
143 0x0066cc, 0xccccff, 0x000080,
144 0xff00ff, 0x00ffff, 0xffff00
145 };
146
147 static const sal_Int32 nMaxDefaultColors = std::size( nDefaultColors );
148 return nDefaultColors[ nIndex % nMaxDefaultColors ];
149}
150
152{
153 m_bNeedsUpdate = true;
154}
155
157{
158 return "com.sun.star.comp.chart2.ConfigDefaultColorScheme" ;
159}
160
161sal_Bool SAL_CALL ConfigColorScheme::supportsService( const OUString& rServiceName )
162{
163 return cppu::supportsService(this, rServiceName);
164}
165
166css::uno::Sequence< OUString > SAL_CALL ConfigColorScheme::getSupportedServiceNames()
167{
168 return { "com.sun.star.chart2.ColorScheme" };
169}
170
171} // namespace chart
172
173extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
175 css::uno::Sequence<css::uno::Any> const &)
176{
177 return cppu::acquire(new ::chart::ConfigColorScheme(context));
178}
179
180/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_ConfigDefaultColorScheme_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< uno::XComponentContext > m_xContext
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual OUString SAL_CALL getImplementationName() override
declare XServiceInfo methods
virtual ::sal_Int32 SAL_CALL getColorByIndex(::sal_Int32 nIndex) override
css::uno::Sequence< sal_Int64 > m_aColorSequence
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ~ConfigColorScheme() override
ConfigColorScheme(const css::uno::Reference< css::uno::XComponentContext > &xContext)
std::unique_ptr< impl::ChartConfigItem > m_apChartConfigItem
virtual void Notify(const Sequence< OUString > &aPropertyNames) override
uno::Any getProperty(const OUString &aPropertyName)
ChartConfigItem(ConfigColorScheme &rListener)
virtual void ImplCommit() override
bool EnableNotification(const css::uno::Sequence< OUString > &rNames, bool bEnableInternalNotification=false)
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
float u
sal_Int32 nIndex
OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< css::chart2::XColorScheme > createConfigColorScheme(const css::uno::Reference< css::uno::XComponentContext > &xContext)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool