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