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"
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
;
55 Chart2ModelContact::Chart2ModelContact(
56 const Reference
< uno::XComponentContext
> & xContext
) :
57 m_xContext( xContext
),
63 Chart2ModelContact::~Chart2ModelContact()
68 void Chart2ModelContact::setModel( const ::com::sun::star::uno::Reference
<
69 ::com::sun::star::frame::XModel
>& xChartModel
)
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);
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
);
119 m_xChartView
= Reference
< lang::XUnoTunnel
>( xFact
->createInstance( CHART_VIEW_SERVICE_NAME
), uno::UNO_QUERY
);
124 ExplicitValueProvider
* Chart2ModelContact::getExplicitValueProvider() const
127 if(!m_xChartView
.is())
130 //obtain the ExplicitValueProvider from the chart view
131 ExplicitValueProvider
* pProvider
= reinterpret_cast<ExplicitValueProvider
*>(m_xChartView
->getSomething(
132 ExplicitValueProvider::getUnoTunnelId() ));
136 uno::Reference
< drawing::XDrawPage
> Chart2ModelContact::getDrawPage()
138 uno::Reference
< drawing::XDrawPage
> xResult
;
139 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
142 xResult
.set( pProvider
->getDrawModelWrapper()->getMainDrawPage() );
147 sal_Bool
Chart2ModelContact::getExplicitValuesForAxis(
148 const Reference
< XAxis
> & xAxis
,
149 ExplicitScaleData
& rOutExplicitScale
,
150 ExplicitIncrementData
& rOutExplicitIncrement
)
152 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
155 return pProvider
->getExplicitValuesForAxis(
156 xAxis
, rOutExplicitScale
, rOutExplicitIncrement
);
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
),
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
);
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
);
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
);
217 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
219 aRect
= pProvider
->getRectangleOfObject( C2U("PlotAreaIncludingAxes") );
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
);
233 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
235 aRect
= pProvider
->getDiagramRectangleExcludingAxes();
240 awt::Size
Chart2ModelContact::GetLegendSize() const
243 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
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
) );
253 awt::Point
Chart2ModelContact::GetLegendPosition() const
256 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
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
) );
266 awt::Size
Chart2ModelContact::GetTitleSize( const uno::Reference
<
267 ::com::sun::star::chart2::XTitle
> & xTitle
) const
270 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
271 if( pProvider
&& xTitle
.is() )
273 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle
, m_xChartModel
) );
274 aSize
= ToSize( pProvider
->getRectangleOfObject( aCID
) );
279 awt::Point
Chart2ModelContact::GetTitlePosition( const uno::Reference
<
280 ::com::sun::star::chart2::XTitle
> & xTitle
) const
283 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
284 if( pProvider
&& xTitle
.is() )
286 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle
, m_xChartModel
) );
287 aPoint
= ToPoint( pProvider
->getRectangleOfObject( aCID
) );
292 awt::Size
Chart2ModelContact::GetAxisSize( const uno::Reference
<
293 ::com::sun::star::chart2::XAxis
> & xAxis
) const
296 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
297 if( pProvider
&& xAxis
.is() )
299 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis
, m_xChartModel
) );
300 aSize
= ToSize( pProvider
->getRectangleOfObject( aCID
) );
305 awt::Point
Chart2ModelContact::GetAxisPosition( const uno::Reference
<
306 ::com::sun::star::chart2::XAxis
> & xAxis
) const
309 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
310 if( pProvider
&& xAxis
.is() )
312 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis
, m_xChartModel
) );
313 aPoint
= ToPoint( pProvider
->getRectangleOfObject( aCID
) );
318 } // namespace wrapper