1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "GridProperties.hxx"
21 #include <LinePropertiesHelper.hxx>
22 #include <UserDefinedProperties.hxx>
23 #include <PropertyHelper.hxx>
24 #include <ModifyListenerHelper.hxx>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <tools/diagnose_ex.h>
30 namespace com::sun::star::beans
{ class XPropertySetInfo
; }
31 namespace com::sun::star::uno
{ class XComponentContext
; }
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::Sequence
;
37 using ::com::sun::star::beans::Property
;
47 void lcl_AddPropertiesToVector(
48 std::vector
< Property
> & rOutProperties
)
50 rOutProperties
.emplace_back( "Show",
52 cppu::UnoType
<bool>::get(),
53 beans::PropertyAttribute::BOUND
54 | beans::PropertyAttribute::MAYBEDEFAULT
);
57 struct StaticGridDefaults_Initializer
59 ::chart::tPropertyValueMap
* operator()()
61 static ::chart::tPropertyValueMap aStaticDefaults
;
62 lcl_AddDefaultsToMap( aStaticDefaults
);
63 return &aStaticDefaults
;
66 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
68 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
70 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_GRID_SHOW
, false );
72 // override other defaults
73 ::chart::PropertyHelper::setPropertyValue
< sal_Int32
>(
74 rOutMap
, ::chart::LinePropertiesHelper::PROP_LINE_COLOR
, 0xb3b3b3 ); // gray30
78 struct StaticGridDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticGridDefaults_Initializer
>
82 struct StaticGridInfoHelper_Initializer
84 ::cppu::OPropertyArrayHelper
* operator()()
86 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
91 static Sequence
< Property
> lcl_GetPropertySequence()
93 std::vector
< Property
> aProperties
;
94 lcl_AddPropertiesToVector( aProperties
);
95 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
96 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
98 std::sort( aProperties
.begin(), aProperties
.end(),
99 ::chart::PropertyNameLess() );
101 return comphelper::containerToSequence( aProperties
);
106 struct StaticGridInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticGridInfoHelper_Initializer
>
110 struct StaticGridInfo_Initializer
112 uno::Reference
< beans::XPropertySetInfo
>* operator()()
114 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
115 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticGridInfoHelper::get() ) );
116 return &xPropertySetInfo
;
120 struct StaticGridInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticGridInfo_Initializer
>
124 } // anonymous namespace
129 GridProperties::GridProperties() :
130 ::property::OPropertySet( m_aMutex
),
131 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
134 GridProperties::GridProperties( const GridProperties
& rOther
) :
135 impl::GridProperties_Base(rOther
),
136 ::property::OPropertySet( rOther
, m_aMutex
),
137 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
141 GridProperties::~GridProperties()
144 // ____ OPropertySet ____
145 uno::Any
GridProperties::GetDefaultValue( sal_Int32 nHandle
) const
147 const tPropertyValueMap
& rStaticDefaults
= *StaticGridDefaults::get();
148 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
149 if( aFound
== rStaticDefaults
.end() )
151 return (*aFound
).second
;
154 ::cppu::IPropertyArrayHelper
& SAL_CALL
GridProperties::getInfoHelper()
156 return *StaticGridInfoHelper::get();
159 // ____ XPropertySet ____
160 Reference
< beans::XPropertySetInfo
> SAL_CALL
GridProperties::getPropertySetInfo()
162 return *StaticGridInfo::get();
165 // ____ XCloneable ____
166 uno::Reference
< util::XCloneable
> SAL_CALL
GridProperties::createClone()
168 return uno::Reference
< util::XCloneable
>( new GridProperties( *this ));
171 // ____ XModifyBroadcaster ____
172 void SAL_CALL
GridProperties::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
176 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
177 xBroadcaster
->addModifyListener( aListener
);
179 catch( const uno::Exception
& )
181 DBG_UNHANDLED_EXCEPTION("chart2");
185 void SAL_CALL
GridProperties::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
189 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
190 xBroadcaster
->removeModifyListener( aListener
);
192 catch( const uno::Exception
& )
194 DBG_UNHANDLED_EXCEPTION("chart2");
198 // ____ XModifyListener ____
199 void SAL_CALL
GridProperties::modified( const lang::EventObject
& aEvent
)
201 m_xModifyEventForwarder
->modified( aEvent
);
204 // ____ XEventListener (base of XModifyListener) ____
205 void SAL_CALL
GridProperties::disposing( const lang::EventObject
& /* Source */ )
210 // ____ OPropertySet ____
211 void GridProperties::firePropertyChangeEvent()
213 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
216 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
217 OUString SAL_CALL
GridProperties::getImplementationName()
219 return "com.sun.star.comp.chart2.GridProperties";
222 sal_Bool SAL_CALL
GridProperties::supportsService( const OUString
& rServiceName
)
224 return cppu::supportsService(this, rServiceName
);
227 css::uno::Sequence
< OUString
> SAL_CALL
GridProperties::getSupportedServiceNames()
230 "com.sun.star.chart2.GridProperties",
231 "com.sun.star.beans.PropertySet" };
234 // needed by MSC compiler
235 using impl::GridProperties_Base
;
237 IMPLEMENT_FORWARD_XINTERFACE2( GridProperties
, GridProperties_Base
, ::property::OPropertySet
)
238 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridProperties
, GridProperties_Base
, ::property::OPropertySet
)
242 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
243 com_sun_star_comp_chart2_GridProperties_get_implementation(css::uno::XComponentContext
*,
244 css::uno::Sequence
<css::uno::Any
> const &)
246 return cppu::acquire(new ::chart::GridProperties
);
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */