Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SC_CHART2UNO_HXX
21 : #define SC_CHART2UNO_HXX
22 :
23 : #include "cellsuno.hxx" // for XModifyListenerArr_Impl / ScLinkListener
24 : #include "rangelst.hxx"
25 : #include "externalrefmgr.hxx"
26 : #include "token.hxx"
27 : #include "chartlis.hxx"
28 :
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/lang/XServiceInfo.hpp>
41 : #include <com/sun/star/beans/XPropertySet.hpp>
42 : #include <com/sun/star/util/XCloneable.hpp>
43 : #include <com/sun/star/util/XModifyBroadcaster.hpp>
44 : #include <cppuhelper/implbase2.hxx>
45 : #include <cppuhelper/implbase5.hxx>
46 : #include <cppuhelper/implbase7.hxx>
47 : #include <rtl/ustring.hxx>
48 : #include <svl/itemprop.hxx>
49 :
50 : #include <list>
51 : #include <vector>
52 : #include <memory>
53 : #include <boost/shared_ptr.hpp>
54 : #include <boost/unordered_set.hpp>
55 : #include <boost/noncopyable.hpp>
56 : #include <boost/scoped_ptr.hpp>
57 :
58 : class ScDocument;
59 :
60 : // DataProvider ==============================================================
61 :
62 : class ScChart2DataProvider : public
63 : ::cppu::WeakImplHelper5<
64 : ::com::sun::star::chart2::data::XDataProvider,
65 : ::com::sun::star::chart2::data::XSheetDataProvider,
66 : ::com::sun::star::chart2::data::XRangeXMLConversion,
67 : ::com::sun::star::beans::XPropertySet,
68 : ::com::sun::star::lang::XServiceInfo>,
69 : SfxListener
70 : {
71 : public:
72 :
73 : explicit ScChart2DataProvider( ScDocument* pDoc );
74 : virtual ~ScChart2DataProvider();
75 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
76 :
77 : // XDataProvider ---------------------------------------------------------
78 :
79 : virtual ::sal_Bool SAL_CALL createDataSourcePossible(
80 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
81 : throw (::com::sun::star::uno::RuntimeException);
82 :
83 : virtual ::com::sun::star::uno::Reference<
84 : ::com::sun::star::chart2::data::XDataSource > SAL_CALL createDataSource(
85 : const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
86 : throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
87 :
88 : virtual ::com::sun::star::uno::Sequence<
89 : ::com::sun::star::beans::PropertyValue > SAL_CALL detectArguments(
90 : const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource )
91 : throw (::com::sun::star::uno::RuntimeException);
92 :
93 : virtual ::sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
94 : const ::rtl::OUString& aRangeRepresentation )
95 : throw (::com::sun::star::uno::RuntimeException);
96 :
97 : virtual ::com::sun::star::uno::Reference<
98 : ::com::sun::star::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
99 : const ::rtl::OUString& aRangeRepresentation )
100 : throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
101 :
102 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XRangeSelection > SAL_CALL getRangeSelection()
103 : throw (::com::sun::star::uno::RuntimeException);
104 :
105 : // XSheetDataProvider ----------------------------------------------------
106 :
107 : virtual sal_Bool SAL_CALL createDataSequenceByFormulaTokensPossible(
108 : const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >& aTokens )
109 : throw (::com::sun::star::uno::RuntimeException);
110 :
111 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >
112 : SAL_CALL createDataSequenceByFormulaTokens(
113 : const ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::FormulaToken >& aTokens )
114 : throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
115 :
116 : // XRangeXMLConversion ---------------------------------------------------
117 :
118 : virtual ::rtl::OUString SAL_CALL convertRangeToXML( const ::rtl::OUString& sRangeRepresentation )
119 : throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
120 :
121 : virtual ::rtl::OUString SAL_CALL convertRangeFromXML( const ::rtl::OUString& sXMLRange )
122 : throw ( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
123 :
124 : // XPropertySet ----------------------------------------------------------
125 :
126 : virtual ::com::sun::star::uno::Reference<
127 : ::com::sun::star::beans::XPropertySetInfo> SAL_CALL
128 : getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException);
129 :
130 : virtual void SAL_CALL setPropertyValue(
131 : const ::rtl::OUString& rPropertyName,
132 : const ::com::sun::star::uno::Any& rValue)
133 : throw( ::com::sun::star::beans::UnknownPropertyException,
134 : ::com::sun::star::beans::PropertyVetoException,
135 : ::com::sun::star::lang::IllegalArgumentException,
136 : ::com::sun::star::lang::WrappedTargetException,
137 : ::com::sun::star::uno::RuntimeException);
138 :
139 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
140 : const ::rtl::OUString& rPropertyName)
141 : throw( ::com::sun::star::beans::UnknownPropertyException,
142 : ::com::sun::star::lang::WrappedTargetException,
143 : ::com::sun::star::uno::RuntimeException);
144 :
145 : virtual void SAL_CALL addPropertyChangeListener(
146 : const ::rtl::OUString& rPropertyName,
147 : const ::com::sun::star::uno::Reference<
148 : ::com::sun::star::beans::XPropertyChangeListener>& xListener)
149 : throw( ::com::sun::star::beans::UnknownPropertyException,
150 : ::com::sun::star::lang::WrappedTargetException,
151 : ::com::sun::star::uno::RuntimeException);
152 :
153 : virtual void SAL_CALL removePropertyChangeListener(
154 : const ::rtl::OUString& rPropertyName,
155 : const ::com::sun::star::uno::Reference<
156 : ::com::sun::star::beans::XPropertyChangeListener>& rListener)
157 : throw( ::com::sun::star::beans::UnknownPropertyException,
158 : ::com::sun::star::lang::WrappedTargetException,
159 : ::com::sun::star::uno::RuntimeException);
160 :
161 : virtual void SAL_CALL addVetoableChangeListener(
162 : const ::rtl::OUString& rPropertyName,
163 : const ::com::sun::star::uno::Reference<
164 : ::com::sun::star::beans::XVetoableChangeListener>& rListener)
165 : throw( ::com::sun::star::beans::UnknownPropertyException,
166 : ::com::sun::star::lang::WrappedTargetException,
167 : ::com::sun::star::uno::RuntimeException);
168 :
169 : virtual void SAL_CALL removeVetoableChangeListener(
170 : const ::rtl::OUString& rPropertyName,
171 : const ::com::sun::star::uno::Reference<
172 : ::com::sun::star::beans::XVetoableChangeListener>& rListener)
173 : throw( ::com::sun::star::beans::UnknownPropertyException,
174 : ::com::sun::star::lang::WrappedTargetException,
175 : ::com::sun::star::uno::RuntimeException);
176 :
177 : // XServiceInfo ----------------------------------------------------------
178 :
179 : virtual ::rtl::OUString SAL_CALL getImplementationName() throw(
180 : ::com::sun::star::uno::RuntimeException);
181 :
182 : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString&
183 : rServiceName) throw( ::com::sun::star::uno::RuntimeException);
184 :
185 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
186 : getSupportedServiceNames() throw(
187 : ::com::sun::star::uno::RuntimeException);
188 :
189 : private:
190 :
191 : ScDocument* m_pDocument;
192 : SfxItemPropertySet m_aPropSet;
193 : sal_Bool m_bIncludeHiddenCells;
194 : };
195 :
196 :
197 : // DataSource ================================================================
198 :
199 : class ScChart2DataSource : public
200 : ::cppu::WeakImplHelper2<
201 : ::com::sun::star::chart2::data::XDataSource,
202 : ::com::sun::star::lang::XServiceInfo>,
203 : SfxListener
204 : {
205 : public:
206 :
207 : explicit ScChart2DataSource( ScDocument* pDoc);
208 : virtual ~ScChart2DataSource();
209 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
210 :
211 : // XDataSource -----------------------------------------------------------
212 :
213 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference<
214 : ::com::sun::star::chart2::data::XLabeledDataSequence > > SAL_CALL
215 : getDataSequences() throw (::com::sun::star::uno::RuntimeException);
216 :
217 : // XServiceInfo ----------------------------------------------------------
218 :
219 : virtual ::rtl::OUString SAL_CALL getImplementationName() throw(
220 : ::com::sun::star::uno::RuntimeException);
221 :
222 : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString&
223 : rServiceName) throw( ::com::sun::star::uno::RuntimeException);
224 :
225 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
226 : getSupportedServiceNames() throw(
227 : ::com::sun::star::uno::RuntimeException);
228 :
229 : // implementation
230 :
231 : void AddLabeledSequence(const com::sun::star::uno::Reference < com::sun::star::chart2::data::XLabeledDataSequence >& xNew);
232 :
233 : private:
234 :
235 : ScDocument* m_pDocument;
236 : typedef std::list < com::sun::star::uno::Reference< com::sun::star::chart2::data::XLabeledDataSequence > > LabeledList;
237 : LabeledList m_aLabeledSequences;
238 :
239 : };
240 :
241 :
242 : // DataSequence ==============================================================
243 :
244 : class ScChart2DataSequence : public
245 : ::cppu::WeakImplHelper7<
246 : ::com::sun::star::chart2::data::XDataSequence,
247 : ::com::sun::star::chart2::data::XTextualDataSequence,
248 : ::com::sun::star::chart2::data::XNumericalDataSequence,
249 : ::com::sun::star::util::XCloneable,
250 : ::com::sun::star::util::XModifyBroadcaster,
251 : ::com::sun::star::beans::XPropertySet,
252 : ::com::sun::star::lang::XServiceInfo>,
253 : SfxListener,
254 : boost::noncopyable
255 : {
256 : public:
257 : explicit ScChart2DataSequence( ScDocument* pDoc,
258 : const com::sun::star::uno::Reference< com::sun::star::chart2::data::XDataProvider >& xDP,
259 : ::std::vector<ScTokenRef>* pTokens, bool bIncludeHiddenCells );
260 :
261 : virtual ~ScChart2DataSequence();
262 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
263 :
264 : // XDataSequence ---------------------------------------------------------
265 :
266 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >
267 : SAL_CALL getData() throw (::com::sun::star::uno::RuntimeException);
268 : virtual ::rtl::OUString SAL_CALL getSourceRangeRepresentation()
269 : throw (::com::sun::star::uno::RuntimeException);
270 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
271 : SAL_CALL generateLabel(::com::sun::star::chart2::data::LabelOrigin nOrigin)
272 : throw (::com::sun::star::uno::RuntimeException);
273 : virtual ::sal_Int32 SAL_CALL getNumberFormatKeyByIndex( ::sal_Int32 nIndex )
274 : throw (::com::sun::star::lang::IndexOutOfBoundsException,
275 : ::com::sun::star::uno::RuntimeException);
276 :
277 : // XNumericalDataSequence --------------------------------------------------
278 :
279 : virtual ::com::sun::star::uno::Sequence< double >
280 : SAL_CALL getNumericalData( ) throw (::com::sun::star::uno::RuntimeException);
281 :
282 : // XTextualDataSequence --------------------------------------------------
283 :
284 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString >
285 : SAL_CALL getTextualData( ) throw (::com::sun::star::uno::RuntimeException);
286 :
287 : // XPropertySet ----------------------------------------------------------
288 :
289 : virtual ::com::sun::star::uno::Reference<
290 : ::com::sun::star::beans::XPropertySetInfo> SAL_CALL
291 : getPropertySetInfo() throw( ::com::sun::star::uno::RuntimeException);
292 :
293 : virtual void SAL_CALL setPropertyValue(
294 : const ::rtl::OUString& rPropertyName,
295 : const ::com::sun::star::uno::Any& rValue)
296 : throw( ::com::sun::star::beans::UnknownPropertyException,
297 : ::com::sun::star::beans::PropertyVetoException,
298 : ::com::sun::star::lang::IllegalArgumentException,
299 : ::com::sun::star::lang::WrappedTargetException,
300 : ::com::sun::star::uno::RuntimeException);
301 :
302 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue(
303 : const ::rtl::OUString& rPropertyName)
304 : throw( ::com::sun::star::beans::UnknownPropertyException,
305 : ::com::sun::star::lang::WrappedTargetException,
306 : ::com::sun::star::uno::RuntimeException);
307 :
308 : virtual void SAL_CALL addPropertyChangeListener(
309 : const ::rtl::OUString& rPropertyName,
310 : const ::com::sun::star::uno::Reference<
311 : ::com::sun::star::beans::XPropertyChangeListener>& xListener)
312 : throw( ::com::sun::star::beans::UnknownPropertyException,
313 : ::com::sun::star::lang::WrappedTargetException,
314 : ::com::sun::star::uno::RuntimeException);
315 :
316 : virtual void SAL_CALL removePropertyChangeListener(
317 : const ::rtl::OUString& rPropertyName,
318 : const ::com::sun::star::uno::Reference<
319 : ::com::sun::star::beans::XPropertyChangeListener>& rListener)
320 : throw( ::com::sun::star::beans::UnknownPropertyException,
321 : ::com::sun::star::lang::WrappedTargetException,
322 : ::com::sun::star::uno::RuntimeException);
323 :
324 : virtual void SAL_CALL addVetoableChangeListener(
325 : const ::rtl::OUString& rPropertyName,
326 : const ::com::sun::star::uno::Reference<
327 : ::com::sun::star::beans::XVetoableChangeListener>& rListener)
328 : throw( ::com::sun::star::beans::UnknownPropertyException,
329 : ::com::sun::star::lang::WrappedTargetException,
330 : ::com::sun::star::uno::RuntimeException);
331 :
332 : virtual void SAL_CALL removeVetoableChangeListener(
333 : const ::rtl::OUString& rPropertyName,
334 : const ::com::sun::star::uno::Reference<
335 : ::com::sun::star::beans::XVetoableChangeListener>& rListener)
336 : throw( ::com::sun::star::beans::UnknownPropertyException,
337 : ::com::sun::star::lang::WrappedTargetException,
338 : ::com::sun::star::uno::RuntimeException);
339 :
340 : // XCloneable ------------------------------------------------------------
341 :
342 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone()
343 : throw (::com::sun::star::uno::RuntimeException);
344 :
345 : // XModifyBroadcaster ----------------------------------------------------
346 :
347 : virtual void SAL_CALL addModifyListener(
348 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener )
349 : throw (::com::sun::star::uno::RuntimeException);
350 : virtual void SAL_CALL removeModifyListener(
351 : const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener )
352 : throw (::com::sun::star::uno::RuntimeException);
353 :
354 : // XServiceInfo ----------------------------------------------------------
355 :
356 : virtual ::rtl::OUString SAL_CALL getImplementationName() throw(
357 : ::com::sun::star::uno::RuntimeException);
358 :
359 : virtual sal_Bool SAL_CALL supportsService( const ::rtl::OUString&
360 : rServiceName) throw( ::com::sun::star::uno::RuntimeException);
361 :
362 : virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL
363 : getSupportedServiceNames() throw(
364 : ::com::sun::star::uno::RuntimeException);
365 :
366 : private:
367 : void setDataChangedHint(bool b);
368 :
369 : // Implementation --------------------------------------------------------
370 :
371 : void RefChanged();
372 : DECL_LINK( ValueListenerHdl, SfxHint* );
373 :
374 : private:
375 : ScChart2DataSequence(); // disabled
376 : ScChart2DataSequence(const ScChart2DataSequence& r); // disabled
377 :
378 : class ExternalRefListener : public ScExternalRefManager::LinkListener
379 : {
380 : public:
381 : ExternalRefListener(ScChart2DataSequence& rParent, ScDocument* pDoc);
382 : virtual ~ExternalRefListener();
383 : virtual void notify(sal_uInt16 nFileId, ScExternalRefManager::LinkUpdateType eType);
384 : void addFileId(sal_uInt16 nFileId);
385 : void removeFileId(sal_uInt16 nFileId);
386 : const ::boost::unordered_set<sal_uInt16>& getAllFileIds();
387 :
388 : private:
389 : ExternalRefListener();
390 : ExternalRefListener(const ExternalRefListener& r);
391 :
392 : ScChart2DataSequence& mrParent;
393 : ::boost::unordered_set<sal_uInt16> maFileIds;
394 : ScDocument* mpDoc;
395 : };
396 :
397 : /**
398 : * Build an internal data array to cache the data ranges, and other
399 : * information such as hidden values.
400 : */
401 : void BuildDataCache();
402 :
403 : void RebuildDataCache();
404 :
405 : sal_Int32 FillCacheFromExternalRef(const ScTokenRef& pToken);
406 :
407 : void UpdateTokensFromRanges(const ScRangeList& rRanges);
408 :
409 : ExternalRefListener* GetExtRefListener();
410 :
411 : void StopListeningToAllExternalRefs();
412 :
413 : void CopyData(const ScChart2DataSequence& r);
414 :
415 : private:
416 :
417 : // data array
418 171 : struct Item
419 : {
420 : double mfValue;
421 : ::rtl::OUString maString;
422 : bool mbIsValue;
423 : Item();
424 : };
425 :
426 : class HiddenRangeListener : public ScChartHiddenRangeListener
427 : {
428 : public:
429 : HiddenRangeListener(ScChart2DataSequence& rParent);
430 : virtual ~HiddenRangeListener();
431 :
432 : virtual void notify();
433 :
434 : private:
435 : ScChart2DataSequence& mrParent;
436 : };
437 :
438 : ::std::list<Item> m_aDataArray;
439 :
440 : /**
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.
444 : */
445 : ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > m_aMixedDataCache;
446 :
447 : ::com::sun::star::uno::Sequence<sal_Int32> m_aHiddenValues;
448 :
449 : // properties
450 : ::com::sun::star::chart2::data::DataSequenceRole m_aRole;
451 : sal_Bool m_bIncludeHiddenCells;
452 :
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;
457 :
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;
465 :
466 : boost::scoped_ptr<HiddenRangeListener> m_pHiddenListener;
467 :
468 : ScLinkListener* m_pValueListener;
469 : XModifyListenerArr_Impl m_aValueListeners;
470 :
471 : bool m_bGotDataChangedHint;
472 : bool m_bExtDataRebuildQueued;
473 : };
474 :
475 : #endif // SC_CHART2UNO_HXX
476 :
477 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|