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 .
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"
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/implbase.hxx>
46 #include <rtl/ustring.hxx>
47 #include <svl/itemprop.hxx>
50 #include <unordered_set>
56 class SC_DLLPUBLIC ScChart2DataProvider
: public
57 ::cppu::WeakImplHelper
<
58 css::chart2::data::XDataProvider
,
59 css::chart2::data::XSheetDataProvider
,
60 css::chart2::data::XRangeXMLConversion
,
61 css::beans::XPropertySet
,
62 css::lang::XServiceInfo
>,
67 explicit ScChart2DataProvider( ScDocument
* pDoc
);
68 virtual ~ScChart2DataProvider() override
;
69 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
72 virtual sal_Bool SAL_CALL
createDataSourcePossible(
73 const css::uno::Sequence
< css::beans::PropertyValue
>& aArguments
) override
;
75 virtual css::uno::Reference
<
76 css::chart2::data::XDataSource
> SAL_CALL
createDataSource(
77 const css::uno::Sequence
< css::beans::PropertyValue
>& aArguments
) override
;
79 virtual css::uno::Sequence
<
80 css::beans::PropertyValue
> SAL_CALL
detectArguments(
81 const css::uno::Reference
< css::chart2::data::XDataSource
>& xDataSource
) override
;
83 virtual sal_Bool SAL_CALL
createDataSequenceByRangeRepresentationPossible(
84 const OUString
& aRangeRepresentation
) override
;
86 virtual css::uno::Reference
<
87 css::chart2::data::XDataSequence
> SAL_CALL
createDataSequenceByRangeRepresentation(
88 const OUString
& aRangeRepresentation
) override
;
90 virtual css::uno::Reference
<css::chart2::data::XDataSequence
> SAL_CALL
91 createDataSequenceByValueArray( const OUString
& aRole
, const OUString
& aRangeRepresentation
) override
;
93 virtual css::uno::Reference
< css::sheet::XRangeSelection
> SAL_CALL
getRangeSelection() override
;
96 virtual sal_Bool SAL_CALL
createDataSequenceByFormulaTokensPossible(
97 const css::uno::Sequence
< css::sheet::FormulaToken
>& aTokens
) override
;
99 virtual css::uno::Reference
< css::chart2::data::XDataSequence
>
100 SAL_CALL
createDataSequenceByFormulaTokens(
101 const css::uno::Sequence
< css::sheet::FormulaToken
>& aTokens
) override
;
103 // XRangeXMLConversion
104 virtual OUString SAL_CALL
convertRangeToXML( const OUString
& sRangeRepresentation
) override
;
106 virtual OUString SAL_CALL
convertRangeFromXML( const OUString
& sXMLRange
) override
;
109 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
110 getPropertySetInfo() override
;
112 virtual void SAL_CALL
setPropertyValue(
113 const OUString
& rPropertyName
,
114 const css::uno::Any
& rValue
) override
;
116 virtual css::uno::Any SAL_CALL
getPropertyValue(
117 const OUString
& rPropertyName
) override
;
119 virtual void SAL_CALL
addPropertyChangeListener(
120 const OUString
& rPropertyName
,
121 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
123 virtual void SAL_CALL
removePropertyChangeListener(
124 const OUString
& rPropertyName
,
125 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& rListener
) override
;
127 virtual void SAL_CALL
addVetoableChangeListener(
128 const OUString
& rPropertyName
,
129 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& rListener
) override
;
131 virtual void SAL_CALL
removeVetoableChangeListener(
132 const OUString
& rPropertyName
,
133 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& rListener
) override
;
136 virtual OUString SAL_CALL
getImplementationName() override
;
138 virtual sal_Bool SAL_CALL
supportsService( const OUString
&
139 rServiceName
) override
;
141 virtual css::uno::Sequence
< OUString
> SAL_CALL
142 getSupportedServiceNames() override
;
146 ScDocument
* m_pDocument
;
147 SfxItemPropertySet m_aPropSet
;
148 bool m_bIncludeHiddenCells
;
152 class ScChart2DataSource
: public
153 ::cppu::WeakImplHelper
<
154 css::chart2::data::XDataSource
,
155 css::lang::XServiceInfo
>,
160 explicit ScChart2DataSource( ScDocument
* pDoc
);
161 virtual ~ScChart2DataSource() override
;
162 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
165 virtual css::uno::Sequence
< css::uno::Reference
<
166 css::chart2::data::XLabeledDataSequence
> > SAL_CALL
167 getDataSequences() override
;
170 virtual OUString SAL_CALL
getImplementationName() override
;
172 virtual sal_Bool SAL_CALL
supportsService( const OUString
&
173 rServiceName
) override
;
175 virtual css::uno::Sequence
< OUString
> SAL_CALL
176 getSupportedServiceNames() override
;
180 void AddLabeledSequence(const css::uno::Reference
< css::chart2::data::XLabeledDataSequence
>& xNew
);
184 ScDocument
* m_pDocument
;
185 std::vector
< css::uno::Reference
< css::chart2::data::XLabeledDataSequence
> > m_aLabeledSequences
;
190 class ScChart2DataSequence
: public
191 ::cppu::WeakImplHelper
<
192 css::chart2::data::XDataSequence
,
193 css::chart2::data::XTextualDataSequence
,
194 css::chart2::data::XNumericalDataSequence
,
195 css::chart2::XTimeBased
,
196 css::util::XCloneable
,
197 css::util::XModifyBroadcaster
,
198 css::beans::XPropertySet
,
199 css::lang::XServiceInfo
>,
203 explicit ScChart2DataSequence( ScDocument
* pDoc
,
204 const css::uno::Reference
< css::chart2::data::XDataProvider
>& xDP
,
205 ::std::vector
<ScTokenRef
>&& rTokens
, bool bIncludeHiddenCells
);
207 virtual ~ScChart2DataSequence() override
;
208 ScChart2DataSequence(const ScChart2DataSequence
&) = delete;
209 ScChart2DataSequence
& operator=(const ScChart2DataSequence
&) = delete;
211 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
214 virtual css::uno::Sequence
< css::uno::Any
>
215 SAL_CALL
getData() override
;
216 virtual OUString SAL_CALL
getSourceRangeRepresentation() override
;
217 virtual css::uno::Sequence
< OUString
>
218 SAL_CALL
generateLabel(css::chart2::data::LabelOrigin nOrigin
) override
;
220 /** Get the number format key for the n-th data entry
221 * If nIndex == -1, then you will get the number format key for the first non-empty entry
223 virtual ::sal_Int32 SAL_CALL
getNumberFormatKeyByIndex( ::sal_Int32 nIndex
) override
;
225 // XNumericalDataSequence
226 virtual css::uno::Sequence
< double >
227 SAL_CALL
getNumericalData() override
;
229 // XTextualDataSequence
230 virtual css::uno::Sequence
< OUString
>
231 SAL_CALL
getTextualData() override
;
234 virtual sal_Bool SAL_CALL
switchToNext(sal_Bool bWrap
) override
;
235 virtual sal_Bool SAL_CALL
setToPointInTime(sal_Int32 nPoint
) override
;
237 virtual void SAL_CALL
setRange(sal_Int32 nStart
, sal_Int32 nEnd
) override
;
240 virtual css::uno::Reference
<
241 css::beans::XPropertySetInfo
> SAL_CALL
242 getPropertySetInfo() override
;
244 virtual void SAL_CALL
setPropertyValue(
245 const OUString
& rPropertyName
,
246 const css::uno::Any
& rValue
) override
;
248 virtual css::uno::Any SAL_CALL
getPropertyValue(
249 const OUString
& rPropertyName
) override
;
251 virtual void SAL_CALL
addPropertyChangeListener(
252 const OUString
& rPropertyName
,
253 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
255 virtual void SAL_CALL
removePropertyChangeListener(
256 const OUString
& rPropertyName
,
257 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& rListener
) override
;
259 virtual void SAL_CALL
addVetoableChangeListener(
260 const OUString
& rPropertyName
,
261 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& rListener
) override
;
263 virtual void SAL_CALL
removeVetoableChangeListener(
264 const OUString
& rPropertyName
,
265 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& rListener
) override
;
268 virtual css::uno::Reference
< css::util::XCloneable
> SAL_CALL
createClone() override
;
270 // XModifyBroadcaster
271 virtual void SAL_CALL
addModifyListener(
272 const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
273 virtual void SAL_CALL
removeModifyListener(
274 const css::uno::Reference
< css::util::XModifyListener
>& aListener
) override
;
277 virtual OUString SAL_CALL
getImplementationName() override
;
279 virtual sal_Bool SAL_CALL
supportsService( const OUString
&
280 rServiceName
) override
;
282 virtual css::uno::Sequence
< OUString
> SAL_CALL
283 getSupportedServiceNames() override
;
286 void setDataChangedHint(bool b
);
290 DECL_LINK( ValueListenerHdl
, const SfxHint
&, void );
293 class ExternalRefListener
: public ScExternalRefManager::LinkListener
296 ExternalRefListener(ScChart2DataSequence
& rParent
, ScDocument
* pDoc
);
297 virtual ~ExternalRefListener() override
;
298 ExternalRefListener(const ExternalRefListener
&) = delete;
299 ExternalRefListener
& operator=(const ExternalRefListener
&) = delete;
301 virtual void notify(sal_uInt16 nFileId
, ScExternalRefManager::LinkUpdateType eType
) override
;
302 void addFileId(sal_uInt16 nFileId
);
303 const std::unordered_set
<sal_uInt16
>& getAllFileIds() { return maFileIds
;}
306 ScChart2DataSequence
& mrParent
;
307 std::unordered_set
<sal_uInt16
> maFileIds
;
312 * Build an internal data array to cache the data ranges, and other
313 * information such as hidden values.
315 void BuildDataCache();
317 void RebuildDataCache();
319 sal_Int32
FillCacheFromExternalRef(const ScTokenRef
& pToken
);
321 void UpdateTokensFromRanges(const ScRangeList
& rRanges
);
323 ExternalRefListener
* GetExtRefListener();
325 void StopListeningToAllExternalRefs();
327 void CopyData(const ScChart2DataSequence
& r
);
341 class HiddenRangeListener
: public ScChartHiddenRangeListener
344 HiddenRangeListener(ScChart2DataSequence
& rParent
);
345 virtual ~HiddenRangeListener() override
;
347 virtual void notify() override
;
350 ScChart2DataSequence
& mrParent
;
353 /** This vector contains the cached data which was calculated with BuildDataCache(). */
354 std::vector
<Item
> m_aDataArray
;
357 * Cached data for getData. We may also need to cache data for the
358 * numerical and textural data series if they turn out to be bottlenecks
359 * under certain scenarios.
361 css::uno::Sequence
< css::uno::Any
> m_aMixedDataCache
;
363 css::uno::Sequence
<sal_Int32
> m_aHiddenValues
;
366 css::chart2::data::DataSequenceRole m_aRole
;
367 bool m_bIncludeHiddenCells
;
370 typedef std::unique_ptr
<std::vector
<sal_uInt32
> > RangeIndexMapPtr
;
371 typedef std::unique_ptr
<ExternalRefListener
> ExtRefListenerPtr
;
373 sal_Int64 m_nObjectId
;
374 ScDocument
* m_pDocument
;
375 std::vector
<ScTokenRef
> m_aTokens
;
376 RangeIndexMapPtr m_pRangeIndices
;
377 ExtRefListenerPtr m_pExtRefListener
;
378 css::uno::Reference
< css::chart2::data::XDataProvider
> m_xDataProvider
;
379 SfxItemPropertySet m_aPropSet
;
381 std::unique_ptr
<HiddenRangeListener
> m_pHiddenListener
;
383 ScLinkListener
* m_pValueListener
;
384 XModifyListenerArr_Impl m_aValueListeners
;
386 bool m_bGotDataChangedHint
;
387 bool m_bExtDataRebuildQueued
;
390 SCTAB mnTimeBasedStart
;
391 SCTAB mnTimeBasedEnd
;
396 #endif // INCLUDED_SC_INC_CHART2UNO_HXX
398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */