1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "StockBar.hxx"
28cdf0e10cSrcweir #include "LineProperties.hxx"
29cdf0e10cSrcweir #include "FillProperties.hxx"
30cdf0e10cSrcweir #include "UserDefinedProperties.hxx"
31cdf0e10cSrcweir #include "PropertyHelper.hxx"
32cdf0e10cSrcweir #include "macros.hxx"
33cdf0e10cSrcweir #include "ContainerHelper.hxx"
34cdf0e10cSrcweir #include "ModifyListenerHelper.hxx"
35cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
36cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp>
37cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
38cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <algorithm>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using namespace ::com::sun::star;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
45cdf0e10cSrcweir using ::com::sun::star::beans::Property;
46cdf0e10cSrcweir using ::osl::MutexGuard;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // ____________________________________________________________
49cdf0e10cSrcweir 
50cdf0e10cSrcweir namespace
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 
53cdf0e10cSrcweir static const ::rtl::OUString lcl_aServiceName(
54cdf0e10cSrcweir     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.StockBar" ));
55cdf0e10cSrcweir 
56cdf0e10cSrcweir struct StaticStockBarInfoHelper_Initializer
57cdf0e10cSrcweir {
operator ()__anonf3cda8970111::StaticStockBarInfoHelper_Initializer58cdf0e10cSrcweir     ::cppu::OPropertyArrayHelper* operator()()
59cdf0e10cSrcweir     {
60cdf0e10cSrcweir         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
61cdf0e10cSrcweir         return &aPropHelper;
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir private:
lcl_GetPropertySequence__anonf3cda8970111::StaticStockBarInfoHelper_Initializer65cdf0e10cSrcweir     uno::Sequence< Property > lcl_GetPropertySequence()
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir         ::std::vector< ::com::sun::star::beans::Property > aProperties;
68cdf0e10cSrcweir         ::chart::LineProperties::AddPropertiesToVector( aProperties );
69cdf0e10cSrcweir         ::chart::FillProperties::AddPropertiesToVector( aProperties );
70cdf0e10cSrcweir         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir         ::std::sort( aProperties.begin(), aProperties.end(),
73cdf0e10cSrcweir                      ::chart::PropertyNameLess() );
74cdf0e10cSrcweir 
75cdf0e10cSrcweir         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir struct StaticStockBarInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticStockBarInfoHelper_Initializer >
81cdf0e10cSrcweir {
82cdf0e10cSrcweir };
83cdf0e10cSrcweir 
84cdf0e10cSrcweir struct StaticStockBarInfo_Initializer
85cdf0e10cSrcweir {
operator ()__anonf3cda8970111::StaticStockBarInfo_Initializer86cdf0e10cSrcweir     uno::Reference< beans::XPropertySetInfo >* operator()()
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
89cdf0e10cSrcweir             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticStockBarInfoHelper::get() ) );
90cdf0e10cSrcweir         return &xPropertySetInfo;
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir };
93cdf0e10cSrcweir 
94cdf0e10cSrcweir struct StaticStockBarInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticStockBarInfo_Initializer >
95cdf0e10cSrcweir {
96cdf0e10cSrcweir };
97cdf0e10cSrcweir 
98cdf0e10cSrcweir struct StaticStockBarDefaults_Initializer
99cdf0e10cSrcweir {
operator ()__anonf3cda8970111::StaticStockBarDefaults_Initializer100cdf0e10cSrcweir     ::chart::tPropertyValueMap* operator()()
101cdf0e10cSrcweir     {
102cdf0e10cSrcweir         static ::chart::tPropertyValueMap aStaticDefaults;
103cdf0e10cSrcweir         lcl_AddDefaultsToMap( aStaticDefaults );
104cdf0e10cSrcweir         return &aStaticDefaults;
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir private:
lcl_AddDefaultsToMap__anonf3cda8970111::StaticStockBarDefaults_Initializer107cdf0e10cSrcweir     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
108cdf0e10cSrcweir     {
109cdf0e10cSrcweir         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
110cdf0e10cSrcweir         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         // override other defaults
113cdf0e10cSrcweir         ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff ); // white
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir struct StaticStockBarDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticStockBarDefaults_Initializer >
118cdf0e10cSrcweir {
119cdf0e10cSrcweir };
120cdf0e10cSrcweir 
121cdf0e10cSrcweir } // anonymous namespace
122cdf0e10cSrcweir 
123cdf0e10cSrcweir // ____________________________________________________________
124cdf0e10cSrcweir 
125cdf0e10cSrcweir namespace chart
126cdf0e10cSrcweir {
127cdf0e10cSrcweir 
StockBar(bool bRisingCourse)128cdf0e10cSrcweir StockBar::StockBar( bool bRisingCourse ) :
129cdf0e10cSrcweir         ::property::OPropertySet( m_aMutex ),
130cdf0e10cSrcweir     m_bRisingCourse( bRisingCourse ),
131cdf0e10cSrcweir     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
132cdf0e10cSrcweir {
133cdf0e10cSrcweir     if( ! m_bRisingCourse )
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         setFastPropertyValue_NoBroadcast(
136cdf0e10cSrcweir             ::chart::FillProperties::PROP_FILL_COLOR,
137cdf0e10cSrcweir             uno::makeAny( sal_Int32( 0x000000 ))); // black
138cdf0e10cSrcweir         setFastPropertyValue_NoBroadcast(
139cdf0e10cSrcweir             ::chart::LineProperties::PROP_LINE_COLOR,
140cdf0e10cSrcweir             uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
StockBar(const StockBar & rOther)144cdf0e10cSrcweir StockBar::StockBar( const StockBar & rOther ) :
145cdf0e10cSrcweir         MutexContainer(),
146cdf0e10cSrcweir         impl::StockBar_Base(),
147cdf0e10cSrcweir         ::property::OPropertySet( rOther, m_aMutex ),
148cdf0e10cSrcweir     m_bRisingCourse( rOther.m_bRisingCourse ),
149cdf0e10cSrcweir     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
150cdf0e10cSrcweir {}
151cdf0e10cSrcweir 
~StockBar()152cdf0e10cSrcweir StockBar::~StockBar()
153cdf0e10cSrcweir {}
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
156cdf0e10cSrcweir // ____ XCloneable ____
createClone()157cdf0e10cSrcweir uno::Reference< util::XCloneable > SAL_CALL StockBar::createClone()
158cdf0e10cSrcweir     throw (uno::RuntimeException)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     return uno::Reference< util::XCloneable >( new StockBar( *this ));
161cdf0e10cSrcweir }
162cdf0e10cSrcweir 
163cdf0e10cSrcweir // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const164cdf0e10cSrcweir uno::Any StockBar::GetDefaultValue( sal_Int32 nHandle ) const
165cdf0e10cSrcweir     throw(beans::UnknownPropertyException)
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     const tPropertyValueMap& rStaticDefaults = *StaticStockBarDefaults::get();
168cdf0e10cSrcweir     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
169cdf0e10cSrcweir     if( aFound == rStaticDefaults.end() )
170cdf0e10cSrcweir         return uno::Any();
171cdf0e10cSrcweir     return (*aFound).second;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
getInfoHelper()174cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & SAL_CALL StockBar::getInfoHelper()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir     return *StaticStockBarInfoHelper::get();
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir // ____ XPropertySet ____
getPropertySetInfo()180cdf0e10cSrcweir Reference< beans::XPropertySetInfo > SAL_CALL StockBar::getPropertySetInfo()
181cdf0e10cSrcweir     throw (uno::RuntimeException)
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     return *StaticStockBarInfo::get();
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir // ____ XModifyBroadcaster ____
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)187cdf0e10cSrcweir void SAL_CALL StockBar::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
188cdf0e10cSrcweir     throw (uno::RuntimeException)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     try
191cdf0e10cSrcweir     {
192cdf0e10cSrcweir         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
193cdf0e10cSrcweir         xBroadcaster->addModifyListener( aListener );
194cdf0e10cSrcweir     }
195cdf0e10cSrcweir     catch( const uno::Exception & ex )
196cdf0e10cSrcweir     {
197cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)201cdf0e10cSrcweir void SAL_CALL StockBar::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
202cdf0e10cSrcweir     throw (uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     try
205cdf0e10cSrcweir     {
206cdf0e10cSrcweir         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
207cdf0e10cSrcweir         xBroadcaster->removeModifyListener( aListener );
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir     catch( const uno::Exception & ex )
210cdf0e10cSrcweir     {
211cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
212cdf0e10cSrcweir     }
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)216cdf0e10cSrcweir void SAL_CALL StockBar::modified( const lang::EventObject& aEvent )
217cdf0e10cSrcweir     throw (uno::RuntimeException)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     m_xModifyEventForwarder->modified( aEvent );
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)223cdf0e10cSrcweir void SAL_CALL StockBar::disposing( const lang::EventObject& /* Source */ )
224cdf0e10cSrcweir     throw (uno::RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     // nothing
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir // ____ OPropertySet ____
firePropertyChangeEvent()230cdf0e10cSrcweir void StockBar::firePropertyChangeEvent()
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     fireModifyEvent();
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
fireModifyEvent()235cdf0e10cSrcweir void StockBar::fireModifyEvent()
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir // ================================================================================
241cdf0e10cSrcweir 
getSupportedServiceNames_Static()242cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > StockBar::getSupportedServiceNames_Static()
243cdf0e10cSrcweir {
244cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aServices( 2 );
245cdf0e10cSrcweir     aServices[ 0 ] = C2U( "com.sun.star.chart2.StockBar" );
246cdf0e10cSrcweir     aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
247cdf0e10cSrcweir     return aServices;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
251cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL( StockBar, lcl_aServiceName );
252cdf0e10cSrcweir 
253cdf0e10cSrcweir using impl::StockBar_Base;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( StockBar, StockBar_Base, ::property::OPropertySet )
256cdf0e10cSrcweir 
257cdf0e10cSrcweir } //  namespace chart
258