1cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5cde9e8dcSAndrew Rist * distributed with this work for additional information
6cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18cde9e8dcSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20cde9e8dcSAndrew Rist *************************************************************/
21cde9e8dcSAndrew Rist
22cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "ObjectHierarchy.hxx"
28cdf0e10cSrcweir #include "ObjectIdentifier.hxx"
29cdf0e10cSrcweir #include "ChartModelHelper.hxx"
30cdf0e10cSrcweir #include "DiagramHelper.hxx"
31cdf0e10cSrcweir #include "RegressionCurveHelper.hxx"
32cdf0e10cSrcweir #include "AxisHelper.hxx"
33cdf0e10cSrcweir #include "chartview/ExplicitValueProvider.hxx"
34cdf0e10cSrcweir #include "macros.hxx"
35cdf0e10cSrcweir #include "LineProperties.hxx"
36cdf0e10cSrcweir #include "ChartTypeHelper.hxx"
37cdf0e10cSrcweir #include "DataSeriesHelper.hxx"
38cdf0e10cSrcweir #include "LegendHelper.hxx"
39cdf0e10cSrcweir #include "chartview/DrawModelWrapper.hxx"
40cdf0e10cSrcweir
41cdf0e10cSrcweir #include <map>
42cdf0e10cSrcweir #include <algorithm>
43cdf0e10cSrcweir
44cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp>
45cdf0e10cSrcweir #include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
46cdf0e10cSrcweir #include <com/sun/star/chart2/XChartTypeContainer.hpp>
47cdf0e10cSrcweir #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
48cdf0e10cSrcweir #include <com/sun/star/chart/ErrorBarStyle.hpp>
49cdf0e10cSrcweir
50cdf0e10cSrcweir #include <com/sun/star/container/XIndexAccess.hpp>
51cdf0e10cSrcweir #include <com/sun/star/awt/Key.hpp>
52cdf0e10cSrcweir #include <com/sun/star/awt/KeyModifier.hpp>
53cdf0e10cSrcweir
54cdf0e10cSrcweir using namespace ::com::sun::star;
55cdf0e10cSrcweir using namespace ::com::sun::star::chart2;
56cdf0e10cSrcweir
57cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
58cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
59cdf0e10cSrcweir using ::rtl::OUString;
60cdf0e10cSrcweir
61cdf0e10cSrcweir namespace
62cdf0e10cSrcweir {
63cdf0e10cSrcweir
64cdf0e10cSrcweir struct lcl_ObjectToOID : public ::std::unary_function< Reference< uno::XInterface >, ::chart::ObjectIdentifier >
65cdf0e10cSrcweir {
lcl_ObjectToOID__anonc0019acf0111::lcl_ObjectToOID66cdf0e10cSrcweir explicit lcl_ObjectToOID( const Reference< chart2::XChartDocument > & xChartDoc ) :
67cdf0e10cSrcweir m_xModel( xChartDoc, uno::UNO_QUERY )
68cdf0e10cSrcweir {}
69cdf0e10cSrcweir
operator ()__anonc0019acf0111::lcl_ObjectToOID70cdf0e10cSrcweir ::chart::ObjectIdentifier operator() ( const Reference< uno::XInterface > & xObj )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir return ::chart::ObjectIdentifier( ::chart::ObjectIdentifier::createClassifiedIdentifierForObject( xObj, m_xModel ) );
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir private:
76cdf0e10cSrcweir Reference< frame::XModel > m_xModel;
77cdf0e10cSrcweir };
78cdf0e10cSrcweir
lcl_getChildOIDs(::chart::ObjectHierarchy::tChildContainer & rOutChildren,const Reference<container::XIndexAccess> & xShapes)79cdf0e10cSrcweir void lcl_getChildOIDs(
80cdf0e10cSrcweir ::chart::ObjectHierarchy::tChildContainer& rOutChildren,
81cdf0e10cSrcweir const Reference< container::XIndexAccess >& xShapes )
82cdf0e10cSrcweir {
83cdf0e10cSrcweir if( xShapes.is())
84cdf0e10cSrcweir {
85cdf0e10cSrcweir sal_Int32 nCount = xShapes->getCount();
86cdf0e10cSrcweir for( sal_Int32 i=0; i<nCount; ++i)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir Reference< beans::XPropertySet > xShapeProp( xShapes->getByIndex( i ), uno::UNO_QUERY );
89cdf0e10cSrcweir if( xShapeProp.is())
90cdf0e10cSrcweir {
91cdf0e10cSrcweir Reference< beans::XPropertySetInfo > xInfo( xShapeProp->getPropertySetInfo());
92cdf0e10cSrcweir OUString aName;
93cdf0e10cSrcweir if( xInfo.is() &&
94cdf0e10cSrcweir xInfo->hasPropertyByName( C2U("Name")) &&
95cdf0e10cSrcweir (xShapeProp->getPropertyValue( C2U("Name")) >>= aName ) &&
96*9ec58d04SHerbert Dürr !aName.isEmpty() &&
97cdf0e10cSrcweir ::chart::ObjectIdentifier::isCID( aName ))
98cdf0e10cSrcweir {
99cdf0e10cSrcweir rOutChildren.push_back( ::chart::ObjectIdentifier( aName ) );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir Reference< container::XIndexAccess > xNewShapes( xShapeProp, uno::UNO_QUERY );
102cdf0e10cSrcweir if( xNewShapes.is())
103cdf0e10cSrcweir lcl_getChildOIDs( rOutChildren, xNewShapes );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir }
106cdf0e10cSrcweir }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
lcl_addAxisTitle(const Reference<XAxis> & xAxis,::chart::ObjectHierarchy::tChildContainer & rContainer,const Reference<frame::XModel> & xChartModel)109cdf0e10cSrcweir void lcl_addAxisTitle( const Reference< XAxis >& xAxis, ::chart::ObjectHierarchy::tChildContainer& rContainer, const Reference< frame::XModel >& xChartModel )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir Reference< XTitled > xAxisTitled( xAxis, uno::UNO_QUERY );
112cdf0e10cSrcweir if( xAxisTitled.is())
113cdf0e10cSrcweir {
114cdf0e10cSrcweir Reference< XTitle > xAxisTitle( xAxisTitled->getTitleObject());
115cdf0e10cSrcweir if( xAxisTitle.is())
116cdf0e10cSrcweir rContainer.push_back(
117cdf0e10cSrcweir ::chart::ObjectIdentifier( ::chart::ObjectIdentifier::createClassifiedIdentifierForObject( xAxisTitle, xChartModel ) ) );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir } // anonymous namespace
122cdf0e10cSrcweir
123cdf0e10cSrcweir namespace chart
124cdf0e10cSrcweir {
125cdf0e10cSrcweir
126cdf0e10cSrcweir namespace impl
127cdf0e10cSrcweir {
128cdf0e10cSrcweir
129cdf0e10cSrcweir class ImplObjectHierarchy
130cdf0e10cSrcweir {
131cdf0e10cSrcweir public:
132cdf0e10cSrcweir explicit ImplObjectHierarchy(
133cdf0e10cSrcweir const Reference< XChartDocument >& xChartDocument,
134cdf0e10cSrcweir ExplicitValueProvider* pExplicitValueProvider,
135cdf0e10cSrcweir bool bFlattenDiagram, bool bOrderingForElementSelector );
136cdf0e10cSrcweir
137cdf0e10cSrcweir bool hasChildren( const ObjectHierarchy::tOID& rParent );
138cdf0e10cSrcweir ObjectHierarchy::tChildContainer getChildren( const ObjectHierarchy::tOID& rParent );
139cdf0e10cSrcweir ObjectHierarchy::tChildContainer getSiblings( const ObjectHierarchy::tOID& rNode );
140cdf0e10cSrcweir
141cdf0e10cSrcweir ObjectHierarchy::tOID getParent( const ObjectHierarchy::tOID& rOID );
142cdf0e10cSrcweir
143cdf0e10cSrcweir private:
144cdf0e10cSrcweir void createTree( const Reference< XChartDocument > & xChartDocument );
145cdf0e10cSrcweir void createAxesTree(
146cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rContainer,
147cdf0e10cSrcweir const Reference< XChartDocument > & xChartDoc,
148cdf0e10cSrcweir const Reference< XDiagram > & xDiagram );
149cdf0e10cSrcweir void createDiagramTree(
150cdf0e10cSrcweir ObjectHierarchy::tChildContainer& rContainer,
151cdf0e10cSrcweir const Reference< XChartDocument >& xChartDoc,
152cdf0e10cSrcweir const Reference< XDiagram >& xDiagram );
153cdf0e10cSrcweir void createDataSeriesTree(
154cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rOutDiagramSubContainer,
155cdf0e10cSrcweir const Reference< XDiagram > & xDiagram );
156cdf0e10cSrcweir void createWallAndFloor(
157cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rContainer,
158cdf0e10cSrcweir const Reference< XDiagram > & xDiagram );
159cdf0e10cSrcweir void createLegendTree(
160cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rContainer,
161cdf0e10cSrcweir const Reference< XChartDocument > & xChartDoc,
162cdf0e10cSrcweir const Reference< XDiagram > & xDiagram );
163cdf0e10cSrcweir void createAdditionalShapesTree( ObjectHierarchy::tChildContainer& rContainer );
164cdf0e10cSrcweir
165cdf0e10cSrcweir ObjectHierarchy::tOID getParentImpl(
166cdf0e10cSrcweir const ObjectHierarchy::tOID& rParentOID,
167cdf0e10cSrcweir const ObjectHierarchy::tOID& rOID );
168cdf0e10cSrcweir
169cdf0e10cSrcweir typedef ::std::map< ObjectHierarchy::tOID, ObjectHierarchy::tChildContainer >
170cdf0e10cSrcweir tChildMap;
171cdf0e10cSrcweir tChildMap m_aChildMap;
172cdf0e10cSrcweir ExplicitValueProvider* m_pExplicitValueProvider;
173cdf0e10cSrcweir bool m_bFlattenDiagram;
174cdf0e10cSrcweir bool m_bOrderingForElementSelector;
175cdf0e10cSrcweir };
176cdf0e10cSrcweir
ImplObjectHierarchy(const Reference<XChartDocument> & xChartDocument,ExplicitValueProvider * pExplicitValueProvider,bool bFlattenDiagram,bool bOrderingForElementSelector)177cdf0e10cSrcweir ImplObjectHierarchy::ImplObjectHierarchy(
178cdf0e10cSrcweir const Reference< XChartDocument >& xChartDocument,
179cdf0e10cSrcweir ExplicitValueProvider* pExplicitValueProvider,
180cdf0e10cSrcweir bool bFlattenDiagram,
181cdf0e10cSrcweir bool bOrderingForElementSelector ) :
182cdf0e10cSrcweir m_pExplicitValueProvider( pExplicitValueProvider ),
183cdf0e10cSrcweir m_bFlattenDiagram( bFlattenDiagram ),
184cdf0e10cSrcweir m_bOrderingForElementSelector( bOrderingForElementSelector )
185cdf0e10cSrcweir {
186cdf0e10cSrcweir createTree( xChartDocument );
187cdf0e10cSrcweir // don't remember this helper to avoid access after lifetime
188cdf0e10cSrcweir m_pExplicitValueProvider = 0;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
createTree(const Reference<XChartDocument> & xChartDocument)191cdf0e10cSrcweir void ImplObjectHierarchy::createTree( const Reference< XChartDocument >& xChartDocument )
192cdf0e10cSrcweir {
193cdf0e10cSrcweir m_aChildMap = tChildMap();//clear tree
194cdf0e10cSrcweir
195cdf0e10cSrcweir if( !xChartDocument.is() )
196cdf0e10cSrcweir return;
197cdf0e10cSrcweir
198cdf0e10cSrcweir //@todo: change ObjectIdentifier to take an XChartDocument rather than XModel
199cdf0e10cSrcweir Reference< frame::XModel > xModel( xChartDocument, uno::UNO_QUERY );
200cdf0e10cSrcweir Reference< XDiagram > xDiagram( ChartModelHelper::findDiagram( xChartDocument ) );
201cdf0e10cSrcweir ObjectHierarchy::tOID aDiaOID;
202cdf0e10cSrcweir if( xDiagram.is() )
203cdf0e10cSrcweir aDiaOID = ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForObject( xDiagram, xModel ) );
204cdf0e10cSrcweir ObjectHierarchy::tChildContainer aTopLevelContainer;
205cdf0e10cSrcweir
206cdf0e10cSrcweir // First Level
207cdf0e10cSrcweir
208cdf0e10cSrcweir // Chart Area
209cdf0e10cSrcweir if( m_bOrderingForElementSelector )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir aTopLevelContainer.push_back( ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, OUString() ) ) );
212cdf0e10cSrcweir if( xDiagram.is() )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir aTopLevelContainer.push_back( aDiaOID );
215cdf0e10cSrcweir createWallAndFloor( aTopLevelContainer, xDiagram );
216cdf0e10cSrcweir createLegendTree( aTopLevelContainer, xChartDocument, xDiagram );
217cdf0e10cSrcweir }
218cdf0e10cSrcweir }
219cdf0e10cSrcweir
220cdf0e10cSrcweir // Main Title
221cdf0e10cSrcweir Reference< XTitled > xDocTitled( xChartDocument, uno::UNO_QUERY );
222cdf0e10cSrcweir if( xDocTitled.is())
223cdf0e10cSrcweir {
224cdf0e10cSrcweir Reference< XTitle > xMainTitle( xDocTitled->getTitleObject());
225cdf0e10cSrcweir if( xMainTitle.is())
226cdf0e10cSrcweir aTopLevelContainer.push_back(
227cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForObject( xMainTitle, xModel ) ) );
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
230cdf0e10cSrcweir if( xDiagram.is())
231cdf0e10cSrcweir {
232cdf0e10cSrcweir // Sub Title. Note: This is interpreted of being top level
233cdf0e10cSrcweir Reference< XTitled > xDiaTitled( xDiagram, uno::UNO_QUERY );
234cdf0e10cSrcweir if( xDiaTitled.is())
235cdf0e10cSrcweir {
236cdf0e10cSrcweir Reference< XTitle > xSubTitle( xDiaTitled->getTitleObject());
237cdf0e10cSrcweir if( xSubTitle.is())
238cdf0e10cSrcweir aTopLevelContainer.push_back(
239cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForObject( xSubTitle, xModel ) ) );
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
242cdf0e10cSrcweir if( !m_bOrderingForElementSelector )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir // Axis Titles. Note: These are interpreted of being top level
245cdf0e10cSrcweir Sequence< Reference< XAxis > > aAxes( AxisHelper::getAllAxesOfDiagram( xDiagram ) );
246cdf0e10cSrcweir for( sal_Int32 i=0; i<aAxes.getLength(); ++i )
247cdf0e10cSrcweir lcl_addAxisTitle( aAxes[i], aTopLevelContainer, xModel );
248cdf0e10cSrcweir
249cdf0e10cSrcweir // Diagram
250cdf0e10cSrcweir aTopLevelContainer.push_back( aDiaOID );
251cdf0e10cSrcweir }
252cdf0e10cSrcweir
253cdf0e10cSrcweir if( m_bFlattenDiagram )
254cdf0e10cSrcweir createDiagramTree( aTopLevelContainer, xChartDocument, xDiagram );
255cdf0e10cSrcweir else
256cdf0e10cSrcweir {
257cdf0e10cSrcweir ObjectHierarchy::tChildContainer aSubContainer;
258cdf0e10cSrcweir createDiagramTree( aSubContainer, xChartDocument, xDiagram );
259cdf0e10cSrcweir if( !aSubContainer.empty() )
260cdf0e10cSrcweir m_aChildMap[ aDiaOID ] = aSubContainer;
261cdf0e10cSrcweir }
262cdf0e10cSrcweir
263cdf0e10cSrcweir if( !m_bOrderingForElementSelector )
264cdf0e10cSrcweir createLegendTree( aTopLevelContainer, xChartDocument, xDiagram );
265cdf0e10cSrcweir }
266cdf0e10cSrcweir
267cdf0e10cSrcweir // #i12587# support for shapes in chart
268cdf0e10cSrcweir if ( !m_bOrderingForElementSelector )
269cdf0e10cSrcweir {
270cdf0e10cSrcweir createAdditionalShapesTree( aTopLevelContainer );
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir // Chart Area
274cdf0e10cSrcweir if( !m_bOrderingForElementSelector )
275cdf0e10cSrcweir aTopLevelContainer.push_back(
276cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_PAGE, OUString() ) ) );
277cdf0e10cSrcweir
278cdf0e10cSrcweir if( ! aTopLevelContainer.empty())
279cdf0e10cSrcweir m_aChildMap[ ObjectHierarchy::getRootNodeOID() ] = aTopLevelContainer;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir
createLegendTree(ObjectHierarchy::tChildContainer & rContainer,const Reference<XChartDocument> & xChartDoc,const Reference<XDiagram> & xDiagram)282cdf0e10cSrcweir void ImplObjectHierarchy::createLegendTree(
283cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rContainer,
284cdf0e10cSrcweir const Reference< XChartDocument > & xChartDoc,
285cdf0e10cSrcweir const Reference< XDiagram > & xDiagram )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir if( xDiagram.is() && LegendHelper::hasLegend( xDiagram ) )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir ObjectHierarchy::tOID aLegendOID( ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForObject( xDiagram->getLegend(), Reference< frame::XModel >( xChartDoc, uno::UNO_QUERY ) ) ) );
290cdf0e10cSrcweir rContainer.push_back( aLegendOID );
291cdf0e10cSrcweir
292cdf0e10cSrcweir // iterate over child shapes of legend and search for matching CIDs
293cdf0e10cSrcweir if( m_pExplicitValueProvider )
294cdf0e10cSrcweir {
295cdf0e10cSrcweir Reference< container::XIndexAccess > xLegendShapeContainer(
296cdf0e10cSrcweir m_pExplicitValueProvider->getShapeForCID( aLegendOID.getObjectCID() ), uno::UNO_QUERY );
297cdf0e10cSrcweir ObjectHierarchy::tChildContainer aLegendEntryOIDs;
298cdf0e10cSrcweir lcl_getChildOIDs( aLegendEntryOIDs, xLegendShapeContainer );
299cdf0e10cSrcweir
300cdf0e10cSrcweir m_aChildMap[ aLegendOID ] = aLegendEntryOIDs;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir }
303cdf0e10cSrcweir }
304cdf0e10cSrcweir
createAxesTree(ObjectHierarchy::tChildContainer & rContainer,const Reference<XChartDocument> & xChartDoc,const Reference<XDiagram> & xDiagram)305cdf0e10cSrcweir void ImplObjectHierarchy::createAxesTree(
306cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rContainer,
307cdf0e10cSrcweir const Reference< XChartDocument > & xChartDoc,
308cdf0e10cSrcweir const Reference< XDiagram > & xDiagram )
309cdf0e10cSrcweir {
310cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
311cdf0e10cSrcweir sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
312cdf0e10cSrcweir uno::Reference< chart2::XChartType > xChartType( DiagramHelper::getChartTypeByIndex( xDiagram, 0 ) );
313cdf0e10cSrcweir bool bSupportsAxesGrids = ChartTypeHelper::isSupportingMainAxis( xChartType, nDimensionCount, 0 );
314cdf0e10cSrcweir if( bSupportsAxesGrids )
315cdf0e10cSrcweir {
316cdf0e10cSrcweir Sequence< Reference< XAxis > > aAxes( AxisHelper::getAllAxesOfDiagram( xDiagram, /* bOnlyVisible = */ true ) );
317cdf0e10cSrcweir if( !m_bOrderingForElementSelector )
318cdf0e10cSrcweir ::std::transform( aAxes.getConstArray(), aAxes.getConstArray() + aAxes.getLength(),
319cdf0e10cSrcweir ::std::back_inserter( rContainer ),
320cdf0e10cSrcweir lcl_ObjectToOID( xChartDoc ));
321cdf0e10cSrcweir
322cdf0e10cSrcweir // get all axes, also invisible ones
323cdf0e10cSrcweir aAxes = AxisHelper::getAllAxesOfDiagram( xDiagram, /* bOnlyVisible = */ false );
324cdf0e10cSrcweir // Grids
325cdf0e10cSrcweir Reference< frame::XModel > xChartModel( xChartDoc, uno::UNO_QUERY );
326cdf0e10cSrcweir for( sal_Int32 nA=0; nA<aAxes.getLength(); ++nA )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir Reference< XAxis > xAxis( aAxes[nA] );
329cdf0e10cSrcweir if(!xAxis.is())
330cdf0e10cSrcweir continue;
331cdf0e10cSrcweir
332cdf0e10cSrcweir sal_Int32 nCooSysIndex = 0;
333cdf0e10cSrcweir sal_Int32 nDimensionIndex = 0;
334cdf0e10cSrcweir sal_Int32 nAxisIndex = 0;
335cdf0e10cSrcweir AxisHelper::getIndicesForAxis( xAxis, xDiagram, nCooSysIndex, nDimensionIndex, nAxisIndex );
336cdf0e10cSrcweir if( nAxisIndex>0 && !ChartTypeHelper::isSupportingSecondaryAxis( xChartType, nDimensionCount, nDimensionIndex ) )
337cdf0e10cSrcweir continue;
338cdf0e10cSrcweir
339cdf0e10cSrcweir if( m_bOrderingForElementSelector )
340cdf0e10cSrcweir {
341cdf0e10cSrcweir // axis
342cdf0e10cSrcweir if( AxisHelper::isAxisVisible( xAxis ) )
343cdf0e10cSrcweir rContainer.push_back(
344cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForObject( xAxis, xChartModel ) ) );
345cdf0e10cSrcweir
346cdf0e10cSrcweir // axis title
347cdf0e10cSrcweir lcl_addAxisTitle( aAxes[nA], rContainer, xChartModel );
348cdf0e10cSrcweir }
349cdf0e10cSrcweir
350cdf0e10cSrcweir Reference< beans::XPropertySet > xGridProperties( xAxis->getGridProperties() );
351cdf0e10cSrcweir if( AxisHelper::isGridVisible( xGridProperties ) )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir //main grid
354cdf0e10cSrcweir rContainer.push_back(
355cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel ) ) ) );
356cdf0e10cSrcweir }
357cdf0e10cSrcweir
358cdf0e10cSrcweir Sequence< Reference< beans::XPropertySet > > aSubGrids( xAxis->getSubGridProperties() );;
359cdf0e10cSrcweir sal_Int32 nSubGrid = 0;
360cdf0e10cSrcweir for( nSubGrid = 0; nSubGrid < aSubGrids.getLength(); ++nSubGrid )
361cdf0e10cSrcweir {
362cdf0e10cSrcweir Reference< beans::XPropertySet > xSubGridProperties( aSubGrids[nSubGrid] );
363cdf0e10cSrcweir if( AxisHelper::isGridVisible( xSubGridProperties ) )
364cdf0e10cSrcweir {
365cdf0e10cSrcweir //sub grid
366cdf0e10cSrcweir rContainer.push_back(
367cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForGrid( xAxis, xChartModel, nSubGrid ) ) ) );
368cdf0e10cSrcweir }
369cdf0e10cSrcweir }
370cdf0e10cSrcweir }
371cdf0e10cSrcweir }
372cdf0e10cSrcweir }
373cdf0e10cSrcweir
createWallAndFloor(ObjectHierarchy::tChildContainer & rContainer,const Reference<XDiagram> & xDiagram)374cdf0e10cSrcweir void ImplObjectHierarchy::createWallAndFloor(
375cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rContainer,
376cdf0e10cSrcweir const Reference< XDiagram > & xDiagram )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
379cdf0e10cSrcweir bool bIsThreeD = ( nDimensionCount == 3 );
380cdf0e10cSrcweir bool bHasWall = DiagramHelper::isSupportingFloorAndWall( xDiagram );
381cdf0e10cSrcweir if( bHasWall && bIsThreeD )
382cdf0e10cSrcweir {
383cdf0e10cSrcweir rContainer.push_back(
384cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_WALL, rtl::OUString() ) ) );
385cdf0e10cSrcweir
386cdf0e10cSrcweir Reference< beans::XPropertySet > xFloor( xDiagram->getFloor());
387cdf0e10cSrcweir if( xFloor.is())
388cdf0e10cSrcweir rContainer.push_back(
389cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifier( OBJECTTYPE_DIAGRAM_FLOOR, rtl::OUString() ) ) );
390cdf0e10cSrcweir }
391cdf0e10cSrcweir
392cdf0e10cSrcweir }
393cdf0e10cSrcweir
createDiagramTree(ObjectHierarchy::tChildContainer & rContainer,const Reference<XChartDocument> & xChartDoc,const Reference<XDiagram> & xDiagram)394cdf0e10cSrcweir void ImplObjectHierarchy::createDiagramTree(
395cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rContainer,
396cdf0e10cSrcweir const Reference< XChartDocument > & xChartDoc,
397cdf0e10cSrcweir const Reference< XDiagram > & xDiagram )
398cdf0e10cSrcweir {
399cdf0e10cSrcweir if( !m_bOrderingForElementSelector )
400cdf0e10cSrcweir {
401cdf0e10cSrcweir createDataSeriesTree( rContainer, xDiagram );
402cdf0e10cSrcweir createAxesTree( rContainer, xChartDoc, xDiagram );
403cdf0e10cSrcweir createWallAndFloor( rContainer, xDiagram );
404cdf0e10cSrcweir }
405cdf0e10cSrcweir else
406cdf0e10cSrcweir {
407cdf0e10cSrcweir createAxesTree( rContainer, xChartDoc, xDiagram );
408cdf0e10cSrcweir createDataSeriesTree( rContainer, xDiagram );
409cdf0e10cSrcweir }
410cdf0e10cSrcweir }
411cdf0e10cSrcweir
createDataSeriesTree(ObjectHierarchy::tChildContainer & rOutDiagramSubContainer,const Reference<XDiagram> & xDiagram)412cdf0e10cSrcweir void ImplObjectHierarchy::createDataSeriesTree(
413cdf0e10cSrcweir ObjectHierarchy::tChildContainer & rOutDiagramSubContainer,
414cdf0e10cSrcweir const Reference< XDiagram > & xDiagram )
415cdf0e10cSrcweir {
416cdf0e10cSrcweir Reference< XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY_THROW );
417cdf0e10cSrcweir
418cdf0e10cSrcweir try
419cdf0e10cSrcweir {
420cdf0e10cSrcweir sal_Int32 nDiagramIndex = 0;
421cdf0e10cSrcweir sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
422cdf0e10cSrcweir Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
423cdf0e10cSrcweir xCooSysCnt->getCoordinateSystems());
424cdf0e10cSrcweir for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx )
425cdf0e10cSrcweir {
426cdf0e10cSrcweir Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW );
427cdf0e10cSrcweir Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
428cdf0e10cSrcweir for( sal_Int32 nCTIdx=0; nCTIdx<aChartTypeSeq.getLength(); ++nCTIdx )
429cdf0e10cSrcweir {
430cdf0e10cSrcweir Reference< XChartType > xChartType( aChartTypeSeq[nCTIdx] );
431cdf0e10cSrcweir Reference< XDataSeriesContainer > xDSCnt( xChartType, uno::UNO_QUERY_THROW );
432cdf0e10cSrcweir Sequence< Reference< XDataSeries > > aSeriesSeq( xDSCnt->getDataSeries() );
433cdf0e10cSrcweir const sal_Int32 nNumberOfSeries =
434cdf0e10cSrcweir ChartTypeHelper::getNumberOfDisplayedSeries( xChartType, aSeriesSeq.getLength());
435cdf0e10cSrcweir
436cdf0e10cSrcweir for( sal_Int32 nSeriesIdx=0; nSeriesIdx<nNumberOfSeries; ++nSeriesIdx )
437cdf0e10cSrcweir {
438cdf0e10cSrcweir OUString aSeriesParticle(
439cdf0e10cSrcweir ObjectIdentifier::createParticleForSeries(
440cdf0e10cSrcweir nDiagramIndex, nCooSysIdx, nCTIdx, nSeriesIdx ));
441cdf0e10cSrcweir ObjectHierarchy::tOID aSeriesOID(
442cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForParticle( aSeriesParticle ) ) );
443cdf0e10cSrcweir rOutDiagramSubContainer.push_back( aSeriesOID );
444cdf0e10cSrcweir
445cdf0e10cSrcweir ObjectHierarchy::tChildContainer aSeriesSubContainer;
446cdf0e10cSrcweir
447cdf0e10cSrcweir Reference< chart2::XDataSeries > xSeries( aSeriesSeq[nSeriesIdx], uno::UNO_QUERY );
448cdf0e10cSrcweir
449cdf0e10cSrcweir // data lablels
450cdf0e10cSrcweir if( DataSeriesHelper::hasDataLabelsAtSeries( xSeries ) )
451cdf0e10cSrcweir {
452cdf0e10cSrcweir rtl::OUString aChildParticle( ObjectIdentifier::getStringForType( OBJECTTYPE_DATA_LABELS ) );
453cdf0e10cSrcweir aChildParticle+=(C2U("="));
454cdf0e10cSrcweir aSeriesSubContainer.push_back(
455cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierForParticles( aSeriesParticle, aChildParticle ) ) );
456cdf0e10cSrcweir }
457cdf0e10cSrcweir
458cdf0e10cSrcweir // Statistics
459cdf0e10cSrcweir if( ChartTypeHelper::isSupportingStatisticProperties( xChartType, nDimensionCount ) )
460cdf0e10cSrcweir {
461cdf0e10cSrcweir Reference< chart2::XRegressionCurveContainer > xCurveCnt( xSeries, uno::UNO_QUERY );
462cdf0e10cSrcweir if( xCurveCnt.is())
463cdf0e10cSrcweir {
464cdf0e10cSrcweir Sequence< Reference< chart2::XRegressionCurve > > aCurves( xCurveCnt->getRegressionCurves());
465cdf0e10cSrcweir for( sal_Int32 nCurveIdx=0; nCurveIdx<aCurves.getLength(); ++nCurveIdx )
466cdf0e10cSrcweir {
467cdf0e10cSrcweir bool bIsAverageLine = RegressionCurveHelper::isMeanValueLine( aCurves[nCurveIdx] );
468cdf0e10cSrcweir aSeriesSubContainer.push_back(
469cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createDataCurveCID( aSeriesParticle, nCurveIdx, bIsAverageLine ) ) );
470cdf0e10cSrcweir if( RegressionCurveHelper::hasEquation( aCurves[nCurveIdx] ) )
471cdf0e10cSrcweir {
472cdf0e10cSrcweir aSeriesSubContainer.push_back(
473cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createDataCurveEquationCID( aSeriesParticle, nCurveIdx ) ) );
474cdf0e10cSrcweir }
475cdf0e10cSrcweir }
476cdf0e10cSrcweir Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY );
477cdf0e10cSrcweir Reference< beans::XPropertySet > xErrorBarProp;
478cdf0e10cSrcweir if( xSeriesProp.is() &&
479cdf0e10cSrcweir (xSeriesProp->getPropertyValue( C2U("ErrorBarY")) >>= xErrorBarProp) &&
480cdf0e10cSrcweir xErrorBarProp.is())
481cdf0e10cSrcweir {
482cdf0e10cSrcweir sal_Int32 nStyle = ::com::sun::star::chart::ErrorBarStyle::NONE;
483cdf0e10cSrcweir if( ( xErrorBarProp->getPropertyValue( C2U("ErrorBarStyle")) >>= nStyle ) &&
484cdf0e10cSrcweir ( nStyle != ::com::sun::star::chart::ErrorBarStyle::NONE ) )
485cdf0e10cSrcweir {
486cdf0e10cSrcweir aSeriesSubContainer.push_back(
487cdf0e10cSrcweir ObjectIdentifier( ObjectIdentifier::createClassifiedIdentifierWithParent(
488cdf0e10cSrcweir OBJECTTYPE_DATA_ERRORS, OUString(), aSeriesParticle ) ) );
489cdf0e10cSrcweir }
490cdf0e10cSrcweir }
491cdf0e10cSrcweir }
492cdf0e10cSrcweir }
493cdf0e10cSrcweir
494cdf0e10cSrcweir // Data Points
495cdf0e10cSrcweir // iterate over child shapes of legend and search for matching CIDs
496cdf0e10cSrcweir if( m_pExplicitValueProvider )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir Reference< container::XIndexAccess > xSeriesShapeContainer(
499cdf0e10cSrcweir m_pExplicitValueProvider->getShapeForCID( aSeriesOID.getObjectCID() ), uno::UNO_QUERY );
500cdf0e10cSrcweir lcl_getChildOIDs( aSeriesSubContainer, xSeriesShapeContainer );
501cdf0e10cSrcweir }
502cdf0e10cSrcweir
503cdf0e10cSrcweir if( ! aSeriesSubContainer.empty())
504cdf0e10cSrcweir m_aChildMap[ aSeriesOID ] = aSeriesSubContainer;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir }
507cdf0e10cSrcweir }
508cdf0e10cSrcweir }
509cdf0e10cSrcweir catch( uno::Exception & ex )
510cdf0e10cSrcweir {
511cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
512cdf0e10cSrcweir }
513cdf0e10cSrcweir }
514cdf0e10cSrcweir
createAdditionalShapesTree(ObjectHierarchy::tChildContainer & rContainer)515cdf0e10cSrcweir void ImplObjectHierarchy::createAdditionalShapesTree( ObjectHierarchy::tChildContainer& rContainer )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir try
518cdf0e10cSrcweir {
519cdf0e10cSrcweir if ( m_pExplicitValueProvider )
520cdf0e10cSrcweir {
521cdf0e10cSrcweir Reference< drawing::XDrawPage > xDrawPage( m_pExplicitValueProvider->getDrawModelWrapper()->getMainDrawPage() );
522cdf0e10cSrcweir Reference< drawing::XShapes > xDrawPageShapes( xDrawPage, uno::UNO_QUERY_THROW );
523cdf0e10cSrcweir Reference< drawing::XShapes > xChartRoot( DrawModelWrapper::getChartRootShape( xDrawPage ) );
524cdf0e10cSrcweir sal_Int32 nCount = xDrawPageShapes->getCount();
525cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i )
526cdf0e10cSrcweir {
527cdf0e10cSrcweir Reference< drawing::XShape > xShape;
528cdf0e10cSrcweir if ( xDrawPageShapes->getByIndex( i ) >>= xShape )
529cdf0e10cSrcweir {
530cdf0e10cSrcweir if ( xShape.is() && xShape != xChartRoot )
531cdf0e10cSrcweir {
532cdf0e10cSrcweir rContainer.push_back( ObjectIdentifier( xShape ) );
533cdf0e10cSrcweir }
534cdf0e10cSrcweir }
535cdf0e10cSrcweir }
536cdf0e10cSrcweir }
537cdf0e10cSrcweir }
538cdf0e10cSrcweir catch ( uno::Exception& ex )
539cdf0e10cSrcweir {
540cdf0e10cSrcweir ASSERT_EXCEPTION( ex );
541cdf0e10cSrcweir }
542cdf0e10cSrcweir }
543cdf0e10cSrcweir
hasChildren(const ObjectHierarchy::tOID & rParent)544cdf0e10cSrcweir bool ImplObjectHierarchy::hasChildren( const ObjectHierarchy::tOID& rParent )
545cdf0e10cSrcweir {
546cdf0e10cSrcweir if ( rParent.isValid() )
547cdf0e10cSrcweir {
548cdf0e10cSrcweir tChildMap::const_iterator aIt( m_aChildMap.find( rParent ));
549cdf0e10cSrcweir if( aIt != m_aChildMap.end())
550cdf0e10cSrcweir return ! (aIt->second.empty());
551cdf0e10cSrcweir }
552cdf0e10cSrcweir return false;
553cdf0e10cSrcweir }
554cdf0e10cSrcweir
getChildren(const ObjectHierarchy::tOID & rParent)555cdf0e10cSrcweir ObjectHierarchy::tChildContainer ImplObjectHierarchy::getChildren( const ObjectHierarchy::tOID& rParent )
556cdf0e10cSrcweir {
557cdf0e10cSrcweir if ( rParent.isValid() )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir tChildMap::const_iterator aIt( m_aChildMap.find( rParent ));
560cdf0e10cSrcweir if( aIt != m_aChildMap.end())
561cdf0e10cSrcweir return aIt->second;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir return ObjectHierarchy::tChildContainer();
564cdf0e10cSrcweir }
565cdf0e10cSrcweir
getSiblings(const ObjectHierarchy::tOID & rNode)566cdf0e10cSrcweir ObjectHierarchy::tChildContainer ImplObjectHierarchy::getSiblings( const ObjectHierarchy::tOID& rNode )
567cdf0e10cSrcweir {
568cdf0e10cSrcweir if ( rNode.isValid() && !ObjectHierarchy::isRootNode( rNode ) )
569cdf0e10cSrcweir {
570cdf0e10cSrcweir for( tChildMap::const_iterator aIt( m_aChildMap.begin());
571cdf0e10cSrcweir aIt != m_aChildMap.end(); ++aIt )
572cdf0e10cSrcweir {
573cdf0e10cSrcweir ObjectHierarchy::tChildContainer::const_iterator aElemIt(
574cdf0e10cSrcweir ::std::find( aIt->second.begin(), aIt->second.end(), rNode ));
575cdf0e10cSrcweir if( aElemIt != aIt->second.end())
576cdf0e10cSrcweir return aIt->second;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir }
579cdf0e10cSrcweir return ObjectHierarchy::tChildContainer();
580cdf0e10cSrcweir }
581cdf0e10cSrcweir
getParentImpl(const ObjectHierarchy::tOID & rParentOID,const ObjectHierarchy::tOID & rOID)582cdf0e10cSrcweir ObjectHierarchy::tOID ImplObjectHierarchy::getParentImpl(
583cdf0e10cSrcweir const ObjectHierarchy::tOID & rParentOID,
584cdf0e10cSrcweir const ObjectHierarchy::tOID & rOID )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir // search children
587cdf0e10cSrcweir ObjectHierarchy::tChildContainer aChildren( getChildren( rParentOID ));
588cdf0e10cSrcweir ObjectHierarchy::tChildContainer::const_iterator aIt(
589cdf0e10cSrcweir ::std::find( aChildren.begin(), aChildren.end(), rOID ));
590cdf0e10cSrcweir // recursion end
591cdf0e10cSrcweir if( aIt != aChildren.end())
592cdf0e10cSrcweir return rParentOID;
593cdf0e10cSrcweir
594cdf0e10cSrcweir for( aIt = aChildren.begin(); aIt != aChildren.end(); ++aIt )
595cdf0e10cSrcweir {
596cdf0e10cSrcweir // recursion
597cdf0e10cSrcweir ObjectHierarchy::tOID aTempParent( getParentImpl( *aIt, rOID ));
598cdf0e10cSrcweir if ( aTempParent.isValid() )
599cdf0e10cSrcweir {
600cdf0e10cSrcweir // exit on success
601cdf0e10cSrcweir return aTempParent;
602cdf0e10cSrcweir }
603cdf0e10cSrcweir }
604cdf0e10cSrcweir
605cdf0e10cSrcweir // exit on fail
606cdf0e10cSrcweir return ObjectHierarchy::tOID();
607cdf0e10cSrcweir }
608cdf0e10cSrcweir
getParent(const ObjectHierarchy::tOID & rOID)609cdf0e10cSrcweir ObjectHierarchy::tOID ImplObjectHierarchy::getParent(
610cdf0e10cSrcweir const ObjectHierarchy::tOID & rOID )
611cdf0e10cSrcweir {
612cdf0e10cSrcweir return getParentImpl( ObjectHierarchy::getRootNodeOID(), rOID );
613cdf0e10cSrcweir }
614cdf0e10cSrcweir
615cdf0e10cSrcweir } // namespace impl
616cdf0e10cSrcweir
617cdf0e10cSrcweir
ObjectHierarchy(const Reference<XChartDocument> & xChartDocument,ExplicitValueProvider * pExplicitValueProvider,bool bFlattenDiagram,bool bOrderingForElementSelector)618cdf0e10cSrcweir ObjectHierarchy::ObjectHierarchy(
619cdf0e10cSrcweir const Reference< XChartDocument > & xChartDocument,
620cdf0e10cSrcweir ExplicitValueProvider * pExplicitValueProvider /* = 0 */,
621cdf0e10cSrcweir bool bFlattenDiagram /* = false */,
622cdf0e10cSrcweir bool bOrderingForElementSelector /* = false */) :
623cdf0e10cSrcweir m_apImpl( new impl::ImplObjectHierarchy( xChartDocument, pExplicitValueProvider, bFlattenDiagram, bOrderingForElementSelector ))
624cdf0e10cSrcweir {}
625cdf0e10cSrcweir
~ObjectHierarchy()626cdf0e10cSrcweir ObjectHierarchy::~ObjectHierarchy()
627cdf0e10cSrcweir {}
628cdf0e10cSrcweir
getRootNodeOID()629cdf0e10cSrcweir ObjectHierarchy::tOID ObjectHierarchy::getRootNodeOID()
630cdf0e10cSrcweir {
631cdf0e10cSrcweir return ObjectIdentifier( C2U( "ROOT" ) );
632cdf0e10cSrcweir }
633cdf0e10cSrcweir
isRootNode(const ObjectHierarchy::tOID & rOID)634cdf0e10cSrcweir bool ObjectHierarchy::isRootNode( const ObjectHierarchy::tOID& rOID )
635cdf0e10cSrcweir {
636cdf0e10cSrcweir return ( rOID == ObjectHierarchy::getRootNodeOID() );
637cdf0e10cSrcweir }
638cdf0e10cSrcweir
getTopLevelChildren() const639cdf0e10cSrcweir ObjectHierarchy::tChildContainer ObjectHierarchy::getTopLevelChildren() const
640cdf0e10cSrcweir {
641cdf0e10cSrcweir return m_apImpl->getChildren( ObjectHierarchy::getRootNodeOID());
642cdf0e10cSrcweir }
643cdf0e10cSrcweir
hasChildren(const tOID & rParent) const644cdf0e10cSrcweir bool ObjectHierarchy::hasChildren( const tOID& rParent ) const
645cdf0e10cSrcweir {
646cdf0e10cSrcweir return m_apImpl->hasChildren( rParent );
647cdf0e10cSrcweir }
648cdf0e10cSrcweir
getChildren(const ObjectHierarchy::tOID & rParent) const649cdf0e10cSrcweir ObjectHierarchy::tChildContainer ObjectHierarchy::getChildren(
650cdf0e10cSrcweir const ObjectHierarchy::tOID& rParent ) const
651cdf0e10cSrcweir {
652cdf0e10cSrcweir if ( rParent.isValid() )
653cdf0e10cSrcweir return m_apImpl->getChildren( rParent );
654cdf0e10cSrcweir
655cdf0e10cSrcweir return ObjectHierarchy::tChildContainer();
656cdf0e10cSrcweir }
657cdf0e10cSrcweir
getSiblings(const ObjectHierarchy::tOID & rNode) const658cdf0e10cSrcweir ObjectHierarchy::tChildContainer ObjectHierarchy::getSiblings(
659cdf0e10cSrcweir const ObjectHierarchy::tOID& rNode ) const
660cdf0e10cSrcweir {
661cdf0e10cSrcweir if ( rNode.isValid() && !isRootNode( rNode ) )
662cdf0e10cSrcweir return m_apImpl->getSiblings( rNode );
663cdf0e10cSrcweir
664cdf0e10cSrcweir return ObjectHierarchy::tChildContainer();
665cdf0e10cSrcweir }
666cdf0e10cSrcweir
getParent(const ObjectHierarchy::tOID & rNode) const667cdf0e10cSrcweir ObjectHierarchy::tOID ObjectHierarchy::getParent(
668cdf0e10cSrcweir const ObjectHierarchy::tOID& rNode ) const
669cdf0e10cSrcweir {
670cdf0e10cSrcweir return m_apImpl->getParent( rNode );
671cdf0e10cSrcweir }
672cdf0e10cSrcweir
getIndexInParent(const ObjectHierarchy::tOID & rNode) const673cdf0e10cSrcweir sal_Int32 ObjectHierarchy::getIndexInParent(
674cdf0e10cSrcweir const ObjectHierarchy::tOID& rNode ) const
675cdf0e10cSrcweir {
676cdf0e10cSrcweir tOID aParentOID( m_apImpl->getParent( rNode ));
677cdf0e10cSrcweir tChildContainer aChildren( m_apImpl->getChildren( aParentOID ) );
678cdf0e10cSrcweir tChildContainer::const_iterator aIt( aChildren.begin() );
679cdf0e10cSrcweir for( sal_Int32 nIndex = 0; aIt != aChildren.end(); ++nIndex, ++aIt )
680cdf0e10cSrcweir {
681cdf0e10cSrcweir if ( *aIt == rNode )
682cdf0e10cSrcweir return nIndex;
683cdf0e10cSrcweir }
684cdf0e10cSrcweir return -1;
685cdf0e10cSrcweir }
686cdf0e10cSrcweir
687cdf0e10cSrcweir // ================================================================================
688cdf0e10cSrcweir
ObjectKeyNavigation(const ObjectHierarchy::tOID & rCurrentOID,const Reference<chart2::XChartDocument> & xChartDocument,ExplicitValueProvider * pExplicitValueProvider)689cdf0e10cSrcweir ObjectKeyNavigation::ObjectKeyNavigation(
690cdf0e10cSrcweir const ObjectHierarchy::tOID & rCurrentOID,
691cdf0e10cSrcweir const Reference< chart2::XChartDocument > & xChartDocument,
692cdf0e10cSrcweir ExplicitValueProvider * pExplicitValueProvider /* = 0 */ ) :
693cdf0e10cSrcweir m_aCurrentOID( rCurrentOID ),
694cdf0e10cSrcweir m_xChartDocument( xChartDocument ),
695cdf0e10cSrcweir m_pExplicitValueProvider( pExplicitValueProvider ),
696cdf0e10cSrcweir m_bStepDownInDiagram( true )
697cdf0e10cSrcweir {
698cdf0e10cSrcweir if ( !m_aCurrentOID.isValid() )
699cdf0e10cSrcweir {
700cdf0e10cSrcweir setCurrentSelection( ObjectHierarchy::getRootNodeOID() );
701cdf0e10cSrcweir }
702cdf0e10cSrcweir }
703cdf0e10cSrcweir
handleKeyEvent(const awt::KeyEvent & rEvent)704cdf0e10cSrcweir bool ObjectKeyNavigation::handleKeyEvent(
705cdf0e10cSrcweir const awt::KeyEvent & rEvent )
706cdf0e10cSrcweir {
707cdf0e10cSrcweir bool bResult = false;
708cdf0e10cSrcweir
709cdf0e10cSrcweir switch( rEvent.KeyCode )
710cdf0e10cSrcweir {
711cdf0e10cSrcweir case awt::Key::TAB:
712cdf0e10cSrcweir if( rEvent.Modifiers & awt::KeyModifier::SHIFT )
713cdf0e10cSrcweir bResult = previous();
714cdf0e10cSrcweir else
715cdf0e10cSrcweir bResult = next();
716cdf0e10cSrcweir break;
717cdf0e10cSrcweir case awt::Key::HOME:
718cdf0e10cSrcweir bResult = first();
719cdf0e10cSrcweir break;
720cdf0e10cSrcweir case awt::Key::END:
721cdf0e10cSrcweir bResult = last();
722cdf0e10cSrcweir break;
723cdf0e10cSrcweir case awt::Key::F3:
724cdf0e10cSrcweir if( rEvent.Modifiers & awt::KeyModifier::SHIFT )
725cdf0e10cSrcweir bResult = up();
726cdf0e10cSrcweir else
727cdf0e10cSrcweir bResult = down();
728cdf0e10cSrcweir break;
729cdf0e10cSrcweir case awt::Key::ESCAPE:
730cdf0e10cSrcweir setCurrentSelection( ObjectIdentifier() );
731cdf0e10cSrcweir bResult = true;
732cdf0e10cSrcweir break;
733cdf0e10cSrcweir default:
734cdf0e10cSrcweir bResult = false;
735cdf0e10cSrcweir break;
736cdf0e10cSrcweir }
737cdf0e10cSrcweir return bResult;
738cdf0e10cSrcweir }
739cdf0e10cSrcweir
setCurrentSelection(const ObjectHierarchy::tOID & rOID)740cdf0e10cSrcweir void ObjectKeyNavigation::setCurrentSelection( const ObjectHierarchy::tOID& rOID )
741cdf0e10cSrcweir {
742cdf0e10cSrcweir m_aCurrentOID = rOID;
743cdf0e10cSrcweir }
744cdf0e10cSrcweir
getCurrentSelection() const745cdf0e10cSrcweir ObjectHierarchy::tOID ObjectKeyNavigation::getCurrentSelection() const
746cdf0e10cSrcweir {
747cdf0e10cSrcweir return m_aCurrentOID;
748cdf0e10cSrcweir }
749cdf0e10cSrcweir
first()750cdf0e10cSrcweir bool ObjectKeyNavigation::first()
751cdf0e10cSrcweir {
752cdf0e10cSrcweir ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider, m_bStepDownInDiagram );
753cdf0e10cSrcweir ObjectHierarchy::tChildContainer aSiblings( aHierarchy.getSiblings( getCurrentSelection() ) );
754cdf0e10cSrcweir bool bResult = !aSiblings.empty();
755cdf0e10cSrcweir if( bResult )
756cdf0e10cSrcweir setCurrentSelection( aSiblings.front());
757cdf0e10cSrcweir else
758cdf0e10cSrcweir bResult = veryFirst();
759cdf0e10cSrcweir return bResult;
760cdf0e10cSrcweir }
761cdf0e10cSrcweir
last()762cdf0e10cSrcweir bool ObjectKeyNavigation::last()
763cdf0e10cSrcweir {
764cdf0e10cSrcweir ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider, m_bStepDownInDiagram );
765cdf0e10cSrcweir ObjectHierarchy::tChildContainer aSiblings( aHierarchy.getSiblings( getCurrentSelection() ) );
766cdf0e10cSrcweir bool bResult = !aSiblings.empty();
767cdf0e10cSrcweir if( bResult )
768cdf0e10cSrcweir setCurrentSelection( aSiblings.back());
769cdf0e10cSrcweir else
770cdf0e10cSrcweir bResult = veryLast();
771cdf0e10cSrcweir return bResult;
772cdf0e10cSrcweir }
773cdf0e10cSrcweir
next()774cdf0e10cSrcweir bool ObjectKeyNavigation::next()
775cdf0e10cSrcweir {
776cdf0e10cSrcweir ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider, m_bStepDownInDiagram );
777cdf0e10cSrcweir ObjectHierarchy::tChildContainer aSiblings( aHierarchy.getSiblings( getCurrentSelection() ) );
778cdf0e10cSrcweir bool bResult = !aSiblings.empty();
779cdf0e10cSrcweir if( bResult )
780cdf0e10cSrcweir {
781cdf0e10cSrcweir ObjectHierarchy::tChildContainer::const_iterator aIt(
782cdf0e10cSrcweir ::std::find( aSiblings.begin(), aSiblings.end(), getCurrentSelection()));
783cdf0e10cSrcweir OSL_ASSERT( aIt != aSiblings.end());
784cdf0e10cSrcweir if( ++aIt == aSiblings.end())
785cdf0e10cSrcweir aIt = aSiblings.begin();
786cdf0e10cSrcweir setCurrentSelection( *aIt );
787cdf0e10cSrcweir }
788cdf0e10cSrcweir else
789cdf0e10cSrcweir bResult = veryFirst();
790cdf0e10cSrcweir
791cdf0e10cSrcweir return bResult;
792cdf0e10cSrcweir }
793cdf0e10cSrcweir
previous()794cdf0e10cSrcweir bool ObjectKeyNavigation::previous()
795cdf0e10cSrcweir {
796cdf0e10cSrcweir ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider, m_bStepDownInDiagram );
797cdf0e10cSrcweir ObjectHierarchy::tChildContainer aSiblings( aHierarchy.getSiblings( getCurrentSelection()));
798cdf0e10cSrcweir bool bResult = !aSiblings.empty();
799cdf0e10cSrcweir if( bResult )
800cdf0e10cSrcweir {
801cdf0e10cSrcweir ObjectHierarchy::tChildContainer::const_iterator aIt(
802cdf0e10cSrcweir ::std::find( aSiblings.begin(), aSiblings.end(), getCurrentSelection()));
803cdf0e10cSrcweir OSL_ASSERT( aIt != aSiblings.end());
804cdf0e10cSrcweir if( aIt == aSiblings.begin())
805cdf0e10cSrcweir aIt = aSiblings.end();
806cdf0e10cSrcweir --aIt;
807cdf0e10cSrcweir setCurrentSelection( *aIt );
808cdf0e10cSrcweir }
809cdf0e10cSrcweir else
810cdf0e10cSrcweir bResult = veryLast();
811cdf0e10cSrcweir return bResult;
812cdf0e10cSrcweir }
813cdf0e10cSrcweir
up()814cdf0e10cSrcweir bool ObjectKeyNavigation::up()
815cdf0e10cSrcweir {
816cdf0e10cSrcweir ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider, m_bStepDownInDiagram );
817cdf0e10cSrcweir bool bResult = !ObjectHierarchy::isRootNode( getCurrentSelection());
818cdf0e10cSrcweir if( bResult )
819cdf0e10cSrcweir setCurrentSelection( aHierarchy.getParent( getCurrentSelection()));
820cdf0e10cSrcweir return bResult;
821cdf0e10cSrcweir }
822cdf0e10cSrcweir
down()823cdf0e10cSrcweir bool ObjectKeyNavigation::down()
824cdf0e10cSrcweir {
825cdf0e10cSrcweir ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider, m_bStepDownInDiagram );
826cdf0e10cSrcweir bool bResult = aHierarchy.hasChildren( getCurrentSelection());
827cdf0e10cSrcweir if( bResult )
828cdf0e10cSrcweir {
829cdf0e10cSrcweir ObjectHierarchy::tChildContainer aChildren = aHierarchy.getChildren( getCurrentSelection());
830cdf0e10cSrcweir OSL_ASSERT( !aChildren.empty());
831cdf0e10cSrcweir setCurrentSelection( aChildren.front());
832cdf0e10cSrcweir }
833cdf0e10cSrcweir return bResult;
834cdf0e10cSrcweir }
835cdf0e10cSrcweir
veryFirst()836cdf0e10cSrcweir bool ObjectKeyNavigation::veryFirst()
837cdf0e10cSrcweir {
838cdf0e10cSrcweir ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider, m_bStepDownInDiagram );
839cdf0e10cSrcweir ObjectHierarchy::tChildContainer aChildren( aHierarchy.getTopLevelChildren());
840cdf0e10cSrcweir bool bResult = !aChildren.empty();
841cdf0e10cSrcweir if( bResult )
842cdf0e10cSrcweir setCurrentSelection( aChildren.front());
843cdf0e10cSrcweir return bResult;
844cdf0e10cSrcweir }
845cdf0e10cSrcweir
veryLast()846cdf0e10cSrcweir bool ObjectKeyNavigation::veryLast()
847cdf0e10cSrcweir {
848cdf0e10cSrcweir ObjectHierarchy aHierarchy( m_xChartDocument, m_pExplicitValueProvider, m_bStepDownInDiagram );
849cdf0e10cSrcweir ObjectHierarchy::tChildContainer aChildren( aHierarchy.getTopLevelChildren());
850cdf0e10cSrcweir bool bResult = !aChildren.empty();
851cdf0e10cSrcweir if( bResult )
852cdf0e10cSrcweir setCurrentSelection( aChildren.back());
853cdf0e10cSrcweir return bResult;
854cdf0e10cSrcweir }
855cdf0e10cSrcweir
856cdf0e10cSrcweir } // namespace chart
857