Bump version to 4.3-4
[LibreOffice.git] / sc / inc / chart2uno.hxx
blob29deec975e698c0868699d2b8b20cad23cd5cd9b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_SC_INC_CHART2UNO_HXX
21 #define INCLUDED_SC_INC_CHART2UNO_HXX
23 #include "cellsuno.hxx"
24 #include "rangelst.hxx"
25 #include "externalrefmgr.hxx"
26 #include "types.hxx"
27 #include "chartlis.hxx"
29 #include <svl/lstner.hxx>
30 #include <com/sun/star/chart/ChartDataRowSource.hpp>
31 #include <com/sun/star/chart2/data/XDataProvider.hpp>
32 #include <com/sun/star/chart2/data/XSheetDataProvider.hpp>
33 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
34 #include <com/sun/star/chart2/data/XDataSource.hpp>
35 #include <com/sun/star/chart2/data/XDataSequence.hpp>
36 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
37 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
38 #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
39 #include <com/sun/star/chart2/data/DataSequenceRole.hpp>
40 #include <com/sun/star/chart2/XTimeBased.hpp>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/util/XCloneable.hpp>
44 #include <com/sun/star/util/XModifyBroadcaster.hpp>
45 #include <cppuhelper/implbase2.hxx>
46 #include <cppuhelper/implbase5.hxx>
47 #include <cppuhelper/implbase8.hxx>
48 #include <rtl/ustring.hxx>
49 #include <svl/itemprop.hxx>
51 #include <list>
52 #include <vector>
53 #include <boost/shared_ptr.hpp>
54 #include <boost/unordered_set.hpp>
55 #include <boost/noncopyable.hpp>
56 #include <boost/scoped_ptr.hpp>
58 class ScDocument;
60 // DataProvider
61 class ScChart2DataProvider : public
62 ::cppu::WeakImplHelper5<
63 ::com::sun::star::chart2::data::XDataProvider,
64 ::com::sun::star::chart2::data::XSheetDataProvider,
65 ::com::sun::star::chart2::data::XRangeXMLConversion,
66 ::com::sun::star::beans::XPropertySet,
67 ::com::sun::star::lang::XServiceInfo>,
68 SfxListener
70 public:
72 explicit ScChart2DataProvider( ScDocument* pDoc );
73 virtual ~ScChart2DataProvider();
74 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
76 // XDataProvider
77 virtual sal_Bool SAL_CALL createDataSourcePossible(
78 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
79 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
81 virtual ::com::sun::star::uno::Reference<
82 ::com::sun::star::chart2::data::XDataSource > SAL_CALL createDataSource(
83 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
84 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
86 virtual ::com::sun::star::uno::Sequence<
87 ::com::sun::star::beans::PropertyValue > SAL_CALL detectArguments(
88 const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource )
89 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
91 virtual sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
92 const OUString& aRangeRepresentation )
93 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
95 virtual ::com::sun::star::uno::Reference<
96 ::com::sun::star::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
97 const OUString& aRangeRepresentation )
98 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
100 virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
101 createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation )
102 throw (css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
104 virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XRangeSelection > SAL_CALL getRangeSelection()
105 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
107 // XSheetDataProvider
108 virtual sal_Bool SAL_CALL createDataSequenceByFormulaTokensPossible(
109 const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >& aTokens )
110 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
112 virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >
113 SAL_CALL createDataSequenceByFormulaTokens(
114 const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >& aTokens )
115 throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
117 // XRangeXMLConversion
118 virtual OUString SAL_CALL convertRangeToXML( const OUString& sRangeRepresentation )
119 throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
121 virtual OUString SAL_CALL convertRangeFromXML( const OUString& sXMLRange )
122 throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException, std::exception ) SAL_OVERRIDE;
124 // XPropertySet
125 virtual ::com::sun::star::uno::Reference<
126 ::com::sun::star::beans::XPropertySetInfo> SAL_CALL
127 getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
129 virtual void SAL_CALL setPropertyValue(
130 const OUString& rPropertyName,
131 const ::com::sun::star::uno::Any& rValue)
132 throw( ::com::sun::star::beans::UnknownPropertyException,
133 ::com::sun::star::beans::PropertyVetoException,
134 ::com::sun::star::lang::IllegalArgumentException,
135 ::com::sun::star::lang::WrappedTargetException,
136 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
138 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
139 const OUString& rPropertyName)
140 throw( ::com::sun::star::beans::UnknownPropertyException,
141 ::com::sun::star::lang::WrappedTargetException,
142 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 virtual void SAL_CALL addPropertyChangeListener(
145 const OUString& rPropertyName,
146 const ::com::sun::star::uno::Reference<
147 ::com::sun::star::beans::XPropertyChangeListener>& xListener)
148 throw( ::com::sun::star::beans::UnknownPropertyException,
149 ::com::sun::star::lang::WrappedTargetException,
150 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 virtual void SAL_CALL removePropertyChangeListener(
153 const OUString& rPropertyName,
154 const ::com::sun::star::uno::Reference<
155 ::com::sun::star::beans::XPropertyChangeListener>& rListener)
156 throw( ::com::sun::star::beans::UnknownPropertyException,
157 ::com::sun::star::lang::WrappedTargetException,
158 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
160 virtual void SAL_CALL addVetoableChangeListener(
161 const OUString& rPropertyName,
162 const ::com::sun::star::uno::Reference<
163 ::com::sun::star::beans::XVetoableChangeListener>& rListener)
164 throw( ::com::sun::star::beans::UnknownPropertyException,
165 ::com::sun::star::lang::WrappedTargetException,
166 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
168 virtual void SAL_CALL removeVetoableChangeListener(
169 const OUString& rPropertyName,
170 const ::com::sun::star::uno::Reference<
171 ::com::sun::star::beans::XVetoableChangeListener>& rListener)
172 throw( ::com::sun::star::beans::UnknownPropertyException,
173 ::com::sun::star::lang::WrappedTargetException,
174 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
176 // XServiceInfo
177 virtual OUString SAL_CALL getImplementationName() throw(
178 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
180 virtual sal_Bool SAL_CALL supportsService( const OUString&
181 rServiceName) throw( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
183 virtual ::com::sun::star::uno::Sequence< OUString> SAL_CALL
184 getSupportedServiceNames() throw(
185 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
187 private:
189 ScDocument* m_pDocument;
190 SfxItemPropertySet m_aPropSet;
191 bool m_bIncludeHiddenCells;
194 // DataSource
195 class ScChart2DataSource : public
196 ::cppu::WeakImplHelper2<
197 ::com::sun::star::chart2::data::XDataSource,
198 ::com::sun::star::lang::XServiceInfo>,
199 SfxListener
201 public:
203 explicit ScChart2DataSource( ScDocument* pDoc);
204 virtual ~ScChart2DataSource();
205 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
207 // XDataSource
208 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
209 ::com::sun::star::chart2::data::XLabeledDataSequence > > SAL_CALL
210 getDataSequences() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
212 // XServiceInfo
213 virtual OUString SAL_CALL getImplementationName() throw(
214 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
216 virtual sal_Bool SAL_CALL supportsService( const OUString&
217 rServiceName) throw( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
219 virtual ::com::sun::star::uno::Sequence< OUString> SAL_CALL
220 getSupportedServiceNames() throw(
221 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
223 // implementation
225 void AddLabeledSequence(const com::sun::star::uno::Reference < com::sun::star::chart2::data::XLabeledDataSequence >& xNew);
227 private:
229 ScDocument* m_pDocument;
230 typedef std::list < com::sun::star::uno::Reference< com::sun::star::chart2::data::XLabeledDataSequence > > LabeledList;
231 LabeledList m_aLabeledSequences;
235 // DataSequence
236 class ScChart2DataSequence : public
237 ::cppu::WeakImplHelper8<
238 ::com::sun::star::chart2::data::XDataSequence,
239 ::com::sun::star::chart2::data::XTextualDataSequence,
240 ::com::sun::star::chart2::data::XNumericalDataSequence,
241 com::sun::star::chart2::XTimeBased,
242 ::com::sun::star::util::XCloneable,
243 ::com::sun::star::util::XModifyBroadcaster,
244 ::com::sun::star::beans::XPropertySet,
245 ::com::sun::star::lang::XServiceInfo>,
246 SfxListener,
247 boost::noncopyable
249 public:
250 explicit ScChart2DataSequence( ScDocument* pDoc,
251 const com::sun::star::uno::Reference< com::sun::star::chart2::data::XDataProvider >& xDP,
252 ::std::vector<ScTokenRef>* pTokens, bool bIncludeHiddenCells );
254 virtual ~ScChart2DataSequence();
255 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) SAL_OVERRIDE;
257 // XDataSequence
258 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
259 SAL_CALL getData()
260 throw (::com::sun::star::uno::RuntimeException,
261 std::exception) SAL_OVERRIDE;
262 virtual OUString SAL_CALL getSourceRangeRepresentation()
263 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
264 virtual ::com::sun::star::uno::Sequence< OUString >
265 SAL_CALL generateLabel(::com::sun::star::chart2::data::LabelOrigin nOrigin)
266 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
267 virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex )
268 throw (::com::sun::star::lang::IndexOutOfBoundsException,
269 ::com::sun::star::uno::RuntimeException,
270 std::exception) SAL_OVERRIDE;
272 // XNumericalDataSequence
273 virtual ::com::sun::star::uno::Sequence< double >
274 SAL_CALL getNumericalData()
275 throw (::com::sun::star::uno::RuntimeException,
276 std::exception) SAL_OVERRIDE;
278 // XTextualDataSequence
279 virtual ::com::sun::star::uno::Sequence< OUString >
280 SAL_CALL getTextualData()
281 throw (::com::sun::star::uno::RuntimeException,
282 std::exception) SAL_OVERRIDE;
284 // XTimeBased
285 virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
286 virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
288 virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
290 // XPropertySet
291 virtual ::com::sun::star::uno::Reference<
292 ::com::sun::star::beans::XPropertySetInfo> SAL_CALL
293 getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
295 virtual void SAL_CALL setPropertyValue(
296 const OUString& rPropertyName,
297 const ::com::sun::star::uno::Any& rValue)
298 throw( ::com::sun::star::beans::UnknownPropertyException,
299 ::com::sun::star::beans::PropertyVetoException,
300 ::com::sun::star::lang::IllegalArgumentException,
301 ::com::sun::star::lang::WrappedTargetException,
302 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
304 virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
305 const OUString& rPropertyName)
306 throw(::com::sun::star::beans::UnknownPropertyException,
307 ::com::sun::star::lang::WrappedTargetException,
308 ::com::sun::star::uno::RuntimeException,
309 std::exception) SAL_OVERRIDE;
311 virtual void SAL_CALL addPropertyChangeListener(
312 const OUString& rPropertyName,
313 const ::com::sun::star::uno::Reference<
314 ::com::sun::star::beans::XPropertyChangeListener>& xListener)
315 throw( ::com::sun::star::beans::UnknownPropertyException,
316 ::com::sun::star::lang::WrappedTargetException,
317 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
319 virtual void SAL_CALL removePropertyChangeListener(
320 const OUString& rPropertyName,
321 const ::com::sun::star::uno::Reference<
322 ::com::sun::star::beans::XPropertyChangeListener>& rListener)
323 throw( ::com::sun::star::beans::UnknownPropertyException,
324 ::com::sun::star::lang::WrappedTargetException,
325 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
327 virtual void SAL_CALL addVetoableChangeListener(
328 const OUString& rPropertyName,
329 const ::com::sun::star::uno::Reference<
330 ::com::sun::star::beans::XVetoableChangeListener>& rListener)
331 throw( ::com::sun::star::beans::UnknownPropertyException,
332 ::com::sun::star::lang::WrappedTargetException,
333 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
335 virtual void SAL_CALL removeVetoableChangeListener(
336 const OUString& rPropertyName,
337 const ::com::sun::star::uno::Reference<
338 ::com::sun::star::beans::XVetoableChangeListener>& rListener)
339 throw( ::com::sun::star::beans::UnknownPropertyException,
340 ::com::sun::star::lang::WrappedTargetException,
341 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
343 // XCloneable
344 virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone()
345 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
347 // XModifyBroadcaster
348 virtual void SAL_CALL addModifyListener(
349 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener )
350 throw (::com::sun::star::uno::RuntimeException,
351 std::exception) SAL_OVERRIDE;
352 virtual void SAL_CALL removeModifyListener(
353 const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener )
354 throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
356 // XServiceInfo
357 virtual OUString SAL_CALL getImplementationName() throw(
358 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
360 virtual sal_Bool SAL_CALL supportsService( const OUString&
361 rServiceName) throw( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
363 virtual ::com::sun::star::uno::Sequence< OUString> SAL_CALL
364 getSupportedServiceNames() throw(
365 ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
367 private:
368 void setDataChangedHint(bool b);
370 // Implementation
371 void RefChanged();
372 DECL_LINK( ValueListenerHdl, SfxHint* );
374 private:
375 ScChart2DataSequence(); // disabled
376 ScChart2DataSequence(const ScChart2DataSequence& r); // disabled
378 class ExternalRefListener : public ScExternalRefManager::LinkListener
380 public:
381 ExternalRefListener(ScChart2DataSequence& rParent, ScDocument* pDoc);
382 virtual ~ExternalRefListener();
383 virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) SAL_OVERRIDE;
384 void addFileId(sal_uInt16 nFileId);
385 void removeFileId(sal_uInt16 nFileId);
386 const ::boost::unordered_set<sal_uInt16>& getAllFileIds();
388 private:
389 ExternalRefListener();
390 ExternalRefListener(const ExternalRefListener& r);
392 ScChart2DataSequence& mrParent;
393 ::boost::unordered_set<sal_uInt16> maFileIds;
394 ScDocument* mpDoc;
398 * Build an internal data array to cache the data ranges, and other
399 * information such as hidden values.
401 void BuildDataCache();
403 void RebuildDataCache();
405 sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
407 void UpdateTokensFromRanges(const ScRangeList& rRanges);
409 ExternalRefListener* GetExtRefListener();
411 void StopListeningToAllExternalRefs();
413 void CopyData(const ScChart2DataSequence& r);
415 private:
417 // data array
418 struct Item
420 double mfValue;
421 OUString maString;
422 bool mbIsValue;
423 Item();
426 class HiddenRangeListener : public ScChartHiddenRangeListener
428 public:
429 HiddenRangeListener(ScChart2DataSequence& rParent);
430 virtual ~HiddenRangeListener();
432 virtual void notify() SAL_OVERRIDE;
434 private:
435 ScChart2DataSequence& mrParent;
438 ::std::list<Item> m_aDataArray;
441 * Cached data for getData. We may also need to cache data for the
442 * numerical and textural data series if they turn out to be bottlenecks
443 * under certain scenarios.
445 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > m_aMixedDataCache;
447 ::com::sun::star::uno::Sequence<sal_Int32> m_aHiddenValues;
449 // properties
450 ::com::sun::star::chart2::data::DataSequenceRole m_aRole;
451 bool m_bIncludeHiddenCells;
453 // internals
454 typedef boost::scoped_ptr<std::vector<ScTokenRef> > TokenListPtr;
455 typedef boost::scoped_ptr<std::vector<sal_uInt32> > RangeIndexMapPtr;
456 typedef boost::scoped_ptr<ExternalRefListener> ExtRefListenerPtr;
458 sal_Int64 m_nObjectId;
459 ScDocument* m_pDocument;
460 TokenListPtr m_pTokens;
461 RangeIndexMapPtr m_pRangeIndices;
462 ExtRefListenerPtr m_pExtRefListener;
463 com::sun::star::uno::Reference < com::sun::star::chart2::data::XDataProvider > m_xDataProvider;
464 SfxItemPropertySet m_aPropSet;
466 boost::scoped_ptr<HiddenRangeListener> m_pHiddenListener;
468 ScLinkListener* m_pValueListener;
469 XModifyListenerArr_Impl m_aValueListeners;
471 bool m_bGotDataChangedHint;
472 bool m_bExtDataRebuildQueued;
474 bool mbTimeBased;
475 SCTAB mnTimeBasedStart;
476 SCTAB mnTimeBasedEnd;
477 SCTAB mnCurrentTab;
481 #endif // INCLUDED_SC_INC_CHART2UNO_HXX
483 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */