Debian Codegraph @

chart2/source/controller/chartapiwrapper/Chart2ModelContact.cxx

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include "Chart2ModelContact.hxx"
21 #include <Legend.hxx>
22 #include <LegendHelper.hxx>
23 #include <CommonConverters.hxx>
24 #include <ObjectIdentifier.hxx>
25 #include <chartview/DrawModelWrapper.hxx>
26 #include <Axis.hxx>
27 #include <AxisHelper.hxx>
28 #include <ChartView.hxx>
29 #include <DiagramHelper.hxx>
30 #include <BaseCoordinateSystem.hxx>
31
32 #include <ChartModel.hxx>
33
34 #include <comphelper/diagnose_ex.hxx>
35
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::chart2;
38
39 using ::com::sun::star::uno::Reference;
40
41 namespace chart::wrapper
42 {
43
44 Chart2ModelContact::Chart2ModelContact(
45 const Reference< uno::XComponentContext > & xContext ) :
46 m_xContext( xContext ),
47 m_xChartModel( nullptr )
48 {
49 }
50
51 Chart2ModelContact::~Chart2ModelContact()
52 {
53 clear();
54 }
55
56 void Chart2ModelContact::setDocumentModel( ChartModel* pChartModel )
57 {
58 clear();
59 m_xChartModel = pChartModel;
60 if( !pChartModel )
61 return;
62
63 m_aTableMap[u"LineDashName"_ustr].set(pChartModel->createInstance(u"com.sun.star.drawing.DashTable"_ustr), uno::UNO_QUERY);
64 m_aTableMap[u"FillGradientName"_ustr].set(pChartModel->createInstance(u"com.sun.star.drawing.GradientTable"_ustr), uno::UNO_QUERY);
65 m_aTableMap[u"FillHatchName"_ustr].set(pChartModel->createInstance(u"com.sun.star.drawing.HatchTable"_ustr), uno::UNO_QUERY);
66 m_aTableMap[u"FillBitmapName"_ustr].set(pChartModel->createInstance(u"com.sun.star.drawing.BitmapTable"_ustr), uno::UNO_QUERY);
67 m_aTableMap[u"FillTransparenceGradientName"_ustr].set(pChartModel->createInstance(u"com.sun.star.drawing.TransparencyGradientTable"_ustr), uno::UNO_QUERY);
68 }
69
70 void Chart2ModelContact::clear()
71 {
72 m_xChartModel.clear();
73 m_xChartView.clear();
74 }
75
76 rtl::Reference< ChartModel > Chart2ModelContact::getDocumentModel() const
77 {
78 return m_xChartModel;
79 }
80
81 rtl::Reference< ::chart::Diagram > Chart2ModelContact::getDiagram() const
82 {
83 try
84 {
85 rtl::Reference<ChartModel> xChartModel = getDocumentModel();
86 if( xChartModel)
87 return xChartModel->getFirstChartDiagram();
88 }
89 catch( const uno::Exception & )
90 {
91 DBG_UNHANDLED_EXCEPTION("chart2");
92 }
93 return nullptr;
94 }
95
96 rtl::Reference< ::chart::ChartView > const & Chart2ModelContact::getChartView() const
97 {
98 if(!m_xChartView.is())
99 {
100 // get the chart view
101 rtl::Reference<ChartModel> xChartModel( m_xChartModel );
102 if( xChartModel )
103 m_xChartView = xChartModel->createChartView();
104 }
105 return m_xChartView;
106 }
107
108 rtl::Reference<SvxDrawPage> Chart2ModelContact::getDrawPage() const
109 {
110 rtl::Reference<SvxDrawPage> xResult;
111 rtl::Reference< ChartView > const & rxChartView = getChartView();
112 if( rxChartView )
113 {
114 xResult = rxChartView->getDrawModelWrapper()->getMainDrawPage();
115 }
116 return xResult;
117 }
118
119 void Chart2ModelContact::getExplicitValuesForAxis(
120 const rtl::Reference< Axis > & xAxis,
121 ExplicitScaleData & rOutExplicitScale,
122 ExplicitIncrementData & rOutExplicitIncrement )
123 {
124 rtl::Reference< ChartView > const & rxChartView = getChartView();
125 if( rxChartView )
126 {
127 rxChartView->getExplicitValuesForAxis(
128 xAxis, rOutExplicitScale, rOutExplicitIncrement );
129 }
130 }
131
132 sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
133 const rtl::Reference< ::chart::Axis >& xAxis )
134 {
135 rtl::Reference< BaseCoordinateSystem > xCooSys(
136 AxisHelper::getCoordinateSystemOfAxis(
137 xAxis, m_xChartModel.get()->getFirstChartDiagram() ) );
138
139 return ChartView::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
140 , m_xChartModel.get() );
141 }
142
143 awt::Size Chart2ModelContact::GetPageSize() const
144 {
145 return m_xChartModel.get()->getPageSize();
146 }
147
148 awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
149 {
150 awt::Rectangle aRect = ChartView::AddSubtractAxisTitleSizes(
151 *m_xChartModel.get(), getChartView().get(), rPositionRect, true );
152 return aRect;
153 }
154
155 awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
156 {
157 awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
158
159 //add axis title sizes to the diagram size
160 aRect = ChartView::AddSubtractAxisTitleSizes(
161 *m_xChartModel.get(), getChartView().get(), aRect, false );
162
163 return aRect;
164 }
165
166 awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
167 {
168 awt::Rectangle aRect(0,0,0,0);
169 rtl::Reference< Diagram > xDiagram = m_xChartModel.get()->getFirstChartDiagram();
170
171 if( xDiagram && xDiagram->getDiagramPositioningMode() == DiagramPositioningMode::Including )
172 aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel.get());
173 else
174 {
175 rtl::Reference< ChartView > const & rxChartView = getChartView();
176 if( rxChartView )
177 aRect = rxChartView->getRectangleOfObject(u"PlotAreaIncludingAxes"_ustr);
178 }
179 return aRect;
180 }
181
182 awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
183 {
184 awt::Rectangle aRect(0,0,0,0);
185 rtl::Reference< Diagram > xDiagram = m_xChartModel.get()->getFirstChartDiagram();
186
187 if( xDiagram && xDiagram->getDiagramPositioningMode() == DiagramPositioningMode::Excluding )
188 aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel.get());
189 else
190 {
191 rtl::Reference< ChartView > const & rxChartView = getChartView();
192 if( rxChartView )
193 aRect = rxChartView->getDiagramRectangleExcludingAxes();
194 }
195 return aRect;
196 }
197
198 awt::Size Chart2ModelContact::GetLegendSize() const
199 {
200 awt::Size aSize;
201 rtl::Reference< ChartView > const & rxChartView = getChartView();
202 if( rxChartView )
203 {
204 rtl::Reference< Legend > xLegend = LegendHelper::getLegend( *m_xChartModel.get() );
205 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) );
206 aSize = ToSize( rxChartView->getRectangleOfObject( aCID ) );
207 }
208 return aSize;
209 }
210
211 awt::Point Chart2ModelContact::GetLegendPosition() const
212 {
213 awt::Point aPoint;
214 rtl::Reference< ChartView > const & rxChartView = getChartView();
215 if( rxChartView )
216 {
217 rtl::Reference< Legend > xLegend = LegendHelper::getLegend( *m_xChartModel.get() );
218 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) );
219 aPoint = ToPoint( rxChartView->getRectangleOfObject( aCID ) );
220 }
221 return aPoint;
222 }
223
224 awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference< css::chart2::XTitle > & xTitle ) const
225 {
226 awt::Size aSize;
227 rtl::Reference< ChartView > const & rxChartView = getChartView();
228 if( rxChartView && xTitle.is() )
229 {
230 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
231 aSize = ToSize( rxChartView->getRectangleOfObject( aCID ) );
232 }
233 return aSize;
234 }
235
236 awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference< css::chart2::XTitle > & xTitle ) const
237 {
238 awt::Point aPoint;
239 rtl::Reference< ChartView > const & rxChartView = getChartView();
240 if( rxChartView && xTitle.is() )
241 {
242 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel.get() ) );
243 aPoint = ToPoint( rxChartView->getRectangleOfObject( aCID ) );
244 }
245 return aPoint;
246 }
247
248 awt::Size Chart2ModelContact::GetAxisSize( const uno::Reference< css::chart2::XAxis > & xAxis ) const
249 {
250 awt::Size aSize;
251 rtl::Reference< ChartView > const & rxChartView = getChartView();
252 if( rxChartView && xAxis.is() )
253 {
254 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel.get() ) );
255 aSize = ToSize( rxChartView->getRectangleOfObject( aCID ) );
256 }
257 return aSize;
258 }
259
260 awt::Point Chart2ModelContact::GetAxisPosition( const uno::Reference< css::chart2::XAxis > & xAxis ) const
261 {
262 awt::Point aPoint;
263 rtl::Reference< ChartView > const & rxChartView = getChartView();
264 if( rxChartView && xAxis.is() )
265 {
266 OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel.get() ) );
267 aPoint = ToPoint( rxChartView->getRectangleOfObject( aCID ) );
268 }
269 return aPoint;
270 }
271
272 } // namespace chart::wrapper
273
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */