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>
29 namespace com::sun::star::beans
{ class XPropertySetInfo
; }
30 namespace com::sun::star::uno
{ class XComponentContext
; }
32 using namespace ::com::sun::star
;
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::Sequence
;
36 using ::com::sun::star::beans::Property
;
46 void lcl_AddPropertiesToVector(
47 std::vector
< Property
> & rOutProperties
)
49 rOutProperties
.emplace_back( "Show",
51 cppu::UnoType
<bool>::get(),
52 beans::PropertyAttribute::BOUND
53 | beans::PropertyAttribute::MAYBEDEFAULT
);
56 const ::chart::tPropertyValueMap
& StaticGridDefaults()
58 static ::chart::tPropertyValueMap aStaticDefaults
= []()
60 ::chart::tPropertyValueMap aTmp
;
61 ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp
);
63 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_GRID_SHOW
, false );
65 // override other defaults
66 ::chart::PropertyHelper::setPropertyValue
< sal_Int32
>(
67 aTmp
, ::chart::LinePropertiesHelper::PROP_LINE_COLOR
, 0xb3b3b3 ); // gray30
70 return aStaticDefaults
;
73 ::cppu::OPropertyArrayHelper
& StaticGridInfoHelper()
75 static ::cppu::OPropertyArrayHelper aPropHelper
= []()
77 std::vector
< Property
> aProperties
;
78 lcl_AddPropertiesToVector( aProperties
);
79 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
80 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
82 std::sort( aProperties
.begin(), aProperties
.end(),
83 ::chart::PropertyNameLess() );
85 return comphelper::containerToSequence( aProperties
);
90 } // anonymous namespace
95 GridProperties::GridProperties() :
96 m_xModifyEventForwarder( new ModifyEventForwarder() )
99 GridProperties::GridProperties( const GridProperties
& rOther
) :
100 impl::GridProperties_Base(rOther
),
101 ::property::OPropertySet( rOther
),
102 m_xModifyEventForwarder( new ModifyEventForwarder() )
106 GridProperties::~GridProperties()
109 // ____ OPropertySet ____
110 void GridProperties::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
112 const tPropertyValueMap
& rStaticDefaults
= StaticGridDefaults();
113 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
114 if( aFound
== rStaticDefaults
.end() )
117 rAny
= (*aFound
).second
;
120 ::cppu::IPropertyArrayHelper
& SAL_CALL
GridProperties::getInfoHelper()
122 return StaticGridInfoHelper();
125 // ____ XPropertySet ____
126 Reference
< beans::XPropertySetInfo
> SAL_CALL
GridProperties::getPropertySetInfo()
128 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
129 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticGridInfoHelper() ) );
130 return xPropertySetInfo
;
133 // ____ XCloneable ____
134 uno::Reference
< util::XCloneable
> SAL_CALL
GridProperties::createClone()
136 return uno::Reference
< util::XCloneable
>( new GridProperties( *this ));
139 // ____ XModifyBroadcaster ____
140 void SAL_CALL
GridProperties::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
142 m_xModifyEventForwarder
->addModifyListener( aListener
);
145 void SAL_CALL
GridProperties::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
147 m_xModifyEventForwarder
->removeModifyListener( aListener
);
150 // ____ XModifyListener ____
151 void SAL_CALL
GridProperties::modified( const lang::EventObject
& aEvent
)
153 m_xModifyEventForwarder
->modified( aEvent
);
156 // ____ XEventListener (base of XModifyListener) ____
157 void SAL_CALL
GridProperties::disposing( const lang::EventObject
& /* Source */ )
162 // ____ OPropertySet ____
163 void GridProperties::firePropertyChangeEvent()
165 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
168 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
169 OUString SAL_CALL
GridProperties::getImplementationName()
171 return u
"com.sun.star.comp.chart2.GridProperties"_ustr
;
174 sal_Bool SAL_CALL
GridProperties::supportsService( const OUString
& rServiceName
)
176 return cppu::supportsService(this, rServiceName
);
179 css::uno::Sequence
< OUString
> SAL_CALL
GridProperties::getSupportedServiceNames()
182 u
"com.sun.star.chart2.GridProperties"_ustr
,
183 u
"com.sun.star.beans.PropertySet"_ustr
};
186 // needed by MSC compiler
187 using impl::GridProperties_Base
;
189 IMPLEMENT_FORWARD_XINTERFACE2( GridProperties
, GridProperties_Base
, ::property::OPropertySet
)
190 IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridProperties
, GridProperties_Base
, ::property::OPropertySet
)
194 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
195 com_sun_star_comp_chart2_GridProperties_get_implementation(css::uno::XComponentContext
*,
196 css::uno::Sequence
<css::uno::Any
> const &)
198 return cppu::acquire(new ::chart::GridProperties
);
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */