1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
23 #include <LegendHelper.hxx>
24 #include <CommonConverters.hxx>
25 #include <servicenames.hxx>
26 #include <ObjectIdentifier.hxx>
27 #include <chartview/ExplicitValueProvider.hxx>
28 #include <chartview/DrawModelWrapper.hxx>
30 #include <AxisHelper.hxx>
31 #include <ChartView.hxx>
32 #include <DiagramHelper.hxx>
33 #include <BaseCoordinateSystem.hxx>
35 #include <ChartModel.hxx>
37 #include <com/sun/star/chart2/XDataSeries.hpp>
38 #include <comphelper/diagnose_ex.hxx>
40 using namespace ::com::sun::star
;
41 using namespace ::com::sun::star::chart2
;
43 using ::com::sun::star::uno::Reference
;
45 namespace chart::wrapper
48 Chart2ModelContact::Chart2ModelContact(
49 const Reference
< uno::XComponentContext
> & xContext
) :
50 m_xContext( xContext
),
51 m_xChartModel( nullptr )
55 Chart2ModelContact::~Chart2ModelContact()
60 void Chart2ModelContact::setDocumentModel( ChartModel
* pChartModel
)
63 m_xChartModel
= pChartModel
;
67 m_aTableMap
[u
"LineDashName"_ustr
].set(pChartModel
->createInstance(u
"com.sun.star.drawing.DashTable"_ustr
), uno::UNO_QUERY
);
68 m_aTableMap
[u
"FillGradientName"_ustr
].set(pChartModel
->createInstance(u
"com.sun.star.drawing.GradientTable"_ustr
), uno::UNO_QUERY
);
69 m_aTableMap
[u
"FillHatchName"_ustr
].set(pChartModel
->createInstance(u
"com.sun.star.drawing.HatchTable"_ustr
), uno::UNO_QUERY
);
70 m_aTableMap
[u
"FillBitmapName"_ustr
].set(pChartModel
->createInstance(u
"com.sun.star.drawing.BitmapTable"_ustr
), uno::UNO_QUERY
);
71 m_aTableMap
[u
"FillTransparenceGradientName"_ustr
].set(pChartModel
->createInstance(u
"com.sun.star.drawing.TransparencyGradientTable"_ustr
), uno::UNO_QUERY
);
74 void Chart2ModelContact::clear()
76 m_xChartModel
.clear();
80 rtl::Reference
< ChartModel
> Chart2ModelContact::getDocumentModel() const
85 rtl::Reference
< ::chart::Diagram
> Chart2ModelContact::getDiagram() const
89 rtl::Reference
<ChartModel
> xChartModel
= getDocumentModel();
91 return xChartModel
->getFirstChartDiagram();
93 catch( const uno::Exception
& )
95 DBG_UNHANDLED_EXCEPTION("chart2");
100 rtl::Reference
< ::chart::ChartView
> const & Chart2ModelContact::getChartView() const
102 if(!m_xChartView
.is())
104 // get the chart view
105 rtl::Reference
<ChartModel
> xChartModel( m_xChartModel
);
108 auto xInstance
= xChartModel
->createInstance( CHART_VIEW_SERVICE_NAME
);
109 auto pChartView
= dynamic_cast<ChartView
*>(xInstance
.get());
110 assert(!xInstance
|| pChartView
);
111 m_xChartView
= pChartView
;
117 ExplicitValueProvider
* Chart2ModelContact::getExplicitValueProvider() const
121 //obtain the ExplicitValueProvider from the chart view
122 return m_xChartView
.get();
125 rtl::Reference
<SvxDrawPage
> Chart2ModelContact::getDrawPage() const
127 rtl::Reference
<SvxDrawPage
> xResult
;
128 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
131 xResult
= pProvider
->getDrawModelWrapper()->getMainDrawPage();
136 void Chart2ModelContact::getExplicitValuesForAxis(
137 const rtl::Reference
< Axis
> & xAxis
,
138 ExplicitScaleData
& rOutExplicitScale
,
139 ExplicitIncrementData
& rOutExplicitIncrement
)
141 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
144 pProvider
->getExplicitValuesForAxis(
145 xAxis
, rOutExplicitScale
, rOutExplicitIncrement
);
149 sal_Int32
Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
150 const rtl::Reference
< ::chart::Axis
>& xAxis
)
152 rtl::Reference
< BaseCoordinateSystem
> xCooSys(
153 AxisHelper::getCoordinateSystemOfAxis(
154 xAxis
, m_xChartModel
.get()->getFirstChartDiagram() ) );
156 return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis
, xCooSys
157 , m_xChartModel
.get() );
160 sal_Int32
Chart2ModelContact::getExplicitNumberFormatKeyForSeries(
161 const Reference
< chart2::XDataSeries
>& xSeries
)
163 return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
164 uno::Reference
< beans::XPropertySet
>( xSeries
, uno::UNO_QUERY
));
167 awt::Size
Chart2ModelContact::GetPageSize() const
169 return ChartModelHelper::getPageSize(m_xChartModel
.get());
172 awt::Rectangle
Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle
& rPositionRect
)
174 awt::Rectangle aRect
= ExplicitValueProvider::AddSubtractAxisTitleSizes(
175 *m_xChartModel
.get(), getChartView().get(), rPositionRect
, true );
179 awt::Rectangle
Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
181 awt::Rectangle
aRect( GetDiagramRectangleIncludingAxes() );
183 //add axis title sizes to the diagram size
184 aRect
= ExplicitValueProvider::AddSubtractAxisTitleSizes(
185 *m_xChartModel
.get(), getChartView().get(), aRect
, false );
190 awt::Rectangle
Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
192 awt::Rectangle
aRect(0,0,0,0);
193 rtl::Reference
< Diagram
> xDiagram
= m_xChartModel
.get()->getFirstChartDiagram();
195 if( xDiagram
&& xDiagram
->getDiagramPositioningMode() == DiagramPositioningMode::Including
)
196 aRect
= DiagramHelper::getDiagramRectangleFromModel(m_xChartModel
.get());
199 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
201 aRect
= pProvider
->getRectangleOfObject(u
"PlotAreaIncludingAxes"_ustr
);
206 awt::Rectangle
Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
208 awt::Rectangle
aRect(0,0,0,0);
209 rtl::Reference
< Diagram
> xDiagram
= m_xChartModel
.get()->getFirstChartDiagram();
211 if( xDiagram
&& xDiagram
->getDiagramPositioningMode() == DiagramPositioningMode::Excluding
)
212 aRect
= DiagramHelper::getDiagramRectangleFromModel(m_xChartModel
.get());
215 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
217 aRect
= pProvider
->getDiagramRectangleExcludingAxes();
222 awt::Size
Chart2ModelContact::GetLegendSize() const
225 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
228 rtl::Reference
< Legend
> xLegend
= LegendHelper::getLegend( *m_xChartModel
.get() );
229 OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend
, m_xChartModel
) );
230 aSize
= ToSize( pProvider
->getRectangleOfObject( aCID
) );
235 awt::Point
Chart2ModelContact::GetLegendPosition() const
238 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
241 rtl::Reference
< Legend
> xLegend
= LegendHelper::getLegend( *m_xChartModel
.get() );
242 OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend
, m_xChartModel
) );
243 aPoint
= ToPoint( pProvider
->getRectangleOfObject( aCID
) );
248 awt::Size
Chart2ModelContact::GetTitleSize( const uno::Reference
< css::chart2::XTitle
> & xTitle
) const
251 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
252 if( pProvider
&& xTitle
.is() )
254 OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle
, m_xChartModel
) );
255 aSize
= ToSize( pProvider
->getRectangleOfObject( aCID
) );
260 awt::Point
Chart2ModelContact::GetTitlePosition( const uno::Reference
< css::chart2::XTitle
> & xTitle
) const
263 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
264 if( pProvider
&& xTitle
.is() )
266 OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle
, m_xChartModel
.get() ) );
267 aPoint
= ToPoint( pProvider
->getRectangleOfObject( aCID
) );
272 awt::Size
Chart2ModelContact::GetAxisSize( const uno::Reference
< css::chart2::XAxis
> & xAxis
) const
275 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
276 if( pProvider
&& xAxis
.is() )
278 OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis
, m_xChartModel
.get() ) );
279 aSize
= ToSize( pProvider
->getRectangleOfObject( aCID
) );
284 awt::Point
Chart2ModelContact::GetAxisPosition( const uno::Reference
< css::chart2::XAxis
> & xAxis
) const
287 ExplicitValueProvider
* pProvider( getExplicitValueProvider() );
288 if( pProvider
&& xAxis
.is() )
290 OUString
aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis
, m_xChartModel
.get() ) );
291 aPoint
= ToPoint( pProvider
->getRectangleOfObject( aCID
) );
296 } // namespace chart::wrapper
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */