1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "Chart2ModelContact.hxx"
28cdf0e10cSrcweir #include "ChartModelHelper.hxx"
29cdf0e10cSrcweir #include "LegendHelper.hxx"
30cdf0e10cSrcweir #include "CommonConverters.hxx"
31cdf0e10cSrcweir #include "macros.hxx"
32cdf0e10cSrcweir #include "servicenames.hxx"
33cdf0e10cSrcweir #include "ObjectIdentifier.hxx"
34cdf0e10cSrcweir #include "chartview/ExplicitValueProvider.hxx"
35cdf0e10cSrcweir #include "chartview/DrawModelWrapper.hxx"
36cdf0e10cSrcweir #include "AxisHelper.hxx"
37cdf0e10cSrcweir #include "DiagramHelper.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir using namespace ::com::sun::star;
40cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
43cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
44cdf0e10cSrcweir using ::rtl::OUString;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace chart
47cdf0e10cSrcweir {
48cdf0e10cSrcweir namespace wrapper
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 
Chart2ModelContact(const Reference<uno::XComponentContext> & xContext)51cdf0e10cSrcweir Chart2ModelContact::Chart2ModelContact(
52cdf0e10cSrcweir     const Reference< uno::XComponentContext > & xContext ) :
53cdf0e10cSrcweir         m_xContext( xContext ),
54cdf0e10cSrcweir         m_xChartModel( 0 ),
55cdf0e10cSrcweir         m_xChartView(0)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
~Chart2ModelContact()59cdf0e10cSrcweir Chart2ModelContact::~Chart2ModelContact()
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     this->clear();
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
setModel(const::com::sun::star::uno::Reference<::com::sun::star::frame::XModel> & xChartModel)64cdf0e10cSrcweir void Chart2ModelContact::setModel( const ::com::sun::star::uno::Reference<
65cdf0e10cSrcweir                        ::com::sun::star::frame::XModel >& xChartModel )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     this->clear();
68cdf0e10cSrcweir     m_xChartModel = xChartModel;
69cdf0e10cSrcweir     uno::Reference< lang::XMultiServiceFactory > xTableFactory( xChartModel, uno::UNO_QUERY );
70cdf0e10cSrcweir     if( xTableFactory.is() )
71cdf0e10cSrcweir     {
72cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xDashTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.DashTable" ) ), uno::UNO_QUERY );
73cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xGradientTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.GradientTable" ) ), uno::UNO_QUERY );
74cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xHatchTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.HatchTable" ) ), uno::UNO_QUERY );
75cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xBitmapTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.BitmapTable" ) ), uno::UNO_QUERY );
76cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xTransparencyGradientTable( xTableFactory->createInstance( C2U( "com.sun.star.drawing.TransparencyGradientTable" ) ), uno::UNO_QUERY );
77cdf0e10cSrcweir         //C2U( "com.sun.star.drawing.MarkerTable" )
78cdf0e10cSrcweir         m_aTableMap[ C2U( "LineDashName" ) ] = xDashTable;
79cdf0e10cSrcweir         m_aTableMap[ C2U( "FillGradientName" ) ] = xGradientTable;
80cdf0e10cSrcweir         m_aTableMap[ C2U( "FillHatchName" ) ] = xHatchTable;
81cdf0e10cSrcweir         m_aTableMap[ C2U( "FillBitmapName" ) ] = xBitmapTable;
82cdf0e10cSrcweir         m_aTableMap[ C2U( "FillTransparenceGradientName" ) ] = xTransparencyGradientTable;
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
clear()86cdf0e10cSrcweir void Chart2ModelContact::clear()
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     m_xChartModel = uno::WeakReference< frame::XModel >(0);
89cdf0e10cSrcweir     m_xChartView.clear();
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
getChartModel() const92cdf0e10cSrcweir Reference< frame::XModel > Chart2ModelContact::getChartModel() const
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     return Reference< frame::XModel >( m_xChartModel.get(), uno::UNO_QUERY );
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
getChart2Document() const97cdf0e10cSrcweir Reference< chart2::XChartDocument > Chart2ModelContact::getChart2Document() const
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     return Reference< chart2::XChartDocument >( m_xChartModel.get(), uno::UNO_QUERY );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
getChart2Diagram() const102cdf0e10cSrcweir Reference< chart2::XDiagram > Chart2ModelContact::getChart2Diagram() const
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     return ChartModelHelper::findDiagram( this->getChartModel() );
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
getChartView() const107cdf0e10cSrcweir uno::Reference< lang::XUnoTunnel > Chart2ModelContact::getChartView() const
108cdf0e10cSrcweir {
109cdf0e10cSrcweir     if(!m_xChartView.is())
110cdf0e10cSrcweir     {
111cdf0e10cSrcweir         // get the chart view
112cdf0e10cSrcweir         Reference<frame::XModel> xModel(m_xChartModel);
113cdf0e10cSrcweir         uno::Reference< lang::XMultiServiceFactory > xFact( xModel, uno::UNO_QUERY );
114cdf0e10cSrcweir 	    if( xFact.is() )
115cdf0e10cSrcweir             m_xChartView = Reference< lang::XUnoTunnel >( xFact->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY );
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir     return m_xChartView;
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
getExplicitValueProvider() const120cdf0e10cSrcweir ExplicitValueProvider* Chart2ModelContact::getExplicitValueProvider() const
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     getChartView();
123cdf0e10cSrcweir     if(!m_xChartView.is())
124cdf0e10cSrcweir         return 0;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     //obtain the ExplicitValueProvider from the chart view
127cdf0e10cSrcweir     ExplicitValueProvider* pProvider = reinterpret_cast<ExplicitValueProvider*>(m_xChartView->getSomething(
128cdf0e10cSrcweir         ExplicitValueProvider::getUnoTunnelId() ));
129cdf0e10cSrcweir     return pProvider;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
getDrawPage()132cdf0e10cSrcweir uno::Reference< drawing::XDrawPage > Chart2ModelContact::getDrawPage()
133cdf0e10cSrcweir {
134cdf0e10cSrcweir     uno::Reference< drawing::XDrawPage > xResult;
135cdf0e10cSrcweir     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
136cdf0e10cSrcweir     if( pProvider )
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         xResult.set( pProvider->getDrawModelWrapper()->getMainDrawPage() );
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir     return xResult;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
getExplicitValuesForAxis(const Reference<XAxis> & xAxis,ExplicitScaleData & rOutExplicitScale,ExplicitIncrementData & rOutExplicitIncrement)143cdf0e10cSrcweir sal_Bool Chart2ModelContact::getExplicitValuesForAxis(
144cdf0e10cSrcweir     const Reference< XAxis > & xAxis,
145cdf0e10cSrcweir     ExplicitScaleData &  rOutExplicitScale,
146cdf0e10cSrcweir     ExplicitIncrementData & rOutExplicitIncrement )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
149cdf0e10cSrcweir     if( pProvider )
150cdf0e10cSrcweir     {
151cdf0e10cSrcweir         return pProvider->getExplicitValuesForAxis(
152cdf0e10cSrcweir             xAxis, rOutExplicitScale, rOutExplicitIncrement );
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir     return sal_False;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
getExplicitNumberFormatKeyForAxis(const Reference<chart2::XAxis> & xAxis)157cdf0e10cSrcweir sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForAxis(
158cdf0e10cSrcweir             const Reference< chart2::XAxis >& xAxis )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     Reference< chart2::XCoordinateSystem > xCooSys(
161cdf0e10cSrcweir         AxisHelper::getCoordinateSystemOfAxis(
162cdf0e10cSrcweir               xAxis, ChartModelHelper::findDiagram( m_xChartModel ) ) );
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     return ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( xAxis, xCooSys
165cdf0e10cSrcweir               , Reference< util::XNumberFormatsSupplier >( m_xChartModel.get(), uno::UNO_QUERY ) );
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
getExplicitNumberFormatKeyForSeries(const Reference<chart2::XDataSeries> & xSeries)168cdf0e10cSrcweir sal_Int32 Chart2ModelContact::getExplicitNumberFormatKeyForSeries(
169cdf0e10cSrcweir             const Reference< chart2::XDataSeries >& xSeries )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir     return ExplicitValueProvider::getExplicitNumberFormatKeyForDataLabel(
172cdf0e10cSrcweir         uno::Reference< beans::XPropertySet >( xSeries, uno::UNO_QUERY ),
173cdf0e10cSrcweir         xSeries,
174cdf0e10cSrcweir         -1 /*-1 for whole series*/,
175cdf0e10cSrcweir         ChartModelHelper::findDiagram( m_xChartModel )
176cdf0e10cSrcweir         );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir //-----------------------------------------------------------------------------
180cdf0e10cSrcweir 
GetPageSize() const181cdf0e10cSrcweir awt::Size Chart2ModelContact::GetPageSize() const
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     return ChartModelHelper::getPageSize(m_xChartModel);
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
SubstractAxisTitleSizes(const awt::Rectangle & rPositionRect)186cdf0e10cSrcweir awt::Rectangle Chart2ModelContact::SubstractAxisTitleSizes( const awt::Rectangle& rPositionRect )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir     awt::Rectangle aRect = ExplicitValueProvider::substractAxisTitleSizes(
189cdf0e10cSrcweir         m_xChartModel, getChartView(), rPositionRect );
190cdf0e10cSrcweir     return aRect;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
GetDiagramRectangleIncludingTitle() const193cdf0e10cSrcweir awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingTitle() const
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     awt::Rectangle aRect( GetDiagramRectangleIncludingAxes() );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     //add axis title sizes to the diagram size
198cdf0e10cSrcweir     aRect = ExplicitValueProvider::addAxisTitleSizes(
199cdf0e10cSrcweir         m_xChartModel, getChartView(), aRect );
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     return aRect;
202cdf0e10cSrcweir }
203cdf0e10cSrcweir 
GetDiagramRectangleIncludingAxes() const204cdf0e10cSrcweir awt::Rectangle Chart2ModelContact::GetDiagramRectangleIncludingAxes() const
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     awt::Rectangle aRect(0,0,0,0);
207cdf0e10cSrcweir     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     if( DiagramPositioningMode_INCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
210cdf0e10cSrcweir         aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
211cdf0e10cSrcweir     else
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         ExplicitValueProvider* pProvider( getExplicitValueProvider() );
214cdf0e10cSrcweir         if( pProvider )
215cdf0e10cSrcweir             aRect = pProvider->getRectangleOfObject( C2U("PlotAreaIncludingAxes") );
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir     return aRect;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
GetDiagramRectangleExcludingAxes() const220cdf0e10cSrcweir awt::Rectangle Chart2ModelContact::GetDiagramRectangleExcludingAxes() const
221cdf0e10cSrcweir {
222cdf0e10cSrcweir     awt::Rectangle aRect(0,0,0,0);
223cdf0e10cSrcweir     uno::Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( m_xChartModel ) );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     if( DiagramPositioningMode_EXCLUDING == DiagramHelper::getDiagramPositioningMode( xDiagram ) )
226cdf0e10cSrcweir         aRect = DiagramHelper::getDiagramRectangleFromModel(m_xChartModel);
227cdf0e10cSrcweir     else
228cdf0e10cSrcweir     {
229cdf0e10cSrcweir         ExplicitValueProvider* pProvider( getExplicitValueProvider() );
230cdf0e10cSrcweir         if( pProvider )
231cdf0e10cSrcweir             aRect = pProvider->getDiagramRectangleExcludingAxes();
232cdf0e10cSrcweir     }
233cdf0e10cSrcweir     return aRect;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
GetLegendSize() const236cdf0e10cSrcweir awt::Size Chart2ModelContact::GetLegendSize() const
237cdf0e10cSrcweir {
238cdf0e10cSrcweir     awt::Size aSize;
239cdf0e10cSrcweir     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
240cdf0e10cSrcweir     if( pProvider )
241cdf0e10cSrcweir     {
242cdf0e10cSrcweir         uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( m_xChartModel ) );
243cdf0e10cSrcweir         rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) );
244cdf0e10cSrcweir         aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir     return aSize;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
GetLegendPosition() const249cdf0e10cSrcweir awt::Point Chart2ModelContact::GetLegendPosition() const
250cdf0e10cSrcweir {
251cdf0e10cSrcweir     awt::Point aPoint;
252cdf0e10cSrcweir     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
253cdf0e10cSrcweir     if( pProvider )
254cdf0e10cSrcweir     {
255cdf0e10cSrcweir         uno::Reference< chart2::XLegend > xLegend( LegendHelper::getLegend( m_xChartModel ) );
256cdf0e10cSrcweir         rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xLegend, m_xChartModel ) );
257cdf0e10cSrcweir         aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir     return aPoint;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
GetTitleSize(const uno::Reference<::com::sun::star::chart2::XTitle> & xTitle) const262cdf0e10cSrcweir awt::Size Chart2ModelContact::GetTitleSize( const uno::Reference<
263cdf0e10cSrcweir         ::com::sun::star::chart2::XTitle > & xTitle ) const
264cdf0e10cSrcweir {
265cdf0e10cSrcweir     awt::Size aSize;
266cdf0e10cSrcweir     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
267cdf0e10cSrcweir     if( pProvider && xTitle.is() )
268cdf0e10cSrcweir     {
269cdf0e10cSrcweir         rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
270cdf0e10cSrcweir         aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
271cdf0e10cSrcweir     }
272cdf0e10cSrcweir     return aSize;
273cdf0e10cSrcweir }
274cdf0e10cSrcweir 
GetTitlePosition(const uno::Reference<::com::sun::star::chart2::XTitle> & xTitle) const275cdf0e10cSrcweir awt::Point Chart2ModelContact::GetTitlePosition( const uno::Reference<
276cdf0e10cSrcweir         ::com::sun::star::chart2::XTitle > & xTitle ) const
277cdf0e10cSrcweir {
278cdf0e10cSrcweir     awt::Point aPoint;
279cdf0e10cSrcweir     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
280cdf0e10cSrcweir     if( pProvider && xTitle.is() )
281cdf0e10cSrcweir     {
282cdf0e10cSrcweir         rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xTitle, m_xChartModel ) );
283cdf0e10cSrcweir         aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
284cdf0e10cSrcweir     }
285cdf0e10cSrcweir     return aPoint;
286cdf0e10cSrcweir }
287cdf0e10cSrcweir 
GetAxisSize(const uno::Reference<::com::sun::star::chart2::XAxis> & xAxis) const288cdf0e10cSrcweir awt::Size Chart2ModelContact::GetAxisSize( const uno::Reference<
289cdf0e10cSrcweir         ::com::sun::star::chart2::XAxis > & xAxis ) const
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     awt::Size aSize;
292cdf0e10cSrcweir     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
293cdf0e10cSrcweir     if( pProvider && xAxis.is() )
294cdf0e10cSrcweir     {
295cdf0e10cSrcweir         rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
296cdf0e10cSrcweir         aSize = ToSize( pProvider->getRectangleOfObject( aCID ) );
297cdf0e10cSrcweir     }
298cdf0e10cSrcweir     return aSize;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
GetAxisPosition(const uno::Reference<::com::sun::star::chart2::XAxis> & xAxis) const301cdf0e10cSrcweir awt::Point Chart2ModelContact::GetAxisPosition( const uno::Reference<
302cdf0e10cSrcweir         ::com::sun::star::chart2::XAxis > & xAxis ) const
303cdf0e10cSrcweir {
304cdf0e10cSrcweir     awt::Point aPoint;
305cdf0e10cSrcweir     ExplicitValueProvider* pProvider( getExplicitValueProvider() );
306cdf0e10cSrcweir     if( pProvider && xAxis.is() )
307cdf0e10cSrcweir     {
308cdf0e10cSrcweir         rtl::OUString aCID( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, m_xChartModel ) );
309cdf0e10cSrcweir         aPoint = ToPoint( pProvider->getRectangleOfObject( aCID ) );
310cdf0e10cSrcweir     }
311cdf0e10cSrcweir     return aPoint;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314cdf0e10cSrcweir } //  namespace wrapper
315cdf0e10cSrcweir } //  namespace chart
316