Branch data 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 : :
21 : : #include "Chart2ModelContact.hxx"
22 : : #include "ChartModelHelper.hxx"
23 : : #include "LegendHelper.hxx"
24 : : #include "CommonConverters.hxx"
25 : : #include "macros.hxx"
26 : : #include "servicenames.hxx"
27 : : #include "ObjectIdentifier.hxx"
28 : : #include "chartview/ExplicitValueProvider.hxx"
29 : : #include "chartview/DrawModelWrapper.hxx"
30 : : #include "AxisHelper.hxx"
31 : : #include "DiagramHelper.hxx"
32 : :
33 : : using namespace ::com::sun::star;
34 : : using namespace ::com::sun::star::chart2;
35 : :
36 : : using ::com::sun::star::uno::Reference;
37 : : using ::com::sun::star::uno::Sequence;
38 : : using ::rtl::OUString;
39 : :
40 : : namespace chart
41 : : {
42 : : namespace wrapper
43 : : {
44 : :
45 : 56 : Chart2ModelContact::Chart2ModelContact(
46 : : const Reference< uno::XComponentContext > & xContext ) :
47 : : m_xContext( xContext ),
48 : : m_xChartModel( 0 ),
49 [ + - ][ + - ]: 56 : m_xChartView(0)
[ + - ][ + - ]
50 : : {
51 : 56 : }
52 : :
53 [ + - ]: 56 : Chart2ModelContact::~Chart2ModelContact()
54 : : {
55 [ + - ]: 56 : this->clear();
56 [ - + ]: 112 : }
57 : :
58 : 56 : void Chart2ModelContact::setModel( const ::com::sun::star::uno::Reference<
59 : : ::com::sun::star::frame::XModel >& xChartModel )
60 : : {
61 [ + - ]: 56 : this->clear();
62 [ + - ]: 56 : m_xChartModel = xChartModel;
63 [ + - ]: 56 : uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartModel, uno::UNO_QUERY );
64 [ + - ]: 56 : if( xTableFactory.is() )
65 : : {
66 [ + - ][ + - ]: 56 : uno::Reference< container::XNameContainer > xDashTable( xTableFactory->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
[ + - ]
67 [ + - ][ + - ]: 56 : uno::Reference< container::XNameContainer > xGradientTable( xTableFactory->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
[ + - ]
68 [ + - ][ + - ]: 56 : uno::Reference< container::XNameContainer > xHatchTable( xTableFactory->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
[ + - ]
69 [ + - ][ + - ]: 56 : uno::Reference< container::XNameContainer > xBitmapTable( xTableFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
[ + - ]
70 [ + - ][ + - ]: 56 : uno::Reference< container::XNameContainer > xTransparencyGradientTable( xTableFactory->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
[ + - ]
71 : : //C2U( "com.sun.star.drawing.MarkerTable" )
72 [ + - ][ + - ]: 56 : m_aTableMap["LineDashName"] = xDashTable;
73 [ + - ][ + - ]: 56 : m_aTableMap["FillGradientName"] = xGradientTable;
74 [ + - ][ + - ]: 56 : m_aTableMap["FillHatchName"] = xHatchTable;
75 [ + - ][ + - ]: 56 : m_aTableMap["FillBitmapName"] = xBitmapTable;
76 [ + - ][ + - ]: 56 : m_aTableMap["FillTransparenceGradientName"] = xTransparencyGradientTable;
77 : 56 : }
78 : 56 : }
79 : :
80 : 168 : void Chart2ModelContact::clear()
81 : : {
82 [ + - ][ + - ]: 168 : m_xChartModel = uno::WeakReference< frame::XModel >(0);
[ + - ]
83 : 168 : m_xChartView.clear();
84 : 168 : }
85 : :
86 : 18375 : Reference< frame::XModel > Chart2ModelContact::getChartModel() const
87 : : {
88 [ + - ]: 18375 : return Reference< frame::XModel >( m_xChartModel.get(), uno::UNO_QUERY );
89 : : }
90 : :
91 : 5830 : Reference< chart2::XChartDocument > Chart2ModelContact::getChart2Document() const
92 : : {
93 [ + - ]: 5830 : return Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY );
94 : : }
95 : :
96 : 16337 : Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
97 : : {
98 [ + - ]: 16337 : return ChartModelHelper::findDiagram( this->getChartModel() );
99 : : }
100 : :
101 : 485 : uno::Reference< lang::XUnoTunnel > Chart2ModelContact::getChartView() const
102 : : {
103 [ + + ]: 485 : if(!m_xChartView.is())
104 : : {
105 : : // get the chart view
106 [ + - ]: 32 : Reference<frame::XModel> xModel(m_xChartModel);
107 [ + - ]: 32 : uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
108 [ + - ]: 32 : if( xFact.is() )
109 [ + - ][ + - ]: 32 : m_xChartView = Reference< lang::XUnoTunnel >( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
[ + - ][ + - ]
[ + - ]
110 : : }
111 : 485 : return m_xChartView;
112 : : }
113 : :
114 : 485 : ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const
115 : : {
116 : 485 : getChartView();
117 [ - + ]: 485 : if(!m_xChartView.is())
118 : 0 : return 0;
119 : :
120 : : //obtain the ExplicitValueProvider from the chart view
121 : 485 : ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(m_xChartView->getSomething(
122 : 485 : ExplicitValueProvider::getUnoTunnelId() ));
123 : 485 : return pProvider;
124 : : }
125 : :
126 : 50 : uno::Reference< drawing::XDrawPage > Chart2ModelContact::getDrawPage()
127 : : {
128 : 50 : uno::Reference< drawing::XDrawPage > xResult;
129 [ + - ]: 50 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
130 [ + - ]: 50 : if( pProvider )
131 : : {
132 [ + - ][ + - ]: 50 : xResult.set( pProvider->getDrawModelWrapper()->getMainDrawPage() );
[ + - ][ + - ]
133 : : }
134 : 50 : return xResult;
135 : : }
136 : :
137 : 382 : sal_Bool Chart2ModelContact::getExplicitValuesForAxis(
138 : : const Reference< XAxis > & xAxis,
139 : : ExplicitScaleData & rOutExplicitScale,
140 : : ExplicitIncrementData & rOutExplicitIncrement )
141 : : {
142 : 382 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
143 [ + - ]: 382 : if( pProvider )
144 : : {
145 : : return pProvider->getExplicitValuesForAxis(
146 [ + - ]: 382 : xAxis, rOutExplicitScale, rOutExplicitIncrement );
147 : : }
148 : 382 : return sal_False;
149 : : }
150 : :
151 : 74 : sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
152 : : const Reference< chart2::XAxis >& xAxis )
153 : : {
154 : : Reference< chart2::XCoordinateSystem > xCooSys(
155 : : AxisHelper::getCoordinateSystemOfAxis(
156 [ + - ][ + - ]: 74 : xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) );
[ + - ]
157 : :
158 : : return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
159 [ + - ][ + - ]: 74 : , Reference< util::XNumberFormatsSupplier >( m_xChartModel.get(), uno::UNO_QUERY ) );
[ + - ]
160 : : }
161 : :
162 : 148 : sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForSeries(
163 : : const Reference< chart2::XDataSeries >& xSeries )
164 : : {
165 : : return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
166 : : uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ),
167 : : xSeries,
168 : : -1 /*-1 for whole series*/,
169 : : ChartModelHelper::findDiagram( m_xChartModel )
170 [ + - ][ + - ]: 148 : );
[ + - ]
171 : : }
172 : :
173 : : //-----------------------------------------------------------------------------
174 : :
175 : 25 : awt::Size Chart2ModelContact::GetPageSize() const
176 : : {
177 [ + - ]: 25 : return ChartModelHelper::getPageSize(m_xChartModel);
178 : : }
179 : :
180 : 0 : awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
181 : : {
182 : : awt::Rectangle aRect = ExplicitValueProvider::substractAxisTitleSizes(
183 [ # # ][ # # ]: 0 : m_xChartModel, getChartView(), rPositionRect );
184 : 0 : return aRect;
185 : : }
186 : :
187 : 0 : awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
188 : : {
189 : 0 : awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
190 : :
191 : : //add axis title sizes to the diagram size
192 : : aRect = ExplicitValueProvider::addAxisTitleSizes(
193 [ # # ][ # # ]: 0 : m_xChartModel, getChartView(), aRect );
194 : :
195 : 0 : return aRect;
196 : : }
197 : :
198 : 26 : awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
199 : : {
200 : 26 : awt::Rectangle aRect(0,0,0,0);
201 [ + - ][ + - ]: 26 : uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
202 : :
203 [ + + ][ + - ]: 26 : if( DiagramPositioningMode_INCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
204 [ + - ][ + - ]: 2 : aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
205 : : else
206 : : {
207 [ + - ]: 24 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
208 [ + - ]: 24 : if( pProvider )
209 [ + - ]: 24 : aRect = pProvider->getRectangleOfObject("PlotAreaIncludingAxes");
210 : : }
211 : 26 : return aRect;
212 : : }
213 : :
214 : 17 : awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
215 : : {
216 : 17 : awt::Rectangle aRect(0,0,0,0);
217 [ + - ][ + - ]: 17 : uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
218 : :
219 [ - + ][ + - ]: 17 : if( DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
220 [ # # ][ # # ]: 0 : aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
221 : : else
222 : : {
223 [ + - ]: 17 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
224 [ + - ]: 17 : if( pProvider )
225 [ + - ]: 17 : aRect = pProvider->getDiagramRectangleExcludingAxes();
226 : : }
227 : 17 : return aRect;
228 : : }
229 : :
230 : 0 : awt::Size Chart2ModelContact::GetLegendSize() const
231 : : {
232 : 0 : awt::Size aSize;
233 : 0 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
234 [ # # ]: 0 : if( pProvider )
235 : : {
236 [ # # ][ # # ]: 0 : uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( m_xChartModel ) );
[ # # ]
237 [ # # ][ # # ]: 0 : rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) );
238 [ # # ][ # # ]: 0 : aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
239 : : }
240 : 0 : return aSize;
241 : : }
242 : :
243 : 9 : awt::Point Chart2ModelContact::GetLegendPosition() const
244 : : {
245 : 9 : awt::Point aPoint;
246 : 9 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
247 [ + - ]: 9 : if( pProvider )
248 : : {
249 [ + - ][ + - ]: 9 : uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( m_xChartModel ) );
[ + - ]
250 [ + - ][ + - ]: 9 : rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) );
251 [ + - ][ + - ]: 9 : aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
252 : : }
253 : 9 : return aPoint;
254 : : }
255 : :
256 : 3 : awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference<
257 : : ::com::sun::star::chart2::XTitle > & xTitle ) const
258 : : {
259 : 3 : awt::Size aSize;
260 : 3 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
261 [ + - ][ + - ]: 3 : if( pProvider && xTitle.is() )
[ + - ]
262 : : {
263 [ + - ][ + - ]: 3 : rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
264 [ + - ][ + - ]: 3 : aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
265 : : }
266 : 3 : return aSize;
267 : : }
268 : :
269 : 0 : awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference<
270 : : ::com::sun::star::chart2::XTitle > & xTitle ) const
271 : : {
272 : 0 : awt::Point aPoint;
273 : 0 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
274 [ # # ][ # # ]: 0 : if( pProvider && xTitle.is() )
[ # # ]
275 : : {
276 [ # # ][ # # ]: 0 : rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
277 [ # # ][ # # ]: 0 : aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
278 : : }
279 : 0 : return aPoint;
280 : : }
281 : :
282 : 0 : awt::Size Chart2ModelContact::GetAxisSize( const uno::Reference<
283 : : ::com::sun::star::chart2::XAxis > & xAxis ) const
284 : : {
285 : 0 : awt::Size aSize;
286 : 0 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
287 [ # # ][ # # ]: 0 : if( pProvider && xAxis.is() )
[ # # ]
288 : : {
289 [ # # ][ # # ]: 0 : rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
290 [ # # ][ # # ]: 0 : aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
291 : : }
292 : 0 : return aSize;
293 : : }
294 : :
295 : 0 : awt::Point Chart2ModelContact::GetAxisPosition( const uno::Reference<
296 : : ::com::sun::star::chart2::XAxis > & xAxis ) const
297 : : {
298 : 0 : awt::Point aPoint;
299 : 0 : ExplicitValueProvider* pProvider( getExplicitValueProvider() );
300 [ # # ][ # # ]: 0 : if( pProvider && xAxis.is() )
[ # # ]
301 : : {
302 [ # # ][ # # ]: 0 : rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
303 [ # # ][ # # ]: 0 : aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
304 : : }
305 : 0 : return aPoint;
306 : : }
307 : :
308 : : } // namespace wrapper
309 : : } // namespace chart
310 : :
311 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|