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