Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / Chart2ModelContact.cxx
blob00f7bd590fd0646e55325aa8298b201963025b1b
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 "Chart2ModelContact.hxx"
21 #include <ChartModelHelper.hxx>
22 #include <LegendHelper.hxx>
23 #include <CommonConverters.hxx>
24 #include <servicenames.hxx>
25 #include <ObjectIdentifier.hxx>
26 #include <chartview/ExplicitValueProvider.hxx>
27 #include <chartview/DrawModelWrapper.hxx>
28 #include <AxisHelper.hxx>
29 #include <DiagramHelper.hxx>
31 #include <ChartModel.hxx>
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::chart2;
36 using ::com::sun::star::uno::Reference;
38 namespace chart
40 namespace wrapper
43 Chart2ModelContact::Chart2ModelContact(
44 const Reference< uno::XComponentContext > & xContext ) :
45 m_xContext( xContext ),
46 m_xChartModel( nullptr ),
47 mpModel( nullptr )
51 Chart2ModelContact::~Chart2ModelContact()
53 clear();
56 void Chart2ModelContact::setModel( const css::uno::Reference< css::frame::XModel >& xChartModel )
58 clear();
59 m_xChartModel = xChartModel;
60 mpModel = dynamic_cast<ChartModel*>(xChartModel.get());
61 uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartModel, uno::UNO_QUERY );
62 if( xTableFactory.is() )
64 uno::Reference< container::XNameContainer > xDashTable( xTableFactory->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
65 uno::Reference< container::XNameContainer > xGradientTable( xTableFactory->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
66 uno::Reference< container::XNameContainer > xHatchTable( xTableFactory->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
67 uno::Reference< container::XNameContainer > xBitmapTable( xTableFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
68 uno::Reference< container::XNameContainer > xTransparencyGradientTable( xTableFactory->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
69 m_aTableMap["LineDashName"] = xDashTable;
70 m_aTableMap["FillGradientName"] = xGradientTable;
71 m_aTableMap["FillHatchName"] = xHatchTable;
72 m_aTableMap["FillBitmapName"] = xBitmapTable;
73 m_aTableMap["FillTransparenceGradientName"] = xTransparencyGradientTable;
77 void Chart2ModelContact::clear()
79 m_xChartModel.clear();
80 m_xChartView.clear();
81 mpModel = nullptr;
84 Reference< frame::XModel > Chart2ModelContact::getChartModel() const
86 return Reference< frame::XModel >( m_xChartModel.get(), uno::UNO_QUERY );
89 Reference< chart2::XChartDocument > Chart2ModelContact::getChart2Document() const
91 return Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY );
94 Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
96 return ChartModelHelper::findDiagram( getChartModel() );
99 uno::Reference< lang::XUnoTunnel > const & Chart2ModelContact::getChartView() const
101 if(!m_xChartView.is())
103 // get the chart view
104 Reference<frame::XModel> xModel(m_xChartModel);
105 uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
106 if( xFact.is() )
107 m_xChartView.set( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
109 return m_xChartView;
112 ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const
114 getChartView();
115 if(!m_xChartView.is())
116 return nullptr;
118 //obtain the ExplicitValueProvider from the chart view
119 ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(m_xChartView->getSomething(
120 ExplicitValueProvider::getUnoTunnelId() ));
121 return pProvider;
124 uno::Reference< drawing::XDrawPage > Chart2ModelContact::getDrawPage() const
126 uno::Reference< drawing::XDrawPage > xResult;
127 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
128 if( pProvider )
130 xResult.set( pProvider->getDrawModelWrapper()->getMainDrawPage() );
132 return xResult;
135 void Chart2ModelContact::getExplicitValuesForAxis(
136 const Reference< XAxis > & xAxis,
137 ExplicitScaleData & rOutExplicitScale,
138 ExplicitIncrementData & rOutExplicitIncrement )
140 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
141 if( pProvider )
143 pProvider->getExplicitValuesForAxis(
144 xAxis, rOutExplicitScale, rOutExplicitIncrement );
148 sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
149 const Reference< chart2::XAxis >& xAxis )
151 Reference< chart2::XCoordinateSystem > xCooSys(
152 AxisHelper::getCoordinateSystemOfAxis(
153 xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) );
155 return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
156 , getChart2Document());
159 sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForSeries(
160 const Reference< chart2::XDataSeries >& xSeries )
162 return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
163 uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ),
164 xSeries,
165 -1 /*-1 for whole series*/,
166 ChartModelHelper::findDiagram( m_xChartModel )
170 awt::Size Chart2ModelContact::GetPageSize() const
172 return ChartModelHelper::getPageSize(m_xChartModel);
175 awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
177 awt::Rectangle aRect = ExplicitValueProvider::AddSubtractAxisTitleSizes(
178 *mpModel, getChartView(), rPositionRect, true );
179 return aRect;
182 awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
184 awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
186 //add axis title sizes to the diagram size
187 aRect = ExplicitValueProvider::AddSubtractAxisTitleSizes(
188 *mpModel, getChartView(), aRect, false );
190 return aRect;
193 awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
195 awt::Rectangle aRect(0,0,0,0);
196 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
198 if( DiagramHelper::getDiagramPositioningMode( xDiagram ) == DiagramPositioningMode_INCLUDING )
199 aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
200 else
202 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
203 if( pProvider )
204 aRect = pProvider->getRectangleOfObject("PlotAreaIncludingAxes");
206 return aRect;
209 awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
211 awt::Rectangle aRect(0,0,0,0);
212 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
214 if( DiagramHelper::getDiagramPositioningMode( xDiagram ) == DiagramPositioningMode_EXCLUDING )
215 aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
216 else
218 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
219 if( pProvider )
220 aRect = pProvider->getDiagramRectangleExcludingAxes();
222 return aRect;
225 awt::Size Chart2ModelContact::GetLegendSize() const
227 awt::Size aSize;
228 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
229 if( pProvider )
231 uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
232 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
233 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
235 return aSize;
238 awt::Point Chart2ModelContact::GetLegendPosition() const
240 awt::Point aPoint;
241 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
242 if( pProvider )
244 uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
245 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
246 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
248 return aPoint;
251 awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference< css::chart2::XTitle > & xTitle ) const
253 awt::Size aSize;
254 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
255 if( pProvider && xTitle.is() )
257 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
258 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
260 return aSize;
263 awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference< css::chart2::XTitle > & xTitle ) const
265 awt::Point aPoint;
266 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
267 if( pProvider && xTitle.is() )
269 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
270 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
272 return aPoint;
275 awt::Size Chart2ModelContact::GetAxisSize( const uno::Reference< css::chart2::XAxis > & xAxis ) const
277 awt::Size aSize;
278 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
279 if( pProvider && xAxis.is() )
281 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
282 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
284 return aSize;
287 awt::Point Chart2ModelContact::GetAxisPosition( const uno::Reference< css::chart2::XAxis > & xAxis ) const
289 awt::Point aPoint;
290 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
291 if( pProvider && xAxis.is() )
293 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
294 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
296 return aPoint;
299 } // namespace wrapper
300 } // namespace chart
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */