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 .
21 #include "StockBar.hxx"
22 #include "LinePropertiesHelper.hxx"
23 #include "FillProperties.hxx"
24 #include "UserDefinedProperties.hxx"
25 #include "PropertyHelper.hxx"
27 #include "ContainerHelper.hxx"
28 #include "ModifyListenerHelper.hxx"
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <com/sun/star/style/XStyle.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/uno/Sequence.hxx>
36 using namespace ::com::sun::star
;
38 using ::com::sun::star::uno::Reference
;
39 using ::com::sun::star::beans::Property
;
40 using ::osl::MutexGuard
;
42 // ____________________________________________________________
47 static const OUString
lcl_aServiceName( "com.sun.star.comp.chart2.StockBar" );
49 struct StaticStockBarInfoHelper_Initializer
51 ::cppu::OPropertyArrayHelper
* operator()()
53 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
58 uno::Sequence
< Property
> lcl_GetPropertySequence()
60 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
61 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
62 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
63 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
65 ::std::sort( aProperties
.begin(), aProperties
.end(),
66 ::chart::PropertyNameLess() );
68 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
73 struct StaticStockBarInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticStockBarInfoHelper_Initializer
>
77 struct StaticStockBarInfo_Initializer
79 uno::Reference
< beans::XPropertySetInfo
>* operator()()
81 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
82 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticStockBarInfoHelper::get() ) );
83 return &xPropertySetInfo
;
87 struct StaticStockBarInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticStockBarInfo_Initializer
>
91 struct StaticStockBarDefaults_Initializer
93 ::chart::tPropertyValueMap
* operator()()
95 static ::chart::tPropertyValueMap aStaticDefaults
;
96 lcl_AddDefaultsToMap( aStaticDefaults
);
97 return &aStaticDefaults
;
100 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
102 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
103 ::chart::FillProperties::AddDefaultsToMap( rOutMap
);
105 // override other defaults
106 ::chart::PropertyHelper::setPropertyValue
< sal_Int32
>( rOutMap
, ::chart::FillProperties::PROP_FILL_COLOR
, 0xffffff ); // white
110 struct StaticStockBarDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticStockBarDefaults_Initializer
>
114 } // anonymous namespace
116 // ____________________________________________________________
121 StockBar::StockBar( bool bRisingCourse
) :
122 ::property::OPropertySet( m_aMutex
),
123 m_bRisingCourse( bRisingCourse
),
124 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
126 if( ! m_bRisingCourse
)
128 setFastPropertyValue_NoBroadcast(
129 ::chart::FillProperties::PROP_FILL_COLOR
,
130 uno::makeAny( sal_Int32( 0x000000 ))); // black
131 setFastPropertyValue_NoBroadcast(
132 ::chart::LinePropertiesHelper::PROP_LINE_COLOR
,
133 uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30
137 StockBar::StockBar( const StockBar
& rOther
) :
139 impl::StockBar_Base(),
140 ::property::OPropertySet( rOther
, m_aMutex
),
141 m_bRisingCourse( rOther
.m_bRisingCourse
),
142 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
145 StockBar::~StockBar()
149 // ____ XCloneable ____
150 uno::Reference
< util::XCloneable
> SAL_CALL
StockBar::createClone()
151 throw (uno::RuntimeException
)
153 return uno::Reference
< util::XCloneable
>( new StockBar( *this ));
156 // ____ OPropertySet ____
157 uno::Any
StockBar::GetDefaultValue( sal_Int32 nHandle
) const
158 throw(beans::UnknownPropertyException
)
160 const tPropertyValueMap
& rStaticDefaults
= *StaticStockBarDefaults::get();
161 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
162 if( aFound
== rStaticDefaults
.end() )
164 return (*aFound
).second
;
167 ::cppu::IPropertyArrayHelper
& SAL_CALL
StockBar::getInfoHelper()
169 return *StaticStockBarInfoHelper::get();
172 // ____ XPropertySet ____
173 Reference
< beans::XPropertySetInfo
> SAL_CALL
StockBar::getPropertySetInfo()
174 throw (uno::RuntimeException
)
176 return *StaticStockBarInfo::get();
179 // ____ XModifyBroadcaster ____
180 void SAL_CALL
StockBar::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
181 throw (uno::RuntimeException
)
185 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
186 xBroadcaster
->addModifyListener( aListener
);
188 catch( const uno::Exception
& ex
)
190 ASSERT_EXCEPTION( ex
);
194 void SAL_CALL
StockBar::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
195 throw (uno::RuntimeException
)
199 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
200 xBroadcaster
->removeModifyListener( aListener
);
202 catch( const uno::Exception
& ex
)
204 ASSERT_EXCEPTION( ex
);
208 // ____ XModifyListener ____
209 void SAL_CALL
StockBar::modified( const lang::EventObject
& aEvent
)
210 throw (uno::RuntimeException
)
212 m_xModifyEventForwarder
->modified( aEvent
);
215 // ____ XEventListener (base of XModifyListener) ____
216 void SAL_CALL
StockBar::disposing( const lang::EventObject
& /* Source */ )
217 throw (uno::RuntimeException
)
222 // ____ OPropertySet ____
223 void StockBar::firePropertyChangeEvent()
228 void StockBar::fireModifyEvent()
230 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
233 // ================================================================================
235 uno::Sequence
< OUString
> StockBar::getSupportedServiceNames_Static()
237 uno::Sequence
< OUString
> aServices( 2 );
238 aServices
[ 0 ] = "com.sun.star.chart2.StockBar";
239 aServices
[ 1 ] = "com.sun.star.beans.PropertySet";
243 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
244 APPHELPER_XSERVICEINFO_IMPL( StockBar
, lcl_aServiceName
);
246 using impl::StockBar_Base
;
248 IMPLEMENT_FORWARD_XINTERFACE2( StockBar
, StockBar_Base
, ::property::OPropertySet
)
252 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */