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 27 #include "RegressionEquation.hxx" 28 #include "LineProperties.hxx" 29 #include "FillProperties.hxx" 30 #include "UserDefinedProperties.hxx" 31 #include "CharacterProperties.hxx" 32 #include "PropertyHelper.hxx" 33 #include "macros.hxx" 34 #include "ContainerHelper.hxx" 35 36 #include <com/sun/star/uno/Sequence.hxx> 37 #include <com/sun/star/drawing/FillStyle.hpp> 38 #include <com/sun/star/drawing/LineStyle.hpp> 39 #include <com/sun/star/beans/PropertyAttribute.hpp> 40 #include <com/sun/star/chart2/RelativePosition.hpp> 41 #include <com/sun/star/awt/Size.hpp> 42 43 #include <algorithm> 44 45 using namespace ::com::sun::star; 46 47 using ::com::sun::star::uno::Reference; 48 using ::com::sun::star::beans::Property; 49 using ::osl::MutexGuard; 50 51 // ____________________________________________________________ 52 53 namespace 54 { 55 56 static const ::rtl::OUString lcl_aImplementationName( 57 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.RegressionEquation" )); 58 static const ::rtl::OUString lcl_aServiceName( 59 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" )); 60 61 enum 62 { 63 PROP_EQUATION_SHOW, 64 PROP_EQUATION_SHOW_CORRELATION_COEFF, 65 // PROP_EQUATION_SEPARATOR, 66 PROP_EQUATION_REF_PAGE_SIZE, 67 PROP_EQUATION_REL_POS, 68 PROP_EQUATION_NUMBER_FORMAT 69 }; 70 71 void lcl_AddPropertiesToVector( 72 ::std::vector< Property > & rOutProperties ) 73 { 74 rOutProperties.push_back( 75 Property( C2U( "ShowEquation" ), 76 PROP_EQUATION_SHOW, 77 ::getBooleanCppuType(), 78 beans::PropertyAttribute::BOUND 79 | beans::PropertyAttribute::MAYBEDEFAULT )); 80 81 rOutProperties.push_back( 82 Property( C2U( "ShowCorrelationCoefficient" ), 83 PROP_EQUATION_SHOW_CORRELATION_COEFF, 84 ::getBooleanCppuType(), 85 beans::PropertyAttribute::BOUND 86 | beans::PropertyAttribute::MAYBEDEFAULT )); 87 88 // rOutProperties.push_back( 89 // Property( C2U( "Separator" ), 90 // PROP_EQUATION_SEPARATOR, 91 // ::getCppuType( reinterpret_cast< ::rtl::OUString * >(0)), 92 // beans::PropertyAttribute::BOUND 93 // | beans::PropertyAttribute::MAYBEDEFAULT )); 94 95 rOutProperties.push_back( 96 Property( C2U( "ReferencePageSize" ), 97 PROP_EQUATION_REF_PAGE_SIZE, 98 ::getCppuType( reinterpret_cast< const awt::Size * >(0)), 99 beans::PropertyAttribute::BOUND 100 | beans::PropertyAttribute::MAYBEVOID )); 101 102 rOutProperties.push_back( 103 Property( C2U( "RelativePosition" ), 104 PROP_EQUATION_REL_POS, 105 ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)), 106 beans::PropertyAttribute::BOUND 107 | beans::PropertyAttribute::MAYBEVOID )); 108 109 rOutProperties.push_back( 110 Property( C2U( "NumberFormat" ), 111 PROP_EQUATION_NUMBER_FORMAT, 112 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), 113 beans::PropertyAttribute::BOUND 114 | beans::PropertyAttribute::MAYBEVOID )); 115 } 116 117 struct StaticRegressionEquationDefaults_Initializer 118 { 119 ::chart::tPropertyValueMap* operator()() 120 { 121 static ::chart::tPropertyValueMap aStaticDefaults; 122 lcl_AddDefaultsToMap( aStaticDefaults ); 123 return &aStaticDefaults; 124 } 125 private: 126 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap ) 127 { 128 ::chart::LineProperties::AddDefaultsToMap( rOutMap ); 129 ::chart::FillProperties::AddDefaultsToMap( rOutMap ); 130 ::chart::CharacterProperties::AddDefaultsToMap( rOutMap ); 131 132 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false ); 133 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false ); 134 //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, ::rtl::OUString( sal_Unicode( '\n' ))); 135 136 // override other defaults 137 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE ); 138 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE ); 139 140 float fDefaultCharHeight = 10.0; 141 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight ); 142 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight ); 143 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight ); 144 } 145 }; 146 147 struct StaticRegressionEquationDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticRegressionEquationDefaults_Initializer > 148 { 149 }; 150 151 struct StaticRegressionEquationInfoHelper_Initializer 152 { 153 ::cppu::OPropertyArrayHelper* operator()() 154 { 155 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() ); 156 return &aPropHelper; 157 } 158 159 private: 160 uno::Sequence< Property > lcl_GetPropertySequence() 161 { 162 ::std::vector< ::com::sun::star::beans::Property > aProperties; 163 lcl_AddPropertiesToVector( aProperties ); 164 ::chart::LineProperties::AddPropertiesToVector( aProperties ); 165 ::chart::FillProperties::AddPropertiesToVector( aProperties ); 166 ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); 167 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties ); 168 169 ::std::sort( aProperties.begin(), aProperties.end(), 170 ::chart::PropertyNameLess() ); 171 172 return ::chart::ContainerHelper::ContainerToSequence( aProperties ); 173 } 174 175 }; 176 177 struct StaticRegressionEquationInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionEquationInfoHelper_Initializer > 178 { 179 }; 180 181 struct StaticRegressionEquationInfo_Initializer 182 { 183 uno::Reference< beans::XPropertySetInfo >* operator()() 184 { 185 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( 186 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionEquationInfoHelper::get() ) ); 187 return &xPropertySetInfo; 188 } 189 }; 190 191 struct StaticRegressionEquationInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionEquationInfo_Initializer > 192 { 193 }; 194 195 } // anonymous namespace 196 197 // ____________________________________________________________ 198 199 namespace chart 200 { 201 202 RegressionEquation::RegressionEquation( const Reference< uno::XComponentContext > & xContext ) : 203 ::property::OPropertySet( m_aMutex ), 204 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()), 205 m_xContext( xContext ) 206 {} 207 208 RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) : 209 MutexContainer(), 210 impl::RegressionEquation_Base(), 211 ::property::OPropertySet( rOther, m_aMutex ), 212 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()) 213 {} 214 215 RegressionEquation::~RegressionEquation() 216 {} 217 218 219 // ____ XCloneable ____ 220 uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone() 221 { 222 return uno::Reference< util::XCloneable >( new RegressionEquation( *this )); 223 } 224 225 // ____ OPropertySet ____ 226 uno::Any RegressionEquation::GetDefaultValue( sal_Int32 nHandle ) const 227 { 228 const tPropertyValueMap& rStaticDefaults = *StaticRegressionEquationDefaults::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 RegressionEquation::getInfoHelper() 236 { 237 return *StaticRegressionEquationInfoHelper::get(); 238 } 239 240 // ____ XPropertySet ____ 241 Reference< beans::XPropertySetInfo > SAL_CALL RegressionEquation::getPropertySetInfo() 242 { 243 return *StaticRegressionEquationInfo::get(); 244 } 245 246 // ____ XModifyBroadcaster ____ 247 void SAL_CALL RegressionEquation::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 RegressionEquation::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 RegressionEquation::modified( const lang::EventObject& aEvent ) 275 { 276 m_xModifyEventForwarder->modified( aEvent ); 277 } 278 279 // ____ XEventListener (base of XModifyListener) ____ 280 void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ ) 281 { 282 // nothing 283 } 284 285 // ____ OPropertySet ____ 286 void RegressionEquation::firePropertyChangeEvent() 287 { 288 fireModifyEvent(); 289 } 290 291 void RegressionEquation::fireModifyEvent() 292 { 293 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); 294 } 295 296 // -------------------------------------------------------------------------------- 297 298 // ____ XTitle ____ 299 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText() 300 { 301 // /-- 302 MutexGuard aGuard( GetMutex() ); 303 return m_aStrings; 304 // \-- 305 } 306 307 void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings ) 308 { 309 // /-- 310 MutexGuard aGuard( GetMutex() ); 311 ModifyListenerHelper::removeListenerFromAllElements( 312 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder ); 313 m_aStrings = Strings; 314 ModifyListenerHelper::addListenerToAllElements( 315 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder ); 316 fireModifyEvent(); 317 // \-- 318 } 319 320 // ================================================================================ 321 322 uno::Sequence< ::rtl::OUString > RegressionEquation::getSupportedServiceNames_Static() 323 { 324 const sal_Int32 nNumServices( 5 ); 325 sal_Int32 nI = 0; 326 uno::Sequence< ::rtl::OUString > aServices( nNumServices ); 327 aServices[ nI++ ] = lcl_aServiceName; 328 aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" ); 329 aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" ); 330 aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" ); 331 aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" ); 332 OSL_ASSERT( nNumServices == nI ); 333 return aServices; 334 } 335 336 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 337 APPHELPER_XSERVICEINFO_IMPL( RegressionEquation, lcl_aImplementationName ); 338 339 using impl::RegressionEquation_Base; 340 341 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet ) 342 343 } // namespace chart 344