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"
30 #include "ChartModelHelper.hxx"
32 #include "DiagramHelper.hxx"
33 #include "DataSourceHelper.hxx"
34 #include "ControllerLockGuard.hxx"
35 #include "RangeHighlighter.hxx"
36 #include "InternalDataProvider.hxx"
38 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
39 #include <com/sun/star/chart2/XChartDocument.hpp>
40 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
41 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
42 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
43 #include <com/sun/star/embed/Aspects.hpp>
44 #include <com/sun/star/embed/XVisualObject.hpp>
45 #include <com/sun/star/view/XSelectionChangeListener.hpp>
47 // header for define DBG_ASSERT
48 #include <tools/debug.hxx>
50 //.............................................................................
53 //.............................................................................
54 using namespace ::com::sun::star
;
55 using namespace ::com::sun::star::chart2
;
58 uno::Reference
< chart2::data::XRangeHighlighter
> ChartModelHelper::createRangeHighlighter(
59 const uno::Reference
< view::XSelectionSupplier
> & xSelectionSupplier
)
61 return new RangeHighlighter( xSelectionSupplier
);
65 uno::Reference
< chart2::data::XDataProvider
> ChartModelHelper::createInternalDataProvider(
66 const uno::Reference
< ::com::sun::star::chart2::XChartDocument
>& xChartDoc
, bool bConnectToModel
)
68 return new InternalDataProvider( xChartDoc
, bConnectToModel
);
72 uno::Reference
< XDiagram
> ChartModelHelper::findDiagram( const uno::Reference
< frame::XModel
>& xModel
)
74 uno::Reference
< XChartDocument
> xChartDoc( xModel
, uno::UNO_QUERY
);
76 return ChartModelHelper::findDiagram( xChartDoc
);
81 uno::Reference
< XDiagram
> ChartModelHelper::findDiagram( const uno::Reference
< chart2::XChartDocument
>& xChartDoc
)
86 return xChartDoc
->getFirstDiagram();
88 catch( uno::Exception
& ex
)
90 ASSERT_EXCEPTION( ex
);
96 uno::Reference
< XCoordinateSystem
> ChartModelHelper::getFirstCoordinateSystem( const uno::Reference
< frame::XModel
>& xModel
)
98 uno::Reference
< XCoordinateSystem
> XCooSys
;
99 uno::Reference
< XCoordinateSystemContainer
> xCooSysCnt( ChartModelHelper::findDiagram( xModel
), uno::UNO_QUERY
);
100 if( xCooSysCnt
.is() )
102 uno::Sequence
< uno::Reference
< XCoordinateSystem
> > aCooSysSeq( xCooSysCnt
->getCoordinateSystems() );
103 if( aCooSysSeq
.getLength() )
104 XCooSys
= aCooSysSeq
[0];
110 ::std::vector
< uno::Reference
< XDataSeries
> > ChartModelHelper::getDataSeries(
111 const uno::Reference
< XChartDocument
> & xChartDoc
)
113 ::std::vector
< uno::Reference
< XDataSeries
> > aResult
;
115 uno::Reference
< XDiagram
> xDiagram
= ChartModelHelper::findDiagram( xChartDoc
);
117 aResult
= DiagramHelper::getDataSeriesFromDiagram( xDiagram
);
123 ::std::vector
< uno::Reference
< XDataSeries
> > ChartModelHelper::getDataSeries(
124 const uno::Reference
< frame::XModel
> & xModel
)
126 return getDataSeries( uno::Reference
< chart2::XChartDocument
>( xModel
, uno::UNO_QUERY
));
130 uno::Reference
< XChartType
> ChartModelHelper::getChartTypeOfSeries(
131 const uno::Reference
< frame::XModel
>& xModel
132 , const uno::Reference
< XDataSeries
>& xGivenDataSeries
)
134 return DiagramHelper::getChartTypeOfSeries( ChartModelHelper::findDiagram( xModel
), xGivenDataSeries
);
137 awt::Size
ChartModelHelper::getDefaultPageSize()
139 return awt::Size( 16000, 9000 );
142 awt::Size
ChartModelHelper::getPageSize( const uno::Reference
< frame::XModel
>& xModel
)
144 awt::Size
aPageSize( ChartModelHelper::getDefaultPageSize() );
145 uno::Reference
< embed::XVisualObject
> xVisualObject(xModel
,uno::UNO_QUERY
);
146 DBG_ASSERT(xVisualObject
.is(),"need xVisualObject for page size");
147 if( xVisualObject
.is() )
148 aPageSize
= xVisualObject
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
);
152 void ChartModelHelper::setPageSize( const awt::Size
& rSize
, const uno::Reference
< frame::XModel
>& xModel
)
154 uno::Reference
< embed::XVisualObject
> xVisualObject(xModel
,uno::UNO_QUERY
);
155 DBG_ASSERT(xVisualObject
.is(),"need xVisualObject for page size");
156 if( xVisualObject
.is() )
157 xVisualObject
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, rSize
);
160 void ChartModelHelper::triggerRangeHighlighting( const uno::Reference
< frame::XModel
>& xModel
)
162 uno::Reference
< chart2::data::XDataReceiver
> xDataReceiver( xModel
, uno::UNO_QUERY
);
163 if( xDataReceiver
.is() )
165 uno::Reference
< view::XSelectionChangeListener
> xSelectionChangeListener( xDataReceiver
->getRangeHighlighter(), uno::UNO_QUERY
);
166 //trigger selection of cell range
167 if( xSelectionChangeListener
.is() )
169 lang::EventObject
aEvent( xSelectionChangeListener
);
170 xSelectionChangeListener
->selectionChanged( aEvent
);
175 bool ChartModelHelper::isIncludeHiddenCells( const uno::Reference
< frame::XModel
>& xChartModel
)
177 bool bIncluded
= true; // hidden cells are included by default.
179 uno::Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram(xChartModel
) );
183 uno::Reference
< beans::XPropertySet
> xProp( xDiagram
, uno::UNO_QUERY
);
189 xProp
->getPropertyValue(C2U("IncludeHiddenCells")) >>= bIncluded
;
191 catch( const beans::UnknownPropertyException
& )
198 bool ChartModelHelper::setIncludeHiddenCells( bool bIncludeHiddenCells
, const uno::Reference
< frame::XModel
>& xChartModel
)
200 bool bChanged
= false;
203 ControllerLockGuard
aLockedControllers( xChartModel
);
205 uno::Reference
< beans::XPropertySet
> xDiagramProperties( ChartModelHelper::findDiagram(xChartModel
), uno::UNO_QUERY
);
206 if (xDiagramProperties
.is())
208 bool bOldValue
= bIncludeHiddenCells
;
209 xDiagramProperties
->getPropertyValue( C2U("IncludeHiddenCells") ) >>= bOldValue
;
210 if( bOldValue
== bIncludeHiddenCells
)
213 //set the property on all instances in all cases to get the different objects in sync!
215 uno::Any aNewValue
= uno::makeAny(bIncludeHiddenCells
);
219 uno::Reference
< chart2::XChartDocument
> xChartDoc( xChartModel
, uno::UNO_QUERY
);
222 uno::Reference
< beans::XPropertySet
> xDataProviderProperties( xChartDoc
->getDataProvider(), uno::UNO_QUERY
);
223 if( xDataProviderProperties
.is() )
224 xDataProviderProperties
->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue
);
227 catch( const beans::UnknownPropertyException
& )
229 //the property is optional!
234 uno::Reference
< chart2::data::XDataSource
> xUsedData( DataSourceHelper::getUsedData( xChartModel
) );
237 uno::Reference
< beans::XPropertySet
> xProp
;
238 uno::Sequence
< uno::Reference
< chart2::data::XLabeledDataSequence
> > aData( xUsedData
->getDataSequences());
239 for( sal_Int32 i
=0; i
<aData
.getLength(); ++i
)
241 xProp
.set( uno::Reference
< beans::XPropertySet
>( aData
[i
]->getValues(), uno::UNO_QUERY
) );
243 xProp
->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue
);
244 xProp
.set( uno::Reference
< beans::XPropertySet
>( aData
[i
]->getLabel(), uno::UNO_QUERY
) );
246 xProp
->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue
);
250 catch( const beans::UnknownPropertyException
& )
252 //the property is optional!
255 xDiagramProperties
->setPropertyValue( C2U("IncludeHiddenCells"), aNewValue
);
258 catch (uno::Exception
& e
)
265 //.............................................................................
267 //.............................................................................