xref: /AOO41X/main/chart2/source/controller/chartapiwrapper/ChartDataWrapper.cxx (revision cde9e8dc2218e857da4894ecba5c903312256674)
1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "ChartDataWrapper.hxx"
27cdf0e10cSrcweir #include "macros.hxx"
28cdf0e10cSrcweir #include "DiagramHelper.hxx"
29cdf0e10cSrcweir #include "DataSourceHelper.hxx"
30cdf0e10cSrcweir #include "servicenames_charttypes.hxx"
31cdf0e10cSrcweir #include "ContainerHelper.hxx"
32cdf0e10cSrcweir #include "CommonFunctors.hxx"
33cdf0e10cSrcweir #include "ChartModelHelper.hxx"
34cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
35cdf0e10cSrcweir #include "ControllerLockGuard.hxx"
36cdf0e10cSrcweir #include "Chart2ModelContact.hxx"
37cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
38cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp>
39cdf0e10cSrcweir #include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
40cdf0e10cSrcweir #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
41cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataSource.hpp>
42cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeries.hpp>
43cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
44cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
45cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp>
46cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataReceiver.hpp>
47cdf0e10cSrcweir #include <com/sun/star/chart/ChartDataRowSource.hpp>
48cdf0e10cSrcweir #include <com/sun/star/chart/XChartDocument.hpp>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include "CharacterProperties.hxx"
51cdf0e10cSrcweir #include "LineProperties.hxx"
52cdf0e10cSrcweir #include "FillProperties.hxx"
53cdf0e10cSrcweir 
54cdf0e10cSrcweir #include <map>
55cdf0e10cSrcweir #include <algorithm>
56cdf0e10cSrcweir #include <rtl/math.hxx>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir using namespace ::com::sun::star;
59cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
60cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
61cdf0e10cSrcweir using ::rtl::OUString;
62cdf0e10cSrcweir using ::osl::MutexGuard;
63cdf0e10cSrcweir using ::com::sun::star::chart2::XAnyDescriptionAccess;
64cdf0e10cSrcweir using ::com::sun::star::chart::XComplexDescriptionAccess;
65cdf0e10cSrcweir using ::com::sun::star::chart::XChartData;
66cdf0e10cSrcweir using ::com::sun::star::chart::XChartDataArray;
67cdf0e10cSrcweir using ::com::sun::star::chart::XDateCategories;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir namespace
70cdf0e10cSrcweir {
71cdf0e10cSrcweir static const ::rtl::OUString lcl_aServiceName(
72cdf0e10cSrcweir     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.ChartData" ));
73cdf0e10cSrcweir 
lcl_getNANInsteadDBL_MIN(const uno::Sequence<uno::Sequence<double>> & rData)74cdf0e10cSrcweir uno::Sequence< uno::Sequence< double > > lcl_getNANInsteadDBL_MIN( const uno::Sequence< uno::Sequence< double > >& rData )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     uno::Sequence< uno::Sequence< double > > aRet;
77cdf0e10cSrcweir     const sal_Int32 nOuterSize = rData.getLength();
78cdf0e10cSrcweir     aRet.realloc( nOuterSize );
79cdf0e10cSrcweir     for( sal_Int32 nOuter=0; nOuter<nOuterSize; ++nOuter )
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         sal_Int32 nInnerSize = rData[nOuter].getLength();
82cdf0e10cSrcweir         aRet[nOuter].realloc( nInnerSize );
83cdf0e10cSrcweir         for( sal_Int32 nInner=0; nInner<nInnerSize; ++nInner )
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             aRet[nOuter][nInner] = rData[nOuter][nInner];
86cdf0e10cSrcweir             double& rValue = aRet[nOuter][nInner];
87cdf0e10cSrcweir             if( rValue == DBL_MIN )
88cdf0e10cSrcweir                 ::rtl::math::setNan( &rValue );
89cdf0e10cSrcweir         }
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir     return aRet;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
lcl_getDBL_MINInsteadNAN(const uno::Sequence<uno::Sequence<double>> & rData)94cdf0e10cSrcweir uno::Sequence< uno::Sequence< double > > lcl_getDBL_MINInsteadNAN( const uno::Sequence< uno::Sequence< double > >& rData )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     uno::Sequence< uno::Sequence< double > > aRet;
97cdf0e10cSrcweir     const sal_Int32 nOuterSize = rData.getLength();
98cdf0e10cSrcweir     aRet.realloc( nOuterSize );
99cdf0e10cSrcweir     for( sal_Int32 nOuter=0; nOuter<nOuterSize; ++nOuter )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         sal_Int32 nInnerSize = rData[nOuter].getLength();
102cdf0e10cSrcweir         aRet[nOuter].realloc( nInnerSize );
103cdf0e10cSrcweir         for( sal_Int32 nInner=0; nInner<nInnerSize; ++nInner )
104cdf0e10cSrcweir         {
105cdf0e10cSrcweir             aRet[nOuter][nInner] = rData[nOuter][nInner];
106cdf0e10cSrcweir             double& rValue = aRet[nOuter][nInner];
107cdf0e10cSrcweir             if( ::rtl::math::isNan( rValue ) )
108cdf0e10cSrcweir                 rValue = DBL_MIN;
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir     return aRet;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir } // anonymous namespace
115cdf0e10cSrcweir 
116cdf0e10cSrcweir // --------------------------------------------------------------------------------
117cdf0e10cSrcweir 
118cdf0e10cSrcweir namespace chart
119cdf0e10cSrcweir {
120cdf0e10cSrcweir namespace wrapper
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 
123cdf0e10cSrcweir //--------------------------------------------------------------------------------------
124cdf0e10cSrcweir 
125cdf0e10cSrcweir struct lcl_Operator
126cdf0e10cSrcweir {
lcl_Operatorchart::wrapper::lcl_Operator127cdf0e10cSrcweir     lcl_Operator()
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir     }
~lcl_Operatorchart::wrapper::lcl_Operator130cdf0e10cSrcweir     virtual ~lcl_Operator()
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess ) = 0;
134cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_Operator135cdf0e10cSrcweir     virtual bool setsCategories( bool /*bDataInColumns*/ )
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         return false;
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir };
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //--------------------------------------------------------------------------
142cdf0e10cSrcweir 
143cdf0e10cSrcweir struct lcl_AllOperator : public lcl_Operator
144cdf0e10cSrcweir {
lcl_AllOperatorchart::wrapper::lcl_AllOperator145cdf0e10cSrcweir     lcl_AllOperator( const Reference< XChartData >& xDataToApply )
146cdf0e10cSrcweir         : lcl_Operator()
147cdf0e10cSrcweir         , m_xDataToApply( xDataToApply )
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_AllOperator151cdf0e10cSrcweir     virtual bool setsCategories( bool /*bDataInColumns*/ )
152cdf0e10cSrcweir     {
153cdf0e10cSrcweir         return true;
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
applychart::wrapper::lcl_AllOperator156cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         if( !xDataAccess.is() )
159cdf0e10cSrcweir             return;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         Reference< XAnyDescriptionAccess > xNewAny( m_xDataToApply, uno::UNO_QUERY );
162cdf0e10cSrcweir         Reference< XComplexDescriptionAccess > xNewComplex( m_xDataToApply, uno::UNO_QUERY );
163cdf0e10cSrcweir         if( xNewAny.is() )
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             xDataAccess->setData( xNewAny->getData() );
166cdf0e10cSrcweir             xDataAccess->setComplexRowDescriptions( xNewAny->getComplexRowDescriptions() );
167cdf0e10cSrcweir             xDataAccess->setComplexColumnDescriptions( xNewAny->getComplexColumnDescriptions() );
168cdf0e10cSrcweir         }
169cdf0e10cSrcweir         else if( xNewComplex.is() )
170cdf0e10cSrcweir         {
171cdf0e10cSrcweir             xDataAccess->setData( xNewComplex->getData() );
172cdf0e10cSrcweir             xDataAccess->setComplexRowDescriptions( xNewComplex->getComplexRowDescriptions() );
173cdf0e10cSrcweir             xDataAccess->setComplexColumnDescriptions( xNewComplex->getComplexColumnDescriptions() );
174cdf0e10cSrcweir         }
175cdf0e10cSrcweir         else
176cdf0e10cSrcweir         {
177cdf0e10cSrcweir             Reference< XChartDataArray > xNew( m_xDataToApply, uno::UNO_QUERY );
178cdf0e10cSrcweir             if( xNew.is() )
179cdf0e10cSrcweir             {
180cdf0e10cSrcweir                 xDataAccess->setData( xNew->getData() );
181cdf0e10cSrcweir                 xDataAccess->setRowDescriptions( xNew->getRowDescriptions() );
182cdf0e10cSrcweir                 xDataAccess->setColumnDescriptions( xNew->getColumnDescriptions() );
183cdf0e10cSrcweir             }
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir     }
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     Reference< XChartData > m_xDataToApply;
188cdf0e10cSrcweir };
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //--------------------------------------------------------------------------
191cdf0e10cSrcweir 
192cdf0e10cSrcweir struct lcl_DataOperator : public lcl_Operator
193cdf0e10cSrcweir {
lcl_DataOperatorchart::wrapper::lcl_DataOperator194cdf0e10cSrcweir     lcl_DataOperator( const Sequence< Sequence< double > >& rData )
195cdf0e10cSrcweir         : lcl_Operator()
196cdf0e10cSrcweir         , m_rData( rData )
197cdf0e10cSrcweir     {
198cdf0e10cSrcweir     }
199cdf0e10cSrcweir 
applychart::wrapper::lcl_DataOperator200cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
201cdf0e10cSrcweir     {
202cdf0e10cSrcweir         if( xDataAccess.is() )
203cdf0e10cSrcweir             xDataAccess->setData( lcl_getNANInsteadDBL_MIN( m_rData ) );
204cdf0e10cSrcweir     }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     const Sequence< Sequence< double > >& m_rData;
207cdf0e10cSrcweir };
208cdf0e10cSrcweir 
209cdf0e10cSrcweir //--------------------------------------------------------------------------
210cdf0e10cSrcweir 
211cdf0e10cSrcweir struct lcl_RowDescriptionsOperator : public lcl_Operator
212cdf0e10cSrcweir {
lcl_RowDescriptionsOperatorchart::wrapper::lcl_RowDescriptionsOperator213cdf0e10cSrcweir     lcl_RowDescriptionsOperator( const Sequence< OUString >& rRowDescriptions
214cdf0e10cSrcweir         , const Reference< chart2::XChartDocument >& xChartDoc )
215cdf0e10cSrcweir         : lcl_Operator()
216cdf0e10cSrcweir         , m_rRowDescriptions( rRowDescriptions )
217cdf0e10cSrcweir         , m_xChartDoc(xChartDoc)
218cdf0e10cSrcweir         , m_bDataInColumns(true)
219cdf0e10cSrcweir     {
220cdf0e10cSrcweir     }
221cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_RowDescriptionsOperator222cdf0e10cSrcweir     virtual bool setsCategories( bool bDataInColumns )
223cdf0e10cSrcweir     {
224cdf0e10cSrcweir         m_bDataInColumns = bDataInColumns;
225cdf0e10cSrcweir         return bDataInColumns;
226cdf0e10cSrcweir     }
227cdf0e10cSrcweir 
applychart::wrapper::lcl_RowDescriptionsOperator228cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         if( xDataAccess.is() )
231cdf0e10cSrcweir         {
232cdf0e10cSrcweir             xDataAccess->setRowDescriptions( m_rRowDescriptions );
233cdf0e10cSrcweir             if( m_bDataInColumns )
234cdf0e10cSrcweir                 DiagramHelper::switchToTextCategories( m_xChartDoc );
235cdf0e10cSrcweir         }
236cdf0e10cSrcweir     }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     const Sequence< OUString >& m_rRowDescriptions;
239cdf0e10cSrcweir     Reference< chart2::XChartDocument > m_xChartDoc;
240cdf0e10cSrcweir     bool m_bDataInColumns;
241cdf0e10cSrcweir };
242cdf0e10cSrcweir 
243cdf0e10cSrcweir //--------------------------------------------------------------------------
244cdf0e10cSrcweir 
245cdf0e10cSrcweir struct lcl_ComplexRowDescriptionsOperator : public lcl_Operator
246cdf0e10cSrcweir {
lcl_ComplexRowDescriptionsOperatorchart::wrapper::lcl_ComplexRowDescriptionsOperator247cdf0e10cSrcweir     lcl_ComplexRowDescriptionsOperator( const Sequence< Sequence< OUString > >& rComplexRowDescriptions
248cdf0e10cSrcweir         , const Reference< chart2::XChartDocument >& xChartDoc )
249cdf0e10cSrcweir         : lcl_Operator()
250cdf0e10cSrcweir         , m_rComplexRowDescriptions( rComplexRowDescriptions )
251cdf0e10cSrcweir         , m_xChartDoc(xChartDoc)
252cdf0e10cSrcweir         , m_bDataInColumns(true)
253cdf0e10cSrcweir     {
254cdf0e10cSrcweir     }
255cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_ComplexRowDescriptionsOperator256cdf0e10cSrcweir     virtual bool setsCategories( bool bDataInColumns )
257cdf0e10cSrcweir     {
258cdf0e10cSrcweir         m_bDataInColumns = bDataInColumns;
259cdf0e10cSrcweir         return bDataInColumns;
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
applychart::wrapper::lcl_ComplexRowDescriptionsOperator262cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         if( xDataAccess.is() )
265cdf0e10cSrcweir         {
266cdf0e10cSrcweir             xDataAccess->setComplexRowDescriptions( m_rComplexRowDescriptions );
267cdf0e10cSrcweir             if( m_bDataInColumns )
268cdf0e10cSrcweir                 DiagramHelper::switchToTextCategories( m_xChartDoc );
269cdf0e10cSrcweir         }
270cdf0e10cSrcweir     }
271cdf0e10cSrcweir 
272cdf0e10cSrcweir     const Sequence< Sequence< OUString > >& m_rComplexRowDescriptions;
273cdf0e10cSrcweir     Reference< chart2::XChartDocument > m_xChartDoc;
274cdf0e10cSrcweir     bool m_bDataInColumns;
275cdf0e10cSrcweir };
276cdf0e10cSrcweir //--------------------------------------------------------------------------
277cdf0e10cSrcweir 
278cdf0e10cSrcweir struct lcl_AnyRowDescriptionsOperator : public lcl_Operator
279cdf0e10cSrcweir {
lcl_AnyRowDescriptionsOperatorchart::wrapper::lcl_AnyRowDescriptionsOperator280cdf0e10cSrcweir     lcl_AnyRowDescriptionsOperator( const Sequence< Sequence< uno::Any > >& rAnyRowDescriptions )
281cdf0e10cSrcweir         : lcl_Operator()
282cdf0e10cSrcweir         , m_rAnyRowDescriptions( rAnyRowDescriptions )
283cdf0e10cSrcweir     {
284cdf0e10cSrcweir     }
285cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_AnyRowDescriptionsOperator286cdf0e10cSrcweir     virtual bool setsCategories( bool bDataInColumns )
287cdf0e10cSrcweir     {
288cdf0e10cSrcweir         return bDataInColumns;
289cdf0e10cSrcweir     }
290cdf0e10cSrcweir 
applychart::wrapper::lcl_AnyRowDescriptionsOperator291cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         if( xDataAccess.is() )
294cdf0e10cSrcweir             xDataAccess->setAnyRowDescriptions( m_rAnyRowDescriptions );
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir     const Sequence< Sequence< uno::Any > >& m_rAnyRowDescriptions;
298cdf0e10cSrcweir };
299cdf0e10cSrcweir 
300cdf0e10cSrcweir //--------------------------------------------------------------------------
301cdf0e10cSrcweir 
302cdf0e10cSrcweir struct lcl_ColumnDescriptionsOperator : public lcl_Operator
303cdf0e10cSrcweir {
lcl_ColumnDescriptionsOperatorchart::wrapper::lcl_ColumnDescriptionsOperator304cdf0e10cSrcweir     lcl_ColumnDescriptionsOperator( const Sequence< OUString >& rColumnDescriptions
305cdf0e10cSrcweir         , const Reference< chart2::XChartDocument >& xChartDoc )
306cdf0e10cSrcweir         : lcl_Operator()
307cdf0e10cSrcweir         , m_rColumnDescriptions( rColumnDescriptions )
308cdf0e10cSrcweir         , m_xChartDoc(xChartDoc)
309cdf0e10cSrcweir         , m_bDataInColumns(true)
310cdf0e10cSrcweir     {
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_ColumnDescriptionsOperator313cdf0e10cSrcweir     virtual bool setsCategories( bool bDataInColumns )
314cdf0e10cSrcweir     {
315cdf0e10cSrcweir         m_bDataInColumns = bDataInColumns;
316cdf0e10cSrcweir         return !bDataInColumns;
317cdf0e10cSrcweir     }
318cdf0e10cSrcweir 
applychart::wrapper::lcl_ColumnDescriptionsOperator319cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
320cdf0e10cSrcweir     {
321cdf0e10cSrcweir         if( xDataAccess.is() )
322cdf0e10cSrcweir         {
323cdf0e10cSrcweir             xDataAccess->setColumnDescriptions( m_rColumnDescriptions );
324cdf0e10cSrcweir             if( !m_bDataInColumns )
325cdf0e10cSrcweir                 DiagramHelper::switchToTextCategories( m_xChartDoc );
326cdf0e10cSrcweir         }
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     const Sequence< OUString >& m_rColumnDescriptions;
330cdf0e10cSrcweir     Reference< chart2::XChartDocument > m_xChartDoc;
331cdf0e10cSrcweir     bool m_bDataInColumns;
332cdf0e10cSrcweir };
333cdf0e10cSrcweir 
334cdf0e10cSrcweir //--------------------------------------------------------------------------
335cdf0e10cSrcweir 
336cdf0e10cSrcweir struct lcl_ComplexColumnDescriptionsOperator : public lcl_Operator
337cdf0e10cSrcweir {
lcl_ComplexColumnDescriptionsOperatorchart::wrapper::lcl_ComplexColumnDescriptionsOperator338cdf0e10cSrcweir     lcl_ComplexColumnDescriptionsOperator( const Sequence< Sequence< OUString > >& rComplexColumnDescriptions
339cdf0e10cSrcweir         , const Reference< chart2::XChartDocument >& xChartDoc )
340cdf0e10cSrcweir         : lcl_Operator()
341cdf0e10cSrcweir         , m_rComplexColumnDescriptions( rComplexColumnDescriptions )
342cdf0e10cSrcweir         , m_xChartDoc(xChartDoc)
343cdf0e10cSrcweir         , m_bDataInColumns(true)
344cdf0e10cSrcweir     {
345cdf0e10cSrcweir     }
346cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_ComplexColumnDescriptionsOperator347cdf0e10cSrcweir     virtual bool setsCategories( bool bDataInColumns )
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         m_bDataInColumns = bDataInColumns;
350cdf0e10cSrcweir         return !bDataInColumns;
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir 
applychart::wrapper::lcl_ComplexColumnDescriptionsOperator353cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
354cdf0e10cSrcweir     {
355cdf0e10cSrcweir         if( xDataAccess.is() )
356cdf0e10cSrcweir         {
357cdf0e10cSrcweir             xDataAccess->setComplexColumnDescriptions( m_rComplexColumnDescriptions );
358cdf0e10cSrcweir             if( !m_bDataInColumns )
359cdf0e10cSrcweir                 DiagramHelper::switchToTextCategories( m_xChartDoc );
360cdf0e10cSrcweir         }
361cdf0e10cSrcweir     }
362cdf0e10cSrcweir 
363cdf0e10cSrcweir     const Sequence< Sequence< OUString > >& m_rComplexColumnDescriptions;
364cdf0e10cSrcweir     Reference< chart2::XChartDocument > m_xChartDoc;
365cdf0e10cSrcweir     bool m_bDataInColumns;
366cdf0e10cSrcweir };
367cdf0e10cSrcweir 
368cdf0e10cSrcweir //--------------------------------------------------------------------------
369cdf0e10cSrcweir 
370cdf0e10cSrcweir struct lcl_AnyColumnDescriptionsOperator : public lcl_Operator
371cdf0e10cSrcweir {
lcl_AnyColumnDescriptionsOperatorchart::wrapper::lcl_AnyColumnDescriptionsOperator372cdf0e10cSrcweir     lcl_AnyColumnDescriptionsOperator( const Sequence< Sequence< uno::Any > >& rAnyColumnDescriptions )
373cdf0e10cSrcweir         : lcl_Operator()
374cdf0e10cSrcweir         , m_rAnyColumnDescriptions( rAnyColumnDescriptions )
375cdf0e10cSrcweir     {
376cdf0e10cSrcweir     }
377cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_AnyColumnDescriptionsOperator378cdf0e10cSrcweir     virtual bool setsCategories( bool bDataInColumns )
379cdf0e10cSrcweir     {
380cdf0e10cSrcweir         return bDataInColumns;
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir 
applychart::wrapper::lcl_AnyColumnDescriptionsOperator383cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         if( xDataAccess.is() )
386cdf0e10cSrcweir             xDataAccess->setAnyColumnDescriptions( m_rAnyColumnDescriptions );
387cdf0e10cSrcweir     }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir     const Sequence< Sequence< uno::Any > >& m_rAnyColumnDescriptions;
390cdf0e10cSrcweir };
391cdf0e10cSrcweir 
392cdf0e10cSrcweir //--------------------------------------------------------------------------
393cdf0e10cSrcweir 
394cdf0e10cSrcweir struct lcl_DateCategoriesOperator : public lcl_Operator
395cdf0e10cSrcweir {
lcl_DateCategoriesOperatorchart::wrapper::lcl_DateCategoriesOperator396cdf0e10cSrcweir     lcl_DateCategoriesOperator( const Sequence< double >& rDates )
397cdf0e10cSrcweir         : lcl_Operator()
398cdf0e10cSrcweir         , m_rDates( rDates )
399cdf0e10cSrcweir     {
400cdf0e10cSrcweir     }
401cdf0e10cSrcweir 
setsCategorieschart::wrapper::lcl_DateCategoriesOperator402cdf0e10cSrcweir     virtual bool setsCategories( bool /*bDataInColumns*/ )
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         return true;
405cdf0e10cSrcweir     }
406cdf0e10cSrcweir 
applychart::wrapper::lcl_DateCategoriesOperator407cdf0e10cSrcweir     virtual void apply( const Reference< XAnyDescriptionAccess >& xDataAccess )
408cdf0e10cSrcweir     {
409cdf0e10cSrcweir         Reference< XDateCategories > xDateCategories( xDataAccess, uno::UNO_QUERY );
410cdf0e10cSrcweir         if( xDateCategories.is() )
411cdf0e10cSrcweir             xDateCategories->setDateCategories( m_rDates );
412cdf0e10cSrcweir     }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir     const Sequence< double >& m_rDates;
415cdf0e10cSrcweir };
416cdf0e10cSrcweir 
417cdf0e10cSrcweir //--------------------------------------------------------------------------
418cdf0e10cSrcweir 
ChartDataWrapper(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)419cdf0e10cSrcweir ChartDataWrapper::ChartDataWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) :
420cdf0e10cSrcweir         m_spChart2ModelContact( spChart2ModelContact ),
421cdf0e10cSrcweir         m_aEventListenerContainer( m_aMutex )
422cdf0e10cSrcweir {
423cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_refCount );
424cdf0e10cSrcweir     initDataAccess();
425cdf0e10cSrcweir     osl_decrementInterlockedCount( &m_refCount );
426cdf0e10cSrcweir }
427cdf0e10cSrcweir 
ChartDataWrapper(::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact,const Reference<XChartData> & xNewData)428cdf0e10cSrcweir ChartDataWrapper::ChartDataWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact,
429cdf0e10cSrcweir                                     const Reference< XChartData >& xNewData ) :
430cdf0e10cSrcweir         m_spChart2ModelContact( spChart2ModelContact ),
431cdf0e10cSrcweir         m_aEventListenerContainer( m_aMutex )
432cdf0e10cSrcweir {
433cdf0e10cSrcweir     osl_incrementInterlockedCount( &m_refCount );
434cdf0e10cSrcweir     lcl_AllOperator aOperator( xNewData );
435cdf0e10cSrcweir     applyData( aOperator );
436cdf0e10cSrcweir     osl_decrementInterlockedCount( &m_refCount );
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
~ChartDataWrapper()439cdf0e10cSrcweir ChartDataWrapper::~ChartDataWrapper()
440cdf0e10cSrcweir {
441cdf0e10cSrcweir     // @todo: implement XComponent and call this in dispose().  In the DTOR the
442cdf0e10cSrcweir     // ref-count is 0, thus creating a stack reference to this calls the DTOR at
443cdf0e10cSrcweir     // the end of the block recursively
444cdf0e10cSrcweir //     uno::Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
445cdf0e10cSrcweir //     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir // ____ XChartDataArray (read)____
getData()449cdf0e10cSrcweir Sequence< Sequence< double > > SAL_CALL ChartDataWrapper::getData()
450cdf0e10cSrcweir     throw (uno::RuntimeException)
451cdf0e10cSrcweir {
452cdf0e10cSrcweir     initDataAccess();
453cdf0e10cSrcweir     if( m_xDataAccess.is() )
454cdf0e10cSrcweir         return lcl_getDBL_MINInsteadNAN( m_xDataAccess->getData() );
455cdf0e10cSrcweir     return Sequence< Sequence< double > >();
456cdf0e10cSrcweir }
getRowDescriptions()457cdf0e10cSrcweir Sequence< OUString > SAL_CALL ChartDataWrapper::getRowDescriptions()
458cdf0e10cSrcweir     throw (uno::RuntimeException)
459cdf0e10cSrcweir {
460cdf0e10cSrcweir     initDataAccess();
461cdf0e10cSrcweir     if( m_xDataAccess.is() )
462cdf0e10cSrcweir         return m_xDataAccess->getRowDescriptions();
463cdf0e10cSrcweir     return Sequence< OUString >();
464cdf0e10cSrcweir }
getColumnDescriptions()465cdf0e10cSrcweir Sequence< OUString > SAL_CALL ChartDataWrapper::getColumnDescriptions()
466cdf0e10cSrcweir     throw (uno::RuntimeException)
467cdf0e10cSrcweir {
468cdf0e10cSrcweir     initDataAccess();
469cdf0e10cSrcweir     if( m_xDataAccess.is() )
470cdf0e10cSrcweir         return m_xDataAccess->getColumnDescriptions();
471cdf0e10cSrcweir     return Sequence< OUString > ();
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir // ____ XComplexDescriptionAccess (read) ____
getComplexRowDescriptions()475cdf0e10cSrcweir Sequence< Sequence< OUString > > SAL_CALL ChartDataWrapper::getComplexRowDescriptions() throw (uno::RuntimeException)
476cdf0e10cSrcweir {
477cdf0e10cSrcweir     initDataAccess();
478cdf0e10cSrcweir     if( m_xDataAccess.is() )
479cdf0e10cSrcweir         return m_xDataAccess->getComplexRowDescriptions();
480cdf0e10cSrcweir     return Sequence< Sequence< OUString > >();
481cdf0e10cSrcweir }
getComplexColumnDescriptions()482cdf0e10cSrcweir Sequence< Sequence< OUString > > SAL_CALL ChartDataWrapper::getComplexColumnDescriptions() throw (uno::RuntimeException)
483cdf0e10cSrcweir {
484cdf0e10cSrcweir     initDataAccess();
485cdf0e10cSrcweir     if( m_xDataAccess.is() )
486cdf0e10cSrcweir         return m_xDataAccess->getComplexColumnDescriptions();
487cdf0e10cSrcweir     return Sequence< Sequence< OUString > >();
488cdf0e10cSrcweir }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir // ____ XAnyDescriptionAccess (read) ____
getAnyRowDescriptions()491cdf0e10cSrcweir Sequence< Sequence< uno::Any > > SAL_CALL ChartDataWrapper::getAnyRowDescriptions() throw (uno::RuntimeException)
492cdf0e10cSrcweir {
493cdf0e10cSrcweir     initDataAccess();
494cdf0e10cSrcweir     if( m_xDataAccess.is() )
495cdf0e10cSrcweir         return m_xDataAccess->getAnyRowDescriptions();
496cdf0e10cSrcweir     return Sequence< Sequence< uno::Any > >();
497cdf0e10cSrcweir }
getAnyColumnDescriptions()498cdf0e10cSrcweir Sequence< Sequence< uno::Any > > SAL_CALL ChartDataWrapper::getAnyColumnDescriptions() throw (uno::RuntimeException)
499cdf0e10cSrcweir {
500cdf0e10cSrcweir     initDataAccess();
501cdf0e10cSrcweir     if( m_xDataAccess.is() )
502cdf0e10cSrcweir         return m_xDataAccess->getAnyColumnDescriptions();
503cdf0e10cSrcweir     return Sequence< Sequence< uno::Any > >();
504cdf0e10cSrcweir }
505cdf0e10cSrcweir 
506cdf0e10cSrcweir // ____ XDateCategories (read) ____
getDateCategories()507cdf0e10cSrcweir Sequence< double > SAL_CALL ChartDataWrapper::getDateCategories() throw (uno::RuntimeException)
508cdf0e10cSrcweir {
509cdf0e10cSrcweir     initDataAccess();
510cdf0e10cSrcweir     Reference< XDateCategories > xDateCategories( m_xDataAccess, uno::UNO_QUERY );
511cdf0e10cSrcweir     if( xDateCategories.is() )
512cdf0e10cSrcweir         return xDateCategories->getDateCategories();
513cdf0e10cSrcweir     return Sequence< double >();
514cdf0e10cSrcweir }
515cdf0e10cSrcweir 
516cdf0e10cSrcweir // ____ XChartDataArray (write)____
setData(const Sequence<Sequence<double>> & rData)517cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::setData( const Sequence< Sequence< double > >& rData )
518cdf0e10cSrcweir     throw (uno::RuntimeException)
519cdf0e10cSrcweir {
520cdf0e10cSrcweir     lcl_DataOperator aOperator( rData );
521cdf0e10cSrcweir     applyData( aOperator );
522cdf0e10cSrcweir }
setRowDescriptions(const Sequence<OUString> & rRowDescriptions)523cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::setRowDescriptions( const Sequence< OUString >& rRowDescriptions )
524cdf0e10cSrcweir     throw (uno::RuntimeException)
525cdf0e10cSrcweir {
526cdf0e10cSrcweir     lcl_RowDescriptionsOperator aOperator( rRowDescriptions, m_spChart2ModelContact->getChart2Document() );
527cdf0e10cSrcweir     applyData( aOperator );
528cdf0e10cSrcweir }
setColumnDescriptions(const Sequence<OUString> & rColumnDescriptions)529cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::setColumnDescriptions( const Sequence< OUString >& rColumnDescriptions )
530cdf0e10cSrcweir     throw (uno::RuntimeException)
531cdf0e10cSrcweir {
532cdf0e10cSrcweir     lcl_ColumnDescriptionsOperator aOperator( rColumnDescriptions, m_spChart2ModelContact->getChart2Document() );
533cdf0e10cSrcweir     applyData( aOperator );
534cdf0e10cSrcweir }
535cdf0e10cSrcweir 
536cdf0e10cSrcweir // ____ XComplexDescriptionAccess (write) ____
setComplexRowDescriptions(const Sequence<Sequence<::rtl::OUString>> & rRowDescriptions)537cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::setComplexRowDescriptions( const Sequence< Sequence< ::rtl::OUString > >& rRowDescriptions ) throw (uno::RuntimeException)
538cdf0e10cSrcweir {
539cdf0e10cSrcweir     lcl_ComplexRowDescriptionsOperator aOperator( rRowDescriptions, m_spChart2ModelContact->getChart2Document() );
540cdf0e10cSrcweir     applyData( aOperator );
541cdf0e10cSrcweir }
setComplexColumnDescriptions(const Sequence<Sequence<::rtl::OUString>> & rColumnDescriptions)542cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::setComplexColumnDescriptions( const Sequence< Sequence< ::rtl::OUString > >& rColumnDescriptions ) throw (uno::RuntimeException)
543cdf0e10cSrcweir {
544cdf0e10cSrcweir     lcl_ComplexColumnDescriptionsOperator aOperator( rColumnDescriptions, m_spChart2ModelContact->getChart2Document() );
545cdf0e10cSrcweir     applyData( aOperator );
546cdf0e10cSrcweir }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir // ____ XAnyDescriptionAccess (write) ____
setAnyRowDescriptions(const Sequence<Sequence<uno::Any>> & rRowDescriptions)549cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::setAnyRowDescriptions( const Sequence< Sequence< uno::Any > >& rRowDescriptions ) throw (uno::RuntimeException)
550cdf0e10cSrcweir {
551cdf0e10cSrcweir     lcl_AnyRowDescriptionsOperator aOperator( rRowDescriptions );
552cdf0e10cSrcweir     applyData( aOperator );
553cdf0e10cSrcweir }
setAnyColumnDescriptions(const Sequence<Sequence<uno::Any>> & rColumnDescriptions)554cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::setAnyColumnDescriptions( const Sequence< Sequence< uno::Any > >& rColumnDescriptions ) throw (uno::RuntimeException)
555cdf0e10cSrcweir {
556cdf0e10cSrcweir     lcl_AnyColumnDescriptionsOperator aOperator( rColumnDescriptions );
557cdf0e10cSrcweir     applyData( aOperator );
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir // ____ XDateCategories (write) ____
setDateCategories(const Sequence<double> & rDates)561cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::setDateCategories( const Sequence< double >& rDates ) throw (uno::RuntimeException)
562cdf0e10cSrcweir {
563cdf0e10cSrcweir     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
564cdf0e10cSrcweir     ControllerLockGuard aCtrlLockGuard( uno::Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ));
565cdf0e10cSrcweir     lcl_DateCategoriesOperator aOperator( rDates );
566cdf0e10cSrcweir     applyData( aOperator );
567cdf0e10cSrcweir     DiagramHelper::switchToDateCategories( xChartDoc );
568cdf0e10cSrcweir }
569cdf0e10cSrcweir 
570cdf0e10cSrcweir //--------------------------------------------------------------------------------------
571cdf0e10cSrcweir 
572cdf0e10cSrcweir // ____ XChartData (base of XChartDataArray) ____
addChartDataChangeEventListener(const uno::Reference<::com::sun::star::chart::XChartDataChangeEventListener> & aListener)573cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::addChartDataChangeEventListener(
574cdf0e10cSrcweir     const uno::Reference<
575cdf0e10cSrcweir         ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
576cdf0e10cSrcweir     throw (uno::RuntimeException)
577cdf0e10cSrcweir {
578cdf0e10cSrcweir     m_aEventListenerContainer.addInterface( aListener );
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
removeChartDataChangeEventListener(const uno::Reference<::com::sun::star::chart::XChartDataChangeEventListener> & aListener)581cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::removeChartDataChangeEventListener(
582cdf0e10cSrcweir     const uno::Reference<
583cdf0e10cSrcweir         ::com::sun::star::chart::XChartDataChangeEventListener >& aListener )
584cdf0e10cSrcweir     throw (uno::RuntimeException)
585cdf0e10cSrcweir {
586cdf0e10cSrcweir     m_aEventListenerContainer.removeInterface( aListener );
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
getNotANumber()589cdf0e10cSrcweir double SAL_CALL ChartDataWrapper::getNotANumber()
590cdf0e10cSrcweir     throw (uno::RuntimeException)
591cdf0e10cSrcweir {
592cdf0e10cSrcweir     return DBL_MIN;
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
isNotANumber(double nNumber)595cdf0e10cSrcweir sal_Bool SAL_CALL ChartDataWrapper::isNotANumber( double nNumber )
596cdf0e10cSrcweir     throw (uno::RuntimeException)
597cdf0e10cSrcweir {
598cdf0e10cSrcweir     return DBL_MIN == nNumber
599cdf0e10cSrcweir         || ::rtl::math::isNan( nNumber )
600cdf0e10cSrcweir         || ::rtl::math::isInf( nNumber );
601cdf0e10cSrcweir }
602cdf0e10cSrcweir 
603cdf0e10cSrcweir // ____ XComponent ____
dispose()604cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::dispose()
605cdf0e10cSrcweir     throw (uno::RuntimeException)
606cdf0e10cSrcweir {
607cdf0e10cSrcweir     m_aEventListenerContainer.disposeAndClear( lang::EventObject( static_cast< ::cppu::OWeakObject* >( this )));
608cdf0e10cSrcweir     m_xDataAccess=0;
609cdf0e10cSrcweir }
610cdf0e10cSrcweir 
addEventListener(const uno::Reference<lang::XEventListener> & xListener)611cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::addEventListener(
612cdf0e10cSrcweir     const uno::Reference< lang::XEventListener > & xListener )
613cdf0e10cSrcweir     throw (uno::RuntimeException)
614cdf0e10cSrcweir {
615cdf0e10cSrcweir 	m_aEventListenerContainer.addInterface( xListener );
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)618cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::removeEventListener(
619cdf0e10cSrcweir     const uno::Reference< lang::XEventListener >& aListener )
620cdf0e10cSrcweir     throw (uno::RuntimeException)
621cdf0e10cSrcweir {
622cdf0e10cSrcweir 	m_aEventListenerContainer.removeInterface( aListener );
623cdf0e10cSrcweir }
624cdf0e10cSrcweir 
625cdf0e10cSrcweir // ____ XEventListener ____
disposing(const lang::EventObject &)626cdf0e10cSrcweir void SAL_CALL ChartDataWrapper::disposing( const lang::EventObject& /* Source */ )
627cdf0e10cSrcweir     throw (uno::RuntimeException)
628cdf0e10cSrcweir {
629cdf0e10cSrcweir }
630cdf0e10cSrcweir 
631cdf0e10cSrcweir //  ::com::sun::star::chart::ChartDataChangeEvent aEvent;
632cdf0e10cSrcweir //  aEvent.Type = chart::ChartDataChangeType_ALL;
633cdf0e10cSrcweir //  aEvent.StartColumn = 0;
634cdf0e10cSrcweir //  aEvent.EndColumn = 0;
635cdf0e10cSrcweir //  aEvent.StartRow = 0;
636cdf0e10cSrcweir //  aEvent.EndRow = 0;
fireChartDataChangeEvent(::com::sun::star::chart::ChartDataChangeEvent & aEvent)637cdf0e10cSrcweir void ChartDataWrapper::fireChartDataChangeEvent(
638cdf0e10cSrcweir     ::com::sun::star::chart::ChartDataChangeEvent& aEvent )
639cdf0e10cSrcweir {
640cdf0e10cSrcweir     if( ! m_aEventListenerContainer.getLength() )
641cdf0e10cSrcweir         return;
642cdf0e10cSrcweir 
643cdf0e10cSrcweir     uno::Reference< uno::XInterface > xSrc( static_cast< cppu::OWeakObject* >( this ));
644cdf0e10cSrcweir     OSL_ASSERT( xSrc.is());
645cdf0e10cSrcweir     if( xSrc.is() )
646cdf0e10cSrcweir         aEvent.Source = xSrc;
647cdf0e10cSrcweir 
648cdf0e10cSrcweir     ::cppu::OInterfaceIteratorHelper aIter( m_aEventListenerContainer );
649cdf0e10cSrcweir 
650cdf0e10cSrcweir     while( aIter.hasMoreElements() )
651cdf0e10cSrcweir     {
652cdf0e10cSrcweir         uno::Reference<
653cdf0e10cSrcweir             ::com::sun::star::chart::XChartDataChangeEventListener > xListener(
654cdf0e10cSrcweir                 aIter.next(), uno::UNO_QUERY );
655cdf0e10cSrcweir         if( xListener.is() )
656cdf0e10cSrcweir             xListener->chartDataChanged( aEvent );
657cdf0e10cSrcweir     }
658cdf0e10cSrcweir }
659cdf0e10cSrcweir 
660cdf0e10cSrcweir // --------------------------------------------------------------------------------
661cdf0e10cSrcweir 
switchToInternalDataProvider()662cdf0e10cSrcweir void ChartDataWrapper::switchToInternalDataProvider()
663cdf0e10cSrcweir {
664cdf0e10cSrcweir     //create an internal data provider that is connected to the model
665cdf0e10cSrcweir     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
666cdf0e10cSrcweir     if( xChartDoc.is() )
667cdf0e10cSrcweir         xChartDoc->createInternalDataProvider( true /*bCloneExistingData*/ );
668cdf0e10cSrcweir     initDataAccess();
669cdf0e10cSrcweir }
670cdf0e10cSrcweir 
initDataAccess()671cdf0e10cSrcweir void ChartDataWrapper::initDataAccess()
672cdf0e10cSrcweir {
673cdf0e10cSrcweir     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
674cdf0e10cSrcweir     if( !xChartDoc.is() )
675cdf0e10cSrcweir         return;
676cdf0e10cSrcweir     if( xChartDoc->hasInternalDataProvider() )
677cdf0e10cSrcweir         m_xDataAccess = Reference< XAnyDescriptionAccess >( xChartDoc->getDataProvider(), uno::UNO_QUERY_THROW );
678cdf0e10cSrcweir     else
679cdf0e10cSrcweir     {
680cdf0e10cSrcweir         //create a separate "internal data provider" that is not connected to the model
681cdf0e10cSrcweir         m_xDataAccess = Reference< XAnyDescriptionAccess >( ChartModelHelper::createInternalDataProvider(
682cdf0e10cSrcweir             xChartDoc, false /*bConnectToModel*/ ), uno::UNO_QUERY_THROW );
683cdf0e10cSrcweir     }
684cdf0e10cSrcweir }
685cdf0e10cSrcweir 
applyData(lcl_Operator & rDataOperator)686cdf0e10cSrcweir void ChartDataWrapper::applyData( lcl_Operator& rDataOperator )
687cdf0e10cSrcweir {
688cdf0e10cSrcweir     //bool bSetValues, bool bSetRowDescriptions, bool bSetColumnDescriptions
689cdf0e10cSrcweir     Reference< chart2::XChartDocument > xChartDoc( m_spChart2ModelContact->getChart2Document() );
690cdf0e10cSrcweir     if( !xChartDoc.is() )
691cdf0e10cSrcweir         return;
692cdf0e10cSrcweir 
693cdf0e10cSrcweir     // remember some diagram properties to reset later
694cdf0e10cSrcweir     sal_Bool bStacked = sal_False;
695cdf0e10cSrcweir     sal_Bool bPercent = sal_False;
696cdf0e10cSrcweir     sal_Bool bDeep = sal_False;
697cdf0e10cSrcweir     uno::Reference< ::com::sun::star::chart::XChartDocument > xOldDoc( xChartDoc, uno::UNO_QUERY );
698cdf0e10cSrcweir     OSL_ASSERT( xOldDoc.is());
699cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xDiaProp( xOldDoc->getDiagram(), uno::UNO_QUERY );
700cdf0e10cSrcweir     if( xDiaProp.is())
701cdf0e10cSrcweir     {
702cdf0e10cSrcweir         xDiaProp->getPropertyValue( C2U("Stacked")) >>= bStacked;
703cdf0e10cSrcweir         xDiaProp->getPropertyValue( C2U("Percent")) >>= bPercent;
704cdf0e10cSrcweir         xDiaProp->getPropertyValue( C2U("Deep")) >>= bDeep;
705cdf0e10cSrcweir     }
706cdf0e10cSrcweir 
707cdf0e10cSrcweir     //detect arguments for the new data source
708cdf0e10cSrcweir     ::rtl::OUString aRangeString;
709cdf0e10cSrcweir     bool bUseColumns = true;
710cdf0e10cSrcweir     bool bFirstCellAsLabel = true;
711cdf0e10cSrcweir     bool bHasCategories = true;
712cdf0e10cSrcweir     uno::Sequence< sal_Int32 > aSequenceMapping;
713cdf0e10cSrcweir 
714cdf0e10cSrcweir     DataSourceHelper::detectRangeSegmentation(
715cdf0e10cSrcweir         uno::Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ),
716cdf0e10cSrcweir         aRangeString, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories );
717cdf0e10cSrcweir 
718cdf0e10cSrcweir     if( !bHasCategories && rDataOperator.setsCategories( bUseColumns ) )
719cdf0e10cSrcweir         bHasCategories = true;
720cdf0e10cSrcweir 
721cdf0e10cSrcweir     aRangeString = C2U("all");
722cdf0e10cSrcweir     uno::Sequence< beans::PropertyValue > aArguments( DataSourceHelper::createArguments(
723cdf0e10cSrcweir             aRangeString, aSequenceMapping, bUseColumns, bFirstCellAsLabel, bHasCategories ) );
724cdf0e10cSrcweir 
725cdf0e10cSrcweir 
726cdf0e10cSrcweir     // /-- locked controllers
727cdf0e10cSrcweir     ControllerLockGuard aCtrlLockGuard( uno::Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ));
728cdf0e10cSrcweir 
729cdf0e10cSrcweir     // create and attach new data source
730cdf0e10cSrcweir     switchToInternalDataProvider();
731cdf0e10cSrcweir     rDataOperator.apply(m_xDataAccess);
732cdf0e10cSrcweir     uno::Reference< chart2::data::XDataProvider > xDataProvider( xChartDoc->getDataProvider() );
733cdf0e10cSrcweir     OSL_ASSERT( xDataProvider.is() );
734cdf0e10cSrcweir     if( !xDataProvider.is() )
735cdf0e10cSrcweir         return;
736cdf0e10cSrcweir     uno::Reference< chart2::data::XDataSource > xSource( xDataProvider->createDataSource( aArguments ) );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir     uno::Reference< chart2::XDiagram > xDia( xChartDoc->getFirstDiagram() );
739cdf0e10cSrcweir     if( xDia.is() )
740cdf0e10cSrcweir         xDia->setDiagramData( xSource, aArguments );
741cdf0e10cSrcweir 
742cdf0e10cSrcweir     //correct stacking mode
743cdf0e10cSrcweir     if( bStacked || bPercent || bDeep )
744cdf0e10cSrcweir     {
745cdf0e10cSrcweir         StackMode eStackMode = StackMode_Y_STACKED;
746cdf0e10cSrcweir         if( bDeep )
747cdf0e10cSrcweir             eStackMode = StackMode_Z_STACKED;
748cdf0e10cSrcweir         else if( bPercent )
749cdf0e10cSrcweir             eStackMode = StackMode_Y_STACKED_PERCENT;
750cdf0e10cSrcweir         DiagramHelper::setStackMode( xDia, eStackMode );
751cdf0e10cSrcweir     }
752cdf0e10cSrcweir 
753cdf0e10cSrcweir     // notify listeners
754cdf0e10cSrcweir     ::com::sun::star::chart::ChartDataChangeEvent aEvent(
755cdf0e10cSrcweir         static_cast< ::cppu::OWeakObject* >( this ),
756cdf0e10cSrcweir         ::com::sun::star::chart::ChartDataChangeType_ALL, 0, 0, 0, 0 );
757cdf0e10cSrcweir     fireChartDataChangeEvent( aEvent );
758cdf0e10cSrcweir     // \-- locked controllers
759cdf0e10cSrcweir }
760cdf0e10cSrcweir 
761cdf0e10cSrcweir // --------------------------------------------------------------------------------
762cdf0e10cSrcweir 
getSupportedServiceNames_Static()763cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > ChartDataWrapper::getSupportedServiceNames_Static()
764cdf0e10cSrcweir {
765cdf0e10cSrcweir     uno::Sequence< ::rtl::OUString > aServices( 2 );
766cdf0e10cSrcweir     aServices[ 0 ] = C2U( "com.sun.star.chart.ChartDataArray" );
767cdf0e10cSrcweir     aServices[ 1 ] = C2U( "com.sun.star.chart.ChartData" );
768cdf0e10cSrcweir 
769cdf0e10cSrcweir     return aServices;
770cdf0e10cSrcweir }
771cdf0e10cSrcweir 
772cdf0e10cSrcweir // ================================================================================
773cdf0e10cSrcweir 
774cdf0e10cSrcweir // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
775cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL( ChartDataWrapper, lcl_aServiceName );
776cdf0e10cSrcweir 
777cdf0e10cSrcweir } //  namespace wrapper
778cdf0e10cSrcweir } //  namespace chart
779