1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 31 #include "RegressionEquation.hxx" 32 #include "LineProperties.hxx" 33 #include "FillProperties.hxx" 34 #include "UserDefinedProperties.hxx" 35 #include "CharacterProperties.hxx" 36 #include "PropertyHelper.hxx" 37 #include "macros.hxx" 38 #include "ContainerHelper.hxx" 39 40 #include <com/sun/star/uno/Sequence.hxx> 41 #include <com/sun/star/drawing/FillStyle.hpp> 42 #include <com/sun/star/drawing/LineStyle.hpp> 43 #include <com/sun/star/beans/PropertyAttribute.hpp> 44 #include <com/sun/star/chart2/RelativePosition.hpp> 45 #include <com/sun/star/awt/Size.hpp> 46 47 #include <algorithm> 48 49 using namespace ::com::sun::star; 50 51 using ::com::sun::star::uno::Reference; 52 using ::com::sun::star::beans::Property; 53 using ::osl::MutexGuard; 54 55 // ____________________________________________________________ 56 57 namespace 58 { 59 60 static const ::rtl::OUString lcl_aImplementationName( 61 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.RegressionEquation" )); 62 static const ::rtl::OUString lcl_aServiceName( 63 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" )); 64 65 enum 66 { 67 PROP_EQUATION_SHOW, 68 PROP_EQUATION_SHOW_CORRELATION_COEFF, 69 // PROP_EQUATION_SEPARATOR, 70 PROP_EQUATION_REF_PAGE_SIZE, 71 PROP_EQUATION_REL_POS, 72 PROP_EQUATION_NUMBER_FORMAT 73 }; 74 75 void lcl_AddPropertiesToVector( 76 ::std::vector< Property > & rOutProperties ) 77 { 78 rOutProperties.push_back( 79 Property( C2U( "ShowEquation" ), 80 PROP_EQUATION_SHOW, 81 ::getBooleanCppuType(), 82 beans::PropertyAttribute::BOUND 83 | beans::PropertyAttribute::MAYBEDEFAULT )); 84 85 rOutProperties.push_back( 86 Property( C2U( "ShowCorrelationCoefficient" ), 87 PROP_EQUATION_SHOW_CORRELATION_COEFF, 88 ::getBooleanCppuType(), 89 beans::PropertyAttribute::BOUND 90 | beans::PropertyAttribute::MAYBEDEFAULT )); 91 92 // rOutProperties.push_back( 93 // Property( C2U( "Separator" ), 94 // PROP_EQUATION_SEPARATOR, 95 // ::getCppuType( reinterpret_cast< ::rtl::OUString * >(0)), 96 // beans::PropertyAttribute::BOUND 97 // | beans::PropertyAttribute::MAYBEDEFAULT )); 98 99 rOutProperties.push_back( 100 Property( C2U( "ReferencePageSize" ), 101 PROP_EQUATION_REF_PAGE_SIZE, 102 ::getCppuType( reinterpret_cast< const awt::Size * >(0)), 103 beans::PropertyAttribute::BOUND 104 | beans::PropertyAttribute::MAYBEVOID )); 105 106 rOutProperties.push_back( 107 Property( C2U( "RelativePosition" ), 108 PROP_EQUATION_REL_POS, 109 ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)), 110 beans::PropertyAttribute::BOUND 111 | beans::PropertyAttribute::MAYBEVOID )); 112 113 rOutProperties.push_back( 114 Property( C2U( "NumberFormat" ), 115 PROP_EQUATION_NUMBER_FORMAT, 116 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), 117 beans::PropertyAttribute::BOUND 118 | beans::PropertyAttribute::MAYBEVOID )); 119 } 120 121 struct StaticRegressionEquationDefaults_Initializer 122 { 123 ::chart::tPropertyValueMap* operator()() 124 { 125 static ::chart::tPropertyValueMap aStaticDefaults; 126 lcl_AddDefaultsToMap( aStaticDefaults ); 127 return &aStaticDefaults; 128 } 129 private: 130 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap ) 131 { 132 ::chart::LineProperties::AddDefaultsToMap( rOutMap ); 133 ::chart::FillProperties::AddDefaultsToMap( rOutMap ); 134 ::chart::CharacterProperties::AddDefaultsToMap( rOutMap ); 135 136 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false ); 137 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false ); 138 //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, ::rtl::OUString( sal_Unicode( '\n' ))); 139 140 // override other defaults 141 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE ); 142 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE ); 143 144 float fDefaultCharHeight = 10.0; 145 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight ); 146 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight ); 147 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight ); 148 } 149 }; 150 151 struct StaticRegressionEquationDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticRegressionEquationDefaults_Initializer > 152 { 153 }; 154 155 struct StaticRegressionEquationInfoHelper_Initializer 156 { 157 ::cppu::OPropertyArrayHelper* operator()() 158 { 159 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() ); 160 return &aPropHelper; 161 } 162 163 private: 164 uno::Sequence< Property > lcl_GetPropertySequence() 165 { 166 ::std::vector< ::com::sun::star::beans::Property > aProperties; 167 lcl_AddPropertiesToVector( aProperties ); 168 ::chart::LineProperties::AddPropertiesToVector( aProperties ); 169 ::chart::FillProperties::AddPropertiesToVector( aProperties ); 170 ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); 171 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties ); 172 173 ::std::sort( aProperties.begin(), aProperties.end(), 174 ::chart::PropertyNameLess() ); 175 176 return ::chart::ContainerHelper::ContainerToSequence( aProperties ); 177 } 178 179 }; 180 181 struct StaticRegressionEquationInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionEquationInfoHelper_Initializer > 182 { 183 }; 184 185 struct StaticRegressionEquationInfo_Initializer 186 { 187 uno::Reference< beans::XPropertySetInfo >* operator()() 188 { 189 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( 190 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionEquationInfoHelper::get() ) ); 191 return &xPropertySetInfo; 192 } 193 }; 194 195 struct StaticRegressionEquationInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionEquationInfo_Initializer > 196 { 197 }; 198 199 } // anonymous namespace 200 201 // ____________________________________________________________ 202 203 namespace chart 204 { 205 206 RegressionEquation::RegressionEquation( const Reference< uno::XComponentContext > & xContext ) : 207 ::property::OPropertySet( m_aMutex ), 208 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()), 209 m_xContext( xContext ) 210 {} 211 212 RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) : 213 MutexContainer(), 214 impl::RegressionEquation_Base(), 215 ::property::OPropertySet( rOther, m_aMutex ), 216 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()) 217 {} 218 219 RegressionEquation::~RegressionEquation() 220 {} 221 222 223 // ____ XCloneable ____ 224 uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone() 225 throw (uno::RuntimeException) 226 { 227 return uno::Reference< util::XCloneable >( new RegressionEquation( *this )); 228 } 229 230 // ____ OPropertySet ____ 231 uno::Any RegressionEquation::GetDefaultValue( sal_Int32 nHandle ) const 232 throw(beans::UnknownPropertyException) 233 { 234 const tPropertyValueMap& rStaticDefaults = *StaticRegressionEquationDefaults::get(); 235 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) ); 236 if( aFound == rStaticDefaults.end() ) 237 return uno::Any(); 238 return (*aFound).second; 239 } 240 241 ::cppu::IPropertyArrayHelper & SAL_CALL RegressionEquation::getInfoHelper() 242 { 243 return *StaticRegressionEquationInfoHelper::get(); 244 } 245 246 // ____ XPropertySet ____ 247 Reference< beans::XPropertySetInfo > SAL_CALL RegressionEquation::getPropertySetInfo() 248 throw (uno::RuntimeException) 249 { 250 return *StaticRegressionEquationInfo::get(); 251 } 252 253 // ____ XModifyBroadcaster ____ 254 void SAL_CALL RegressionEquation::addModifyListener( const uno::Reference< util::XModifyListener >& aListener ) 255 throw (uno::RuntimeException) 256 { 257 try 258 { 259 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); 260 xBroadcaster->addModifyListener( aListener ); 261 } 262 catch( const uno::Exception & ex ) 263 { 264 ASSERT_EXCEPTION( ex ); 265 } 266 } 267 268 void SAL_CALL RegressionEquation::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener ) 269 throw (uno::RuntimeException) 270 { 271 try 272 { 273 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); 274 xBroadcaster->removeModifyListener( aListener ); 275 } 276 catch( const uno::Exception & ex ) 277 { 278 ASSERT_EXCEPTION( ex ); 279 } 280 } 281 282 // ____ XModifyListener ____ 283 void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent ) 284 throw (uno::RuntimeException) 285 { 286 m_xModifyEventForwarder->modified( aEvent ); 287 } 288 289 // ____ XEventListener (base of XModifyListener) ____ 290 void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ ) 291 throw (uno::RuntimeException) 292 { 293 // nothing 294 } 295 296 // ____ OPropertySet ____ 297 void RegressionEquation::firePropertyChangeEvent() 298 { 299 fireModifyEvent(); 300 } 301 302 void RegressionEquation::fireModifyEvent() 303 { 304 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); 305 } 306 307 // -------------------------------------------------------------------------------- 308 309 // ____ XTitle ____ 310 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText() 311 throw (uno::RuntimeException) 312 { 313 // /-- 314 MutexGuard aGuard( GetMutex() ); 315 return m_aStrings; 316 // \-- 317 } 318 319 void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings ) 320 throw (uno::RuntimeException) 321 { 322 // /-- 323 MutexGuard aGuard( GetMutex() ); 324 ModifyListenerHelper::removeListenerFromAllElements( 325 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder ); 326 m_aStrings = Strings; 327 ModifyListenerHelper::addListenerToAllElements( 328 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder ); 329 fireModifyEvent(); 330 // \-- 331 } 332 333 // ================================================================================ 334 335 uno::Sequence< ::rtl::OUString > RegressionEquation::getSupportedServiceNames_Static() 336 { 337 const sal_Int32 nNumServices( 5 ); 338 sal_Int32 nI = 0; 339 uno::Sequence< ::rtl::OUString > aServices( nNumServices ); 340 aServices[ nI++ ] = lcl_aServiceName; 341 aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" ); 342 aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" ); 343 aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" ); 344 aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" ); 345 OSL_ASSERT( nNumServices == nI ); 346 return aServices; 347 } 348 349 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 350 APPHELPER_XSERVICEINFO_IMPL( RegressionEquation, lcl_aImplementationName ); 351 352 using impl::RegressionEquation_Base; 353 354 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet ) 355 356 } // namespace chart 357