Update ooo320-m1
[ooovba.git] / chart2 / source / model / template / NetChartTypeTemplate.cxx
bloba9bc6bce22545ec64043b8cd50c7f19a7ad610e9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NetChartTypeTemplate.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "NetChartTypeTemplate.hxx"
34 #include "macros.hxx"
35 #include "PolarCoordinateSystem.hxx"
36 #include "DiagramHelper.hxx"
37 #include "servicenames_charttypes.hxx"
38 #include "DataSeriesHelper.hxx"
39 #include <com/sun/star/chart2/SymbolStyle.hpp>
40 #include <com/sun/star/chart2/Symbol.hpp>
41 #include <com/sun/star/drawing/LineStyle.hpp>
43 using namespace ::com::sun::star;
45 using ::com::sun::star::uno::Reference;
46 using ::com::sun::star::uno::Sequence;
47 using ::rtl::OUString;
48 using ::com::sun::star::uno::Reference;
49 using ::com::sun::star::uno::Any;
50 using ::osl::MutexGuard;
53 namespace
55 static const ::rtl::OUString lcl_aServiceName(
56 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.NetChartTypeTemplate" ));
57 } // anonymous namespace
59 namespace chart
62 NetChartTypeTemplate::NetChartTypeTemplate(
63 Reference< uno::XComponentContext > const & xContext,
64 const ::rtl::OUString & rServiceName,
65 StackMode eStackMode,
66 bool bSymbols,
67 bool bHasLines ,
68 bool bHasFilledArea ) :
69 ChartTypeTemplate( xContext, rServiceName ),
70 m_eStackMode( eStackMode ),
71 m_bHasSymbols( bSymbols ),
72 m_bHasLines( bHasLines ),
73 m_bHasFilledArea( bHasFilledArea )
76 NetChartTypeTemplate::~NetChartTypeTemplate()
79 StackMode NetChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
81 return m_eStackMode;
84 void SAL_CALL NetChartTypeTemplate::applyStyle(
85 const Reference< chart2::XDataSeries >& xSeries,
86 ::sal_Int32 nChartTypeIndex,
87 ::sal_Int32 nSeriesIndex,
88 ::sal_Int32 nSeriesCount )
89 throw (uno::RuntimeException)
91 ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
93 try
95 Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
97 DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex );
98 DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines );
99 DataSeriesHelper::makeLinesThickOrThin( xProp, true );
101 catch( uno::Exception & ex )
103 ASSERT_EXCEPTION( ex );
107 // ____ XChartTypeTemplate ____
108 sal_Bool SAL_CALL NetChartTypeTemplate::matchesTemplate(
109 const Reference< chart2::XDiagram >& xDiagram,
110 sal_Bool bAdaptProperties )
111 throw (uno::RuntimeException)
113 sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
115 uno::Reference< beans::XPropertySet > xChartTypeProp(
116 DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW );
118 if( bResult )
120 //filled net chart?:
121 if( m_bHasFilledArea )
122 return sal_True;
124 // check symbol-style
125 // for a template with symbols it is ok, if there is at least one series
126 // with symbols, otherwise an unknown template is too easy to achieve
127 bool bSymbolFound = false;
128 bool bLineFound = false;
130 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
131 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
133 for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
134 aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
138 chart2::Symbol aSymbProp;
139 drawing::LineStyle eLineStyle;
140 Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
142 bool bCurrentHasSymbol = (xProp->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp) &&
143 (aSymbProp.Style != chart2::SymbolStyle_NONE);
145 if( bCurrentHasSymbol )
146 bSymbolFound = true;
148 if( bCurrentHasSymbol && (!m_bHasSymbols) )
150 bResult = false;
151 break;
154 bool bCurrentHasLine = (xProp->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle) &&
155 ( eLineStyle != drawing::LineStyle_NONE );
157 if( bCurrentHasLine )
158 bLineFound = true;
160 if( bCurrentHasLine && (!m_bHasLines) )
162 bResult = false;
163 break;
166 catch( uno::Exception & ex )
168 ASSERT_EXCEPTION( ex );
172 if(bResult)
174 if( !bLineFound && m_bHasLines && bSymbolFound )
175 bResult = false;
176 else if( !bSymbolFound && m_bHasSymbols && bLineFound )
177 bResult = false;
178 else if( !bLineFound && !bSymbolFound )
179 return m_bHasLines && m_bHasSymbols;
183 return bResult;
186 Reference< chart2::XChartType > NetChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
188 Reference< chart2::XChartType > xResult;
192 Reference< lang::XMultiServiceFactory > xFact(
193 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
195 if( m_bHasFilledArea )
196 xResult.set( xFact->createInstance(
197 CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ), uno::UNO_QUERY_THROW );
198 else
199 xResult.set( xFact->createInstance(
200 CHART2_SERVICE_NAME_CHARTTYPE_NET ), uno::UNO_QUERY_THROW );
202 catch( uno::Exception & ex )
204 ASSERT_EXCEPTION( ex );
207 return xResult;
210 Reference< chart2::XChartType > SAL_CALL NetChartTypeTemplate::getChartTypeForNewSeries(
211 const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
212 throw (uno::RuntimeException)
214 Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
215 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
216 setStackModePropertiesToChartType(xResult);
217 return xResult;
220 // ----------------------------------------
222 Sequence< OUString > NetChartTypeTemplate::getSupportedServiceNames_Static()
224 Sequence< OUString > aServices( 2 );
225 aServices[ 0 ] = lcl_aServiceName;
226 aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
227 return aServices;
230 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
231 APPHELPER_XSERVICEINFO_IMPL( NetChartTypeTemplate, lcl_aServiceName );
233 } // namespace chart