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_charttools.hxx" 26 #include "ErrorBar.hxx" 27 #include "macros.hxx" 28 #include "LineProperties.hxx" 29 #include "ContainerHelper.hxx" 30 #include "EventListenerHelper.hxx" 31 #include "PropertyHelper.hxx" 32 #include "CloneHelper.hxx" 33 34 #include <com/sun/star/beans/PropertyAttribute.hpp> 35 #include <com/sun/star/chart/ErrorBarStyle.hpp> 36 37 #include <rtl/math.hxx> 38 #include <rtl/ustrbuf.hxx> 39 40 using namespace ::com::sun::star; 41 42 using ::rtl::OUString; 43 using ::rtl::OUStringBuffer; 44 using ::com::sun::star::beans::Property; 45 using ::osl::MutexGuard; 46 47 namespace 48 { 49 static const OUString lcl_aServiceName( 50 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ErrorBar" )); 51 52 enum 53 { 54 PROP_ERROR_BAR_STYLE, 55 PROP_ERROR_BAR_POS_ERROR, 56 PROP_ERROR_BAR_NEG_ERROR, 57 PROP_ERROR_BAR_WEIGHT, 58 PROP_ERROR_BAR_SHOW_POS_ERROR, 59 PROP_ERROR_BAR_SHOW_NEG_ERROR 60 }; 61 62 void lcl_AddPropertiesToVector( 63 ::std::vector< Property > & rOutProperties ) 64 { 65 rOutProperties.push_back( 66 Property( C2U( "ErrorBarStyle" ), 67 PROP_ERROR_BAR_STYLE, 68 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), 69 beans::PropertyAttribute::BOUND 70 | beans::PropertyAttribute::MAYBEDEFAULT )); 71 72 rOutProperties.push_back( 73 Property( C2U( "PositiveError" ), 74 PROP_ERROR_BAR_POS_ERROR, 75 ::getCppuType( reinterpret_cast< const double * >(0)), 76 beans::PropertyAttribute::BOUND 77 | beans::PropertyAttribute::MAYBEDEFAULT )); 78 rOutProperties.push_back( 79 Property( C2U( "NegativeError" ), 80 PROP_ERROR_BAR_NEG_ERROR, 81 ::getCppuType( reinterpret_cast< const double * >(0)), 82 beans::PropertyAttribute::BOUND 83 | beans::PropertyAttribute::MAYBEDEFAULT )); 84 85 rOutProperties.push_back( 86 Property( C2U( "Weight" ), 87 PROP_ERROR_BAR_WEIGHT, 88 ::getCppuType( reinterpret_cast< const double * >(0)), 89 beans::PropertyAttribute::BOUND 90 | beans::PropertyAttribute::MAYBEDEFAULT )); 91 92 rOutProperties.push_back( 93 Property( C2U( "ShowPositiveError" ), 94 PROP_ERROR_BAR_SHOW_POS_ERROR, 95 ::getBooleanCppuType(), 96 beans::PropertyAttribute::BOUND 97 | beans::PropertyAttribute::MAYBEDEFAULT )); 98 rOutProperties.push_back( 99 Property( C2U( "ShowNegativeError" ), 100 PROP_ERROR_BAR_SHOW_NEG_ERROR, 101 ::getBooleanCppuType(), 102 beans::PropertyAttribute::BOUND 103 | beans::PropertyAttribute::MAYBEDEFAULT )); 104 } 105 106 struct StaticErrorBarDefaults_Initializer 107 { 108 ::chart::tPropertyValueMap* operator()() 109 { 110 static ::chart::tPropertyValueMap aStaticDefaults; 111 lcl_AddDefaultsToMap( aStaticDefaults ); 112 return &aStaticDefaults; 113 } 114 private: 115 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap ) 116 { 117 ::chart::LineProperties::AddDefaultsToMap( rOutMap ); 118 119 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_STYLE, ::com::sun::star::chart::ErrorBarStyle::NONE ); 120 ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_POS_ERROR, 0.0 ); 121 ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_NEG_ERROR, 0.0 ); 122 ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_WEIGHT, 1.0 ); 123 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_SHOW_POS_ERROR, true ); 124 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_SHOW_NEG_ERROR, true ); 125 } 126 }; 127 128 struct StaticErrorBarDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticErrorBarDefaults_Initializer > 129 { 130 }; 131 132 struct StaticErrorBarInfoHelper_Initializer 133 { 134 ::cppu::OPropertyArrayHelper* operator()() 135 { 136 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() ); 137 return &aPropHelper; 138 } 139 140 private: 141 uno::Sequence< Property > lcl_GetPropertySequence() 142 { 143 ::std::vector< ::com::sun::star::beans::Property > aProperties; 144 lcl_AddPropertiesToVector( aProperties ); 145 ::chart::LineProperties::AddPropertiesToVector( aProperties ); 146 147 ::std::sort( aProperties.begin(), aProperties.end(), 148 ::chart::PropertyNameLess() ); 149 150 return ::chart::ContainerHelper::ContainerToSequence( aProperties ); 151 } 152 153 }; 154 155 struct StaticErrorBarInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticErrorBarInfoHelper_Initializer > 156 { 157 }; 158 159 struct StaticErrorBarInfo_Initializer 160 { 161 uno::Reference< beans::XPropertySetInfo >* operator()() 162 { 163 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( 164 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticErrorBarInfoHelper::get() ) ); 165 return &xPropertySetInfo; 166 } 167 }; 168 169 struct StaticErrorBarInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticErrorBarInfo_Initializer > 170 { 171 }; 172 173 bool lcl_isInternalData( const uno::Reference< chart2::data::XLabeledDataSequence > & xLSeq ) 174 { 175 uno::Reference< lang::XServiceInfo > xServiceInfo( xLSeq, uno::UNO_QUERY ); 176 return ( xServiceInfo.is() && xServiceInfo->getImplementationName().equalsAsciiL( 177 RTL_CONSTASCII_STRINGPARAM("com.sun.star.comp.chart2.LabeledDataSequence"))); 178 } 179 180 } // anonymous namespace 181 182 namespace chart 183 { 184 185 uno::Reference< beans::XPropertySet > createErrorBar( const uno::Reference< uno::XComponentContext > & xContext ) 186 { 187 return new ErrorBar( xContext ); 188 } 189 190 ErrorBar::ErrorBar( 191 uno::Reference< uno::XComponentContext > const & xContext ) : 192 ::property::OPropertySet( m_aMutex ), 193 m_xContext( xContext ), 194 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) 195 {} 196 197 ErrorBar::ErrorBar( const ErrorBar & rOther ) : 198 MutexContainer(), 199 impl::ErrorBar_Base(), 200 ::property::OPropertySet( rOther, m_aMutex ), 201 m_xContext( rOther.m_xContext ), 202 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) 203 { 204 if( ! rOther.m_aDataSequences.empty()) 205 { 206 if( lcl_isInternalData( rOther.m_aDataSequences.front())) 207 CloneHelper::CloneRefVector< tDataSequenceContainer::value_type >( 208 rOther.m_aDataSequences, m_aDataSequences ); 209 else 210 m_aDataSequences = rOther.m_aDataSequences; 211 ModifyListenerHelper::addListenerToAllElements( m_aDataSequences, m_xModifyEventForwarder ); 212 } 213 } 214 215 ErrorBar::~ErrorBar() 216 {} 217 218 uno::Reference< util::XCloneable > SAL_CALL ErrorBar::createClone() 219 { 220 return uno::Reference< util::XCloneable >( new ErrorBar( *this )); 221 } 222 223 // ================================================================================ 224 225 // ____ OPropertySet ____ 226 uno::Any ErrorBar::GetDefaultValue( sal_Int32 nHandle ) const 227 { 228 const tPropertyValueMap& rStaticDefaults = *StaticErrorBarDefaults::get(); 229 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) ); 230 if( aFound == rStaticDefaults.end() ) 231 return uno::Any(); 232 return (*aFound).second; 233 } 234 235 ::cppu::IPropertyArrayHelper & SAL_CALL ErrorBar::getInfoHelper() 236 { 237 return *StaticErrorBarInfoHelper::get(); 238 } 239 240 // ____ XPropertySet ____ 241 uno::Reference< beans::XPropertySetInfo > SAL_CALL ErrorBar::getPropertySetInfo() 242 { 243 return *StaticErrorBarInfo::get(); 244 } 245 246 // ____ XModifyBroadcaster ____ 247 void SAL_CALL ErrorBar::addModifyListener( const uno::Reference< util::XModifyListener >& aListener ) 248 { 249 try 250 { 251 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); 252 xBroadcaster->addModifyListener( aListener ); 253 } 254 catch( const uno::Exception & ex ) 255 { 256 ASSERT_EXCEPTION( ex ); 257 } 258 } 259 260 void SAL_CALL ErrorBar::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener ) 261 { 262 try 263 { 264 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); 265 xBroadcaster->removeModifyListener( aListener ); 266 } 267 catch( const uno::Exception & ex ) 268 { 269 ASSERT_EXCEPTION( ex ); 270 } 271 } 272 273 // ____ XModifyListener ____ 274 void SAL_CALL ErrorBar::modified( const lang::EventObject& aEvent ) 275 { 276 m_xModifyEventForwarder->modified( aEvent ); 277 } 278 279 // ____ XEventListener (base of XModifyListener) ____ 280 void SAL_CALL ErrorBar::disposing( const lang::EventObject& /* Source */ ) 281 { 282 // nothing 283 } 284 285 // ____ XDataSink ____ 286 void SAL_CALL ErrorBar::setData( const uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > >& aData ) 287 { 288 ModifyListenerHelper::removeListenerFromAllElements( m_aDataSequences, m_xModifyEventForwarder ); 289 EventListenerHelper::removeListenerFromAllElements( m_aDataSequences, this ); 290 m_aDataSequences = ContainerHelper::SequenceToVector( aData ); 291 EventListenerHelper::addListenerToAllElements( m_aDataSequences, this ); 292 ModifyListenerHelper::addListenerToAllElements( m_aDataSequences, m_xModifyEventForwarder ); 293 } 294 295 // ____ XDataSource ____ 296 uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ErrorBar::getDataSequences() 297 { 298 return ContainerHelper::ContainerToSequence( m_aDataSequences ); 299 } 300 301 // ____ XChild ____ 302 uno::Reference< uno::XInterface > SAL_CALL ErrorBar::getParent() 303 { 304 return m_xParent; 305 } 306 307 void SAL_CALL ErrorBar::setParent( 308 const uno::Reference< uno::XInterface >& Parent ) 309 { 310 m_xParent.set( Parent ); 311 } 312 313 // ____ OPropertySet ____ 314 void ErrorBar::firePropertyChangeEvent() 315 { 316 fireModifyEvent(); 317 } 318 319 void ErrorBar::fireModifyEvent() 320 { 321 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); 322 } 323 324 // ================================================================================ 325 326 uno::Sequence< ::rtl::OUString > ErrorBar::getSupportedServiceNames_Static() 327 { 328 uno::Sequence< ::rtl::OUString > aServices( 2 ); 329 aServices[ 0 ] = lcl_aServiceName; 330 aServices[ 1 ] = C2U( "com.sun.star.chart2.ErrorBar" ); 331 return aServices; 332 } 333 334 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 335 APPHELPER_XSERVICEINFO_IMPL( ErrorBar, lcl_aServiceName ); 336 337 // needed by MSC compiler 338 using impl::ErrorBar_Base; 339 340 IMPLEMENT_FORWARD_XINTERFACE2( ErrorBar, ErrorBar_Base, OPropertySet ) 341 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ErrorBar, ErrorBar_Base, OPropertySet ) 342 343 } // namespace chart 344