Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
29 :
30 : using namespace ::com::sun::star;
31 :
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;
36 :
37 :
38 : namespace
39 : {
40 11 : static const OUString lcl_aServiceName( "com.sun.star.chart2.NetChartTypeTemplate" );
41 : } // anonymous namespace
42 :
43 : namespace chart
44 : {
45 :
46 188 : NetChartTypeTemplate::NetChartTypeTemplate(
47 : Reference< uno::XComponentContext > const & xContext,
48 : const OUString & rServiceName,
49 : StackMode eStackMode,
50 : bool bSymbols,
51 : bool bHasLines ,
52 : bool bHasFilledArea ) :
53 : ChartTypeTemplate( xContext, rServiceName ),
54 : m_eStackMode( eStackMode ),
55 : m_bHasSymbols( bSymbols ),
56 : m_bHasLines( bHasLines ),
57 188 : m_bHasFilledArea( bHasFilledArea )
58 188 : {}
59 :
60 376 : NetChartTypeTemplate::~NetChartTypeTemplate()
61 376 : {}
62 :
63 0 : StackMode NetChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const
64 : {
65 0 : return m_eStackMode;
66 : }
67 :
68 0 : void SAL_CALL NetChartTypeTemplate::applyStyle(
69 : const Reference< chart2::XDataSeries >& xSeries,
70 : ::sal_Int32 nChartTypeIndex,
71 : ::sal_Int32 nSeriesIndex,
72 : ::sal_Int32 nSeriesCount )
73 : throw (uno::RuntimeException)
74 : {
75 0 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
76 :
77 : try
78 : {
79 0 : Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW );
80 :
81 0 : DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex );
82 0 : DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines );
83 0 : DataSeriesHelper::makeLinesThickOrThin( xProp, true );
84 : }
85 0 : catch( const uno::Exception & ex )
86 : {
87 : ASSERT_EXCEPTION( ex );
88 : }
89 0 : }
90 :
91 : // ____ XChartTypeTemplate ____
92 188 : sal_Bool SAL_CALL NetChartTypeTemplate::matchesTemplate(
93 : const Reference< chart2::XDiagram >& xDiagram,
94 : sal_Bool bAdaptProperties )
95 : throw (uno::RuntimeException)
96 : {
97 188 : sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties );
98 :
99 : uno::Reference< beans::XPropertySet > xChartTypeProp(
100 188 : DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW );
101 :
102 188 : if( bResult )
103 : {
104 : //filled net chart?:
105 0 : if( m_bHasFilledArea )
106 0 : return sal_True;
107 :
108 : // check symbol-style
109 : // for a template with symbols it is ok, if there is at least one series
110 : // with symbols, otherwise an unknown template is too easy to achieve
111 0 : bool bSymbolFound = false;
112 0 : bool bLineFound = false;
113 :
114 : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
115 0 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
116 :
117 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt =
118 0 : aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt )
119 : {
120 : try
121 : {
122 0 : chart2::Symbol aSymbProp;
123 : drawing::LineStyle eLineStyle;
124 0 : Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW );
125 :
126 0 : bool bCurrentHasSymbol = (xProp->getPropertyValue( "Symbol") >>= aSymbProp) &&
127 0 : (aSymbProp.Style != chart2::SymbolStyle_NONE);
128 :
129 0 : if( bCurrentHasSymbol )
130 0 : bSymbolFound = true;
131 :
132 0 : if( bCurrentHasSymbol && (!m_bHasSymbols) )
133 : {
134 0 : bResult = false;
135 0 : break;
136 : }
137 :
138 0 : bool bCurrentHasLine = (xProp->getPropertyValue( "LineStyle") >>= eLineStyle) &&
139 0 : ( eLineStyle != drawing::LineStyle_NONE );
140 :
141 0 : if( bCurrentHasLine )
142 0 : bLineFound = true;
143 :
144 0 : if( bCurrentHasLine && (!m_bHasLines) )
145 : {
146 0 : bResult = false;
147 0 : break;
148 0 : }
149 : }
150 0 : catch( const uno::Exception & ex )
151 : {
152 : ASSERT_EXCEPTION( ex );
153 : }
154 : }
155 :
156 0 : if(bResult)
157 : {
158 0 : if( !bLineFound && m_bHasLines && bSymbolFound )
159 0 : bResult = false;
160 0 : else if( !bSymbolFound && m_bHasSymbols && bLineFound )
161 0 : bResult = false;
162 0 : else if( !bLineFound && !bSymbolFound )
163 0 : return m_bHasLines && m_bHasSymbols;
164 0 : }
165 : }
166 :
167 188 : return bResult;
168 : }
169 :
170 188 : Reference< chart2::XChartType > NetChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ )
171 : {
172 188 : Reference< chart2::XChartType > xResult;
173 :
174 : try
175 : {
176 : Reference< lang::XMultiServiceFactory > xFact(
177 188 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
178 :
179 188 : if( m_bHasFilledArea )
180 56 : xResult.set( xFact->createInstance(
181 56 : CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ), uno::UNO_QUERY_THROW );
182 : else
183 132 : xResult.set( xFact->createInstance(
184 132 : CHART2_SERVICE_NAME_CHARTTYPE_NET ), uno::UNO_QUERY_THROW );
185 : }
186 0 : catch( const uno::Exception & ex )
187 : {
188 : ASSERT_EXCEPTION( ex );
189 : }
190 :
191 188 : return xResult;
192 : }
193 :
194 188 : Reference< chart2::XChartType > SAL_CALL NetChartTypeTemplate::getChartTypeForNewSeries(
195 : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
196 : throw (uno::RuntimeException)
197 : {
198 188 : Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) );
199 188 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
200 188 : return xResult;
201 : }
202 :
203 : // ----------------------------------------
204 :
205 0 : Sequence< OUString > NetChartTypeTemplate::getSupportedServiceNames_Static()
206 : {
207 0 : Sequence< OUString > aServices( 2 );
208 0 : aServices[ 0 ] = lcl_aServiceName;
209 0 : aServices[ 1 ] = "com.sun.star.chart2.ChartTypeTemplate";
210 0 : return aServices;
211 : }
212 :
213 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
214 0 : APPHELPER_XSERVICEINFO_IMPL( NetChartTypeTemplate, lcl_aServiceName );
215 :
216 33 : } // namespace chart
217 :
218 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|