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