1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "NetChartTypeTemplate.hxx"
32 #include "PolarCoordinateSystem.hxx"
33 #include "DiagramHelper.hxx"
34 #include "servicenames_charttypes.hxx"
35 #include "DataSeriesHelper.hxx"
36 #include <com/sun/star/chart2/SymbolStyle.hpp>
37 #include <com/sun/star/chart2/Symbol.hpp>
38 #include <com/sun/star/drawing/LineStyle.hpp>
40 using namespace ::com::sun::star
;
42 using ::com::sun::star::uno::Reference
;
43 using ::com::sun::star::uno::Sequence
;
44 using ::rtl::OUString
;
45 using ::com::sun::star::uno::Reference
;
46 using ::com::sun::star::uno::Any
;
47 using ::osl::MutexGuard
;
52 static const ::rtl::OUString
lcl_aServiceName(
53 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.NetChartTypeTemplate" ));
54 } // anonymous namespace
59 NetChartTypeTemplate::NetChartTypeTemplate(
60 Reference
< uno::XComponentContext
> const & xContext
,
61 const ::rtl::OUString
& rServiceName
,
65 bool bHasFilledArea
) :
66 ChartTypeTemplate( xContext
, rServiceName
),
67 m_eStackMode( eStackMode
),
68 m_bHasSymbols( bSymbols
),
69 m_bHasLines( bHasLines
),
70 m_bHasFilledArea( bHasFilledArea
)
73 NetChartTypeTemplate::~NetChartTypeTemplate()
76 StackMode
NetChartTypeTemplate::getStackMode( sal_Int32
/* nChartTypeIndex */ ) const
81 void SAL_CALL
NetChartTypeTemplate::applyStyle(
82 const Reference
< chart2::XDataSeries
>& xSeries
,
83 ::sal_Int32 nChartTypeIndex
,
84 ::sal_Int32 nSeriesIndex
,
85 ::sal_Int32 nSeriesCount
)
86 throw (uno::RuntimeException
)
88 ChartTypeTemplate::applyStyle( xSeries
, nChartTypeIndex
, nSeriesIndex
, nSeriesCount
);
92 Reference
< beans::XPropertySet
> xProp( xSeries
, uno::UNO_QUERY_THROW
);
94 DataSeriesHelper::switchSymbolsOnOrOff( xProp
, m_bHasSymbols
, nSeriesIndex
);
95 DataSeriesHelper::switchLinesOnOrOff( xProp
, m_bHasLines
);
96 DataSeriesHelper::makeLinesThickOrThin( xProp
, true );
98 catch( uno::Exception
& ex
)
100 ASSERT_EXCEPTION( ex
);
104 // ____ XChartTypeTemplate ____
105 sal_Bool SAL_CALL
NetChartTypeTemplate::matchesTemplate(
106 const Reference
< chart2::XDiagram
>& xDiagram
,
107 sal_Bool bAdaptProperties
)
108 throw (uno::RuntimeException
)
110 sal_Bool bResult
= ChartTypeTemplate::matchesTemplate( xDiagram
, bAdaptProperties
);
112 uno::Reference
< beans::XPropertySet
> xChartTypeProp(
113 DiagramHelper::getChartTypeByIndex( xDiagram
, 0 ), uno::UNO_QUERY_THROW
);
118 if( m_bHasFilledArea
)
121 // check symbol-style
122 // for a template with symbols it is ok, if there is at least one series
123 // with symbols, otherwise an unknown template is too easy to achieve
124 bool bSymbolFound
= false;
125 bool bLineFound
= false;
127 ::std::vector
< Reference
< chart2::XDataSeries
> > aSeriesVec(
128 DiagramHelper::getDataSeriesFromDiagram( xDiagram
));
130 for( ::std::vector
< Reference
< chart2::XDataSeries
> >::const_iterator aIt
=
131 aSeriesVec
.begin(); aIt
!= aSeriesVec
.end(); ++aIt
)
135 chart2::Symbol aSymbProp
;
136 drawing::LineStyle eLineStyle
;
137 Reference
< beans::XPropertySet
> xProp( *aIt
, uno::UNO_QUERY_THROW
);
139 bool bCurrentHasSymbol
= (xProp
->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp
) &&
140 (aSymbProp
.Style
!= chart2::SymbolStyle_NONE
);
142 if( bCurrentHasSymbol
)
145 if( bCurrentHasSymbol
&& (!m_bHasSymbols
) )
151 bool bCurrentHasLine
= (xProp
->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle
) &&
152 ( eLineStyle
!= drawing::LineStyle_NONE
);
154 if( bCurrentHasLine
)
157 if( bCurrentHasLine
&& (!m_bHasLines
) )
163 catch( uno::Exception
& ex
)
165 ASSERT_EXCEPTION( ex
);
171 if( !bLineFound
&& m_bHasLines
&& bSymbolFound
)
173 else if( !bSymbolFound
&& m_bHasSymbols
&& bLineFound
)
175 else if( !bLineFound
&& !bSymbolFound
)
176 return m_bHasLines
&& m_bHasSymbols
;
183 Reference
< chart2::XChartType
> NetChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
185 Reference
< chart2::XChartType
> xResult
;
189 Reference
< lang::XMultiServiceFactory
> xFact(
190 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
192 if( m_bHasFilledArea
)
193 xResult
.set( xFact
->createInstance(
194 CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET
), uno::UNO_QUERY_THROW
);
196 xResult
.set( xFact
->createInstance(
197 CHART2_SERVICE_NAME_CHARTTYPE_NET
), uno::UNO_QUERY_THROW
);
199 catch( uno::Exception
& ex
)
201 ASSERT_EXCEPTION( ex
);
207 Reference
< chart2::XChartType
> SAL_CALL
NetChartTypeTemplate::getChartTypeForNewSeries(
208 const uno::Sequence
< Reference
< chart2::XChartType
> >& aFormerlyUsedChartTypes
)
209 throw (uno::RuntimeException
)
211 Reference
< chart2::XChartType
> xResult( getChartTypeForIndex( 0 ) );
212 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes
, xResult
);
216 // ----------------------------------------
218 Sequence
< OUString
> NetChartTypeTemplate::getSupportedServiceNames_Static()
220 Sequence
< OUString
> aServices( 2 );
221 aServices
[ 0 ] = lcl_aServiceName
;
222 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
226 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
227 APPHELPER_XSERVICEINFO_IMPL( NetChartTypeTemplate
, lcl_aServiceName
);