merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / Chart2ModelContact.cxx
blob1b0d8fb4889c5ded08ca9fc49e31fd30cf08983f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "Chart2ModelContact.hxx"
32 #include "ChartModelHelper.hxx"
33 #include "LegendHelper.hxx"
34 #include "CommonConverters.hxx"
35 #include "macros.hxx"
36 #include "servicenames.hxx"
37 #include "ObjectIdentifier.hxx"
38 #include "chartview/ExplicitValueProvider.hxx"
39 #include "chartview/DrawModelWrapper.hxx"
40 #include "AxisHelper.hxx"
41 #include "DiagramHelper.hxx"
43 using namespace ::com::sun::star;
44 using namespace ::com::sun::star::chart2;
46 using ::com::sun::star::uno::Reference;
47 using ::com::sun::star::uno::Sequence;
48 using ::rtl::OUString;
50 namespace chart
52 namespace wrapper
55 Chart2ModelContact::Chart2ModelContact(
56 const Reference< uno::XComponentContext > & xContext ) :
57 m_xContext( xContext ),
58 m_xChartModel( 0 ),
59 m_xChartView(0)
63 Chart2ModelContact::~Chart2ModelContact()
65 this->clear();
68 void Chart2ModelContact::setModel( const ::com::sun::star::uno::Reference<
69 ::com::sun::star::frame::XModel >& xChartModel )
71 this->clear();
72 m_xChartModel = xChartModel;
73 uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartModel, uno::UNO_QUERY );
74 if( xTableFactory.is() )
76 uno::Reference< container::XNameContainer > xDashTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.DashTable" ) ), uno::UNO_QUERY );
77 uno::Reference< container::XNameContainer > xGradientTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.GradientTable" ) ), uno::UNO_QUERY );
78 uno::Reference< container::XNameContainer > xHatchTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.HatchTable" ) ), uno::UNO_QUERY );
79 uno::Reference< container::XNameContainer > xBitmapTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.BitmapTable" ) ), uno::UNO_QUERY );
80 uno::Reference< container::XNameContainer > xTransparencyGradientTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.TransparencyGradientTable" ) ), uno::UNO_QUERY );
81 //C2U( "com.sun.star.drawing.MarkerTable" )
82 m_aTableMap[ C2U( "LineDashName" ) ] = xDashTable;
83 m_aTableMap[ C2U( "FillGradientName" ) ] = xGradientTable;
84 m_aTableMap[ C2U( "FillHatchName" ) ] = xHatchTable;
85 m_aTableMap[ C2U( "FillBitmapName" ) ] = xBitmapTable;
86 m_aTableMap[ C2U( "FillTransparenceGradientName" ) ] = xTransparencyGradientTable;
90 void Chart2ModelContact::clear()
92 m_xChartModel = uno::WeakReference< frame::XModel >(0);
93 m_xChartView.clear();
96 Reference< frame::XModel > Chart2ModelContact::getChartModel() const
98 return Reference< frame::XModel >( m_xChartModel.get(), uno::UNO_QUERY );
101 Reference< chart2::XChartDocument > Chart2ModelContact::getChart2Document() const
103 return Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY );
106 Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
108 return ChartModelHelper::findDiagram( this->getChartModel() );
111 uno::Reference< lang::XUnoTunnel > Chart2ModelContact::getChartView() const
113 if(!m_xChartView.is())
115 // get the chart view
116 Reference<frame::XModel> xModel(m_xChartModel);
117 uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
118 if( xFact.is() )
119 m_xChartView = Reference< lang::XUnoTunnel >( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
121 return m_xChartView;
124 ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const
126 getChartView();
127 if(!m_xChartView.is())
128 return 0;
130 //obtain the ExplicitValueProvider from the chart view
131 ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(m_xChartView->getSomething(
132 ExplicitValueProvider::getUnoTunnelId() ));
133 return pProvider;
136 uno::Reference< drawing::XDrawPage > Chart2ModelContact::getDrawPage()
138 uno::Reference< drawing::XDrawPage > xResult;
139 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
140 if( pProvider )
142 xResult.set( pProvider->getDrawModelWrapper()->getMainDrawPage() );
144 return xResult;
147 sal_Bool Chart2ModelContact::getExplicitValuesForAxis(
148 const Reference< XAxis > & xAxis,
149 ExplicitScaleData & rOutExplicitScale,
150 ExplicitIncrementData & rOutExplicitIncrement )
152 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
153 if( pProvider )
155 return pProvider->getExplicitValuesForAxis(
156 xAxis, rOutExplicitScale, rOutExplicitIncrement );
158 return sal_False;
161 sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
162 const Reference< chart2::XAxis >& xAxis )
164 Reference< chart2::XCoordinateSystem > xCooSys(
165 AxisHelper::getCoordinateSystemOfAxis(
166 xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) );
168 return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
169 , Reference< util::XNumberFormatsSupplier >( m_xChartModel.get(), uno::UNO_QUERY ) );
172 sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForSeries(
173 const Reference< chart2::XDataSeries >& xSeries )
175 return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
176 uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ),
177 xSeries,
178 -1 /*-1 for whole series*/,
179 ChartModelHelper::findDiagram( m_xChartModel )
183 //-----------------------------------------------------------------------------
185 awt::Size Chart2ModelContact::GetPageSize() const
187 return ChartModelHelper::getPageSize(m_xChartModel);
190 awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
192 awt::Rectangle aRect = ExplicitValueProvider::substractAxisTitleSizes(
193 m_xChartModel, getChartView(), rPositionRect );
194 return aRect;
197 awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
199 awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
201 //add axis title sizes to the diagram size
202 aRect = ExplicitValueProvider::addAxisTitleSizes(
203 m_xChartModel, getChartView(), aRect );
205 return aRect;
208 awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
210 awt::Rectangle aRect(0,0,0,0);
211 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
213 if( DiagramPositioningMode_INCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
214 aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
215 else
217 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
218 if( pProvider )
219 aRect = pProvider->getRectangleOfObject( C2U("PlotAreaIncludingAxes") );
221 return aRect;
224 awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
226 awt::Rectangle aRect(0,0,0,0);
227 uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
229 if( DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
230 aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
231 else
233 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
234 if( pProvider )
235 aRect = pProvider->getDiagramRectangleExcludingAxes();
237 return aRect;
240 awt::Size Chart2ModelContact::GetLegendSize() const
242 awt::Size aSize;
243 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
244 if( pProvider )
246 uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( m_xChartModel ) );
247 rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) );
248 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
250 return aSize;
253 awt::Point Chart2ModelContact::GetLegendPosition() const
255 awt::Point aPoint;
256 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
257 if( pProvider )
259 uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( m_xChartModel ) );
260 rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) );
261 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
263 return aPoint;
266 awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference<
267 ::com::sun::star::chart2::XTitle > & xTitle ) const
269 awt::Size aSize;
270 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
271 if( pProvider && xTitle.is() )
273 rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
274 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
276 return aSize;
279 awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference<
280 ::com::sun::star::chart2::XTitle > & xTitle ) const
282 awt::Point aPoint;
283 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
284 if( pProvider && xTitle.is() )
286 rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
287 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
289 return aPoint;
292 awt::Size Chart2ModelContact::GetAxisSize( const uno::Reference<
293 ::com::sun::star::chart2::XAxis > & xAxis ) const
295 awt::Size aSize;
296 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
297 if( pProvider && xAxis.is() )
299 rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
300 aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
302 return aSize;
305 awt::Point Chart2ModelContact::GetAxisPosition( const uno::Reference<
306 ::com::sun::star::chart2::XAxis > & xAxis ) const
308 awt::Point aPoint;
309 ExplicitValueProvider* pProvider( getExplicitValueProvider() );
310 if( pProvider && xAxis.is() )
312 rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
313 aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
315 return aPoint;
318 } // namespace wrapper
319 } // namespace chart