1de7b3f82SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3de7b3f82SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4de7b3f82SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5de7b3f82SAndrew Rist  * distributed with this work for additional information
6de7b3f82SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7de7b3f82SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8de7b3f82SAndrew Rist  * "License"); you may not use this file except in compliance
9de7b3f82SAndrew Rist  * with the License.  You may obtain a copy of the License at
10de7b3f82SAndrew Rist  *
11de7b3f82SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12de7b3f82SAndrew Rist  *
13de7b3f82SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14de7b3f82SAndrew Rist  * software distributed under the License is distributed on an
15de7b3f82SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16de7b3f82SAndrew Rist  * KIND, either express or implied.  See the License for the
17de7b3f82SAndrew Rist  * specific language governing permissions and limitations
18de7b3f82SAndrew Rist  * under the License.
19de7b3f82SAndrew Rist  *
20de7b3f82SAndrew Rist  *************************************************************/
21de7b3f82SAndrew Rist 
22de7b3f82SAndrew Rist 
23cdf0e10cSrcweir #ifndef CHART2_INTERNALDATAPROVIDER_HXX
24cdf0e10cSrcweir #define CHART2_INTERNALDATAPROVIDER_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "InternalData.hxx"
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
29cdf0e10cSrcweir #include <com/sun/star/chart/XDateCategories.hpp>
30cdf0e10cSrcweir #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
31cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataProvider.hpp>
32cdf0e10cSrcweir #include <com/sun/star/chart2/XInternalDataProvider.hpp>
33cdf0e10cSrcweir #include <com/sun/star/chart2/data/XLabeledDataSequence.hpp>
34cdf0e10cSrcweir #include <com/sun/star/chart2/data/XRangeXMLConversion.hpp>
35cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
37cdf0e10cSrcweir #include <com/sun/star/util/XCloneable.hpp>
38cdf0e10cSrcweir #include <cppuhelper/implbase7.hxx>
39cdf0e10cSrcweir #include "ServiceMacros.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include "CachedDataSequence.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <map>
44cdf0e10cSrcweir #include <memory>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace chart
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace impl
50cdf0e10cSrcweir {
51cdf0e10cSrcweir 
52cdf0e10cSrcweir typedef ::cppu::WeakImplHelper7<
53cdf0e10cSrcweir         ::com::sun::star::chart2::XInternalDataProvider,
54cdf0e10cSrcweir         ::com::sun::star::chart2::data::XRangeXMLConversion,
55cdf0e10cSrcweir         ::com::sun::star::chart2::XAnyDescriptionAccess,
56cdf0e10cSrcweir         ::com::sun::star::chart::XDateCategories,
57cdf0e10cSrcweir         ::com::sun::star::util::XCloneable,
58cdf0e10cSrcweir 		::com::sun::star::lang::XInitialization,
59cdf0e10cSrcweir         ::com::sun::star::lang::XServiceInfo >
60cdf0e10cSrcweir     InternalDataProvider_Base;
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /** Data provider that handles data internally.  This is used for charts with
64cdf0e10cSrcweir     their own data.
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     <p>The format for single ranges is "categories|label n|n" where n is a
67cdf0e10cSrcweir     non-negative number. Meaning return all categories, the label of sequence n,
68cdf0e10cSrcweir     or the data of sequence n.</p>
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     <p>The format for a complete range is "all". (Do we need more than
71cdf0e10cSrcweir     that?)</p>
72cdf0e10cSrcweir  */
73cdf0e10cSrcweir class InternalDataProvider :
74cdf0e10cSrcweir         public impl::InternalDataProvider_Base
75cdf0e10cSrcweir {
76cdf0e10cSrcweir public:
77cdf0e10cSrcweir     explicit InternalDataProvider(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > & _xContext);
78*8b276638SArmin Le Grand 
79*8b276638SArmin Le Grand     // #120559# allow handing over a default for data orientation (DataInColumns) that will
80*8b276638SArmin Le Grand     // be used when no data is available
81*8b276638SArmin Le Grand     explicit InternalDataProvider(
82*8b276638SArmin Le Grand         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument > & xChartDoc,
83*8b276638SArmin Le Grand         bool bConnectToModel,
84*8b276638SArmin Le Grand         bool bDefaultDataInColumns );
85cdf0e10cSrcweir     explicit InternalDataProvider( const InternalDataProvider & rOther );
86cdf0e10cSrcweir 	virtual ~InternalDataProvider();
87cdf0e10cSrcweir 
88cdf0e10cSrcweir     void createDefaultData();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     /// declare XServiceInfo methods
91cdf0e10cSrcweir     APPHELPER_XSERVICEINFO_DECL()
92cdf0e10cSrcweir     APPHELPER_SERVICE_FACTORY_HELPER(InternalDataProvider)
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     // ____ XInternalDataProvider ____
95cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL hasDataByRangeRepresentation( const ::rtl::OUString& aRange )
96cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
97cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL
98cdf0e10cSrcweir         getDataByRangeRepresentation( const ::rtl::OUString& aRange )
99cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
100cdf0e10cSrcweir     virtual void SAL_CALL setDataByRangeRepresentation(
101cdf0e10cSrcweir         const ::rtl::OUString& aRange,
102cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aNewData )
103cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
104cdf0e10cSrcweir     virtual void SAL_CALL insertSequence( ::sal_Int32 nAfterIndex )
105cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
106cdf0e10cSrcweir     virtual void SAL_CALL deleteSequence( ::sal_Int32 nAtIndex )
107cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
108cdf0e10cSrcweir     virtual void SAL_CALL appendSequence()
109cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
110cdf0e10cSrcweir     virtual void SAL_CALL insertComplexCategoryLevel( ::sal_Int32 nLevel )
111cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
112cdf0e10cSrcweir     virtual void SAL_CALL deleteComplexCategoryLevel( ::sal_Int32 nLevel )
113cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
114cdf0e10cSrcweir     virtual void SAL_CALL insertDataPointForAllSequences( ::sal_Int32 nAfterIndex )
115cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
116cdf0e10cSrcweir     virtual void SAL_CALL deleteDataPointForAllSequences( ::sal_Int32 nAtIndex )
117cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
118cdf0e10cSrcweir     virtual void SAL_CALL swapDataPointWithNextOneForAllSequences( ::sal_Int32 nAtIndex )
119cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
120cdf0e10cSrcweir     virtual void SAL_CALL registerDataSequenceForChanges(
121cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >& xSeq )
122cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     // ____ XDataProvider (base of XInternalDataProvider) ____
125cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL createDataSourcePossible(
126cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
127cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
128cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource > SAL_CALL createDataSource(
129cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
130cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
131cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
132cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL detectArguments(
133cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource )
134cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
135cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
136cdf0e10cSrcweir         const ::rtl::OUString& aRangeRepresentation )
137cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
138cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
139cdf0e10cSrcweir         const ::rtl::OUString& aRangeRepresentation )
140cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
141cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
142cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XRangeSelection > SAL_CALL getRangeSelection()
143cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     // ____ XRangeXMLConversion ____
146cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL convertRangeToXML(
147cdf0e10cSrcweir         const ::rtl::OUString& aRangeRepresentation )
148cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
149cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
150cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL convertRangeFromXML(
151cdf0e10cSrcweir         const ::rtl::OUString& aXMLRange )
152cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
153cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     // ____ XDateCategories ____
156cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getDateCategories() throw (::com::sun::star::uno::RuntimeException);
157cdf0e10cSrcweir     virtual void SAL_CALL setDateCategories( const ::com::sun::star::uno::Sequence< double >& rDates ) throw (::com::sun::star::uno::RuntimeException);
158cdf0e10cSrcweir 
159cdf0e10cSrcweir     // ____ XAnyDescriptionAccess ____
160cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > SAL_CALL
161cdf0e10cSrcweir         getAnyRowDescriptions() throw (::com::sun::star::uno::RuntimeException);
162cdf0e10cSrcweir     virtual void SAL_CALL setAnyRowDescriptions(
163cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
164cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aRowDescriptions )
165cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
166cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > SAL_CALL
167cdf0e10cSrcweir         getAnyColumnDescriptions() throw (::com::sun::star::uno::RuntimeException);
168cdf0e10cSrcweir     virtual void SAL_CALL setAnyColumnDescriptions(
169cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
170cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aColumnDescriptions )
171cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     // ____ XComplexDescriptionAccess (base of XAnyDescriptionAccess) ____
174cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL
175cdf0e10cSrcweir         getComplexRowDescriptions() throw (::com::sun::star::uno::RuntimeException);
176cdf0e10cSrcweir     virtual void SAL_CALL setComplexRowDescriptions(
177cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
178cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::rtl::OUString > >& aRowDescriptions )
179cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
180cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL
181cdf0e10cSrcweir         getComplexColumnDescriptions() throw (::com::sun::star::uno::RuntimeException);
182cdf0e10cSrcweir     virtual void SAL_CALL setComplexColumnDescriptions(
183cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
184cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::rtl::OUString > >& aColumnDescriptions )
185cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     // ____ XChartDataArray (base of XComplexDescriptionAccess) ____
188cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > > SAL_CALL getData()
189cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
190cdf0e10cSrcweir     virtual void SAL_CALL setData(
191cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& aData )
192cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
193cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRowDescriptions()
194cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
195cdf0e10cSrcweir     virtual void SAL_CALL setRowDescriptions(
196cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRowDescriptions )
197cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
198cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getColumnDescriptions()
199cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
200cdf0e10cSrcweir     virtual void SAL_CALL setColumnDescriptions(
201cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aColumnDescriptions )
202cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
203cdf0e10cSrcweir 
204cdf0e10cSrcweir     // ____ XChartData (base of XChartDataArray) ____
205cdf0e10cSrcweir     virtual void SAL_CALL addChartDataChangeEventListener(
206cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
207cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
208cdf0e10cSrcweir     virtual void SAL_CALL removeChartDataChangeEventListener(
209cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
210cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
211cdf0e10cSrcweir     virtual double SAL_CALL getNotANumber()
212cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
213cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL isNotANumber(
214cdf0e10cSrcweir         double nNumber )
215cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     // ____ XCloneable ____
218cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone()
219cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
220cdf0e10cSrcweir 	// ::com::sun::star::lang::XInitialization:
221cdf0e10cSrcweir     virtual void SAL_CALL initialize(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > & aArguments)
222cdf0e10cSrcweir 		throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::uno::Exception);
223cdf0e10cSrcweir 
224cdf0e10cSrcweir private:
225cdf0e10cSrcweir     void lcl_addDataSequenceToMap(
226cdf0e10cSrcweir         const ::rtl::OUString & rRangeRepresentation,
227cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
228cdf0e10cSrcweir             ::com::sun::star::chart2::data::XDataSequence > & xSequence );
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
231cdf0e10cSrcweir             ::com::sun::star::chart2::data::XDataSequence >
232cdf0e10cSrcweir         lcl_createDataSequenceAndAddToMap( const ::rtl::OUString & rRangeRepresentation,
233cdf0e10cSrcweir                                        const ::rtl::OUString & rRole );
234cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
235cdf0e10cSrcweir             ::com::sun::star::chart2::data::XDataSequence >
236cdf0e10cSrcweir         lcl_createDataSequenceAndAddToMap( const ::rtl::OUString & rRangeRepresentation );
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     void lcl_deleteMapReferences( const ::rtl::OUString & rRangeRepresentation );
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     void lcl_adaptMapReferences(
241cdf0e10cSrcweir         const ::rtl::OUString & rOldRangeRepresentation,
242cdf0e10cSrcweir         const ::rtl::OUString & rNewRangeRepresentation );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir     void lcl_increaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
245cdf0e10cSrcweir     void lcl_decreaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     typedef ::std::multimap< ::rtl::OUString,
248cdf0e10cSrcweir             ::com::sun::star::uno::WeakReference< ::com::sun::star::chart2::data::XDataSequence > >
249cdf0e10cSrcweir         tSequenceMap;
250cdf0e10cSrcweir     typedef ::std::pair< tSequenceMap::iterator, tSequenceMap::iterator > tSequenceMapRange;
251cdf0e10cSrcweir     typedef ::std::pair< tSequenceMap::const_iterator, tSequenceMap::const_iterator > tConstSequenceMapRange;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     /** cache for all sequences that have been returned.
254cdf0e10cSrcweir 
255cdf0e10cSrcweir         If the range-representation of a sequence changes and it is still
256cdf0e10cSrcweir         referred to by some component (weak reference is valid), the range will
257cdf0e10cSrcweir         be adapted.
258cdf0e10cSrcweir      */
259cdf0e10cSrcweir     tSequenceMap m_aSequenceMap;
260cdf0e10cSrcweir     InternalData m_aInternalData;
261cdf0e10cSrcweir     bool m_bDataInColumns;
262cdf0e10cSrcweir };
263cdf0e10cSrcweir 
264cdf0e10cSrcweir } //  namespace chart
265cdf0e10cSrcweir 
266cdf0e10cSrcweir // CHART2_INTERNALDATAPROVIDER_HXX
267cdf0e10cSrcweir #endif
268