1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include "UncachedDataSequence.hxx"
23 #include "PropertyHelper.hxx"
24 #include "CommonFunctors.hxx"
25 #include "ModifyListenerHelper.hxx"
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <rtl/math.hxx>
31 using namespace ::com::sun::star
;
33 using ::com::sun::star::uno::Sequence
;
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::uno::Any
;
36 using ::osl::MutexGuard
;
38 // necessary for MS compiler
39 using ::comphelper::OPropertyContainer
;
40 using ::chart::impl::UncachedDataSequence_Base
;
44 static const OUString
lcl_aServiceName( "com.sun.star.comp.chart.UncachedDataSequence" );
48 PROP_NUMBERFORMAT_KEY
,
52 } // anonymous namespace
55 // ____________________
59 UncachedDataSequence::UncachedDataSequence(
60 const Reference
< chart2::XInternalDataProvider
> & xIntDataProv
,
61 const OUString
& rRangeRepresentation
)
62 : OPropertyContainer( GetBroadcastHelper()),
63 UncachedDataSequence_Base( GetMutex()),
64 m_nNumberFormatKey(0),
65 m_xDataProvider( xIntDataProv
),
66 m_aSourceRepresentation( rRangeRepresentation
),
67 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
72 UncachedDataSequence::UncachedDataSequence(
73 const Reference
< chart2::XInternalDataProvider
> & xIntDataProv
,
74 const OUString
& rRangeRepresentation
,
75 const OUString
& rRole
)
76 : OPropertyContainer( GetBroadcastHelper()),
77 UncachedDataSequence_Base( GetMutex()),
78 m_nNumberFormatKey(0),
79 m_xDataProvider( xIntDataProv
),
80 m_aSourceRepresentation( rRangeRepresentation
),
81 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
84 setFastPropertyValue_NoBroadcast( PROP_PROPOSED_ROLE
, uno::makeAny( rRole
));
87 UncachedDataSequence::UncachedDataSequence( const UncachedDataSequence
& rSource
)
88 : ::comphelper::OMutexAndBroadcastHelper(),
89 OPropertyContainer( GetBroadcastHelper()),
90 ::comphelper::OPropertyArrayUsageHelper
< UncachedDataSequence
>(),
91 UncachedDataSequence_Base( GetMutex()),
92 m_nNumberFormatKey( rSource
.m_nNumberFormatKey
),
93 m_sRole( rSource
.m_sRole
),
94 m_xDataProvider( rSource
.m_xDataProvider
),
95 m_aSourceRepresentation( rSource
.m_aSourceRepresentation
),
96 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
101 UncachedDataSequence::~UncachedDataSequence()
104 void UncachedDataSequence::registerProperties()
106 registerProperty( "NumberFormatKey",
107 PROP_NUMBERFORMAT_KEY
,
108 0, // PropertyAttributes
109 & m_nNumberFormatKey
,
110 ::getCppuType( & m_nNumberFormatKey
) );
112 registerProperty( "Role",
114 0, // PropertyAttributes
116 ::getCppuType( & m_sRole
) );
118 registerProperty( "CachedXMLRange",
120 0, // PropertyAttributes
122 ::getCppuType( & m_aXMLRange
) );
125 // ================================================================================
127 Sequence
< OUString
> UncachedDataSequence::getSupportedServiceNames_Static()
129 Sequence
< OUString
> aServices( 4 );
130 aServices
[ 0 ] = lcl_aServiceName
;
131 aServices
[ 1 ] = "com.sun.star.chart2.data.DataSequence";
132 aServices
[ 2 ] = "com.sun.star.chart2.data.NumericalDataSequence";
133 aServices
[ 3 ] = "com.sun.star.chart2.data.TextualDataSequence";
137 IMPLEMENT_FORWARD_XINTERFACE2( UncachedDataSequence
, UncachedDataSequence_Base
, OPropertyContainer
)
138 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UncachedDataSequence
, UncachedDataSequence_Base
, OPropertyContainer
)
140 // ____ XPropertySet ____
141 Reference
< beans::XPropertySetInfo
> SAL_CALL
UncachedDataSequence::getPropertySetInfo()
142 throw(uno::RuntimeException
)
144 return Reference
< beans::XPropertySetInfo
>( createPropertySetInfo( getInfoHelper() ) );
147 // ____ ::comphelper::OPropertySetHelper ____
148 // __________________________________________
149 ::cppu::IPropertyArrayHelper
& UncachedDataSequence::getInfoHelper()
151 return *getArrayHelper();
154 // ____ ::comphelper::OPropertyArrayHelper ____
155 // ____________________________________________
156 ::cppu::IPropertyArrayHelper
* UncachedDataSequence::createArrayHelper() const
158 Sequence
< beans::Property
> aProps
;
159 // describes all properties which have been registered in the ctor
160 describeProperties( aProps
);
162 return new ::cppu::OPropertyArrayHelper( aProps
);
165 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
166 APPHELPER_XSERVICEINFO_IMPL( UncachedDataSequence
, lcl_aServiceName
)
168 // ================================================================================
170 // ________ XNumericalDataSequence ________
171 Sequence
< double > SAL_CALL
UncachedDataSequence::getNumericalData()
172 throw (uno::RuntimeException
)
174 Sequence
< double > aResult
;
175 MutexGuard
aGuard( GetMutex() );
176 if( m_xDataProvider
.is())
178 Sequence
< uno::Any
> aValues( m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
));
179 aResult
.realloc( aValues
.getLength());
180 ::std::transform( aValues
.getConstArray(), aValues
.getConstArray() + aValues
.getLength(),
181 aResult
.getArray(), CommonFunctors::AnyToDouble());
186 // ________ XTextualDataSequence ________
187 Sequence
< OUString
> SAL_CALL
UncachedDataSequence::getTextualData()
188 throw (uno::RuntimeException
)
190 Sequence
< OUString
> aResult
;
191 MutexGuard
aGuard( GetMutex() );
192 if( m_xDataProvider
.is())
194 Sequence
< uno::Any
> aValues( m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
));
195 aResult
.realloc( aValues
.getLength());
196 ::std::transform( aValues
.getConstArray(), aValues
.getConstArray() + aValues
.getLength(),
197 aResult
.getArray(), CommonFunctors::AnyToString());
202 // ________ XDataSequence ________
203 Sequence
< Any
> SAL_CALL
UncachedDataSequence::getData()
204 throw (uno::RuntimeException
)
206 MutexGuard
aGuard( GetMutex() );
207 if( m_xDataProvider
.is())
208 return m_xDataProvider
->getDataByRangeRepresentation( m_aSourceRepresentation
);
209 return Sequence
< Any
>();
212 OUString SAL_CALL
UncachedDataSequence::getSourceRangeRepresentation()
213 throw (uno::RuntimeException
)
219 Sequence
< OUString
> SAL_CALL
UncachedDataSequence::generateLabel( chart2::data::LabelOrigin
)
220 throw (uno::RuntimeException
)
222 // auto-generated label is an empty string
223 return Sequence
< OUString
>(1);
226 ::sal_Int32 SAL_CALL
UncachedDataSequence::getNumberFormatKeyByIndex( ::sal_Int32
)
227 throw (lang::IndexOutOfBoundsException
,
228 uno::RuntimeException
)
230 return m_nNumberFormatKey
;
233 // ____ XIndexReplace ____
234 void SAL_CALL
UncachedDataSequence::replaceByIndex( ::sal_Int32 Index
, const uno::Any
& Element
)
235 throw (lang::IllegalArgumentException
,
236 lang::IndexOutOfBoundsException
,
237 lang::WrappedTargetException
,
238 uno::RuntimeException
)
240 MutexGuard
aGuard( GetMutex() );
241 Sequence
< Any
> aData( getData());
242 if( Index
< aData
.getLength() &&
243 m_xDataProvider
.is() )
245 aData
[Index
] = Element
;
246 m_xDataProvider
->setDataByRangeRepresentation( m_aSourceRepresentation
, aData
);
251 // ____ XIndexAccess (base of XIndexReplace) ____
252 ::sal_Int32 SAL_CALL
UncachedDataSequence::getCount()
253 throw (uno::RuntimeException
)
255 OSL_FAIL( "Implement!" );
259 uno::Any SAL_CALL
UncachedDataSequence::getByIndex( ::sal_Int32
)
260 throw (lang::IndexOutOfBoundsException
,
261 lang::WrappedTargetException
,
262 uno::RuntimeException
)
264 OSL_FAIL( "Implement!" );
268 // ____ XElementAccess (base of XIndexAccess) ____
269 uno::Type SAL_CALL
UncachedDataSequence::getElementType()
270 throw (uno::RuntimeException
)
272 return ::getCppuType( reinterpret_cast< uno::Any
* >(0));
275 ::sal_Bool SAL_CALL
UncachedDataSequence::hasElements()
276 throw (uno::RuntimeException
)
278 if( ! m_xDataProvider
.is())
280 return m_xDataProvider
->hasDataByRangeRepresentation( m_aSourceRepresentation
);
284 OUString SAL_CALL
UncachedDataSequence::getName()
285 throw (uno::RuntimeException
)
287 return m_aSourceRepresentation
;
290 void SAL_CALL
UncachedDataSequence::setName( const OUString
& aName
)
291 throw (uno::RuntimeException
)
293 m_aSourceRepresentation
= aName
;
299 Reference
< util::XCloneable
> SAL_CALL
UncachedDataSequence::createClone()
300 throw (uno::RuntimeException
)
302 UncachedDataSequence
* pNewSeq
= new UncachedDataSequence( *this );
303 return Reference
< util::XCloneable
>( pNewSeq
);
307 // ____ XModifiable ____
308 ::sal_Bool SAL_CALL
UncachedDataSequence::isModified()
309 throw (uno::RuntimeException
)
314 void SAL_CALL
UncachedDataSequence::setModified( ::sal_Bool bModified
)
315 throw (beans::PropertyVetoException
,
316 uno::RuntimeException
)
322 // ____ XModifyBroadcaster (base of XModifiable) ____
323 void SAL_CALL
UncachedDataSequence::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
324 throw (uno::RuntimeException
)
328 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
329 xBroadcaster
->addModifyListener( aListener
);
331 catch( const uno::Exception
& ex
)
333 ASSERT_EXCEPTION( ex
);
337 void SAL_CALL
UncachedDataSequence::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
338 throw (uno::RuntimeException
)
342 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
343 xBroadcaster
->removeModifyListener( aListener
);
345 catch( const uno::Exception
& ex
)
347 ASSERT_EXCEPTION( ex
);
351 void UncachedDataSequence::fireModifyEvent()
353 // @todo: currently never called, as data changes are not yet reported by
355 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */