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_chartmodel.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 ()__anon0c4710770111::StaticStockBarInfoHelper_Initializer58 ::cppu::OPropertyArrayHelper* operator()()
59 {
60 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
61 return &aPropHelper;
62 }
63
64 private:
lcl_GetPropertySequence__anon0c4710770111::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 ()__anon0c4710770111::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 ()__anon0c4710770111::StaticStockBarDefaults_Initializer100 ::chart::tPropertyValueMap* operator()()
101 {
102 static ::chart::tPropertyValueMap aStaticDefaults;
103 lcl_AddDefaultsToMap( aStaticDefaults );
104 return &aStaticDefaults;
105 }
106 private:
lcl_AddDefaultsToMap__anon0c4710770111::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 {
159 return uno::Reference< util::XCloneable >( new StockBar( *this ));
160 }
161
162 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const163 uno::Any StockBar::GetDefaultValue( sal_Int32 nHandle ) const
164 {
165 const tPropertyValueMap& rStaticDefaults = *StaticStockBarDefaults::get();
166 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
167 if( aFound == rStaticDefaults.end() )
168 return uno::Any();
169 return (*aFound).second;
170 }
171
getInfoHelper()172 ::cppu::IPropertyArrayHelper & SAL_CALL StockBar::getInfoHelper()
173 {
174 return *StaticStockBarInfoHelper::get();
175 }
176
177 // ____ XPropertySet ____
getPropertySetInfo()178 Reference< beans::XPropertySetInfo > SAL_CALL StockBar::getPropertySetInfo()
179 {
180 return *StaticStockBarInfo::get();
181 }
182
183 // ____ XModifyBroadcaster ____
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)184 void SAL_CALL StockBar::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
185 {
186 try
187 {
188 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
189 xBroadcaster->addModifyListener( aListener );
190 }
191 catch( const uno::Exception & ex )
192 {
193 ASSERT_EXCEPTION( ex );
194 }
195 }
196
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)197 void SAL_CALL StockBar::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
198 {
199 try
200 {
201 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
202 xBroadcaster->removeModifyListener( aListener );
203 }
204 catch( const uno::Exception & ex )
205 {
206 ASSERT_EXCEPTION( ex );
207 }
208 }
209
210 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)211 void SAL_CALL StockBar::modified( const lang::EventObject& aEvent )
212 {
213 m_xModifyEventForwarder->modified( aEvent );
214 }
215
216 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)217 void SAL_CALL StockBar::disposing( const lang::EventObject& /* Source */ )
218 {
219 // nothing
220 }
221
222 // ____ OPropertySet ____
firePropertyChangeEvent()223 void StockBar::firePropertyChangeEvent()
224 {
225 fireModifyEvent();
226 }
227
fireModifyEvent()228 void StockBar::fireModifyEvent()
229 {
230 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
231 }
232
233 // ================================================================================
234
getSupportedServiceNames_Static()235 uno::Sequence< ::rtl::OUString > StockBar::getSupportedServiceNames_Static()
236 {
237 uno::Sequence< ::rtl::OUString > aServices( 2 );
238 aServices[ 0 ] = C2U( "com.sun.star.chart2.StockBar" );
239 aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
240 return aServices;
241 }
242
243 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
244 APPHELPER_XSERVICEINFO_IMPL( StockBar, lcl_aServiceName );
245
246 using impl::StockBar_Base;
247
248 IMPLEMENT_FORWARD_XINTERFACE2( StockBar, StockBar_Base, ::property::OPropertySet )
249
250 } // namespace chart
251