nss: upgrade to release 3.73
[LibreOffice.git] / sc / inc / chart2uno.hxx
blob5f63433feef327db06ea11bee964561a18c16455
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/chart2/data/XDataProvider.hpp>
31 #include <com/sun/star/chart2/data/XSheetDataProvider.hpp>
32 #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
33 #include <com/sun/star/chart2/data/XDataSource.hpp>
34 #include <com/sun/star/chart2/data/XDataSequence.hpp>
35 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
36 #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
37 #include <com/sun/star/chart2/data/DataSequenceRole.hpp>
38 #include <com/sun/star/chart2/XTimeBased.hpp>
39 #include <com/sun/star/lang/XServiceInfo.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/util/XCloneable.hpp>
42 #include <com/sun/star/util/XModifyBroadcaster.hpp>
43 #include <cppuhelper/implbase.hxx>
44 #include <rtl/ustring.hxx>
45 #include <svl/itemprop.hxx>
47 #include <memory>
48 #include <unordered_set>
49 #include <vector>
51 namespace com::sun::star::chart2::data { class XLabeledDataSequence; }
53 class ScDocument;
55 // DataProvider
56 class SC_DLLPUBLIC ScChart2DataProvider final : 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>,
63 public SfxListener
65 public:
67 explicit ScChart2DataProvider( ScDocument* pDoc );
68 virtual ~ScChart2DataProvider() override;
69 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
71 // XDataProvider
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;
95 // XSheetDataProvider
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;
108 // XPropertySet
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;
135 // XServiceInfo
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;
144 private:
146 ScDocument* m_pDocument;
147 SfxItemPropertySet m_aPropSet;
148 bool m_bIncludeHiddenCells;
151 // DataSource
152 class ScChart2DataSource final : public
153 ::cppu::WeakImplHelper<
154 css::chart2::data::XDataSource,
155 css::lang::XServiceInfo>,
156 public SfxListener
158 public:
160 explicit ScChart2DataSource( ScDocument* pDoc);
161 virtual ~ScChart2DataSource() override;
162 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
164 // XDataSource
165 virtual css::uno::Sequence< css::uno::Reference<
166 css::chart2::data::XLabeledDataSequence > > SAL_CALL
167 getDataSequences() override;
169 // XServiceInfo
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;
178 // implementation
180 void AddLabeledSequence(const css::uno::Reference < css::chart2::data::XLabeledDataSequence >& xNew);
182 private:
184 ScDocument* m_pDocument;
185 std::vector < css::uno::Reference< css::chart2::data::XLabeledDataSequence > > m_aLabeledSequences;
189 // DataSequence
190 class ScChart2DataSequence final : 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>,
200 public SfxListener
202 public:
203 explicit ScChart2DataSequence( ScDocument* pDoc,
204 ::std::vector<ScTokenRef>&& rTokens, bool bIncludeHiddenCells );
206 virtual ~ScChart2DataSequence() override;
207 ScChart2DataSequence(const ScChart2DataSequence&) = delete;
208 ScChart2DataSequence& operator=(const ScChart2DataSequence&) = delete;
210 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
212 // XDataSequence
213 virtual css::uno::Sequence< css::uno::Any >
214 SAL_CALL getData() override;
215 virtual OUString SAL_CALL getSourceRangeRepresentation() override;
216 virtual css::uno::Sequence< OUString >
217 SAL_CALL generateLabel(css::chart2::data::LabelOrigin nOrigin) override;
219 /** Get the number format key for the n-th data entry
220 * If nIndex == -1, then you will get the number format key for the first non-empty entry
222 virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex ) override;
224 // XNumericalDataSequence
225 virtual css::uno::Sequence< double >
226 SAL_CALL getNumericalData() override;
228 // XTextualDataSequence
229 virtual css::uno::Sequence< OUString >
230 SAL_CALL getTextualData() override;
232 // XTimeBased
233 virtual sal_Bool SAL_CALL switchToNext(sal_Bool bWrap) override;
234 virtual sal_Bool SAL_CALL setToPointInTime(sal_Int32 nPoint) override;
236 virtual void SAL_CALL setRange(sal_Int32 nStart, sal_Int32 nEnd) override;
238 // XPropertySet
239 virtual css::uno::Reference<
240 css::beans::XPropertySetInfo> SAL_CALL
241 getPropertySetInfo() override;
243 virtual void SAL_CALL setPropertyValue(
244 const OUString& rPropertyName,
245 const css::uno::Any& rValue) override;
247 virtual css::uno::Any SAL_CALL getPropertyValue(
248 const OUString& rPropertyName) override;
250 virtual void SAL_CALL addPropertyChangeListener(
251 const OUString& rPropertyName,
252 const css::uno::Reference< css::beans::XPropertyChangeListener>& xListener) override;
254 virtual void SAL_CALL removePropertyChangeListener(
255 const OUString& rPropertyName,
256 const css::uno::Reference< css::beans::XPropertyChangeListener>& rListener) override;
258 virtual void SAL_CALL addVetoableChangeListener(
259 const OUString& rPropertyName,
260 const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
262 virtual void SAL_CALL removeVetoableChangeListener(
263 const OUString& rPropertyName,
264 const css::uno::Reference< css::beans::XVetoableChangeListener>& rListener) override;
266 // XCloneable
267 virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override;
269 // XModifyBroadcaster
270 virtual void SAL_CALL addModifyListener(
271 const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
272 virtual void SAL_CALL removeModifyListener(
273 const css::uno::Reference< css::util::XModifyListener >& aListener ) override;
275 // XServiceInfo
276 virtual OUString SAL_CALL getImplementationName() override;
278 virtual sal_Bool SAL_CALL supportsService( const OUString&
279 rServiceName) override;
281 virtual css::uno::Sequence< OUString> SAL_CALL
282 getSupportedServiceNames() override;
284 private:
285 void setDataChangedHint(bool b);
287 // Implementation
288 void RefChanged();
289 DECL_LINK( ValueListenerHdl, const SfxHint&, void );
291 private:
292 class ExternalRefListener final : public ScExternalRefManager::LinkListener
294 public:
295 ExternalRefListener(ScChart2DataSequence& rParent, ScDocument* pDoc);
296 virtual ~ExternalRefListener() override;
297 ExternalRefListener(const ExternalRefListener&) = delete;
298 ExternalRefListener& operator=(const ExternalRefListener&) = delete;
300 virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType) override;
301 void addFileId(sal_uInt16 nFileId);
302 const std::unordered_set<sal_uInt16>& getAllFileIds() const { return maFileIds;}
304 private:
305 ScChart2DataSequence& mrParent;
306 std::unordered_set<sal_uInt16> maFileIds;
307 ScDocument* mpDoc;
311 * Build an internal data array to cache the data ranges, and other
312 * information such as hidden values.
314 void BuildDataCache();
316 void RebuildDataCache();
318 sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
320 void UpdateTokensFromRanges(const ScRangeList& rRanges);
322 ExternalRefListener* GetExtRefListener();
324 void StopListeningToAllExternalRefs();
326 void CopyData(const ScChart2DataSequence& r);
328 private:
330 // data array
331 struct Item
333 double mfValue;
334 OUString maString;
335 bool mbIsValue;
336 ScAddress mAddress;
337 Item();
340 class HiddenRangeListener final : public ScChartHiddenRangeListener
342 public:
343 HiddenRangeListener(ScChart2DataSequence& rParent);
344 virtual ~HiddenRangeListener() override;
346 virtual void notify() override;
348 private:
349 ScChart2DataSequence& mrParent;
352 /** This vector contains the cached data which was calculated with BuildDataCache(). */
353 std::vector<Item> m_aDataArray;
356 * Cached data for getData. We may also need to cache data for the
357 * numerical and textural data series if they turn out to be bottlenecks
358 * under certain scenarios.
360 css::uno::Sequence< css::uno::Any > m_aMixedDataCache;
362 css::uno::Sequence<sal_Int32> m_aHiddenValues;
364 // properties
365 css::chart2::data::DataSequenceRole m_aRole;
366 bool m_bIncludeHiddenCells;
368 // internals
369 typedef std::unique_ptr<std::vector<sal_uInt32> > RangeIndexMapPtr;
371 sal_Int64 m_nObjectId;
372 ScDocument* m_pDocument;
373 std::vector<ScTokenRef> m_aTokens;
374 RangeIndexMapPtr m_pRangeIndices;
375 std::unique_ptr<ExternalRefListener>
376 m_pExtRefListener;
377 SfxItemPropertySet m_aPropSet;
379 std::unique_ptr<HiddenRangeListener> m_pHiddenListener;
381 std::unique_ptr<ScLinkListener> m_pValueListener;
382 XModifyListenerArr_Impl m_aValueListeners;
384 bool m_bGotDataChangedHint;
385 bool m_bExtDataRebuildQueued;
387 bool mbTimeBased;
388 SCTAB mnTimeBasedStart;
389 SCTAB mnTimeBasedEnd;
390 SCTAB mnCurrentTab;
394 #endif // INCLUDED_SC_INC_CHART2UNO_HXX
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */