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 "StockBar.hxx"
21 #include "LinePropertiesHelper.hxx"
22 #include "FillProperties.hxx"
23 #include "UserDefinedProperties.hxx"
24 #include "PropertyHelper.hxx"
26 #include "ContainerHelper.hxx"
27 #include "ModifyListenerHelper.hxx"
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/style/XStyle.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <com/sun/star/uno/Sequence.hxx>
35 using namespace ::com::sun::star
;
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::beans::Property
;
39 using ::osl::MutexGuard
;
44 struct StaticStockBarInfoHelper_Initializer
46 ::cppu::OPropertyArrayHelper
* operator()()
48 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
53 static uno::Sequence
< Property
> lcl_GetPropertySequence()
55 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
56 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
57 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
58 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
60 ::std::sort( aProperties
.begin(), aProperties
.end(),
61 ::chart::PropertyNameLess() );
63 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
68 struct StaticStockBarInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticStockBarInfoHelper_Initializer
>
72 struct StaticStockBarInfo_Initializer
74 uno::Reference
< beans::XPropertySetInfo
>* operator()()
76 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
77 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticStockBarInfoHelper::get() ) );
78 return &xPropertySetInfo
;
82 struct StaticStockBarInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticStockBarInfo_Initializer
>
86 struct StaticStockBarDefaults_Initializer
88 ::chart::tPropertyValueMap
* operator()()
90 static ::chart::tPropertyValueMap aStaticDefaults
;
91 lcl_AddDefaultsToMap( aStaticDefaults
);
92 return &aStaticDefaults
;
95 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
97 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
98 ::chart::FillProperties::AddDefaultsToMap( rOutMap
);
100 // override other defaults
101 ::chart::PropertyHelper::setPropertyValue
< sal_Int32
>( rOutMap
, ::chart::FillProperties::PROP_FILL_COLOR
, 0xffffff ); // white
105 struct StaticStockBarDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticStockBarDefaults_Initializer
>
109 } // anonymous namespace
114 StockBar::StockBar( bool bRisingCourse
) :
115 ::property::OPropertySet( m_aMutex
),
116 m_bRisingCourse( bRisingCourse
),
117 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
119 if( ! m_bRisingCourse
)
121 setFastPropertyValue_NoBroadcast(
122 ::chart::FillProperties::PROP_FILL_COLOR
,
123 uno::makeAny( sal_Int32( 0x000000 ))); // black
124 setFastPropertyValue_NoBroadcast(
125 ::chart::LinePropertiesHelper::PROP_LINE_COLOR
,
126 uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30
130 StockBar::StockBar( const StockBar
& rOther
) :
132 impl::StockBar_Base(),
133 ::property::OPropertySet( rOther
, m_aMutex
),
134 m_bRisingCourse( rOther
.m_bRisingCourse
),
135 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
138 StockBar::~StockBar()
141 // ____ XCloneable ____
142 uno::Reference
< util::XCloneable
> SAL_CALL
StockBar::createClone()
143 throw (uno::RuntimeException
, std::exception
)
145 return uno::Reference
< util::XCloneable
>( new StockBar( *this ));
148 // ____ OPropertySet ____
149 uno::Any
StockBar::GetDefaultValue( sal_Int32 nHandle
) const
150 throw(beans::UnknownPropertyException
)
152 const tPropertyValueMap
& rStaticDefaults
= *StaticStockBarDefaults::get();
153 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
154 if( aFound
== rStaticDefaults
.end() )
156 return (*aFound
).second
;
159 ::cppu::IPropertyArrayHelper
& SAL_CALL
StockBar::getInfoHelper()
161 return *StaticStockBarInfoHelper::get();
164 // ____ XPropertySet ____
165 Reference
< beans::XPropertySetInfo
> SAL_CALL
StockBar::getPropertySetInfo()
166 throw (uno::RuntimeException
, std::exception
)
168 return *StaticStockBarInfo::get();
171 // ____ XModifyBroadcaster ____
172 void SAL_CALL
StockBar::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
173 throw (uno::RuntimeException
, std::exception
)
177 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
178 xBroadcaster
->addModifyListener( aListener
);
180 catch( const uno::Exception
& ex
)
182 ASSERT_EXCEPTION( ex
);
186 void SAL_CALL
StockBar::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
187 throw (uno::RuntimeException
, std::exception
)
191 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
192 xBroadcaster
->removeModifyListener( aListener
);
194 catch( const uno::Exception
& ex
)
196 ASSERT_EXCEPTION( ex
);
200 // ____ XModifyListener ____
201 void SAL_CALL
StockBar::modified( const lang::EventObject
& aEvent
)
202 throw (uno::RuntimeException
, std::exception
)
204 m_xModifyEventForwarder
->modified( aEvent
);
207 // ____ XEventListener (base of XModifyListener) ____
208 void SAL_CALL
StockBar::disposing( const lang::EventObject
& /* Source */ )
209 throw (uno::RuntimeException
, std::exception
)
214 // ____ OPropertySet ____
215 void StockBar::firePropertyChangeEvent()
220 void StockBar::fireModifyEvent()
222 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
225 using impl::StockBar_Base
;
227 IMPLEMENT_FORWARD_XINTERFACE2( StockBar
, StockBar_Base
, ::property::OPropertySet
)
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */