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