1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Chart2ModelContact.cxx,v $
10 * $Revision: 1.4.44.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "Chart2ModelContact.hxx"
35 #include "ChartModelHelper.hxx"
36 #include "LegendHelper.hxx"
37 #include "CommonConverters.hxx"
39 #include "servicenames.hxx"
40 #include "ObjectIdentifier.hxx"
41 #include "chartview/ExplicitValueProvider.hxx"
42 #include "chartview/DrawModelWrapper.hxx"
43 #include "AxisHelper.hxx"
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::chart2
;
48 using ::com::sun::star::uno::Reference
;
49 using ::com::sun::star::uno::Sequence
;
50 using ::rtl::OUString
;
60 rtl::OUString
lcl_getCIDForDiagram( const Reference
< frame::XModel
>& xChartModel
)
62 uno::Reference
< XDiagram
> xDiagram( ChartModelHelper::findDiagram( xChartModel
) );
63 return ObjectIdentifier::createClassifiedIdentifierForObject( xDiagram
, xChartModel
);
66 } //anonymous namespace
68 Chart2ModelContact::Chart2ModelContact(
69 const Reference
< uno::XComponentContext
> & xContext
) :
70 m_xContext( xContext
),
76 Chart2ModelContact::~Chart2ModelContact()
81 void Chart2ModelContact::setModel( const ::com::sun::star::uno::Reference
<
82 ::com::sun::star::frame::XModel
>& xChartModel
)
85 m_xChartModel
= xChartModel
;
86 uno::Reference
< lang::XMultiServiceFactory
> xTableFactory( xChartModel
, uno::UNO_QUERY
);
87 if( xTableFactory
.is() )
89 uno::Reference
< container::XNameContainer
> xDashTable( xTableFactory
->createInstance( C2U( "com.sun.star.drawing.DashTable" ) ), uno::UNO_QUERY
);
90 uno::Reference
< container::XNameContainer
> xGradientTable( xTableFactory
->createInstance( C2U( "com.sun.star.drawing.GradientTable" ) ), uno::UNO_QUERY
);
91 uno::Reference
< container::XNameContainer
> xHatchTable( xTableFactory
->createInstance( C2U( "com.sun.star.drawing.HatchTable" ) ), uno::UNO_QUERY
);
92 uno::Reference
< container::XNameContainer
> xBitmapTable( xTableFactory
->createInstance( C2U( "com.sun.star.drawing.BitmapTable" ) ), uno::UNO_QUERY
);
93 uno::Reference
< container::XNameContainer
> xTransparencyGradientTable( xTableFactory
->createInstance( C2U( "com.sun.star.drawing.TransparencyGradientTable" ) ), uno::UNO_QUERY
);
94 //C2U( "com.sun.star.drawing.MarkerTable" )
95 m_aTableMap
[ C2U( "LineDashName" ) ] = xDashTable
;
96 m_aTableMap
[ C2U( "FillGradientName" ) ] = xGradientTable
;
97 m_aTableMap
[ C2U( "FillHatchName" ) ] = xHatchTable
;
98 m_aTableMap
[ C2U( "FillBitmapName" ) ] = xBitmapTable
;
99 m_aTableMap
[ C2U( "FillTransparenceGradientName" ) ] = xTransparencyGradientTable
;
103 void Chart2ModelContact::clear()
105 m_xChartModel
= uno::WeakReference
< frame::XModel
>(0);
106 m_xChartView
.clear();
109 Reference
< frame::XModel
> Chart2ModelContact::getChartModel() const
111 return Reference
< frame::XModel
>( m_xChartModel
.get(), uno::UNO_QUERY
);
114 Reference
< chart2::XChartDocument
> Chart2ModelContact::getChart2Document() const
116 return Reference
< chart2::XChartDocument
>( m_xChartModel
.get(), uno::UNO_QUERY
);
119 Reference
< chart2::XDiagram
> Chart2ModelContact::getChart2Diagram() const
121 return ChartModelHelper::findDiagram( this->getChartModel() );
124 ExplicitValueProvider
* Chart2ModelContact::getExplicitValueProvider() const
126 if(!m_xChartView
.is())
128 // get the chart view
129 Reference
<frame::XModel
> xModel(m_xChartModel
);
130 uno::Reference
< lang::XMultiServiceFactory
> xFact( xModel
, uno::UNO_QUERY
);
132 m_xChartView
= Reference
< lang::XUnoTunnel
>( xFact
->createInstance( CHART_VIEW_SERVICE_NAME
), uno::UNO_QUERY
);
135 if(!m_xChartView
.is())
138 //obtain the ExplicitValueProvider from the chart view
139 ExplicitValueProvider
* pProvider
= reinterpret_cast<ExplicitValueProvider
*>(m_xChartView
->getSomething(
140 ExplicitValueProvider::getUnoTunnelId() ));
144 uno::Reference
< drawing::XDrawPage
> Chart2ModelContact::getDrawPage()
146 uno::Reference
< drawing::XDrawPage
> xResult
;
147 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
150 xResult
.set( pProvider
->getDrawModelWrapper()->getMainDrawPage() );
155 sal_Bool
Chart2ModelContact::getExplicitValuesForAxis(
156 const Reference
< XAxis
> & xAxis
,
157 ExplicitScaleData
& rOutExplicitScale
,
158 ExplicitIncrementData
& rOutExplicitIncrement
)
160 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
163 return pProvider
->getExplicitValuesForAxis(
164 xAxis
, rOutExplicitScale
, rOutExplicitIncrement
);
169 sal_Int32
Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
170 const Reference
< chart2::XAxis
>& xAxis
)
172 Reference
< chart2::XCoordinateSystem
> xCooSys(
173 AxisHelper::getCoordinateSystemOfAxis(
174 xAxis
, ChartModelHelper::findDiagram( m_xChartModel
) ) );
176 return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis
, xCooSys
177 , Reference
< util::XNumberFormatsSupplier
>( m_xChartModel
.get(), uno::UNO_QUERY
) );
180 sal_Int32
Chart2ModelContact::getExplicitNumberFormatKeyForSeries(
181 const Reference
< chart2::XDataSeries
>& xSeries
)
183 return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
184 uno::Reference
< beans::XPropertySet
>( xSeries
, uno::UNO_QUERY
),
186 -1 /*-1 for whole series*/,
187 ChartModelHelper::findDiagram( m_xChartModel
)
191 //-----------------------------------------------------------------------------
193 awt::Size
Chart2ModelContact::GetPageSize() const
195 return ChartModelHelper::getPageSize(m_xChartModel
);
198 awt::Rectangle
Chart2ModelContact::GetDiagramRectangleInclusive() const
200 awt::Rectangle aRect
;
202 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
205 aRect
= pProvider
->getRectangleOfObject( lcl_getCIDForDiagram( m_xChartModel
) );
207 //add axis title sizes to the diagram size
208 aRect
= ExplicitValueProvider::calculateDiagramPositionAndSizeInclusiveTitle(
209 m_xChartModel
, m_xChartView
, aRect
);
214 awt::Size
Chart2ModelContact::GetDiagramSizeInclusive() const
216 return ToSize( this->GetDiagramRectangleInclusive() );
219 awt::Point
Chart2ModelContact::GetDiagramPositionInclusive() const
221 return ToPoint( this->GetDiagramRectangleInclusive() );
224 awt::Size
Chart2ModelContact::GetLegendSize() const
227 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
230 uno::Reference
< chart2::XLegend
> xLegend( LegendHelper::getLegend( m_xChartModel
) );
231 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend
, m_xChartModel
) );
232 aSize
= ToSize( pProvider
->getRectangleOfObject( aCID
) );
237 awt::Point
Chart2ModelContact::GetLegendPosition() const
240 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
243 uno::Reference
< chart2::XLegend
> xLegend( LegendHelper::getLegend( m_xChartModel
) );
244 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend
, m_xChartModel
) );
245 aPoint
= ToPoint( pProvider
->getRectangleOfObject( aCID
) );
250 awt::Size
Chart2ModelContact::GetTitleSize( const uno::Reference
<
251 ::com::sun::star::chart2::XTitle
> & xTitle
) const
254 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
255 if( pProvider
&& xTitle
.is() )
257 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle
, m_xChartModel
) );
258 aSize
= ToSize( pProvider
->getRectangleOfObject( aCID
) );
263 awt::Point
Chart2ModelContact::GetTitlePosition( const uno::Reference
<
264 ::com::sun::star::chart2::XTitle
> & xTitle
) const
267 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
268 if( pProvider
&& xTitle
.is() )
270 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle
, m_xChartModel
) );
271 aPoint
= ToPoint( pProvider
->getRectangleOfObject( aCID
) );
276 awt::Size
Chart2ModelContact::GetAxisSize( const uno::Reference
<
277 ::com::sun::star::chart2::XAxis
> & xAxis
) const
280 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
281 if( pProvider
&& xAxis
.is() )
283 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis
, m_xChartModel
) );
284 aSize
= ToSize( pProvider
->getRectangleOfObject( aCID
) );
289 awt::Point
Chart2ModelContact::GetAxisPosition( const uno::Reference
<
290 ::com::sun::star::chart2::XAxis
> & xAxis
) const
293 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
294 if( pProvider
&& xAxis
.is() )
296 rtl::OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis
, m_xChartModel
) );
297 aPoint
= ToPoint( pProvider
->getRectangleOfObject( aCID
) );
302 } // namespace wrapper