fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / Chart2ModelContact.cxx
blobafdebd1db5aee867221107f591bda741f6790f96
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 "macros.hxx"
25 #include "servicenames.hxx"
26 #include "ObjectIdentifier.hxx"
27 #include "chartview/ExplicitValueProvider.hxx"
28 #include "chartview/DrawModelWrapper.hxx"
29 #include "AxisHelper.hxx"
30 #include "DiagramHelper.hxx"
32 #include "ChartModel.hxx"
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::chart2;
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::uno::Sequence;
40 namespace chart
42 namespace wrapper
45 Chart2ModelContact::Chart2ModelContact(
46 const Reference< uno::XComponentContext > & xContext ) :
47 m_xContext( xContext ),
48 m_xChartModel( 0 ),
49 mpModel( NULL ),
50 m_xChartView(0)
54 Chart2ModelContact::~Chart2ModelContact()
56 this->clear();
59 void Chart2ModelContact::setModel( const ::com::sun::star::uno::Reference<
60 ::com::sun::star::frame::XModel >& xChartModel )
62 this->clear();
63 m_xChartModel = xChartModel;
64 mpModel = dynamic_cast<ChartModel*>(xChartModel.get());
65 uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartModel, uno::UNO_QUERY );
66 if( xTableFactory.is() )
68 uno::Reference< container::XNameContainer > xDashTable( xTableFactory->createInstance("com.sun.star.drawing.DashTable"), uno::UNO_QUERY );
69 uno::Reference< container::XNameContainer > xGradientTable( xTableFactory->createInstance("com.sun.star.drawing.GradientTable"), uno::UNO_QUERY );
70 uno::Reference< container::XNameContainer > xHatchTable( xTableFactory->createInstance("com.sun.star.drawing.HatchTable"), uno::UNO_QUERY );
71 uno::Reference< container::XNameContainer > xBitmapTable( xTableFactory->createInstance("com.sun.star.drawing.BitmapTable"), uno::UNO_QUERY );
72 uno::Reference< container::XNameContainer > xTransparencyGradientTable( xTableFactory->createInstance("com.sun.star.drawing.TransparencyGradientTable"), uno::UNO_QUERY );
73 m_aTableMap["LineDashName"] = xDashTable;
74 m_aTableMap["FillGradientName"] = xGradientTable;
75 m_aTableMap["FillHatchName"] = xHatchTable;
76 m_aTableMap["FillBitmapName"] = xBitmapTable;
77 m_aTableMap["FillTransparenceGradientName"] = xTransparencyGradientTable;
81 void Chart2ModelContact::clear()
83 m_xChartModel = uno::WeakReference< frame::XModel >(0);
84 m_xChartView.clear();
85 mpModel = NULL;
88 Reference< frame::XModel > Chart2ModelContact::getChartModel() const
90 return Reference< frame::XModel >( m_xChartModel.get(), uno::UNO_QUERY );
93 Reference< chart2::XChartDocument > Chart2ModelContact::getChart2Document() const
95 return Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY );
98 Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
100 return ChartModelHelper::findDiagram( this->getChartModel() );
103 uno::Reference< lang::XUnoTunnel > Chart2ModelContact::getChartView() const
105 if(!m_xChartView.is())
107 // get the chart view
108 Reference<frame::XModel> xModel(m_xChartModel);
109 uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
110 if( xFact.is() )
111 m_xChartView = Reference< lang::XUnoTunnel >( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
113 return m_xChartView;
116 ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const
118 getChartView();
119 if(!m_xChartView.is())
120 return 0;
122 //obtain the ExplicitValueProvider from the chart view
123 ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(m_xChartView->getSomething(
124 ExplicitValueProvider::getUnoTunnelId() ));
125 return pProvider;
128 uno::Reference< drawing::XDrawPage > Chart2ModelContact::getDrawPage()
130 uno::Reference< drawing::XDrawPage > xResult;
131 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
132 if( pProvider )
134 xResult.set( pProvider->getDrawModelWrapper()->getMainDrawPage() );
136 return xResult;
139 bool Chart2ModelContact::getExplicitValuesForAxis(
140 const Reference< XAxis > & xAxis,
141 ExplicitScaleData & rOutExplicitScale,
142 ExplicitIncrementData & rOutExplicitIncrement )
144 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
145 if( pProvider )
147 return pProvider->getExplicitValuesForAxis(
148 xAxis, rOutExplicitScale, rOutExplicitIncrement );
150 return false;
153 sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
154 const Reference< chart2::XAxis >& xAxis )
156 Reference< chart2::XCoordinateSystem > xCooSys(
157 AxisHelper::getCoordinateSystemOfAxis(
158 xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) );
160 return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
161 , getChart2Document());
164 sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForSeries(
165 const Reference< chart2::XDataSeries >& xSeries )
167 return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
168 uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ),
169 xSeries,
170 -1 /*-1 for whole series*/,
171 ChartModelHelper::findDiagram( m_xChartModel )
175 awt::Size Chart2ModelContact::GetPageSize() const
177 return ChartModelHelper::getPageSize(m_xChartModel);
180 awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
182 awt::Rectangle aRect = ExplicitValueProvider::substractAxisTitleSizes(
183 *mpModel, getChartView(), rPositionRect );
184 return aRect;
187 awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
189 awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
191 //add axis title sizes to the diagram size
192 aRect = ExplicitValueProvider::addAxisTitleSizes(
193 *mpModel, getChartView(), aRect );
195 return aRect;
198 awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
200 awt::Rectangle aRect(0,0,0,0);
201 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
203 if( DiagramPositioningMode_INCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
204 aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
205 else
207 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
208 if( pProvider )
209 aRect = pProvider->getRectangleOfObject("PlotAreaIncludingAxes");
211 return aRect;
214 awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
216 awt::Rectangle aRect(0,0,0,0);
217 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
219 if( DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
220 aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
221 else
223 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
224 if( pProvider )
225 aRect = pProvider->getDiagramRectangleExcludingAxes();
227 return aRect;
230 awt::Size Chart2ModelContact::GetLegendSize() const
232 awt::Size aSize;
233 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
234 if( pProvider )
236 uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
237 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
238 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
240 return aSize;
243 awt::Point Chart2ModelContact::GetLegendPosition() const
245 awt::Point aPoint;
246 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
247 if( pProvider )
249 uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( *mpModel ) );
250 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, *mpModel ) );
251 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
253 return aPoint;
256 awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference<
257 ::com::sun::star::chart2::XTitle > & xTitle ) const
259 awt::Size aSize;
260 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
261 if( pProvider && xTitle.is() )
263 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
264 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
266 return aSize;
269 awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference<
270 ::com::sun::star::chart2::XTitle > & xTitle ) const
272 awt::Point aPoint;
273 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
274 if( pProvider && xTitle.is() )
276 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
277 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
279 return aPoint;
282 awt::Size Chart2ModelContact::GetAxisSize( const uno::Reference<
283 ::com::sun::star::chart2::XAxis > & xAxis ) const
285 awt::Size aSize;
286 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
287 if( pProvider && xAxis.is() )
289 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
290 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
292 return aSize;
295 awt::Point Chart2ModelContact::GetAxisPosition( const uno::Reference<
296 ::com::sun::star::chart2::XAxis > & xAxis ) const
298 awt::Point aPoint;
299 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
300 if( pProvider && xAxis.is() )
302 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
303 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
305 return aPoint;
308 } // namespace wrapper
309 } // namespace chart
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */