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