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: ChartModelHelper.cxx,v $
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"
33 #include "ChartModelHelper.hxx"
35 #include "DiagramHelper.hxx"
36 #include "DataSourceHelper.hxx"
37 #include "ControllerLockGuard.hxx"
38 #include "UndoManager.hxx"
39 #include "RangeHighlighter.hxx"
40 #include "InternalDataProvider.hxx"
42 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
43 #include <com/sun/star/chart2/XChartDocument.hpp>
44 #include <com/sun/star/chart2/XChartTypeContainer.hpp>
45 #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
46 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
47 #include <com/sun/star/embed/Aspects.hpp>
48 #include <com/sun/star/embed/XVisualObject.hpp>
49 #include <com/sun/star/view/XSelectionChangeListener.hpp>
51 // header for define DBG_ASSERT
52 #include <tools/debug.hxx>
54 //.............................................................................
57 //.............................................................................
58 using namespace ::com::sun::star
;
59 using namespace ::com::sun::star::chart2
;
62 uno::Reference
< chart2::XUndoManager
> ChartModelHelper::createUndoManager()
64 return new UndoManager();
68 uno::Reference
< chart2::data::XRangeHighlighter
> ChartModelHelper::createRangeHighlighter(
69 const uno::Reference
< view::XSelectionSupplier
> & xSelectionSupplier
)
71 return new RangeHighlighter( xSelectionSupplier
);
75 uno::Reference
< chart2::data::XDataProvider
> ChartModelHelper::createInternalDataProvider()
77 return new InternalDataProvider();
81 uno::Reference
< chart2::data::XDataProvider
> ChartModelHelper::createInternalDataProvider(
82 const uno::Reference
< ::com::sun::star::chart::XChartDataArray
>& xDataToCopy
)
84 return new InternalDataProvider( xDataToCopy
);
88 uno::Reference
< chart2::data::XDataProvider
> ChartModelHelper::createInternalDataProvider(
89 const uno::Reference
< ::com::sun::star::chart2::XChartDocument
>& xChartDoc
)
91 return new InternalDataProvider( xChartDoc
);
95 uno::Reference
< XDiagram
> ChartModelHelper::findDiagram( const uno::Reference
< frame::XModel
>& xModel
)
97 uno::Reference
< XChartDocument
> xChartDoc( xModel
, uno::UNO_QUERY
);
99 return ChartModelHelper::findDiagram( xChartDoc
);
104 uno::Reference
< XDiagram
> ChartModelHelper::findDiagram( const uno::Reference
< chart2::XChartDocument
>& xChartDoc
)
109 return xChartDoc
->getFirstDiagram();
111 catch( uno::Exception
& ex
)
113 ASSERT_EXCEPTION( ex
);
119 ::std::vector
< uno::Reference
< XDataSeries
> > ChartModelHelper::getDataSeries(
120 const uno::Reference
< XChartDocument
> & xChartDoc
)
122 ::std::vector
< uno::Reference
< XDataSeries
> > aResult
;
124 uno::Reference
< XDiagram
> xDiagram
= ChartModelHelper::findDiagram( xChartDoc
);
126 aResult
= DiagramHelper::getDataSeriesFromDiagram( xDiagram
);
132 ::std::vector
< uno::Reference
< XDataSeries
> > ChartModelHelper::getDataSeries(
133 const uno::Reference
< frame::XModel
> & xModel
)
135 return getDataSeries( uno::Reference
< chart2::XChartDocument
>( xModel
, uno::UNO_QUERY
));
139 uno::Reference
< XChartType
> ChartModelHelper::getChartTypeOfSeries(
140 const uno::Reference
< frame::XModel
>& xModel
141 , const uno::Reference
< XDataSeries
>& xGivenDataSeries
)
143 return DiagramHelper::getChartTypeOfSeries( ChartModelHelper::findDiagram( xModel
), xGivenDataSeries
);
146 awt::Size
ChartModelHelper::getPageSize( const uno::Reference
< frame::XModel
>& xModel
)
148 awt::Size
aPageSize( 8000, 7000 );
149 uno::Reference
< embed::XVisualObject
> xVisualObject(xModel
,uno::UNO_QUERY
);
150 DBG_ASSERT(xVisualObject
.is(),"need xVisualObject for page size");
151 if( xVisualObject
.is() )
152 aPageSize
= xVisualObject
->getVisualAreaSize( embed::Aspects::MSOLE_CONTENT
);
156 void ChartModelHelper::setPageSize( const awt::Size
& rSize
, const uno::Reference
< frame::XModel
>& xModel
)
158 uno::Reference
< embed::XVisualObject
> xVisualObject(xModel
,uno::UNO_QUERY
);
159 DBG_ASSERT(xVisualObject
.is(),"need xVisualObject for page size");
160 if( xVisualObject
.is() )
161 xVisualObject
->setVisualAreaSize( embed::Aspects::MSOLE_CONTENT
, rSize
);
164 void ChartModelHelper::triggerRangeHighlighting( const uno::Reference
< frame::XModel
>& xModel
)
166 uno::Reference
< chart2::data::XDataReceiver
> xDataReceiver( xModel
, uno::UNO_QUERY
);
167 if( xDataReceiver
.is() )
169 uno::Reference
< view::XSelectionChangeListener
> xSelectionChangeListener( xDataReceiver
->getRangeHighlighter(), uno::UNO_QUERY
);
170 //trigger selection of cell range
171 if( xSelectionChangeListener
.is() )
173 lang::EventObject
aEvent( xSelectionChangeListener
);
174 xSelectionChangeListener
->selectionChanged( aEvent
);
179 bool ChartModelHelper::isIncludeHiddenCells( const uno::Reference
< frame::XModel
>& xChartModel
)
181 bool bIncluded
= true; // hidden cells are included by default.
183 uno::Reference
< chart2::XDiagram
> xDiagram( ChartModelHelper::findDiagram(xChartModel
) );
187 uno::Reference
< beans::XPropertySet
> xProp( xDiagram
, uno::UNO_QUERY
);
193 xProp
->getPropertyValue(C2U("IncludeHiddenCells")) >>= bIncluded
;
195 catch( const beans::UnknownPropertyException
& )
202 bool ChartModelHelper::setIncludeHiddenCells( bool bIncludeHiddenCells
, const uno::Reference
< frame::XModel
>& xChartModel
)
204 bool bChanged
= false;
207 ControllerLockGuard
aLockedControllers( xChartModel
);
209 uno::Reference
< beans::XPropertySet
> xDiagramProperties( ChartModelHelper::findDiagram(xChartModel
), uno::UNO_QUERY
);
210 if (xDiagramProperties
.is())
212 bool bOldValue
= bIncludeHiddenCells
;
213 xDiagramProperties
->getPropertyValue( C2U("IncludeHiddenCells") ) >>= bOldValue
;
214 if( bOldValue
== bIncludeHiddenCells
)
217 //set the property on all instances in all cases to get the different objects in sync!
219 uno::Any aNewValue
= uno::makeAny(bIncludeHiddenCells
);
223 uno::Reference
< chart2::XChartDocument
> xChartDoc( xChartModel
, uno::UNO_QUERY
);
226 uno::Reference
< beans::XPropertySet
> xDataProviderProperties( xChartDoc
->getDataProvider(), uno::UNO_QUERY
);
227 if( xDataProviderProperties
.is() )
228 xDataProviderProperties
->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue
);
231 catch( const beans::UnknownPropertyException
& )
233 //the property is optional!
238 uno::Reference
< chart2::data::XDataSource
> xUsedData( DataSourceHelper::getUsedData( xChartModel
) );
241 uno::Reference
< beans::XPropertySet
> xProp
;
242 uno::Sequence
< uno::Reference
< chart2::data::XLabeledDataSequence
> > aData( xUsedData
->getDataSequences());
243 for( sal_Int32 i
=0; i
<aData
.getLength(); ++i
)
245 xProp
.set( uno::Reference
< beans::XPropertySet
>( aData
[i
]->getValues(), uno::UNO_QUERY
) );
247 xProp
->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue
);
248 xProp
.set( uno::Reference
< beans::XPropertySet
>( aData
[i
]->getLabel(), uno::UNO_QUERY
) );
250 xProp
->setPropertyValue(C2U("IncludeHiddenCells"), aNewValue
);
254 catch( const beans::UnknownPropertyException
& )
256 //the property is optional!
259 xDiagramProperties
->setPropertyValue( C2U("IncludeHiddenCells"), aNewValue
);
262 catch (uno::Exception
& e
)
269 //.............................................................................
271 //.............................................................................