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
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
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.
19*cde9e8dcSAndrew Rist  *
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 "DiagramHelper.hxx"
27cdf0e10cSrcweir #include "LegendHelper.hxx"
28cdf0e10cSrcweir #include "PropertyHelper.hxx"
29cdf0e10cSrcweir #include "macros.hxx"
30cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
31cdf0e10cSrcweir #include "AxisHelper.hxx"
32cdf0e10cSrcweir #include "ContainerHelper.hxx"
33cdf0e10cSrcweir #include "ChartTypeHelper.hxx"
34cdf0e10cSrcweir #include "ChartModelHelper.hxx"
35cdf0e10cSrcweir #include "CommonConverters.hxx"
36cdf0e10cSrcweir #include "ExplicitCategoriesProvider.hxx"
37cdf0e10cSrcweir #include "servicenames_charttypes.hxx"
38cdf0e10cSrcweir #include "ChartModelHelper.hxx"
39cdf0e10cSrcweir #include "RelativePositionHelper.hxx"
40cdf0e10cSrcweir #include "ControllerLockGuard.hxx"
41cdf0e10cSrcweir #include "NumberFormatterWrapper.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <com/sun/star/chart/MissingValueTreatment.hpp>
44cdf0e10cSrcweir #include <com/sun/star/chart/XChartDocument.hpp>
45cdf0e10cSrcweir #include <com/sun/star/chart/XDiagramPositioning.hpp>
46cdf0e10cSrcweir #include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
47cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp>
48cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp>
49cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeTemplate.hpp>
50cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
51cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
52cdf0e10cSrcweir #include <com/sun/star/chart2/InterpretedData.hpp>
53cdf0e10cSrcweir #include <com/sun/star/chart2/AxisType.hpp>
54cdf0e10cSrcweir #include <com/sun/star/chart2/DataPointGeometry3D.hpp>
55cdf0e10cSrcweir #include <com/sun/star/chart2/RelativePosition.hpp>
56cdf0e10cSrcweir #include <com/sun/star/chart2/RelativeSize.hpp>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp>
59cdf0e10cSrcweir #include <com/sun/star/util/XModifiable.hpp>
60cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
61cdf0e10cSrcweir 
62cdf0e10cSrcweir #include <unotools/saveopt.hxx>
63cdf0e10cSrcweir #include <rtl/math.hxx>
64cdf0e10cSrcweir #include <svl/zformat.hxx>
65cdf0e10cSrcweir // header for class Application
66cdf0e10cSrcweir #include <vcl/svapp.hxx>
67cdf0e10cSrcweir 
68cdf0e10cSrcweir using namespace ::com::sun::star;
69cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
70cdf0e10cSrcweir using namespace ::std;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
73cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
74cdf0e10cSrcweir using ::com::sun::star::uno::Any;
75cdf0e10cSrcweir using ::rtl::OUString;
76cdf0e10cSrcweir using ::com::sun::star::chart2::XAnyDescriptionAccess;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir namespace chart
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 
81cdf0e10cSrcweir DiagramHelper::tTemplateWithServiceName
82cdf0e10cSrcweir     DiagramHelper::getTemplateForDiagram(
83cdf0e10cSrcweir         const Reference< XDiagram > & xDiagram,
84cdf0e10cSrcweir         const Reference< lang::XMultiServiceFactory > & xChartTypeManager,
85cdf0e10cSrcweir         const OUString & rPreferredTemplateName )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     DiagramHelper::tTemplateWithServiceName aResult;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     if( ! (xChartTypeManager.is() && xDiagram.is()))
90cdf0e10cSrcweir         return aResult;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     Sequence< OUString > aServiceNames( xChartTypeManager->getAvailableServiceNames());
93cdf0e10cSrcweir     const sal_Int32 nLength = aServiceNames.getLength();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     bool bHasPreferredTemplate = (rPreferredTemplateName.getLength() > 0);
96cdf0e10cSrcweir     bool bTemplateFound = false;
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     if( bHasPreferredTemplate )
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         Reference< XChartTypeTemplate > xTempl(
101cdf0e10cSrcweir             xChartTypeManager->createInstance( rPreferredTemplateName ), uno::UNO_QUERY );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         if( xTempl.is() &&
104cdf0e10cSrcweir             xTempl->matchesTemplate( xDiagram, sal_True ))
105cdf0e10cSrcweir         {
106cdf0e10cSrcweir             aResult.first = xTempl;
107cdf0e10cSrcweir             aResult.second = rPreferredTemplateName;
108cdf0e10cSrcweir             bTemplateFound = true;
109cdf0e10cSrcweir         }
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     for( sal_Int32 i = 0; ! bTemplateFound && i < nLength; ++i )
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         try
115cdf0e10cSrcweir         {
116cdf0e10cSrcweir             if( ! bHasPreferredTemplate ||
117cdf0e10cSrcweir                 ! rPreferredTemplateName.equals( aServiceNames[ i ] ))
118cdf0e10cSrcweir             {
119cdf0e10cSrcweir                 Reference< XChartTypeTemplate > xTempl(
120cdf0e10cSrcweir                     xChartTypeManager->createInstance( aServiceNames[ i ] ), uno::UNO_QUERY_THROW );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir                 if( xTempl->matchesTemplate( xDiagram, sal_True ))
123cdf0e10cSrcweir                 {
124cdf0e10cSrcweir                     aResult.first = xTempl;
125cdf0e10cSrcweir                     aResult.second = aServiceNames[ i ];
126cdf0e10cSrcweir                     bTemplateFound = true;
127cdf0e10cSrcweir                 }
128cdf0e10cSrcweir             }
129cdf0e10cSrcweir         }
130cdf0e10cSrcweir         catch( uno::Exception & ex )
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             ASSERT_EXCEPTION( ex );
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     return aResult;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir void DiagramHelper::setVertical(
140cdf0e10cSrcweir     const Reference< XDiagram > & xDiagram,
141cdf0e10cSrcweir     bool bVertical /* = true */ )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir     try
144cdf0e10cSrcweir     {
145cdf0e10cSrcweir         Reference< XCoordinateSystemContainer > xCnt( xDiagram, uno::UNO_QUERY );
146cdf0e10cSrcweir         if( xCnt.is())
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             Sequence< Reference< XCoordinateSystem > > aCooSys(
149cdf0e10cSrcweir                 xCnt->getCoordinateSystems());
150cdf0e10cSrcweir             uno::Any aValue;
151cdf0e10cSrcweir             aValue <<= bVertical;
152cdf0e10cSrcweir             for( sal_Int32 i=0; i<aCooSys.getLength(); ++i )
153cdf0e10cSrcweir             {
154cdf0e10cSrcweir                 uno::Reference< XCoordinateSystem > xCooSys( aCooSys[i] );
155cdf0e10cSrcweir                 Reference< beans::XPropertySet > xProp( xCooSys, uno::UNO_QUERY );
156cdf0e10cSrcweir                 bool bChanged = false;
157cdf0e10cSrcweir                 if( xProp.is() )
158cdf0e10cSrcweir                 {
159cdf0e10cSrcweir                     bool bOldSwap = sal_False;
160cdf0e10cSrcweir                     if( !(xProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bOldSwap)
161cdf0e10cSrcweir                         || bVertical != bOldSwap )
162cdf0e10cSrcweir                         bChanged = true;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir                     if( bChanged )
165cdf0e10cSrcweir                         xProp->setPropertyValue( C2U("SwapXAndYAxis"), aValue );
166cdf0e10cSrcweir                 }
167cdf0e10cSrcweir                 if( xCooSys.is() )
168cdf0e10cSrcweir                 {
169cdf0e10cSrcweir                     const sal_Int32 nDimensionCount( xCooSys->getDimension() );
170cdf0e10cSrcweir                     sal_Int32 nDimIndex = 0;
171cdf0e10cSrcweir                     for(nDimIndex=0; nDimIndex<nDimensionCount; ++nDimIndex)
172cdf0e10cSrcweir                     {
173cdf0e10cSrcweir                         const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(nDimIndex);
174cdf0e10cSrcweir                         for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI)
175cdf0e10cSrcweir                         {
176cdf0e10cSrcweir                             Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( nDimIndex,nI ));
177cdf0e10cSrcweir                             if( xAxis.is() )
178cdf0e10cSrcweir                             {
179cdf0e10cSrcweir                                 //adapt title rotation only when axis swapping has changed
180cdf0e10cSrcweir                                 if( bChanged )
181cdf0e10cSrcweir                                 {
182cdf0e10cSrcweir                                     Reference< XTitled > xTitled( xAxis, uno::UNO_QUERY );
183cdf0e10cSrcweir                                     if( xTitled.is())
184cdf0e10cSrcweir                                     {
185cdf0e10cSrcweir                                         Reference< beans::XPropertySet > xTitleProps( xTitled->getTitleObject(), uno::UNO_QUERY );
186cdf0e10cSrcweir                                         if( !xTitleProps.is() )
187cdf0e10cSrcweir                                             continue;
188cdf0e10cSrcweir                                         double fAngleDegree = 0.0;
189cdf0e10cSrcweir                                         xTitleProps->getPropertyValue( C2U( "TextRotation" ) ) >>= fAngleDegree;
190cdf0e10cSrcweir                                         if( !::rtl::math::approxEqual( fAngleDegree, 0.0 )
191cdf0e10cSrcweir                                             && !::rtl::math::approxEqual( fAngleDegree, 90.0 ) )
192cdf0e10cSrcweir                                             continue;
193cdf0e10cSrcweir 
194cdf0e10cSrcweir                                         double fNewAngleDegree = 0.0;
195cdf0e10cSrcweir                                         if( !bVertical && nDimIndex == 1 )
196cdf0e10cSrcweir                                             fNewAngleDegree = 90.0;
197cdf0e10cSrcweir                                         else if( bVertical && nDimIndex == 0 )
198cdf0e10cSrcweir                                             fNewAngleDegree = 90.0;
199cdf0e10cSrcweir 
200cdf0e10cSrcweir                                         xTitleProps->setPropertyValue( C2U( "TextRotation" ), uno::makeAny( fNewAngleDegree ));
201cdf0e10cSrcweir                                     }
202cdf0e10cSrcweir                                 }
203cdf0e10cSrcweir                             }
204cdf0e10cSrcweir                         }
205cdf0e10cSrcweir                     }
206cdf0e10cSrcweir                 }
207cdf0e10cSrcweir             }
208cdf0e10cSrcweir         }
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir     catch( uno::Exception & ex )
211cdf0e10cSrcweir     {
212cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
216cdf0e10cSrcweir bool DiagramHelper::getVertical( const uno::Reference< chart2::XDiagram > & xDiagram,
217cdf0e10cSrcweir                              bool& rbFound, bool& rbAmbiguous )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     bool bValue = false;
220cdf0e10cSrcweir     rbFound = false;
221cdf0e10cSrcweir     rbAmbiguous = false;
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     Reference< XCoordinateSystemContainer > xCnt( xDiagram, uno::UNO_QUERY );
224cdf0e10cSrcweir     if( xCnt.is())
225cdf0e10cSrcweir     {
226cdf0e10cSrcweir         Sequence< Reference< XCoordinateSystem > > aCooSys(
227cdf0e10cSrcweir             xCnt->getCoordinateSystems());
228cdf0e10cSrcweir         for( sal_Int32 i=0; i<aCooSys.getLength(); ++i )
229cdf0e10cSrcweir         {
230cdf0e10cSrcweir             Reference< beans::XPropertySet > xProp( aCooSys[i], uno::UNO_QUERY );
231cdf0e10cSrcweir             if( xProp.is())
232cdf0e10cSrcweir             {
233cdf0e10cSrcweir                 bool bCurrent = false;
234cdf0e10cSrcweir                 if( xProp->getPropertyValue( C2U("SwapXAndYAxis") ) >>= bCurrent )
235cdf0e10cSrcweir                 {
236cdf0e10cSrcweir                     if( !rbFound )
237cdf0e10cSrcweir                     {
238cdf0e10cSrcweir                         bValue = bCurrent;
239cdf0e10cSrcweir                         rbFound = true;
240cdf0e10cSrcweir                     }
241cdf0e10cSrcweir                     else if( bCurrent != bValue )
242cdf0e10cSrcweir                     {
243cdf0e10cSrcweir                         // ambiguous -> choose always first found
244cdf0e10cSrcweir                         rbAmbiguous = true;
245cdf0e10cSrcweir                     }
246cdf0e10cSrcweir                 }
247cdf0e10cSrcweir             }
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir     }
250cdf0e10cSrcweir     return bValue;
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
253cdf0e10cSrcweir void DiagramHelper::setStackMode(
254cdf0e10cSrcweir     const Reference< XDiagram > & xDiagram,
255cdf0e10cSrcweir     StackMode eStackMode,
256cdf0e10cSrcweir     bool bOnlyAtFirstChartType /* = true */
257cdf0e10cSrcweir )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir     try
260cdf0e10cSrcweir     {
261cdf0e10cSrcweir         if( eStackMode == StackMode_AMBIGUOUS )
262cdf0e10cSrcweir             return;
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         bool bValueFound = false;
265cdf0e10cSrcweir         bool bIsAmbiguous = false;
266cdf0e10cSrcweir         StackMode eOldStackMode = DiagramHelper::getStackMode( xDiagram, bValueFound, bIsAmbiguous );
267cdf0e10cSrcweir 
268cdf0e10cSrcweir         if( eStackMode == eOldStackMode && !bIsAmbiguous )
269cdf0e10cSrcweir             return;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         StackingDirection eNewDirection = StackingDirection_NO_STACKING;
272cdf0e10cSrcweir         if( eStackMode == StackMode_Y_STACKED || eStackMode == StackMode_Y_STACKED_PERCENT )
273cdf0e10cSrcweir             eNewDirection = StackingDirection_Y_STACKING;
274cdf0e10cSrcweir         else if( eStackMode == StackMode_Z_STACKED )
275cdf0e10cSrcweir             eNewDirection = StackingDirection_Z_STACKING;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir         uno::Any aNewDirection( uno::makeAny(eNewDirection) );
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         sal_Bool bPercent = sal_False;
280cdf0e10cSrcweir         if( eStackMode == StackMode_Y_STACKED_PERCENT )
281cdf0e10cSrcweir             bPercent = sal_True;
282cdf0e10cSrcweir 
283cdf0e10cSrcweir         //iterate through all coordinate systems
284cdf0e10cSrcweir         uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
285cdf0e10cSrcweir         if( !xCooSysContainer.is() )
286cdf0e10cSrcweir             return;
287cdf0e10cSrcweir         uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
288cdf0e10cSrcweir         for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
289cdf0e10cSrcweir         {
290cdf0e10cSrcweir             uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] );
291cdf0e10cSrcweir             //set correct percent stacking
292cdf0e10cSrcweir             const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(1);
293cdf0e10cSrcweir             for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI)
294cdf0e10cSrcweir             {
295cdf0e10cSrcweir                 Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( 1,nI ));
296cdf0e10cSrcweir                 if( xAxis.is())
297cdf0e10cSrcweir                 {
298cdf0e10cSrcweir                     chart2::ScaleData aScaleData = xAxis->getScaleData();
299cdf0e10cSrcweir                     if( (aScaleData.AxisType==AxisType::PERCENT) != bPercent )
300cdf0e10cSrcweir                     {
301cdf0e10cSrcweir                         if( bPercent )
302cdf0e10cSrcweir                             aScaleData.AxisType = AxisType::PERCENT;
303cdf0e10cSrcweir                         else
304cdf0e10cSrcweir                             aScaleData.AxisType = AxisType::REALNUMBER;
305cdf0e10cSrcweir                         xAxis->setScaleData( aScaleData );
306cdf0e10cSrcweir                     }
307cdf0e10cSrcweir                 }
308cdf0e10cSrcweir             }
309cdf0e10cSrcweir             //iterate through all chart types in the current coordinate system
310cdf0e10cSrcweir             uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
311cdf0e10cSrcweir             if( !xChartTypeContainer.is() )
312cdf0e10cSrcweir                 continue;
313cdf0e10cSrcweir             uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
314cdf0e10cSrcweir             sal_Int32 nMax = aChartTypeList.getLength();
315cdf0e10cSrcweir             if( bOnlyAtFirstChartType
316cdf0e10cSrcweir                 && nMax >= 1 )
317cdf0e10cSrcweir                 nMax = 1;
318cdf0e10cSrcweir             for( sal_Int32 nT = 0; nT < nMax; ++nT )
319cdf0e10cSrcweir             {
320cdf0e10cSrcweir                 uno::Reference< XChartType > xChartType( aChartTypeList[nT] );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir                 //iterate through all series in this chart type
323cdf0e10cSrcweir                 uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
324cdf0e10cSrcweir                 OSL_ASSERT( xDataSeriesContainer.is());
325cdf0e10cSrcweir                 if( !xDataSeriesContainer.is() )
326cdf0e10cSrcweir                     continue;
327cdf0e10cSrcweir 
328cdf0e10cSrcweir                 uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
329cdf0e10cSrcweir                 for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
330cdf0e10cSrcweir                 {
331cdf0e10cSrcweir                     Reference< beans::XPropertySet > xProp( aSeriesList[nS], uno::UNO_QUERY );
332cdf0e10cSrcweir 		            if(xProp.is())
333cdf0e10cSrcweir                         xProp->setPropertyValue( C2U( "StackingDirection" ), aNewDirection );
334cdf0e10cSrcweir                 }
335cdf0e10cSrcweir             }
336cdf0e10cSrcweir         }
337cdf0e10cSrcweir     }
338cdf0e10cSrcweir     catch( uno::Exception & ex )
339cdf0e10cSrcweir     {
340cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
341cdf0e10cSrcweir     }
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir StackMode DiagramHelper::getStackMode( const Reference< XDiagram > & xDiagram, bool& rbFound, bool& rbAmbiguous )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir     rbFound=false;
347cdf0e10cSrcweir     rbAmbiguous=false;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir     StackMode eGlobalStackMode = StackMode_NONE;
350cdf0e10cSrcweir 
351cdf0e10cSrcweir     //iterate through all coordinate systems
352cdf0e10cSrcweir     uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
353cdf0e10cSrcweir     if( !xCooSysContainer.is() )
354cdf0e10cSrcweir         return eGlobalStackMode;
355cdf0e10cSrcweir     uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
356cdf0e10cSrcweir     for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
357cdf0e10cSrcweir     {
358cdf0e10cSrcweir         uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] );
359cdf0e10cSrcweir 
360cdf0e10cSrcweir         //iterate through all chart types in the current coordinate system
361cdf0e10cSrcweir         uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
362cdf0e10cSrcweir         if( !xChartTypeContainer.is() )
363cdf0e10cSrcweir             continue;
364cdf0e10cSrcweir         uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
365cdf0e10cSrcweir         for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
366cdf0e10cSrcweir         {
367cdf0e10cSrcweir             uno::Reference< XChartType > xChartType( aChartTypeList[nT] );
368cdf0e10cSrcweir 
369cdf0e10cSrcweir             StackMode eLocalStackMode = DiagramHelper::getStackModeFromChartType(
370cdf0e10cSrcweir                 xChartType, rbFound, rbAmbiguous, xCooSys );
371cdf0e10cSrcweir 
372cdf0e10cSrcweir             if( rbFound && eLocalStackMode != eGlobalStackMode && nT>0 )
373cdf0e10cSrcweir             {
374cdf0e10cSrcweir                 rbAmbiguous = true;
375cdf0e10cSrcweir                 return eGlobalStackMode;
376cdf0e10cSrcweir             }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir             eGlobalStackMode = eLocalStackMode;
379cdf0e10cSrcweir         }
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     return eGlobalStackMode;
383cdf0e10cSrcweir }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir StackMode DiagramHelper::getStackModeFromChartType(
386cdf0e10cSrcweir     const Reference< XChartType > & xChartType,
387cdf0e10cSrcweir     bool& rbFound, bool& rbAmbiguous,
388cdf0e10cSrcweir     const Reference< XCoordinateSystem > & xCorrespondingCoordinateSystem )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir     StackMode eStackMode = StackMode_NONE;
391cdf0e10cSrcweir     rbFound = false;
392cdf0e10cSrcweir     rbAmbiguous = false;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     try
395cdf0e10cSrcweir     {
396cdf0e10cSrcweir         Reference< XDataSeriesContainer > xDSCnt( xChartType, uno::UNO_QUERY_THROW );
397cdf0e10cSrcweir         Sequence< Reference< chart2::XDataSeries > > aSeries( xDSCnt->getDataSeries());
398cdf0e10cSrcweir 
399cdf0e10cSrcweir         chart2::StackingDirection eCommonDirection = chart2::StackingDirection_NO_STACKING;
400cdf0e10cSrcweir         bool bDirectionInitialized = false;
401cdf0e10cSrcweir 
402cdf0e10cSrcweir         // first series is irrelvant for stacking, start with second, unless
403cdf0e10cSrcweir         // there is only one series
404cdf0e10cSrcweir         const sal_Int32 nSeriesCount = aSeries.getLength();
405cdf0e10cSrcweir         sal_Int32 i = (nSeriesCount == 1) ? 0: 1;
406cdf0e10cSrcweir         for( ; i<nSeriesCount; ++i )
407cdf0e10cSrcweir         {
408cdf0e10cSrcweir             rbFound = true;
409cdf0e10cSrcweir             Reference< beans::XPropertySet > xProp( aSeries[i], uno::UNO_QUERY_THROW );
410cdf0e10cSrcweir             chart2::StackingDirection eCurrentDirection = eCommonDirection;
411cdf0e10cSrcweir             // property is not MAYBEVOID
412cdf0e10cSrcweir             bool bSuccess = ( xProp->getPropertyValue( C2U("StackingDirection") ) >>= eCurrentDirection );
413cdf0e10cSrcweir             OSL_ASSERT( bSuccess );
414cdf0e10cSrcweir             (void)(bSuccess);  // avoid warning in non-debug builds
415cdf0e10cSrcweir             if( ! bDirectionInitialized )
416cdf0e10cSrcweir             {
417cdf0e10cSrcweir                 eCommonDirection = eCurrentDirection;
418cdf0e10cSrcweir                 bDirectionInitialized = true;
419cdf0e10cSrcweir             }
420cdf0e10cSrcweir             else
421cdf0e10cSrcweir             {
422cdf0e10cSrcweir                 if( eCommonDirection != eCurrentDirection )
423cdf0e10cSrcweir                 {
424cdf0e10cSrcweir                     rbAmbiguous = true;
425cdf0e10cSrcweir                     break;
426cdf0e10cSrcweir                 }
427cdf0e10cSrcweir             }
428cdf0e10cSrcweir         }
429cdf0e10cSrcweir 
430cdf0e10cSrcweir         if( rbFound )
431cdf0e10cSrcweir         {
432cdf0e10cSrcweir             if( eCommonDirection == chart2::StackingDirection_Z_STACKING )
433cdf0e10cSrcweir                 eStackMode = StackMode_Z_STACKED;
434cdf0e10cSrcweir             else if( eCommonDirection == chart2::StackingDirection_Y_STACKING )
435cdf0e10cSrcweir             {
436cdf0e10cSrcweir                 eStackMode = StackMode_Y_STACKED;
437cdf0e10cSrcweir 
438cdf0e10cSrcweir                 // percent stacking
439cdf0e10cSrcweir                 if( xCorrespondingCoordinateSystem.is() )
440cdf0e10cSrcweir                 {
441cdf0e10cSrcweir                     if( 1 < xCorrespondingCoordinateSystem->getDimension() )
442cdf0e10cSrcweir                     {
443cdf0e10cSrcweir                         sal_Int32 nAxisIndex = 0;
444cdf0e10cSrcweir                         if( nSeriesCount )
445cdf0e10cSrcweir                             nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(aSeries[0]);
446cdf0e10cSrcweir 
447cdf0e10cSrcweir                         Reference< chart2::XAxis > xAxis(
448cdf0e10cSrcweir                             xCorrespondingCoordinateSystem->getAxisByDimension( 1,nAxisIndex ));
449cdf0e10cSrcweir                         if( xAxis.is())
450cdf0e10cSrcweir                         {
451cdf0e10cSrcweir                             chart2::ScaleData aScaleData = xAxis->getScaleData();
452cdf0e10cSrcweir                             if( aScaleData.AxisType==chart2::AxisType::PERCENT )
453cdf0e10cSrcweir                                 eStackMode = StackMode_Y_STACKED_PERCENT;
454cdf0e10cSrcweir                         }
455cdf0e10cSrcweir                     }
456cdf0e10cSrcweir                 }
457cdf0e10cSrcweir             }
458cdf0e10cSrcweir         }
459cdf0e10cSrcweir     }
460cdf0e10cSrcweir     catch( uno::Exception & ex )
461cdf0e10cSrcweir     {
462cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir 
465cdf0e10cSrcweir     return eStackMode;
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir sal_Int32 DiagramHelper::getDimension( const Reference< XDiagram > & xDiagram )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir     // -1: not yet set
471cdf0e10cSrcweir     sal_Int32 nResult = -1;
472cdf0e10cSrcweir 
473cdf0e10cSrcweir     try
474cdf0e10cSrcweir     {
475cdf0e10cSrcweir         Reference< XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY );
476cdf0e10cSrcweir         if( xCooSysCnt.is() )
477cdf0e10cSrcweir         {
478cdf0e10cSrcweir             Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
479cdf0e10cSrcweir                 xCooSysCnt->getCoordinateSystems());
480cdf0e10cSrcweir 
481cdf0e10cSrcweir             for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
482cdf0e10cSrcweir             {
483cdf0e10cSrcweir                 Reference< XCoordinateSystem > xCooSys( aCooSysSeq[i] );
484cdf0e10cSrcweir                 if(xCooSys.is())
485cdf0e10cSrcweir                 {
486cdf0e10cSrcweir                     nResult = xCooSys->getDimension();
487cdf0e10cSrcweir                     break;
488cdf0e10cSrcweir                 }
489cdf0e10cSrcweir             }
490cdf0e10cSrcweir         }
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir     catch( uno::Exception & ex )
493cdf0e10cSrcweir     {
494cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
495cdf0e10cSrcweir     }
496cdf0e10cSrcweir 
497cdf0e10cSrcweir     return nResult;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir void DiagramHelper::setDimension(
501cdf0e10cSrcweir     const Reference< XDiagram > & xDiagram,
502cdf0e10cSrcweir     sal_Int32 nNewDimensionCount )
503cdf0e10cSrcweir {
504cdf0e10cSrcweir     if( ! xDiagram.is())
505cdf0e10cSrcweir         return;
506cdf0e10cSrcweir 
507cdf0e10cSrcweir     if( DiagramHelper::getDimension( xDiagram ) == nNewDimensionCount )
508cdf0e10cSrcweir         return;
509cdf0e10cSrcweir 
510cdf0e10cSrcweir     try
511cdf0e10cSrcweir     {
512cdf0e10cSrcweir         bool rbFound = false;
513cdf0e10cSrcweir         bool rbAmbiguous = true;
514cdf0e10cSrcweir         StackMode eStackMode = DiagramHelper::getStackMode( xDiagram, rbFound, rbAmbiguous );
515cdf0e10cSrcweir         bool bIsSupportingOnlyDeepStackingFor3D=false;
516cdf0e10cSrcweir 
517cdf0e10cSrcweir         //change all coordinate systems:
518cdf0e10cSrcweir         Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY_THROW );
519cdf0e10cSrcweir         Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
520cdf0e10cSrcweir         for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
521cdf0e10cSrcweir         {
522cdf0e10cSrcweir             Reference< XCoordinateSystem > xOldCooSys( aCooSysList[nCS], uno::UNO_QUERY );
523cdf0e10cSrcweir             Reference< XCoordinateSystem > xNewCooSys;
524cdf0e10cSrcweir 
525cdf0e10cSrcweir             Reference< XChartTypeContainer > xChartTypeContainer( xOldCooSys, uno::UNO_QUERY );
526cdf0e10cSrcweir             if( !xChartTypeContainer.is() )
527cdf0e10cSrcweir                 continue;
528cdf0e10cSrcweir 
529cdf0e10cSrcweir             Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
530cdf0e10cSrcweir             for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
531cdf0e10cSrcweir             {
532cdf0e10cSrcweir                 Reference< XChartType > xChartType( aChartTypeList[nT], uno::UNO_QUERY );
533cdf0e10cSrcweir                 bIsSupportingOnlyDeepStackingFor3D = ChartTypeHelper::isSupportingOnlyDeepStackingFor3D( xChartType );
534cdf0e10cSrcweir                 if(!xNewCooSys.is())
535cdf0e10cSrcweir                 {
536cdf0e10cSrcweir                     xNewCooSys = xChartType->createCoordinateSystem( nNewDimensionCount );
537cdf0e10cSrcweir                     break;
538cdf0e10cSrcweir                 }
539cdf0e10cSrcweir                 //@todo make sure that all following charttypes are also capable of the new dimension
540cdf0e10cSrcweir                 //otherwise separate them in a different group
541cdf0e10cSrcweir                 //BM: might be done in replaceCoordinateSystem()
542cdf0e10cSrcweir             }
543cdf0e10cSrcweir 
544cdf0e10cSrcweir             // replace the old coordinate system at all places where it was used
545cdf0e10cSrcweir             DiagramHelper::replaceCoordinateSystem( xDiagram, xOldCooSys, xNewCooSys );
546cdf0e10cSrcweir         }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir         //correct stack mode if necessary
549cdf0e10cSrcweir         if( nNewDimensionCount==3 && eStackMode != StackMode_Z_STACKED && bIsSupportingOnlyDeepStackingFor3D )
550cdf0e10cSrcweir             DiagramHelper::setStackMode( xDiagram, StackMode_Z_STACKED );
551cdf0e10cSrcweir         else if( nNewDimensionCount==2 && eStackMode == StackMode_Z_STACKED )
552cdf0e10cSrcweir             DiagramHelper::setStackMode( xDiagram, StackMode_NONE );
553cdf0e10cSrcweir     }
554cdf0e10cSrcweir     catch( uno::Exception & ex )
555cdf0e10cSrcweir     {
556cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
557cdf0e10cSrcweir     }
558cdf0e10cSrcweir }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir void DiagramHelper::replaceCoordinateSystem(
561cdf0e10cSrcweir     const Reference< XDiagram > & xDiagram,
562cdf0e10cSrcweir     const Reference< XCoordinateSystem > & xCooSysToReplace,
563cdf0e10cSrcweir     const Reference< XCoordinateSystem > & xReplacement )
564cdf0e10cSrcweir {
565cdf0e10cSrcweir     OSL_ASSERT( xDiagram.is());
566cdf0e10cSrcweir     if( ! xDiagram.is())
567cdf0e10cSrcweir         return;
568cdf0e10cSrcweir 
569cdf0e10cSrcweir     // update the coordinate-system container
570cdf0e10cSrcweir     Reference< XCoordinateSystemContainer > xCont( xDiagram, uno::UNO_QUERY );
571cdf0e10cSrcweir     if( xCont.is())
572cdf0e10cSrcweir     {
573cdf0e10cSrcweir         try
574cdf0e10cSrcweir         {
575cdf0e10cSrcweir             Reference< chart2::data::XLabeledDataSequence > xCategories = DiagramHelper::getCategoriesFromDiagram( xDiagram );
576cdf0e10cSrcweir 
577cdf0e10cSrcweir             // move chart types of xCooSysToReplace to xReplacement
578cdf0e10cSrcweir             Reference< XChartTypeContainer > xCTCntCooSys( xCooSysToReplace, uno::UNO_QUERY_THROW );
579cdf0e10cSrcweir             Reference< XChartTypeContainer > xCTCntReplacement( xReplacement, uno::UNO_QUERY_THROW );
580cdf0e10cSrcweir             xCTCntReplacement->setChartTypes( xCTCntCooSys->getChartTypes());
581cdf0e10cSrcweir 
582cdf0e10cSrcweir             xCont->removeCoordinateSystem( xCooSysToReplace );
583cdf0e10cSrcweir             xCont->addCoordinateSystem( xReplacement );
584cdf0e10cSrcweir 
585cdf0e10cSrcweir             if( xCategories.is() )
586cdf0e10cSrcweir                 DiagramHelper::setCategoriesToDiagram( xCategories, xDiagram );
587cdf0e10cSrcweir         }
588cdf0e10cSrcweir         catch( uno::Exception & ex )
589cdf0e10cSrcweir         {
590cdf0e10cSrcweir             ASSERT_EXCEPTION( ex );
591cdf0e10cSrcweir         }
592cdf0e10cSrcweir     }
593cdf0e10cSrcweir }
594cdf0e10cSrcweir 
595cdf0e10cSrcweir bool DiagramHelper::isSeriesAttachedToMainAxis(
596cdf0e10cSrcweir 			              const uno::Reference< chart2::XDataSeries >& xDataSeries )
597cdf0e10cSrcweir {
598cdf0e10cSrcweir     sal_Int32 nAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
599cdf0e10cSrcweir     return (nAxisIndex==0);
600cdf0e10cSrcweir }
601cdf0e10cSrcweir 
602cdf0e10cSrcweir bool DiagramHelper::attachSeriesToAxis( bool bAttachToMainAxis
603cdf0e10cSrcweir 			            , const uno::Reference< chart2::XDataSeries >& xDataSeries
604cdf0e10cSrcweir                         , const uno::Reference< chart2::XDiagram >& xDiagram
605cdf0e10cSrcweir                         , const uno::Reference< uno::XComponentContext > & xContext
606cdf0e10cSrcweir                         , bool bAdaptAxes )
607cdf0e10cSrcweir {
608cdf0e10cSrcweir     bool bChanged = false;
609cdf0e10cSrcweir 
610cdf0e10cSrcweir     //set property at axis
611cdf0e10cSrcweir     Reference< beans::XPropertySet > xProp( xDataSeries, uno::UNO_QUERY_THROW );
612cdf0e10cSrcweir     if( !xProp.is() )
613cdf0e10cSrcweir         return bChanged;
614cdf0e10cSrcweir 
615cdf0e10cSrcweir     sal_Int32 nNewAxisIndex = bAttachToMainAxis ? 0 : 1;
616cdf0e10cSrcweir     sal_Int32 nOldAxisIndex = DataSeriesHelper::getAttachedAxisIndex(xDataSeries);
617cdf0e10cSrcweir     uno::Reference< chart2::XAxis > xOldAxis( DiagramHelper::getAttachedAxis( xDataSeries, xDiagram ) );
618cdf0e10cSrcweir 
619cdf0e10cSrcweir     if( nOldAxisIndex != nNewAxisIndex )
620cdf0e10cSrcweir     {
621cdf0e10cSrcweir         try
622cdf0e10cSrcweir         {
623cdf0e10cSrcweir             xProp->setPropertyValue( C2U("AttachedAxisIndex"), uno::makeAny( nNewAxisIndex ) );
624cdf0e10cSrcweir             bChanged = true;
625cdf0e10cSrcweir         }
626cdf0e10cSrcweir         catch( const uno::Exception & ex )
627cdf0e10cSrcweir         {
628cdf0e10cSrcweir             ASSERT_EXCEPTION( ex );
629cdf0e10cSrcweir         }
630cdf0e10cSrcweir     }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir     if( bChanged && xDiagram.is() )
633cdf0e10cSrcweir     {
634cdf0e10cSrcweir         uno::Reference< XAxis > xAxis( AxisHelper::getAxis( 1, bAttachToMainAxis, xDiagram ) );
635cdf0e10cSrcweir         if(!xAxis.is()) //create an axis if necessary
636cdf0e10cSrcweir             xAxis = AxisHelper::createAxis( 1, bAttachToMainAxis, xDiagram, xContext );
637cdf0e10cSrcweir         if( bAdaptAxes )
638cdf0e10cSrcweir         {
639cdf0e10cSrcweir             AxisHelper::makeAxisVisible( xAxis );
640cdf0e10cSrcweir             AxisHelper::hideAxisIfNoDataIsAttached( xOldAxis, xDiagram );
641cdf0e10cSrcweir         }
642cdf0e10cSrcweir     }
643cdf0e10cSrcweir 
644cdf0e10cSrcweir     return bChanged;
645cdf0e10cSrcweir }
646cdf0e10cSrcweir 
647cdf0e10cSrcweir uno::Reference< XAxis > DiagramHelper::getAttachedAxis(
648cdf0e10cSrcweir         const uno::Reference< XDataSeries >& xSeries,
649cdf0e10cSrcweir         const uno::Reference< XDiagram >& xDiagram )
650cdf0e10cSrcweir {
651cdf0e10cSrcweir     return AxisHelper::getAxis( 1, DiagramHelper::isSeriesAttachedToMainAxis( xSeries ), xDiagram );
652cdf0e10cSrcweir }
653cdf0e10cSrcweir 
654cdf0e10cSrcweir uno::Reference< XChartType > DiagramHelper::getChartTypeOfSeries(
655cdf0e10cSrcweir 								const uno::Reference< chart2::XDiagram >&   xDiagram
656cdf0e10cSrcweir 						      , const uno::Reference< XDataSeries >&        xGivenDataSeries )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir     if( !xGivenDataSeries.is() )
659cdf0e10cSrcweir         return 0;
660cdf0e10cSrcweir     if(!xDiagram.is())
661cdf0e10cSrcweir         return 0;
662cdf0e10cSrcweir 
663cdf0e10cSrcweir 	//iterate through the model to find the given xSeries
664cdf0e10cSrcweir 	//the found parent indicates the charttype
665cdf0e10cSrcweir 
666cdf0e10cSrcweir     //iterate through all coordinate systems
667cdf0e10cSrcweir     uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
668cdf0e10cSrcweir     if( !xCooSysContainer.is())
669cdf0e10cSrcweir         return 0;
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
672cdf0e10cSrcweir     for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
673cdf0e10cSrcweir     {
674cdf0e10cSrcweir         uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] );
675cdf0e10cSrcweir 
676cdf0e10cSrcweir         //iterate through all chart types in the current coordinate system
677cdf0e10cSrcweir         uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
678cdf0e10cSrcweir         OSL_ASSERT( xChartTypeContainer.is());
679cdf0e10cSrcweir         if( !xChartTypeContainer.is() )
680cdf0e10cSrcweir             continue;
681cdf0e10cSrcweir         uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
682cdf0e10cSrcweir         for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
683cdf0e10cSrcweir         {
684cdf0e10cSrcweir             uno::Reference< XChartType > xChartType( aChartTypeList[nT] );
685cdf0e10cSrcweir 
686cdf0e10cSrcweir             //iterate through all series in this chart type
687cdf0e10cSrcweir             uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY );
688cdf0e10cSrcweir             OSL_ASSERT( xDataSeriesContainer.is());
689cdf0e10cSrcweir             if( !xDataSeriesContainer.is() )
690cdf0e10cSrcweir                 continue;
691cdf0e10cSrcweir 
692cdf0e10cSrcweir             uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
693cdf0e10cSrcweir             for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS )
694cdf0e10cSrcweir             {
695cdf0e10cSrcweir 			    if( xGivenDataSeries==aSeriesList[nS] )
696cdf0e10cSrcweir                     return xChartType;
697cdf0e10cSrcweir             }
698cdf0e10cSrcweir         }
699cdf0e10cSrcweir     }
700cdf0e10cSrcweir 	return 0;
701cdf0e10cSrcweir }
702cdf0e10cSrcweir 
703cdf0e10cSrcweir ::std::vector< Reference< XDataSeries > >
704cdf0e10cSrcweir     DiagramHelper::getDataSeriesFromDiagram(
705cdf0e10cSrcweir         const Reference< XDiagram > & xDiagram )
706cdf0e10cSrcweir {
707cdf0e10cSrcweir     ::std::vector< Reference< XDataSeries > > aResult;
708cdf0e10cSrcweir 
709cdf0e10cSrcweir     try
710cdf0e10cSrcweir     {
711cdf0e10cSrcweir         Reference< XCoordinateSystemContainer > xCooSysCnt(
712cdf0e10cSrcweir             xDiagram, uno::UNO_QUERY_THROW );
713cdf0e10cSrcweir         Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
714cdf0e10cSrcweir             xCooSysCnt->getCoordinateSystems());
715cdf0e10cSrcweir         for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
716cdf0e10cSrcweir         {
717cdf0e10cSrcweir             Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW );
718cdf0e10cSrcweir             Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
719cdf0e10cSrcweir             for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j )
720cdf0e10cSrcweir             {
721cdf0e10cSrcweir                 Reference< XDataSeriesContainer > xDSCnt( aChartTypeSeq[j], uno::UNO_QUERY_THROW );
722cdf0e10cSrcweir                 Sequence< Reference< XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
723cdf0e10cSrcweir                 ::std::copy( aSeriesSeq.getConstArray(), aSeriesSeq.getConstArray() + aSeriesSeq.getLength(),
724cdf0e10cSrcweir                              ::std::back_inserter( aResult ));
725cdf0e10cSrcweir             }
726cdf0e10cSrcweir         }
727cdf0e10cSrcweir     }
728cdf0e10cSrcweir     catch( uno::Exception & ex )
729cdf0e10cSrcweir     {
730cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
731cdf0e10cSrcweir     }
732cdf0e10cSrcweir 
733cdf0e10cSrcweir     return aResult;
734cdf0e10cSrcweir }
735cdf0e10cSrcweir 
736cdf0e10cSrcweir Sequence< Sequence< Reference< XDataSeries > > >
737cdf0e10cSrcweir         DiagramHelper::getDataSeriesGroups( const Reference< XDiagram > & xDiagram )
738cdf0e10cSrcweir {
739cdf0e10cSrcweir     vector< Sequence< Reference< XDataSeries > > > aResult;
740cdf0e10cSrcweir 
741cdf0e10cSrcweir     //iterate through all coordinate systems
742cdf0e10cSrcweir     Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
743cdf0e10cSrcweir     if( xCooSysContainer.is() )
744cdf0e10cSrcweir     {
745cdf0e10cSrcweir         Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
746cdf0e10cSrcweir         for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
747cdf0e10cSrcweir         {
748cdf0e10cSrcweir             //iterate through all chart types in the current coordinate system
749cdf0e10cSrcweir             Reference< XChartTypeContainer > xChartTypeContainer( aCooSysList[nCS], uno::UNO_QUERY );
750cdf0e10cSrcweir             if( !xChartTypeContainer.is() )
751cdf0e10cSrcweir                 continue;
752cdf0e10cSrcweir             Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
753cdf0e10cSrcweir             for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT )
754cdf0e10cSrcweir             {
755cdf0e10cSrcweir                 Reference< XDataSeriesContainer > xDataSeriesContainer( aChartTypeList[nT], uno::UNO_QUERY );
756cdf0e10cSrcweir                 if( !xDataSeriesContainer.is() )
757cdf0e10cSrcweir                     continue;
758cdf0e10cSrcweir                 aResult.push_back( xDataSeriesContainer->getDataSeries() );
759cdf0e10cSrcweir             }
760cdf0e10cSrcweir         }
761cdf0e10cSrcweir     }
762cdf0e10cSrcweir     return ContainerHelper::ContainerToSequence( aResult );
763cdf0e10cSrcweir }
764cdf0e10cSrcweir 
765cdf0e10cSrcweir Reference< XChartType >
766cdf0e10cSrcweir     DiagramHelper::getChartTypeByIndex( const Reference< XDiagram >& xDiagram, sal_Int32 nIndex )
767cdf0e10cSrcweir {
768cdf0e10cSrcweir     Reference< XChartType > xChartType;
769cdf0e10cSrcweir 
770cdf0e10cSrcweir     //iterate through all coordinate systems
771cdf0e10cSrcweir     Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
772cdf0e10cSrcweir     if( ! xCooSysContainer.is())
773cdf0e10cSrcweir         return xChartType;
774cdf0e10cSrcweir 
775cdf0e10cSrcweir     Sequence< Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
776cdf0e10cSrcweir     sal_Int32 nTypesSoFar = 0;
777cdf0e10cSrcweir     for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS )
778cdf0e10cSrcweir     {
779cdf0e10cSrcweir         Reference< XChartTypeContainer > xChartTypeContainer( aCooSysList[nCS], uno::UNO_QUERY );
780cdf0e10cSrcweir         if( !xChartTypeContainer.is() )
781cdf0e10cSrcweir             continue;
782cdf0e10cSrcweir         Sequence< Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
783cdf0e10cSrcweir         if( nIndex >= 0 && nIndex < (nTypesSoFar + aChartTypeList.getLength()) )
784cdf0e10cSrcweir         {
785cdf0e10cSrcweir             xChartType.set( aChartTypeList[nIndex - nTypesSoFar] );
786cdf0e10cSrcweir             break;
787cdf0e10cSrcweir         }
788cdf0e10cSrcweir         nTypesSoFar += aChartTypeList.getLength();
789cdf0e10cSrcweir     }
790cdf0e10cSrcweir 
791cdf0e10cSrcweir     return xChartType;
792cdf0e10cSrcweir }
793cdf0e10cSrcweir 
794cdf0e10cSrcweir namespace
795cdf0e10cSrcweir {
796cdf0e10cSrcweir 
797cdf0e10cSrcweir std::vector< Reference< XAxis > > lcl_getAxisHoldingCategoriesFromDiagram(
798cdf0e10cSrcweir     const Reference< XDiagram > & xDiagram )
799cdf0e10cSrcweir {
800cdf0e10cSrcweir     std::vector< Reference< XAxis > > aRet;
801cdf0e10cSrcweir 
802cdf0e10cSrcweir     Reference< XAxis > xResult;
803cdf0e10cSrcweir     // return first x-axis as fall-back
804cdf0e10cSrcweir     Reference< XAxis > xFallBack;
805cdf0e10cSrcweir     try
806cdf0e10cSrcweir     {
807cdf0e10cSrcweir         Reference< XCoordinateSystemContainer > xCooSysCnt(
808cdf0e10cSrcweir             xDiagram, uno::UNO_QUERY_THROW );
809cdf0e10cSrcweir         Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
810cdf0e10cSrcweir             xCooSysCnt->getCoordinateSystems());
811cdf0e10cSrcweir         for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
812cdf0e10cSrcweir         {
813cdf0e10cSrcweir             Reference< XCoordinateSystem > xCooSys( aCooSysSeq[i] );
814cdf0e10cSrcweir             OSL_ASSERT( xCooSys.is());
815cdf0e10cSrcweir             for( sal_Int32 nN = xCooSys->getDimension(); nN--; )
816cdf0e10cSrcweir             {
817cdf0e10cSrcweir                 const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(nN);
818cdf0e10cSrcweir                 for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI)
819cdf0e10cSrcweir                 {
820cdf0e10cSrcweir                     Reference< XAxis > xAxis = xCooSys->getAxisByDimension( nN,nI );
821cdf0e10cSrcweir                     OSL_ASSERT( xAxis.is());
822cdf0e10cSrcweir                     if( xAxis.is())
823cdf0e10cSrcweir                     {
824cdf0e10cSrcweir                         ScaleData aScaleData = xAxis->getScaleData();
825cdf0e10cSrcweir                         if( aScaleData.Categories.is() || (aScaleData.AxisType == AxisType::CATEGORY) )
826cdf0e10cSrcweir                         {
827cdf0e10cSrcweir                             aRet.push_back(xAxis);
828cdf0e10cSrcweir                         }
829cdf0e10cSrcweir                         if( (nN == 0) && !xFallBack.is())
830cdf0e10cSrcweir                             xFallBack.set( xAxis );
831cdf0e10cSrcweir                     }
832cdf0e10cSrcweir                 }
833cdf0e10cSrcweir             }
834cdf0e10cSrcweir         }
835cdf0e10cSrcweir     }
836cdf0e10cSrcweir     catch( uno::Exception & ex )
837cdf0e10cSrcweir     {
838cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
839cdf0e10cSrcweir     }
840cdf0e10cSrcweir 
841cdf0e10cSrcweir     if( aRet.empty() )
842cdf0e10cSrcweir         aRet.push_back(xFallBack);
843cdf0e10cSrcweir 
844cdf0e10cSrcweir     return aRet;
845cdf0e10cSrcweir }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir } // anonymous namespace
848cdf0e10cSrcweir 
849cdf0e10cSrcweir bool DiagramHelper::isCategoryDiagram(
850cdf0e10cSrcweir             const Reference< XDiagram >& xDiagram )
851cdf0e10cSrcweir {
852cdf0e10cSrcweir     try
853cdf0e10cSrcweir     {
854cdf0e10cSrcweir         Reference< XCoordinateSystemContainer > xCooSysCnt(
855cdf0e10cSrcweir             xDiagram, uno::UNO_QUERY_THROW );
856cdf0e10cSrcweir         Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
857cdf0e10cSrcweir             xCooSysCnt->getCoordinateSystems());
858cdf0e10cSrcweir         for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
859cdf0e10cSrcweir         {
860cdf0e10cSrcweir             Reference< XCoordinateSystem > xCooSys( aCooSysSeq[i] );
861cdf0e10cSrcweir             OSL_ASSERT( xCooSys.is());
862cdf0e10cSrcweir             for( sal_Int32 nN = xCooSys->getDimension(); nN--; )
863cdf0e10cSrcweir             {
864cdf0e10cSrcweir                 const sal_Int32 nMaximumScaleIndex = xCooSys->getMaximumAxisIndexByDimension(nN);
865cdf0e10cSrcweir                 for(sal_Int32 nI=0; nI<=nMaximumScaleIndex; ++nI)
866cdf0e10cSrcweir                 {
867cdf0e10cSrcweir                     Reference< XAxis > xAxis = xCooSys->getAxisByDimension( nN,nI );
868cdf0e10cSrcweir                     OSL_ASSERT( xAxis.is());
869cdf0e10cSrcweir                     if( xAxis.is())
870cdf0e10cSrcweir                     {
871cdf0e10cSrcweir                         ScaleData aScaleData = xAxis->getScaleData();
872cdf0e10cSrcweir                         if( aScaleData.AxisType == AxisType::CATEGORY || aScaleData.AxisType == AxisType::DATE )
873cdf0e10cSrcweir                             return true;
874cdf0e10cSrcweir                     }
875cdf0e10cSrcweir                 }
876cdf0e10cSrcweir             }
877cdf0e10cSrcweir         }
878cdf0e10cSrcweir     }
879cdf0e10cSrcweir     catch( uno::Exception & ex )
880cdf0e10cSrcweir     {
881cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
882cdf0e10cSrcweir     }
883cdf0e10cSrcweir 
884cdf0e10cSrcweir     return false;
885cdf0e10cSrcweir }
886cdf0e10cSrcweir 
887cdf0e10cSrcweir void DiagramHelper::setCategoriesToDiagram(
888cdf0e10cSrcweir     const Reference< chart2::data::XLabeledDataSequence >& xCategories,
889cdf0e10cSrcweir     const Reference< XDiagram >& xDiagram,
890cdf0e10cSrcweir     bool bSetAxisType  /* = false */,
891cdf0e10cSrcweir     bool bCategoryAxis /* = true */ )
892cdf0e10cSrcweir {
893cdf0e10cSrcweir     std::vector< Reference< chart2::XAxis > > aCatAxes(
894cdf0e10cSrcweir         lcl_getAxisHoldingCategoriesFromDiagram( xDiagram ));
895cdf0e10cSrcweir 
896cdf0e10cSrcweir     std::vector< Reference< chart2::XAxis > >::iterator aIt( aCatAxes.begin() );
897cdf0e10cSrcweir     std::vector< Reference< chart2::XAxis > >::const_iterator aEnd( aCatAxes.end() );
898cdf0e10cSrcweir 
899cdf0e10cSrcweir     for( aIt = aCatAxes.begin(); aIt != aEnd; ++aIt )
900cdf0e10cSrcweir     {
901cdf0e10cSrcweir         Reference< chart2::XAxis > xCatAxis(*aIt);
902cdf0e10cSrcweir         if( xCatAxis.is())
903cdf0e10cSrcweir         {
904cdf0e10cSrcweir             ScaleData aScaleData( xCatAxis->getScaleData());
905cdf0e10cSrcweir             aScaleData.Categories = xCategories;
906cdf0e10cSrcweir             if( bSetAxisType )
907cdf0e10cSrcweir             {
908cdf0e10cSrcweir                 if( bCategoryAxis )
909cdf0e10cSrcweir                     aScaleData.AxisType = AxisType::CATEGORY;
910cdf0e10cSrcweir                 else if( aScaleData.AxisType == AxisType::CATEGORY || aScaleData.AxisType == AxisType::DATE )
911cdf0e10cSrcweir                     aScaleData.AxisType = AxisType::REALNUMBER;
912cdf0e10cSrcweir             }
913cdf0e10cSrcweir             xCatAxis->setScaleData( aScaleData );
914cdf0e10cSrcweir         }
915cdf0e10cSrcweir     }
916cdf0e10cSrcweir }
917cdf0e10cSrcweir 
918cdf0e10cSrcweir Reference< data::XLabeledDataSequence >
919cdf0e10cSrcweir     DiagramHelper::getCategoriesFromDiagram(
920cdf0e10cSrcweir         const Reference< XDiagram > & xDiagram )
921cdf0e10cSrcweir {
922cdf0e10cSrcweir     Reference< data::XLabeledDataSequence > xResult;
923cdf0e10cSrcweir 
924cdf0e10cSrcweir     try
925cdf0e10cSrcweir     {
926cdf0e10cSrcweir         std::vector< Reference< chart2::XAxis > > aCatAxes(
927cdf0e10cSrcweir             lcl_getAxisHoldingCategoriesFromDiagram( xDiagram ));
928cdf0e10cSrcweir         std::vector< Reference< chart2::XAxis > >::iterator aIt( aCatAxes.begin() );
929cdf0e10cSrcweir         std::vector< Reference< chart2::XAxis > >::const_iterator aEnd( aCatAxes.end() );
930cdf0e10cSrcweir         //search for first categories
931cdf0e10cSrcweir         if( aIt != aEnd )
932cdf0e10cSrcweir         {
933cdf0e10cSrcweir             Reference< chart2::XAxis > xCatAxis(*aIt);
934cdf0e10cSrcweir             if( xCatAxis.is())
935cdf0e10cSrcweir             {
936cdf0e10cSrcweir                 ScaleData aScaleData( xCatAxis->getScaleData());
937cdf0e10cSrcweir                 if( aScaleData.Categories.is() )
938cdf0e10cSrcweir                 {
939cdf0e10cSrcweir                     xResult.set( aScaleData.Categories );
940cdf0e10cSrcweir                     uno::Reference<beans::XPropertySet> xProp(aScaleData.Categories->getValues(), uno::UNO_QUERY );
941cdf0e10cSrcweir                     if( xProp.is() )
942cdf0e10cSrcweir                     {
943cdf0e10cSrcweir                         try
944cdf0e10cSrcweir                         {
945cdf0e10cSrcweir                             xProp->setPropertyValue( C2U( "Role" ), uno::makeAny( C2U("categories") ) );
946cdf0e10cSrcweir                         }
947cdf0e10cSrcweir                         catch( uno::Exception & ex )
948cdf0e10cSrcweir                         {
949cdf0e10cSrcweir                             ASSERT_EXCEPTION( ex );
950cdf0e10cSrcweir                         }
951cdf0e10cSrcweir                     }
952cdf0e10cSrcweir                 }
953cdf0e10cSrcweir             }
954cdf0e10cSrcweir         }
955cdf0e10cSrcweir     }
956cdf0e10cSrcweir     catch( uno::Exception & ex )
957cdf0e10cSrcweir     {
958cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
959cdf0e10cSrcweir     }
960cdf0e10cSrcweir 
961cdf0e10cSrcweir     return xResult;
962cdf0e10cSrcweir }
963cdf0e10cSrcweir 
964cdf0e10cSrcweir void lcl_generateAutomaticCategoriesFromChartType(
965cdf0e10cSrcweir             Sequence< rtl::OUString >& rRet,
966cdf0e10cSrcweir             const Reference< XChartType >& xChartType )
967cdf0e10cSrcweir {
968cdf0e10cSrcweir     if(!xChartType.is())
969cdf0e10cSrcweir         return;
970cdf0e10cSrcweir     rtl::OUString aMainSeq( xChartType->getRoleOfSequenceForSeriesLabel() );
971cdf0e10cSrcweir         Reference< XDataSeriesContainer > xSeriesCnt( xChartType, uno::UNO_QUERY );
972cdf0e10cSrcweir     if( xSeriesCnt.is() )
973cdf0e10cSrcweir     {
974cdf0e10cSrcweir         Sequence< Reference< XDataSeries > > aSeriesSeq( xSeriesCnt->getDataSeries() );
975cdf0e10cSrcweir         for( sal_Int32 nS = 0; nS < aSeriesSeq.getLength(); nS++ )
976cdf0e10cSrcweir         {
977cdf0e10cSrcweir             Reference< data::XDataSource > xDataSource( aSeriesSeq[nS], uno::UNO_QUERY );
978cdf0e10cSrcweir             if( !xDataSource.is() )
979cdf0e10cSrcweir                 continue;
980cdf0e10cSrcweir             Reference< chart2::data::XLabeledDataSequence > xLabeledSeq(
981cdf0e10cSrcweir                 ::chart::DataSeriesHelper::getDataSequenceByRole( xDataSource, aMainSeq ));
982cdf0e10cSrcweir             if( !xLabeledSeq.is() )
983cdf0e10cSrcweir                 continue;
984cdf0e10cSrcweir             Reference< chart2::data::XDataSequence > xValueSeq( xLabeledSeq->getValues() );
985cdf0e10cSrcweir             if( !xValueSeq.is() )
986cdf0e10cSrcweir                 continue;
987cdf0e10cSrcweir             rRet = xValueSeq->generateLabel( chart2::data::LabelOrigin_LONG_SIDE );
988cdf0e10cSrcweir             if( rRet.getLength() )
989cdf0e10cSrcweir                 return;
990cdf0e10cSrcweir         }
991cdf0e10cSrcweir     }
992cdf0e10cSrcweir }
993cdf0e10cSrcweir 
994cdf0e10cSrcweir Sequence< rtl::OUString > DiagramHelper::generateAutomaticCategoriesFromCooSys( const Reference< XCoordinateSystem > & xCooSys )
995cdf0e10cSrcweir {
996cdf0e10cSrcweir     Sequence< rtl::OUString > aRet;
997cdf0e10cSrcweir 
998cdf0e10cSrcweir     Reference< XChartTypeContainer > xTypeCntr( xCooSys, uno::UNO_QUERY );
999cdf0e10cSrcweir     if( xTypeCntr.is() )
1000cdf0e10cSrcweir     {
1001cdf0e10cSrcweir         Sequence< Reference< XChartType > > aChartTypes( xTypeCntr->getChartTypes() );
1002cdf0e10cSrcweir         for( sal_Int32 nN=0; nN<aChartTypes.getLength(); nN++ )
1003cdf0e10cSrcweir         {
1004cdf0e10cSrcweir             lcl_generateAutomaticCategoriesFromChartType( aRet, aChartTypes[nN] );
1005cdf0e10cSrcweir             if( aRet.getLength() )
1006cdf0e10cSrcweir                 return aRet;
1007cdf0e10cSrcweir         }
1008cdf0e10cSrcweir     }
1009cdf0e10cSrcweir     return aRet;
1010cdf0e10cSrcweir }
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir Sequence< rtl::OUString > DiagramHelper::getExplicitSimpleCategories(
1013cdf0e10cSrcweir             const Reference< XChartDocument >& xChartDoc )
1014cdf0e10cSrcweir {
1015cdf0e10cSrcweir     Sequence< rtl::OUString > aRet;
1016cdf0e10cSrcweir     uno::Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
1017cdf0e10cSrcweir     if(xChartModel.is())
1018cdf0e10cSrcweir     {
1019cdf0e10cSrcweir         uno::Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
1020cdf0e10cSrcweir         ExplicitCategoriesProvider aExplicitCategoriesProvider( xCooSys, xChartModel );
1021cdf0e10cSrcweir         aRet = aExplicitCategoriesProvider.getSimpleCategories();
1022cdf0e10cSrcweir     }
1023cdf0e10cSrcweir     return aRet;
1024cdf0e10cSrcweir }
1025cdf0e10cSrcweir 
1026cdf0e10cSrcweir namespace
1027cdf0e10cSrcweir {
1028cdf0e10cSrcweir void lcl_switchToDateCategories( const Reference< XChartDocument >& xChartDoc, const Reference< XAxis >& xAxis )
1029cdf0e10cSrcweir {
1030cdf0e10cSrcweir     if( !xAxis.is() )
1031cdf0e10cSrcweir         return;
1032cdf0e10cSrcweir     if( !xChartDoc.is() )
1033cdf0e10cSrcweir         return;
1034cdf0e10cSrcweir 
1035cdf0e10cSrcweir     ScaleData aScale( xAxis->getScaleData() );
1036cdf0e10cSrcweir     if( xChartDoc->hasInternalDataProvider() )
1037cdf0e10cSrcweir     {
1038cdf0e10cSrcweir         //remove all content the is not of type double and remove multiple level
1039cdf0e10cSrcweir         Reference< XAnyDescriptionAccess > xDataAccess( xChartDoc->getDataProvider(), uno::UNO_QUERY );
1040cdf0e10cSrcweir         if( xDataAccess.is() )
1041cdf0e10cSrcweir         {
1042cdf0e10cSrcweir             Sequence< Sequence< Any > > aAnyCategories( xDataAccess->getAnyRowDescriptions() );
1043cdf0e10cSrcweir             double fTest = 0.0;
1044cdf0e10cSrcweir             double fNan = 0.0;
1045cdf0e10cSrcweir             ::rtl::math::setNan( & fNan );
1046cdf0e10cSrcweir             sal_Int32 nN = aAnyCategories.getLength();
1047cdf0e10cSrcweir             for( ; nN--; )
1048cdf0e10cSrcweir             {
1049cdf0e10cSrcweir                 Sequence< Any >& rCat = aAnyCategories[nN];
1050cdf0e10cSrcweir                 if( rCat.getLength() > 1 )
1051cdf0e10cSrcweir                     rCat.realloc(1);
1052cdf0e10cSrcweir                 if( rCat.getLength() == 1 )
1053cdf0e10cSrcweir                 {
1054cdf0e10cSrcweir                     Any& rAny = rCat[0];
1055cdf0e10cSrcweir                     if( !(rAny>>=fTest) )
1056cdf0e10cSrcweir                     {
1057cdf0e10cSrcweir                         rAny = uno::makeAny(fNan);
1058cdf0e10cSrcweir                     }
1059cdf0e10cSrcweir                 }
1060cdf0e10cSrcweir             }
1061cdf0e10cSrcweir             xDataAccess->setAnyRowDescriptions( aAnyCategories );
1062cdf0e10cSrcweir         }
1063cdf0e10cSrcweir         //check the numberformat at the axis
1064cdf0e10cSrcweir         Reference< beans::XPropertySet > xAxisProps( xAxis, uno::UNO_QUERY );
1065cdf0e10cSrcweir         Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( xChartDoc, uno::UNO_QUERY );
1066cdf0e10cSrcweir         if( xAxisProps.is() && xNumberFormatsSupplier.is() )
1067cdf0e10cSrcweir         {
1068cdf0e10cSrcweir             sal_Int32 nNumberFormat = -1;
1069cdf0e10cSrcweir             xAxisProps->getPropertyValue( C2U("NumberFormat") ) >>= nNumberFormat;
1070cdf0e10cSrcweir 
1071cdf0e10cSrcweir             Reference< util::XNumberFormats > xNumberFormats = Reference< util::XNumberFormats >( xNumberFormatsSupplier->getNumberFormats() );
1072cdf0e10cSrcweir             if( xNumberFormats.is() )
1073cdf0e10cSrcweir             {
1074cdf0e10cSrcweir                 Reference< beans::XPropertySet > xKeyProps;
1075cdf0e10cSrcweir                 try
1076cdf0e10cSrcweir                 {
1077cdf0e10cSrcweir                     xKeyProps = xNumberFormats->getByKey( nNumberFormat );
1078cdf0e10cSrcweir                 }
1079cdf0e10cSrcweir                 catch( uno::Exception & ex )
1080cdf0e10cSrcweir                 {
1081cdf0e10cSrcweir                     ASSERT_EXCEPTION( ex );
1082cdf0e10cSrcweir                 }
1083cdf0e10cSrcweir                 sal_Int32 nType = util::NumberFormat::UNDEFINED;
1084cdf0e10cSrcweir                 if( xKeyProps.is() )
1085cdf0e10cSrcweir                     xKeyProps->getPropertyValue( C2U("Type") ) >>= nType;
1086cdf0e10cSrcweir                 if( !( nType & util::NumberFormat::DATE ) )
1087cdf0e10cSrcweir                 {
1088cdf0e10cSrcweir                     //set a date format to the axis
1089cdf0e10cSrcweir                     sal_Bool bCreate = sal_True;
1090cdf0e10cSrcweir                     const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
1091cdf0e10cSrcweir                     Sequence<sal_Int32> aKeySeq = xNumberFormats->queryKeys( util::NumberFormat::DATE,  rLocaleDataWrapper.getLocale(), bCreate );
1092cdf0e10cSrcweir                     if( aKeySeq.getLength() )
1093cdf0e10cSrcweir                     {
1094cdf0e10cSrcweir                         xAxisProps->setPropertyValue( C2U("NumberFormat"), uno::makeAny(aKeySeq[0]) );
1095cdf0e10cSrcweir                     }
1096cdf0e10cSrcweir                 }
1097cdf0e10cSrcweir             }
1098cdf0e10cSrcweir         }
1099cdf0e10cSrcweir     }
1100cdf0e10cSrcweir     if( aScale.AxisType != chart2::AxisType::DATE )
1101cdf0e10cSrcweir         AxisHelper::removeExplicitScaling( aScale );
1102cdf0e10cSrcweir     aScale.AxisType = chart2::AxisType::DATE;
1103cdf0e10cSrcweir     xAxis->setScaleData( aScale );
1104cdf0e10cSrcweir }
1105cdf0e10cSrcweir 
1106cdf0e10cSrcweir void lcl_switchToTextCategories( const Reference< XChartDocument >& xChartDoc, const Reference< XAxis >& xAxis )
1107cdf0e10cSrcweir {
1108cdf0e10cSrcweir     if( !xAxis.is() )
1109cdf0e10cSrcweir         return;
1110cdf0e10cSrcweir     if( !xChartDoc.is() )
1111cdf0e10cSrcweir         return;
1112cdf0e10cSrcweir     ScaleData aScale( xAxis->getScaleData() );
1113cdf0e10cSrcweir     if( aScale.AxisType != chart2::AxisType::CATEGORY )
1114cdf0e10cSrcweir         AxisHelper::removeExplicitScaling( aScale );
1115cdf0e10cSrcweir     //todo migrate dates to text?
1116cdf0e10cSrcweir     aScale.AxisType = chart2::AxisType::CATEGORY;
1117cdf0e10cSrcweir     aScale.AutoDateAxis = false;
1118cdf0e10cSrcweir     xAxis->setScaleData( aScale );
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir 
1121cdf0e10cSrcweir }
1122cdf0e10cSrcweir 
1123cdf0e10cSrcweir void DiagramHelper::switchToDateCategories( const Reference< XChartDocument >& xChartDoc )
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir     Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
1126cdf0e10cSrcweir     if(xChartModel.is())
1127cdf0e10cSrcweir     {
1128cdf0e10cSrcweir         ControllerLockGuard aCtrlLockGuard( xChartModel );
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir         Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
1131cdf0e10cSrcweir         if( xCooSys.is() )
1132cdf0e10cSrcweir         {
1133cdf0e10cSrcweir             Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,0) );
1134cdf0e10cSrcweir             lcl_switchToDateCategories( xChartDoc, xAxis );
1135cdf0e10cSrcweir         }
1136cdf0e10cSrcweir     }
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir void DiagramHelper::switchToTextCategories( const Reference< XChartDocument >& xChartDoc )
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir     Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
1142cdf0e10cSrcweir     if(xChartModel.is())
1143cdf0e10cSrcweir     {
1144cdf0e10cSrcweir         ControllerLockGuard aCtrlLockGuard( xChartModel );
1145cdf0e10cSrcweir 
1146cdf0e10cSrcweir         Reference< chart2::XCoordinateSystem > xCooSys( ChartModelHelper::getFirstCoordinateSystem( xChartModel ) );
1147cdf0e10cSrcweir         if( xCooSys.is() )
1148cdf0e10cSrcweir         {
1149cdf0e10cSrcweir             Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,0) );
1150cdf0e10cSrcweir             lcl_switchToTextCategories( xChartDoc, xAxis );
1151cdf0e10cSrcweir         }
1152cdf0e10cSrcweir     }
1153cdf0e10cSrcweir }
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir bool DiagramHelper::isSupportingDateAxis( const Reference< chart2::XDiagram >& xDiagram )
1156cdf0e10cSrcweir {
1157cdf0e10cSrcweir     return ::chart::ChartTypeHelper::isSupportingDateAxis(
1158cdf0e10cSrcweir             DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), DiagramHelper::getDimension( xDiagram ), 0 );
1159cdf0e10cSrcweir }
1160cdf0e10cSrcweir 
1161cdf0e10cSrcweir bool DiagramHelper::isDateNumberFormat( sal_Int32 nNumberFormat, const Reference< util::XNumberFormats >& xNumberFormats )
1162cdf0e10cSrcweir {
1163cdf0e10cSrcweir     bool bIsDate = false;
1164cdf0e10cSrcweir     if( !xNumberFormats.is() )
1165cdf0e10cSrcweir         return bIsDate;
1166cdf0e10cSrcweir 
1167cdf0e10cSrcweir     Reference< beans::XPropertySet > xKeyProps = xNumberFormats->getByKey( nNumberFormat );
1168cdf0e10cSrcweir     if( xKeyProps.is() )
1169cdf0e10cSrcweir     {
1170cdf0e10cSrcweir         sal_Int32 nType = util::NumberFormat::UNDEFINED;
1171cdf0e10cSrcweir         xKeyProps->getPropertyValue( C2U("Type") ) >>= nType;
1172cdf0e10cSrcweir         bIsDate = nType & util::NumberFormat::DATE;
1173cdf0e10cSrcweir     }
1174cdf0e10cSrcweir     return bIsDate;
1175cdf0e10cSrcweir }
1176cdf0e10cSrcweir 
1177cdf0e10cSrcweir sal_Int32 DiagramHelper::getDateNumberFormat( const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier )
1178cdf0e10cSrcweir {
1179cdf0e10cSrcweir     sal_Int32 nRet=-1;
1180cdf0e10cSrcweir     Reference< util::XNumberFormats > xNumberFormats( xNumberFormatsSupplier->getNumberFormats() );
1181cdf0e10cSrcweir     if( xNumberFormats.is() )
1182cdf0e10cSrcweir     {
1183cdf0e10cSrcweir         sal_Bool bCreate = sal_True;
1184cdf0e10cSrcweir         const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
1185cdf0e10cSrcweir         Sequence<sal_Int32> aKeySeq = xNumberFormats->queryKeys( util::NumberFormat::DATE,
1186cdf0e10cSrcweir 			rLocaleDataWrapper.getLocale(), bCreate );
1187cdf0e10cSrcweir         if( aKeySeq.getLength() )
1188cdf0e10cSrcweir         {
1189cdf0e10cSrcweir             nRet = aKeySeq[0];
1190cdf0e10cSrcweir         }
1191cdf0e10cSrcweir     }
1192cdf0e10cSrcweir 
1193cdf0e10cSrcweir     //try to get a date format with full year display
1194cdf0e10cSrcweir     NumberFormatterWrapper aNumberFormatterWrapper( xNumberFormatsSupplier );
1195cdf0e10cSrcweir     SvNumberFormatter* pNumFormatter = aNumberFormatterWrapper.getSvNumberFormatter();
1196cdf0e10cSrcweir     if( pNumFormatter )
1197cdf0e10cSrcweir     {
1198cdf0e10cSrcweir         const SvNumberformat* pFormat = pNumFormatter->GetEntry( nRet );
1199cdf0e10cSrcweir         if( pFormat )
1200cdf0e10cSrcweir             nRet = pNumFormatter->GetFormatIndex( NF_DATE_SYS_DDMMYYYY, pFormat->GetLanguage() );
1201cdf0e10cSrcweir     }
1202cdf0e10cSrcweir     return nRet;
1203cdf0e10cSrcweir }
1204cdf0e10cSrcweir 
1205cdf0e10cSrcweir sal_Int32 DiagramHelper::getPercentNumberFormat( const Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier )
1206cdf0e10cSrcweir {
1207cdf0e10cSrcweir     sal_Int32 nRet=-1;
1208cdf0e10cSrcweir     Reference< util::XNumberFormats > xNumberFormats( xNumberFormatsSupplier->getNumberFormats() );
1209cdf0e10cSrcweir     if( xNumberFormats.is() )
1210cdf0e10cSrcweir     {
1211cdf0e10cSrcweir         sal_Bool bCreate = sal_True;
1212cdf0e10cSrcweir         const LocaleDataWrapper& rLocaleDataWrapper = Application::GetSettings().GetLocaleDataWrapper();
1213cdf0e10cSrcweir         Sequence<sal_Int32> aKeySeq = xNumberFormats->queryKeys( util::NumberFormat::PERCENT,
1214cdf0e10cSrcweir 			rLocaleDataWrapper.getLocale(), bCreate );
1215cdf0e10cSrcweir         if( aKeySeq.getLength() )
1216cdf0e10cSrcweir         {
1217cdf0e10cSrcweir             nRet = aKeySeq[0];
1218cdf0e10cSrcweir         }
1219cdf0e10cSrcweir     }
1220cdf0e10cSrcweir     return nRet;
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir Sequence< Reference< XChartType > >
1224cdf0e10cSrcweir     DiagramHelper::getChartTypesFromDiagram(
1225cdf0e10cSrcweir         const Reference< XDiagram > & xDiagram )
1226cdf0e10cSrcweir {
1227cdf0e10cSrcweir     ::std::vector< Reference< XChartType > > aResult;
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir     if(xDiagram.is())
1230cdf0e10cSrcweir     try
1231cdf0e10cSrcweir     {
1232cdf0e10cSrcweir         Reference< XCoordinateSystemContainer > xCooSysCnt(
1233cdf0e10cSrcweir             xDiagram, uno::UNO_QUERY_THROW );
1234cdf0e10cSrcweir         Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
1235cdf0e10cSrcweir             xCooSysCnt->getCoordinateSystems());
1236cdf0e10cSrcweir         for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
1237cdf0e10cSrcweir         {
1238cdf0e10cSrcweir             Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW );
1239cdf0e10cSrcweir             Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
1240cdf0e10cSrcweir             ::std::copy( aChartTypeSeq.getConstArray(), aChartTypeSeq.getConstArray() + aChartTypeSeq.getLength(),
1241cdf0e10cSrcweir                          ::std::back_inserter( aResult ));
1242cdf0e10cSrcweir         }
1243cdf0e10cSrcweir     }
1244cdf0e10cSrcweir     catch( uno::Exception & ex )
1245cdf0e10cSrcweir     {
1246cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
1247cdf0e10cSrcweir     }
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir     return ContainerHelper::ContainerToSequence( aResult );
1250cdf0e10cSrcweir }
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir bool DiagramHelper::areChartTypesCompatible( const Reference< ::chart2::XChartType >& xFirstType,
1253cdf0e10cSrcweir                 const Reference< ::chart2::XChartType >& xSecondType )
1254cdf0e10cSrcweir {
1255cdf0e10cSrcweir     if( !xFirstType.is() || !xSecondType.is() )
1256cdf0e10cSrcweir         return false;
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir     ::std::vector< ::rtl::OUString > aFirstRoles( ContainerHelper::SequenceToVector( xFirstType->getSupportedMandatoryRoles() ) );
1259cdf0e10cSrcweir     ::std::vector< ::rtl::OUString > aSecondRoles( ContainerHelper::SequenceToVector( xSecondType->getSupportedMandatoryRoles() ) );
1260cdf0e10cSrcweir     ::std::sort( aFirstRoles.begin(), aFirstRoles.end() );
1261cdf0e10cSrcweir     ::std::sort( aSecondRoles.begin(), aSecondRoles.end() );
1262cdf0e10cSrcweir     return ( aFirstRoles == aSecondRoles );
1263cdf0e10cSrcweir }
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir namespace
1266cdf0e10cSrcweir {
1267cdf0e10cSrcweir      /**
1268cdf0e10cSrcweir      * This method implements the logic of checking if a series can be moved
1269cdf0e10cSrcweir      * forward/backward. Depending on the "bDoMove" parameter the series will
1270cdf0e10cSrcweir      * be moved (bDoMove = true) or the function just will test if the
1271cdf0e10cSrcweir      * series can be moved without doing the move (bDoMove = false).
1272cdf0e10cSrcweir      *
1273cdf0e10cSrcweir      * @param xDiagram
1274cdf0e10cSrcweir      *  Reference to the diagram that contains the series.
1275cdf0e10cSrcweir      *
1276cdf0e10cSrcweir      * @param xGivenDataSeries
1277cdf0e10cSrcweir      *  Reference to the series that should moved or tested for moving.
1278cdf0e10cSrcweir      *
1279cdf0e10cSrcweir      * @param bForward
1280cdf0e10cSrcweir      *  Direction in which the series should be moved or tested for moving.
1281cdf0e10cSrcweir      *
1282cdf0e10cSrcweir      * @param bDoMove
1283cdf0e10cSrcweir      *  Should this function really move the series (true) or just test if it is
1284cdf0e10cSrcweir      *  possible (false).
1285cdf0e10cSrcweir      *
1286cdf0e10cSrcweir      *
1287cdf0e10cSrcweir      * @returns
1288cdf0e10cSrcweir      *  in case of bDoMove == true
1289cdf0e10cSrcweir      *      - True : if the move was done
1290cdf0e10cSrcweir      *      - False : the move failed
1291cdf0e10cSrcweir      *  in case of bDoMove == false
1292cdf0e10cSrcweir      *      - True : the series can be moved
1293cdf0e10cSrcweir      *      - False : the series can not be moved
1294cdf0e10cSrcweir      *
1295cdf0e10cSrcweir      */
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir bool lcl_moveSeriesOrCheckIfMoveIsAllowed(
1298cdf0e10cSrcweir     const Reference< XDiagram >& xDiagram,
1299cdf0e10cSrcweir     const Reference< XDataSeries >& xGivenDataSeries,
1300cdf0e10cSrcweir     bool bForward,
1301cdf0e10cSrcweir     bool bDoMove )
1302cdf0e10cSrcweir {
1303cdf0e10cSrcweir     bool bMovedOrMoveAllowed = false;
1304cdf0e10cSrcweir 
1305cdf0e10cSrcweir     try
1306cdf0e10cSrcweir     {
1307cdf0e10cSrcweir         uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY );
1308cdf0e10cSrcweir 
1309cdf0e10cSrcweir         //find position of series.
1310cdf0e10cSrcweir         bool bFound = false;
1311cdf0e10cSrcweir 
1312cdf0e10cSrcweir         if( xGivenDataSeries.is() && xCooSysContainer.is() )
1313cdf0e10cSrcweir         {
1314cdf0e10cSrcweir             uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() );
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir             for( sal_Int32 nCS = 0; !bFound && nCS < aCooSysList.getLength(); ++nCS )
1317cdf0e10cSrcweir             {
1318cdf0e10cSrcweir                 uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] );
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir                 //iterate through all chart types in the current coordinate system
1321cdf0e10cSrcweir                 uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY );
1322cdf0e10cSrcweir                 OSL_ASSERT( xChartTypeContainer.is());
1323cdf0e10cSrcweir                 if( !xChartTypeContainer.is() )
1324cdf0e10cSrcweir                     continue;
1325cdf0e10cSrcweir                 uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() );
1326cdf0e10cSrcweir                 uno::Reference< XChartType > xFormerChartType;
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir                 for( sal_Int32 nT = 0; !bFound && nT < aChartTypeList.getLength(); ++nT )
1329cdf0e10cSrcweir                 {
1330cdf0e10cSrcweir                     uno::Reference< XChartType > xCurrentChartType( aChartTypeList[nT] );
1331cdf0e10cSrcweir 
1332cdf0e10cSrcweir                     //iterate through all series in this chart type
1333cdf0e10cSrcweir                     uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xCurrentChartType, uno::UNO_QUERY );
1334cdf0e10cSrcweir                     OSL_ASSERT( xDataSeriesContainer.is());
1335cdf0e10cSrcweir                     if( !xDataSeriesContainer.is() )
1336cdf0e10cSrcweir                         continue;
1337cdf0e10cSrcweir 
1338cdf0e10cSrcweir                     uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() );
1339cdf0e10cSrcweir 
1340cdf0e10cSrcweir                     for( sal_Int32 nS = 0; !bFound && nS < aSeriesList.getLength(); ++nS )
1341cdf0e10cSrcweir                     {
1342cdf0e10cSrcweir 
1343cdf0e10cSrcweir                         // We found the series we are interrested in !
1344cdf0e10cSrcweir                         if( xGivenDataSeries==aSeriesList[nS] )
1345cdf0e10cSrcweir                         {
1346cdf0e10cSrcweir                             sal_Int32 nOldSeriesIndex = nS;
1347cdf0e10cSrcweir                             bFound = true;
1348cdf0e10cSrcweir 
1349cdf0e10cSrcweir                             try
1350cdf0e10cSrcweir                             {
1351cdf0e10cSrcweir                                 sal_Int32 nNewSeriesIndex = nS;
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir                                 if( bForward )
1354cdf0e10cSrcweir                                     nNewSeriesIndex--;
1355cdf0e10cSrcweir                                 else
1356cdf0e10cSrcweir                                     nNewSeriesIndex++;
1357cdf0e10cSrcweir 
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir                                 if( nNewSeriesIndex >= 0 && nNewSeriesIndex < aSeriesList.getLength() )
1360cdf0e10cSrcweir                                 {
1361cdf0e10cSrcweir                                     //move series in the same charttype
1362cdf0e10cSrcweir                                     bMovedOrMoveAllowed = true;
1363cdf0e10cSrcweir                                     if( bDoMove )
1364cdf0e10cSrcweir                                     {
1365cdf0e10cSrcweir                                         aSeriesList[ nOldSeriesIndex ] = aSeriesList[ nNewSeriesIndex ];
1366cdf0e10cSrcweir                                         aSeriesList[ nNewSeriesIndex ] = xGivenDataSeries;
1367cdf0e10cSrcweir                                         xDataSeriesContainer->setDataSeries( aSeriesList );
1368cdf0e10cSrcweir                                     }
1369cdf0e10cSrcweir                                 }
1370cdf0e10cSrcweir                                 else if( nNewSeriesIndex<0 )
1371cdf0e10cSrcweir                                 {
1372cdf0e10cSrcweir                                     //exchange series with former charttype
1373cdf0e10cSrcweir                                     if( xFormerChartType.is() && DiagramHelper::areChartTypesCompatible( xFormerChartType, xCurrentChartType ) )
1374cdf0e10cSrcweir                                     {
1375cdf0e10cSrcweir                                         bMovedOrMoveAllowed = true;
1376cdf0e10cSrcweir                                         if( bDoMove )
1377cdf0e10cSrcweir                                         {
1378cdf0e10cSrcweir                                             uno::Reference< XDataSeriesContainer > xOtherDataSeriesContainer( xFormerChartType, uno::UNO_QUERY );
1379cdf0e10cSrcweir                                             if( xOtherDataSeriesContainer.is() )
1380cdf0e10cSrcweir                                             {
1381cdf0e10cSrcweir                                                 uno::Sequence< uno::Reference< XDataSeries > > aOtherSeriesList( xOtherDataSeriesContainer->getDataSeries() );
1382cdf0e10cSrcweir                                                 sal_Int32 nOtherSeriesIndex = aOtherSeriesList.getLength()-1;
1383cdf0e10cSrcweir                                                 if( nOtherSeriesIndex >= 0 && nOtherSeriesIndex < aOtherSeriesList.getLength() )
1384cdf0e10cSrcweir                                                 {
1385cdf0e10cSrcweir                                                     uno::Reference< XDataSeries > xExchangeSeries( aOtherSeriesList[nOtherSeriesIndex] );
1386cdf0e10cSrcweir                                                     aOtherSeriesList[nOtherSeriesIndex] = xGivenDataSeries;
1387cdf0e10cSrcweir                                                     xOtherDataSeriesContainer->setDataSeries(aOtherSeriesList);
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir                                                     aSeriesList[nOldSeriesIndex]=xExchangeSeries;
1390cdf0e10cSrcweir                                                     xDataSeriesContainer->setDataSeries(aSeriesList);
1391cdf0e10cSrcweir                                                 }
1392cdf0e10cSrcweir                                             }
1393cdf0e10cSrcweir                                         }
1394cdf0e10cSrcweir                                     }
1395cdf0e10cSrcweir                                 }
1396cdf0e10cSrcweir                                 else if( nT+1 < aChartTypeList.getLength() )
1397cdf0e10cSrcweir                                 {
1398cdf0e10cSrcweir                                     //exchange series with next charttype
1399cdf0e10cSrcweir                                     uno::Reference< XChartType > xOtherChartType( aChartTypeList[nT+1] );
1400cdf0e10cSrcweir                                     if( xOtherChartType.is() && DiagramHelper::areChartTypesCompatible( xOtherChartType, xCurrentChartType ) )
1401cdf0e10cSrcweir                                     {
1402cdf0e10cSrcweir                                         bMovedOrMoveAllowed = true;
1403cdf0e10cSrcweir                                         if( bDoMove )
1404cdf0e10cSrcweir                                         {
1405cdf0e10cSrcweir                                             uno::Reference< XDataSeriesContainer > xOtherDataSeriesContainer( xOtherChartType, uno::UNO_QUERY );
1406cdf0e10cSrcweir                                             if( xOtherDataSeriesContainer.is() )
1407cdf0e10cSrcweir                                             {
1408cdf0e10cSrcweir                                                 uno::Sequence< uno::Reference< XDataSeries > > aOtherSeriesList( xOtherDataSeriesContainer->getDataSeries() );
1409cdf0e10cSrcweir                                                 sal_Int32 nOtherSeriesIndex = 0;
1410cdf0e10cSrcweir                                                 if( nOtherSeriesIndex >= 0 && nOtherSeriesIndex < aOtherSeriesList.getLength() )
1411cdf0e10cSrcweir                                                 {
1412cdf0e10cSrcweir                                                     uno::Reference< XDataSeries > xExchangeSeries( aOtherSeriesList[nOtherSeriesIndex] );
1413cdf0e10cSrcweir                                                     aOtherSeriesList[nOtherSeriesIndex] = xGivenDataSeries;
1414cdf0e10cSrcweir                                                     xOtherDataSeriesContainer->setDataSeries(aOtherSeriesList);
1415cdf0e10cSrcweir 
1416cdf0e10cSrcweir                                                     aSeriesList[nOldSeriesIndex]=xExchangeSeries;
1417cdf0e10cSrcweir                                                     xDataSeriesContainer->setDataSeries(aSeriesList);
1418cdf0e10cSrcweir                                                 }
1419cdf0e10cSrcweir                                             }
1420cdf0e10cSrcweir                                         }
1421cdf0e10cSrcweir                                     }
1422cdf0e10cSrcweir                                 }
1423cdf0e10cSrcweir                             }
1424cdf0e10cSrcweir                             catch( util::CloseVetoException& )
1425cdf0e10cSrcweir                             {
1426cdf0e10cSrcweir                             }
1427cdf0e10cSrcweir                             catch( uno::RuntimeException& )
1428cdf0e10cSrcweir                             {
1429cdf0e10cSrcweir                             }
1430cdf0e10cSrcweir                         }
1431cdf0e10cSrcweir                     }
1432cdf0e10cSrcweir                     xFormerChartType = xCurrentChartType;
1433cdf0e10cSrcweir                 }
1434cdf0e10cSrcweir             }
1435cdf0e10cSrcweir         }
1436cdf0e10cSrcweir     }
1437cdf0e10cSrcweir     catch( util::CloseVetoException& )
1438cdf0e10cSrcweir     {
1439cdf0e10cSrcweir     }
1440cdf0e10cSrcweir     catch( uno::RuntimeException& )
1441cdf0e10cSrcweir     {
1442cdf0e10cSrcweir     }
1443cdf0e10cSrcweir     return bMovedOrMoveAllowed;
1444cdf0e10cSrcweir }
1445cdf0e10cSrcweir } // anonymous namespace
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir 
1448cdf0e10cSrcweir bool DiagramHelper::isSeriesMoveable(
1449cdf0e10cSrcweir     const Reference< XDiagram >& xDiagram,
1450cdf0e10cSrcweir     const Reference< XDataSeries >& xGivenDataSeries,
1451cdf0e10cSrcweir     bool bForward )
1452cdf0e10cSrcweir {
1453cdf0e10cSrcweir     bool bIsMoveable = false;
1454cdf0e10cSrcweir     const bool bDoMove = false;
1455cdf0e10cSrcweir 
1456cdf0e10cSrcweir     bIsMoveable = lcl_moveSeriesOrCheckIfMoveIsAllowed(
1457cdf0e10cSrcweir         xDiagram, xGivenDataSeries, bForward, bDoMove );
1458cdf0e10cSrcweir 
1459cdf0e10cSrcweir     return bIsMoveable;
1460cdf0e10cSrcweir }
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir 
1463cdf0e10cSrcweir bool DiagramHelper::moveSeries( const Reference< XDiagram >& xDiagram, const Reference< XDataSeries >& xGivenDataSeries, bool bForward )
1464cdf0e10cSrcweir {
1465cdf0e10cSrcweir     bool bMoved = false;
1466cdf0e10cSrcweir     const bool bDoMove = true;
1467cdf0e10cSrcweir 
1468cdf0e10cSrcweir     bMoved = lcl_moveSeriesOrCheckIfMoveIsAllowed(
1469cdf0e10cSrcweir         xDiagram, xGivenDataSeries, bForward, bDoMove );
1470cdf0e10cSrcweir 
1471cdf0e10cSrcweir     return bMoved;
1472cdf0e10cSrcweir }
1473cdf0e10cSrcweir 
1474cdf0e10cSrcweir bool DiagramHelper::isSupportingFloorAndWall( const Reference<
1475cdf0e10cSrcweir                 chart2::XDiagram >& xDiagram )
1476cdf0e10cSrcweir {
1477cdf0e10cSrcweir     //pies and donuts currently do not support this because of wrong files from older versions
1478cdf0e10cSrcweir     //todo: allow this in future again, if fileversion are available for ole objects (metastream)
1479cdf0e10cSrcweir     //thus the wrong bottom can be removed on import
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir     Sequence< Reference< chart2::XChartType > > aTypes(
1482cdf0e10cSrcweir             ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
1483cdf0e10cSrcweir     for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
1484cdf0e10cSrcweir     {
1485cdf0e10cSrcweir         Reference< chart2::XChartType > xType( aTypes[nN] );
1486cdf0e10cSrcweir         if( xType.is() && xType->getChartType().match(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
1487cdf0e10cSrcweir             return false;
1488cdf0e10cSrcweir         if( xType.is() && xType->getChartType().match(CHART2_SERVICE_NAME_CHARTTYPE_NET) )
1489cdf0e10cSrcweir             return false;
1490cdf0e10cSrcweir         if( xType.is() && xType->getChartType().match(CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET) )
1491cdf0e10cSrcweir             return false;
1492cdf0e10cSrcweir     }
1493cdf0e10cSrcweir     return true;
1494cdf0e10cSrcweir }
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir bool DiagramHelper::isPieOrDonutChart( const ::com::sun::star::uno::Reference<
1497cdf0e10cSrcweir                 ::com::sun::star::chart2::XDiagram >& xDiagram )
1498cdf0e10cSrcweir {
1499cdf0e10cSrcweir     uno::Reference< chart2::XChartType > xChartType( DiagramHelper::getChartTypeByIndex(
1500cdf0e10cSrcweir         xDiagram, 0 ) );
1501cdf0e10cSrcweir 
1502cdf0e10cSrcweir     if( xChartType .is() )
1503cdf0e10cSrcweir     {
1504cdf0e10cSrcweir         rtl::OUString aChartType = xChartType->getChartType();
1505cdf0e10cSrcweir         if( aChartType.equals(CHART2_SERVICE_NAME_CHARTTYPE_PIE) )
1506cdf0e10cSrcweir             return true;
1507cdf0e10cSrcweir     }
1508cdf0e10cSrcweir     return false;
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir 
1511cdf0e10cSrcweir sal_Int32 DiagramHelper::getGeometry3D(
1512cdf0e10cSrcweir     const uno::Reference< chart2::XDiagram > & xDiagram,
1513cdf0e10cSrcweir     bool& rbFound, bool& rbAmbiguous )
1514cdf0e10cSrcweir {
1515cdf0e10cSrcweir     sal_Int32 nCommonGeom( DataPointGeometry3D::CUBOID );
1516cdf0e10cSrcweir     rbFound = false;
1517cdf0e10cSrcweir     rbAmbiguous = false;
1518cdf0e10cSrcweir 
1519cdf0e10cSrcweir     ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
1520cdf0e10cSrcweir         DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
1521cdf0e10cSrcweir 
1522cdf0e10cSrcweir     if( aSeriesVec.empty())
1523cdf0e10cSrcweir         rbAmbiguous = true;
1524cdf0e10cSrcweir 
1525cdf0e10cSrcweir     for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
1526cdf0e10cSrcweir              aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
1527cdf0e10cSrcweir     {
1528cdf0e10cSrcweir         try
1529cdf0e10cSrcweir         {
1530cdf0e10cSrcweir             sal_Int32 nGeom = 0;
1531cdf0e10cSrcweir             Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
1532cdf0e10cSrcweir             if( xProp->getPropertyValue( C2U( "Geometry3D" )) >>= nGeom )
1533cdf0e10cSrcweir             {
1534cdf0e10cSrcweir                 if( ! rbFound )
1535cdf0e10cSrcweir                 {
1536cdf0e10cSrcweir                     // first series
1537cdf0e10cSrcweir                     nCommonGeom = nGeom;
1538cdf0e10cSrcweir                     rbFound = true;
1539cdf0e10cSrcweir                 }
1540cdf0e10cSrcweir                 // further series: compare for uniqueness
1541cdf0e10cSrcweir                 else if( nCommonGeom != nGeom )
1542cdf0e10cSrcweir                 {
1543cdf0e10cSrcweir                     rbAmbiguous = true;
1544cdf0e10cSrcweir                     break;
1545cdf0e10cSrcweir                 }
1546cdf0e10cSrcweir             }
1547cdf0e10cSrcweir         }
1548cdf0e10cSrcweir         catch( uno::Exception & ex )
1549cdf0e10cSrcweir         {
1550cdf0e10cSrcweir             ASSERT_EXCEPTION( ex );
1551cdf0e10cSrcweir         }
1552cdf0e10cSrcweir     }
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir     return nCommonGeom;
1555cdf0e10cSrcweir }
1556cdf0e10cSrcweir 
1557cdf0e10cSrcweir void DiagramHelper::setGeometry3D(
1558cdf0e10cSrcweir     const Reference< chart2::XDiagram > & xDiagram,
1559cdf0e10cSrcweir     sal_Int32 nNewGeometry )
1560cdf0e10cSrcweir {
1561cdf0e10cSrcweir     ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
1562cdf0e10cSrcweir         DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir     for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
1565cdf0e10cSrcweir              aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
1566cdf0e10cSrcweir     {
1567cdf0e10cSrcweir         DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints(
1568cdf0e10cSrcweir             *aIt, C2U( "Geometry3D" ), uno::makeAny( nNewGeometry ));
1569cdf0e10cSrcweir     }
1570cdf0e10cSrcweir }
1571cdf0e10cSrcweir 
1572cdf0e10cSrcweir sal_Int32 DiagramHelper::getCorrectedMissingValueTreatment(
1573cdf0e10cSrcweir             const Reference< chart2::XDiagram > & xDiagram,
1574cdf0e10cSrcweir             const Reference< chart2::XChartType >& xChartType )
1575cdf0e10cSrcweir {
1576cdf0e10cSrcweir     sal_Int32 nResult = ::com::sun::star::chart::MissingValueTreatment::LEAVE_GAP;
1577cdf0e10cSrcweir     uno::Sequence < sal_Int32 > aAvailableMissingValueTreatments(
1578cdf0e10cSrcweir                 ChartTypeHelper::getSupportedMissingValueTreatments( xChartType ) );
1579cdf0e10cSrcweir 
1580cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY );
1581cdf0e10cSrcweir     if( xDiaProp.is() && (xDiaProp->getPropertyValue( C2U( "MissingValueTreatment" ) ) >>= nResult) )
1582cdf0e10cSrcweir     {
1583cdf0e10cSrcweir         //ensure that the set value is supported by this charttype
1584cdf0e10cSrcweir         for( sal_Int32 nN = 0; nN < aAvailableMissingValueTreatments.getLength(); nN++ )
1585cdf0e10cSrcweir             if( aAvailableMissingValueTreatments[nN] == nResult )
1586cdf0e10cSrcweir                 return nResult; //ok
1587cdf0e10cSrcweir     }
1588cdf0e10cSrcweir 
1589cdf0e10cSrcweir     //otherwise use the first supported one
1590cdf0e10cSrcweir     if( aAvailableMissingValueTreatments.getLength() )
1591cdf0e10cSrcweir     {
1592cdf0e10cSrcweir         nResult = aAvailableMissingValueTreatments[0];
1593cdf0e10cSrcweir         return nResult;
1594cdf0e10cSrcweir     }
1595cdf0e10cSrcweir 
1596cdf0e10cSrcweir     return nResult;
1597cdf0e10cSrcweir }
1598cdf0e10cSrcweir 
1599cdf0e10cSrcweir DiagramPositioningMode DiagramHelper::getDiagramPositioningMode( const uno::Reference<
1600cdf0e10cSrcweir                 chart2::XDiagram > & xDiagram )
1601cdf0e10cSrcweir {
1602cdf0e10cSrcweir     DiagramPositioningMode eMode = DiagramPositioningMode_AUTO;
1603cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xDiaProps( xDiagram, uno::UNO_QUERY );
1604cdf0e10cSrcweir     if( xDiaProps.is() )
1605cdf0e10cSrcweir     {
1606cdf0e10cSrcweir         RelativePosition aRelPos;
1607cdf0e10cSrcweir         RelativeSize aRelSize;
1608cdf0e10cSrcweir         if( (xDiaProps->getPropertyValue(C2U("RelativePosition")) >>= aRelPos ) &&
1609cdf0e10cSrcweir             (xDiaProps->getPropertyValue(C2U("RelativeSize")) >>= aRelSize ) )
1610cdf0e10cSrcweir         {
1611cdf0e10cSrcweir             bool bPosSizeExcludeAxes=false;
1612cdf0e10cSrcweir             xDiaProps->getPropertyValue(C2U("PosSizeExcludeAxes")) >>= bPosSizeExcludeAxes;
1613cdf0e10cSrcweir             if( bPosSizeExcludeAxes )
1614cdf0e10cSrcweir                 eMode = DiagramPositioningMode_EXCLUDING;
1615cdf0e10cSrcweir             else
1616cdf0e10cSrcweir                 eMode = DiagramPositioningMode_INCLUDING;
1617cdf0e10cSrcweir         }
1618cdf0e10cSrcweir     }
1619cdf0e10cSrcweir     return eMode;
1620cdf0e10cSrcweir }
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir void lcl_ensureRange0to1( double& rValue )
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir     if(rValue<0.0)
1625cdf0e10cSrcweir         rValue=0.0;
1626cdf0e10cSrcweir     if(rValue>1.0)
1627cdf0e10cSrcweir         rValue=1.0;
1628cdf0e10cSrcweir }
1629cdf0e10cSrcweir 
1630cdf0e10cSrcweir bool DiagramHelper::setDiagramPositioning( const uno::Reference< frame::XModel >& xChartModel,
1631cdf0e10cSrcweir         const awt::Rectangle& rPosRect /*100th mm*/ )
1632cdf0e10cSrcweir {
1633cdf0e10cSrcweir     ControllerLockGuard aCtrlLockGuard( xChartModel );
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir     bool bChanged = false;
1636cdf0e10cSrcweir     awt::Size aPageSize( ChartModelHelper::getPageSize(xChartModel) );
1637cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xDiaProps( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY );
1638cdf0e10cSrcweir     if( !xDiaProps.is() )
1639cdf0e10cSrcweir         return bChanged;
1640cdf0e10cSrcweir 
1641cdf0e10cSrcweir     RelativePosition aOldPos;
1642cdf0e10cSrcweir     RelativeSize aOldSize;
1643cdf0e10cSrcweir     xDiaProps->getPropertyValue(C2U("RelativePosition") ) >>= aOldPos;
1644cdf0e10cSrcweir     xDiaProps->getPropertyValue(C2U("RelativeSize") ) >>= aOldSize;
1645cdf0e10cSrcweir 
1646cdf0e10cSrcweir     RelativePosition aNewPos;
1647cdf0e10cSrcweir     aNewPos.Anchor = drawing::Alignment_TOP_LEFT;
1648cdf0e10cSrcweir     aNewPos.Primary = double(rPosRect.X)/double(aPageSize.Width);
1649cdf0e10cSrcweir     aNewPos.Secondary = double(rPosRect.Y)/double(aPageSize.Height);
1650cdf0e10cSrcweir 
1651cdf0e10cSrcweir     chart2::RelativeSize aNewSize;
1652cdf0e10cSrcweir     aNewSize.Primary = double(rPosRect.Width)/double(aPageSize.Width);
1653cdf0e10cSrcweir     aNewSize.Secondary = double(rPosRect.Height)/double(aPageSize.Height);
1654cdf0e10cSrcweir 
1655cdf0e10cSrcweir     lcl_ensureRange0to1( aNewPos.Primary );
1656cdf0e10cSrcweir     lcl_ensureRange0to1( aNewPos.Secondary );
1657cdf0e10cSrcweir     lcl_ensureRange0to1( aNewSize.Primary );
1658cdf0e10cSrcweir     lcl_ensureRange0to1( aNewSize.Secondary );
1659cdf0e10cSrcweir     if( (aNewPos.Primary + aNewSize.Primary) > 1.0 )
1660cdf0e10cSrcweir         aNewPos.Primary = 1.0 - aNewSize.Primary;
1661cdf0e10cSrcweir     if( (aNewPos.Secondary + aNewSize.Secondary) > 1.0 )
1662cdf0e10cSrcweir         aNewPos.Secondary = 1.0 - aNewSize.Secondary;
1663cdf0e10cSrcweir 
1664cdf0e10cSrcweir     xDiaProps->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aNewPos) );
1665cdf0e10cSrcweir     xDiaProps->setPropertyValue( C2U( "RelativeSize" ), uno::makeAny(aNewSize) );
1666cdf0e10cSrcweir 
1667cdf0e10cSrcweir     bChanged = (aOldPos.Anchor!=aNewPos.Anchor) ||
1668cdf0e10cSrcweir         (aOldPos.Primary!=aNewPos.Primary) ||
1669cdf0e10cSrcweir         (aOldPos.Secondary!=aNewPos.Secondary) ||
1670cdf0e10cSrcweir         (aOldSize.Primary!=aNewSize.Primary) ||
1671cdf0e10cSrcweir         (aOldSize.Secondary!=aNewSize.Secondary);
1672cdf0e10cSrcweir     return bChanged;
1673cdf0e10cSrcweir }
1674cdf0e10cSrcweir 
1675cdf0e10cSrcweir awt::Rectangle DiagramHelper::getDiagramRectangleFromModel( const uno::Reference< frame::XModel >& xChartModel )
1676cdf0e10cSrcweir {
1677cdf0e10cSrcweir     awt::Rectangle aRet(-1,-1,-1,-1);
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xDiaProps( ChartModelHelper::findDiagram( xChartModel ), uno::UNO_QUERY );
1680cdf0e10cSrcweir     if( !xDiaProps.is() )
1681cdf0e10cSrcweir         return aRet;
1682cdf0e10cSrcweir 
1683cdf0e10cSrcweir     awt::Size aPageSize( ChartModelHelper::getPageSize(xChartModel) );
1684cdf0e10cSrcweir 
1685cdf0e10cSrcweir     RelativePosition aRelPos;
1686cdf0e10cSrcweir     RelativeSize aRelSize;
1687cdf0e10cSrcweir     xDiaProps->getPropertyValue(C2U("RelativePosition") ) >>= aRelPos;
1688cdf0e10cSrcweir     xDiaProps->getPropertyValue(C2U("RelativeSize") ) >>= aRelSize;
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir     awt::Size aAbsSize(
1691cdf0e10cSrcweir         static_cast< sal_Int32 >( aRelSize.Primary * aPageSize.Width ),
1692cdf0e10cSrcweir         static_cast< sal_Int32 >( aRelSize.Secondary * aPageSize.Height ));
1693cdf0e10cSrcweir 
1694cdf0e10cSrcweir     awt::Point aAbsPos(
1695cdf0e10cSrcweir         static_cast< sal_Int32 >( aRelPos.Primary * aPageSize.Width ),
1696cdf0e10cSrcweir         static_cast< sal_Int32 >( aRelPos.Secondary * aPageSize.Height ));
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir     awt::Point aAbsPosLeftTop = RelativePositionHelper::getUpperLeftCornerOfAnchoredObject( aAbsPos, aAbsSize, aRelPos.Anchor );
1699cdf0e10cSrcweir 
1700cdf0e10cSrcweir     aRet = awt::Rectangle(aAbsPosLeftTop.X, aAbsPosLeftTop.Y, aAbsSize.Width, aAbsSize.Height );
1701cdf0e10cSrcweir 
1702cdf0e10cSrcweir     return aRet;
1703cdf0e10cSrcweir }
1704cdf0e10cSrcweir 
1705cdf0e10cSrcweir bool DiagramHelper::switchDiagramPositioningToExcludingPositioning(
1706cdf0e10cSrcweir     const uno::Reference< frame::XModel >& xChartModel
1707cdf0e10cSrcweir     , bool bResetModifiedState, bool bConvertAlsoFromAutoPositioning )
1708cdf0e10cSrcweir {
1709cdf0e10cSrcweir     //return true if something was changed
1710cdf0e10cSrcweir     const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() );
1711cdf0e10cSrcweir     if( nCurrentODFVersion == SvtSaveOptions::ODFVER_LATEST )//#i100778# todo: change this dependent on fileformat evolution
1712cdf0e10cSrcweir     {
1713cdf0e10cSrcweir         uno::Reference< ::com::sun::star::chart::XChartDocument > xOldDoc( xChartModel, uno::UNO_QUERY ) ;
1714cdf0e10cSrcweir         if( xOldDoc.is() )
1715cdf0e10cSrcweir         {
1716cdf0e10cSrcweir             uno::Reference< ::com::sun::star::chart::XDiagramPositioning > xDiagramPositioning( xOldDoc->getDiagram(), uno::UNO_QUERY );
1717cdf0e10cSrcweir             if( xDiagramPositioning.is() && ( bConvertAlsoFromAutoPositioning || !xDiagramPositioning->isAutomaticDiagramPositioning() )
1718cdf0e10cSrcweir                 && !xDiagramPositioning->isExcludingDiagramPositioning() )
1719cdf0e10cSrcweir             {
1720cdf0e10cSrcweir                 ControllerLockGuard aCtrlLockGuard( xChartModel );
1721cdf0e10cSrcweir                 uno::Reference< util::XModifiable > xModifiable( xChartModel, uno::UNO_QUERY );
1722cdf0e10cSrcweir                 bool bModelWasModified = xModifiable.is() && xModifiable->isModified();
1723cdf0e10cSrcweir                 xDiagramPositioning->setDiagramPositionExcludingAxes( xDiagramPositioning->calculateDiagramPositionExcludingAxes() );
1724cdf0e10cSrcweir                 if(bResetModifiedState && !bModelWasModified && xModifiable.is() )
1725cdf0e10cSrcweir                     xModifiable->setModified(sal_False);
1726cdf0e10cSrcweir                 return true;
1727cdf0e10cSrcweir             }
1728cdf0e10cSrcweir         }
1729cdf0e10cSrcweir     }
1730cdf0e10cSrcweir     return false;
1731cdf0e10cSrcweir }
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir } //  namespace chart
1734