1*cde9e8dcSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*cde9e8dcSAndrew Rist * distributed with this work for additional information 6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance 9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an 15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the 17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations 18*cde9e8dcSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*cde9e8dcSAndrew Rist *************************************************************/ 21*cde9e8dcSAndrew Rist 22*cde9e8dcSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_chart2.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "UncachedDataSequence.hxx" 28cdf0e10cSrcweir #include "macros.hxx" 29cdf0e10cSrcweir #include "PropertyHelper.hxx" 30cdf0e10cSrcweir #include "CommonFunctors.hxx" 31cdf0e10cSrcweir #include "ModifyListenerHelper.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <algorithm> 34cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 35cdf0e10cSrcweir #include <rtl/math.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir using namespace ::com::sun::star; 38cdf0e10cSrcweir 39cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 40cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 41cdf0e10cSrcweir using ::com::sun::star::uno::Any; 42cdf0e10cSrcweir using ::rtl::OUString; 43cdf0e10cSrcweir using ::osl::MutexGuard; 44cdf0e10cSrcweir 45cdf0e10cSrcweir // necessary for MS compiler 46cdf0e10cSrcweir using ::comphelper::OPropertyContainer; 47cdf0e10cSrcweir using ::chart::impl::UncachedDataSequence_Base; 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace 50cdf0e10cSrcweir { 51cdf0e10cSrcweir static const OUString lcl_aServiceName( 52cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.UncachedDataSequence" )); 53cdf0e10cSrcweir 54cdf0e10cSrcweir enum 55cdf0e10cSrcweir { 56cdf0e10cSrcweir // PROP_SOURCE_IDENTIFIER, 57cdf0e10cSrcweir PROP_NUMBERFORMAT_KEY, 58cdf0e10cSrcweir PROP_PROPOSED_ROLE, 59cdf0e10cSrcweir PROP_XML_RANGE 60cdf0e10cSrcweir }; 61cdf0e10cSrcweir } // anonymous namespace 62cdf0e10cSrcweir 63cdf0e10cSrcweir 64cdf0e10cSrcweir // ____________________ 65cdf0e10cSrcweir namespace chart 66cdf0e10cSrcweir { 67cdf0e10cSrcweir 68cdf0e10cSrcweir UncachedDataSequence::UncachedDataSequence( 69cdf0e10cSrcweir const Reference< chart2::XInternalDataProvider > & xIntDataProv, 70cdf0e10cSrcweir const OUString & rRangeRepresentation ) 71cdf0e10cSrcweir : OPropertyContainer( GetBroadcastHelper()), 72cdf0e10cSrcweir UncachedDataSequence_Base( GetMutex()), 73cdf0e10cSrcweir m_nNumberFormatKey(0), 74cdf0e10cSrcweir m_xDataProvider( xIntDataProv ), 75cdf0e10cSrcweir m_aSourceRepresentation( rRangeRepresentation ), 76cdf0e10cSrcweir m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir registerProperties(); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir UncachedDataSequence::UncachedDataSequence( 82cdf0e10cSrcweir const Reference< chart2::XInternalDataProvider > & xIntDataProv, 83cdf0e10cSrcweir const OUString & rRangeRepresentation, 84cdf0e10cSrcweir const OUString & rRole ) 85cdf0e10cSrcweir : OPropertyContainer( GetBroadcastHelper()), 86cdf0e10cSrcweir UncachedDataSequence_Base( GetMutex()), 87cdf0e10cSrcweir m_nNumberFormatKey(0), 88cdf0e10cSrcweir m_xDataProvider( xIntDataProv ), 89cdf0e10cSrcweir m_aSourceRepresentation( rRangeRepresentation ), 90cdf0e10cSrcweir m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir registerProperties(); 93cdf0e10cSrcweir setFastPropertyValue_NoBroadcast( PROP_PROPOSED_ROLE, uno::makeAny( rRole )); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir 96cdf0e10cSrcweir UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence & rSource ) 97cdf0e10cSrcweir : ::comphelper::OMutexAndBroadcastHelper(), 98cdf0e10cSrcweir OPropertyContainer( GetBroadcastHelper()), 99cdf0e10cSrcweir ::comphelper::OPropertyArrayUsageHelper< UncachedDataSequence >(), 100cdf0e10cSrcweir UncachedDataSequence_Base( GetMutex()), 101cdf0e10cSrcweir m_nNumberFormatKey( rSource.m_nNumberFormatKey ), 102cdf0e10cSrcweir m_sRole( rSource.m_sRole ), 103cdf0e10cSrcweir m_xDataProvider( rSource.m_xDataProvider ), 104cdf0e10cSrcweir m_aSourceRepresentation( rSource.m_aSourceRepresentation ), 105cdf0e10cSrcweir m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir registerProperties(); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir 110cdf0e10cSrcweir UncachedDataSequence::~UncachedDataSequence() 111cdf0e10cSrcweir {} 112cdf0e10cSrcweir 113cdf0e10cSrcweir void UncachedDataSequence::registerProperties() 114cdf0e10cSrcweir { 115cdf0e10cSrcweir registerProperty( C2U( "NumberFormatKey" ), 116cdf0e10cSrcweir PROP_NUMBERFORMAT_KEY, 117cdf0e10cSrcweir 0, // PropertyAttributes 118cdf0e10cSrcweir & m_nNumberFormatKey, 119cdf0e10cSrcweir ::getCppuType( & m_nNumberFormatKey ) ); 120cdf0e10cSrcweir 121cdf0e10cSrcweir registerProperty( C2U( "Role" ), 122cdf0e10cSrcweir PROP_PROPOSED_ROLE, 123cdf0e10cSrcweir 0, // PropertyAttributes 124cdf0e10cSrcweir & m_sRole, 125cdf0e10cSrcweir ::getCppuType( & m_sRole ) ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir registerProperty( C2U( "CachedXMLRange" ), 128cdf0e10cSrcweir PROP_XML_RANGE, 129cdf0e10cSrcweir 0, // PropertyAttributes 130cdf0e10cSrcweir & m_aXMLRange, 131cdf0e10cSrcweir ::getCppuType( & m_aXMLRange ) ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir // ================================================================================ 135cdf0e10cSrcweir 136cdf0e10cSrcweir Sequence< OUString > UncachedDataSequence::getSupportedServiceNames_Static() 137cdf0e10cSrcweir { 138cdf0e10cSrcweir Sequence< OUString > aServices( 4 ); 139cdf0e10cSrcweir aServices[ 0 ] = lcl_aServiceName; 140cdf0e10cSrcweir aServices[ 1 ] = C2U( "com.sun.star.chart2.data.DataSequence" ); 141cdf0e10cSrcweir aServices[ 2 ] = C2U( "com.sun.star.chart2.data.NumericalDataSequence" ); 142cdf0e10cSrcweir aServices[ 3 ] = C2U( "com.sun.star.chart2.data.TextualDataSequence" ); 143cdf0e10cSrcweir return aServices; 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer ) 147cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( UncachedDataSequence, UncachedDataSequence_Base, OPropertyContainer ) 148cdf0e10cSrcweir 149cdf0e10cSrcweir // ____ XPropertySet ____ 150cdf0e10cSrcweir Reference< beans::XPropertySetInfo > SAL_CALL UncachedDataSequence::getPropertySetInfo() 151cdf0e10cSrcweir throw(uno::RuntimeException) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir return Reference< beans::XPropertySetInfo >( createPropertySetInfo( getInfoHelper() ) ); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir // ____ ::comphelper::OPropertySetHelper ____ 157cdf0e10cSrcweir // __________________________________________ 158cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& UncachedDataSequence::getInfoHelper() 159cdf0e10cSrcweir { 160cdf0e10cSrcweir return *getArrayHelper(); 161cdf0e10cSrcweir } 162cdf0e10cSrcweir 163cdf0e10cSrcweir // ____ ::comphelper::OPropertyArrayHelper ____ 164cdf0e10cSrcweir // ____________________________________________ 165cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* UncachedDataSequence::createArrayHelper() const 166cdf0e10cSrcweir { 167cdf0e10cSrcweir Sequence< beans::Property > aProps; 168cdf0e10cSrcweir // describes all properties which have been registered in the ctor 169cdf0e10cSrcweir describeProperties( aProps ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir return new ::cppu::OPropertyArrayHelper( aProps ); 172cdf0e10cSrcweir } 173cdf0e10cSrcweir 174cdf0e10cSrcweir // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 175cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL( UncachedDataSequence, lcl_aServiceName ) 176cdf0e10cSrcweir 177cdf0e10cSrcweir // ================================================================================ 178cdf0e10cSrcweir 179cdf0e10cSrcweir // ________ XNumericalDataSequence ________ 180cdf0e10cSrcweir Sequence< double > SAL_CALL UncachedDataSequence::getNumericalData() 181cdf0e10cSrcweir throw (uno::RuntimeException) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir Sequence< double > aResult; 184cdf0e10cSrcweir // /-- 185cdf0e10cSrcweir MutexGuard aGuard( GetMutex() ); 186cdf0e10cSrcweir if( m_xDataProvider.is()) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation )); 189cdf0e10cSrcweir aResult.realloc( aValues.getLength()); 190cdf0e10cSrcweir ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(), 191cdf0e10cSrcweir aResult.getArray(), CommonFunctors::AnyToDouble()); 192cdf0e10cSrcweir } 193cdf0e10cSrcweir return aResult; 194cdf0e10cSrcweir // \-- 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir // ________ XTextualDataSequence ________ 198cdf0e10cSrcweir Sequence< OUString > SAL_CALL UncachedDataSequence::getTextualData() 199cdf0e10cSrcweir throw (uno::RuntimeException) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir Sequence< OUString > aResult; 202cdf0e10cSrcweir // /-- 203cdf0e10cSrcweir MutexGuard aGuard( GetMutex() ); 204cdf0e10cSrcweir if( m_xDataProvider.is()) 205cdf0e10cSrcweir { 206cdf0e10cSrcweir Sequence< uno::Any > aValues( m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation )); 207cdf0e10cSrcweir aResult.realloc( aValues.getLength()); 208cdf0e10cSrcweir ::std::transform( aValues.getConstArray(), aValues.getConstArray() + aValues.getLength(), 209cdf0e10cSrcweir aResult.getArray(), CommonFunctors::AnyToString()); 210cdf0e10cSrcweir } 211cdf0e10cSrcweir return aResult; 212cdf0e10cSrcweir // \-- 213cdf0e10cSrcweir } 214cdf0e10cSrcweir 215cdf0e10cSrcweir // ________ XDataSequence ________ 216cdf0e10cSrcweir Sequence< Any > SAL_CALL UncachedDataSequence::getData() 217cdf0e10cSrcweir throw (uno::RuntimeException) 218cdf0e10cSrcweir { 219cdf0e10cSrcweir // /-- 220cdf0e10cSrcweir MutexGuard aGuard( GetMutex() ); 221cdf0e10cSrcweir if( m_xDataProvider.is()) 222cdf0e10cSrcweir return m_xDataProvider->getDataByRangeRepresentation( m_aSourceRepresentation ); 223cdf0e10cSrcweir return Sequence< Any >(); 224cdf0e10cSrcweir // \-- 225cdf0e10cSrcweir } 226cdf0e10cSrcweir 227cdf0e10cSrcweir OUString SAL_CALL UncachedDataSequence::getSourceRangeRepresentation() 228cdf0e10cSrcweir throw (uno::RuntimeException) 229cdf0e10cSrcweir { 230cdf0e10cSrcweir return getName(); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir 233cdf0e10cSrcweir 234cdf0e10cSrcweir Sequence< OUString > SAL_CALL UncachedDataSequence::generateLabel( chart2::data::LabelOrigin ) 235cdf0e10cSrcweir throw (uno::RuntimeException) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir // auto-generated label is an empty string 238cdf0e10cSrcweir static const Sequence< OUString > aOneEmptyString( 1 ); 239cdf0e10cSrcweir return aOneEmptyString; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir ::sal_Int32 SAL_CALL UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32 ) 243cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, 244cdf0e10cSrcweir uno::RuntimeException) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir return m_nNumberFormatKey; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir // ____ XIndexReplace ____ 250cdf0e10cSrcweir void SAL_CALL UncachedDataSequence::replaceByIndex( ::sal_Int32 Index, const uno::Any& Element ) 251cdf0e10cSrcweir throw (lang::IllegalArgumentException, 252cdf0e10cSrcweir lang::IndexOutOfBoundsException, 253cdf0e10cSrcweir lang::WrappedTargetException, 254cdf0e10cSrcweir uno::RuntimeException) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir // /-- 257cdf0e10cSrcweir MutexGuard aGuard( GetMutex() ); 258cdf0e10cSrcweir Sequence< Any > aData( getData()); 259cdf0e10cSrcweir if( Index < aData.getLength() && 260cdf0e10cSrcweir m_xDataProvider.is() ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir aData[Index] = Element; 263cdf0e10cSrcweir m_xDataProvider->setDataByRangeRepresentation( m_aSourceRepresentation, aData ); 264cdf0e10cSrcweir fireModifyEvent(); 265cdf0e10cSrcweir } 266cdf0e10cSrcweir } 267cdf0e10cSrcweir 268cdf0e10cSrcweir // ____ XIndexAccess (base of XIndexReplace) ____ 269cdf0e10cSrcweir ::sal_Int32 SAL_CALL UncachedDataSequence::getCount() 270cdf0e10cSrcweir throw (uno::RuntimeException) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir OSL_ENSURE( false, "Implement!" ); 273cdf0e10cSrcweir return 0; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir uno::Any SAL_CALL UncachedDataSequence::getByIndex( ::sal_Int32 ) 277cdf0e10cSrcweir throw (lang::IndexOutOfBoundsException, 278cdf0e10cSrcweir lang::WrappedTargetException, 279cdf0e10cSrcweir uno::RuntimeException) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir OSL_ENSURE( false, "Implement!" ); 282cdf0e10cSrcweir return uno::Any(); 283cdf0e10cSrcweir } 284cdf0e10cSrcweir 285cdf0e10cSrcweir // ____ XElementAccess (base of XIndexAccess) ____ 286cdf0e10cSrcweir uno::Type SAL_CALL UncachedDataSequence::getElementType() 287cdf0e10cSrcweir throw (uno::RuntimeException) 288cdf0e10cSrcweir { 289cdf0e10cSrcweir return ::getCppuType( reinterpret_cast< uno::Any * >(0)); 290cdf0e10cSrcweir } 291cdf0e10cSrcweir 292cdf0e10cSrcweir ::sal_Bool SAL_CALL UncachedDataSequence::hasElements() 293cdf0e10cSrcweir throw (uno::RuntimeException) 294cdf0e10cSrcweir { 295cdf0e10cSrcweir if( ! m_xDataProvider.is()) 296cdf0e10cSrcweir return sal_False; 297cdf0e10cSrcweir return m_xDataProvider->hasDataByRangeRepresentation( m_aSourceRepresentation ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir // ____ XNamed ____ 301cdf0e10cSrcweir ::rtl::OUString SAL_CALL UncachedDataSequence::getName() 302cdf0e10cSrcweir throw (uno::RuntimeException) 303cdf0e10cSrcweir { 304cdf0e10cSrcweir return m_aSourceRepresentation; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir 307cdf0e10cSrcweir void SAL_CALL UncachedDataSequence::setName( const OUString& aName ) 308cdf0e10cSrcweir throw (uno::RuntimeException) 309cdf0e10cSrcweir { 310cdf0e10cSrcweir m_aSourceRepresentation = aName; 311cdf0e10cSrcweir fireModifyEvent(); 312cdf0e10cSrcweir } 313cdf0e10cSrcweir 314cdf0e10cSrcweir 315cdf0e10cSrcweir 316cdf0e10cSrcweir Reference< util::XCloneable > SAL_CALL UncachedDataSequence::createClone() 317cdf0e10cSrcweir throw (uno::RuntimeException) 318cdf0e10cSrcweir { 319cdf0e10cSrcweir UncachedDataSequence * pNewSeq = new UncachedDataSequence( *this ); 320cdf0e10cSrcweir return Reference< util::XCloneable >( pNewSeq ); 321cdf0e10cSrcweir } 322cdf0e10cSrcweir 323cdf0e10cSrcweir 324cdf0e10cSrcweir // ____ XModifiable ____ 325cdf0e10cSrcweir ::sal_Bool SAL_CALL UncachedDataSequence::isModified() 326cdf0e10cSrcweir throw (uno::RuntimeException) 327cdf0e10cSrcweir { 328cdf0e10cSrcweir return sal_False; 329cdf0e10cSrcweir } 330cdf0e10cSrcweir 331cdf0e10cSrcweir void SAL_CALL UncachedDataSequence::setModified( ::sal_Bool bModified ) 332cdf0e10cSrcweir throw (beans::PropertyVetoException, 333cdf0e10cSrcweir uno::RuntimeException) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir if( bModified ) 336cdf0e10cSrcweir fireModifyEvent(); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir // ____ XModifyBroadcaster (base of XModifiable) ____ 340cdf0e10cSrcweir void SAL_CALL UncachedDataSequence::addModifyListener( const Reference< util::XModifyListener >& aListener ) 341cdf0e10cSrcweir throw (uno::RuntimeException) 342cdf0e10cSrcweir { 343cdf0e10cSrcweir try 344cdf0e10cSrcweir { 345cdf0e10cSrcweir Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); 346cdf0e10cSrcweir xBroadcaster->addModifyListener( aListener ); 347cdf0e10cSrcweir } 348cdf0e10cSrcweir catch( const uno::Exception & ex ) 349cdf0e10cSrcweir { 350cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir } 353cdf0e10cSrcweir 354cdf0e10cSrcweir void SAL_CALL UncachedDataSequence::removeModifyListener( const Reference< util::XModifyListener >& aListener ) 355cdf0e10cSrcweir throw (uno::RuntimeException) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir try 358cdf0e10cSrcweir { 359cdf0e10cSrcweir Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); 360cdf0e10cSrcweir xBroadcaster->removeModifyListener( aListener ); 361cdf0e10cSrcweir } 362cdf0e10cSrcweir catch( const uno::Exception & ex ) 363cdf0e10cSrcweir { 364cdf0e10cSrcweir ASSERT_EXCEPTION( ex ); 365cdf0e10cSrcweir } 366cdf0e10cSrcweir } 367cdf0e10cSrcweir 368cdf0e10cSrcweir void UncachedDataSequence::fireModifyEvent() 369cdf0e10cSrcweir { 370cdf0e10cSrcweir // @todo: currently never called, as data changes are not yet reported by 371cdf0e10cSrcweir // the data provider 372cdf0e10cSrcweir m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir } // namespace chart 376