1*de7b3f82SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*de7b3f82SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*de7b3f82SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*de7b3f82SAndrew Rist  * distributed with this work for additional information
6*de7b3f82SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*de7b3f82SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*de7b3f82SAndrew Rist  * "License"); you may not use this file except in compliance
9*de7b3f82SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*de7b3f82SAndrew Rist  *
11*de7b3f82SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*de7b3f82SAndrew Rist  *
13*de7b3f82SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*de7b3f82SAndrew Rist  * software distributed under the License is distributed on an
15*de7b3f82SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*de7b3f82SAndrew Rist  * KIND, either express or implied.  See the License for the
17*de7b3f82SAndrew Rist  * specific language governing permissions and limitations
18*de7b3f82SAndrew Rist  * under the License.
19*de7b3f82SAndrew Rist  *
20*de7b3f82SAndrew Rist  *************************************************************/
21*de7b3f82SAndrew Rist 
22*de7b3f82SAndrew 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);
78cdf0e10cSrcweir     explicit InternalDataProvider( const ::com::sun::star::uno::Reference<
79cdf0e10cSrcweir                                        ::com::sun::star::chart2::XChartDocument > & xChartDoc, bool bConnectToModel );
80cdf0e10cSrcweir     explicit InternalDataProvider( const InternalDataProvider & rOther );
81cdf0e10cSrcweir 	virtual ~InternalDataProvider();
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     void createDefaultData();
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     /// declare XServiceInfo methods
86cdf0e10cSrcweir     APPHELPER_XSERVICEINFO_DECL()
87cdf0e10cSrcweir     APPHELPER_SERVICE_FACTORY_HELPER(InternalDataProvider)
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     // ____ XInternalDataProvider ____
90cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL hasDataByRangeRepresentation( const ::rtl::OUString& aRange )
91cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
92cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > SAL_CALL
93cdf0e10cSrcweir         getDataByRangeRepresentation( const ::rtl::OUString& aRange )
94cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
95cdf0e10cSrcweir     virtual void SAL_CALL setDataByRangeRepresentation(
96cdf0e10cSrcweir         const ::rtl::OUString& aRange,
97cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aNewData )
98cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
99cdf0e10cSrcweir     virtual void SAL_CALL insertSequence( ::sal_Int32 nAfterIndex )
100cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
101cdf0e10cSrcweir     virtual void SAL_CALL deleteSequence( ::sal_Int32 nAtIndex )
102cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
103cdf0e10cSrcweir     virtual void SAL_CALL appendSequence()
104cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
105cdf0e10cSrcweir     virtual void SAL_CALL insertComplexCategoryLevel( ::sal_Int32 nLevel )
106cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
107cdf0e10cSrcweir     virtual void SAL_CALL deleteComplexCategoryLevel( ::sal_Int32 nLevel )
108cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
109cdf0e10cSrcweir     virtual void SAL_CALL insertDataPointForAllSequences( ::sal_Int32 nAfterIndex )
110cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
111cdf0e10cSrcweir     virtual void SAL_CALL deleteDataPointForAllSequences( ::sal_Int32 nAtIndex )
112cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
113cdf0e10cSrcweir     virtual void SAL_CALL swapDataPointWithNextOneForAllSequences( ::sal_Int32 nAtIndex )
114cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
115cdf0e10cSrcweir     virtual void SAL_CALL registerDataSequenceForChanges(
116cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence >& xSeq )
117cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     // ____ XDataProvider (base of XInternalDataProvider) ____
120cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL createDataSourcePossible(
121cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
122cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
123cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource > SAL_CALL createDataSource(
124cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments )
125cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
126cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
127cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL detectArguments(
128cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource )
129cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
130cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL createDataSequenceByRangeRepresentationPossible(
131cdf0e10cSrcweir         const ::rtl::OUString& aRangeRepresentation )
132cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
133cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSequence > SAL_CALL createDataSequenceByRangeRepresentation(
134cdf0e10cSrcweir         const ::rtl::OUString& aRangeRepresentation )
135cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
136cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
137cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XRangeSelection > SAL_CALL getRangeSelection()
138cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     // ____ XRangeXMLConversion ____
141cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL convertRangeToXML(
142cdf0e10cSrcweir         const ::rtl::OUString& aRangeRepresentation )
143cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
144cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
145cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL convertRangeFromXML(
146cdf0e10cSrcweir         const ::rtl::OUString& aXMLRange )
147cdf0e10cSrcweir         throw (::com::sun::star::lang::IllegalArgumentException,
148cdf0e10cSrcweir                ::com::sun::star::uno::RuntimeException);
149cdf0e10cSrcweir 
150cdf0e10cSrcweir     // ____ XDateCategories ____
151cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< double > SAL_CALL getDateCategories() throw (::com::sun::star::uno::RuntimeException);
152cdf0e10cSrcweir     virtual void SAL_CALL setDateCategories( const ::com::sun::star::uno::Sequence< double >& rDates ) throw (::com::sun::star::uno::RuntimeException);
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     // ____ XAnyDescriptionAccess ____
155cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > SAL_CALL
156cdf0e10cSrcweir         getAnyRowDescriptions() throw (::com::sun::star::uno::RuntimeException);
157cdf0e10cSrcweir     virtual void SAL_CALL setAnyRowDescriptions(
158cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
159cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aRowDescriptions )
160cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
161cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > > SAL_CALL
162cdf0e10cSrcweir         getAnyColumnDescriptions() throw (::com::sun::star::uno::RuntimeException);
163cdf0e10cSrcweir     virtual void SAL_CALL setAnyColumnDescriptions(
164cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
165cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > >& aColumnDescriptions )
166cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     // ____ XComplexDescriptionAccess (base of XAnyDescriptionAccess) ____
169cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL
170cdf0e10cSrcweir         getComplexRowDescriptions() throw (::com::sun::star::uno::RuntimeException);
171cdf0e10cSrcweir     virtual void SAL_CALL setComplexRowDescriptions(
172cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
173cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::rtl::OUString > >& aRowDescriptions )
174cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
175cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< ::rtl::OUString > > SAL_CALL
176cdf0e10cSrcweir         getComplexColumnDescriptions() throw (::com::sun::star::uno::RuntimeException);
177cdf0e10cSrcweir     virtual void SAL_CALL setComplexColumnDescriptions(
178cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence<
179cdf0e10cSrcweir         ::com::sun::star::uno::Sequence< ::rtl::OUString > >& aColumnDescriptions )
180cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     // ____ XChartDataArray (base of XComplexDescriptionAccess) ____
183cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > > SAL_CALL getData()
184cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
185cdf0e10cSrcweir     virtual void SAL_CALL setData(
186cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Sequence< double > >& aData )
187cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
188cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getRowDescriptions()
189cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
190cdf0e10cSrcweir     virtual void SAL_CALL setRowDescriptions(
191cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aRowDescriptions )
192cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
193cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getColumnDescriptions()
194cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
195cdf0e10cSrcweir     virtual void SAL_CALL setColumnDescriptions(
196cdf0e10cSrcweir         const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aColumnDescriptions )
197cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     // ____ XChartData (base of XChartDataArray) ____
200cdf0e10cSrcweir     virtual void SAL_CALL addChartDataChangeEventListener(
201cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
202cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
203cdf0e10cSrcweir     virtual void SAL_CALL removeChartDataChangeEventListener(
204cdf0e10cSrcweir         const ::com::sun::star::uno::Reference< ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
205cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
206cdf0e10cSrcweir     virtual double SAL_CALL getNotANumber()
207cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
208cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL isNotANumber(
209cdf0e10cSrcweir         double nNumber )
210cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     // ____ XCloneable ____
213cdf0e10cSrcweir     virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone()
214cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
215cdf0e10cSrcweir 	// ::com::sun::star::lang::XInitialization:
216cdf0e10cSrcweir     virtual void SAL_CALL initialize(const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > & aArguments)
217cdf0e10cSrcweir 		throw (::com::sun::star::uno::RuntimeException, ::com::sun::star::uno::Exception);
218cdf0e10cSrcweir 
219cdf0e10cSrcweir private:
220cdf0e10cSrcweir     void lcl_addDataSequenceToMap(
221cdf0e10cSrcweir         const ::rtl::OUString & rRangeRepresentation,
222cdf0e10cSrcweir         const ::com::sun::star::uno::Reference<
223cdf0e10cSrcweir             ::com::sun::star::chart2::data::XDataSequence > & xSequence );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
226cdf0e10cSrcweir             ::com::sun::star::chart2::data::XDataSequence >
227cdf0e10cSrcweir         lcl_createDataSequenceAndAddToMap( const ::rtl::OUString & rRangeRepresentation,
228cdf0e10cSrcweir                                        const ::rtl::OUString & rRole );
229cdf0e10cSrcweir     ::com::sun::star::uno::Reference<
230cdf0e10cSrcweir             ::com::sun::star::chart2::data::XDataSequence >
231cdf0e10cSrcweir         lcl_createDataSequenceAndAddToMap( const ::rtl::OUString & rRangeRepresentation );
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     void lcl_deleteMapReferences( const ::rtl::OUString & rRangeRepresentation );
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     void lcl_adaptMapReferences(
236cdf0e10cSrcweir         const ::rtl::OUString & rOldRangeRepresentation,
237cdf0e10cSrcweir         const ::rtl::OUString & rNewRangeRepresentation );
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     void lcl_increaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
240cdf0e10cSrcweir     void lcl_decreaseMapReferences( sal_Int32 nBegin, sal_Int32 nEnd );
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     typedef ::std::multimap< ::rtl::OUString,
243cdf0e10cSrcweir             ::com::sun::star::uno::WeakReference< ::com::sun::star::chart2::data::XDataSequence > >
244cdf0e10cSrcweir         tSequenceMap;
245cdf0e10cSrcweir     typedef ::std::pair< tSequenceMap::iterator, tSequenceMap::iterator > tSequenceMapRange;
246cdf0e10cSrcweir     typedef ::std::pair< tSequenceMap::const_iterator, tSequenceMap::const_iterator > tConstSequenceMapRange;
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     /** cache for all sequences that have been returned.
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         If the range-representation of a sequence changes and it is still
251cdf0e10cSrcweir         referred to by some component (weak reference is valid), the range will
252cdf0e10cSrcweir         be adapted.
253cdf0e10cSrcweir      */
254cdf0e10cSrcweir     tSequenceMap m_aSequenceMap;
255cdf0e10cSrcweir     InternalData m_aInternalData;
256cdf0e10cSrcweir     bool m_bDataInColumns;
257cdf0e10cSrcweir };
258cdf0e10cSrcweir 
259cdf0e10cSrcweir } //  namespace chart
260cdf0e10cSrcweir 
261cdf0e10cSrcweir // CHART2_INTERNALDATAPROVIDER_HXX
262cdf0e10cSrcweir #endif
263