fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / model / template / NetChartTypeTemplate.cxx
blobecf7435146ef99f8a85bb6fb1a21c08cdca63cfd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "NetChartTypeTemplate.hxx"
21 #include "macros.hxx"
22 #include "PolarCoordinateSystem.hxx"
23 #include "DiagramHelper.hxx"
24 #include "servicenames_charttypes.hxx"
25 #include "DataSeriesHelper.hxx"
26 #include <com/sun/star/chart2/SymbolStyle.hpp>
27 #include <com/sun/star/chart2/Symbol.hpp>
28 #include <com/sun/star/drawing/LineStyle.hpp>
30 using namespace ::com::sun::star;
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::Sequence;
34 using ::com::sun::star::uno::Any;
35 using ::osl::MutexGuard;
37 namespace chart
40 NetChartTypeTemplate::NetChartTypeTemplate(
41 Reference< uno::XComponentContext > const & xContext,
42 const OUString & rServiceName,
43 StackMode eStackMode,
44 bool bSymbols,
45 bool bHasLines ,
46 bool bHasFilledArea ) :
47 ChartTypeTemplate( xContext, rServiceName ),
48 m_eStackMode( eStackMode ),
49 m_bHasSymbols( bSymbols ),
50 m_bHasLines( bHasLines ),
51 m_bHasFilledArea( bHasFilledArea )
54 NetChartTypeTemplate::~NetChartTypeTemplate()
57 StackMode NetChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
59 return m_eStackMode;
62 void SAL_CALL NetChartTypeTemplate::applyStyle(
63 const Reference< chart2::XDataSeries >& xSeries,
64 ::sal_Int32 nChartTypeIndex,
65 ::sal_Int32 nSeriesIndex,
66 ::sal_Int32 nSeriesCount )
67 throw (uno::RuntimeException, std::exception)
69 ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
71 try
73 Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
75 DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex );
76 DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines );
77 DataSeriesHelper::makeLinesThickOrThin( xProp, true );
79 catch( const uno::Exception & ex )
81 ASSERT_EXCEPTION( ex );
85 // ____ XChartTypeTemplate ____
86 sal_Bool SAL_CALL NetChartTypeTemplate::matchesTemplate(
87 const Reference< chart2::XDiagram >& xDiagram,
88 sal_Bool bAdaptProperties )
89 throw (uno::RuntimeException, std::exception)
91 bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
93 uno::Reference< beans::XPropertySet > xChartTypeProp(
94 DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW );
96 if( bResult )
98 //filled net chart?:
99 if( m_bHasFilledArea )
100 return sal_True;
102 // check symbol-style
103 // for a template with symbols it is ok, if there is at least one series
104 // with symbols, otherwise an unknown template is too easy to achieve
105 bool bSymbolFound = false;
106 bool bLineFound = false;
108 ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
109 DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
111 for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
112 aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
116 chart2::Symbol aSymbProp;
117 drawing::LineStyle eLineStyle;
118 Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
120 bool bCurrentHasSymbol = (xProp->getPropertyValue( "Symbol") >>= aSymbProp) &&
121 (aSymbProp.Style != chart2::SymbolStyle_NONE);
123 if( bCurrentHasSymbol )
124 bSymbolFound = true;
126 if( bCurrentHasSymbol && (!m_bHasSymbols) )
128 bResult = false;
129 break;
132 bool bCurrentHasLine = (xProp->getPropertyValue( "LineStyle") >>= eLineStyle) &&
133 ( eLineStyle != drawing::LineStyle_NONE );
135 if( bCurrentHasLine )
136 bLineFound = true;
138 if( bCurrentHasLine && (!m_bHasLines) )
140 bResult = false;
141 break;
144 catch( const uno::Exception & ex )
146 ASSERT_EXCEPTION( ex );
150 if(bResult)
152 if( !bLineFound && m_bHasLines && bSymbolFound )
153 bResult = false;
154 else if( !bSymbolFound && m_bHasSymbols && bLineFound )
155 bResult = false;
156 else if( !bLineFound && !bSymbolFound )
157 return m_bHasLines && m_bHasSymbols;
161 return bResult;
164 Reference< chart2::XChartType > NetChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
166 Reference< chart2::XChartType > xResult;
170 Reference< lang::XMultiServiceFactory > xFact(
171 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
173 if( m_bHasFilledArea )
174 xResult.set( xFact->createInstance(
175 CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ), uno::UNO_QUERY_THROW );
176 else
177 xResult.set( xFact->createInstance(
178 CHART2_SERVICE_NAME_CHARTTYPE_NET ), uno::UNO_QUERY_THROW );
180 catch( const uno::Exception & ex )
182 ASSERT_EXCEPTION( ex );
185 return xResult;
188 Reference< chart2::XChartType > SAL_CALL NetChartTypeTemplate::getChartTypeForNewSeries(
189 const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
190 throw (uno::RuntimeException, std::exception)
192 Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
193 ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
194 return xResult;
197 } // namespace chart
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */